コード例 #1
0
        public void AppendMesh(IMeshDecoder <int> srcMesh)
        {
            var dstMesh = new MeshContent();

            dstMesh.Name = srcMesh.Name;
            dstMesh.Tag  = srcMesh.Tag;

            foreach (var prim in srcMesh.Primitives)
            {
                var vdecl = MeshPrimitiveDecoder.GetVertexDeclaration(prim);

                int vbIndex = _UseVertexBuffer(vdecl);
                int ibIndex = _UseIndexBuffer();

                var geometry = CreateGeometry(vbIndex, ibIndex, prim, vdecl);
                if (geometry == null)
                {
                    continue;
                }

                dstMesh.AddMeshPart(geometry, prim.Material);
            }

            _Meshes.Add(dstMesh);
        }
コード例 #2
0
        private MeshGeometryContent CreateGeometry(int vbIndex, int ibIndex, IMeshPrimitiveDecoder <int> primitive, VertexDeclaration vdecl)
        {
            var partVertices  = MeshPrimitiveDecoder.ToXnaVertices(primitive, vdecl);
            var partTriangles = primitive.TriangleIndices.ToList();

            if (partTriangles.Count == 0)
            {
                return(null);
            }

            var vRange = _VertexBuffers[vbIndex].AddVertices(partVertices, vdecl);
            var iRange = _IndexBuffers[ibIndex].AddTriangleIndices(partTriangles);

            var geometry = new MeshGeometryContent();

            geometry.SetVertices(vbIndex, vRange.VertexOffset, vRange.VertexCount);
            geometry.SetIndices(ibIndex, iRange.Offset, iRange.Count, partTriangles.Count);

            return(geometry);
        }