diff --git a/example/assets/cube.blend b/example/assets/cube.blend index 335fb3b3..8ac5a7f4 100644 Binary files a/example/assets/cube.blend and b/example/assets/cube.blend differ diff --git a/example/assets/cube.glb b/example/assets/cube.glb index 4ef0781e..e8407372 100644 Binary files a/example/assets/cube.glb and b/example/assets/cube.glb differ diff --git a/example/lib/main.dart b/example/lib/main.dart index ef54b3e5..690b3905 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -220,15 +220,27 @@ class _MyAppState extends State with SingleTickerProviderStateMixin { _cube!, BoneAnimationData( "Bone.001", ["Cube.001"], frameData, 1000.0 / 60.0)); - // , - // "Bone.001", - // "Cube.001", - // BoneTransform([Vec3(x: 0, y: 0.0, z: 0.0)], - // [Quaternion(x: 1, y: 1, z: 1, w: 1)])); - // break; + // , + // "Bone.001", + // "Cube.001", + // BoneTransform([Vec3(x: 0, y: 0.0, z: 0.0)], + // [Quaternion(x: 1, y: 1, z: 1, w: 1)])); + // break; + break; + case 33: + if (_coneHidden) { + _filamentController.reveal(_cube!, "Cone"); + } else { + _filamentController.hide(_cube!, "Cone"); + } + setState(() { + _coneHidden = !_coneHidden; + }); } } + bool _coneHidden = false; + Widget _item({int value = 0, Widget? child = null}) { return GestureDetector( onTap: () { @@ -271,6 +283,9 @@ class _MyAppState extends State with SingleTickerProviderStateMixin { child: Text('remove skybox'), ), _item(value: 3, child: Text('load cube GLB')), + _item( + value: 33, + child: Text(_coneHidden ? 'show cone' : 'hide cone')), _item(value: 4, child: Text('load cube GLTF')), _item(value: 21, child: Text('swap cube texture')), _item(value: 22, child: Text('transform to unit cube')), diff --git a/ios/include/AssetManager.hpp b/ios/include/AssetManager.hpp index 376edbe8..beab0a28 100644 --- a/ios/include/AssetManager.hpp +++ b/ios/include/AssetManager.hpp @@ -64,6 +64,8 @@ namespace polyvox { void setMorphTargetWeights(const char* const entityName, float *weights, int count); void loadTexture(EntityId entity, const char* resourcePath, int renderableIndex); void setAnimationFrame(EntityId entity, int animationIndex, int animationFrame); + bool hide(EntityId entity, const char* meshName); + bool reveal(EntityId entity, const char* meshName); private: AssetLoader* _assetLoader = nullptr; diff --git a/ios/include/PolyvoxFilamentApi.h b/ios/include/PolyvoxFilamentApi.h index b107cbc9..4ee60afe 100644 --- a/ios/include/PolyvoxFilamentApi.h +++ b/ios/include/PolyvoxFilamentApi.h @@ -97,6 +97,8 @@ void set_camera_rotation(void *viewer, float rads, float x, float y, float z); void set_camera_model_matrix(void *viewer, const float *const matrix); void set_camera_focal_length(void *viewer, float focalLength); void set_camera_focus_distance(void *viewer, float focusDistance); +int hide_mesh(void* assetManager, EntityId asset, const char* meshName); +int reveal_mesh(void* assetManager, EntityId asset, const char* meshName); void ios_dummy(); #endif diff --git a/ios/src/AssetManager.cpp b/ios/src/AssetManager.cpp index d4f80348..0bf02531 100644 --- a/ios/src/AssetManager.cpp +++ b/ios/src/AssetManager.cpp @@ -150,20 +150,7 @@ EntityId AssetManager::loadGlb(const char *uri, bool unlit) { _gltfResourceLoader->loadResources(asset); - // const Entity *entities = asset->getEntities(); - - // RenderableManager &rm = _engine->getRenderableManager(); - - // MaterialKey config; - // auto mi_new = _materialProvider->createMaterialInstance(&config, nullptr); - - // for (int i = 0; i < asset->getEntityCount(); i++) { - // auto entityInstance = rm.getInstance(entities[i]); - // auto mi = rm.getMaterialInstanceAt(entityInstance, 0); - // // auto m = mi->getMaterial(); - // // auto shading = m->getShading(); - // // Log("Shading %d", shading); - // } + const Entity *entities = asset->getEntities(); auto lights = asset->getLightEntities(); _scene->addEntities(lights, asset->getLightEntityCount()); @@ -185,10 +172,46 @@ EntityId AssetManager::loadGlb(const char *uri, bool unlit) { _entityIdLookup.emplace(eid, _assets.size()); _assets.push_back(sceneAsset); - + return eid; } +bool AssetManager::hide(EntityId entityId, const char* meshName) { + + auto asset = getAssetByEntityId(entityId); + if(!asset) { + return false; + } + + auto entity = findEntityByName(asset, meshName); + + if(entity.isNull()) { + Log("Mesh %s could not be found", meshName); + return false; + } + _scene->remove(entity); + return true; +} + +bool AssetManager::reveal(EntityId entityId, const char* meshName) { + auto asset = getAssetByEntityId(entityId); + if(!asset) { + Log("No asset found under entity ID"); + return false; + } + + auto entity = findEntityByName(asset, meshName); + + RenderableManager &rm = _engine->getRenderableManager(); + + if(entity.isNull()) { + Log("Mesh %s could not be found", meshName); + return false; + } + _scene->addEntity(entity); + return true; +} + void AssetManager::destroyAll() { for (auto& asset : _assets) { _scene->removeEntities(asset.mAsset->getEntities(), diff --git a/ios/src/PolyvoxFilamentApi.cpp b/ios/src/PolyvoxFilamentApi.cpp index 121a9d08..e2fb6c90 100644 --- a/ios/src/PolyvoxFilamentApi.cpp +++ b/ios/src/PolyvoxFilamentApi.cpp @@ -568,6 +568,22 @@ extern "C" { // fut.wait(); } + FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName) { + //std::packaged_task lambda([=]() mutable { + return ((AssetManager*)assetManager)->hide(asset, meshName); + //}); +// auto fut = _tp->add_task(lambda); +// fut.wait(); + } + + FLUTTER_PLUGIN_EXPORT int reveal_mesh(void* assetManager, EntityId asset, const char* meshName) { + //std::packaged_task lambda([=]() mutable { + return ((AssetManager*)assetManager)->reveal(asset, meshName); + //}); +// auto fut = _tp->add_task(lambda); +// fut.wait(); + } + FLUTTER_PLUGIN_EXPORT void ios_dummy() { Log("Dummy called"); } diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index b225795d..d43ed823 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -459,4 +459,20 @@ class FilamentController { FilamentEntity asset, double rads, double x, double y, double z) async { _nativeLibrary.set_rotation(_assetManager, asset, rads, x, y, z); } + + void hide(FilamentEntity asset, String meshName) { + if (_nativeLibrary.hide_mesh( + _assetManager, asset, meshName.toNativeUtf8().cast()) != + 1) { + throw Exception("Failed to hide mesh $meshName"); + } + } + + void reveal(FilamentEntity asset, String meshName) { + if (_nativeLibrary.reveal_mesh( + _assetManager, asset, meshName.toNativeUtf8().cast()) != + 1) { + throw Exception("Failed to unhide mesh $meshName"); + } + } } diff --git a/lib/generated_bindings.dart b/lib/generated_bindings.dart index 13debb0d..2648b08d 100644 --- a/lib/generated_bindings.dart +++ b/lib/generated_bindings.dart @@ -1146,6 +1146,44 @@ class NativeLibrary { late final _set_camera_focus_distance = _set_camera_focus_distancePtr .asFunction, double)>(); + int hide_mesh( + ffi.Pointer assetManager, + int asset, + ffi.Pointer meshName, + ) { + return _hide_mesh( + assetManager, + asset, + meshName, + ); + } + + late final _hide_meshPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, EntityId, + ffi.Pointer)>>('hide_mesh'); + late final _hide_mesh = _hide_meshPtr.asFunction< + int Function(ffi.Pointer, int, ffi.Pointer)>(); + + int reveal_mesh( + ffi.Pointer assetManager, + int asset, + ffi.Pointer meshName, + ) { + return _reveal_mesh( + assetManager, + asset, + meshName, + ); + } + + late final _reveal_meshPtr = _lookup< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, EntityId, + ffi.Pointer)>>('reveal_mesh'); + late final _reveal_mesh = _reveal_meshPtr.asFunction< + int Function(ffi.Pointer, int, ffi.Pointer)>(); + void ios_dummy() { return _ios_dummy(); } @@ -1155,9 +1193,96 @@ class NativeLibrary { late final _ios_dummy = _ios_dummyPtr.asFunction(); } -class __fsid_t extends ffi.Struct { - @ffi.Array.multi([2]) - external ffi.Array __val; +class __mbstate_t extends ffi.Union { + @ffi.Array.multi([128]) + external ffi.Array __mbstate8; + + @ffi.LongLong() + external int _mbstateL; +} + +class __darwin_pthread_handler_rec extends ffi.Struct { + external ffi + .Pointer)>> + __routine; + + external ffi.Pointer __arg; + + external ffi.Pointer<__darwin_pthread_handler_rec> __next; +} + +class _opaque_pthread_attr_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([56]) + external ffi.Array __opaque; +} + +class _opaque_pthread_cond_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([40]) + external ffi.Array __opaque; +} + +class _opaque_pthread_condattr_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([8]) + external ffi.Array __opaque; +} + +class _opaque_pthread_mutex_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([56]) + external ffi.Array __opaque; +} + +class _opaque_pthread_mutexattr_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([8]) + external ffi.Array __opaque; +} + +class _opaque_pthread_once_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([8]) + external ffi.Array __opaque; +} + +class _opaque_pthread_rwlock_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([192]) + external ffi.Array __opaque; +} + +class _opaque_pthread_rwlockattr_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + @ffi.Array.multi([16]) + external ffi.Array __opaque; +} + +class _opaque_pthread_t extends ffi.Struct { + @ffi.Long() + external int __sig; + + external ffi.Pointer<__darwin_pthread_handler_rec> __cleanup_stack; + + @ffi.Array.multi([8176]) + external ffi.Array __opaque; } class ResourceBuffer extends ffi.Struct { @@ -1194,135 +1319,67 @@ typedef FreeResourceFromOwner = ffi.Pointer< ffi.Void Function(ResourceBuffer, ffi.Pointer)>>; typedef EntityId = ffi.Int32; -const int _STDINT_H = 1; - -const int _FEATURES_H = 1; - -const int _DEFAULT_SOURCE = 1; - -const int __GLIBC_USE_ISOC2X = 1; - -const int __USE_ISOC11 = 1; - -const int __USE_ISOC99 = 1; - -const int __USE_ISOC95 = 1; - -const int _POSIX_SOURCE = 1; - -const int _POSIX_C_SOURCE = 200809; - -const int __USE_POSIX = 1; - -const int __USE_POSIX2 = 1; - -const int __USE_POSIX199309 = 1; - -const int __USE_POSIX199506 = 1; - -const int __USE_XOPEN2K = 1; - -const int __USE_XOPEN2K8 = 1; - -const int _ATFILE_SOURCE = 1; - const int __WORDSIZE = 64; -const int __WORDSIZE_TIME64_COMPAT32 = 1; +const int __DARWIN_ONLY_64_BIT_INO_T = 1; -const int __SYSCALL_WORDSIZE = 64; +const int __DARWIN_ONLY_UNIX_CONFORMANCE = 1; -const int __TIMESIZE = 64; +const int __DARWIN_ONLY_VERS_1050 = 1; -const int __USE_MISC = 1; +const int __DARWIN_UNIX03 = 1; -const int __USE_ATFILE = 1; +const int __DARWIN_64_BIT_INO_T = 1; -const int __USE_FORTIFY_LEVEL = 0; +const int __DARWIN_VERS_1050 = 1; -const int __GLIBC_USE_DEPRECATED_GETS = 0; +const int __DARWIN_NON_CANCELABLE = 0; -const int __GLIBC_USE_DEPRECATED_SCANF = 0; +const String __DARWIN_SUF_EXTSN = '\$DARWIN_EXTSN'; -const int _STDC_PREDEF_H = 1; +const int __DARWIN_C_ANSI = 4096; -const int __STDC_IEC_559__ = 1; +const int __DARWIN_C_FULL = 900000; -const int __STDC_IEC_60559_BFP__ = 201404; +const int __DARWIN_C_LEVEL = 900000; -const int __STDC_IEC_559_COMPLEX__ = 1; +const int __STDC_WANT_LIB_EXT1__ = 1; -const int __STDC_IEC_60559_COMPLEX__ = 201404; +const int __DARWIN_NO_LONG_LONG = 0; -const int __STDC_ISO_10646__ = 201706; +const int _DARWIN_FEATURE_64_BIT_INODE = 1; -const int __GNU_LIBRARY__ = 6; +const int _DARWIN_FEATURE_ONLY_64_BIT_INODE = 1; -const int __GLIBC__ = 2; +const int _DARWIN_FEATURE_ONLY_VERS_1050 = 1; -const int __GLIBC_MINOR__ = 37; +const int _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE = 1; -const int _SYS_CDEFS_H = 1; +const int _DARWIN_FEATURE_UNIX_CONFORMANCE = 3; -const int __THROW = 1; +const int __has_ptrcheck = 0; -const int __THROWNL = 1; +const int __DARWIN_NULL = 0; -const int __glibc_c99_flexarr_available = 1; +const int __PTHREAD_SIZE__ = 8176; -const int __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI = 0; +const int __PTHREAD_ATTR_SIZE__ = 56; -const int __HAVE_GENERIC_SELECTION = 0; +const int __PTHREAD_MUTEXATTR_SIZE__ = 8; -const int __GLIBC_USE_LIB_EXT2 = 1; +const int __PTHREAD_MUTEX_SIZE__ = 56; -const int __GLIBC_USE_IEC_60559_BFP_EXT = 1; +const int __PTHREAD_CONDATTR_SIZE__ = 8; -const int __GLIBC_USE_IEC_60559_BFP_EXT_C2X = 1; +const int __PTHREAD_COND_SIZE__ = 40; -const int __GLIBC_USE_IEC_60559_EXT = 1; +const int __PTHREAD_ONCE_SIZE__ = 8; -const int __GLIBC_USE_IEC_60559_FUNCS_EXT = 1; +const int __PTHREAD_RWLOCK_SIZE__ = 192; -const int __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X = 1; +const int __PTHREAD_RWLOCKATTR_SIZE__ = 16; -const int __GLIBC_USE_IEC_60559_TYPES_EXT = 1; - -const int _BITS_TYPES_H = 1; - -const int _BITS_TYPESIZES_H = 1; - -const int __OFF_T_MATCHES_OFF64_T = 1; - -const int __INO_T_MATCHES_INO64_T = 1; - -const int __RLIM_T_MATCHES_RLIM64_T = 1; - -const int __STATFS_MATCHES_STATFS64 = 1; - -const int __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 = 1; - -const int __FD_SETSIZE = 1024; - -const int _BITS_TIME64_H = 1; - -const int _BITS_WCHAR_H = 1; - -const int __WCHAR_MAX = 2147483647; - -const int __WCHAR_MIN = -2147483648; - -const int _BITS_STDINT_INTN_H = 1; - -const int _BITS_STDINT_UINTN_H = 1; - -const int INT8_MIN = -128; - -const int INT16_MIN = -32768; - -const int INT32_MIN = -2147483648; - -const int INT64_MIN = -9223372036854775808; +const int USER_ADDR_NULL = 0; const int INT8_MAX = 127; @@ -1332,6 +1389,14 @@ const int INT32_MAX = 2147483647; const int INT64_MAX = 9223372036854775807; +const int INT8_MIN = -128; + +const int INT16_MIN = -32768; + +const int INT32_MIN = -2147483648; + +const int INT64_MIN = -9223372036854775808; + const int UINT8_MAX = 255; const int UINT16_MAX = 65535; @@ -1366,54 +1431,66 @@ const int UINT_LEAST64_MAX = -1; const int INT_FAST8_MIN = -128; -const int INT_FAST16_MIN = -9223372036854775808; +const int INT_FAST16_MIN = -32768; -const int INT_FAST32_MIN = -9223372036854775808; +const int INT_FAST32_MIN = -2147483648; const int INT_FAST64_MIN = -9223372036854775808; const int INT_FAST8_MAX = 127; -const int INT_FAST16_MAX = 9223372036854775807; +const int INT_FAST16_MAX = 32767; -const int INT_FAST32_MAX = 9223372036854775807; +const int INT_FAST32_MAX = 2147483647; const int INT_FAST64_MAX = 9223372036854775807; const int UINT_FAST8_MAX = 255; -const int UINT_FAST16_MAX = -1; +const int UINT_FAST16_MAX = 65535; -const int UINT_FAST32_MAX = -1; +const int UINT_FAST32_MAX = 4294967295; const int UINT_FAST64_MAX = -1; -const int INTPTR_MIN = -9223372036854775808; - const int INTPTR_MAX = 9223372036854775807; -const int UINTPTR_MAX = -1; +const int INTPTR_MIN = -9223372036854775808; -const int INTMAX_MIN = -9223372036854775808; +const int UINTPTR_MAX = -1; const int INTMAX_MAX = 9223372036854775807; const int UINTMAX_MAX = -1; +const int INTMAX_MIN = -9223372036854775808; + const int PTRDIFF_MIN = -9223372036854775808; const int PTRDIFF_MAX = 9223372036854775807; +const int SIZE_MAX = -1; + +const int RSIZE_MAX = 9223372036854775807; + +const int WCHAR_MAX = 2147483647; + +const int WCHAR_MIN = -2147483648; + +const int WINT_MIN = -2147483648; + +const int WINT_MAX = 2147483647; + const int SIG_ATOMIC_MIN = -2147483648; const int SIG_ATOMIC_MAX = 2147483647; -const int SIZE_MAX = -1; +const int __DARWIN_WCHAR_MAX = 2147483647; -const int WCHAR_MIN = -2147483648; +const int __DARWIN_WCHAR_MIN = -2147483648; -const int WCHAR_MAX = 2147483647; +const int __DARWIN_WEOF = -1; -const int WINT_MIN = 0; +const int _FORTIFY_SOURCE = 2; -const int WINT_MAX = 4294967295; +const int NULL = 0;