1#include <Gui/Viewer/Gizmo/Gizmo.hpp>
3#include <Core/Asset/Camera.hpp>
4#include <Core/Geometry/RayCast.hpp>
5#include <Engine/Data/Mesh.hpp>
6#include <Engine/Rendering/RenderObject.hpp>
7#include <Engine/Rendering/RenderObjectManager.hpp>
8#include <Engine/Scene/CameraComponent.hpp>
10#include <Core/Containers/MakeShared.hpp>
11#include <Engine/Data/PlainMaterial.hpp>
12#include <Engine/Data/ShaderConfigFactory.hpp>
13#include <Engine/Rendering/RenderTechnique.hpp>
20Gizmo::Gizmo( Engine::Scene::Component* c,
21 const Core::Transform& worldTo,
22 const Core::Transform& t,
24 m_worldTo( worldTo ), m_transform( t ), m_comp( c ), m_mode( mode ) {
25 using namespace Core::Utils;
26 if ( !s_material[0] ) {
27 auto mat = Core::make_shared<Engine::Data::PlainMaterial>(
"GizmoRedMaterial" );
28 mat->setColor( Color::Red() );
30 mat = Core::make_shared<Engine::Data::PlainMaterial>(
"GizmoGreenMaterial" );
31 mat->setColor( Color::Green() );
33 mat = Core::make_shared<Engine::Data::PlainMaterial>(
"GizmoBlueMaterial" );
34 mat->setColor( Color::Blue() );
40 for (
auto ro : m_ros ) {
41 m_comp->removeRenderObject( ro->getIndex() );
45void Gizmo::show(
bool on ) {
46 for (
auto ro : m_ros ) {
52 const Core::Vector3& origin,
53 const Core::Vector3& axis,
54 const Core::Vector2& pix,
55 Core::Vector3& pointOut,
60 const Core::Vector3 ortho = cam.
getDirection().cross( axis );
61 const Core::Vector3 normal =
62 ( ortho.squaredNorm() > 0 ) ? axis.cross( ortho ) : axis.cross( cam.
getUpVector() );
65 bool hasHit = Core::Geometry::RayCastPlane( ray, origin, normal, hits );
66 if ( hasHit ) { pointOut = origin + ( axis.dot( ray.pointAt( hits[0] ) - origin ) ) * axis; }
71 const Core::Vector3& origin,
72 const Core::Vector3& axis,
73 const Core::Vector2& pix,
74 Core::Vector3& pointOut,
78 bool hasHit = Core::Geometry::RayCastPlane( ray, origin, axis, hits );
79 if ( hasHit ) { pointOut = ray.pointAt( hits[0] ); }
84 m_comp->addRenderObject( ro );
85 m_ros.push_back( ro );
89 auto rt = Core::make_shared<Engine::Rendering::RenderTechnique>();
92 rt->setConfiguration( *plaincfg );
100 m_ros[ro]->getRenderTechnique()->getParametersProvider() );
101 CORE_ASSERT( c !=
nullptr,
"Gizmo not set (or with wrong state controler?" );
105Gizmo::UiSelectionControler::UiSelectionControler(
108 ShaderParameterProvider(), m_associatedMaterial( material ), m_selectedColor( selectedColor ) {}
111 m_associatedMaterial->updateGL();
112 auto& renderParameters = getParameters();
113 renderParameters.mergeReplaceVariables( m_associatedMaterial->getParameters() );
114 if ( m_selected ) { renderParameters.setVariable(
"material.color", m_selectedColor ); }
118 m_selected = !m_selected;
Camera class storing the Camera frame and the projection properties The view direction is -z in camer...
Core::Ray getRayFromScreen(const Core::Vector2 &pix) const
Core::Vector3 getUpVector() const
Return the up vector.
Core::Vector3 getDirection() const
Return the direction the camera is looking at.
void setState()
Set the state of the controler to true.
void toggleState()
Swap the state of the controler.
void clearState()
Set the state of the controler to false.
void updateGL() override
Inherited.
static std::array< std::shared_ptr< Ra::Engine::Data::PlainMaterial >, 3 > s_material
Core::Utils::optional< ShaderConfiguration > getConfiguration(const std::string &name)
hepler function to manage enum as underlying types in VariableSet