from static method
Implementation
static Future<GltfRoot> from({
required String prefix,
required Map<String, dynamic> json,
required List<GlbChunk> chunks,
}) async {
final root = GltfRoot._(prefix: prefix);
root.chunks = chunks;
Future<List<T>> parse<T>(
String key,
T Function(GltfRoot, Map<String, Object?>) parser,
) async {
final objects = Parser.objectList(root, json, key, parser) ?? [];
for (final object in objects) {
if (object is GltfNodeWithData) {
await object.init();
}
}
return objects;
}
root.buffers = await parse('buffers', Buffer.parse);
root.bufferViews = await parse('bufferViews', BufferView.parse);
root.accessors = await parse('accessors', RawAccessor.parse);
root.scenes = await parse('scenes', Scene.parse);
root.scene = Parser.integer(json, 'scene')!;
root.nodes = await parse('nodes', Node.parse);
root.cameras = await parse('cameras', Camera.parse);
root.skins = await parse('skins', Skin.parse);
root.meshes = await parse('meshes', Mesh.parse);
root.materials = await parse('materials', Material.parse);
root.textures = await parse('textures', Texture.parse);
root.animations = await parse('animations', Animation.parse);
root.samplers = await parse('samplers', Sampler.parse);
root.images = await parse('images', Image.parse);
return root;
}