Exemple #1
0
 internal ModelBoneContent(string name, int index, Matrix4x4 transform, ModelBoneContent parent)
 {
     Name      = name;
     Index     = index;
     Transform = transform;
     Parent    = parent;
 }
        private ModelBoneContent ProcessNode(
            NodeContent node,
            ModelBoneContent parent,
            List <ModelBoneContent> boneList,
            List <ModelMeshContent> meshList,
            ContentProcessorContext context)
        {
            var result = new ModelBoneContent(node.Name, boneList.Count, node.Transform, parent);

            boneList.Add(result);

            if (node is MeshContent)
            {
                meshList.Add(ProcessMesh(node as MeshContent, result, context));
            }

            var children = new List <ModelBoneContent>();

            foreach (var child in node.Children)
            {
                children.Add(ProcessNode(child, result, boneList, meshList, context));
            }
            result.Children = new ModelBoneContentCollection(children);

            return(result);
        }
 internal ModelMeshContent(string name, MeshContent sourceMesh, ModelBoneContent parentBone,
                           BoundingSphere boundingSphere, IList <ModelMeshPartContent> meshParts)
 {
     Name           = name;
     _sourceMesh    = sourceMesh;
     ParentBone     = parentBone;
     BoundingSphere = boundingSphere;
     MeshParts      = new ModelMeshPartContentCollection(meshParts);
 }
Exemple #4
0
 internal ModelContent(ModelBoneContent root, IList <ModelBoneContent> bones, IList <ModelMeshContent> meshes)
 {
     _root  = root;
     Bones  = new ModelBoneContentCollection(bones);
     Meshes = new ModelMeshContentCollection(meshes);
 }
        private ModelMeshContent ProcessMesh(
            MeshContent mesh, ModelBoneContent parent, ContentProcessorContext context)
        {
            var parts        = new List <ModelMeshPartContent>();
            var vertexBuffer = new VertexBufferContent();
            var indexBuffer  = new IndexCollection();

            if (GenerateTangentFrames)
            {
                context.Logger.LogMessage("Generating tangent frames.");
                foreach (GeometryContent geom in mesh.Geometry)
                {
                    if (!geom.Vertices.Channels.Contains(VertexChannelNames.Normal(0)))
                    {
                        MeshHelper.CalculateNormals(geom, true);
                    }

                    if (!geom.Vertices.Channels.Contains(VertexChannelNames.Tangent(0)) ||
                        !geom.Vertices.Channels.Contains(VertexChannelNames.Binormal(0)))
                    {
                        MeshHelper.CalculateTangentFrames(
                            geom,
                            VertexChannelNames.TextureCoordinate(0),
                            VertexChannelNames.Tangent(0),
                            VertexChannelNames.Binormal(0));
                    }
                }
            }

            var startVertex = 0;

            foreach (var geometry in mesh.Geometry)
            {
                var vertices    = geometry.Vertices;
                var vertexCount = vertices.VertexCount;
                ModelMeshPartContent partContent;
                if (vertexCount == 0)
                {
                    partContent = new ModelMeshPartContent();
                }
                else
                {
                    var geomBuffer = geometry.Vertices.CreateVertexBuffer();
                    vertexBuffer.Write(vertexBuffer.VertexData.Length, 1, geomBuffer.VertexData);

                    var startIndex = indexBuffer.Count;
                    indexBuffer.AddRange(geometry.Indices);

                    partContent = new ModelMeshPartContent(
                        vertexBuffer, indexBuffer,
                        startVertex, vertexCount, startIndex, geometry.Indices.Count / 3);

                    // Geoms are supposed to all have the same decl, so just steal one of these
                    vertexBuffer.VertexDeclaration = geomBuffer.VertexDeclaration;

                    startVertex += vertexCount;
                }

                partContent.Material = geometry.Material;
                parts.Add(partContent);
            }

            var bounds = new BoundingSphere();

            if (mesh.Positions.Count > 0)
            {
                bounds = BoundingSphere.CreateFromPoints(mesh.Positions);
            }

            return(new ModelMeshContent(mesh.Name, mesh, parent, bounds, parts));
        }