private void CollectNodes(Node node, ModelData.Bone targetParent) { bool isModelNode = IsModelNode(node); if (!isModelNode) { return; } var parent = new ModelData.Bone { Index = model.Bones.Count, Name = node.Name, ParentIndex = targetParent == null ? -1 : targetParent.Index, Transform = ConvertMatrix(node.Transform), Children = new List <int>() }; if (targetParent != null && targetParent.Children != null) { targetParent.Children.Add(parent.Index); } // Associate created bones with local index skeletonNodes[node] = model.Bones.Count; model.Bones.Add(parent); // continue for all child nodes if (node.HasChildren) { foreach (var subNode in node.Children) { CollectNodes(subNode, parent); } } }
private void CollectNodes(Node node, ModelData.Bone targetParent) { bool isModelNode = IsModelNode(node); if (!isModelNode) { return; } var parent = new ModelData.Bone { Index = model.Bones.Count, Name = node.Name, ParentIndex = targetParent == null ? -1 : targetParent.Index, Transform = ConvertMatrix(node.Transform), Children = new List <int>() }; if (targetParent != null && targetParent.Children != null) { targetParent.Children.Add(parent.Index); } // Associate created bones with local index meshNodes[node] = model.Bones.Count; model.Bones.Add(parent); // if node has meshes, create a new scene object for it if (node.MeshCount > 0) { var mesh = new ModelData.Mesh { Name = parent.Name, ParentBoneIndex = parent.Index, MeshParts = new List <ModelData.MeshPart>() }; model.Meshes.Add(mesh); // Precalculate the number of vertices for bounding sphere calculation boundingPointCount = 0; for (int i = 0; i < node.MeshCount; i++) { var meshIndex = node.MeshIndices[i]; var meshPart = scene.Meshes[meshIndex]; boundingPointCount += meshPart.VertexCount; } // Reallocate the buffer if needed if (boundingPoints == null || boundingPoints.Length < boundingPointCount) { boundingPoints = new Vector3[boundingPointCount]; } currentBoundingPointIndex = 0; for (int i = 0; i < node.MeshCount; i++) { var meshIndex = node.MeshIndices[i]; var meshPart = Process(mesh, scene.Meshes[meshIndex]); var meshToPartList = registeredMeshParts[meshIndex]; if (meshToPartList == null) { meshToPartList = new List <ModelData.MeshPart>(); registeredMeshParts[meshIndex] = meshToPartList; } meshToPartList.Add(meshPart); mesh.MeshParts.Add(meshPart); } // Calculate the bounding sphere. BoundingSphere.FromPoints(boundingPoints, 0, boundingPointCount, out mesh.BoundingSphere); } // continue for all child nodes if (node.HasChildren) { foreach (var subNode in node.Children) { CollectNodes(subNode, parent); } } }
private void CollectNodes(Node node, ModelData.Bone targetParent) { bool isModelNode = IsModelNode(node); if (!isModelNode) { return; } var parent = new ModelData.Bone { Index = model.Bones.Count, Name = node.Name, ParentIndex = targetParent == null ? -1 : targetParent.Index, Transform = ConvertMatrix(node.Transform), Children = new List<int>() }; if (targetParent!= null && targetParent.Children != null) { targetParent.Children.Add(parent.Index); } // Associate created bones with local index meshNodes[node] = model.Bones.Count; model.Bones.Add(parent); // if node has meshes, create a new scene object for it if( node.MeshCount > 0) { var mesh = new ModelData.Mesh { Name = parent.Name, ParentBoneIndex = parent.Index, MeshParts = new List<ModelData.MeshPart>() }; model.Meshes.Add(mesh); // Precalculate the number of vertices for bounding sphere calculation boundingPointCount = 0; for (int i = 0; i < node.MeshCount; i++) { var meshIndex = node.MeshIndices[i]; var meshPart = scene.Meshes[meshIndex]; boundingPointCount += meshPart.VertexCount; } // Reallocate the buffer if needed if (boundingPoints == null || boundingPoints.Length < boundingPointCount) { boundingPoints = new Vector3[boundingPointCount]; } currentBoundingPointIndex = 0; for (int i = 0; i < node.MeshCount; i++) { var meshIndex = node.MeshIndices[i]; var meshPart = Process(mesh, scene.Meshes[meshIndex]); var meshToPartList = registeredMeshParts[meshIndex]; if (meshToPartList == null) { meshToPartList = new List<ModelData.MeshPart>(); registeredMeshParts[meshIndex] = meshToPartList; } meshToPartList.Add(meshPart); mesh.MeshParts.Add(meshPart); } // Calculate the bounding sphere. BoundingSphere.FromPoints(boundingPoints, 0, boundingPointCount, out mesh.BoundingSphere); } // continue for all child nodes if (node.HasChildren) { foreach (var subNode in node.Children) { CollectNodes(subNode, parent); } } }
private void CollectNodes(Node node, ModelData.Bone targetParent) { bool isModelNode = IsModelNode(node); if (!isModelNode) { return; } var parent = new ModelData.Bone { Index = model.Bones.Count, Name = node.Name, ParentIndex = targetParent == null ? -1 : targetParent.Index, Transform = ConvertMatrix(node.Transform), Children = new List<int>() }; if (targetParent != null && targetParent.Children != null) { targetParent.Children.Add(parent.Index); } // Associate created bones with local index skeletonNodes[node] = model.Bones.Count; model.Bones.Add(parent); // continue for all child nodes if (node.HasChildren) { foreach (var subNode in node.Children) { CollectNodes(subNode, parent); } } }