kcoley / gltf2usd

command-line utility for converting glTF 2.0 models to USD
MIT License
263 stars 39 forks source link

Conversion special character in name bug #144

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi,

It seems we have some exceptions coming up on our gltf2usd server when we use some special characters on the node or accessors names in the gltf file.

I get this exception

converted usd file extension from .usdz to .usdc: /var/app/current/tmp/325196664e676c984d3f98e0c26dfa33b119b12cc0d869e99c1e16a3aa1f584f/usdz/dist.usdc
Warning: in _InitWithString at line 106 of /usr/local/src/USD-18.09/pxr/usd/lib/sdf/path.cpp -- Ill-formed SdfPath </root/m10[All_variants]_0>: syntax error
Traceback (most recent call last):
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 822, in <module>
    convert_to_usd(os.path.expanduser(args.gltf_file), os.path.abspath(os.path.expanduser(args.usd_file)), args.fps, args.scale, args.arkit, args.verbose, args.use_euler_rotation, args.optimize_textures)
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 770, in convert_to_usd
    usd = GLTF2USD(gltf_file=gltf_file, usd_file=usd_file, fps=fps, scale=scale, verbose=verbose, use_euler_rotation=use_euler_rotation, optimize_textures=optimize_textures)
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 74, in __init__
    self.convert()
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 741, in convert
    self.convert_nodes_to_xform()
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 90, in convert_nodes_to_xform
    self._convert_node_to_xform(node, parent_transform)
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 101, in _convert_node_to_xform
    xformPrim = UsdGeom.Xform.Define(self.stage, '{0}/{1}'.format(usd_xform.GetPath(), GLTF2USDUtils.convert_to_usd_friendly_node_name(node.name)))
pxr.Tf.ErrorException: 
    Error in 'pxrInternal_v0_18__pxrReserved__::UsdStage::_IsValidPathForCreatingPrim' at line 3096 in file /usr/local/src/USD-18.09/pxr/usd/lib/usd/stage.cpp : 'Path must be an absolute path: <>'

Below a sample of glTF file.

