add setCameraModelMatrix method for iOS
This commit is contained in:
@@ -209,6 +209,8 @@ class _MyAppState extends State<MyApp> {
|
||||
await _filamentController.clearLights();
|
||||
break;
|
||||
case 32:
|
||||
await _filamentController
|
||||
.setCameraModelMatrix(List<double>.filled(16, 1.0));
|
||||
|
||||
// await _filamentController.setBoneTransform(
|
||||
// _cube!,
|
||||
@@ -297,6 +299,7 @@ class _MyAppState extends State<MyApp> {
|
||||
_item(value: 29, child: Text('add light')),
|
||||
_item(value: 30, child: Text('remove light')),
|
||||
_item(value: 31, child: Text('clear all lights')),
|
||||
_item(value: 32, child: Text('set camera model matrix')),
|
||||
])),
|
||||
Container(
|
||||
width: _vertical ? 200 : 400,
|
||||
|
||||
@@ -326,10 +326,12 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
let meshName = args[1] as! String
|
||||
let numNames = get_morph_target_name_count(assetPtr, meshName)
|
||||
var names = [String]()
|
||||
for i in 0...numNames - 1 {
|
||||
let outPtr = UnsafeMutablePointer<CChar>.allocate(capacity:256)
|
||||
get_morph_target_name(assetPtr, meshName, outPtr, i)
|
||||
names.append(String(cString:outPtr))
|
||||
if(numNames > 0) {
|
||||
for i in 0...numNames - 1 {
|
||||
let outPtr = UnsafeMutablePointer<CChar>.allocate(capacity:256)
|
||||
get_morph_target_name(assetPtr, meshName, outPtr, i)
|
||||
names.append(String(cString:outPtr))
|
||||
}
|
||||
}
|
||||
result(names);
|
||||
case "getAnimationNames":
|
||||
@@ -419,6 +421,12 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
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))
|
||||
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":
|
||||
set_camera_focal_length(self.viewer, Float(call.arguments as! Double))
|
||||
result("OK");
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace polyvox {
|
||||
|
||||
void setCameraPosition(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 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_end(void* viewer);
|
||||
|
||||
void apply_weights(void* asset, float* const weights, int count);
|
||||
|
||||
void set_animation(
|
||||
void* asset,
|
||||
const float* const morphData,
|
||||
int numMorphWeights,
|
||||
const BoneAnimation* const boneAnimations,
|
||||
int numBoneAnimations,
|
||||
int numFrames,
|
||||
float frameLengthInMs
|
||||
);
|
||||
void apply_weights(void* asset, float* const weights, int count);
|
||||
|
||||
void set_animation(
|
||||
void* asset,
|
||||
const float* const morphData,
|
||||
int numMorphWeights,
|
||||
const BoneAnimation* const boneAnimations,
|
||||
int numBoneAnimations,
|
||||
int numFrames,
|
||||
float frameLengthInMs
|
||||
);
|
||||
|
||||
// void set_bone_transform(
|
||||
// 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_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_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);
|
||||
}
|
||||
|
||||
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() {
|
||||
if(_manipulator) {
|
||||
delete _manipulator;
|
||||
@@ -919,7 +947,7 @@ void FilamentViewer::_createManipulator() {
|
||||
.targetPosition(tp[0], tp[1], tp[2])
|
||||
.build(Mode::ORBIT);
|
||||
_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) {
|
||||
@@ -958,9 +986,27 @@ void FilamentViewer::grabEnd() {
|
||||
delete _manipulator;
|
||||
_manipulator = nullptr;
|
||||
Camera& cam =_view->getCamera();
|
||||
math::float3 home = cam.getPosition();
|
||||
math::float3 fv = cam.getForwardVector();
|
||||
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::mat4 camMatrix = cam.getModelMatrix();
|
||||
// math::float3 home = cam.getPosition();
|
||||
// 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 {
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -82,6 +82,10 @@ extern "C" {
|
||||
((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) {
|
||||
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
import 'animations/animation_builder.dart';
|
||||
import 'animations/animations.dart';
|
||||
@@ -88,6 +89,7 @@ abstract class FilamentController {
|
||||
Future setCameraFocusDistance(double focusDistance);
|
||||
Future setCameraPosition(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].
|
||||
@@ -362,6 +364,11 @@ class PolyvoxFilamentController extends FilamentController {
|
||||
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,
|
||||
{int renderableIndex = 0}) async {
|
||||
await _channel
|
||||
|
||||
Reference in New Issue
Block a user