Skip to content

Commit

Permalink
feat: scene.entityCount
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Apr 5, 2024
1 parent baff0f8 commit 5de3a70
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions package/cpp/core/SceneWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void margelo::SceneWrapper::loadHybridMethods() {
registerHybridMethod("removeEntity", &SceneWrapper::removeEntity, this);
registerHybridMethod("addAssetEntities", &SceneWrapper::addAssetEntities, this);
registerHybridMethod("removeAssetEntities", &SceneWrapper::removeAssetEntities, this);
registerHybridGetter("entityCount", &SceneWrapper::getEntityCount, this);
}

void margelo::SceneWrapper::addEntity(const std::shared_ptr<EntityWrapper>& entity) {
Expand Down Expand Up @@ -74,4 +75,8 @@ void SceneWrapper::addAssetEntities(const std::shared_ptr<FilamentAssetWrapper>&
addAsset(filamentAsset);
}

int SceneWrapper::getEntityCount() {
return _scene->getEntityCount();
}

} // namespace margelo
2 changes: 2 additions & 0 deletions package/cpp/core/SceneWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ class SceneWrapper : public HybridObject {
* Adds all entities associated with the provided asset to the scene.
*/
void addAssetEntities(const std::shared_ptr<FilamentAssetWrapper>& asset);

int getEntityCount();
};
} // namespace margelo
7 changes: 4 additions & 3 deletions package/example/src/hooks/useDefaultLight.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Platform } from 'react-native'
import { Engine, useAsset, useWorkletEffect } from 'react-native-filament'
import { Engine, useAsset, useScene, useWorkletEffect } from 'react-native-filament'

const indirectLightPath = Platform.select({
android: 'custom/default_env_ibl.ktx',
Expand All @@ -8,12 +8,13 @@ const indirectLightPath = Platform.select({

export function useDefaultLight(engine: Engine) {
const lightBuffer = useAsset({ path: indirectLightPath })
const scene = useScene(engine)

useWorkletEffect(() => {
'worklet'
if (lightBuffer == null) return
engine.setIndirectLight(lightBuffer)
const directionalLight = engine.createLightEntity('directional', 6500, 10000, 0, -1, 0, true)
engine.getScene().addEntity(directionalLight)
}, [lightBuffer])
scene.addEntity(directionalLight)
}, [lightBuffer, scene])
}
5 changes: 5 additions & 0 deletions package/src/types/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ export interface Scene {
* Removes all entities associated with the given asset from the scene.
*/
removeAssetEntities(asset: FilamentAsset): void

/**
* Returns the number of entities in the scene.
*/
readonly entityCount: number
}

0 comments on commit 5de3a70

Please sign in to comment.