public static ModelData Load(Stream stream) { ModelData modelData = new ModelData(); Collada.ColladaRoot colladaRoot = new Collada.ColladaRoot(XElement.Load(stream)); if (colladaRoot.Scene.VisualScene.Nodes.Count > 1) { ModelBoneData modelBoneData = new ModelBoneData(); modelData.Bones.Add(modelBoneData); modelBoneData.ParentBoneIndex = -1; modelBoneData.Name = string.Empty; modelBoneData.Transform = Matrix.Identity; using (List <Collada.ColladaNode> .Enumerator enumerator = colladaRoot.Scene.VisualScene.Nodes.GetEnumerator()) { while (enumerator.MoveNext()) { Collada.ColladaNode node = enumerator.Current; Collada.LoadNode(modelData, modelBoneData, node, Matrix.CreateScale(colladaRoot.Asset.Meter)); } goto IL_104; } } foreach (Collada.ColladaNode node2 in colladaRoot.Scene.VisualScene.Nodes) { Collada.LoadNode(modelData, null, node2, Matrix.CreateScale(colladaRoot.Asset.Meter)); } IL_104: foreach (ModelBuffersData modelBuffersData in modelData.Buffers) { Collada.IndexVertices(modelBuffersData.VertexDeclaration.VertexStride, modelBuffersData.Vertices, out modelBuffersData.Vertices, out modelBuffersData.Indices); } return(modelData); }
private static ModelBoneData LoadNode(ModelData data, ModelBoneData parentBoneData, Collada.ColladaNode node, Matrix transform) { ModelBoneData modelBoneData = new ModelBoneData(); data.Bones.Add(modelBoneData); modelBoneData.ParentBoneIndex = ((parentBoneData != null) ? data.Bones.IndexOf(parentBoneData) : -1); modelBoneData.Name = node.Name; modelBoneData.Transform = node.Transform * transform; foreach (Collada.ColladaNode node2 in node.Nodes) { Collada.LoadNode(data, modelBoneData, node2, Matrix.Identity); } foreach (Collada.ColladaGeometry geometry in node.Geometries) { Collada.LoadGeometry(data, modelBoneData, geometry); } return(modelBoneData); }