add (very rough) gizmo, restructure Dart package into library, add EntityListWidget
This commit is contained in:
@@ -248,6 +248,7 @@ namespace flutter_filament
|
||||
.build(*_engine, imageEntity);
|
||||
_imageEntity = &imageEntity;
|
||||
_scene->addEntity(imageEntity);
|
||||
Log("Added imageEntity %d", imageEntity);
|
||||
}
|
||||
|
||||
void FilamentViewer::setAntiAliasing(bool msaa, bool fxaa, bool taa) {
|
||||
@@ -320,6 +321,9 @@ namespace flutter_filament
|
||||
int32_t FilamentViewer::addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows)
|
||||
{
|
||||
auto light = EntityManager::get().create();
|
||||
auto& transformManager = _engine->getTransformManager();
|
||||
transformManager.create(light);
|
||||
auto parent = transformManager.getInstance(light);
|
||||
auto builder = LightManager::Builder(t)
|
||||
.color(Color::cct(colour))
|
||||
.intensity(intensity)
|
||||
@@ -329,6 +333,7 @@ namespace flutter_filament
|
||||
.build(*_engine, light);
|
||||
_scene->addEntity(light);
|
||||
_lights.push_back(light);
|
||||
|
||||
auto entityId = Entity::smuggle(light);
|
||||
Log("Added light under entity ID %d of type %d with colour %f intensity %f at (%f, %f, %f) with direction (%f, %f, %f) with shadows %d", entityId, t, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows);
|
||||
return entityId;
|
||||
@@ -1450,7 +1455,7 @@ namespace flutter_filament
|
||||
});
|
||||
}
|
||||
|
||||
EntityId FilamentViewer::createGeometry(float *vertices, uint32_t numVertices, uint16_t *indices, uint32_t numIndices, const char* materialPath)
|
||||
EntityId FilamentViewer::createGeometry(float *vertices, uint32_t numVertices, uint16_t *indices, uint32_t numIndices, RenderableManager::PrimitiveType primitiveType, const char* materialPath)
|
||||
{
|
||||
|
||||
float *verticesCopy = (float*)malloc(numVertices * sizeof(float));
|
||||
@@ -1499,7 +1504,7 @@ namespace flutter_filament
|
||||
RenderableManager::Builder builder = RenderableManager::Builder(1);
|
||||
builder
|
||||
.boundingBox({{minX, minY, minZ}, {maxX, maxY, maxZ}})
|
||||
.geometry(0, RenderableManager::PrimitiveType::TRIANGLES,
|
||||
.geometry(0, primitiveType,
|
||||
vb, ib, 0, numIndices)
|
||||
.culling(false)
|
||||
.receiveShadows(false)
|
||||
@@ -1510,7 +1515,8 @@ namespace flutter_filament
|
||||
auto result = builder.build(*_engine, renderable);
|
||||
|
||||
_scene->addEntity(renderable);
|
||||
Log("Created geometry with result %d", result);
|
||||
|
||||
Log("Created geometry with primitive type %d (result %d)", primitiveType, result);
|
||||
|
||||
return Entity::smuggle(renderable);
|
||||
}
|
||||
|
||||
@@ -597,8 +597,15 @@ extern "C"
|
||||
((SceneManager*)sceneManager)->addAnimationComponent(entityId);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT EntityId create_geometry(void *const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, const char* materialPath) {
|
||||
return ((FilamentViewer*)viewer)->createGeometry(vertices, (uint32_t)numVertices, indices, numIndices, materialPath);
|
||||
FLUTTER_PLUGIN_EXPORT EntityId create_geometry(void *const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, int primitiveType, const char* materialPath) {
|
||||
return ((FilamentViewer*)viewer)->createGeometry(
|
||||
vertices,
|
||||
(uint32_t)numVertices,
|
||||
indices,
|
||||
numIndices,
|
||||
(filament::RenderableManager::PrimitiveType)primitiveType,
|
||||
materialPath
|
||||
);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT EntityId find_child_entity_by_name(void *const sceneManager, const EntityId parent, const char* name) {
|
||||
@@ -614,4 +621,12 @@ extern "C"
|
||||
((SceneManager*)sceneManager)->testCollisions(entity);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_priority(void *const sceneManager, EntityId entity, int priority) {
|
||||
((SceneManager*)sceneManager)->setPriority(entity, priority);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void get_gizmo(void *const sceneManager, EntityId* out) {
|
||||
return ((SceneManager*)sceneManager)->getGizmo(out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ public:
|
||||
_t = new std::thread([this]() {
|
||||
auto last = std::chrono::high_resolution_clock::now();
|
||||
while (!_stop) {
|
||||
last = std::chrono::high_resolution_clock::now();
|
||||
|
||||
if (_rendering) {
|
||||
// auto frameStart = std::chrono::high_resolution_clock::now();
|
||||
@@ -48,6 +47,8 @@ public:
|
||||
// auto frameEnd = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
last = std::chrono::high_resolution_clock::now();
|
||||
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
|
||||
float elapsed = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - last).count());
|
||||
@@ -58,7 +59,6 @@ public:
|
||||
|
||||
if(_tasks.empty()) {
|
||||
_cond.wait_for(lock, std::chrono::duration<float, std::milli>(1));
|
||||
continue;
|
||||
}
|
||||
while(!_tasks.empty()) {
|
||||
task = std::move(_tasks.front());
|
||||
@@ -571,10 +571,10 @@ FLUTTER_PLUGIN_EXPORT void add_bone_animation_ffi(
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi() { Log("Dummy called"); }
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_geometry_ffi(void* const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, const char* materialPath, void (*callback)(EntityId) ) {
|
||||
FLUTTER_PLUGIN_EXPORT void create_geometry_ffi(void* const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, int primitiveType, const char* materialPath, void (*callback)(EntityId) ) {
|
||||
std::packaged_task<EntityId()> lambda(
|
||||
[=] {
|
||||
auto entity = create_geometry(viewer, vertices, numVertices, indices, numIndices, materialPath);
|
||||
auto entity = create_geometry(viewer, vertices, numVertices, indices, numIndices, primitiveType, materialPath);
|
||||
callback(entity);
|
||||
return entity;
|
||||
});
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "Log.hpp"
|
||||
#include "SceneManager.hpp"
|
||||
|
||||
#include "material/FileMaterialProvider.hpp"
|
||||
#include "gltfio/materials/uberarchive.h"
|
||||
|
||||
extern "C"
|
||||
@@ -88,6 +87,8 @@ namespace flutter_filament
|
||||
_collisionComponentManager = new CollisionComponentManager(tm);
|
||||
_animationComponentManager = new AnimationComponentManager(tm, _engine->getRenderableManager());
|
||||
|
||||
addGizmo();
|
||||
|
||||
}
|
||||
|
||||
SceneManager::~SceneManager()
|
||||
@@ -307,8 +308,10 @@ namespace flutter_filament
|
||||
if(asset) {
|
||||
instance = asset->getInstance();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// Log("Failed to find glTF instance under entityID %d, hiding as regular entity", entityId);
|
||||
_scene->remove(Entity::import(entityId));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
utils::Entity entity;
|
||||
@@ -342,7 +345,9 @@ namespace flutter_filament
|
||||
if(asset) {
|
||||
instance = asset->getInstance();
|
||||
} else {
|
||||
return false;
|
||||
// Log("Failed to find glTF instance under entityID %d, revealing as regular entity", entityId);
|
||||
_scene->addEntity(Entity::import(entityId));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1563,4 +1568,161 @@ namespace flutter_filament
|
||||
return _ncm->getName(inst);
|
||||
}
|
||||
|
||||
void SceneManager::setPriority(EntityId entityId, int priority) {
|
||||
auto& rm = _engine->getRenderableManager();
|
||||
auto renderableInstance = rm.getInstance(Entity::import(entityId));
|
||||
if(!renderableInstance.isValid()) {
|
||||
Log("Error: invalid renderable, did you pass the correct entity?", priority);
|
||||
return;
|
||||
}
|
||||
rm.setPriority(renderableInstance, priority);
|
||||
Log("Set instance renderable priority to %d", priority);
|
||||
}
|
||||
|
||||
EntityId SceneManager::addGizmo() {
|
||||
auto mat = _resourceLoaderWrapper->load("file:///Users/nickfisher/Documents/polyvox/flutter/flutter_filament/materials/gizmo.filamat");
|
||||
_gizmoMaterial =
|
||||
Material::Builder()
|
||||
.package(mat.data, mat.size)
|
||||
// .package(GIZMO_GIZMO_DATA, GIZMO_GIZMO_SIZE)
|
||||
.build(*_engine);
|
||||
|
||||
auto vertexCount = 9;
|
||||
|
||||
float* vertices = new float[vertexCount * 3] {
|
||||
-0.05, 0.0f, 0.05f,
|
||||
0.05f, 0.0f, 0.05f,
|
||||
0.05f, 0.0f, -0.05f,
|
||||
-0.05f, 0.0f, -0.05f,
|
||||
-0.05f, 1.0f, 0.05f,
|
||||
0.05f, 1.0f, 0.05f,
|
||||
0.05f, 1.0f, -0.05f,
|
||||
-0.05f, 1.0f, -0.05f,
|
||||
0.00f, 1.1f, 0.0f
|
||||
};
|
||||
|
||||
VertexBuffer::BufferDescriptor::Callback vertexCallback = [](void *buf, size_t,
|
||||
void *data)
|
||||
{
|
||||
free((void*)buf);
|
||||
};
|
||||
|
||||
auto indexCount = 42;
|
||||
uint16_t* indices = new uint16_t[indexCount] {
|
||||
//bottom quad
|
||||
0,1,2,
|
||||
0,2,3,
|
||||
// top "cone"
|
||||
4,5,8,
|
||||
5,6,8,
|
||||
4,7,8,
|
||||
6,7,8,
|
||||
// front
|
||||
0,1,4,
|
||||
1,5,4,
|
||||
// right
|
||||
1,2,5,
|
||||
2,6,5,
|
||||
// back
|
||||
2,6,7,
|
||||
7,3,2,
|
||||
// left
|
||||
0,4,7,
|
||||
7,3,0
|
||||
|
||||
};
|
||||
|
||||
IndexBuffer::BufferDescriptor::Callback indexCallback = [](void *buf, size_t,
|
||||
void *data)
|
||||
{
|
||||
free((void*)buf);
|
||||
};
|
||||
|
||||
auto vb = VertexBuffer::Builder()
|
||||
.vertexCount(vertexCount)
|
||||
.bufferCount(1)
|
||||
.attribute(
|
||||
VertexAttribute::POSITION, 0, VertexBuffer::AttributeType::FLOAT3)
|
||||
.build(*_engine);
|
||||
|
||||
vb->setBufferAt(
|
||||
*_engine,
|
||||
0,
|
||||
VertexBuffer::BufferDescriptor(vertices, vb->getVertexCount() * sizeof(filament::math::float3), 0, vertexCallback)
|
||||
);
|
||||
|
||||
auto ib = IndexBuffer::Builder().indexCount(indexCount).bufferType(IndexBuffer::IndexType::USHORT).build(*_engine);
|
||||
ib->setBuffer(*_engine, IndexBuffer::BufferDescriptor(indices, ib->getIndexCount() * sizeof(uint16_t), 0, indexCallback));
|
||||
|
||||
auto &entityManager = EntityManager::get();
|
||||
|
||||
_gizmoY = entityManager.create();
|
||||
auto materialY = _gizmoMaterial->createInstance();
|
||||
materialY->setParameter("color", math::float3 { 1.0f, 0.0f, 0.0f });
|
||||
RenderableManager::Builder(1)
|
||||
.boundingBox({{}, {1.0f, 1.0f, 1.0f}})
|
||||
.material(0, materialY)
|
||||
.geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb,
|
||||
ib, 0, indexCount)
|
||||
.culling(false)
|
||||
.build(*_engine, _gizmoY);
|
||||
|
||||
_gizmoX = entityManager.create();
|
||||
auto materialX = _gizmoMaterial->createInstance();
|
||||
materialX->setParameter("color", math::float3 { 0.0f, 1.0f, 0.0f });
|
||||
auto xTransform = math::mat4f::translation(math::float3 { 0.0f, 0.05f, -0.05f}) * math::mat4f::rotation(-math::F_PI_2, math::float3 { 0, 0, 1 });
|
||||
auto* instanceBufferX = InstanceBuffer::Builder(1).localTransforms(&xTransform).build(*_engine);
|
||||
RenderableManager::Builder(1)
|
||||
.boundingBox({{}, {1.0f, 1.0f, 1.0f}})
|
||||
.instances(1, instanceBufferX)
|
||||
.material(0, materialX)
|
||||
.geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb,
|
||||
ib, 0, indexCount)
|
||||
.culling(false)
|
||||
.build(*_engine, _gizmoX);
|
||||
|
||||
_gizmoZ = entityManager.create();
|
||||
auto materialZ = _gizmoMaterial->createInstance();
|
||||
materialZ->setParameter("color", math::float3 { 0.0f, 0.0f, 1.0f });
|
||||
auto zTransform = math::mat4f::translation(math::float3 { 0.0f, 0.05f, -0.05f}) * math::mat4f::rotation(3 * math::F_PI_2, math::float3 { 1, 0, 0 });
|
||||
auto* instanceBufferZ = InstanceBuffer::Builder(1).localTransforms(&zTransform).build(*_engine);
|
||||
RenderableManager::Builder(1)
|
||||
.boundingBox({{}, {1.0f, 1.0f, 1.0f}})
|
||||
.instances(1, instanceBufferZ)
|
||||
.material(0, materialZ)
|
||||
.geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb,
|
||||
ib, 0, indexCount)
|
||||
.culling(false)
|
||||
.build(*_engine, _gizmoZ);
|
||||
|
||||
|
||||
// auto localTransforms = math::mat4f[3] {
|
||||
// math::mat4f(),
|
||||
// math::mat4f::translation(math::float3 { 0.0f, 0.05f, -0.05f}) * math::mat4f::rotation(3 * math::F_PI_2, math::float3 { 1, 0, 0 }) ,
|
||||
// math::mat4f::translation(math::float3 { 0.0f, 0.05f, -0.05f}) * math::mat4f::rotation(math::F_PI_2, math::float3 { 0, 0, 1 })
|
||||
// };
|
||||
|
||||
|
||||
// RenderableManager::Builder(1)
|
||||
// .boundingBox({{}, {1.0f, 1.0f, 1.0f}})
|
||||
// .instances(3, instanceBuffer)
|
||||
// .material(0, _gizmoMaterial->getDefaultInstance())
|
||||
// .geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vb,
|
||||
// ib, 0, indexCount)
|
||||
// .culling(false)
|
||||
// .build(*_engine, _gizmo);
|
||||
|
||||
auto& rm = _engine->getRenderableManager();
|
||||
rm.setPriority(rm.getInstance(_gizmoX), 7);
|
||||
rm.setPriority(rm.getInstance(_gizmoY), 7);
|
||||
rm.setPriority(rm.getInstance(_gizmoZ), 7);
|
||||
return Entity::smuggle(_gizmoX);
|
||||
}
|
||||
|
||||
void SceneManager::getGizmo(EntityId* out) {
|
||||
out[0] = Entity::smuggle(_gizmoX);
|
||||
out[1] = Entity::smuggle(_gizmoY);
|
||||
out[2] = Entity::smuggle(_gizmoZ);
|
||||
}
|
||||
|
||||
} // namespace flutter_filament
|
||||
|
||||
Reference in New Issue
Block a user