FBX -Netz nicht mit korrekter Transformation laden. Annahme 5.2.5C++

Programme in C++. Entwicklerforum
Anonymous
 FBX -Netz nicht mit korrekter Transformation laden. Annahme 5.2.5

Post by Anonymous »

Ich habe ein Modell in das FBX -Format in 3DS max exportiert. In maximaler Szene sehen Sie wie folgt aus:

< /p>
Wenn ich es in meiner Software importiere, bekomme ich:

Wenn ich in meiner Software importiere:


Die Netze -Transformation ist falsch. Aber wenn ich die Max -FBX -Datei in Blender importiere, dann werde ich von dort aus dem richtigen Weg :


Hier wird ein Modell geladen:

Code: Select all

void BaseModel::loadAssimpModel(const std::wstring& path)
{
// Read file via ASSIMP
aiPropertyStore* props = aiCreatePropertyStore();
aiSetImportPropertyInteger(props, AI_CONFIG_PP_SLM_TRIANGLE_LIMIT, MAX_TRIANGLES_PER_MESH);

const uint32_t flags = aiProcess_Triangulate | aiProcess_CalcTangentSpace;
const std::string pathStr = Utilities::nativeStringToStdString(path);
const aiScene* scene = aiImportFileExWithProperties(pathStr.c_str(), flags, NULL, props);

aiReleasePropertyStore(props);

// Check for errors
const nbBool success = scene && scene->mFlags != AI_SCENE_FLAGS_INCOMPLETE && scene->mRootNode;
assert(success);

// Process ASSIMP's root node recursively here !!! :)
processNode(scene, scene->mRootNode, aiMatrix4x4());

aiReleaseImport(scene);
}
Die Prozessnode -Methode ist einfach:

Code: Select all

void BaseModel::processNode(const aiScene* scene, aiNode* node, const aiMatrix4x4& transform)
{
const aiMatrix4x4 accTransform = node->mTransformation * transform;

// Process each mesh located at the current node.
if (node->mNumMeshes)
{
// Create group.
DatabaseMeshPtr meshGroup;
{
aiMesh* firstMesh = scene->mMeshes[node->mMeshes[0]];

std::wstring groupName(Utilities::stdStringToNativeString(firstMesh->mName.C_Str()));

meshGroup = EntityDatabaseSingleton::instance()->createEntity();
meshGroup->setName(groupName);

meshGroup->m_materialId = m_aiLoadingMaterialIds[firstMesh->mMaterialIndex];

m_meshGroupIdentifiers.push_back(meshGroup->getIdentifier());
}

// Add meshes.
for (uint32_t i = 0; i < node->mNumMeshes; i++)
{
// The node object only contains indices to index the actual objects in the scene.
// The scene contains all the data, node is just to keep stuff organized (like relations between nodes).
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
this->addMesh(mesh, accTransform, meshGroup);
}
}

// After we've processed all of the meshes (if any) we then recursively process each of the children nodes
for (uint32_t i = 0; i < node->mNumChildren; i++)
{
this->processNode(scene, node->mChildren[i], accTransform);
}
}
Die addMesh -Methode:

Code: Select all

