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 e6d5556077
commit 7dd9ed971f
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 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); 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 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_count(asset:Pointer, meshName:String) : Int;
fun get_target_name(asset:Pointer, meshName:String, outPtr:Pointer, index:Int); fun get_target_name(asset:Pointer, meshName:String, outPtr:Pointer, index:Int);
fun get_animation_count(asset:Pointer) : Int; fun get_animation_count(asset:Pointer) : Int;

View File

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