1
0
Fork 0

Find right sized texture

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2020-11-19 08:37:17 +11:00
parent accf495a9e
commit 9764819178

View file

@ -604,16 +604,16 @@ var res2str = func(resolution) {
# than the given limit
var findTexByRes = func(path, file, maxRes) {
res = maxRes;
# TODO fix
# os.path: file operation on 'Path "Aircraft/A320-family/Models/Liveries/A320/CFM/4k/SWR-fuselage.png"' access denied (relative paths not accepted; use realpath() to make a path absolute)
checkFile = os.path.new(path);
checkFile = os.path.new(getprop("/sim/aircraft-dir") ~ "/" ~ path);
while (res >= 1024) {
checkFile.set(path ~ "/" ~ res2str(res) ~ "/" ~ file);
checkFile.set(getprop("/sim/aircraft-dir") ~ "/" ~ path ~ "/" ~ res2str(res) ~ "/" ~ file);
if (checkFile.isFile()) {
return res2str(res);
}
res = res / 2;
}
print("No suiting texture found");
return nil;
};
@ -625,12 +625,11 @@ var findTexByRes = func(path, file, maxRes) {
var canvas_livery = {
new: func(liveriesdir, interval = 10.01, callback = nili, resolution=4096) {
var m = { parents: [canvas_livery, overlay_update.new()] };
m.parents[1].add(liveriesdir, "sim/model/livery/file", callback);
m.parents[1].add(getprop("/sim/aircraft-dir") ~ "/" ~ liveriesdir, "sim/model/livery/file", callback);
m.parents[1].interval = interval;
m.liveriesdir = liveriesdir;
m.resolution = resolution;
m.targets = {};
m.targetsByProperty = {};
return m;
},
stop: func {
@ -661,11 +660,18 @@ var canvas_livery = {
me.targets[name].canvas.addPlacement({"node": object});
}
me.targets[name].groups["base"] = me.targets[name].canvas.createGroup("base");
me.targets[name].layers["base"] = me.targets[name].groups["base"].createChild("image").setFile(me.liveriesdir ~ "/" ~ findTexByRes(me.liveriesdir, getprop(property), resolution) ~ "/" ~ getprop(property)).setSize(resolution,resolution);
me.targetsByProperty[property] = name;
resStr = findTexByRes(me.liveriesdir, getprop(property), resolution);
if (resStr == nil) {
return nil;
}
me.targets[name].layers["base"] = me.targets[name].groups["base"].createChild("image").setFile(me.liveriesdir ~ "/" ~ resStr ~ "/" ~ getprop(property)).setSize(resolution,resolution);
me.targets[name].listener = setlistener(property, func(property) {
resStr = findTexByRes(me.liveriesdir, property.getValue(), resolution);
if (resStr == nil) {
return nil;
}
me.targets[name].groups["base"].removeAllChildren();
me.targets[name].layers["base"] = me.targets[name].groups["base"].createChild("image").setFile(me.liveriesdir ~ "/" ~ findTexByRes(me.liveriesdir, getprop(property), resolution) ~ "/" ~ getprop(property)).setSize(resolution,resolution);
me.targets[name].layers["base"] = me.targets[name].groups["base"].createChild("image").setFile(me.liveriesdir ~ "/" ~ resStr ~ "/" ~ property.getValue()).setSize(resolution,resolution);
});
},
addLayer: func(target, name, file) {