Exemple #1
0
        public static ModelData Load(Stream stream)
        {
            ModelData   modelData   = new ModelData();
            ColladaRoot colladaRoot = new 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;
                foreach (ColladaNode node in colladaRoot.Scene.VisualScene.Nodes)
                {
                    LoadNode(modelData, modelBoneData, node, Matrix.CreateScale(colladaRoot.Asset.Meter));
                }
            }
            else
            {
                foreach (ColladaNode node2 in colladaRoot.Scene.VisualScene.Nodes)
                {
                    LoadNode(modelData, null, node2, Matrix.CreateScale(colladaRoot.Asset.Meter));
                }
            }
            foreach (ModelBuffersData buffer in modelData.Buffers)
            {
                IndexVertices(buffer.VertexDeclaration.VertexStride, buffer.Vertices, out buffer.Vertices, out buffer.Indices);
            }
            return(modelData);
        }
Exemple #2
0
        public static ModelMeshData LoadGeometry(ModelData data, ModelBoneData parentBoneData, ColladaGeometry geometry)
        {
            ModelMeshData modelMeshData = new ModelMeshData();

            data.Meshes.Add(modelMeshData);
            modelMeshData.Name            = parentBoneData.Name;
            modelMeshData.ParentBoneIndex = data.Bones.IndexOf(parentBoneData);
            bool flag = false;

            foreach (ColladaPolygons polygon in geometry.Mesh.Polygons)
            {
                ModelMeshPartData modelMeshPartData = LoadPolygons(data, polygon);
                modelMeshData.MeshParts.Add(modelMeshPartData);
                modelMeshData.BoundingBox = (flag ? BoundingBox.Union(modelMeshData.BoundingBox, modelMeshPartData.BoundingBox) : modelMeshPartData.BoundingBox);
                flag = true;
            }
            return(modelMeshData);
        }
Exemple #3
0
        public static ModelBoneData LoadNode(ModelData data, ModelBoneData parentBoneData, 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 (ColladaNode node2 in node.Nodes)
            {
                LoadNode(data, modelBoneData, node2, Matrix.Identity);
            }
            foreach (ColladaGeometry geometry in node.Geometries)
            {
                LoadGeometry(data, modelBoneData, geometry);
            }
            return(modelBoneData);
        }