void PolygonToPolygonIndex(FbxObjectGeometryPolygonMap map) { if (MappingInformationType == MappingInformationType.ByPolygon) { Array = MeshOperator.PolygonToPolygonIndex(Array, ArrayElemNum, map); } }
public static T[] TriangleDivision <T>(T[] array, int num, FbxObjectGeometryPolygonMap map) { var triangle = new T[map.VertexNum * num]; var vertexCount = 0; var triangleCount = 0; foreach (var vertexNum in map.VertexNumArray) { var firstIndex = vertexCount; for (var i = 0; i < vertexNum - 2; i++) { var secondIndex = vertexCount + i + 1; var thirdIndex = vertexCount + i + 2; for (var e = 0; e < num; e++) { try { triangle[triangleCount * num + e] = array[firstIndex * num + e]; triangle[(triangleCount + 1) * num + e] = array[secondIndex * num + e]; triangle[(triangleCount + 2) * num + e] = array[thirdIndex * num + e]; } catch (Exception exception) { Console.WriteLine(exception); throw; } } triangleCount += 3; } vertexCount += vertexNum; } return(triangle); }
public FbxGeometry(FbxDocument fbxDocument, FbxNode node) { FbxDocument = fbxDocument; FbxDocument.ObjectCache.Add(this, Id); Id = new FbxObjectId { Id = (long)node.Properties[0] }; foreach (var child in node.Childs) { switch (child.Name) { case "Vertices": ObjectGeometryVertices = new FbxObjectGeometryVertices(child); break; case "PolygonVertexIndex": FbxObjectGeometryPolygonMap = new FbxObjectGeometryPolygonMap(child); ObjectGeometryPolygonVertexIndex = new FbxObjectGeometryPolygonVertexIndex(child, FbxObjectGeometryPolygonMap); break; case "LayerElementNormal": Normal = new FbxObjectGeometryLayerElementNormal(child, FbxObjectGeometryPolygonMap); break; case "LayerElementUV": UV = new FbxObjectGeometryLayerElementUv(child); break; case "LayerElementMaterial": MaterialIndex = new FbxObjectGeometryLayerElementMaterial(child); break; } } }
/// <summary> ///反転しているビットを戻す /// https://stackoverflow.com/questions/7736845/can-anyone-explain-the-fbx-format-for-me /// </summary> /// <param name="indexes"></param> /// <returns></returns> static void VertexIndexNegativeToPositive(int[] indexes, FbxObjectGeometryPolygonMap map) { int lastPolygonIndex = -1; foreach (var polygonNum in map.VertexNumArray) { lastPolygonIndex += polygonNum; indexes[lastPolygonIndex] = ~indexes[lastPolygonIndex]; } }
void TriangleDivision(FbxObjectGeometryPolygonMap map) { if (MappingInformationType == MappingInformationType.ByPolygon) { Array = MeshOperator.TriangleDivision(Array, ArrayElemNum, map); } else { if (ReferenceInformationType == ReferenceInformationType.IndexToDirect) { Index = MeshOperator.TriangleDivision(Index, 1, map); } else { Array = MeshOperator.TriangleDivision(Array, ArrayElemNum, map); } } }
public static T[] PolygonToPolygonIndex <T>(T[] array, int num, FbxObjectGeometryPolygonMap map) { var res = new T[map.VertexNum]; var resIndex = 0; var polygonIndex = 0; for (var i = 0; i < array.Length / num; i++) { for (var k = 0; k < map.VertexNumArray[polygonIndex]; k++) { for (var e = 0; e < num; e++) { res[resIndex * num + e] = array[i * num + e]; } resIndex++; } polygonIndex++; } return(res); }
public FbxObjectGeometryPolygonVertexIndex(FbxNode node, FbxObjectGeometryPolygonMap map) { Array = (int[])node.Properties[0]; VertexIndexNegativeToPositive(Array, map); }
public void ToTrainable(FbxObjectGeometryPolygonMap map) { Array = MeshOperator.TriangleDivision(Array, 1, map); }
public void ToTriangleVertex(FbxObjectGeometryPolygonMap map) { PolygonToPolygonIndex(map); TriangleDivision(map); IndexToVertex(); }
public FbxObjectGeometryLayerElementNormal(FbxNode node, FbxObjectGeometryPolygonMap map) : base(node, 3) { Array = node.GetChild("Normals").GetProperty <double[]>(0); }