------------------------------------------------------------------------------------------------ Collect vertex/face data
| 142 | // ------------------------------------------------------------------------------------------------ |
| 143 | // Collect vertex/face data |
| 144 | void PretransformVertices::CollectData(const aiScene *pcScene, const aiNode *pcNode, unsigned int iMat, |
| 145 | unsigned int iVFormat, aiMesh *pcMeshOut, |
| 146 | unsigned int aiCurrent[2], unsigned int *num_refs) const { |
| 147 | // No need to multiply if there's no transformation |
| 148 | const bool identity = pcNode->mTransformation.IsIdentity(); |
| 149 | for (unsigned int i = 0; i < pcNode->mNumMeshes; ++i) { |
| 150 | aiMesh *pcMesh = pcScene->mMeshes[pcNode->mMeshes[i]]; |
| 151 | if (iMat == pcMesh->mMaterialIndex && iVFormat == GetMeshVFormat(pcMesh)) { |
| 152 | // Decrement mesh reference counter |
| 153 | unsigned int &num_ref = num_refs[pcNode->mMeshes[i]]; |
| 154 | ai_assert(0 != num_ref); |
| 155 | --num_ref; |
| 156 | // Save the name of the last mesh |
| 157 | if (num_ref == 0) { |
| 158 | pcMeshOut->mName = pcMesh->mName; |
| 159 | } |
| 160 | |
| 161 | if (identity) { |
| 162 | // copy positions without modifying them |
| 163 | ::memcpy(pcMeshOut->mVertices + aiCurrent[AI_PTVS_VERTEX], |
| 164 | pcMesh->mVertices, |
| 165 | pcMesh->mNumVertices * sizeof(aiVector3D)); |
| 166 | |
| 167 | if (iVFormat & 0x2) { |
| 168 | // copy normals without modifying them |
| 169 | ::memcpy(pcMeshOut->mNormals + aiCurrent[AI_PTVS_VERTEX], |
| 170 | pcMesh->mNormals, |
| 171 | pcMesh->mNumVertices * sizeof(aiVector3D)); |
| 172 | } |
| 173 | if (iVFormat & 0x4) { |
| 174 | // copy tangents without modifying them |
| 175 | ::memcpy(pcMeshOut->mTangents + aiCurrent[AI_PTVS_VERTEX], |
| 176 | pcMesh->mTangents, |
| 177 | pcMesh->mNumVertices * sizeof(aiVector3D)); |
| 178 | // copy bitangents without modifying them |
| 179 | ::memcpy(pcMeshOut->mBitangents + aiCurrent[AI_PTVS_VERTEX], |
| 180 | pcMesh->mBitangents, |
| 181 | pcMesh->mNumVertices * sizeof(aiVector3D)); |
| 182 | } |
| 183 | } else { |
| 184 | // copy positions, transform them to worldspace |
| 185 | for (unsigned int n = 0; n < pcMesh->mNumVertices; ++n) { |
| 186 | pcMeshOut->mVertices[aiCurrent[AI_PTVS_VERTEX] + n] = pcNode->mTransformation * pcMesh->mVertices[n]; |
| 187 | } |
| 188 | aiMatrix4x4 mWorldIT = pcNode->mTransformation; |
| 189 | mWorldIT.Inverse().Transpose(); |
| 190 | |
| 191 | // TODO: implement Inverse() for aiMatrix3x3 |
| 192 | aiMatrix3x3 m = aiMatrix3x3(mWorldIT); |
| 193 | |
| 194 | if (iVFormat & 0x2) { |
| 195 | // copy normals, transform them to worldspace |
| 196 | for (unsigned int n = 0; n < pcMesh->mNumVertices; ++n) { |
| 197 | pcMeshOut->mNormals[aiCurrent[AI_PTVS_VERTEX] + n] = |
| 198 | (m * pcMesh->mNormals[n]).Normalize(); |
| 199 | } |
| 200 | } |
| 201 | if (iVFormat & 0x4) { |
nothing calls this directly
no test coverage detected