use inactive/active color gizmo
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:1ce59256956f5dbb76f6ac3c51e4811f71483427db689afae5f0fd982a53b90f
|
||||
size 647
|
||||
oid sha256:3158461d081f058dcb9582ce19cc2daedc73abbe758ba5094c94df89028d8c4d
|
||||
size 981
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <filament/Scene.h>
|
||||
#include <filament/Camera.h>
|
||||
#include <filament/View.h>
|
||||
#include <filament/Viewport.h>
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
@@ -20,15 +21,19 @@
|
||||
|
||||
#include "Aabb2.h"
|
||||
|
||||
namespace thermion_filament {
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
|
||||
|
||||
class Gizmo {
|
||||
|
||||
enum Axis { X, Y, Z};
|
||||
|
||||
public:
|
||||
Gizmo(Engine* const engine);
|
||||
void updateTransform();
|
||||
void destroy(Engine* const engine);
|
||||
Gizmo(Engine& engine);
|
||||
void updateTransform(Camera& camera, const Viewport& vp);
|
||||
void destroy();
|
||||
Entity x() {
|
||||
return _entities[0];
|
||||
};
|
||||
@@ -41,8 +46,24 @@ class Gizmo {
|
||||
Entity center() {
|
||||
return _entities[3];
|
||||
};
|
||||
|
||||
void highlight(Entity entity);
|
||||
void unhighlight();
|
||||
private:
|
||||
Engine &_engine;
|
||||
utils::Entity _entities[4];
|
||||
Material* _material;
|
||||
MaterialInstance* _materialInstances[4];
|
||||
};
|
||||
math::float3 inactiveColors[3] {
|
||||
math::float3 { 0.75f, 0.0f, 0.0f },
|
||||
math::float3 { 0.0f, 0.75f, 0.0f },
|
||||
math::float3 { 0.0f, 0.0f, 0.75f },
|
||||
};
|
||||
math::float3 activeColors[3] {
|
||||
math::float3 { 1.0f, 0.0f, 0.0f },
|
||||
math::float3 { 0.0f, 1.0f, 0.0f },
|
||||
math::float3 { 0.0f, 0.0f, 1.0f },
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -68,7 +68,8 @@ Gizmo::Gizmo(Engine &engine) : _engine(engine)
|
||||
{ delete[] static_cast<uint16_t *>(buffer); }));
|
||||
|
||||
RenderableManager::Builder(1)
|
||||
.boundingBox({{}, {centerCubeSize, centerCubeSize, centerCubeSize}})
|
||||
.boundingBox({{-centerCubeSize, -centerCubeSize, -centerCubeSize},
|
||||
{centerCubeSize, centerCubeSize, centerCubeSize}})
|
||||
.material(0, _materialInstances[3])
|
||||
.layerMask(0xFF, 2)
|
||||
.priority(0)
|
||||
@@ -138,28 +139,27 @@ Gizmo::Gizmo(Engine &engine) : _engine(engine)
|
||||
_entities[i] = entityManager.create();
|
||||
_materialInstances[i] = _material->createInstance();
|
||||
|
||||
math::float3 color;
|
||||
auto baseColor = inactiveColors[i];
|
||||
|
||||
math::mat4f transform;
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0: // X-axis (Red)
|
||||
color = {1.0f, 0.0f, 0.0f};
|
||||
case Axis::X:
|
||||
transform = math::mat4f::rotation(math::F_PI_2, math::float3{0, 1, 0});
|
||||
break;
|
||||
case 1: // Y-axis (Green)
|
||||
color = {0.0f, 1.0f, 0.0f};
|
||||
case 1:
|
||||
transform = math::mat4f::rotation(-math::F_PI_2, math::float3{1, 0, 0});
|
||||
break;
|
||||
case 2: // Z-axis (Blue)
|
||||
color = {0.0f, 0.0f, 1.0f};
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
|
||||
_materialInstances[i]->setParameter("color", color);
|
||||
_materialInstances[i]->setParameter("color", baseColor);
|
||||
|
||||
RenderableManager::Builder(1)
|
||||
.boundingBox({{0, 0, (lineLength + arrowLength) / 2}, {arrowWidth / 2, arrowWidth / 2, (lineLength + arrowLength) / 2}})
|
||||
.boundingBox({{-arrowWidth, -arrowWidth, 0},
|
||||
{arrowWidth, arrowWidth, lineLength + arrowLength}})
|
||||
.material(0, _materialInstances[i])
|
||||
.geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb, ib, 0, 54)
|
||||
.priority(0)
|
||||
@@ -178,6 +178,37 @@ Gizmo::Gizmo(Engine &engine) : _engine(engine)
|
||||
}
|
||||
}
|
||||
|
||||
void Gizmo::highlight(Entity entity) {
|
||||
auto &rm = _engine.getRenderableManager();
|
||||
auto renderableInstance = rm.getInstance(entity);
|
||||
auto materialInstance = rm.getMaterialInstanceAt(renderableInstance, 0);
|
||||
|
||||
math::float3 baseColor;
|
||||
if(entity == x()) {
|
||||
baseColor = activeColors[Axis::X];
|
||||
} else if(entity == y()) {
|
||||
baseColor = activeColors[Axis::Y];
|
||||
} else if(entity == z()) {
|
||||
baseColor = activeColors[Axis::Z];
|
||||
} else {
|
||||
baseColor = math::float3 { 1.0f, 1.0f, 1.0f };
|
||||
}
|
||||
|
||||
materialInstance->setParameter("color", baseColor);
|
||||
}
|
||||
|
||||
void Gizmo::unhighlight() {
|
||||
auto &rm = _engine.getRenderableManager();
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
auto renderableInstance = rm.getInstance(_entities[i]);
|
||||
auto materialInstance = rm.getMaterialInstanceAt(renderableInstance, 0);
|
||||
|
||||
math::float3 baseColor = inactiveColors[i];
|
||||
materialInstance->setParameter("color", baseColor);
|
||||
}
|
||||
}
|
||||
|
||||
void Gizmo::destroy()
|
||||
{
|
||||
auto& rm = _engine.getRenderableManager();
|
||||
|
||||
Reference in New Issue
Block a user