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