Skip to content

Commit f196d63

Browse files
authored
material: texture wrap 'repeat' (#63)
1 parent 1ad4594 commit f196d63

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

tests/testMaterial.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def test_material_texture(self):
144144
texture_material = UsdShade.Material(texture_material_prim)
145145
self.assertTrue(texture_material)
146146
self.assertTrue(texture_material.GetPrim().HasAuthoredReferences())
147+
wrap_mode = self.get_material_wrap_mode(texture_material)
148+
self.assertEqual(wrap_mode, "repeat")
147149

148150
diffuse_color = self.get_material_diffuse_color(texture_material)
149151
self.assertEqual(diffuse_color, None)
@@ -159,6 +161,8 @@ def test_material_texture(self):
159161
color_texture_material = UsdShade.Material(color_texture_material_prim)
160162
self.assertTrue(color_texture_material)
161163
self.assertTrue(color_texture_material.GetPrim().HasAuthoredReferences())
164+
wrap_mode = self.get_material_wrap_mode(color_texture_material)
165+
self.assertEqual(wrap_mode, "repeat")
162166

163167
opacity = self.get_material_opacity(color_texture_material)
164168
self.assertEqual(opacity, 1.0)
@@ -457,6 +461,8 @@ def test_material_mesh_texture(self):
457461
self.assertTrue(texture_material_prim.IsA(UsdShade.Material))
458462
texture_material = UsdShade.Material(texture_material_prim)
459463
self.assertTrue(texture_material)
464+
wrap_mode = self.get_material_wrap_mode(texture_material)
465+
self.assertEqual(wrap_mode, "repeat")
460466

461467
diffuse_color = self.get_material_diffuse_color(texture_material)
462468
self.assertIsNone(diffuse_color)
@@ -478,6 +484,8 @@ def test_material_mesh_texture(self):
478484
self.assertTrue(texture_opacity_material_prim.IsA(UsdShade.Material))
479485
texture_opacity_material = UsdShade.Material(texture_opacity_material_prim)
480486
self.assertTrue(texture_opacity_material)
487+
wrap_mode = self.get_material_wrap_mode(texture_opacity_material)
488+
self.assertEqual(wrap_mode, "repeat")
481489

482490
diffuse_color = self.get_material_diffuse_color(texture_opacity_material)
483491
self.assertIsNone(diffuse_color)
@@ -491,6 +499,8 @@ def test_material_mesh_texture(self):
491499
self.assertTrue(texture_specular_workflow_material_prim.IsA(UsdShade.Material))
492500
texture_specular_workflow_material = UsdShade.Material(texture_specular_workflow_material_prim)
493501
self.assertTrue(texture_specular_workflow_material)
502+
wrap_mode = self.get_material_wrap_mode(texture_specular_workflow_material)
503+
self.assertEqual(wrap_mode, "repeat")
494504

495505
diffuse_color = self.get_material_diffuse_color(texture_specular_workflow_material)
496506
diffuse_color = usdex.core.linearToSrgb(diffuse_color)

tests/util/ConverterTestCase.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ def get_material_metallic(self, material: UsdShade.Material) -> float:
6262
def get_material_ior(self, material: UsdShade.Material) -> float:
6363
return self._get_material_input_value(material, "ior")
6464

65+
def get_material_wrap_mode(self, material: UsdShade.Material) -> str:
66+
wrap_mode_input = material.GetInput("wrapMode")
67+
wrap_mode = wrap_mode_input.Get() if wrap_mode_input else None
68+
69+
for child in material.GetPrim().GetAllChildren():
70+
shader = UsdShade.Shader(child)
71+
if shader.GetShaderId() == "UsdUVTexture":
72+
wrap_s = shader.GetInput("wrapS").Get()
73+
wrap_t = shader.GetInput("wrapT").Get()
74+
self.assertEqual(wrap_mode, wrap_s)
75+
self.assertEqual(wrap_mode, wrap_t)
76+
return wrap_mode
77+
6578
def get_material_texture_path(self, material: UsdShade.Material, texture_type: str = "diffuseColor") -> pathlib.Path:
6679
"""
6780
Get the texture path for the given texture type.

urdf_usd_converter/_impl/material.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def _convert_material(
169169
if not result:
170170
Tf.RaiseRuntimeError(f'Failed to add material instance to material prim "{material_prim.GetPath()}"')
171171

172+
# Set the wrap mode to repeat.
173+
_set_wrap_mode(material_prim, "repeat")
174+
172175
material_prim.GetPrim().SetInstanceable(True)
173176

174177
return material_prim
@@ -236,6 +239,16 @@ def _acquire_texture_reader(
236239
return tex_shader
237240

238241

242+
def _set_wrap_mode(material_prim: UsdShade.Material, wrap_mode: str):
243+
wrap_mode_input = material_prim.CreateInput("wrapMode", Sdf.ValueTypeNames.Token)
244+
wrap_mode_input.Set(wrap_mode)
245+
for child in material_prim.GetPrim().GetAllChildren():
246+
shader = UsdShade.Shader(child)
247+
if shader.GetShaderId() == "UsdUVTexture":
248+
shader.CreateInput("wrapS", Sdf.ValueTypeNames.Token).ConnectToSource(wrap_mode_input)
249+
shader.CreateInput("wrapT", Sdf.ValueTypeNames.Token).ConnectToSource(wrap_mode_input)
250+
251+
239252
def _get_texture_asset_path(texture_path: pathlib.Path, texture_paths: dict[pathlib.Path, str], data: ConversionData) -> Sdf.AssetPath:
240253
"""
241254
Get the asset path for the texture.

0 commit comments

Comments
 (0)