void BaseModel::addMesh(aiMesh* mesh, const aiMatrix4x4& transform, DatabaseMeshPtr meshGroup)
{
// Data to fill
VertexArray vertices;
std::vector indices;

// The 3x3 transform.
const aiMatrix3x3 transform3x3 = aiMatrix3x3(transform);

// Walk through each of the mesh's vertices
for (uint32_t i = 0; i < mesh->mNumVertices; i++)
{
FullVertex vertex;

mesh->mVertices[i] = transform * mesh->mVertices[i];

// Position
vertex.position.x = mesh->mVertices[i].x;
vertex.position.y = mesh->mVertices[i].y;
vertex.position.z = mesh->mVertices[i].z;

// Normal.
if (mesh->mNormals)
{
mesh->mNormals[i] = transform3x3 * mesh->mNormals[i];

vertex.normal.x = mesh->mNormals[i].x;
vertex.normal.y = mesh->mNormals[i].y;
vertex.normal.z = mesh->mNormals[i].z;
}

// Tangent
if (mesh->mTangents)
{
vertex.tangent.x = mesh->mTangents[i].x;
vertex.tangent.y = mesh->mTangents[i].y;
vertex.tangent.z = mesh->mTangents[i].z;
}

// Bitangent
if (mesh->mBitangents)
{
vertex.bitangent.x = mesh->mBitangents[i].x;
vertex.bitangent.y = mesh->mBitangents[i].y;
vertex.bitangent.z = mesh->mBitangents[i].z;
}

// Texture Coordinates
if (mesh->mTextureCoords[0]) // Does the mesh contain texture coordinates?
{
// A vertex can contain up to 8 different texture coordinates. We thus make the assumption that we won't
// use models where a vertex can have multiple texture coordinates so we always take the first set (0).
vertex.texCoord.x = mesh->mTextureCoords[0][i].x;
vertex.texCoord.y = mesh->mTextureCoords[0][i].y;
}

vertices.push_back(vertex);
}

// Now wak through each of the mesh's faces (a face is a mesh its triangle) and retrieve the corresponding vertex indices.
for (uint32_t i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
// Retrieve all indices of the face and store them in the indices vector
for (uint32_t j = 0; j < face.mNumIndices; j++)
indices.push_back(face.mIndices[j]);
}

const MeshFlatId meshFlatId = (MeshFlatId)m_flatMeshContainer.size();

Mesh* nativeMesh = new Mesh(vertices, indices, meshFlatId, meshGroup.get());

meshGroup->m_meshes.push_back(nativeMesh);
m_flatMeshContainer.push_back(nativeMesh);
}
< /code>
Sobald das Laden durchgeführt wird, werden Scheitelpunkte in den lokalen Raum umgewandelt. Ich glaube nicht, dass dies mit dem [url=viewtopic.php?t=20324]Problem[/url] verbunden ist: < /p>
for (const EntityIdentifier& entityId : m_meshGroupIdentifiers)
{
Math::Vec3 center;
size_t nbVertices = 0u;

const auto group = getMeshGroupPtr_FromEntity(entityId);

for (const auto*mesh : group->m_meshes)
{
const auto& vertices = mesh->getRealVertices();
for (auto& vertex : vertices)
center += vertex.position;

nbVertices += vertices.size();
}

center /= nbVertices;
for (auto* mesh : group->m_meshes)
{
auto& vertices = mesh->getMutableVertices();
for (auto& vertex : vertices)
vertex.position -= center;
}

group->setPosition(center);
}
Die letzte SetPosition Call Set die Worlspace -Transformation der Netzgruppe. Es wird bei der Durchführung von DirectX 12 -Realtime -Rendering verwendet. Dies ist eindeutig nicht das Problem: < /p>
cbuffer VertexShaderSharedCB : register(b0)
{
float4x4 vpMat;
};

VS_OUTPUT main(VS_INPUT input, uint instanceID : SV_InstanceID)
{
VS_OUTPUT output;

const float4x4 modelMat = meshGroupDatas[instanceID].transform;// transform here!
const float4 worldPosition = mul(float4(input.position, 1.0f), modelMat);
output.worldPosition = worldPosition.xyz;
output.position = mul(worldPosition, vpMat);
output.texCoord = input.texCoord;
output.normal = normalize(mul(float4(input.normal, 0.0f), modelMat));
output.tangent = normalize(mul(float4(input.tangent, 0.0f), modelMat));
output.bitangent = normalize(mul(float4(input.bitangent, 0.0f), modelMat));

return output;
}
< /code>
Was mache ich falsch? Und vor allem, warum der Mixer FBX richtig geladen ist und nicht der 3DS max. Mir fehlt wahrscheinlich irgendwo eine Transformation. Beachten Sie, dass OBJs immer ordnungsgemäß geladen sind;) < /strong> < /p>
Danke!

// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------liche />https Datei:

https://www.dropbox.com/scl/fi/zv9slsjz ... 351rj0lbws. 3DS MAX 2025 Native Datei:

https://www.dropbox.com/scl/fi/pjcv6896 ... e7hq6k7&dl =>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post