add loadGlbFromBuffer implementation to ThermionViewerFFI
This commit is contained in:
@@ -455,6 +455,31 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
@override
|
||||||
|
Future<ThermionEntity> loadGlbFromBuffer(Uint8List data,
|
||||||
|
{bool unlit = false, int numInstances = 1, bool keepData = false}) async {
|
||||||
|
if (unlit) {
|
||||||
|
throw Exception("Not yet implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
var entity = await withIntCallback((callback) => load_glb_from_buffer_ffi(
|
||||||
|
_sceneManager!,
|
||||||
|
data.address,
|
||||||
|
data.length,
|
||||||
|
numInstances,
|
||||||
|
keepData,
|
||||||
|
callback));
|
||||||
|
|
||||||
|
if (entity == _FILAMENT_ASSET_ERROR) {
|
||||||
|
throw Exception("An error occurred loading GLB from buffer");
|
||||||
|
}
|
||||||
|
_scene!.registerEntity(entity);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@@ -1739,6 +1764,8 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
Future<ThermionEntity> createGeometry(
|
Future<ThermionEntity> createGeometry(
|
||||||
List<double> vertices, List<int> indices,
|
List<double> vertices, List<int> indices,
|
||||||
{String? materialPath,
|
{String? materialPath,
|
||||||
|
List<double>? normals,
|
||||||
|
bool keepData = false,
|
||||||
PrimitiveType primitiveType = PrimitiveType.TRIANGLES}) async {
|
PrimitiveType primitiveType = PrimitiveType.TRIANGLES}) async {
|
||||||
if (_viewer == null) {
|
if (_viewer == null) {
|
||||||
throw Exception("Viewer must not be null");
|
throw Exception("Viewer must not be null");
|
||||||
@@ -1749,22 +1776,36 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
final vertexPtr = allocator<Float>(vertices.length);
|
final vertexPtr = allocator<Float>(vertices.length);
|
||||||
final indicesPtr = allocator<Uint16>(indices.length);
|
final indicesPtr = allocator<Uint16>(indices.length);
|
||||||
for (int i = 0; i < vertices.length; i++) {
|
for (int i = 0; i < vertices.length; i++) {
|
||||||
vertexPtr.elementAt(i).value = vertices[i];
|
vertexPtr[i] = vertices[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < indices.length; i++) {
|
for (int i = 0; i < indices.length; i++) {
|
||||||
(indicesPtr + i).value = indices[i];
|
(indicesPtr + i).value = indices[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
var entity = await withIntCallback((callback) => create_geometry_ffi(
|
var normalsPtr = nullptr.cast<Float>();
|
||||||
_sceneManager!,
|
if (normals != null) {
|
||||||
vertexPtr,
|
normalsPtr = allocator<Float>(normals.length);
|
||||||
vertices.length,
|
for (int i = 0; i < normals.length; i++) {
|
||||||
indicesPtr,
|
normalsPtr[i] = normals[i];
|
||||||
indices.length,
|
}
|
||||||
primitiveType.index,
|
}
|
||||||
materialPathPtr.cast<Char>(),
|
|
||||||
callback));
|
print("ALLOCATION DONE");
|
||||||
|
|
||||||
|
var entity = await withIntCallback((callback) =>
|
||||||
|
create_geometry_with_normals_ffi(
|
||||||
|
_sceneManager!,
|
||||||
|
vertexPtr,
|
||||||
|
vertices.length,
|
||||||
|
normalsPtr,
|
||||||
|
normals?.length ?? 0,
|
||||||
|
indicesPtr,
|
||||||
|
indices.length,
|
||||||
|
primitiveType.index,
|
||||||
|
materialPathPtr.cast<Char>(),
|
||||||
|
keepData,
|
||||||
|
callback));
|
||||||
if (entity == _FILAMENT_ASSET_ERROR) {
|
if (entity == _FILAMENT_ASSET_ERROR) {
|
||||||
throw Exception("Failed to create geometry");
|
throw Exception("Failed to create geometry");
|
||||||
}
|
}
|
||||||
@@ -1775,6 +1816,10 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
allocator.free(vertexPtr);
|
allocator.free(vertexPtr);
|
||||||
allocator.free(indicesPtr);
|
allocator.free(indicesPtr);
|
||||||
|
|
||||||
|
if (normals != null) {
|
||||||
|
allocator.free(normalsPtr);
|
||||||
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user