Exemple #1
0
        protected override MeshInfo Read(ContentReader input, MeshInfo existingInstance)
        {
            List <TrackModelProcessor.MeshInfo.Triangle> triangles = new List <MeshInfo.Triangle>();

            int num = input.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                Vector3 p0 = input.ReadObject <Vector3>();
                Vector3 p1 = input.ReadObject <Vector3>();
                Vector3 p2 = input.ReadObject <Vector3>();

                TrackModelProcessor.MeshInfo.Triangle triangle = new MeshInfo.Triangle(p0, p1, p2);
                triangles.Add(triangle);
            }

            BoundingBox box  = input.ReadObject <BoundingBox>();
            MeshInfo    info = new MeshInfo(triangles, box);

            return(info);
        }
Exemple #2
0
        private void ProcessChildren(NodeContent node)
        {
            float minX = float.MaxValue;
            float minY = float.MaxValue;
            float minZ = float.MaxValue;

            float maxX = float.MinValue;
            float maxY = float.MinValue;
            float maxZ = float.MinValue;

            MeshContent mesh = node as MeshContent;

            foreach (NodeContent child in node.Children)
            {
                ProcessChildren(child);
            }

            if (mesh != null)
            {
                foreach (Vector3 vertex in mesh.Positions)
                {
                    if (vertex.Z < minZ)
                    {
                        minZ = vertex.Z;
                    }
                    if (vertex.X < minX)
                    {
                        minX = vertex.X;
                    }
                    if (vertex.Y < minY)
                    {
                        minY = vertex.Y;
                    }

                    if (vertex.Z > maxZ)
                    {
                        maxZ = vertex.Z;
                    }
                    if (vertex.X > maxX)
                    {
                        maxX = vertex.X;
                    }
                    if (vertex.Y > maxY)
                    {
                        maxY = vertex.Y;
                    }
                }

                Matrix absoluteTransformation         = mesh.AbsoluteTransform;
                List <MeshInfo.Triangle> triangleList = new List <MeshInfo.Triangle>();

                foreach (GeometryContent geo in mesh.Geometry)
                {
                    int triangles = geo.Indices.Count / 3;

                    for (int currentTriangle = 0; currentTriangle < triangles; currentTriangle++)
                    {
                        int[] indexes = new int[3];

                        for (int i = 0; i < 3; i++)
                        {
                            indexes[i] = geo.Indices[currentTriangle * 3 + i];
                        }

                        Vector3[] vertices            = new Vector3[3];
                        Vector3[] transformedVertices = new Vector3[3];

                        for (int i = 0; i < 3; i++)
                        {
                            vertices[i]            = geo.Vertices.Positions[indexes[i]];
                            transformedVertices[i] = Vector3.Transform(vertices[i], absoluteTransformation);
                        }

                        MeshInfo.Triangle triangle = new MeshInfo.Triangle(transformedVertices[0], transformedVertices[1], transformedVertices[2]);
                        triangleList.Add(triangle);
                    }
                }

                BoundingBox box  = new BoundingBox(new Vector3(minX, minY, minZ), new Vector3(maxX, maxY, maxZ));
                MeshInfo    info = new MeshInfo(triangleList, box);

                information.Add(info);
            }
        }