示例#1
0
        public void GenerateNormalsAndTangents()
        {
            if (_Primitives.Length == 0)
            {
                return;
            }

            var geometries = _Primitives.Select(item => item._Geometry);

            // we can only skip normals and tangents calculation if all the
            // primitives have them. If we get a case in wich some primitives
            // have normals and other not, we need to calculate the normals
            // for all of them because there's vertex adyacencies shared
            // between primitives.

            var hasNormals  = geometries.All(item => item.HasNormals);
            var hasTangents = geometries.All(item => item.HasTangents);

            if (!hasNormals)
            {
                VertexNormalsFactory.CalculateSmoothNormals(geometries);
            }
            if (!hasTangents)
            {
                VertexTangentsFactory.CalculateTangents(geometries);
            }

            var morphTargetsCount = _Primitives.Min(item => item.MorphTargetsCount);

            for (int i = 0; i < morphTargetsCount; ++i)
            {
                var targets = _Primitives.Select(item => item._MorphTargets[i]);

                hasNormals  = targets.All(item => item.HasNormals);
                hasTangents = targets.All(item => item.HasTangents);

                if (!hasNormals)
                {
                    VertexNormalsFactory.CalculateSmoothNormals(targets);
                }
                if (!hasTangents)
                {
                    VertexTangentsFactory.CalculateTangents(targets);
                }
            }
        }
示例#2
0
        internal void _WriteMesh(SRCMESH srcMesh)
        {
            if (_Device == null)
            {
                throw new InvalidOperationException();
            }

            var srcPrims = _GetValidPrimitives(srcMesh)
                           .ToDictionary(item => item, item => new MeshPrimitiveReader(item, item.Material?.DoubleSided ?? false));

            VertexNormalsFactory.CalculateSmoothNormals(srcPrims.Values.ToList());
            VertexTangentsFactory.CalculateTangents(srcPrims.Values.ToList());

            foreach (var srcPrim in srcPrims)
            {
                _CurrentMeshIndex = srcMesh.LogicalIndex;

                _WriteMeshPrimitive(srcPrim.Value, srcPrim.Key.Material);
            }
        }
示例#3
0
        public void GenerateNormalsAndTangents()
        {
            if (_Primitives.Length == 0)
            {
                return;
            }

            var geometries = _Primitives.Select(item => item._Geometry);

            VertexNormalsFactory.CalculateSmoothNormals(geometries);
            VertexTangentsFactory.CalculateTangents(geometries);

            var morphTargetsCount = _Primitives.Min(item => item.MorphTargetsCount);

            for (int i = 0; i < morphTargetsCount; ++i)
            {
                var targets = _Primitives.Select(item => item._MorphTargets[i]);
                VertexNormalsFactory.CalculateSmoothNormals(targets);
                VertexTangentsFactory.CalculateTangents(targets);
            }
        }