add camera utils to API
This commit is contained in:
@@ -85,5 +85,10 @@ interface FilamentInterop : Library {
|
||||
|
||||
fun set_position(asset:Pointer, x:Float, y:Float, z:Float);
|
||||
fun set_rotation(asset:Pointer, rads:Float, x:Float, y:Float, z:Float);
|
||||
|
||||
fun set_camera_position(asset:Pointer, x:Float, y:Float, z:Float);
|
||||
fun set_camera_rotation(asset:Pointer, rads:Float, x:Float, y:Float, z:Float);
|
||||
fun set_camera_focal_length(asset:Pointer, focalLength:Float);
|
||||
fun set_camera_focus_distance(asset:Pointer, focusDistance:Float);
|
||||
}
|
||||
|
||||
|
||||
@@ -212,9 +212,9 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
|
||||
val args = call.arguments as ArrayList<Int>
|
||||
val width = args[0]
|
||||
val height = args[1]
|
||||
|
||||
val scale = if(args.size > 2) (args[2] as Double).toFloat() else 1.0f
|
||||
surfaceTexture!!.setDefaultBufferSize(width, height)
|
||||
_lib.update_viewport_and_camera_projection(_viewer!!, width, height, 1.0f);
|
||||
_lib.update_viewport_and_camera_projection(_viewer!!, width, height, scale);
|
||||
result.success(null)
|
||||
}
|
||||
}
|
||||
@@ -291,6 +291,32 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
|
||||
result.success("OK");
|
||||
}
|
||||
}
|
||||
"setCameraPosition" -> {
|
||||
executor.execute {
|
||||
val args = call.arguments as ArrayList<*>
|
||||
_lib.set_camera_position(_viewer!!, (args[0] as Double).toFloat(), (args[1] as Double).toFloat(), (args[2] as Double).toFloat())
|
||||
result.success("OK");
|
||||
}
|
||||
}
|
||||
"setCameraRotation" -> {
|
||||
executor.execute {
|
||||
val args = call.arguments as ArrayList<*>
|
||||
_lib.set_camera_rotation(_viewer!!, (args[0] as Double).toFloat(), (args[1] as Double).toFloat(), (args[2] as Double).toFloat(), (args[3] as Double).toFloat())
|
||||
result.success("OK");
|
||||
}
|
||||
}
|
||||
"setCameraFocalLength" -> {
|
||||
executor.execute {
|
||||
_lib.set_camera_focal_length(_viewer!!, (call.arguments as Double).toFloat())
|
||||
result.success("OK");
|
||||
}
|
||||
}
|
||||
"setCameraFocusDistance" -> {
|
||||
executor.execute {
|
||||
_lib.set_camera_focus_distance(_viewer!!, (call.arguments as Double).toFloat())
|
||||
result.success("OK");
|
||||
}
|
||||
}
|
||||
"setTexture" -> {
|
||||
executor.execute {
|
||||
val args = call.arguments as ArrayList<*>
|
||||
@@ -460,14 +486,13 @@ class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler, ActivityAware {
|
||||
|
||||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
channel.setMethodCallHandler(null)
|
||||
//_lib.destroy_swap_chain(_viewer!!)
|
||||
_lib.destroy_swap_chain(_viewer!!)
|
||||
}
|
||||
|
||||
|
||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
||||
onAttachedToActivity(binding)
|
||||
//_lib.create_swap_chain(_viewer!!, surface, JNIEnv.CURRENT)
|
||||
|
||||
_lib.create_swap_chain(_viewer!!, surface, JNIEnv.CURRENT)
|
||||
}
|
||||
|
||||
override fun onDetachedFromActivityForConfigChanges() {
|
||||
|
||||
@@ -121,6 +121,7 @@ FilamentViewer::FilamentViewer(void *layer, LoadResource loadResource,
|
||||
Entity camera = EntityManager::get().create();
|
||||
|
||||
_mainCamera = _engine->createCamera(camera);
|
||||
|
||||
Log("Main camera created");
|
||||
_view = _engine->createView();
|
||||
_view->setScene(_scene);
|
||||
@@ -133,6 +134,8 @@ FilamentViewer::FilamentViewer(void *layer, LoadResource loadResource,
|
||||
_view->setColorGrading(colorGrading);
|
||||
|
||||
_cameraFocalLength = 28.0f;
|
||||
_mainCamera->setLensProjection(_cameraFocalLength, 1.0f, kNearPlane,
|
||||
kFarPlane);
|
||||
_mainCamera->setExposure(kAperture, kShutterSpeed, kSensitivity);
|
||||
#if TARGET_OS_IPHONE
|
||||
_swapChain = _engine->createSwapChain(layer, filament::backend::SWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER);
|
||||
@@ -435,6 +438,25 @@ void FilamentViewer::removeAsset(SceneAsset *asset) {
|
||||
mtx.unlock();
|
||||
}
|
||||
|
||||
///
|
||||
/// Set the focal length of the active camera.
|
||||
///
|
||||
void FilamentViewer::setCameraFocalLength(float focalLength) {
|
||||
Camera& cam =_view->getCamera();
|
||||
_cameraFocalLength = focalLength;
|
||||
cam.setLensProjection(_cameraFocalLength, 1.0f, kNearPlane,
|
||||
kFarPlane);
|
||||
}
|
||||
|
||||
///
|
||||
/// Set the focus distance of the active camera.
|
||||
///
|
||||
void FilamentViewer::setCameraFocusDistance(float focusDistance) {
|
||||
Camera& cam =_view->getCamera();
|
||||
_cameraFocusDistance = focusDistance;
|
||||
cam.setFocusDistance(_cameraFocusDistance);
|
||||
}
|
||||
|
||||
///
|
||||
/// Sets the active camera to the first GLTF camera node found in the hierarchy.
|
||||
/// Useful when your asset only has one camera.
|
||||
|
||||
@@ -76,6 +76,8 @@ namespace polyvox {
|
||||
|
||||
void setCameraPosition(float x, float y, float z);
|
||||
void setCameraRotation(float rads, float x, float y, float z);
|
||||
void setCameraFocalLength(float fl);
|
||||
void setCameraFocusDistance(float focusDistance);
|
||||
|
||||
private:
|
||||
void createImageRenderable();
|
||||
@@ -120,7 +122,8 @@ namespace polyvox {
|
||||
|
||||
bool _actualSize = false;
|
||||
|
||||
float _cameraFocalLength = 0.0f;
|
||||
float _cameraFocalLength = 28.0f;
|
||||
float _cameraFocusDistance = 0.0f;
|
||||
|
||||
// these flags relate to the textured quad we use for rendering unlit background images
|
||||
Texture* _imageTexture = nullptr;
|
||||
|
||||
@@ -57,11 +57,15 @@ extern "C" {
|
||||
}
|
||||
|
||||
void set_camera_position(void* viewer, float x, float y, float z) {
|
||||
return ((FilamentViewer*)viewer)->setCameraPosition(x, y, z);
|
||||
((FilamentViewer*)viewer)->setCameraPosition(x, y, z);
|
||||
}
|
||||
|
||||
void set_camera_rotation(void* viewer, float rads, float x, float y, float z) {
|
||||
return ((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
||||
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
||||
}
|
||||
|
||||
void set_camera_focal_length(void* viewer, float focalLength) {
|
||||
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
||||
}
|
||||
|
||||
void render(
|
||||
|
||||
@@ -60,5 +60,7 @@ void stop_animation(void* asset, int index);
|
||||
void set_camera_position(void* viewer, float x, float y, float z);
|
||||
|
||||
void set_camera_rotation(void* viewer, float rads, float x, float y, float z);
|
||||
void set_camera_focal_length(void* viewer, float focalLength);
|
||||
void set_camera_focus_distance(void* viewer, float focusDistance);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,7 +8,7 @@ abstract class FilamentController {
|
||||
late int textureId;
|
||||
Future get initialized;
|
||||
Future initialize(int width, int height);
|
||||
Future resize(int width, int height);
|
||||
Future resize(int width, int height, {double contentScaleFactor=1});
|
||||
Future setBackgroundImage(String path);
|
||||
Future loadSkybox(String skyboxPath);
|
||||
Future removeSkybox();
|
||||
@@ -38,6 +38,10 @@ abstract class FilamentController {
|
||||
Future setPosition(FilamentAsset asset, double x, double y, double z);
|
||||
Future setRotation(
|
||||
FilamentAsset asset, double rads, double x, double y, double z);
|
||||
Future setCameraFocalLength(
|
||||
double focalLength);
|
||||
Future setCameraFocusDistance(
|
||||
double focusDistance);
|
||||
|
||||
///
|
||||
/// Set the weights of all morph targets in the mesh to the specified weights at successive frames (where each frame requires a duration of [frameLengthInMs].
|
||||
@@ -68,8 +72,8 @@ class PolyvoxFilamentController extends FilamentController {
|
||||
_initialized.complete(true);
|
||||
}
|
||||
|
||||
Future resize(int width, int height) async {
|
||||
await _channel.invokeMethod("resize", [width, height]);
|
||||
Future resize(int width, int height, { double contentScaleFactor=1.0}) async {
|
||||
await _channel.invokeMethod("resize", [width, height, contentScaleFactor]);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -193,6 +197,14 @@ class PolyvoxFilamentController extends FilamentController {
|
||||
await _channel.invokeMethod("setCamera", [asset, name]);
|
||||
}
|
||||
|
||||
Future setCameraFocalLength(double focalLength) async {
|
||||
await _channel.invokeMethod("setCameraFocalLength", focalLength);
|
||||
}
|
||||
|
||||
Future setCameraFocusDistance(double focusDistance) async {
|
||||
await _channel.invokeMethod("setCameraFocusDistance", focusDistance);
|
||||
}
|
||||
|
||||
Future setTexture(FilamentAsset asset, String assetPath,
|
||||
{int renderableIndex = 0}) async {
|
||||
await _channel
|
||||
|
||||
Reference in New Issue
Block a user