re-add morph animation

This commit is contained in:
Nick Fisher
2022-02-07 14:52:03 +08:00
parent b28097b054
commit 9892f36363
7 changed files with 160 additions and 120 deletions

View File

@@ -117,6 +117,11 @@ extern "C" {
((FilamentViewer*)viewer)->applyWeights(weights, count);
}
void animate_weights(void* viewer, float* data, int numWeights, int numFrames, float frameRate) {
__android_log_print(ANDROID_LOG_VERBOSE, "filament_api", "Animating %d frames, each with %d weights", numFrames, numWeights);
((FilamentViewer*)viewer)->animateWeights((float*)data, numWeights, numFrames, frameRate);
}
void get_target_names(void* viewer, char* meshName, char*** outPtr, int* countPtr ) {
StringList names = ((FilamentViewer*)viewer)->getTargetNames(meshName);
@@ -136,9 +141,11 @@ extern "C" {
void free_pointer(char*** ptr, int size) {
__android_log_print(ANDROID_LOG_VERBOSE, "filament_api", "Freeing %d char pointers", size);
for(int i = 0; i < size; i++) {
free((*ptr)[i]);
__android_log_print(ANDROID_LOG_VERBOSE, "filament_api", "%d", i);
// free((*ptr)[i]);
}
free(*ptr);
__android_log_print(ANDROID_LOG_VERBOSE, "filament_api", "Free complete");
// free(*ptr);
}
void release_source_assets(void* viewer) {

View File

@@ -32,7 +32,7 @@ interface FilamentInterop : Library {
fun load_gltf(viewer:Pointer, uri:String, relativeResourcePath:String) : Pointer;
fun set_camera(viewer:Pointer, nodeName:String) : Pointer;
fun set_camera(viewer:Pointer, nodeName:String) : Boolean;
fun render(viewer:Pointer);
@@ -52,9 +52,11 @@ interface FilamentInterop : Library {
fun apply_weights(viewer:Pointer, weights:FloatArray, size:Int);
fun animate_weights(viewer:Pointer, frames:FloatArray, numWeights:Int, numFrames:Int, frameRate:Float);
fun get_target_names(viewer:Pointer, meshName:String, outPtr:PointerByReference, outLen:IntByReference);
fun free_pointer(ptr:Pointer, size:Int)
fun free_pointer(ptr:PointerByReference, size:Int)
fun release_source_assets(viewer:Pointer)

View File

@@ -182,11 +182,15 @@ PlatformView {
"setCamera" -> {
if (_viewer == null)
return;
_lib.set_camera(
val success = _lib.set_camera(
_viewer!!,
call.arguments as String
)
result.success("OK");
if(success) {
result.success("OK");
} else {
result.error("failed","failed", "Failed to set camera")
}
}
"zoom" -> {
if(_viewer == null)
@@ -203,8 +207,14 @@ PlatformView {
val names = arrPtr.value.getStringArray(0, countPtr.value);
_lib.free_pointer(arrPtr.value, countPtr.getValue())
val namesAsList = names.toCollection(ArrayList())
Log.v(TAG, "Got target names $names")
val namesAsList = names.toCollection(ArrayList())
_lib.free_pointer(arrPtr, countPtr.getValue())
Log.v(TAG, "Free complete")
result.success(namesAsList)
}
"applyWeights" -> {
@@ -215,6 +225,17 @@ PlatformView {
_lib.apply_weights(_viewer!!, weights.toFloatArray(), weights.size)
result.success("OK");
}
"animateWeights" -> {
if(_viewer == null)
return;
val args = call.arguments as ArrayList<Any?>
val frames = args[0] as ArrayList<Float>;
val numWeights = args[1] as Int
val frameRate = args[2] as Double
_lib.animate_weights(_viewer!!, frames.toFloatArray(), numWeights, (frames.size / numWeights).toInt(), frameRate.toFloat())
result.success("OK");
}
"panStart" -> {
val args = call.arguments as ArrayList<Any?>
_lib.grab_begin(_viewer!!, args[0] as Int, args[1] as Int, true)