add createGeometry
This commit is contained in:
@@ -545,4 +545,10 @@ abstract class FilamentController {
|
||||
/// If there is a collision between the controlled entity and [collidableEntity], the transform will not be updated.
|
||||
///
|
||||
Future addCollisionComponent(FilamentEntity collidableEntity);
|
||||
|
||||
///
|
||||
/// Creates a (renderable) entity with the specified geometry and adds to the scene.
|
||||
///
|
||||
Future createGeometry(
|
||||
List<double> vertices, List<int> indices, String? materialPath);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:developer' as dev;
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -1367,4 +1366,39 @@ class FilamentControllerFFI extends FilamentController {
|
||||
|
||||
add_collision_component(_assetManager!, entity);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FilamentEntity> createGeometry(
|
||||
List<double> vertices, List<int> indices, String? materialPath) async {
|
||||
if (_viewer == null) {
|
||||
throw Exception("Viewer must not be null");
|
||||
}
|
||||
|
||||
final materialPathPtr =
|
||||
materialPath?.toNativeUtf8(allocator: allocator) ?? nullptr;
|
||||
final vertexPtr = allocator<Float>(vertices.length);
|
||||
final indicesPtr = allocator<Uint16>(indices.length);
|
||||
for (int i = 0; i < vertices.length; i++) {
|
||||
vertexPtr.elementAt(i).value = vertices[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
indicesPtr.elementAt(i).value = indices[i];
|
||||
}
|
||||
|
||||
var entity = create_geometry_ffi(_viewer!, vertexPtr, vertices.length,
|
||||
indicesPtr, indices.length, materialPathPtr.cast<Char>());
|
||||
if (entity == _FILAMENT_ASSET_ERROR) {
|
||||
throw Exception("Failed to create geometry");
|
||||
}
|
||||
|
||||
_entities.add(entity);
|
||||
_onLoadController.sink.add(entity);
|
||||
|
||||
allocator.free(materialPathPtr);
|
||||
allocator.free(vertexPtr);
|
||||
allocator.free(indicesPtr);
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -835,6 +835,19 @@ external void add_collision_component(
|
||||
int entityId,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Float>,
|
||||
ffi.Int, ffi.Pointer<ffi.Uint16>, ffi.Int, ffi.Pointer<ffi.Char>)>(
|
||||
symbol: 'create_geometry', assetId: 'flutter_filament_plugin')
|
||||
external int create_geometry(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
ffi.Pointer<ffi.Float> vertices,
|
||||
int numVertices,
|
||||
ffi.Pointer<ffi.Uint16> indices,
|
||||
int numIndices,
|
||||
ffi.Pointer<ffi.Char> materialPath,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<ffi.Void> Function(
|
||||
ffi.Pointer<ffi.Void>,
|
||||
@@ -1284,6 +1297,19 @@ external void reset_to_rest_pose_ffi(
|
||||
symbol: 'ios_dummy_ffi', assetId: 'flutter_filament_plugin')
|
||||
external void ios_dummy_ffi();
|
||||
|
||||
@ffi.Native<
|
||||
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Float>,
|
||||
ffi.Int, ffi.Pointer<ffi.Uint16>, ffi.Int, ffi.Pointer<ffi.Char>)>(
|
||||
symbol: 'create_geometry_ffi', assetId: 'flutter_filament_plugin')
|
||||
external int create_geometry_ffi(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
ffi.Pointer<ffi.Float> vertices,
|
||||
int numVertices,
|
||||
ffi.Pointer<ffi.Uint16> indices,
|
||||
int numIndices,
|
||||
ffi.Pointer<ffi.Char> materialPath,
|
||||
);
|
||||
|
||||
final class __mbstate_t extends ffi.Union {
|
||||
@ffi.Array.multi([128])
|
||||
external ffi.Array<ffi.Char> __mbstate8;
|
||||
|
||||
Reference in New Issue
Block a user