diff --git a/defold-rive/editor/src/rive.clj b/defold-rive/editor/src/rive.clj index 92cb2f5b..34133323 100644 --- a/defold-rive/editor/src/rive.clj +++ b/defold-rive/editor/src/rive.clj @@ -75,6 +75,9 @@ (defn- plugin-update-file [file dt bytes-texture-set] (plugin-invoke-static rive-plugin-cls "UpdateInternal" (into-array Class [rive-plugin-file-cls Float/TYPE byte-array-cls]) [file (float dt) bytes-texture-set])) +(defn- plugin-set-artboard [file artboard] + (plugin-invoke-static rive-plugin-cls "SetArtboardInternal" (into-array Class [rive-plugin-file-cls String]) [file artboard])) + ; .rivemodel (defn load-rive-model [project self resource content] (let [rive-scene-resource (workspace/resolve-resource resource (:scene content)) @@ -742,6 +745,7 @@ [:atlas-resource :atlas-resource] [:texture-set-pb :texture-set-pb] [:main-scene :rive-main-scene] + [:rive-file-handle :rive-file-handle] [:rive-artboards :rive-artboards] [:rive-anim-ids :rive-anim-ids] [:rive-state-machine-ids :rive-state-machine-ids] @@ -782,6 +786,7 @@ (property create-go-bones g/Bool (default false)) (input dep-build-targets g/Any :array) + (input rive-file-handle g/Any) (input rive-scene-resource resource/Resource) (input rive-main-scene g/Any) (input scene-structure g/Any) @@ -802,10 +807,11 @@ (output anim-ids g/Any :cached (g/fnk [anim-data] (vec (sort (keys anim-data))))) (output state-machine-ids g/Any :cached (g/fnk [anim-data] (vec (sort (keys anim-data))))) (output material-shader ShaderLifecycle (gu/passthrough material-shader)) - (output scene g/Any :cached (g/fnk [_node-id rive-main-scene material-shader] + (output scene g/Any :cached (g/fnk [_node-id rive-file-handle artboard rive-main-scene artboard default-animation material-shader] (if (and (some? material-shader) (some? (:renderable rive-main-scene))) (let [aabb (:aabb rive-main-scene) - rive-scene-node-id (:node-id rive-main-scene)] + rive-scene-node-id (:node-id rive-main-scene) + _ (plugin-set-artboard rive-file-handle artboard )] (-> rive-main-scene (assoc-in [:renderable :user-data :shader] material-shader) ;;;;;;;;;;;(assoc :gpu-texture texture/white-pixel) diff --git a/defold-rive/plugins/lib/arm64-osx/libRiveExt.dylib b/defold-rive/plugins/lib/arm64-osx/libRiveExt.dylib index 2cb23e81..7b825a79 100644 Binary files a/defold-rive/plugins/lib/arm64-osx/libRiveExt.dylib and b/defold-rive/plugins/lib/arm64-osx/libRiveExt.dylib differ diff --git a/defold-rive/plugins/share/pluginRiveExt.jar b/defold-rive/plugins/share/pluginRiveExt.jar index d1d8464c..8aebaa25 100644 Binary files a/defold-rive/plugins/share/pluginRiveExt.jar and b/defold-rive/plugins/share/pluginRiveExt.jar differ diff --git a/defold-rive/pluginsrc/com/defold/bob/pipeline/Rive.java b/defold-rive/pluginsrc/com/defold/bob/pipeline/Rive.java index abdfc7c2..bee0b88d 100644 --- a/defold-rive/pluginsrc/com/defold/bob/pipeline/Rive.java +++ b/defold-rive/pluginsrc/com/defold/bob/pipeline/Rive.java @@ -93,6 +93,7 @@ public static class Bone { public static native RiveFile LoadFromBufferInternal(String path, byte[] buffer); public static native void Destroy(RiveFile rive_file); public static native void Update(RiveFile rive_file, float dt, byte[] texture_set_buffer); + public static native void SetArtboard(RiveFile rive_file, String artboard); public static native void DebugPrint(); public static class RiveFile { @@ -123,6 +124,11 @@ public static void UpdateInternal(RiveFile rive_file, float dt, byte[] texture_s Rive.Update(rive_file, dt, texture_set_pb); } + public static void SetArtboardInternal(RiveFile rive_file, String artboard) + { + Rive.SetArtboard(rive_file, artboard); + } + public static RiveFile LoadFromBuffer(String path, byte[] bytes) { RiveFile rive_file = Rive.LoadFromBufferInternal(path, bytes); diff --git a/defold-rive/pluginsrc/plugin.cpp b/defold-rive/pluginsrc/plugin.cpp index d44bc414..636c3ce8 100644 --- a/defold-rive/pluginsrc/plugin.cpp +++ b/defold-rive/pluginsrc/plugin.cpp @@ -186,6 +186,18 @@ static void JNICALL Java_Rive_Update(JNIEnv* env, jclass cls, jobject rive_file, DM_CHECK_JNI_ERROR(); } +static void JNICALL Java_Rive_SetArtboard(JNIEnv* env, jclass cls, jobject rive_file, jstring _artboard) +{ + DM_CHECK_JNI_ERROR(); + + dmDefoldJNI::ScopedString j_artboard(env, _artboard); + const char* artboard = j_artboard.m_String; + + TypeRegister register_t(env); + dmRiveJNI::SetArtboard(env, cls, rive_file, artboard); + DM_CHECK_JNI_ERROR(); +} + // static JNIEXPORT jlong JNICALL Java_RiveFile_AddressOf(JNIEnv* env, jclass cls, jobject object) // { // TypeRegister register_t(env); @@ -215,6 +227,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) DM_JNI_FUNCTION(LoadFromBufferInternal, "(Ljava/lang/String;[B)Lcom/dynamo/bob/pipeline/Rive$RiveFile;"), DM_JNI_FUNCTION(Destroy, "(Lcom/dynamo/bob/pipeline/Rive$RiveFile;)V"), DM_JNI_FUNCTION(Update, "(Lcom/dynamo/bob/pipeline/Rive$RiveFile;F[B)V"), + DM_JNI_FUNCTION(SetArtboard, "(Lcom/dynamo/bob/pipeline/Rive$RiveFile;Ljava/lang/String;)V"), //DM_JNI_FUNCTION(AddressOf, "(Ljava/lang/Object;)J"), }; #undef DM_JNI_FUNCTION @@ -227,4 +240,3 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) dmLogDebug("JNI_OnLoad return.\n"); return JNI_VERSION_1_8; } - diff --git a/defold-rive/pluginsrc/rive_file.cpp b/defold-rive/pluginsrc/rive_file.cpp index 251dcf75..93294580 100644 --- a/defold-rive/pluginsrc/rive_file.cpp +++ b/defold-rive/pluginsrc/rive_file.cpp @@ -314,6 +314,30 @@ static dmGameSystemDDF::TextureSet* LoadAtlasFromBuffer(void* buffer, size_t buf return texture_set_ddf; } +void SetArtboard(RiveFile* rive_file, const char* artboard) +{ + if (!rive_file->m_File) + { + return; + } + + if (artboard != 0) + { + rive_file->m_ArtboardInstance = rive_file->m_File->artboardNamed(artboard); + } + + if (!rive_file->m_ArtboardInstance) + { + rive_file->m_ArtboardInstance = rive_file->m_File->artboardAt(0); + } + rive_file->m_ArtboardInstance->advance(0.0f); + + dmRive::SetupBones(rive_file); + + PlayAnimation(rive_file, 0); + Update(rive_file, 0.0f, 0, 0); +} + void Update(RiveFile* rive_file, float dt, const uint8_t* texture_set_data, uint32_t texture_set_data_length) { if (!rive_file->m_File) diff --git a/defold-rive/pluginsrc/rive_file.h b/defold-rive/pluginsrc/rive_file.h index 02715e5d..512acdc2 100644 --- a/defold-rive/pluginsrc/rive_file.h +++ b/defold-rive/pluginsrc/rive_file.h @@ -44,6 +44,7 @@ void SetupBones(RiveFile* file); void PlayAnimation(RiveFile* rive_file, int index); void Update(RiveFile* rive_file, float dt, const uint8_t* texture_set_data, uint32_t texture_set_data_length); +void SetArtboard(RiveFile* rive_file, const char* artboard); } // namespace diff --git a/defold-rive/pluginsrc/rive_jni.cpp b/defold-rive/pluginsrc/rive_jni.cpp index b347f36a..9478f651 100644 --- a/defold-rive/pluginsrc/rive_jni.cpp +++ b/defold-rive/pluginsrc/rive_jni.cpp @@ -436,4 +436,18 @@ void Update(JNIEnv* env, jclass cls, jobject rive_file_obj, jfloat dt, const uin UpdateJNIRenderData(env, rive_file_obj, rive_file); } +void SetArtboard(JNIEnv* env, jclass cls, jobject rive_file_obj, const char* artboard) +{ + dmRive::RiveFile* rive_file = FromObject(env, rive_file_obj); + if (!rive_file || !rive_file->m_File) + { + return; + } + + dmRive::SetArtboard(rive_file, artboard); + + UpdateJNIRenderData(env, rive_file_obj, rive_file); +} + + } // namespace diff --git a/defold-rive/pluginsrc/rive_jni.h b/defold-rive/pluginsrc/rive_jni.h index 1fc0a829..ce3fca6d 100644 --- a/defold-rive/pluginsrc/rive_jni.h +++ b/defold-rive/pluginsrc/rive_jni.h @@ -29,6 +29,7 @@ namespace dmRiveJNI jobject LoadFileFromBuffer(JNIEnv* env, jclass cls, const char* path, const uint8_t* data, uint32_t data_length); void DestroyFile(JNIEnv* env, jclass cls, jobject rive_file); void Update(JNIEnv* env, jclass cls, jobject rive_file, jfloat dt, const uint8_t* texture_set_data, uint32_t texture_set_data_length); + void SetArtboard(JNIEnv* env, jclass cls, jobject rive_file, const char* artboard); } diff --git a/defold-rive/src/comp_rive.cpp b/defold-rive/src/comp_rive.cpp index b89114a8..5f52c1fd 100644 --- a/defold-rive/src/comp_rive.cpp +++ b/defold-rive/src/comp_rive.cpp @@ -204,9 +204,6 @@ namespace dmRive dmRive::RiveSceneData* data = (dmRive::RiveSceneData*) component->m_Resource->m_Scene->m_Scene; - //Todo: choose artboard by index: m_ArtboardIndex = (index == REQUEST_DEFAULT_SCENE) ? 0 : index; - //component->m_ArtboardInstance = data->m_File->artboardAt(0); - if (component->m_Resource->m_DDF->m_Artboard) { component->m_ArtboardInstance = data->m_File->artboardNamed(component->m_Resource->m_DDF->m_Artboard);