| 704 | } |
| 705 | |
| 706 | bool ProcessMesh(ModelData& result, OpenFbxImporterData& data, const ofbx::Mesh* aMesh, MeshData& mesh, String& errorMsg, int partitionIndex) |
| 707 | { |
| 708 | PROFILE_CPU(); |
| 709 | mesh.Name = aMesh->name; |
| 710 | ZoneText(*mesh.Name, mesh.Name.Length()); |
| 711 | const ofbx::GeometryData& geometryData = aMesh->getGeometryData(); |
| 712 | const ofbx::GeometryPartition& partition = geometryData.getPartition(partitionIndex); |
| 713 | const int vertexCount = partition.triangles_count * 3; |
| 714 | const ofbx::Vec3Attributes& positions = geometryData.getPositions(); |
| 715 | const ofbx::Vec3Attributes& normals = geometryData.getNormals(); |
| 716 | const ofbx::Vec3Attributes& tangents = geometryData.getTangents(); |
| 717 | const ofbx::Vec4Attributes& colors = geometryData.getColors(); |
| 718 | const ofbx::Skin* skin = aMesh->getSkin(); |
| 719 | const ofbx::BlendShape* blendShape = aMesh->getBlendShape(); |
| 720 | OPEN_FBX_GET_CACHE_LIST(TriangulatedIndicesCache, triangulatedIndices, vertexCount); |
| 721 | |
| 722 | // Properties |
| 723 | const ofbx::Material* aMaterial = nullptr; |
| 724 | if (aMesh->getMaterialCount() > 0) |
| 725 | aMaterial = aMesh->getMaterial(partitionIndex); |
| 726 | mesh.MaterialSlotIndex = data.AddMaterial(result, aMaterial); |
| 727 | |
| 728 | // Vertex positions |
| 729 | mesh.Positions.Resize(vertexCount, false); |
| 730 | { |
| 731 | int numIndicesTotal = 0; |
| 732 | for (int i = 0; i < partition.polygon_count; i++) |
| 733 | { |
| 734 | int numIndices = Triangulate(data, geometryData, partition.polygons[i], &triangulatedIndices[numIndicesTotal]); |
| 735 | for (int j = numIndicesTotal; j < numIndicesTotal + numIndices; j++) |
| 736 | mesh.Positions.Get()[j] = ToFloat3(positions.get(triangulatedIndices[j])); |
| 737 | numIndicesTotal += numIndices; |
| 738 | } |
| 739 | ASSERT_LOW_LAYER(numIndicesTotal == vertexCount); |
| 740 | } |
| 741 | |
| 742 | // Indices (dummy index buffer) |
| 743 | mesh.Indices.Resize(vertexCount, false); |
| 744 | for (int i = 0; i < vertexCount; i++) |
| 745 | mesh.Indices.Get()[i] = i; |
| 746 | |
| 747 | // Texture coordinates |
| 748 | for (int32 channelIndex = 0; channelIndex < MODEL_MAX_UV && geometryData.getUVs(channelIndex).values; channelIndex++) |
| 749 | { |
| 750 | const ofbx::Vec2Attributes& uvs = geometryData.getUVs(channelIndex); |
| 751 | mesh.UVs.Resize(channelIndex + 1); |
| 752 | auto& channel = mesh.UVs[channelIndex]; |
| 753 | channel.Resize(vertexCount, false); |
| 754 | for (int i = 0; i < vertexCount; i++) |
| 755 | channel.Get()[i] = ToFloat2(uvs.get(triangulatedIndices[i])); |
| 756 | if (data.ConvertRH) |
| 757 | { |
| 758 | for (int v = 0; v < vertexCount; v++) |
| 759 | channel.Get()[v].Y = 1.0f - channel.Get()[v].Y; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // Normals |
no test coverage detected