vpenades / SharpGLTF

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

There is any way to apply trasnform matrix set model? #110

Closed learnerandtrainer closed 2 years ago

learnerandtrainer commented 2 years ago

Hi, I have a b3dm model that created by sharp gltf and one json file that cantains transform parameter for cesium to load my b3dm. whenI want to preview every think is okey. But I want to set my transform parameter into b3dm(glb) itself because cesium transform my other child geometries using root and childs parameters. I used model.ApplyBasisTransform function but it doesnt work. Is there any way to transform model by trasnform matrix? Here my example files 157146.zip

vpenades commented 2 years ago

Not sure which would be the solution, since b3dm is beyond the scope of SharpGLTF.

I suspect the problem lies in that b3dm uses the internal meshes of a glTF, but not the transforms, which are overriden by b3dm. If that's the case, changing the transforms of the nodes in the gltf (as ApplyBasisTransform does) will take no effect.

learnerandtrainer commented 2 years ago

Hi vpenades, do you have any idea about trasnform tringles by trasnform matrix before set them into gltf?

vpenades commented 2 years ago

I think the best approach is this:

You have to "transfer" the mesh resources from one glTF to another, applying a mesh transform in between.

there is a unit test that does something like that here

Essentially, you create a new SceneBuilder, and you add the meshes from the source glTF to the destination SceneBuilder, applying a transform matrix, Then, you can save the SceneBuilder as a glTF

learnerandtrainer commented 2 years ago

Hi vpenades, I cant combine them in a new one because they have different trasnform values. for this scenario I have to trasnform geometries by their transform parameter before save them as gltf. I dont know cesium how calculate geometries by transform at runtime. I asked them but didnt get answer yet. I suppose that it is a bit complex. But I find new solution to merge them without calculating geometries by transform. I took center point of 15 level for 15,17,18 levels. And then translated all levels by this center point . This helped identify a single conversion for all levels . After that I could add levels as upper level child and set trasnform to only root element. Thank you for answers