Fixed texture appearance, added scaling, removed unused code
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/mesh.h>
|
||||
#include <assimp/material.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
@@ -101,11 +101,13 @@ namespace OpenVulkano::Scene
|
||||
mesh->mTextureCoords[0] = new aiVector3D[geometry->vertexCount];
|
||||
mesh->mMaterialIndex = 0;
|
||||
mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
||||
mesh->mNumUVComponents[0] = 2;
|
||||
|
||||
float scaling = 100; // fbx units are centimeters...
|
||||
for (uint32_t i = 0; i < geometry->vertexCount; ++i)
|
||||
{
|
||||
const Vertex& vertex = geometry->vertices[i];
|
||||
mesh->mVertices[i] = aiVector3D(vertex.position.x, vertex.position.y, vertex.position.z);
|
||||
mesh->mVertices[i] = aiVector3D(vertex.position.x, vertex.position.y, vertex.position.z) * scaling;
|
||||
mesh->mNormals[i] = aiVector3D(vertex.normal.x, vertex.normal.y, vertex.normal.z);
|
||||
mesh->mTextureCoords[0][i] = aiVector3D(vertex.textureCoordinates.x, vertex.textureCoordinates.y, 0.0f);
|
||||
}
|
||||
@@ -136,56 +138,8 @@ namespace OpenVulkano::Scene
|
||||
scene.mMaterials[0] = material;
|
||||
scene.mNumMaterials = 1;
|
||||
|
||||
// aiColor3D diffuseColor(1.0f, 1.0f, 1.0f);
|
||||
// material->AddProperty(&diffuseColor, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||
|
||||
Array<char> textureData = Utils::ReadFile(texturePath);
|
||||
|
||||
aiTexture* texture = new aiTexture();
|
||||
texture->mWidth = static_cast<unsigned int>(textureData.Size());
|
||||
texture->mHeight = 0; // indicates that this is compressed texture and the pcData has size mWidth
|
||||
texture->pcData = reinterpret_cast<aiTexel*>(new uint8_t[textureData.Size()]);
|
||||
std::memcpy(texture->pcData, textureData.Data(), textureData.Size());
|
||||
|
||||
scene.mTextures = new aiTexture*[1];
|
||||
scene.mTextures[0] = texture;
|
||||
scene.mNumTextures = 1;
|
||||
|
||||
std::string ext = texturePath.substr(texturePath.find_last_of('.') + 1);
|
||||
if (ext == "png")
|
||||
{
|
||||
std::memcpy(texture->achFormatHint, "png", 3);
|
||||
}
|
||||
else if (ext == "jpg" || ext == "jpeg")
|
||||
{
|
||||
std::memcpy(texture->achFormatHint, "jpg", 3);
|
||||
}
|
||||
texture->achFormatHint[3] = '\0';
|
||||
|
||||
aiString texName = aiString("*0");
|
||||
material->AddProperty(&texName, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0));
|
||||
|
||||
// Validation
|
||||
for (uint32_t i = 0; i < geometry->indexCount; ++i) {
|
||||
if (geometry->GetIndex(i) >= geometry->vertexCount) {
|
||||
std::cerr << "Invalid index at position " << i << ": "
|
||||
<< geometry->GetIndex(i) << " (vertex count: "
|
||||
<< geometry->vertexCount << ")" << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (geometry->indexCount % 3 != 0) {
|
||||
std::cerr << "Invalid index count: " << geometry->indexCount
|
||||
<< " (not divisible by 3)" << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
//
|
||||
//aiString externalPath(texturePath);
|
||||
//scene.mMaterials[0]->AddProperty(&externalPath, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0));
|
||||
|
||||
// Export
|
||||
aiString externalPath(texturePath);
|
||||
scene.mMaterials[0]->AddProperty(&externalPath, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0));
|
||||
|
||||
Assimp::Exporter exporter;
|
||||
aiReturn result = exporter.Export(&scene, "fbx", fbxPath);
|
||||
@@ -218,8 +172,6 @@ namespace OpenVulkano::Scene
|
||||
SAFE_DELETE_ARRAY(scene.mMeshes);
|
||||
SAFE_DELETE_ARRAY(scene.mRootNode->mMeshes);
|
||||
SAFE_DELETE_ARRAY(scene.mMaterials);
|
||||
SAFE_DELETE_ARRAY(scene.mTextures);
|
||||
SAFE_DELETE_ARRAY(texture->pcData);
|
||||
delete scene.mRootNode;
|
||||
scene.mRootNode = nullptr;
|
||||
#undef SAFE_DELETE_ARRAY
|
||||
|
||||
Reference in New Issue
Block a user