From 6ce6bcc393fc7569a7602781263a4b8740ee8c6e Mon Sep 17 00:00:00 2001 From: Yutaka Yoshisaka Date: Mon, 26 Jan 2026 17:04:15 +0900 Subject: [PATCH 1/2] material: texture wrap 'repeat' --- tests/testMaterial.py | 10 ++++++++++ tests/util/ConverterTestCase.py | 13 +++++++++++++ urdf_usd_converter/_impl/material.py | 13 +++++++++++++ 3 files changed, 36 insertions(+) diff --git a/tests/testMaterial.py b/tests/testMaterial.py index cf6850f..b5300f0 100644 --- a/tests/testMaterial.py +++ b/tests/testMaterial.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests/util/ConverterTestCase.py b/tests/util/ConverterTestCase.py index d155e54..b3d4acb 100644 --- a/tests/util/ConverterTestCase.py +++ b/tests/util/ConverterTestCase.py @@ -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. diff --git a/urdf_usd_converter/_impl/material.py b/urdf_usd_converter/_impl/material.py index c65ad30..6bd11af 100644 --- a/urdf_usd_converter/_impl/material.py +++ b/urdf_usd_converter/_impl/material.py @@ -164,6 +164,9 @@ def _convert_material( material_prim, "emissiveColor", "EmissiveTexture", _get_texture_asset_path(material_data.emissive_texture_path, texture_paths, data) ) + # Set the wrap mode to repeat. + _set_wrap_mode(material_prim, "repeat") + # Add the material interface. result = usdex.core.addPreviewMaterialInterface(material_prim) if not result: @@ -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. From a075101dd8d06ea54e0a9032c0bc5eae4d84b29e Mon Sep 17 00:00:00 2001 From: Yutaka Yoshisaka Date: Tue, 27 Jan 2026 09:50:26 +0900 Subject: [PATCH 2/2] material: Tweaking texture wrap 'repeat' --- urdf_usd_converter/_impl/material.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/urdf_usd_converter/_impl/material.py b/urdf_usd_converter/_impl/material.py index 6bd11af..570c9df 100644 --- a/urdf_usd_converter/_impl/material.py +++ b/urdf_usd_converter/_impl/material.py @@ -164,14 +164,14 @@ def _convert_material( material_prim, "emissiveColor", "EmissiveTexture", _get_texture_asset_path(material_data.emissive_texture_path, texture_paths, data) ) - # Set the wrap mode to repeat. - _set_wrap_mode(material_prim, "repeat") - # Add the material interface. result = usdex.core.addPreviewMaterialInterface(material_prim) 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