Start looking for a suitable sized texture
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
93b9098b9c
commit
58a2b38970
2 changed files with 60 additions and 2 deletions
|
@ -571,6 +571,53 @@ var livery_update = {
|
|||
};
|
||||
|
||||
|
||||
|
||||
# res2str
|
||||
# =============================================================================
|
||||
# Helper function for canvas_livery
|
||||
# Returns the Nk version for the given resolution
|
||||
var res2str = func(resolution) {
|
||||
if (resolution == 1024) {
|
||||
return "1k";
|
||||
}
|
||||
if (resolution == 2048) {
|
||||
return "2k";
|
||||
}
|
||||
if (resolution == 4096) {
|
||||
return "4k";
|
||||
}
|
||||
if (resolution == 8192) {
|
||||
return "8k";
|
||||
}
|
||||
if (resolution == 16384) {
|
||||
return "16k";
|
||||
}
|
||||
return nil;
|
||||
};
|
||||
|
||||
|
||||
|
||||
# findTexByRes
|
||||
# =============================================================================
|
||||
# Helper function for canvas_livery
|
||||
# Looks for the largest available livery texture in resolution equal or smaller
|
||||
# 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);
|
||||
while (res >= 1024) {
|
||||
checkFile.set(path ~ "/" ~ res2str(res) ~ "/" ~ file);
|
||||
if (checkFile.isFile()) {
|
||||
return res2str(res);
|
||||
}
|
||||
res = res / 2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
# canvas_livery
|
||||
# =============================================================================
|
||||
# Class for Canvas based liveries
|
||||
|
@ -580,6 +627,7 @@ var canvas_livery = {
|
|||
var m = { parents: [canvas_livery, overlay_update.new()] };
|
||||
m.parents[1].add(liveriesdir, "sim/model/livery/file", callback);
|
||||
m.parents[1].interval = interval;
|
||||
m.liveriesdir = liveriesdir;
|
||||
m.resolution = resolution;
|
||||
m.targets = {};
|
||||
m.targetsByProperty = {};
|
||||
|
@ -598,6 +646,11 @@ var canvas_livery = {
|
|||
listener: nil,
|
||||
resolution: resolution,
|
||||
};
|
||||
maxRes = getprop("/sim/model/livery/max-resolution");
|
||||
# Make sure we never load too large textures
|
||||
if (resolution > maxRes) {
|
||||
resolution = maxRes;
|
||||
}
|
||||
me.targets[name].canvas = canvas.new({
|
||||
"name": name,
|
||||
"size": [resolution, resolution],
|
||||
|
@ -608,11 +661,11 @@ 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(getprop(property)).setSize(resolution,resolution);
|
||||
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;
|
||||
me.targets[name].listener = setlistener(property, func(property) {
|
||||
me.targets[name].groups["base"].removeAllChildren();
|
||||
me.targets[name].layers["base"] = me.targets[name].groups["base"].createChild("image").setFile(property.getValue()).setSize(resolution,resolution);
|
||||
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);
|
||||
});
|
||||
},
|
||||
addLayer: func(target, name, file) {
|
||||
|
|
|
@ -972,6 +972,11 @@ Started September 2000 by David Megginson, david@megginson.com
|
|||
<adress type="string" userarchive="y">127.0.0.1</adress>
|
||||
<port type="int" userarchive="y">45003</port>
|
||||
</swift>
|
||||
<model>
|
||||
<livery>
|
||||
<max-resolution type="int" userarchive="y">4096</max-resolution>
|
||||
</livery>
|
||||
</model>
|
||||
</sim>
|
||||
<!-- accelerations -->
|
||||
<accelerations>
|
||||
|
|
Loading…
Add table
Reference in a new issue