toAsset method

Flix3DAsset toAsset({
  1. String? name,
})

Implementation

Flix3DAsset toAsset({String? name}) {
  final vertexData = positions;
  final normalData = normals;
  final meshPositions = <Vector3>[
    for (var index = 0; index + 2 < vertexData.length; index += 3)
      Vector3(
        vertexData[index],
        vertexData[index + 1],
        vertexData[index + 2],
      ),
  ];
  final meshNormals = <Vector3>[
    for (var index = 0; index + 2 < normalData.length; index += 3)
      Vector3(
        normalData[index],
        normalData[index + 1],
        normalData[index + 2],
      ),
  ];
  final mesh = Flix3DMesh(
    name: filename,
    positions: List<Vector3>.unmodifiable(meshPositions),
    indices: List<int>.unmodifiable(indices),
    normals: List<Vector3>.unmodifiable(meshNormals),
  );
  return Flix3DAsset(
    id: filename
        .split(RegExp(r'[/\\]'))
        .last
        .replaceAll(RegExp(r'\.[^.]+$'), '')
        .toLowerCase()
        .replaceAll(RegExp(r'[^a-z0-9_-]+'), '-'),
    name: name ?? filename.split(RegExp(r'[/\\]')).last,
    category: 'Native imports',
    tags: const <String>['imported', 'obj', 'native-cpp'],
    format: Flix3DAssetFormat.obj,
    meshes: <Flix3DMesh>[mesh],
    sourcePath: filename,
  );
}