public static MeshData[] ProcMesh(FbxManager manager, FbxNode node, FbxMesh mesh, ImportOptions importOptions, Matrix4 additionalTransform) { var transform = additionalTransform * FbxMath.EvaluateGlobalTransform(node).ToMatrix4(); transform = transform * FbxMath.GetGeometryOffset(node).ToMatrix4(); var converter = new FbxGeometryConverter(manager); bool success = false; try { mesh = FbxMesh.Cast(converter.Triangulate(mesh, false)); //ToDo :? Может true? Чтобы не создавать второй mesh в Attribute success = true; } catch (Exception ex) { FbxImportLog.LogError(node, "Inside Triangulate error: " + ex); } if (!success || mesh == null) { return(null); } MeshData data = ReadTriangles(mesh, node); var ret = ReadMaterialsAndSplitByMaterials(data); foreach (var m in ret) { ReadMeshElements(m, importOptions, ref transform); } return(ret); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FbxGeometryConverter obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
protected override FbxMesh GenerateFbx() { string meshName = (Souls.meshRoot != null ? Souls.meshRoot.Name : "") + "_Mesh"; FbxMesh mesh = FbxMesh.Create(Scene, meshName); mesh.InitControlPoints(Souls.mesh.Vertices.Count); int layerIndex = mesh.CreateLayer(); FbxLayer layer = mesh.GetLayer(layerIndex); FbxLayerContainer layerContainer = FbxLayerContainer.Create(Scene, meshName + "_LayerContainer"); FbxLayerElementUV uv = FbxLayerElementUV.Create(layerContainer, "Diffuse"); layer.SetUVs(uv); FbxLayerElementNormal normal = FbxLayerElementNormal.Create(layerContainer, "Normal"); layer.SetNormals(normal); normal.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); normal.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); FbxLayerElementBinormal binormal = FbxLayerElementBinormal.Create(layerContainer, "Binormal"); layer.SetBinormals(binormal); FbxLayerElementTangent tangent = FbxLayerElementTangent.Create(layerContainer, "Tangent"); layer.SetTangents(tangent); tangent.SetReferenceMode(FbxLayerElement.EReferenceMode.eDirect); tangent.SetMappingMode(FbxLayerElement.EMappingMode.eByControlPoint); for (int vertexIndex = 0; vertexIndex < Souls.mesh.Vertices.Count; ++vertexIndex) { FLVER.Vertex vertex = Souls.mesh.Vertices[vertexIndex]; Vector3 position = vertex.Position; // this fixes vertex positions since otherwise the model is turned inside out // and it appears like it holds weapons in the left hand position.Z = -position.Z; normal.GetDirectArray().Add(vertex.Normal.ToFbxVector4()); tangent.GetDirectArray().Add(new FbxVector4(vertex.Tangents[0].X, vertex.Tangents[0].Y, vertex.Tangents[0].Z)); Vector2 uvValue = new Vector2(0); if (vertex.UVs.Count > 0) { uvValue.X = vertex.UVs[0].X; uvValue.Y = vertex.UVs[0].Y; } uv.GetDirectArray().Add(uvValue.ToFbxVector2()); mesh.SetControlPointAt(position.ToFbxVector4(), vertexIndex); } for (int faceSetIndex = 0; faceSetIndex < Souls.mesh.FaceSets.Count; ++faceSetIndex) { FLVER2.FaceSet faceSet = Souls.mesh.FaceSets[faceSetIndex]; if (faceSet.Flags != FLVER2.FaceSet.FSFlags.None) { continue; } for (int faceStartIndex = 0; faceStartIndex < faceSet.Indices.Count; faceStartIndex += 3) { mesh.AddCompletePolygon( faceSet.Indices[faceStartIndex], faceSet.Indices[faceStartIndex + 1], faceSet.Indices[faceStartIndex + 2] ); //mesh.AddCompletePolygon( // faceSet.Indices[faceStartIndex + 2], // faceSet.Indices[faceStartIndex + 1], // faceSet.Indices[faceStartIndex] //); } } mesh.BuildMeshEdgeArray(); FbxGeometryConverter converter = new FbxGeometryConverter(Scene.GetFbxManager()); converter.ComputeEdgeSmoothingFromNormals(mesh); converter.ComputePolygonSmoothingFromEdgeSmoothing(mesh); return(mesh); }