kcoley / gltf2usd

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

Crash due to node name starting with number #61

Closed MrDChristop closed 5 years ago

MrDChristop commented 5 years ago

Hi I noticed that if the node xform names start with a number the exporter crashes inside usd with an illformed sdfPath. Warning: in _InitWithString at line 106 of c:\users\d_chr\downloads\usd-master\pxr\usd\lib\sdf\path.cpp -- Ill-formed SdfPath </root/00095036_LACK_N_cff_tbl_90x55_white001_1_0>: syntax error This is the section in the gltf file,notice the name of each xform. "nodes":[{"mesh":0,"translation":[-0.00169372559,0.0,0.00169372559],"rotation":[0.0,0.0,0.0,-1.0],"scale":[1.0,1.0,1.0],"name":"00095036-LACK_N_cff_tbl_90x55_white001:1"},{"mesh":1,"translation":[-0.00169372559,0.0,0.00169372559],"rotation":[0.0,0.0,0.0,-1.0],"scale":[1.0,1.0,1.0],"name":"00095036-LACK_N_cff_tbl_90x55_white001:2"},{"mesh":2,"translation":[-0.00169372559,0.0,0.00169372559],"rotation":[0.0,0.0,0.0,-1.0],"scale":[1.0,1.0,1.0],"name":"00095036-LACK_N_cff_tbl_90x55_white001:3"}]

The error manifests in gltf2usd.py in line 95. 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.get_name())))

Just by changing the xform name with starting a letter no error is thrown. This must be a limitation of the usd sdk it can not process xform node names that start with a number. For example this passes. note the character before the name. "nodes":[{"mesh":0,"translation":[-0.00169372559,0.0,0.00169372559],"rotation":[0.0,0.0,0.0,-1.0],"scale":[1.0,1.0,1.0],"name":"d00095036-LACK_N_cff_tbl_90x55_white001:1"},{"mesh":1,"translation":[-0.00169372559,0.0,0.00169372559],"rotation":[0.0,0.0,0.0,-1.0],"scale":[1.0,1.0,1.0],"name":"d00095036-LACK_N_cff_tbl_90x55_white001:2"},{"mesh":2,"translation":[-0.00169372559,0.0,0.00169372559],"rotation":[0.0,0.0,0.0,-1.0],"scale":[1.0,1.0,1.0],"name":"d00095036-LACK_N_cff_tbl_90x55_white001:3"}]

Thanks Dimi

sulydeni commented 5 years ago

I had the same issue and tried to make a substitution in the former commit - it worked for me back then but would not work with the current one. https://github.com/kcoley/gltf2usd/commit/396ea0b0d70cf83f0a5b2776c4eee0ab2fcd5ea8

MrDChristop commented 5 years ago

Hi i added a substitution code fix in gltf2usdUtils.py in convert_to_usd_friendly_nodename `` name = re.sub(r'.|\b \b|-\b|:|(|)|[ \t]|-', '', name) # replace '.',' ','-',':','/','\','(',')' and ':' with '_' if str(name[0]).isdigit(): name = "d"+name;

return re.sub('//', '/', name)


and it processed.
kcoley commented 5 years ago

Sorry, when merging my changes, it overwrote @sulydeni 's fix. I'll add it to gltf2usdUtils