Skip to content

Commit

Permalink
Assimp importer global scale
Browse files Browse the repository at this point in the history
  • Loading branch information
roeas committed Nov 5, 2024
1 parent b9d29d7 commit 571f1d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Engine/Source/Editor/Layer/SandboxLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SandboxLayer::SandboxLayer()
transform.m_rotation = glm::vec3{ 0.0f, glm::radians(-90.0f), 0.0f};

sl::ModelImporter importer("D:/Works/Model/slum_house/scene.gltf");
importer.SetGlobalScale(glm::vec3{ 1.0f });
importer.SetGlobalScale(1.0f);
importer.Import();
}

Expand Down
6 changes: 2 additions & 4 deletions Engine/Source/Engine/Resource/ModelImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void ModelImporter::Import()
SL_PROFILE;
SL_LOG_TRACE("Importing model: \"{}\"", m_sourcePath.c_str());

constexpr int ImportFlags = aiProcess_Triangulate |
constexpr int ImportFlags = aiProcess_Triangulate | aiProcess_GlobalScale |
aiProcess_GenSmoothNormals | aiProcess_CalcTangentSpace | aiProcess_GenUVCoords | aiProcess_GenBoundingBoxes |
aiProcess_FindInvalidData | aiProcess_FixInfacingNormals | aiProcess_DropNormals |
aiProcess_FindDegenerates | aiProcess_SortByPType |
Expand All @@ -34,6 +34,7 @@ void ModelImporter::Import()
aiProcess_PreTransformVertices; // TODO: Hierarchy

Assimp::Importer importer;
importer.SetPropertyFloat(AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY, m_globalScale);
importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType::aiPrimitiveType_LINE | aiPrimitiveType::aiPrimitiveType_POINT);

m_pScene = importer.ReadFile(m_sourcePath.c_str(), ImportFlags);
Expand Down Expand Up @@ -190,9 +191,6 @@ void ModelImporter::ProcessMesh(const aiMesh *pMesh)
auto &rendering = entity.AddComponent<sl::RenderingComponent>();
rendering.m_optMeshResourceName = std::move(MeshResourceName);
rendering.m_optMaterialResourceName = std::move(materialResourceName);

auto &transform = entity.GetComponents<TransformComponent>();
transform.m_scale = m_globalScale;

// TODO: AABB
// TODO: Parent entity
Expand Down
9 changes: 7 additions & 2 deletions Engine/Source/Engine/Resource/ModelImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class ModelImporter final
ModelImporter(std::string_view sourcePath);

void SetParentEntity(sl::Entity entity) { m_parentEntity = entity; }
void SetGlobalScale(const glm::vec3 &scale) { m_globalScale = scale; }
sl::Entity GetParentEntity() const { return m_parentEntity; }
sl::Entity &GetParentEntity() { return m_parentEntity; }

void SetGlobalScale(float scale) { m_globalScale = scale; }
float GetGlobalScale() const { return m_globalScale; }
float &GetGlobalScale() { return m_globalScale; }

void Import();

Expand All @@ -36,7 +41,7 @@ class ModelImporter final
std::string m_sourcePath;

sl::Entity m_parentEntity;
glm::vec3 m_globalScale{ 1.0f };
float m_globalScale;

const aiScene *m_pScene;
};
Expand Down

0 comments on commit 571f1d4

Please sign in to comment.