Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/testMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def test_material_texture(self):
texture_material = UsdShade.Material(texture_material_prim)
self.assertTrue(texture_material)
self.assertTrue(texture_material.GetPrim().HasAuthoredReferences())
wrap_mode = self.get_material_wrap_mode(texture_material)
self.assertEqual(wrap_mode, "repeat")

diffuse_color = self.get_material_diffuse_color(texture_material)
self.assertEqual(diffuse_color, None)
Expand All @@ -159,6 +161,8 @@ def test_material_texture(self):
color_texture_material = UsdShade.Material(color_texture_material_prim)
self.assertTrue(color_texture_material)
self.assertTrue(color_texture_material.GetPrim().HasAuthoredReferences())
wrap_mode = self.get_material_wrap_mode(color_texture_material)
self.assertEqual(wrap_mode, "repeat")

opacity = self.get_material_opacity(color_texture_material)
self.assertEqual(opacity, 1.0)
Expand Down Expand Up @@ -457,6 +461,8 @@ def test_material_mesh_texture(self):
self.assertTrue(texture_material_prim.IsA(UsdShade.Material))
texture_material = UsdShade.Material(texture_material_prim)
self.assertTrue(texture_material)
wrap_mode = self.get_material_wrap_mode(texture_material)
self.assertEqual(wrap_mode, "repeat")

diffuse_color = self.get_material_diffuse_color(texture_material)
self.assertIsNone(diffuse_color)
Expand All @@ -478,6 +484,8 @@ def test_material_mesh_texture(self):
self.assertTrue(texture_opacity_material_prim.IsA(UsdShade.Material))
texture_opacity_material = UsdShade.Material(texture_opacity_material_prim)
self.assertTrue(texture_opacity_material)
wrap_mode = self.get_material_wrap_mode(texture_opacity_material)
self.assertEqual(wrap_mode, "repeat")

diffuse_color = self.get_material_diffuse_color(texture_opacity_material)
self.assertIsNone(diffuse_color)
Expand All @@ -491,6 +499,8 @@ def test_material_mesh_texture(self):
self.assertTrue(texture_specular_workflow_material_prim.IsA(UsdShade.Material))
texture_specular_workflow_material = UsdShade.Material(texture_specular_workflow_material_prim)
self.assertTrue(texture_specular_workflow_material)
wrap_mode = self.get_material_wrap_mode(texture_specular_workflow_material)
self.assertEqual(wrap_mode, "repeat")

diffuse_color = self.get_material_diffuse_color(texture_specular_workflow_material)
diffuse_color = usdex.core.linearToSrgb(diffuse_color)
Expand Down
13 changes: 13 additions & 0 deletions tests/util/ConverterTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ def get_material_metallic(self, material: UsdShade.Material) -> float:
def get_material_ior(self, material: UsdShade.Material) -> float:
return self._get_material_input_value(material, "ior")

def get_material_wrap_mode(self, material: UsdShade.Material) -> str:
wrap_mode_input = material.GetInput("wrapMode")
wrap_mode = wrap_mode_input.Get() if wrap_mode_input else None

for child in material.GetPrim().GetAllChildren():
shader = UsdShade.Shader(child)
if shader.GetShaderId() == "UsdUVTexture":
wrap_s = shader.GetInput("wrapS").Get()
wrap_t = shader.GetInput("wrapT").Get()
self.assertEqual(wrap_mode, wrap_s)
self.assertEqual(wrap_mode, wrap_t)
return wrap_mode

def get_material_texture_path(self, material: UsdShade.Material, texture_type: str = "diffuseColor") -> pathlib.Path:
"""
Get the texture path for the given texture type.
Expand Down
13 changes: 13 additions & 0 deletions urdf_usd_converter/_impl/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def _convert_material(
if not result:
Tf.RaiseRuntimeError(f'Failed to add material instance to material prim "{material_prim.GetPath()}"')

# Set the wrap mode to repeat.
_set_wrap_mode(material_prim, "repeat")

material_prim.GetPrim().SetInstanceable(True)

return material_prim
Expand Down Expand Up @@ -236,6 +239,16 @@ def _acquire_texture_reader(
return tex_shader


def _set_wrap_mode(material_prim: UsdShade.Material, wrap_mode: str):
wrap_mode_input = material_prim.CreateInput("wrapMode", Sdf.ValueTypeNames.Token)
wrap_mode_input.Set(wrap_mode)
for child in material_prim.GetPrim().GetAllChildren():
shader = UsdShade.Shader(child)
if shader.GetShaderId() == "UsdUVTexture":
shader.CreateInput("wrapS", Sdf.ValueTypeNames.Token).ConnectToSource(wrap_mode_input)
shader.CreateInput("wrapT", Sdf.ValueTypeNames.Token).ConnectToSource(wrap_mode_input)


def _get_texture_asset_path(texture_path: pathlib.Path, texture_paths: dict[pathlib.Path, str], data: ConversionData) -> Sdf.AssetPath:
"""
Get the asset path for the texture.
Expand Down
Loading