parseTextures method
Map
parseTextures(
- dynamic json,
- dynamic images
)
Implementation
Map parseTextures(json, images) {
parseConstant(value, type) {
if (value is num) return value;
console.warning('ObjectLoader.parseTexture: Constant should be in numeric form. $value');
return type[value];
}
final textures = {};
if (json != null) {
for (int i = 0, l = json.length; i < l; i++) {
Map<String, dynamic> data = json[i];
if (data['image'] == null) {
console.warning('ObjectLoader: No "image" specified for ${data["uuid"]}');
}
if (images[data["image"]] == null) {
console.warning('ObjectLoader: Undefined image ${data["image"]}');
}
Texture texture;
final source = images[data["image"]];
final image = source.data;
if (image is List) {
texture = CubeTexture();
if (image.length == 6) texture.needsUpdate = true;
}
else {
if (image != null && image.data != null && image.url == null) {
texture = DataTexture();
} else {
texture = Texture();
}
if (image != null) {
texture.needsUpdate = true;
} // textures can have null image data
}
texture.source = source;
texture.uuid = data["uuid"];
if (data["name"] != null) texture.name = data["name"];
if (data["mapping"] != null) {
texture.mapping = parseConstant(data["mapping"], textureMapping);
}
if (data["offset"] != null) texture.offset.copyFromArray(data["offset"]);
if (data["repeat"] != null) texture.repeat.copyFromArray(data["repeat"]);
if (data["center"] != null) texture.center.copyFromArray(data["center"]);
if (data["rotation"] != null) texture.rotation = data["rotation"];
if (data["wrap"] != null) {
texture.wrapS = parseConstant(data["wrap"][0], textureWrapping);
texture.wrapT = parseConstant(data["wrap"][1], textureWrapping);
}
if (data["format"] != null) texture.format = data["format"];
if (data["type"] != null) texture.type = data["type"];
if (data["colorSpace"] != null) texture.colorSpace = data["colorSpace"];
if (data["minFilter"] != null) {
texture.minFilter = parseConstant(data["minFilter"], textureFilter);
}
if (data["magFilter"] != null) {
texture.magFilter = parseConstant(data["magFilter"], textureFilter);
}
if (data["anisotropy"] != null) texture.anisotropy = data["anisotropy"];
if (data["flipY"] != null) texture.flipY = data["flipY"];
if (data["premultiplyAlpha"] != null) {
texture.premultiplyAlpha = data["premultiplyAlpha"];
}
if (data["unpackAlignment"] != null) {
texture.unpackAlignment = data["unpackAlignment"];
}
if (data["userData"] != null) texture.userData = data["userData"];
textures[data["uuid"]] = texture;
}
}
return textures;
}