createGeometry method
Future
createGeometry(
- List<
double> vertices, - List<
int> indices, { - String? materialPath,
- PrimitiveType primitiveType = PrimitiveType.TRIANGLES,
override
Creates a (renderable) entity with the specified geometry and adds to the scene.
Implementation
@override
Future createGeometry(List<double> vertices, List<int> indices,
{String? materialPath,
PrimitiveType primitiveType = PrimitiveType.TRIANGLES}) async {
final verticesData = td.Float32List.fromList(vertices);
final indicesData = Uint16List.fromList(indices);
final verticesPtr = _module._malloc(verticesData.lengthInBytes);
final indicesPtr = _module._malloc(indicesData.lengthInBytes);
_module.writeArrayToMemory(
verticesData.buffer.asUint8List().toJS, verticesPtr);
_module.writeArrayToMemory(
indicesData.buffer.asUint8List().toJS, indicesPtr);
final entityId = _module.ccall(
"create_geometry",
"int",
[
"void*".toJS,
"float*".toJS,
"int".toJS,
"uint16_t*".toJS,
"int".toJS,
"int".toJS,
"string".toJS
].toJS,
[
_viewer!,
verticesPtr,
vertices.length.toJS,
indicesPtr,
indices.length.toJS,
primitiveType.index.toJS,
materialPath?.toJS ?? "".toJS,
].toJS,
null) as JSNumber;
_module._free(verticesPtr);
_module._free(indicesPtr);
if (entityId.toDartInt == -1) {
throw Exception("Failed to create geometry");
}
return entityId.toDartInt;
}