eArmada8 / ed8pkg2gltf

Modding toolset for Trails of Cold Steel games
MIT License
9 stars 0 forks source link

Build failure on Edel #5

Closed SheLikesCloth closed 1 year ago

SheLikesCloth commented 1 year ago

Problem

build_collada.py failed when using Edel’s model from CS4.

Reproduce

Edel’s pkg file attached to ease in troubleshooting: C_CHR735.zip

Result

This is the information I got from running python build_collada.py from the terminal:

...
Reading submesh shadowmodel_09...
Adding materials...
Adding skeleton...
Traceback (most recent call last):
  File "...\build_collada.py", line 883, in <module>
    build_collada(models[i])
  File "...\build_collada.py", line 859, in build_collada
    skeleton = add_bone_info(metadata['heirarchy'])
  File "...\build_collada.py", line 339, in add_bone_info
    skeleton = calc_abs_matrix(child, skeleton)
  File "...\build_collada.py", line 295, in calc_abs_matrix
    skeleton = calc_abs_matrix(child, skeleton)
  File "...\build_collada.py", line 295, in calc_abs_matrix
    skeleton = calc_abs_matrix(child, skeleton)
  File "...\build_collada.py", line 295, in calc_abs_matrix
    skeleton = calc_abs_matrix(child, skeleton)
  File "...\build_collada.py", line 291, in calc_abs_matrix
    skeleton[node]['inv_matrix'] = numpy.linalg.inv(skeleton[node]['abs_matrix'])
  File "<__array_function__ internals>", line 200, in inv
  File "...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\linalg\linalg.py", line 538, in inv
    ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
  File "...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\linalg\linalg.py", line 89, in _raise_linalgerror_singular
    raise LinAlgError("Singular matrix")
numpy.linalg.LinAlgError: Singular matrix

File version:

2.2.0 (2023-05-01)

eArmada8 commented 1 year ago

There are two invalid matrices in Edel's skeleton, center_point and L_hand_point (line 4511 and 6155 in metadata.json, respectively). Both are [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]], which is mathematically invalid for a rotation matrix. If you correct them to [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], then the model should compile fine. Angelica's skeleton (CHR019) has the same issue.

I will not be "fixing" this as it is not a bug in my script. I have no idea why mathematically-invalid matrices are in the skeleton; I have to assume that someone at Falcom inputted them by hand because no software would have come up with them. I think it's best that errors due to hand-coded errors are fixed by hand, because any attempt I make at detecting these errors and fixing them in a robust manner would have unintended consequences that may be very difficult to track down. (In other words, if they are not fixed by hand, there may be crazy distortions in the model and you would not know why. After all, I cannot guarantee that the only errors will be mistyped identity matrices.)

eArmada8 commented 1 year ago

I posted a workaround, with this commit: https://github.com/eArmada8/ed8pkg2gltf/commit/190045ac91a1e5f182df70da3a4cefe813c358e6

The fix is included in v2.2.2

Tested working with both Edel and Angelica.