createGeometry method
Future<ThermionEntity>
createGeometry(
- List<
double> vertices, - List<
int> indices, { - String? materialPath,
- PrimitiveType primitiveType = PrimitiveType.TRIANGLES,
override
Implementation
@override
Future<ThermionEntity> createGeometry(
List<double> vertices, List<int> indices,
{String? materialPath,
PrimitiveType primitiveType = PrimitiveType.TRIANGLES}) 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 + i).value = indices[i];
}
var entity = await withIntCallback((callback) => create_geometry_ffi(
_viewer!,
vertexPtr,
vertices.length,
indicesPtr,
indices.length,
primitiveType.index,
materialPathPtr.cast<Char>(),
callback));
if (entity == _FILAMENT_ASSET_ERROR) {
throw Exception("Failed to create geometry");
}
_scene!.registerEntity(entity);
allocator.free(materialPathPtr);
allocator.free(vertexPtr);
allocator.free(indicesPtr);
return entity;
}