|
|
@@ -190,150 +190,6 @@ void Exporter::exportMesh(
|
|
|
const aiMesh& mesh,
|
|
|
const aiMatrix4x4* transform) const
|
|
|
{
|
|
|
-#if 0
|
|
|
- std::string name = getMeshName(mesh);
|
|
|
- std::fstream file;
|
|
|
- LOGI("Exporting mesh %s", name.c_str());
|
|
|
-
|
|
|
- uint32_t vertsCount = mesh.mNumVertices;
|
|
|
-
|
|
|
- // Open file
|
|
|
- file.open(m_outputDirectory + name + ".ankimesh",
|
|
|
- std::ios::out | std::ios::binary);
|
|
|
-
|
|
|
- // Write magic word
|
|
|
- file.write("ANKIMESH", 8);
|
|
|
-
|
|
|
- // Write the name
|
|
|
- uint32_t size = name.size();
|
|
|
- file.write((char*)&size, sizeof(uint32_t));
|
|
|
- file.write(&name[0], size);
|
|
|
-
|
|
|
- // Write positions
|
|
|
- file.write((char*)&vertsCount, sizeof(uint32_t));
|
|
|
- for(uint32_t i = 0; i < mesh.mNumVertices; i++)
|
|
|
- {
|
|
|
- aiVector3D pos = mesh.mVertices[i];
|
|
|
-
|
|
|
- // Transform
|
|
|
- if(transform)
|
|
|
- {
|
|
|
- pos = (*transform) * pos;
|
|
|
- }
|
|
|
-
|
|
|
- // flip
|
|
|
- if(m_flipyz)
|
|
|
- {
|
|
|
- static const aiMatrix4x4 toLefthanded(
|
|
|
- 1, 0, 0, 0,
|
|
|
- 0, 0, 1, 0,
|
|
|
- 0, -1, 0, 0,
|
|
|
- 0, 0, 0, 1);
|
|
|
-
|
|
|
- pos = toLefthanded * pos;
|
|
|
- }
|
|
|
-
|
|
|
- for(uint32_t j = 0; j < 3; j++)
|
|
|
- {
|
|
|
- file.write((char*)&pos[j], sizeof(float));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Write the indices
|
|
|
- file.write((char*)&mesh.mNumFaces, sizeof(uint32_t));
|
|
|
- for(uint32_t i = 0; i < mesh.mNumFaces; i++)
|
|
|
- {
|
|
|
- const aiFace& face = mesh.mFaces[i];
|
|
|
-
|
|
|
- if(face.mNumIndices != 3)
|
|
|
- {
|
|
|
- ERROR("For some reason the assimp didn't triangulate");
|
|
|
- }
|
|
|
-
|
|
|
- for(uint32_t j = 0; j < 3; j++)
|
|
|
- {
|
|
|
- uint32_t index = face.mIndices[j];
|
|
|
- file.write((char*)&index, sizeof(uint32_t));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Write the tex coords
|
|
|
- file.write((char*)&vertsCount, sizeof(uint32_t));
|
|
|
-
|
|
|
- // For all channels
|
|
|
- for(uint32_t ch = 0; ch < mesh.GetNumUVChannels(); ch++)
|
|
|
- {
|
|
|
- if(mesh.mNumUVComponents[ch] != 2)
|
|
|
- {
|
|
|
- ERROR("Incorrect number of UV components");
|
|
|
- }
|
|
|
-
|
|
|
- // For all tex coords of this channel
|
|
|
- for(uint32_t i = 0; i < vertsCount; i++)
|
|
|
- {
|
|
|
- aiVector3D texCoord = mesh.mTextureCoords[ch][i];
|
|
|
-
|
|
|
- for(uint32_t j = 0; j < 2; j++)
|
|
|
- {
|
|
|
- file.write((char*)&texCoord[j], sizeof(float));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Write bone weigths count
|
|
|
- if(mesh.HasBones())
|
|
|
- {
|
|
|
-#if 0
|
|
|
- // Write file
|
|
|
- file.write((char*)&vertsCount, sizeof(uint32_t));
|
|
|
-
|
|
|
- // Gather info for each vertex
|
|
|
- std::vector<Vw> vw;
|
|
|
- vw.resize(vertsCount);
|
|
|
- memset(&vw[0], 0, sizeof(Vw) * vertsCount);
|
|
|
-
|
|
|
- // For all bones
|
|
|
- for(uint32_t i = 0; i < mesh.mNumBones; i++)
|
|
|
- {
|
|
|
- const aiBone& bone = *mesh.mBones[i];
|
|
|
-
|
|
|
- // for every weights of the bone
|
|
|
- for(uint32_t j = 0; j < bone.mWeightsCount; j++)
|
|
|
- {
|
|
|
- const aiVertexWeight& weigth = bone.mWeights[j];
|
|
|
-
|
|
|
- // Sanity check
|
|
|
- if(weight.mVertexId >= vertCount)
|
|
|
- {
|
|
|
- ERROR("Out of bounds vert ID");
|
|
|
- }
|
|
|
-
|
|
|
- Vm& a = vm[weight.mVertexId];
|
|
|
-
|
|
|
- // Check out of bounds
|
|
|
- if(a.bonesCount >= MAX_BONES_PER_VERTEX)
|
|
|
- {
|
|
|
- LOGW("Too many bones for vertex %d", weigth.mVertexId);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // Write to vertex
|
|
|
- a.boneIds[a.bonesCount] = i;
|
|
|
- a.weigths[a.bonesCount] = weigth.mWeigth;
|
|
|
- ++a.bonesCount;
|
|
|
- }
|
|
|
-
|
|
|
- // Now write the file
|
|
|
- }
|
|
|
-#endif
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- uint32_t num = 0;
|
|
|
- file.write((char*)&num, sizeof(uint32_t));
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
std::string name = mesh.mName.C_Str();
|
|
|
std::fstream file;
|
|
|
LOGI("Exporting mesh %s", name.c_str());
|