parse method
Implementation
parse(data, [String? path, Function? onLoad, Function? onError]) {
var content;
var extensions = {};
var plugins = {};
if (data is String) {
content = data;
} else {
var magic = LoaderUtils.decodeText(Uint8List.view(data.buffer, 0, 4));
if (magic == BINARY_EXTENSION_HEADER_MAGIC) {
// try {
extensions[EXTENSIONS["KHR_BINARY_GLTF"]] =
new GLTFBinaryExtension(data.buffer);
// } catch ( error ) {
// if ( onError != null ) onError( error );
// return;
// }
content = extensions[EXTENSIONS["KHR_BINARY_GLTF"]].content;
} else {
content = LoaderUtils.decodeText(data);
}
}
Map<String, dynamic> json = convert.jsonDecode(content);
if (json["asset"] == null || num.parse(json["asset"]["version"]) < 2.0) {
if (onError != null)
onError(
'THREE.GLTFLoader: Unsupported asset. glTF versions >= 2.0 are supported.');
return;
}
var parser = new GLTFParser(json, {
"path": path != null
? path
: this.resourcePath != null
? this.resourcePath
: '',
"crossOrigin": this.crossOrigin,
"requestHeader": this.requestHeader,
"manager": this.manager,
"ktx2Loader": this.ktx2Loader,
"meshoptDecoder": this.meshoptDecoder
});
parser.fileLoader.setRequestHeader(this.requestHeader);
for (var i = 0; i < this.pluginCallbacks.length; i++) {
var plugin = this.pluginCallbacks[i](parser);
plugins[plugin.name] = plugin;
// Workaround to avoid determining as unknown extension
// in addUnknownExtensionsToUserData().
// Remove this workaround if we move all the existing
// extension handlers to plugin system
extensions[plugin.name] = true;
}
if (json["extensionsUsed"] != null) {
for (var i = 0; i < json["extensionsUsed"].length; ++i) {
var extensionName = json["extensionsUsed"][i];
var extensionsRequired = json["extensionsRequired"] ?? [];
if (extensionName == EXTENSIONS["KHR_MATERIALS_UNLIT"]) {
extensions[extensionName] = new GLTFMaterialsUnlitExtension();
} else if (extensionName ==
EXTENSIONS["KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS"]) {
extensions[extensionName] =
new GLTFMaterialsPbrSpecularGlossinessExtension();
} else if (extensionName == EXTENSIONS["KHR_DRACO_MESH_COMPRESSION"]) {
extensions[extensionName] =
new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
} else if (extensionName == EXTENSIONS["MSFT_TEXTURE_DDS"]) {
extensions[extensionName] =
new GLTFTextureDDSExtension(this.ddsLoader);
} else if (extensionName == EXTENSIONS["KHR_TEXTURE_TRANSFORM"]) {
extensions[extensionName] = new GLTFTextureTransformExtension();
} else if (extensionName == EXTENSIONS["KHR_MESH_QUANTIZATION"]) {
extensions[extensionName] = new GLTFMeshQuantizationExtension();
} else {
if (extensionsRequired.indexOf(extensionName) >= 0 &&
plugins[extensionName] == null) {
print('THREE.GLTFLoader: Unknown extension ${extensionName}.');
}
}
// switch ( extensionName ) {
// case EXTENSIONS["KHR_MATERIALS_UNLIT"]:
// extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
// break;
// case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
// extensions[ extensionName ] = new GLTFMaterialsPbrSpecularGlossinessExtension();
// break;
// case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
// extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
// break;
// case EXTENSIONS.MSFT_TEXTURE_DDS:
// extensions[ extensionName ] = new GLTFTextureDDSExtension( this.ddsLoader );
// break;
// case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
// extensions[ extensionName ] = new GLTFTextureTransformExtension();
// break;
// case EXTENSIONS.KHR_MESH_QUANTIZATION:
// extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
// break;
// default:
// if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] == null ) {
// print( 'THREE.GLTFLoader: Unknown extension ${extensionName}.' );
// }
// }
}
}
parser.setExtensions(extensions);
parser.setPlugins(plugins);
parser.parse(onLoad, onError);
}