/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include namespace AZ { namespace FbxSDKWrapper { TestFbxMesh::TestFbxMesh() : m_vertexControlPoints(nullptr) , m_vertexCount(0) , m_polygonVertexIndices(nullptr) , m_materialIndices(new FbxLayerElementArrayTemplate(eFbxInt)) , m_uvElements(FbxGeometryElementUV::Create(nullptr, "TestElements_UV")) , m_vertexColorElements(FbxGeometryElementVertexColor::Create(nullptr, "TestElements_VertexColors")) , m_expectedVertexCount(0) { } int TestFbxMesh::GetDeformerCount() const { // For current test need, only have one skin for the mesh return m_skin ? 1 : 0; } AZStd::shared_ptr TestFbxMesh::GetSkin(int index) const { // For current test need, only have one skin for the mesh return m_skin; } bool TestFbxMesh::GetMaterialIndices(FbxLayerElementArrayTemplate** lockableArray) const { *lockableArray = m_materialIndices; return true; } int TestFbxMesh::GetControlPointsCount() const { return static_cast(m_vertexCount); } AZStd::vector TestFbxMesh::GetControlPoints() const { return m_vertexControlPoints; } int TestFbxMesh::GetPolygonCount() const { return static_cast(m_polygonInfo.size()); } int TestFbxMesh::GetPolygonSize(int polygonIndex) const { if (m_polygonInfo.find(polygonIndex) != m_polygonInfo.end()) { return aznumeric_caster(m_polygonInfo.find(polygonIndex)->second.m_vertexCount); } return -1; } int* TestFbxMesh::GetPolygonVertices() const { return m_polygonVertexIndices; } int TestFbxMesh::GetPolygonVertexIndex(int polygonIndex) const { if (m_polygonInfo.find(polygonIndex) != m_polygonInfo.end()) { return aznumeric_caster(m_polygonInfo.find(polygonIndex)->second.m_startVertexIndex); } return -1; } FbxUVWrapper TestFbxMesh::GetElementUV(int index) { (void)index; return m_uvElements; } int TestFbxMesh::GetElementUVCount() const { return 1; } FbxVertexColorWrapper TestFbxMesh::GetElementVertexColor(int index) { (void)index; return m_vertexColorElements; } int TestFbxMesh::GetElementVertexColorCount() const { return 1; } bool TestFbxMesh::GetPolygonVertexNormal(int polyIndex, int vertexIndex, Vector3& normal) const { normal = Vector3(1.0f, 0.0f, 0.0f); return true; } void TestFbxMesh::CreateMesh(std::vector& points, std::vector >& polygonVertexIndices) { m_vertexControlPoints.clear(); m_materialIndices->Clear(); m_polygonInfo.clear(); // Create fbx control point (position) data, and associated material index data m_vertexCount = aznumeric_caster(points.size()); m_vertexControlPoints.reserve(points.size()); for (unsigned int i = 0; i < points.size(); ++i) { m_vertexControlPoints.push_back(Vector3(points[i].GetX(), points[i].GetY(), points[i].GetZ())); m_materialIndices->Add(i); } // Create fbx face data m_expectedVertexCount = 0; for (const std::vector& onePolygonIndices : polygonVertexIndices) { for (const int& index : onePolygonIndices) { m_expectedVertexCount++; } } if (m_polygonVertexIndices) { delete m_polygonVertexIndices; } m_polygonVertexIndices = new int[m_expectedVertexCount]; size_t i = 0; for (const std::vector& onePolygonIndices : polygonVertexIndices) { m_polygonInfo.insert(std::make_pair(aznumeric_caster(m_polygonInfo.size()), TestFbxPolygon(i, aznumeric_caster(onePolygonIndices.size())))); for (const int& index : onePolygonIndices) { m_polygonVertexIndices[i] = index; i++; } } } void TestFbxMesh::SetSkin(const AZStd::shared_ptr& skin) { m_skin = skin; } void TestFbxMesh::CreateExpectMeshInfo(std::vector >& expectedFaceVertexIndices) { m_expectedFaceVertexIndices = expectedFaceVertexIndices; } size_t TestFbxMesh::GetExpectedVetexCount() const { return m_expectedVertexCount; } size_t TestFbxMesh::GetExpectedFaceCount() const { return m_expectedFaceVertexIndices.size(); } AZ::Vector3 TestFbxMesh::GetExpectedFaceVertexPosition(unsigned int faceIndex, unsigned int vertexIndex) const { return m_vertexControlPoints[m_expectedFaceVertexIndices[faceIndex][vertexIndex]]; } } }