getBoneNames method

  1. @override
Future<List<String>> getBoneNames(
  1. ThermionEntity entity, {
  2. int skinIndex = 0,
})
override

Gets the names of all bones for the armature at skinIndex under the specified entity.

Implementation

@override
Future<List<String>> getBoneNames(ThermionEntity entity,
    {int skinIndex = 0}) async {
  var boneCountJS = _module.ccall(
      "get_bone_count",
      "int",
      ["void*".toJS, "int".toJS, "int".toJS].toJS,
      [_sceneManager!, entity.toJS, skinIndex.toJS].toJS,
      null) as JSNumber;
  var boneCount = boneCountJS.toDartInt;
  var buf = _module._malloc(boneCount * 4) as JSNumber;

  var empty = " ".toJS;
  var ptrs = <JSNumber>[];
  for (int i = 0; i < boneCount; i++) {
    var ptr = _module._malloc(256);
    _module.stringToUTF8(empty, ptr, 255.toJS);
    ptrs.add(ptr);
    _module.setValue((buf.toDartInt + (i * 4)).toJS, ptr, "i32");
  }
  _module.ccall(
      "get_bone_names",
      "void",
      ["void*".toJS, "int".toJS, "char**".toJS, "int".toJS].toJS,
      [_sceneManager!, entity.toJS, buf, skinIndex.toJS].toJS,
      null);
  var names = <String>[];
  for (int i = 0; i < boneCount; i++) {
    var name = _module.UTF8ToString(ptrs[i]).toDart;
    names.add(name);
  }

  return names;
}