示例#1
0
        private static IEnumerable <Schema2.MeshPrimitive> GetValidPrimitives(Schema2.Mesh srcMesh)
        {
            foreach (var srcPrim in srcMesh.Primitives)
            {
                var ppp = srcPrim.GetVertexAccessor("POSITION");
                if (ppp.Count < 3)
                {
                    continue;
                }

                if (srcPrim.DrawPrimitiveType == Schema2.PrimitiveType.POINTS)
                {
                    continue;
                }
                if (srcPrim.DrawPrimitiveType == Schema2.PrimitiveType.LINES)
                {
                    continue;
                }
                if (srcPrim.DrawPrimitiveType == Schema2.PrimitiveType.LINE_LOOP)
                {
                    continue;
                }
                if (srcPrim.DrawPrimitiveType == Schema2.PrimitiveType.LINE_STRIP)
                {
                    continue;
                }

                yield return(srcPrim);
            }
        }
示例#2
0
        public ModelMesh CreateMesh(Schema2.Mesh srcMesh, int maxBones = 72)
        {
            if (_Device == null)
            {
                throw new InvalidOperationException();
            }

            var srcPrims = GetValidPrimitives(srcMesh).ToList();

            var dstMesh = new ModelMesh(_Device, Enumerable.Range(0, srcPrims.Count).Select(item => new ModelMeshPart()).ToList());

            dstMesh.Name           = srcMesh.Name;
            dstMesh.BoundingSphere = srcMesh.CreateBoundingSphere();

            var srcNormals = new MeshNormalsFallback(srcMesh);

            var idx = 0;

            foreach (var srcPrim in srcPrims)
            {
                CreateMeshPart(dstMesh.MeshParts[idx++], srcPrim, srcNormals, maxBones);
            }

            return(dstMesh);
        }
        public MeshNormalsFallback(Schema2.Mesh mesh)
        {
            foreach (var srcPrim in mesh.Primitives)
            {
                var accessor = srcPrim.GetVertexAccessor("POSITION");
                if (accessor == null)
                {
                    continue;
                }

                var positions = accessor.AsVector3Array();

                foreach (var srcTri in srcPrim.GetTriangleIndices())
                {
                    var a = positions[srcTri.A];
                    var b = positions[srcTri.B];
                    var c = positions[srcTri.C];
                    var d = XYZ.Cross(b - a, c - a);

                    AddWeightedNormal(a, d);
                    AddWeightedNormal(b, d);
                    AddWeightedNormal(c, d);
                }
            }
        }
示例#4
0
文件: Reports.cs 项目: rsfc/SharpGLTF
        internal MeshReport(Schema2.Mesh mesh)
        {
            Name = mesh.Name;

            _Primitives = mesh.Primitives
                          .Select(prim => new PrimitiveReport(prim))
                          .ToArray();

            this.SetFrom(_Primitives);
        }
示例#5
0
        public static BoundingSphere CreateBoundingSphere(this Schema2.Mesh mesh)
        {
            var points = mesh
                         .Primitives
                         .Select(item => item.GetVertexAccessor("POSITION"))
                         .Where(item => item != null)
                         .SelectMany(item => item.AsVector3Array())
                         .Select(item => item.ToXna());

            return(BoundingSphere.CreateFromPoints(points));
        }
示例#6
0
        public _MeshDecoder(Schema2.Mesh srcMesh, RuntimeOptions options)
        {
            Guard.NotNull(srcMesh, nameof(srcMesh));

            _Name   = srcMesh.Name;
            _Extras = RuntimeOptions.ConvertExtras(srcMesh, options);

            _LogicalIndex = srcMesh.LogicalIndex;

            _Primitives = srcMesh
                          .Primitives
                          .Select(item => new _MeshPrimitiveDecoder <TMaterial>(item))
                          .ToArray();
        }
示例#7
0
        public _MeshDecoder(Schema2.Mesh srcMesh)
        {
            Guard.NotNull(srcMesh, nameof(srcMesh));

            _Name = srcMesh.Name;

            _LogicalIndex = srcMesh.LogicalIndex;

            _Primitives = srcMesh
                          .Primitives
                          .Select(item => new _MeshPrimitiveDecoder <TMaterial>(item))
                          .ToArray();

            _Extras = srcMesh.Extras;
        }