예제 #1
0
        public static IEnumerable <GroupNode> LoadMapMGEO(MGEOFile mgeo, MapData mapData, string mapPath)
        {
            foreach (MGEOObject mgeoModel in mgeo.Objects)
            {
                IntCollection     indices  = new IntCollection(mgeoModel.Indices.Select(x => (int)x).AsEnumerable());
                Vector3Collection vertices = new Vector3Collection(mgeoModel.Vertices.Count);
                Vector2Collection uvs      = new Vector2Collection(mgeoModel.Vertices.Count);
                foreach (MGEOVertex vertex in mgeoModel.Vertices)
                {
                    vertices.Add(new dxVector3(vertex.Position.X, vertex.Position.Y, vertex.Position.Z));
                    uvs.Add(new dxVector2(vertex.DiffuseUV.X, vertex.DiffuseUV.Y));
                }

                foreach (MGEOSubmesh submesh in mgeoModel.Submeshes)
                {
                    GroupNode groupNode = new GroupNode()
                    {
                        Name = mgeoModel.Name
                    };

                    MeshGeometry3D submeshGeometry3D = new MeshGeometry3D()
                    {
                        Indices            = indices.GetRange((int)submesh.StartIndex, (int)submesh.IndexCount) as IntCollection,
                        Positions          = vertices,
                        TextureCoordinates = uvs
                    };

                    DiffuseMaterial diffuseMaterial = new DiffuseMaterial()
                    {
                        Name        = submesh.Material,
                        DiffuseMap  = CreateMaterial(submesh.Material, mapData, mapPath),
                        EnableUnLit = true
                    };

                    groupNode.AddChildNode(new MeshNode()
                    {
                        Name     = mgeoModel.Name + "|" + submesh.Material,
                        Geometry = submeshGeometry3D,
                        Material = diffuseMaterial
                    });

                    yield return(groupNode);
                }
            }
        }