add android bindings for set_frame_interval and use frame time for render

This commit is contained in:
Nick Fisher
2022-09-01 14:27:45 +10:00
parent dc9e639c40
commit 2cfb8ee78b
2 changed files with 25 additions and 20 deletions

View File

@@ -38,7 +38,9 @@ interface FilamentInterop : Library {
fun set_camera(viewer:Pointer, asset:Pointer, nodeName:String) : Boolean;
fun render(viewer:Pointer);
fun render(viewer:Pointer, frameTimeInNanos:Long);
fun set_frame_interval(viewer:Pointer, interval:Float);
fun create_swap_chain(viewer:Pointer, surface:Surface, env:JNIEnv);
@@ -59,6 +61,7 @@ interface FilamentInterop : Library {
fun animate_weights(asset:Pointer, frames:FloatArray, numWeights:Int, numFrames:Int, frameRate:Float);
fun get_target_name_count(asset:Pointer, meshName:String) : Int;
fun get_target_name(asset:Pointer, meshName:String, outPtr:Pointer, index:Int);
fun get_animation_count(asset:Pointer) : Int;

View File

@@ -27,7 +27,7 @@ import android.content.pm.PackageManager
import io.flutter.FlutterInjector
import android.os.CountDownTimer
import android.os.CountDownTimer
import android.os.Handler
import android.opengl.GLU
@@ -92,12 +92,14 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
private val startTime = System.nanoTime()
override fun doFrame(frameTimeNanos: Long) {
choreographer.postFrameCallback(this)
executor.execute {
if(_viewer != null) {
if(!surface.isValid()) {
Log.v(TAG, "INVALID")
}
_lib.render(_viewer!!)
if(_viewer == null) {
} else if(!surface.isValid()) {
Log.v(TAG, "INVALID")
} else {
_lib.render(_viewer!!, frameTimeNanos)
}
}
}
@@ -114,7 +116,7 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel
/// Keep a referene to the plugin binding so we can use the TextureRegistry when initialize is called from the platform channel.
/// Keep a reference to the plugin binding so we can use the TextureRegistry when initialize is called from the platform channel.
private lateinit var flutterPluginBinding : FlutterPlugin.FlutterPluginBinding
private var lifecycle: Lifecycle? = null
@@ -147,10 +149,9 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
lifecycle = (binding.lifecycle as? HiddenLifecycleReference)?.lifecycle
activity = binding.activity
activity.window.setFormat(PixelFormat.RGBA_8888)
choreographer = Choreographer.getInstance()
choreographer.postFrameCallback(frameCallback)
activity.window.setFormat(PixelFormat.RGBA_8888)
}
fun getAssetPath(path:String) : String {
@@ -170,13 +171,12 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
val entry = flutterPluginBinding.textureRegistry.createSurfaceTexture();
executor.execute {
if(_viewer != null) {
synchronized(lock) {
print("Deleting existing viewer")
_lib.filament_viewer_delete(_viewer!!);
print("Deleted viewer")
_viewer = null;
}
print("Deleting existing viewer")
_lib.filament_viewer_delete(_viewer!!);
print("Deleted viewer")
_viewer = null;
}
if(surfaceTexture != null) {
print("Releasing existing texture")
@@ -187,7 +187,6 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
val width = args[0]
val height = args[1]
surfaceTexture = entry.surfaceTexture()
surfaceTexture!!.setDefaultBufferSize(width, height)
@@ -198,9 +197,6 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
surface as Object,
JNIEnv.CURRENT,
(activity as Context).assets)
_lib.update_viewport_and_camera_projection(_viewer!!, width, height, 1.0f);
result.success(entry.id().toInt())
@@ -217,6 +213,12 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
_lib.update_viewport_and_camera_projection(_viewer!!, width, height, scale);
result.success(null)
}
}
"setFrameInterval" -> {
executor.execute {
_lib.set_frame_interval(_viewer!!, (call.arguments as Double).toFloat());
result.success(null)
}
}
"setBackgroundImage" -> {
executor.execute {