parseTextures method
Map
parseTextures(
- dynamic json,
- dynamic images
)
Implementation
Map parseTextures(json, images) {
parseConstant(value, type) {
if (value is num) return value;
print('three.ObjectLoader.parseTexture: Constant should be in numeric form. $value');
return type[value];
}
var textures = {};
if (json != null) {
for (var i = 0, l = json.length; i < l; i++) {
Map<String, dynamic> data = json[i];
if (data['image'] == null) {
print('three.ObjectLoader: No "image" specified for ${data["uuid"]}');
}
if (images[data["image"]] == null) {
print('three.ObjectLoader: Undefined image ${data["image"]}');
}
Texture texture;
var source = images[data["image"]];
var 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.fromArray(data["offset"]);
if (data["repeat"] != null) texture.repeat.fromArray(data["repeat"]);
if (data["center"] != null) texture.center.fromArray(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["encoding"] != null) texture.encoding = data["encoding"];
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;
}