feat: add getAncestor method
This commit is contained in:
@@ -181,6 +181,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);
|
||||
EntityId getAncestor(EntityId child);
|
||||
void setParent(EntityId child, EntityId parent, bool preserveScaling);
|
||||
bool addAnimationComponent(EntityId entity);
|
||||
void removeAnimationComponent(EntityId entity);
|
||||
|
||||
@@ -251,6 +251,7 @@ extern "C"
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE EntityId create_geometry(void *const sceneManager, 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 EntityId get_ancestor(void *const sceneManager, EntityId child);
|
||||
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);
|
||||
|
||||
@@ -1542,6 +1542,25 @@ namespace thermion_filament
|
||||
return Entity::smuggle(parent);
|
||||
}
|
||||
|
||||
EntityId SceneManager::getAncestor(EntityId childEntityId)
|
||||
{
|
||||
auto &tm = _engine->getTransformManager();
|
||||
const auto child = Entity::import(childEntityId);
|
||||
auto transformInstance = tm.getInstance(child);
|
||||
Entity parent;
|
||||
|
||||
while(true) {
|
||||
auto newParent = tm.getParent(transformInstance);
|
||||
if(newParent.isNull()) {
|
||||
break;
|
||||
}
|
||||
parent = newParent;
|
||||
transformInstance = tm.getInstance(parent);
|
||||
}
|
||||
|
||||
return Entity::smuggle(parent);
|
||||
}
|
||||
|
||||
void SceneManager::setParent(EntityId childEntityId, EntityId parentEntityId, bool preserveScaling)
|
||||
{
|
||||
auto &tm = _engine->getTransformManager();
|
||||
@@ -1561,8 +1580,6 @@ namespace thermion_filament
|
||||
return;
|
||||
}
|
||||
|
||||
Log("Parenting child entity %d to new parent entity %d", childEntityId, parentEntityId);
|
||||
|
||||
if (preserveScaling)
|
||||
{
|
||||
auto parentTransform = tm.getWorldTransform(parentInstance);
|
||||
|
||||
@@ -851,6 +851,10 @@ extern "C"
|
||||
return ((SceneManager *)sceneManager)->getParent(child);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE EntityId get_ancestor(void *const sceneManager, EntityId child) {
|
||||
return ((SceneManager *)sceneManager)->getAncestor(child);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_parent(void *const sceneManager, EntityId child, EntityId parent, bool preserveScaling)
|
||||
{
|
||||
((SceneManager *)sceneManager)->setParent(child, parent, preserveScaling);
|
||||
|
||||
Reference in New Issue
Block a user