From 03dd2cf6acacccf14c63de315fcce32e6d03d55d Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 23 Aug 2023 15:38:12 +0800 Subject: [PATCH] fix int64->int32 conversion bug for morph indices --- ios/src/AssetManager.cpp | 9 ++++++++- ios/src/PolyvoxFilamentApi.cpp | 2 ++ lib/filament_controller.dart | 4 ++-- linux/polyvox_filament_plugin.cc | 21 +++++++++++++++------ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ios/src/AssetManager.cpp b/ios/src/AssetManager.cpp index 642a2264..1ecbe6b1 100644 --- a/ios/src/AssetManager.cpp +++ b/ios/src/AssetManager.cpp @@ -390,9 +390,16 @@ void AssetManager::setMorphTargetWeights(EntityId entityId, const char* const en } RenderableManager &rm = _engine->getRenderableManager(); + + auto renderableInstance = rm.getInstance(entity); + + if(!renderableInstance.isValid()) { + Log("Warning: failed to find renderable instance for entity %s", entityName); + return; + } rm.setMorphWeights( - rm.getInstance(entity), + renderableInstance, weights, count ); diff --git a/ios/src/PolyvoxFilamentApi.cpp b/ios/src/PolyvoxFilamentApi.cpp index 446aaf69..7113408a 100644 --- a/ios/src/PolyvoxFilamentApi.cpp +++ b/ios/src/PolyvoxFilamentApi.cpp @@ -191,6 +191,8 @@ extern "C" { ); } + + FLUTTER_PLUGIN_EXPORT bool set_morph_animation( void* assetManager, EntityId asset, diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index 16cd8e7b..51a84fd2 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -89,9 +89,9 @@ class FilamentController { await _channel.invokeMethod("updateViewportAndCameraProjection", [size.width.toInt(), size.height.toInt(), 1.0]); - - _initialized.complete(true); _assetManager = await _channel.invokeMethod("getAssetManager"); + _initialized.complete(true); + _textureIdController.add(_textureId); } diff --git a/linux/polyvox_filament_plugin.cc b/linux/polyvox_filament_plugin.cc index b58b9529..94eafe09 100644 --- a/linux/polyvox_filament_plugin.cc +++ b/linux/polyvox_filament_plugin.cc @@ -540,15 +540,23 @@ static FlMethodResponse* _set_morph_target_weights(PolyvoxFilamentPlugin* self, auto assetManager = (void*)fl_value_get_int(fl_value_get_list_value(args, 0)); auto asset = (EntityId)fl_value_get_int(fl_value_get_list_value(args, 1)); auto entityName = fl_value_get_string(fl_value_get_list_value(args, 2)); - auto weightsValue = fl_value_get_list_value(args, 3); - float weight = fl_value_get_float(fl_value_get_list_value(weightsValue, 0)); - size_t len = fl_value_get_length(weightsValue); - set_morph_target_weights(assetManager, asset, entityName, &weight, (int)len); + auto flWeights = fl_value_get_list_value(args, 3); + size_t numWeights = fl_value_get_length(flWeights); + + std::vector weights(numWeights); + for(int i =0; i < numWeights; i++) { + float val = fl_value_get_float(fl_value_get_list_value(flWeights, i)); + weights[i] = val; + } + + set_morph_target_weights(assetManager, asset, entityName, weights.data(), (int)numWeights); g_autoptr(FlValue) result = fl_value_new_string("OK"); return FL_METHOD_RESPONSE(fl_method_success_response_new(result)); } +template class std::vector; + static FlMethodResponse* _set_morph_animation(PolyvoxFilamentPlugin* self, FlMethodCall* method_call) { FlValue* args = fl_method_call_get_args(method_call); auto assetManager = (void*)fl_value_get_int(fl_value_get_list_value(args, 0)); @@ -565,10 +573,11 @@ static FlMethodResponse* _set_morph_animation(PolyvoxFilamentPlugin* self, FlMet auto morphIndicesList = fl_value_get_list_value(args, 4); auto morphIndicesListLength = fl_value_get_length(morphIndicesList); - auto indices = std::vector(morphIndicesListLength); + auto indices = std::vector(morphIndicesListLength); for(int i =0; i < morphIndicesListLength; i++) { - indices[i] = fl_value_get_int(fl_value_get_list_value(morphIndicesList, i)); + FlValue* flMorphIndex = fl_value_get_list_value(morphIndicesList, i); + indices[i] = static_cast(fl_value_get_int(flMorphIndex)); } int64_t numMorphTargets = fl_value_get_int(fl_value_get_list_value(args, 5));