// Compute per-face normals but store them per-vertex
        static void CalculateNormalForFace(VertexInfo[] vertices, RangeI indexRange, bool normalize)
        {
            if (indexRange.Size < 3)
            {
                for (int i = indexRange.Minimum; i < indexRange.Maximum; i++)
                {
                    vertices[i].Vertex.Normal = new Vector3F(Single.NaN, Single.NaN, Single.NaN);
                }
                FbxImportLog.LogWarning("To calculate the tangents a polygon must have > 2 vertices");
            }

            ref Vector3F p0     = ref vertices[indexRange.Minimum].Vertex.Position;
        static void CalculateTangentForFace(VertexInfo[] vertices, RangeI indexRange, Vector3F[] tangents, Vector3F[] bitangents, GetTextureCoord getTextureCoord = null)
        {
            // triangle or polygon... we always use only the first three indices. A polygon
            // is supposed to be planar anyways....

            if (indexRange.Size < 3)
            {
                for (int i = indexRange.Minimum; i < indexRange.Maximum; i++)
                {
                    tangents[i]   = new Vector3F(float.NaN, float.NaN, float.NaN);
                    bitangents[i] = new Vector3F(float.NaN, float.NaN, float.NaN);
                }
                FbxImportLog.LogWarning("To calculate the tangents a polygon must have > 2 vertices");
                return;
            }

            ref StandardVertex pt0 = ref vertices[indexRange.Minimum].Vertex;
Esempio n. 3
0
        static void ReadColor(MeshData data)
        {
            FbxLayerElementVertexColor pVertexColors = data.Mesh.GetElementVertexColor();

            if (pVertexColors == null)
            {
                for (int i = 0; i < data.Vertices.Length; i++)
                {
                    data.Vertices[i].Vertex.Color = new ColorValue(1, 1, 1);
                }
                return;
            }

            var mappingMode = pVertexColors.GetMappingMode();

            if (!CheckPolygonVertexOrControlPoint(mappingMode))
            {
                FbxImportLog.LogWarning(data.Node, $"has unsupported VertexColors mapping mode: {pVertexColors.GetMappingMode()}");
                return;
            }
            data.VertexComponents |= StandardVertex.Components.Color;
            var indexArray  = pVertexColors.GetReferenceMode() != FbxLayerElement.EReferenceMode.eDirect ? pVertexColors.GetIndexArray() : null;
            var directArray = pVertexColors.GetDirectArray();

            for (int i = 0; i < data.Vertices.Length; i++)
            {
                ref VertexInfo vertex = ref data.Vertices[i];
                FbxColor       color  = null;
                switch (pVertexColors.GetMappingMode())
                {
                case FbxLayerElement.EMappingMode.eByPolygonVertex:
                    color = directArray.GetAt(indexArray?.GetAt(vertex.PolygonVertexIndex) ?? vertex.PolygonVertexIndex);
                    break;

                case FbxLayerElement.EMappingMode.eByControlPoint:
                    color = directArray.GetAt(indexArray?.GetAt(vertex.ControlPointIndex) ?? vertex.ControlPointIndex);
                    break;
                }
                data.Vertices[i].Vertex.Color = color?.ToColorValue() ?? new ColorValue(1, 1, 1);
            }