expose addAnimationComponent and dont add by default on loadGlb
This commit is contained in:
@@ -130,7 +130,7 @@ namespace flutter_filament
|
||||
void addCollisionComponent(EntityId entity, void (*onCollisionCallback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform);
|
||||
void removeCollisionComponent(EntityId entityId);
|
||||
void setParent(EntityId child, EntityId parent);
|
||||
void addAnimatableComponent(EntityId entity);
|
||||
void addAnimationComponent(EntityId entity);
|
||||
|
||||
/// @brief returns the number of instances of the FilamentAsset represented by the given entity.
|
||||
/// @param entityId
|
||||
|
||||
@@ -589,6 +589,10 @@ extern "C"
|
||||
((SceneManager*)sceneManager)->addCollisionComponent(entityId, onCollisionCallback, affectsCollidingTransform);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void add_animation_component(void *const sceneManager, EntityId entityId) {
|
||||
((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, (size_t)numVertices, indices, numIndices, materialPath);
|
||||
}
|
||||
|
||||
@@ -250,7 +250,6 @@ namespace flutter_filament
|
||||
auto instanceEntity = inst->getRoot();
|
||||
auto instanceEntityId = Entity::smuggle(instanceEntity);
|
||||
_instances.emplace(instanceEntityId, inst);
|
||||
addAnimatableComponent(instanceEntityId);
|
||||
}
|
||||
|
||||
asset->releaseSourceData();
|
||||
@@ -260,7 +259,7 @@ namespace flutter_filament
|
||||
return eid;
|
||||
}
|
||||
|
||||
void SceneManager::addAnimatableComponent(EntityId entityId) {
|
||||
void SceneManager::addAnimationComponent(EntityId entityId) {
|
||||
|
||||
auto* instance = getInstanceByEntityId(entityId);
|
||||
if (!instance)
|
||||
@@ -387,7 +386,7 @@ namespace flutter_filament
|
||||
const auto &pos = _instances.find(entityId);
|
||||
if (pos == _instances.end())
|
||||
{
|
||||
Log("Failed to find FilamentInstance for entity %d", entityId);
|
||||
// Log("Failed to find FilamentInstance for entity %d", entityId);
|
||||
return nullptr;
|
||||
}
|
||||
return pos->second;
|
||||
@@ -398,7 +397,7 @@ namespace flutter_filament
|
||||
const auto &pos = _assets.find(entityId);
|
||||
if (pos == _assets.end())
|
||||
{
|
||||
Log("Failed to find FilamentAsset for entity %d", entityId);
|
||||
// Log("Failed to find FilamentAsset for entity %d", entityId);
|
||||
return nullptr;
|
||||
}
|
||||
return pos->second;
|
||||
@@ -561,9 +560,9 @@ namespace flutter_filament
|
||||
// {
|
||||
// _engine->destroy(sceneAsset.texture);
|
||||
// }
|
||||
|
||||
utils::EntityManager &em = utils::EntityManager::get();
|
||||
em.destroy(entity);
|
||||
//
|
||||
// utils::EntityManager &em = utils::EntityManager::get();
|
||||
// em.destroy(entity);
|
||||
}
|
||||
|
||||
void SceneManager::setMorphTargetWeights(EntityId entityId, const char *const entityName, const float *const weights, const int count)
|
||||
@@ -604,13 +603,16 @@ namespace flutter_filament
|
||||
utils::Entity SceneManager::findChildEntityByName(EntityId entityId, const char *entityName) {
|
||||
std::lock_guard lock(_mutex);
|
||||
|
||||
const auto &pos = _instances.find(entityId);
|
||||
if (pos == _instances.end())
|
||||
auto* instance = getInstanceByEntityId(entityId);
|
||||
if (!instance)
|
||||
{
|
||||
Log("Couldn't find asset under specified entity id.");
|
||||
return utils::Entity();
|
||||
auto* asset = getAssetByEntityId(entityId);
|
||||
if(!asset) {
|
||||
return utils::Entity();
|
||||
}
|
||||
instance = asset->getInstance();
|
||||
}
|
||||
const auto* instance = pos->second;
|
||||
|
||||
|
||||
const auto entity = findEntityByName(instance, entityName);
|
||||
|
||||
@@ -1199,7 +1201,6 @@ namespace flutter_filament
|
||||
return;
|
||||
} else {
|
||||
instance = asset->getInstance();
|
||||
|
||||
}
|
||||
}
|
||||
auto collisionInstance = _collisionComponentManager->addComponent(instance->getRoot());
|
||||
@@ -1212,20 +1213,20 @@ namespace flutter_filament
|
||||
const auto *instance = getInstanceByEntityId(entityId);
|
||||
if(!instance) {
|
||||
auto asset = getAssetByEntityId(entityId);
|
||||
if(!asset) {
|
||||
if(asset) {
|
||||
instance = asset->getInstance();
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const auto entity = Entity::import(entityId);
|
||||
|
||||
const auto& tm = _engine->getTransformManager();
|
||||
|
||||
auto transformInstance = tm.getInstance(instance->getRoot());
|
||||
auto worldTransform = tm.getWorldTransform(transformInstance);
|
||||
// Log("World transform for %d is %f %f %f", entityId, worldTransform[3][0], worldTransform[3][1], worldTransform[3][2]);
|
||||
auto aabb = instance->getBoundingBox();
|
||||
aabb = aabb.transform(worldTransform);
|
||||
_collisionComponentManager->collides(entity, aabb);
|
||||
_collisionComponentManager->collides(instance->getRoot(), aabb);
|
||||
}
|
||||
|
||||
void SceneManager::updateAnimations() {
|
||||
@@ -1248,7 +1249,6 @@ namespace flutter_filament
|
||||
Aabb boundingBox;
|
||||
if (pos == _instances.end())
|
||||
{
|
||||
Log("WARNING: SceneAsset not found for entity.");
|
||||
isCollidable = false;
|
||||
entity = Entity::import(entityId);
|
||||
} else {
|
||||
|
||||
@@ -610,12 +610,18 @@ abstract class FilamentController {
|
||||
///
|
||||
Future setRecordingOutputDirectory(String outputDirectory);
|
||||
|
||||
// Stream get keyboardFocusRequested;
|
||||
// void requestKeyboardFocus();
|
||||
|
||||
///
|
||||
/// Attach the keyboard/mouse to [entity].
|
||||
///
|
||||
Future<EntityTransformController> control(FilamentEntity entity,
|
||||
{double? translationSpeed, String? forwardAnimation});
|
||||
|
||||
///
|
||||
/// An [entity] will only be animatable after an animation component is attached.
|
||||
/// Any calls to [playAnimation]/[setBoneAnimation]/[setMorphAnimation] will have no visual effect until [addAnimationComponent] has been called on the instance.
|
||||
///
|
||||
Future addAnimationComponent(FilamentEntity entity);
|
||||
|
||||
///
|
||||
/// Makes [collidableEntity] collidable with
|
||||
/// (a) any entity whose transform is being controlled (via [control]) or
|
||||
|
||||
@@ -1269,7 +1269,8 @@ class FilamentControllerFFI extends FilamentController {
|
||||
final outPtr = allocator<EntityId>(1);
|
||||
outPtr.value = 0;
|
||||
|
||||
pick_ffi(_viewer!, x, textureDetails.value!.height - y, outPtr);
|
||||
pick_ffi(_viewer!, (x * _pixelRatio).toInt(),
|
||||
textureDetails.value!.height - (y * _pixelRatio).toInt(), outPtr);
|
||||
int wait = 0;
|
||||
while (outPtr.value == 0) {
|
||||
await Future.delayed(const Duration(milliseconds: 32));
|
||||
@@ -1497,6 +1498,11 @@ class FilamentControllerFFI extends FilamentController {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future addAnimationComponent(FilamentEntity entity) async {
|
||||
add_animation_component(_sceneManager!, entity);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FilamentEntity> createGeometry(
|
||||
List<double> vertices, List<int> indices, String? materialPath) async {
|
||||
|
||||
@@ -225,10 +225,10 @@ external int get_instance_count(
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Int Function(
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<ffi.Void>, EntityId, ffi.Pointer<EntityId>)>(
|
||||
symbol: 'get_instances', assetId: 'flutter_filament_plugin')
|
||||
external int get_instances(
|
||||
external void get_instances(
|
||||
ffi.Pointer<ffi.Void> sceneManager,
|
||||
int entityId,
|
||||
ffi.Pointer<EntityId> out,
|
||||
@@ -931,6 +931,13 @@ external void add_collision_component(
|
||||
bool affectsCollidingTransform,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>(
|
||||
symbol: 'add_animation_component', assetId: 'flutter_filament_plugin')
|
||||
external void add_animation_component(
|
||||
ffi.Pointer<ffi.Void> sceneManager,
|
||||
int entityId,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Float>,
|
||||
ffi.Int, ffi.Pointer<ffi.Uint16>, ffi.Int, ffi.Pointer<ffi.Char>)>(
|
||||
|
||||
Reference in New Issue
Block a user