Esempio n. 1
0
        //const int maxNameLength = 40;

        //static void AppendName(ref string name1, string name2)
        //{
        //	if (name1.Length < maxNameLength)
        //	{
        //		name1 = name1 + " + " + name2;
        //		if (name1.Length >= maxNameLength) //no more append
        //			name1 += " + ...";
        //	}
        //}

        //void MergeGeometriesByMaterials()
        //{
        //	int mergedCount = 0;
        //	for (int i = 0; i < Geometries.Count; i++)
        //	{
        //		MeshData g1 = Geometries[i];
        //		if(g1 == null)
        //			continue;
        //		for (int j = i + 1; j < Geometries.Count; j++)
        //		{
        //			MeshData g2 = Geometries[j];
        //			if (g2 != null && g1.MaterialIndex == g2.MaterialIndex && g1.VertexComponents == g2.VertexComponents && g1.PolygonSize == g2.PolygonSize)
        //			{
        //				var newVertices = new VertexInfo[g1.Vertices.Length + g2.Vertices.Length];
        //				g1.Vertices.CopyTo(newVertices, 0);
        //				g2.Vertices.CopyTo(newVertices, g1.Vertices.Length);
        //				g1.Vertices = newVertices;
        //				g1.ClearCache(); //No longer valid
        //				AppendName(ref g1.Name, g2.Name);
        //				//m1.NormalsSource remains from first
        //				Geometries[j] = null;
        //				mergedCount++;
        //			}
        //		}
        //	}

        //	int count = Geometries.Count - mergedCount;
        //	var res = new List<MeshData>(count);
        //	for (int i = 0; i < count; i++)
        //		if (Geometries[i] != null)
        //			res.Add(Geometries[i]);
        //	Geometries = res;
        //}


        static void FillBoneAssignments(MeshData data, Skeleton skeleton)
        {
            if (skeleton == null)
            {
                for (int i = 0; i < data.Vertices.Length; i++)
                {
                    data.Vertices[i].Vertex.BlendIndices = new Vector4I(-1, -1, -1, -1);
                }
            }
            data.VertexComponents |= StandardVertex.Components.BlendIndices | StandardVertex.Components.BlendWeights;
            Dictionary <int, BoneAssignment> boneAssignments = ProcessSkeleton.GetBoneAssignments(data.Mesh, skeleton);

            if (boneAssignments != null)
            {
                for (int i = 0; i < data.Vertices.Length; i++)
                {
                    ref VertexInfo v = ref data.Vertices[i];
                    if (boneAssignments.TryGetValue(v.ControlPointIndex, out BoneAssignment ba))
                    {
                        FbxMath.ConvertBoneAssignment(ref ba, out v.Vertex.BlendIndices, out v.Vertex.BlendWeights);
                    }
                    else
                    {
                        v.Vertex.BlendIndices = new Vector4I(-1, -1, -1, -1);
                    }
                }
            }
Esempio n. 2
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);
            }