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