vpenades / SharpGLTF

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

How can get MeshContent from gltf file? #95

Closed learnerandtrainer closed 3 years ago

learnerandtrainer commented 3 years ago

Hi , I have too many files created with SharpGLTF libraray. But some times I have to open them and read MeshContent. But when I want to cast to SharpGLTF.Scenes.MeshContent , the message says me its protected. there is any way to get content (geometries) of mesh my code like below

string glbFile = fileUrl.Substring(0, fileUrl.LastIndexOf(".")) + ".glb";
  System.IO.File.WriteAllBytes(glbFile, b3dm.GlbData);
  var scene = SceneBuilder.Load(glbFile);
  var meshContent = ((SharpGLTF.Scenes.MeshContent)(scene.Instances[0]).Content.Content).Mesh;
vpenades commented 3 years ago

If you want to access the MeshBuilder, you don't need to cast MeshContent, you can get the mesh directly:

string glbFile = fileUrl.Substring(0, fileUrl.LastIndexOf(".")) + ".glb";
  System.IO.File.WriteAllBytes(glbFile, b3dm.GlbData);
  var scene = SceneBuilder.Load(glbFile);
  var mesh = scene.Instances[0].Content.GetGeometryAsset();

If what you need is to access to the MeshContent itself, let me know why you need it so I can figure out a solution

learnerandtrainer commented 3 years ago

thank you vpenades. I will try it

learnerandtrainer commented 3 years ago

thanks it worked