add hide/reveal entity

This commit is contained in:
Nick Fisher
2023-07-03 22:54:27 +08:00
parent 4adf8bbf80
commit 313fb9bebf
9 changed files with 288 additions and 137 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -220,15 +220,27 @@ class _MyAppState extends State<MyApp> 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<MyApp> 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')),

View File

@@ -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;

View File

@@ -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

View File

@@ -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(),

View File

@@ -568,6 +568,22 @@ extern "C" {
// fut.wait();
}
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName) {
//std::packaged_task<void()> 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<void()> 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");
}

View File

@@ -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<Char>()) !=
1) {
throw Exception("Failed to hide mesh $meshName");
}
}
void reveal(FilamentEntity asset, String meshName) {
if (_nativeLibrary.reveal_mesh(
_assetManager, asset, meshName.toNativeUtf8().cast<Char>()) !=
1) {
throw Exception("Failed to unhide mesh $meshName");
}
}
}

View File

@@ -1146,6 +1146,44 @@ class NativeLibrary {
late final _set_camera_focus_distance = _set_camera_focus_distancePtr
.asFunction<void Function(ffi.Pointer<ffi.Void>, double)>();
int hide_mesh(
ffi.Pointer<ffi.Void> assetManager,
int asset,
ffi.Pointer<ffi.Char> meshName,
) {
return _hide_mesh(
assetManager,
asset,
meshName,
);
}
late final _hide_meshPtr = _lookup<
ffi.NativeFunction<
ffi.Int Function(ffi.Pointer<ffi.Void>, EntityId,
ffi.Pointer<ffi.Char>)>>('hide_mesh');
late final _hide_mesh = _hide_meshPtr.asFunction<
int Function(ffi.Pointer<ffi.Void>, int, ffi.Pointer<ffi.Char>)>();
int reveal_mesh(
ffi.Pointer<ffi.Void> assetManager,
int asset,
ffi.Pointer<ffi.Char> meshName,
) {
return _reveal_mesh(
assetManager,
asset,
meshName,
);
}
late final _reveal_meshPtr = _lookup<
ffi.NativeFunction<
ffi.Int Function(ffi.Pointer<ffi.Void>, EntityId,
ffi.Pointer<ffi.Char>)>>('reveal_mesh');
late final _reveal_mesh = _reveal_meshPtr.asFunction<
int Function(ffi.Pointer<ffi.Void>, int, ffi.Pointer<ffi.Char>)>();
void ios_dummy() {
return _ios_dummy();
}
@@ -1155,9 +1193,96 @@ class NativeLibrary {
late final _ios_dummy = _ios_dummyPtr.asFunction<void Function()>();
}
class __fsid_t extends ffi.Struct {
@ffi.Array.multi([2])
external ffi.Array<ffi.Int> __val;
class __mbstate_t extends ffi.Union {
@ffi.Array.multi([128])
external ffi.Array<ffi.Char> __mbstate8;
@ffi.LongLong()
external int _mbstateL;
}
class __darwin_pthread_handler_rec extends ffi.Struct {
external ffi
.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>
__routine;
external ffi.Pointer<ffi.Void> __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<ffi.Char> __opaque;
}
class _opaque_pthread_cond_t extends ffi.Struct {
@ffi.Long()
external int __sig;
@ffi.Array.multi([40])
external ffi.Array<ffi.Char> __opaque;
}
class _opaque_pthread_condattr_t extends ffi.Struct {
@ffi.Long()
external int __sig;
@ffi.Array.multi([8])
external ffi.Array<ffi.Char> __opaque;
}
class _opaque_pthread_mutex_t extends ffi.Struct {
@ffi.Long()
external int __sig;
@ffi.Array.multi([56])
external ffi.Array<ffi.Char> __opaque;
}
class _opaque_pthread_mutexattr_t extends ffi.Struct {
@ffi.Long()
external int __sig;
@ffi.Array.multi([8])
external ffi.Array<ffi.Char> __opaque;
}
class _opaque_pthread_once_t extends ffi.Struct {
@ffi.Long()
external int __sig;
@ffi.Array.multi([8])
external ffi.Array<ffi.Char> __opaque;
}
class _opaque_pthread_rwlock_t extends ffi.Struct {
@ffi.Long()
external int __sig;
@ffi.Array.multi([192])
external ffi.Array<ffi.Char> __opaque;
}
class _opaque_pthread_rwlockattr_t extends ffi.Struct {
@ffi.Long()
external int __sig;
@ffi.Array.multi([16])
external ffi.Array<ffi.Char> __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<ffi.Char> __opaque;
}
class ResourceBuffer extends ffi.Struct {
@@ -1194,135 +1319,67 @@ typedef FreeResourceFromOwner = ffi.Pointer<
ffi.Void Function(ResourceBuffer, ffi.Pointer<ffi.Void>)>>;
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;