1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (C) 2016 The Qt Company Ltd.
7 Copyright (c) 2006-2012, 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 "CreateAnimMesh.h"
44 
45 namespace Assimp    {
46 
aiCreateAnimMesh(const aiMesh * mesh)47 aiAnimMesh *aiCreateAnimMesh(const aiMesh *mesh)
48 {
49     aiAnimMesh *animesh = new aiAnimMesh;
50     animesh->mVertices = NULL;
51     animesh->mNormals = NULL;
52     animesh->mTangents = NULL;
53     animesh->mBitangents = NULL;
54     animesh->mNumVertices = mesh->mNumVertices;
55     if (mesh->mVertices) {
56         animesh->mVertices = new aiVector3D[animesh->mNumVertices];
57         std::memcpy(animesh->mVertices, mesh->mVertices, mesh->mNumVertices * sizeof(aiVector3D));
58     }
59     if (mesh->mNormals) {
60         animesh->mNormals = new aiVector3D[animesh->mNumVertices];
61         std::memcpy(animesh->mNormals, mesh->mNormals, mesh->mNumVertices * sizeof(aiVector3D));
62     }
63     if (mesh->mTangents) {
64         animesh->mTangents = new aiVector3D[animesh->mNumVertices];
65         std::memcpy(animesh->mTangents, mesh->mTangents, mesh->mNumVertices * sizeof(aiVector3D));
66     }
67     if (mesh->mBitangents) {
68         animesh->mBitangents = new aiVector3D[animesh->mNumVertices];
69         std::memcpy(animesh->mBitangents, mesh->mBitangents, mesh->mNumVertices * sizeof(aiVector3D));
70     }
71 
72     for (int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
73         if (mesh->mColors[i]) {
74             animesh->mColors[i] = new aiColor4D[animesh->mNumVertices];
75             std::memcpy(animesh->mColors[i], mesh->mColors[i], mesh->mNumVertices * sizeof(aiColor4D));
76         } else {
77             animesh->mColors[i] = NULL;
78         }
79     }
80 
81     for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
82         if (mesh->mTextureCoords[i]) {
83             animesh->mTextureCoords[i] = new aiVector3D[animesh->mNumVertices];
84             std::memcpy(animesh->mTextureCoords[i], mesh->mTextureCoords[i], mesh->mNumVertices * sizeof(aiVector3D));
85         } else {
86             animesh->mTextureCoords[i] = NULL;
87         }
88     }
89     return animesh;
90 }
91 
92 } // end of namespace Assimp
93