properly free memory in model/view matrix getters

This commit is contained in:
Nick Fisher
2023-11-03 22:43:04 +08:00
parent 48be185bba
commit 8120cbea6d
3 changed files with 16 additions and 4 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_filament/filament_controller.dart';
@@ -105,6 +107,12 @@ class _SceneMenuState extends State<SceneMenu> {
},
child: const Text("Move camera to shapes asset"),
),
MenuItemButton(
onPressed: () {
widget.controller!.setCameraRotation(pi / 4, 0.0, 1.0, 0.0);
},
child: const Text("Rotate camera 45 degrees around y axis"),
),
MenuItemButton(
onPressed: () {
setState(() {

View File

@@ -348,7 +348,7 @@ abstract class FilamentController {
Future<Matrix4> getCameraViewMatrix();
///
/// Set the camera position in world space.
/// Set the camera position in world space. Note this is not persistent - any viewport navigation will reset the camera transform.
///
Future setCameraPosition(double x, double y, double z);
@@ -374,7 +374,7 @@ abstract class FilamentController {
double aperture, double shutterSpeed, double sensitivity);
///
/// Rotate the camera by [rads] around the given axis.
/// Rotate the camera by [rads] around the given axis. Note this is not persistent - any viewport navigation will reset the camera transform.
///
Future setCameraRotation(double rads, double x, double y, double z);

View File

@@ -992,7 +992,9 @@ class FilamentControllerFFI extends FilamentController {
throw Exception("No viewer available");
}
var arrayPtr = _lib.get_camera_view_matrix(_viewer!);
return Matrix4.fromList(arrayPtr.asTypedList(16));
var viewMatrix = Matrix4.fromList(arrayPtr.asTypedList(16));
calloc.free(arrayPtr);
return viewMatrix;
}
@override
@@ -1001,7 +1003,9 @@ class FilamentControllerFFI extends FilamentController {
throw Exception("No viewer available");
}
var arrayPtr = _lib.get_camera_model_matrix(_viewer!);
return Matrix4.fromList(arrayPtr.asTypedList(16));
var modelMatrix = Matrix4.fromList(arrayPtr.asTypedList(16));
calloc.free(arrayPtr);
return modelMatrix;
}
@override