private void GetChildrenMeshes(ref Game3DObject parent, Node node) { if (node.HasChildren) { var objects = new List <Game3DObject>(); foreach (var child in node.Children) { node.Transform.Decompose(out Vector3D _, out Assimp.Quaternion rotation, out Vector3D position); var newChildObject = new Game3DObject(new Vector3(position.X, position.Y, position.Z), ToEulerAngles(rotation)); newChildObject.AddMeshObject(meshList.Find(x => x.Name == child.Name)); objects.Add(newChildObject); GetChildrenMeshes(ref newChildObject, child); } parent.Children.AddRange(objects); } }
public Game3DObject LoadGameObjectFromFile(string path, Vector3 startPosition, Vector3 startRotation, string texture = null) { var importer = new AssimpContext(); importer.SetConfig(new NormalSmoothingAngleConfig(66.0f)); var fileScene = importer.ImportFile(path, PostProcessSteps.Triangulate); var indices = new List <uint>(); var vertices = new List <Renderer.VertexDataStruct>(); var root = fileScene.RootNode; Game3DObject gameObject = null; meshList = new List <MeshObject>(); materials = new List <Graphics.Material>(); textures = new List <Texture>(); ExtractTextures(fileScene); ExtractMaterials(fileScene, texture); ExtractMeshes(fileScene, indices, vertices); gameObject = new Game3DObject(startPosition, startRotation); if (root.HasChildren) { foreach (var child in root.Children) { if (child.HasMeshes) { child.Transform.Decompose(out Vector3D _, out Assimp.Quaternion rotation, out Vector3D position); var childObject = gameObject.AddChild(new Game3DObject(new Vector3(position.X, position.Y, position.Z), ToEulerAngles(rotation))); childObject.AddMeshObject(meshList[child.MeshIndices[0]]); GetChildrenMeshes(ref childObject, child); } } } else { gameObject.AddMeshObject(meshList[root.MeshIndices[0]]); } return(gameObject); }