{
  "accessors": [
    {
      "name": "10[All_variants]_1_0_positions",
      "componentType": 5126,
      "count": 37014,
      "min": [8.615839958190918, 0, -2.7404041290283203],
      "max": [9.575827598571777, 1.03200101852417, -1.5404040813446045],
      "type": "VEC3",
      "bufferView": 0,
      "byteOffset": 0
    },
    {
      "name": "10[All_variants]_1_0_normals",
      "componentType": 5126,
      "count": 37014,
      "min": [-1, -1, -1],
      "max": [1, 1, 1],
      "type": "VEC3",
      "bufferView": 1,
      "byteOffset": 0
    },
    {
      "name": "10[All_variants]_1_0_texcoords",
      "componentType": 5126,
      "count": 37014,
      "min": [0.0020000000949949026, 0.018599987030029297],
      "max": [0.9980000257492065, 0.9980000257492065],
      "type": "VEC2",
      "bufferView": 2,
      "byteOffset": 0
    },
    {
      "name": "10[All_variants]_1_0_indices",
      "componentType": 5123,
      "count": 115464,
      "min": [0],
      "max": [37013],
      "type": "SCALAR",
      "bufferView": 3,
      "byteOffset": 0
    }
  ],
  "asset": { "generator": "obj2gltf", "version": "2.0" },
  "buffers": [
    {
      "name": "10_All_variants__fixed",
      "byteLength": 1415376,
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/9dc-original.bin"
    }
  ],
  "bufferViews": [
    {
      "name": "bufferView_0",
      "buffer": 0,
      "byteLength": 444168,
      "byteOffset": 0,
      "byteStride": 12,
      "target": 34962
    },
    {
      "name": "bufferView_1",
      "buffer": 0,
      "byteLength": 444168,
      "byteOffset": 444168,
      "byteStride": 12,
      "target": 34962
    },
    {
      "name": "bufferView_2",
      "buffer": 0,
      "byteLength": 296112,
      "byteOffset": 888336,
      "byteStride": 8,
      "target": 34962
    },
    {
      "name": "bufferView_3",
      "buffer": 0,
      "byteLength": 230928,
      "byteOffset": 1184448,
      "target": 34963
    }
  ],
  "materials": [
    {
      "name": "Red rust - standard 10",
      "alphaMode": "BLEND",
      "doubleSided": false,
      "emissiveFactor": [0, 0, 0],
      "pbrMetallicRoughness": {
        "baseColorFactor": [1, 1, 1, 1],
        "baseColorTexture": {
          "index": 0,
          "extensions": {
            "KHR_texture_transform": {
              "scale": [1, 1],
              "offset": [0, 0],
              "rotation": 0
            }
          }
        },
        "metallicRoughnessTexture": {
          "index": 1,
          "extensions": {
            "KHR_texture_transform": {
              "scale": [1, 1],
              "offset": [0, 0],
              "rotation": 0
            }
          }
        }
      },
      "normalTexture": {
        "index": 5,
        "extensions": {
          "KHR_texture_transform": {
            "scale": [1, 1],
            "offset": [0, 0],
            "rotation": 0
          }
        }
      },
      "occlusionTexture": { "index": 1, "strength": 1 },
      "extras": {
        "sayduck": { "uuid": "14b7bc60-0b44-0137-0ef4-36612cffbc46" }
      }
    }
  ],
  "meshes": [
    {
      "name": "10[All_variants]_1",
      "primitives": [
        {
          "attributes": { "POSITION": 0, "NORMAL": 1, "TEXCOORD_0": 2 },
          "indices": 3,
          "material": 0,
          "mode": 4
        }
      ],
      "extras": {
        "sayduck": { "uuid": "a5617750-0dbc-0137-f4ab-02876086fc58" }
      }
    }
  ],
  "nodes": [{ "name": "10[All_variants]", "mesh": 0 }],
  "scene": 0,
  "scenes": [{ "nodes": [0] }],
  "samplers": [
    { "magFilter": 9729, "minFilter": 9986, "wrapS": 10497, "wrapT": 10497 }
  ],
  "textures": [
    { "name": "albedo", "sampler": 0, "source": 0 },
    { "name": "occlusion_roughness_metallic", "sampler": 0, "source": 1 },
    { "name": "occlusion_roughness_metallic", "sampler": 0, "source": 2 },
    { "name": "occlusion", "sampler": 0, "source": 3 },
    { "name": "roughness", "sampler": 0, "source": 4 },
    { "name": "normal", "sampler": 0, "source": 5 },
    { "name": "metallic", "sampler": 0, "source": 6 }
  ],
  "images": [
    {
      "name": "albedo",
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/6c9-optimized_texture_jpg_2048.jpg"
    },
    {
      "name": "occlusion_roughness_metallic",
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/60b-optimized_texture_jpg_2048.jpg"
    },
    {
      "name": "occlusion_roughness_metallic",
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/60b-optimized_texture_jpg_2048.jpg"
    },
    {
      "name": "occlusion",
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/a3a-optimized_texture_jpg_2048.jpg"
    },
    {
      "name": "roughness",
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/0de-optimized_texture_jpg_2048.jpg"
    },
    {
      "name": "normal",
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/f15-optimized_texture_jpg_2048.jpg"
    },
    {
      "name": "metallic",
      "uri": "https://s3.us-east-1.amazonaws.com/(...)/797-optimized_texture_jpg_2048.jpg"
    }
  ],
  "extensionsUsed": ["KHR_texture_transform"],
  "extensionsRequired": ["KHR_texture_transform"]
}
kcoley commented 5 years ago

@sayduck-daniel I made an update to include square brackets in the regex. Does that work for you?

ghost commented 5 years ago

I'm gonna give it a try. I let you know.

I would actually remove everything that is not a-zA-Z0-9_- to be on the safe side.

ghost commented 5 years ago

Getting this error now:

