feat: re-implement (native) Gizmo class, expose preserveScaling parameter for setParent, add methods for getting viewport bounding box from renderable entity
This commit is contained in:
18
thermion_dart/native/include/Aabb2.h
Normal file
18
thermion_dart/native/include/Aabb2.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
struct Aabb2 {
|
||||
float minX;
|
||||
float minY;
|
||||
float maxX;
|
||||
float maxY;
|
||||
};
|
||||
|
||||
typedef struct Aabb2 Aabb2;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
48
thermion_dart/native/include/Gizmo.hpp
Normal file
48
thermion_dart/native/include/Gizmo.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/Entity.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/Material.h>
|
||||
#include <filament/MaterialInstance.h>
|
||||
#include <filament/Scene.h>
|
||||
#include <filament/Camera.h>
|
||||
#include <filament/View.h>
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <gltfio/FilamentInstance.h>
|
||||
#include <gltfio/ResourceLoader.h>
|
||||
|
||||
#include <filament/IndexBuffer.h>
|
||||
#include <filament/InstanceBuffer.h>
|
||||
|
||||
#include "material/gizmo.h"
|
||||
|
||||
#include "Aabb2.h"
|
||||
|
||||
using namespace filament;
|
||||
using namespace utils;
|
||||
|
||||
|
||||
class Gizmo {
|
||||
public:
|
||||
Gizmo(Engine* const engine);
|
||||
void updateTransform();
|
||||
void destroy(Engine* const engine);
|
||||
Entity x() {
|
||||
return _entities[0];
|
||||
};
|
||||
Entity y() {
|
||||
return _entities[1];
|
||||
};
|
||||
Entity z() {
|
||||
return _entities[2];
|
||||
};
|
||||
Entity center() {
|
||||
return _entities[3];
|
||||
};
|
||||
private:
|
||||
utils::Entity _entities[4];
|
||||
Material* _material;
|
||||
MaterialInstance* _materialInstances[4];
|
||||
};
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <map>
|
||||
|
||||
#include <filament/Scene.h>
|
||||
#include <filament/Camera.h>
|
||||
#include <filament/View.h>
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
@@ -17,11 +19,13 @@
|
||||
|
||||
#include "material/gizmo.h"
|
||||
#include "utils/NameComponentManager.h"
|
||||
#include "Gizmo.hpp"
|
||||
#include "ResourceBuffer.hpp"
|
||||
#include "components/CollisionComponentManager.hpp"
|
||||
#include "components/AnimationComponentManager.hpp"
|
||||
|
||||
#include "tsl/robin_map.h"
|
||||
#include "Aabb2.h"
|
||||
|
||||
namespace thermion_filament
|
||||
{
|
||||
@@ -37,7 +41,8 @@ namespace thermion_filament
|
||||
class SceneManager
|
||||
{
|
||||
public:
|
||||
SceneManager(const ResourceLoaderWrapperImpl *const loader,
|
||||
SceneManager(View* view,
|
||||
const ResourceLoaderWrapperImpl *const loader,
|
||||
Engine *engine,
|
||||
Scene *scene,
|
||||
const char *uberArchivePath);
|
||||
@@ -146,7 +151,7 @@ namespace thermion_filament
|
||||
void addCollisionComponent(EntityId entity, void (*onCollisionCallback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform);
|
||||
void removeCollisionComponent(EntityId entityId);
|
||||
EntityId getParent(EntityId child);
|
||||
void setParent(EntityId child, EntityId parent);
|
||||
void setParent(EntityId child, EntityId parent, bool preserveScaling);
|
||||
bool addAnimationComponent(EntityId entity);
|
||||
void removeAnimationComponent(EntityId entity);
|
||||
|
||||
@@ -165,11 +170,18 @@ namespace thermion_filament
|
||||
void setPriority(EntityId entity, int priority);
|
||||
|
||||
/// @brief returns the gizmo entity, used to manipulate the global transform for entities
|
||||
/// @param out a pointer to an array of three EntityId {x, y, z}
|
||||
/// @param out a pointer sized large enough to hold three EntityId values (representing the x, y, and z axis of the translation gizmo).
|
||||
/// @return
|
||||
///
|
||||
void getGizmo(EntityId *out);
|
||||
|
||||
|
||||
/// @brief returns the 2D min/max viewport coordinates of the bounding box for the specified enitty;
|
||||
/// @param out a pointer large enough to store four floats (the min/max coordinates of the bounding box)
|
||||
/// @return
|
||||
///
|
||||
Aabb2 getBoundingBox(EntityId entity);
|
||||
|
||||
friend class FilamentViewer;
|
||||
|
||||
private:
|
||||
@@ -177,6 +189,7 @@ namespace thermion_filament
|
||||
const ResourceLoaderWrapperImpl *const _resourceLoaderWrapper;
|
||||
Engine *_engine;
|
||||
Scene *_scene;
|
||||
View* _view;
|
||||
gltfio::MaterialProvider *_ubershaderProvider = nullptr;
|
||||
gltfio::ResourceLoader *_gltfResourceLoader = nullptr;
|
||||
gltfio::TextureProvider *_stbDecoder = nullptr;
|
||||
@@ -203,9 +216,8 @@ namespace thermion_filament
|
||||
const char *entityName);
|
||||
|
||||
EntityId addGizmo();
|
||||
utils::Entity _gizmo[3];
|
||||
Material* _gizmoMaterial;
|
||||
MaterialInstance* _gizmoMaterialInstances[3];
|
||||
Gizmo* _gizmo = nullptr;
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#endif
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
#include "Aabb2.h"
|
||||
|
||||
typedef int32_t EntityId;
|
||||
typedef int32_t _ManipulatorMode;
|
||||
@@ -244,10 +245,11 @@ extern "C"
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE EntityId create_geometry(void *const viewer, float *vertices, int numVertices, uint16_t *indices, int numIndices, int primitiveType, const char *materialPath);
|
||||
EMSCRIPTEN_KEEPALIVE EntityId get_parent(void *const sceneManager, EntityId child);
|
||||
EMSCRIPTEN_KEEPALIVE void set_parent(void *const sceneManager, EntityId child, EntityId parent);
|
||||
EMSCRIPTEN_KEEPALIVE void set_parent(void *const sceneManager, EntityId child, EntityId parent, bool preserveScaling);
|
||||
EMSCRIPTEN_KEEPALIVE void test_collisions(void *const sceneManager, EntityId entity);
|
||||
EMSCRIPTEN_KEEPALIVE void set_priority(void *const sceneManager, EntityId entityId, int priority);
|
||||
EMSCRIPTEN_KEEPALIVE void get_gizmo(void *const sceneManager, EntityId *out);
|
||||
EMSCRIPTEN_KEEPALIVE Aabb2 get_bounding_box(void *const sceneManager, EntityId entity);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user