vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
454 stars 72 forks source link

Reading meshes #152

Closed gotoarchi closed 1 year ago

gotoarchi commented 1 year ago

Saludos Vicente

Thanks for your great library.

We are reading a GLTF trying to find the final (global?) coordinates of the positon vertices. We looping the nodes->meshes and came across the Local Transform object and matrix. Is there any example that shows any methods that help transforming the vertices across their absolute final location. I understand that being a child you inherit transformations, but I am stuck in the transformation process.

Any example or documentation would be highly appreciated.

bertt commented 1 year ago

Hi maybe Toolkit .EvaluateTriangles is what you are looking for.

gotoarchi commented 1 year ago

I am afraid I need a very simple example to understand the implementation of the TRS transformation to the final coordinate.

vpenades commented 1 year ago

Every node also has a world matrix.

You just need to multiply the vertices of the mesh by the world matrix of the node containing the mesh.

gotoarchi commented 1 year ago

Thank you. I understand that each vertex gets the multiplication by the 3 transformation columns, and then added the translation vector from the World matrix. For the x coordinate: globalx=(x M11)+(x M21)+(x * M31)+M41

vpenades commented 1 year ago

vector x matrix multiplication is handled by the System.Numerics types, if you're new to them I would suggest you to learn about their types, because they're widely used along all the library. There's plenty of documentation and examples about vector3 and matrix4x4 around.

gotoarchi commented 1 year ago

Thank you. That helped. The following worked:

System.Numerics.Vector3 resultvector = System.Numerics.Vector3.Transform((System.Numerics.Vector3)(lstpoints[tx8]), nodem.WorldMatrix);