converted usd file extension from .usdz to .usdc: /var/app/current/tmp/ad09871fbfc6fca0cdd8c8c20720525517c4de2b874c50924d0b51b19c9f3842/usdz/dist.usdc
Warning: in _InitWithString at line 106 of /usr/local/src/USD-18.09/pxr/usd/lib/sdf/path.cpp -- Ill-formed SdfPath </Materials/Red rust standard 10>: syntax error
Traceback (most recent call last):
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 835, in <module>
    convert_to_usd(os.path.expanduser(args.gltf_file), os.path.abspath(os.path.expanduser(args.usd_file)), args.fps, args.scale, args.arkit, args.verbose, args.use_euler_rotation, args.optimize_textures, args.generate_texture_transform_texture)
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 779, in convert_to_usd
    usd = GLTF2USD(gltf_file=gltf_file, usd_file=usd_file, fps=fps, scale=scale, verbose=verbose, use_euler_rotation=use_euler_rotation, optimize_textures=optimize_textures, generate_texture_transform_texture=generate_texture_transform_texture)
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 74, in __init__
    self.convert()
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 749, in convert
    self._convert_materials_to_preview_surface_new()
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 458, in _convert_materials_to_preview_surface_new
    usd_material = USDMaterial(self.stage, material.get_name(), scope, i, self.gltf_loader)
  File "/usr/local/gltf2usd/Source/_gltf2usd/usd_material.py", line 15, in __init__
    self._usd_material = UsdShade.Material.Define(stage, self._material_path)
pxr.Tf.ErrorException: 
    Error in 'pxrInternal_v0_18__pxrReserved__::UsdStage::_IsValidPathForCreatingPrim' at line 3096 in file /usr/local/src/USD-18.09/pxr/usd/lib/usd/stage.cpp : 'Path must be an absolute path: <>'
kcoley commented 5 years ago

@sayduck-daniel does this branch work for you?: https://github.com/kcoley/gltf2usd/tree/materialNameTest

ghost commented 5 years ago

Sill not working. I sent you privately on twitter the glTF we using.

The error we got:

converted usd file extension from .usdz to .usdc: /var/app/current/tmp/12dad0a75392660b12fc01f41beb293b4987a6cb0aeac21889872991404bd4f7/usdz/dist.usdc
Warning: in AppendChild at line 607 of /usr/local/src/USD-18.09/pxr/usd/lib/sdf/path.cpp -- Invalid prim name '028'
Traceback (most recent call last):
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 835, in <module>
    convert_to_usd(os.path.expanduser(args.gltf_file), os.path.abspath(os.path.expanduser(args.usd_file)), args.fps, args.scale, args.arkit, args.verbose, args.use_euler_rotation, args.optimize_textures, args.generate_texture_transform_texture)
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 779, in convert_to_usd
    usd = GLTF2USD(gltf_file=gltf_file, usd_file=usd_file, fps=fps, scale=scale, verbose=verbose, use_euler_rotation=use_euler_rotation, optimize_textures=optimize_textures, generate_texture_transform_texture=generate_texture_transform_texture)
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 74, in __init__
    self.convert()
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 749, in convert
    self._convert_materials_to_preview_surface_new()
  File "/usr/local/gltf2usd/Source/gltf2usd.py", line 459, in _convert_materials_to_preview_surface_new
    usd_material.convert_material_to_usd_preview_surface(material, self.output_dir)
  File "/usr/local/gltf2usd/Source/_gltf2usd/usd_material.py", line 21, in convert_material_to_usd_preview_surface
    usd_preview_surface = USDPreviewSurface(self._stage, gltf_material, self, output_directory)
  File "/usr/local/gltf2usd/Source/_gltf2usd/usd_material.py", line 38, in __init__
    material = UsdShade.Shader.Define(self._stage, material_path.AppendChild(gltf_material.get_name()))
pxr.Tf.ErrorException: 
    Error in 'pxrInternal_v0_18__pxrReserved__::UsdStage::_IsValidPathForCreatingPrim' at line 3096 in file /usr/local/src/USD-18.09/pxr/usd/lib/usd/stage.cpp : 'Path must be an absolute path: <>'

It says Warning: in AppendChild at line 607 of /usr/local/src/USD-18.09/pxr/usd/lib/sdf/path.cpp -- Invalid prim name '028' and our material name is 028

Let me know if you have something for us to test.

kcoley commented 5 years ago

@sayduck-daniel I just merged an update with more special characters detected: https://github.com/kcoley/gltf2usd/pull/148