loadGeometries method
dynamic
loadGeometries(
- dynamic primitives
Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
Creates BufferGeometries from primitives.
@param {Array<GLTF.Primitive>} primitives @return {Promise<Array
Implementation
loadGeometries(primitives) async {
var parser = this;
var extensions = this.extensions;
var cache = primitiveCache;
createDracoPrimitive(primitive) async {
var geometry = await extensions[gltfExtensions["KHR_DRACO_MESH_COMPRESSION"]].decodePrimitive(primitive, parser);
return await addPrimitiveAttributes(geometry, primitive, parser);
}
List<BufferGeometry> pending = [];
for (var i = 0, il = primitives.length; i < il; i++) {
Map<String, dynamic> primitive = primitives[i];
var cacheKey = createPrimitiveKey(primitive);
// See if we've already created this geometry
var cached = cache[cacheKey];
if (cached != null) {
// Use the cached geometry if it exists
pending.add(cached.promise);
} else {
var geometryPromise;
if (primitive["extensions"] != null &&
primitive["extensions"][gltfExtensions["KHR_DRACO_MESH_COMPRESSION"]] != null) {
// Use DRACO geometry if available
geometryPromise = await createDracoPrimitive(primitive);
} else {
// Otherwise create a new geometry
geometryPromise = await addPrimitiveAttributes(BufferGeometry(), primitive, parser);
}
// Cache this geometry
cache[cacheKey] = {"primitive": primitive, "promise": geometryPromise};
pending.add(geometryPromise);
}
}
return pending;
}