Setup for computing and using tangents to determine TBN

This commit is contained in:
2025-07-05 13:19:15 -04:00
parent d8b03bfba9
commit 37ad9e4a2a
25 changed files with 344 additions and 114 deletions

View File

@@ -11,8 +11,7 @@ namespace fgl::engine::components
{
ModelComponent::ModelComponent( const std::shared_ptr< Model >& model ) :
m_model_instance( model->createInstance() ),
m_transform()
m_model_instance( model->createInstance() )
{}
void ModelComponent::drawImGui()

View File

@@ -8,11 +8,65 @@
namespace fgl::engine::components
{
void TransformComponent::triggerUpdate()
{
auto visitorFunc = [ & ]< typename T0 >( T0& to_update )
{
if constexpr ( std::same_as< T0, std::weak_ptr< ModelInstance > > )
{
if ( const std::shared_ptr< ModelInstance > model_instance = to_update.lock() )
{
model_instance->setTransform( m_transform );
model_instance->flagUpdate();
}
}
};
for ( auto& to_update : m_updatables )
{
std::visit( visitorFunc, to_update );
}
}
TransformComponent::TransformComponent()
{}
TransformComponent::TransformComponent( const WorldTransform& transform ) : m_transform( transform )
{}
void TransformComponent::drawImGui()
{}
{
glm::vec3& position = m_transform.translation.vec();
if ( ImGui::DragFloat3( "Position", &position.x, 0.1f ) )
{
triggerUpdate();
}
if ( m_transform.rotation.isEuler() )
{
glm::vec3& rotation = m_transform.rotation.euler().vec();
if ( ImGui::DragFloat3( "Rotation", &rotation.x, 0.1f ) )
{
// Clamp high
while ( rotation.x > 180.0f ) rotation.x -= 360.0f;
while ( rotation.y > 180.0f ) rotation.y -= 360.0f;
while ( rotation.z > 180.0f ) rotation.z -= 360.0f;
// Clamp low
while ( rotation.x < -180.0f ) rotation.x += 360.0f;
while ( rotation.y < -180.0f ) rotation.y += 360.0f;
while ( rotation.z < -180.0f ) rotation.z += 360.0f;
triggerUpdate();
}
}
glm::vec3& scale = m_transform.scale;
if ( ImGui::DragFloat3( "Scale", &scale.x, 0.1f ) )
{
triggerUpdate();
}
}
std::string_view TransformComponent::humanName() const
{
@@ -28,4 +82,12 @@ namespace fgl::engine::components
{
return m_transform;
}
void TransformComponent::setTransform( const WorldTransform& transform )
{
m_transform = transform;
}
TransformComponent::~TransformComponent()
{}
} // namespace fgl::engine::components