feat: expose more camera methods
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
output: '../lib/thermion_dart/viewer/ffi/thermion_dart.g.dart'
|
||||
output: '../lib/thermion_dart/viewer/ffi/src/thermion_dart.g.dart'
|
||||
headers:
|
||||
entry-points:
|
||||
- '../native/include/ThermionDartRenderThreadApi.h'
|
||||
|
||||
@@ -11,12 +11,13 @@ class ThermionFFICamera extends Camera {
|
||||
ThermionFFICamera(this.pointer);
|
||||
|
||||
@override
|
||||
Future setProjectionMatrixWithCulling(Matrix4 projectionMatrix,
|
||||
double near, double far) async {
|
||||
Future setProjectionMatrixWithCulling(
|
||||
Matrix4 projectionMatrix, double near, double far) async {
|
||||
Camera_setCustomProjectionWithCulling(
|
||||
pointer,
|
||||
matrix4ToDouble4x4(projectionMatrix),
|
||||
near,
|
||||
far);
|
||||
pointer, matrix4ToDouble4x4(projectionMatrix), near, far);
|
||||
}
|
||||
|
||||
Future<Matrix4> getModelMatrix() async {
|
||||
return double4x4ToMatrix4(Camera_getModelMatrix(pointer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,6 @@ external ffi.Pointer<ffi.Void> make_resource_loader(
|
||||
ffi.Pointer<ffi.Void> owner,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<TViewer> Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>,
|
||||
ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>)>(isLeaf: true)
|
||||
external ffi.Pointer<TViewer> create_filament_viewer(
|
||||
ffi.Pointer<ffi.Void> context,
|
||||
ffi.Pointer<ffi.Void> loader,
|
||||
ffi.Pointer<ffi.Void> platform,
|
||||
ffi.Pointer<ffi.Char> uberArchivePath,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>)>(isLeaf: true)
|
||||
external void destroy_filament_viewer(
|
||||
ffi.Pointer<TViewer> viewer,
|
||||
@@ -906,11 +896,9 @@ external void Camera_setCustomProjectionWithCulling(
|
||||
double far,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Pointer<TCamera> Function(ffi.Pointer<TEngine>, EntityId)>(
|
||||
isLeaf: true)
|
||||
external ffi.Pointer<TCamera> get_camera_component(
|
||||
ffi.Pointer<TEngine> engine,
|
||||
int entity,
|
||||
@ffi.Native<double4x4 Function(ffi.Pointer<TCamera>)>(isLeaf: true)
|
||||
external double4x4 Camera_getModelMatrix(
|
||||
ffi.Pointer<TCamera> camera,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
abstract class Camera {
|
||||
Future setProjectionMatrixWithCulling(
|
||||
Matrix4 projectionMatrix, double near, double far);
|
||||
|
||||
Future setProjectionMatrixWithCulling(Matrix4 projectionMatrix, double near, double far);
|
||||
|
||||
Future<Matrix4> getModelMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -230,10 +230,10 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE void set_camera_lens_projection(TCamera *camera, double near, double far, double aspect, double focalLength);
|
||||
EMSCRIPTEN_KEEPALIVE void set_camera_focus_distance(TCamera *camera, float focusDistance);
|
||||
EMSCRIPTEN_KEEPALIVE void set_camera_manipulator_options(TViewer *viewer, _ManipulatorMode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed);
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setCustomProjectionWithCulling(TCamera* camera, double4x4 projectionMatrix, double near, double far);
|
||||
EMSCRIPTEN_KEEPALIVE TCamera *get_camera_component(TEngine *engine, EntityId entity);
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setCustomProjectionWithCulling(TCamera* camera, double4x4 projectionMatrix, double near, double far);
|
||||
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera* camera);
|
||||
EMSCRIPTEN_KEEPALIVE TCamera *Engine_getCameraComponent(TEngine *engine, EntityId entity);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE int hide_mesh(void *sceneManager, EntityId entity, const char *meshName);
|
||||
EMSCRIPTEN_KEEPALIVE int reveal_mesh(void *sceneManager, EntityId entity, const char *meshName);
|
||||
|
||||
@@ -1068,6 +1068,11 @@ EMSCRIPTEN_KEEPALIVE void Camera_setCustomProjectionWithCulling(TCamera* tCamera
|
||||
camera->setCustomProjection(convert_double4x4_to_mat4(projectionMatrix), near, far);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera* tCamera) {
|
||||
auto * camera = reinterpret_cast<Camera*>(tCamera);
|
||||
return convert_mat4_to_double4x4(camera->getModelMatrix());
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TCamera *Engine_getCameraComponent(TEngine* tEngine, EntityId entityId) {
|
||||
auto * engine = reinterpret_cast<Engine*>(tEngine);
|
||||
auto * camera = engine->getCameraComponent(utils::Entity::import(entityId));
|
||||
|
||||
@@ -104,24 +104,40 @@ void main() async {
|
||||
});
|
||||
|
||||
test('set custom projection/culling matrix', () async {
|
||||
var viewer = await createViewer(bg:kRed, cameraPosition:Vector3(0,0,4));
|
||||
var viewer =
|
||||
await createViewer(bg: kRed, cameraPosition: Vector3(0, 0, 4));
|
||||
var camera = await viewer.getMainCamera();
|
||||
final cube = await viewer.createGeometry(GeometryHelper.cube());
|
||||
|
||||
|
||||
// cube is visible when inside the frustum, cube is visible
|
||||
var projectionMatrix =
|
||||
makeOrthographicMatrix(-10.0, 10.0, -10.0, 10.0, 0.05, 10000);
|
||||
await camera.setProjectionMatrixWithCulling(
|
||||
projectionMatrix, 0.05, 10000);
|
||||
await _capture(viewer, "camera_projection_culling_matrix_object_in_frustum");
|
||||
|
||||
await _capture(
|
||||
viewer, "camera_projection_culling_matrix_object_in_frustum");
|
||||
|
||||
// cube no longer visible when the far plane is moved closer to camera so cube is outside
|
||||
projectionMatrix =
|
||||
makeOrthographicMatrix(-10.0, 10.0, -10.0, 10.0, 0.05, 1);
|
||||
await camera.setProjectionMatrixWithCulling(
|
||||
projectionMatrix, 0.05, 1);
|
||||
await _capture(viewer, "camera_projection_culling_matrix_object_outside_frustum");
|
||||
await camera.setProjectionMatrixWithCulling(projectionMatrix, 0.05, 1);
|
||||
await _capture(
|
||||
viewer, "camera_projection_culling_matrix_object_outside_frustum");
|
||||
});
|
||||
|
||||
test('setting camera transform updates model matrix', () async {
|
||||
var viewer = await createViewer();
|
||||
|
||||
var cameraEntity = await viewer.getMainCameraEntity();
|
||||
var camera = await viewer.getMainCamera();
|
||||
|
||||
await viewer.setPosition(cameraEntity, 1, 0, 0);
|
||||
|
||||
var modelMatrix = await viewer.getCameraModelMatrix();
|
||||
expect(modelMatrix.getColumn(3).x, 1.0);
|
||||
expect(modelMatrix.getColumn(3).y, 0.0);
|
||||
expect(modelMatrix.getColumn(3).z, 0.0);
|
||||
expect(modelMatrix.getColumn(3).w, 1.0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user