/src/assimp/code/Common/CreateAnimMesh.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | --------------------------------------------------------------------------- |
3 | | Open Asset Import Library (assimp) |
4 | | --------------------------------------------------------------------------- |
5 | | |
6 | | Copyright (C) 2016 The Qt Company Ltd. |
7 | | Copyright (c) 2006-2025, assimp team |
8 | | |
9 | | All rights reserved. |
10 | | |
11 | | Redistribution and use of this software in source and binary forms, |
12 | | with or without modification, are permitted provided that the following |
13 | | conditions are met: |
14 | | |
15 | | * Redistributions of source code must retain the above |
16 | | copyright notice, this list of conditions and the |
17 | | following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above |
20 | | copyright notice, this list of conditions and the |
21 | | following disclaimer in the documentation and/or other |
22 | | materials provided with the distribution. |
23 | | |
24 | | * Neither the name of the assimp team, nor the names of its |
25 | | contributors may be used to endorse or promote products |
26 | | derived from this software without specific prior |
27 | | written permission of the assimp team. |
28 | | |
29 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
30 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
31 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
32 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
33 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
34 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
35 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
36 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
37 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
38 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
39 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
40 | | --------------------------------------------------------------------------- |
41 | | */ |
42 | | |
43 | | #include <assimp/CreateAnimMesh.h> |
44 | | |
45 | | namespace Assimp { |
46 | | |
47 | | aiAnimMesh *aiCreateAnimMesh(const aiMesh *mesh, bool needPositions, bool needNormals, bool needTangents, bool needColors, bool needTexCoords) |
48 | 0 | { |
49 | 0 | aiAnimMesh *animesh = new aiAnimMesh; |
50 | 0 | animesh->mNumVertices = mesh->mNumVertices; |
51 | 0 | if (needPositions && mesh->mVertices) { |
52 | 0 | animesh->mVertices = new aiVector3D[animesh->mNumVertices]; |
53 | 0 | std::memcpy(animesh->mVertices, mesh->mVertices, mesh->mNumVertices * sizeof(aiVector3D)); |
54 | 0 | } |
55 | 0 | if (needNormals && mesh->mNormals) { |
56 | 0 | animesh->mNormals = new aiVector3D[animesh->mNumVertices]; |
57 | 0 | std::memcpy(animesh->mNormals, mesh->mNormals, mesh->mNumVertices * sizeof(aiVector3D)); |
58 | 0 | } |
59 | 0 | if (needTangents && mesh->mTangents) { |
60 | 0 | animesh->mTangents = new aiVector3D[animesh->mNumVertices]; |
61 | 0 | std::memcpy(animesh->mTangents, mesh->mTangents, mesh->mNumVertices * sizeof(aiVector3D)); |
62 | 0 | } |
63 | 0 | if (needTangents && mesh->mBitangents) { |
64 | 0 | animesh->mBitangents = new aiVector3D[animesh->mNumVertices]; |
65 | 0 | std::memcpy(animesh->mBitangents, mesh->mBitangents, mesh->mNumVertices * sizeof(aiVector3D)); |
66 | 0 | } |
67 | |
|
68 | 0 | if (needColors) { |
69 | 0 | for (int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) { |
70 | 0 | if (mesh->mColors[i]) { |
71 | 0 | animesh->mColors[i] = new aiColor4D[animesh->mNumVertices]; |
72 | 0 | std::memcpy(animesh->mColors[i], mesh->mColors[i], mesh->mNumVertices * sizeof(aiColor4D)); |
73 | 0 | } else { |
74 | 0 | animesh->mColors[i] = nullptr; |
75 | 0 | } |
76 | 0 | } |
77 | 0 | } |
78 | |
|
79 | 0 | if (needTexCoords) { |
80 | 0 | for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { |
81 | 0 | if (mesh->mTextureCoords[i]) { |
82 | 0 | animesh->mTextureCoords[i] = new aiVector3D[animesh->mNumVertices]; |
83 | 0 | std::memcpy(animesh->mTextureCoords[i], mesh->mTextureCoords[i], mesh->mNumVertices * sizeof(aiVector3D)); |
84 | 0 | } else { |
85 | 0 | animesh->mTextureCoords[i] = nullptr; |
86 | 0 | } |
87 | 0 | } |
88 | 0 | } |
89 | 0 | return animesh; |
90 | 0 | } |
91 | | |
92 | | } // end of namespace Assimp |