rev |
line source |
nuclear@0
|
1 /*
|
nuclear@0
|
2 ---------------------------------------------------------------------------
|
nuclear@0
|
3 Open Asset Import Library (assimp)
|
nuclear@0
|
4 ---------------------------------------------------------------------------
|
nuclear@0
|
5
|
nuclear@0
|
6 Copyright (c) 2006-2012, assimp team
|
nuclear@0
|
7
|
nuclear@0
|
8 All rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Redistribution and use of this software in source and binary forms,
|
nuclear@0
|
11 with or without modification, are permitted provided that the following
|
nuclear@0
|
12 conditions are met:
|
nuclear@0
|
13
|
nuclear@0
|
14 * Redistributions of source code must retain the above
|
nuclear@0
|
15 copyright notice, this list of conditions and the
|
nuclear@0
|
16 following disclaimer.
|
nuclear@0
|
17
|
nuclear@0
|
18 * Redistributions in binary form must reproduce the above
|
nuclear@0
|
19 copyright notice, this list of conditions and the
|
nuclear@0
|
20 following disclaimer in the documentation and/or other
|
nuclear@0
|
21 materials provided with the distribution.
|
nuclear@0
|
22
|
nuclear@0
|
23 * Neither the name of the assimp team, nor the names of its
|
nuclear@0
|
24 contributors may be used to endorse or promote products
|
nuclear@0
|
25 derived from this software without specific prior
|
nuclear@0
|
26 written permission of the assimp team.
|
nuclear@0
|
27
|
nuclear@0
|
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
nuclear@0
|
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
nuclear@0
|
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
nuclear@0
|
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
nuclear@0
|
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
nuclear@0
|
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
nuclear@0
|
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
nuclear@0
|
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
nuclear@0
|
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
nuclear@0
|
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
nuclear@0
|
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
nuclear@0
|
39 ---------------------------------------------------------------------------
|
nuclear@0
|
40 */
|
nuclear@0
|
41 /** @file Implementation of the post processing step "MakeVerboseFormat"
|
nuclear@0
|
42 */
|
nuclear@0
|
43
|
nuclear@0
|
44 #include "AssimpPCH.h"
|
nuclear@0
|
45 #include "MakeVerboseFormat.h"
|
nuclear@0
|
46
|
nuclear@0
|
47 using namespace Assimp;
|
nuclear@0
|
48
|
nuclear@0
|
49 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
50 MakeVerboseFormatProcess::MakeVerboseFormatProcess()
|
nuclear@0
|
51 {
|
nuclear@0
|
52 // nothing to do here
|
nuclear@0
|
53 }
|
nuclear@0
|
54 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
55 MakeVerboseFormatProcess::~MakeVerboseFormatProcess()
|
nuclear@0
|
56 {
|
nuclear@0
|
57 // nothing to do here
|
nuclear@0
|
58 }
|
nuclear@0
|
59 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
60 // Executes the post processing step on the given imported data.
|
nuclear@0
|
61 void MakeVerboseFormatProcess::Execute( aiScene* pScene)
|
nuclear@0
|
62 {
|
nuclear@0
|
63 ai_assert(NULL != pScene);
|
nuclear@0
|
64 DefaultLogger::get()->debug("MakeVerboseFormatProcess begin");
|
nuclear@0
|
65
|
nuclear@0
|
66 bool bHas = false;
|
nuclear@0
|
67 for( unsigned int a = 0; a < pScene->mNumMeshes; a++)
|
nuclear@0
|
68 {
|
nuclear@0
|
69 if( MakeVerboseFormat( pScene->mMeshes[a]))
|
nuclear@0
|
70 bHas = true;
|
nuclear@0
|
71 }
|
nuclear@0
|
72 if (bHas) DefaultLogger::get()->info("MakeVerboseFormatProcess finished. There was much work to do ...");
|
nuclear@0
|
73 else DefaultLogger::get()->debug("MakeVerboseFormatProcess. There was nothing to do.");
|
nuclear@0
|
74
|
nuclear@0
|
75 pScene->mFlags &= ~AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
|
nuclear@0
|
76
|
nuclear@0
|
77 }
|
nuclear@0
|
78 // ------------------------------------------------------------------------------------------------
|
nuclear@0
|
79 // Executes the post processing step on the given imported data.
|
nuclear@0
|
80 bool MakeVerboseFormatProcess::MakeVerboseFormat(aiMesh* pcMesh)
|
nuclear@0
|
81 {
|
nuclear@0
|
82 ai_assert(NULL != pcMesh);
|
nuclear@0
|
83
|
nuclear@0
|
84 unsigned int iOldNumVertices = pcMesh->mNumVertices;
|
nuclear@0
|
85 const unsigned int iNumVerts = pcMesh->mNumFaces*3;
|
nuclear@0
|
86
|
nuclear@0
|
87 aiVector3D* pvPositions = new aiVector3D[ iNumVerts ];
|
nuclear@0
|
88
|
nuclear@0
|
89 aiVector3D* pvNormals = NULL;
|
nuclear@0
|
90 if (pcMesh->HasNormals())
|
nuclear@0
|
91 {
|
nuclear@0
|
92 pvNormals = new aiVector3D[iNumVerts];
|
nuclear@0
|
93 }
|
nuclear@0
|
94 aiVector3D* pvTangents = NULL, *pvBitangents = NULL;
|
nuclear@0
|
95 if (pcMesh->HasTangentsAndBitangents())
|
nuclear@0
|
96 {
|
nuclear@0
|
97 pvTangents = new aiVector3D[iNumVerts];
|
nuclear@0
|
98 pvBitangents = new aiVector3D[iNumVerts];
|
nuclear@0
|
99 }
|
nuclear@0
|
100
|
nuclear@0
|
101 aiVector3D* apvTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS] = {0};
|
nuclear@0
|
102 aiColor4D* apvColorSets[AI_MAX_NUMBER_OF_COLOR_SETS] = {0};
|
nuclear@0
|
103
|
nuclear@0
|
104 unsigned int p = 0;
|
nuclear@0
|
105 while (pcMesh->HasTextureCoords(p))
|
nuclear@0
|
106 apvTextureCoords[p++] = new aiVector3D[iNumVerts];
|
nuclear@0
|
107
|
nuclear@0
|
108 p = 0;
|
nuclear@0
|
109 while (pcMesh->HasVertexColors(p))
|
nuclear@0
|
110 apvColorSets[p++] = new aiColor4D[iNumVerts];
|
nuclear@0
|
111
|
nuclear@0
|
112 // allocate enough memory to hold output bones and vertex weights ...
|
nuclear@0
|
113 std::vector<aiVertexWeight>* newWeights = new std::vector<aiVertexWeight>[pcMesh->mNumBones];
|
nuclear@0
|
114 for (unsigned int i = 0;i < pcMesh->mNumBones;++i) {
|
nuclear@0
|
115 newWeights[i].reserve(pcMesh->mBones[i]->mNumWeights*3);
|
nuclear@0
|
116 }
|
nuclear@0
|
117
|
nuclear@0
|
118 // iterate through all faces and build a clean list
|
nuclear@0
|
119 unsigned int iIndex = 0;
|
nuclear@0
|
120 for (unsigned int a = 0; a< pcMesh->mNumFaces;++a)
|
nuclear@0
|
121 {
|
nuclear@0
|
122 aiFace* pcFace = &pcMesh->mFaces[a];
|
nuclear@0
|
123 for (unsigned int q = 0; q < pcFace->mNumIndices;++q,++iIndex)
|
nuclear@0
|
124 {
|
nuclear@0
|
125 // need to build a clean list of bones, too
|
nuclear@0
|
126 for (unsigned int i = 0;i < pcMesh->mNumBones;++i)
|
nuclear@0
|
127 {
|
nuclear@0
|
128 for (unsigned int a = 0; a < pcMesh->mBones[i]->mNumWeights;a++)
|
nuclear@0
|
129 {
|
nuclear@0
|
130 const aiVertexWeight& w = pcMesh->mBones[i]->mWeights[a];
|
nuclear@0
|
131 if(pcFace->mIndices[q] == w.mVertexId)
|
nuclear@0
|
132 {
|
nuclear@0
|
133 aiVertexWeight wNew;
|
nuclear@0
|
134 wNew.mVertexId = iIndex;
|
nuclear@0
|
135 wNew.mWeight = w.mWeight;
|
nuclear@0
|
136 newWeights[i].push_back(wNew);
|
nuclear@0
|
137 }
|
nuclear@0
|
138 }
|
nuclear@0
|
139 }
|
nuclear@0
|
140
|
nuclear@0
|
141 pvPositions[iIndex] = pcMesh->mVertices[pcFace->mIndices[q]];
|
nuclear@0
|
142
|
nuclear@0
|
143 if (pcMesh->HasNormals())
|
nuclear@0
|
144 {
|
nuclear@0
|
145 pvNormals[iIndex] = pcMesh->mNormals[pcFace->mIndices[q]];
|
nuclear@0
|
146 }
|
nuclear@0
|
147 if (pcMesh->HasTangentsAndBitangents())
|
nuclear@0
|
148 {
|
nuclear@0
|
149 pvTangents[iIndex] = pcMesh->mTangents[pcFace->mIndices[q]];
|
nuclear@0
|
150 pvBitangents[iIndex] = pcMesh->mBitangents[pcFace->mIndices[q]];
|
nuclear@0
|
151 }
|
nuclear@0
|
152
|
nuclear@0
|
153 unsigned int p = 0;
|
nuclear@0
|
154 while (pcMesh->HasTextureCoords(p))
|
nuclear@0
|
155 {
|
nuclear@0
|
156 apvTextureCoords[p][iIndex] = pcMesh->mTextureCoords[p][pcFace->mIndices[q]];
|
nuclear@0
|
157 ++p;
|
nuclear@0
|
158 }
|
nuclear@0
|
159 p = 0;
|
nuclear@0
|
160 while (pcMesh->HasVertexColors(p))
|
nuclear@0
|
161 {
|
nuclear@0
|
162 apvColorSets[p][iIndex] = pcMesh->mColors[p][pcFace->mIndices[q]];
|
nuclear@0
|
163 ++p;
|
nuclear@0
|
164 }
|
nuclear@0
|
165 pcFace->mIndices[q] = iIndex;
|
nuclear@0
|
166 }
|
nuclear@0
|
167 }
|
nuclear@0
|
168
|
nuclear@0
|
169 // build output vertex weights
|
nuclear@0
|
170 for (unsigned int i = 0;i < pcMesh->mNumBones;++i)
|
nuclear@0
|
171 {
|
nuclear@0
|
172 delete pcMesh->mBones[i]->mWeights;
|
nuclear@0
|
173 if (!newWeights[i].empty())
|
nuclear@0
|
174 {
|
nuclear@0
|
175 pcMesh->mBones[i]->mWeights = new aiVertexWeight[newWeights[i].size()];
|
nuclear@0
|
176 memcpy(pcMesh->mBones[i]->mWeights,&newWeights[i][0],
|
nuclear@0
|
177 sizeof(aiVertexWeight) * newWeights[i].size());
|
nuclear@0
|
178 }
|
nuclear@0
|
179 else pcMesh->mBones[i]->mWeights = NULL;
|
nuclear@0
|
180 }
|
nuclear@0
|
181
|
nuclear@0
|
182 // delete the old members
|
nuclear@0
|
183 delete[] pcMesh->mVertices;
|
nuclear@0
|
184 pcMesh->mVertices = pvPositions;
|
nuclear@0
|
185
|
nuclear@0
|
186 p = 0;
|
nuclear@0
|
187 while (pcMesh->HasTextureCoords(p))
|
nuclear@0
|
188 {
|
nuclear@0
|
189 delete pcMesh->mTextureCoords[p];
|
nuclear@0
|
190 pcMesh->mTextureCoords[p] = apvTextureCoords[p];
|
nuclear@0
|
191 ++p;
|
nuclear@0
|
192 }
|
nuclear@0
|
193 p = 0;
|
nuclear@0
|
194 while (pcMesh->HasVertexColors(p))
|
nuclear@0
|
195 {
|
nuclear@0
|
196 delete pcMesh->mColors[p];
|
nuclear@0
|
197 pcMesh->mColors[p] = apvColorSets[p];
|
nuclear@0
|
198 ++p;
|
nuclear@0
|
199 }
|
nuclear@0
|
200 pcMesh->mNumVertices = iNumVerts;
|
nuclear@0
|
201
|
nuclear@0
|
202 if (pcMesh->HasNormals())
|
nuclear@0
|
203 {
|
nuclear@0
|
204 delete[] pcMesh->mNormals;
|
nuclear@0
|
205 pcMesh->mNormals = pvNormals;
|
nuclear@0
|
206 }
|
nuclear@0
|
207 if (pcMesh->HasTangentsAndBitangents())
|
nuclear@0
|
208 {
|
nuclear@0
|
209 delete[] pcMesh->mTangents;
|
nuclear@0
|
210 pcMesh->mTangents = pvTangents;
|
nuclear@0
|
211 delete[] pcMesh->mBitangents;
|
nuclear@0
|
212 pcMesh->mBitangents = pvBitangents;
|
nuclear@0
|
213 }
|
nuclear@0
|
214 return (pcMesh->mNumVertices != iOldNumVertices);
|
nuclear@0
|
215 }
|