add setCameraModelMatrix method for iOS
This commit is contained in:
@@ -209,6 +209,8 @@ class _MyAppState extends State<MyApp> {
|
|||||||
await _filamentController.clearLights();
|
await _filamentController.clearLights();
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
|
await _filamentController
|
||||||
|
.setCameraModelMatrix(List<double>.filled(16, 1.0));
|
||||||
|
|
||||||
// await _filamentController.setBoneTransform(
|
// await _filamentController.setBoneTransform(
|
||||||
// _cube!,
|
// _cube!,
|
||||||
@@ -297,6 +299,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
_item(value: 29, child: Text('add light')),
|
_item(value: 29, child: Text('add light')),
|
||||||
_item(value: 30, child: Text('remove light')),
|
_item(value: 30, child: Text('remove light')),
|
||||||
_item(value: 31, child: Text('clear all lights')),
|
_item(value: 31, child: Text('clear all lights')),
|
||||||
|
_item(value: 32, child: Text('set camera model matrix')),
|
||||||
])),
|
])),
|
||||||
Container(
|
Container(
|
||||||
width: _vertical ? 200 : 400,
|
width: _vertical ? 200 : 400,
|
||||||
|
|||||||
@@ -326,10 +326,12 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
let meshName = args[1] as! String
|
let meshName = args[1] as! String
|
||||||
let numNames = get_morph_target_name_count(assetPtr, meshName)
|
let numNames = get_morph_target_name_count(assetPtr, meshName)
|
||||||
var names = [String]()
|
var names = [String]()
|
||||||
for i in 0...numNames - 1 {
|
if(numNames > 0) {
|
||||||
let outPtr = UnsafeMutablePointer<CChar>.allocate(capacity:256)
|
for i in 0...numNames - 1 {
|
||||||
get_morph_target_name(assetPtr, meshName, outPtr, i)
|
let outPtr = UnsafeMutablePointer<CChar>.allocate(capacity:256)
|
||||||
names.append(String(cString:outPtr))
|
get_morph_target_name(assetPtr, meshName, outPtr, i)
|
||||||
|
names.append(String(cString:outPtr))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result(names);
|
result(names);
|
||||||
case "getAnimationNames":
|
case "getAnimationNames":
|
||||||
@@ -419,6 +421,12 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
|||||||
let args = call.arguments as! Array<Any>
|
let args = call.arguments as! Array<Any>
|
||||||
set_camera_rotation(self.viewer, Float(args[0] as! Double), Float(args[1] as! Double), Float(args[2] as! Double),Float(args[3] as! Double))
|
set_camera_rotation(self.viewer, Float(args[0] as! Double), Float(args[1] as! Double), Float(args[2] as! Double),Float(args[3] as! Double))
|
||||||
result("OK")
|
result("OK")
|
||||||
|
case "setCameraModelMatrix":
|
||||||
|
let matrix = call.arguments as! FlutterStandardTypedData
|
||||||
|
matrix.data.withUnsafeBytes{ (floatPtr: UnsafePointer<Float>) in
|
||||||
|
set_camera_model_matrix(self.viewer, floatPtr)
|
||||||
|
}
|
||||||
|
result("OK")
|
||||||
case "setCameraFocalLength":
|
case "setCameraFocalLength":
|
||||||
set_camera_focal_length(self.viewer, Float(call.arguments as! Double))
|
set_camera_focal_length(self.viewer, Float(call.arguments as! Double))
|
||||||
result("OK");
|
result("OK");
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ namespace polyvox {
|
|||||||
|
|
||||||
void setCameraPosition(float x, float y, float z);
|
void setCameraPosition(float x, float y, float z);
|
||||||
void setCameraRotation(float rads, float x, float y, float z);
|
void setCameraRotation(float rads, float x, float y, float z);
|
||||||
|
void setCameraModelMatrix(const float* const matrix);
|
||||||
void setCameraFocalLength(float fl);
|
void setCameraFocalLength(float fl);
|
||||||
void setCameraFocusDistance(float focusDistance);
|
void setCameraFocusDistance(float focusDistance);
|
||||||
|
|
||||||
|
|||||||
@@ -52,17 +52,17 @@ void grab_begin(void* viewer, float x, float y, bool pan);
|
|||||||
void grab_update(void* viewer, float x, float y);
|
void grab_update(void* viewer, float x, float y);
|
||||||
void grab_end(void* viewer);
|
void grab_end(void* viewer);
|
||||||
|
|
||||||
void apply_weights(void* asset, float* const weights, int count);
|
void apply_weights(void* asset, float* const weights, int count);
|
||||||
|
|
||||||
void set_animation(
|
void set_animation(
|
||||||
void* asset,
|
void* asset,
|
||||||
const float* const morphData,
|
const float* const morphData,
|
||||||
int numMorphWeights,
|
int numMorphWeights,
|
||||||
const BoneAnimation* const boneAnimations,
|
const BoneAnimation* const boneAnimations,
|
||||||
int numBoneAnimations,
|
int numBoneAnimations,
|
||||||
int numFrames,
|
int numFrames,
|
||||||
float frameLengthInMs
|
float frameLengthInMs
|
||||||
);
|
);
|
||||||
|
|
||||||
// void set_bone_transform(
|
// void set_bone_transform(
|
||||||
// void* asset,
|
// void* asset,
|
||||||
@@ -103,6 +103,7 @@ void set_scale(void* asset, float scale);
|
|||||||
|
|
||||||
void set_camera_position(void* viewer, float x, float y, float z);
|
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_rotation(void* viewer, float rads, float x, float y, float z);
|
||||||
|
void set_camera_model_matrix(void* viewer, const float* const matrix);
|
||||||
void set_camera_focal_length(void* viewer, float focalLength);
|
void set_camera_focal_length(void* viewer, float focalLength);
|
||||||
void set_camera_focus_distance(void* viewer, float focusDistance);
|
void set_camera_focus_distance(void* viewer, float focusDistance);
|
||||||
|
|
||||||
|
|||||||
@@ -904,6 +904,34 @@ void FilamentViewer::setCameraRotation(float rads, float x, float y, float z) {
|
|||||||
cam.setModelMatrix(_cameraPosition * _cameraRotation);
|
cam.setModelMatrix(_cameraPosition * _cameraRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilamentViewer::setCameraModelMatrix(const float* const matrix) {
|
||||||
|
if(_manipulator) {
|
||||||
|
delete _manipulator;
|
||||||
|
_manipulator = nullptr;
|
||||||
|
}
|
||||||
|
Camera& cam =_view->getCamera();
|
||||||
|
|
||||||
|
mat4 modelMatrix(
|
||||||
|
matrix[0],
|
||||||
|
matrix[1],
|
||||||
|
matrix[2],
|
||||||
|
matrix[3],
|
||||||
|
matrix[4],
|
||||||
|
matrix[5],
|
||||||
|
matrix[6],
|
||||||
|
matrix[7],
|
||||||
|
matrix[8],
|
||||||
|
matrix[9],
|
||||||
|
matrix[10],
|
||||||
|
matrix[11],
|
||||||
|
matrix[12],
|
||||||
|
matrix[13],
|
||||||
|
matrix[14],
|
||||||
|
matrix[15]
|
||||||
|
);
|
||||||
|
cam.setModelMatrix(modelMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
void FilamentViewer::_createManipulator() {
|
void FilamentViewer::_createManipulator() {
|
||||||
if(_manipulator) {
|
if(_manipulator) {
|
||||||
delete _manipulator;
|
delete _manipulator;
|
||||||
@@ -919,7 +947,7 @@ void FilamentViewer::_createManipulator() {
|
|||||||
.targetPosition(tp[0], tp[1], tp[2])
|
.targetPosition(tp[0], tp[1], tp[2])
|
||||||
.build(Mode::ORBIT);
|
.build(Mode::ORBIT);
|
||||||
_lastFrameTimeInNanos = 0;
|
_lastFrameTimeInNanos = 0;
|
||||||
Log("Created orbit manipulator for vp width %d height %d with home %f %f %f and target pos %f %f %f ", vp.width, vp.height, home[0], home[1], home[2], tp[0], tp[1], tp[2]);
|
// Log("Created orbit manipulator for vp width %d height %d with home %f %f %f and target pos %f %f %f ", vp.width, vp.height, home[0], home[1], home[2], tp[0], tp[1], tp[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::grabBegin(float x, float y, bool pan) {
|
void FilamentViewer::grabBegin(float x, float y, bool pan) {
|
||||||
@@ -958,9 +986,27 @@ void FilamentViewer::grabEnd() {
|
|||||||
delete _manipulator;
|
delete _manipulator;
|
||||||
_manipulator = nullptr;
|
_manipulator = nullptr;
|
||||||
Camera& cam =_view->getCamera();
|
Camera& cam =_view->getCamera();
|
||||||
math::float3 home = cam.getPosition();
|
math::mat4 camMatrix = cam.getModelMatrix();
|
||||||
math::float3 fv = cam.getForwardVector();
|
// math::float3 home = cam.getPosition();
|
||||||
Log("Destroyed manipulator, end camera pos/fv was %f %f %f / %f %f %f ", home[0], home[1], home[2], fv[0], fv[1], fv[2]);
|
// math::float3 fv = cam.getForwardVector();
|
||||||
|
Log("Destroyed manipulator, end camera model matrix was %0.3f %0.3f %03.f %03.f %0.3f %0.3f %03.f %03.f %0.3f %0.3f %03.f %03.f %0.3f %0.3f %03.f %03.f ",
|
||||||
|
camMatrix[0][0],
|
||||||
|
camMatrix[0][1],
|
||||||
|
camMatrix[0][2],
|
||||||
|
camMatrix[0][3],
|
||||||
|
camMatrix[1][0],
|
||||||
|
camMatrix[1][1],
|
||||||
|
camMatrix[1][2],
|
||||||
|
camMatrix[1][3],
|
||||||
|
camMatrix[2][0],
|
||||||
|
camMatrix[2][1],
|
||||||
|
camMatrix[2][2],
|
||||||
|
camMatrix[2][3],
|
||||||
|
camMatrix[3][0],
|
||||||
|
camMatrix[3][1],
|
||||||
|
camMatrix[3][2],
|
||||||
|
camMatrix[3][3]
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
Log("Error - trying to call GrabEnd when a manipulator is not available. Ensure you call grabBegin before grabUpdate/grabEnd");
|
Log("Error - trying to call GrabEnd when a manipulator is not available. Ensure you call grabBegin before grabUpdate/grabEnd");
|
||||||
}
|
}
|
||||||
@@ -992,4 +1038,4 @@ void FilamentViewer::scrollEnd() {
|
|||||||
|
|
||||||
} // namespace polyvox
|
} // namespace polyvox
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ extern "C" {
|
|||||||
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_camera_model_matrix(void* viewer, const float* const matrix) {
|
||||||
|
((FilamentViewer*)viewer)->setCameraModelMatrix(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
void set_camera_focal_length(void* viewer, float focalLength) {
|
void set_camera_focal_length(void* viewer, float focalLength) {
|
||||||
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
import 'animations/animation_builder.dart';
|
import 'animations/animation_builder.dart';
|
||||||
import 'animations/animations.dart';
|
import 'animations/animations.dart';
|
||||||
@@ -88,6 +89,7 @@ abstract class FilamentController {
|
|||||||
Future setCameraFocusDistance(double focusDistance);
|
Future setCameraFocusDistance(double focusDistance);
|
||||||
Future setCameraPosition(double x, double y, double z);
|
Future setCameraPosition(double x, double y, double z);
|
||||||
Future setCameraRotation(double rads, double x, double y, double z);
|
Future setCameraRotation(double rads, double x, double y, double z);
|
||||||
|
Future setCameraModelMatrix(List<double> matrix);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Animates morph target weights/bone transforms (where each frame requires a duration of [frameLengthInMs].
|
/// Animates morph target weights/bone transforms (where each frame requires a duration of [frameLengthInMs].
|
||||||
@@ -362,6 +364,11 @@ class PolyvoxFilamentController extends FilamentController {
|
|||||||
await _channel.invokeMethod("setCameraRotation", [rads, x, y, z]);
|
await _channel.invokeMethod("setCameraRotation", [rads, x, y, z]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future setCameraModelMatrix(List<double> matrix) async {
|
||||||
|
await _channel.invokeMethod(
|
||||||
|
"setCameraModelMatrix", Float32List.fromList(matrix));
|
||||||
|
}
|
||||||
|
|
||||||
Future setTexture(FilamentAsset asset, String assetPath,
|
Future setTexture(FilamentAsset asset, String assetPath,
|
||||||
{int renderableIndex = 0}) async {
|
{int renderableIndex = 0}) async {
|
||||||
await _channel
|
await _channel
|
||||||
|
|||||||
Reference in New Issue
Block a user