Board index FlightGear Development Canvas

Two Images to a Texture

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Re: Two Images to a Texture

Postby Hooray » Wed Sep 17, 2014 9:31 pm

That is just 3 lines of code, but it will be better to continue as is for testing purposes - so please let's just finish this first, I can then convert it for pure-aircraft use later on, should just take 20 seconds ... the dialog is a good thing for development purposes - and whatever you do in the Nasal console is NOT specific to the GUI dialog.

You can find an example for doing this in the c172p-canvas or the HUD - but I'd really prefer if we could proceed for now using the GUI dialog and the Nasal console, while using the wiki to post screen shots and updates/code snippets there.

After all, this is also supposed to be aircraft agnostic and useful elsewhere.
Now, what you CAN do already, would be using a Canvas without the dialog, and simply opening a dialog with a placement instead of doing the opposite.
See: http://wiki.flightgear.org/Howto:Add_a_ ... e_a_Canvas

But in the long-term, I would prefer turning this into a Nasal class that can manage multiple Canvases per aircraft, so that we can also re-implement the existing livery system accordingly, so that it stops interfering with canvas. Which would also mean that people can reuse the same class for placing bullet holes or doing other fancy things (e.g. immatriculation)

EDIT: I've edited your wiki code to demonstrate how to detach the canvas from the window, allocate it without a window, and then use a canvas placement to show the aircraft canvas. It's still untested, so you may need to fiddle a bit with it....
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Two Images to a Texture

Postby Algernon » Wed Sep 17, 2014 9:41 pm

OK, no problem. I agree about the Nasal class. Am now updating the wiki, but here's the new screenshot for convenience. Note that the fuselage section is free from dirt, except for the smudge over the APU exhaust which is a special case, whereas the wings and tail have the livery's existing integral dirt layer. If we keep the experiment practice the same for now, is the next thing to do to add in another image and try to manipulate the transparency?

Image
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

Re: Two Images to a Texture

Postby Hooray » Wed Sep 17, 2014 9:44 pm

Yes, you would add multiple raster images to the canvas to serve as "layers" and then toggle them on/off, adjust alpha/transparency etc - and if that isn't random enough, you can also use texture-maps (sub-texturing) to extract a random sub-texture from your dirt texture, transform it in some way and then insert it. You could basically make the effect depend on groundspeed/windspeed, i.e. to make dirt stick when the aircraft is hardly moving (e.g. starting up), while letting it disappear when flying etc

Note that you'll probably want to set the z-index explicitly once you start using multiple "layered" raster images.

PS: Please upload fullscreen screen shots, I can hardly recognize anything in your "thumbnails" :D
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Two Images to a Texture

Postby Algernon » Wed Sep 17, 2014 9:58 pm

Yes, I was just noticing that you can't really see the differences. I added another image child identical to the first except setting the file source to the dirt layer. And voila - it works beautifully, the fuselage is filthy again :) I won't post a screenshot of that, as it looks identical to the rest of the aircraft again and would serve no purpose. But I'm confident it's working. Now to dynamically change the transparency of one of the image children.

The code is already in place for the "dirtying" effect - it's a fairly simple linear introduction of the dirt texture, becoming less transparent the more the aircraft flies without being washed. Being washed also includes rain - continued exposure to precipitation will "wash away" dirt by making the dirt layer more transparent according to the heaviness of the weather. It's been tried on the APU smudge, and whilst the values will need to be tweaked, it already works pretty much to my expectations and satisfaction.
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

Re: Two Images to a Texture

Postby Algernon » Wed Sep 17, 2014 10:20 pm

The wiki is now updated, and here are two full sized screenshots to illustrate progress thus far. In the first, the canvas is created and applied to the fuselage model object, resulting in a clean paint job (the best point of reference is the vent right at the leading edge of the wing root). In the second, the second child is added, and voila, fully filthy once again. :)

Image
Image
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

Re: Two Images to a Texture

Postby Hooray » Wed Sep 17, 2014 10:23 pm

I think, we'll want to come up with some kind of "TextureManager" class that aircraft developers can use to also manage liveries - we already have a "SymbolCache" class in MapStructure.nas which allows multiple raster images to be loaded into a single fixed-size texture - something like this would make sense to adopt sooner or later, because we want to ensure that there are not too many individual textures added/used, which is better for OSG, i.e. more OpenGL-friendly because there will be less OSG::StateSet changes involved - obviously, having people use 2048x2048-sized textures for a ton of features would not be a good idea and reflect badly upon Nasal/Canvas - IIRC, the extra500 managed to use even bigger textures. Also, you'll want to keep the number of updates low and simple, i.e. it should be cheaper to use texture maps than adding individual raster images -equally, hiding/showing textures is better than loading them on demand for performance reasons.

PS: Thanks for letting the pilot wear at least some underwear !! :D
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Two Images to a Texture

Postby Algernon » Wed Sep 17, 2014 10:29 pm

Roger that. So are we talking about a Nasal script in the data/Nasal folder of FlightGear, or a script which can be added to the aircraft's Nasal?

PS: Yes, sorry about the pilot, the cockpit air conditioning has not yet been coded and it can get pretty warm in there.
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

Re: Two Images to a Texture

Postby Hooray » Wed Sep 17, 2014 10:37 pm

For something like this, I feel that it is key to maintain this outside the actual aircraft directory - given that our Nasal code is no longer being actively maintained, we need to consciously work towards unifying such contributions - if you just add it a single aircraft, people will adapt it in a copy & paste fashion by adding your code to their aircraft. What we did with the ND code was creating a generic module outside $FG_AIRCRAFT, and merely adding an integration layer/wrapper to each aircraft - that way, the generic module no longer contains any aircraft specific details, and people who just use copy&paste, will automatically not cause any problems - while people wanting to add to the system, and extend it with new features, will automatically contribute to a common/shared module that will benefit all aircraft developers automatically - in the case of the ND, this meant that Gijs suddenly ended up with half a dozen of contributors - none of whom were interested in contributing to the 747-400 directly.
There are very impressive counter-examples like the much better-developed Avidyne Entegra R9 that don't have as many contributors, because its design is not sufficiently generic/aircraft agnostic, so that people who want to use it cannot use it, and have to resort to using the ND code instead...

Thus, I would prefer this to either live in $FG_ROOT/Aircraft/Generic - or preferably, in the canvas namespace, because having a "TextureManager" class will not necessarily be useful just for aircraft, we can just as well use the same approach for handling scenery objects, or even AI aircraft - while all of this may seem a bit fancy and sound like "over-engineering", it also means that the number of potential contributors will be larger this way. In addition, Nasal code in $FG_ROOT/Nasal/canvas is being maintained actively -not just TheTom, but by a handful of other Nasal developers - and the feature itself is not useful without Canvas, so I think it should be put there for the time being.

A TextureManager should evolve automatically once you start managing a few more textures per aircraft, and maybe adopt the system on another aircraft (which other aircraft devs will surely do) - so it is better, not to use put functionality into $FG_AIRCRAFT.

Overall, the results are really impressive and a testimonty to the generic nature of the Canvas system (kudos to TheTom !!) - we could now even render GUI widgets on top of aircraft :-)

This is also a very good proof that it is indeed technically the right thing to do to expose the FG view manager and effects/shaders to the Canvas system as new elements at some point, because aircraft developers could then implement all sorts of fancy features like tail cameras, night vision, FLIR etc without having to bother core developers.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Two Images to a Texture

Postby Algernon » Wed Sep 17, 2014 10:44 pm

Yes, that all makes sense. In order to get an idea of how we then manipulate the textures, can you point me to any documentation about changing values of the image children, with a view to adjusting transparency?
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

Re: Two Images to a Texture

Postby Hooray » Wed Sep 17, 2014 10:48 pm

I just updated the wiki accordingly - the basic idea is that whenever you call root.createChild() that you need to store its return value (the created child object) - iniitally, I appended everything to a vector, but I have now used a hash instead (untested):

Code: Select all
# vector with all images added (beginning at 0)
var layers = {};
# texture path
var path="Aircraft/EF2000/Models/";
foreach(var image; ['EF2000.png','EF2000-dirt.png']) {
# Put a raster image into the canvas and save the image in a hash: layers['EF2000.png].setScale(0.2);
layers[image] = root.createChild("image")
     .setFile( path~image )
     .setSize(2048,2048)
}


If this doesn't contain any typos, you can address each layer by using its file name like this (the example will hide/show layers):

Code: Select all
layers['EF2000.png'].hide();
layers['EF2000-dirt.png'].show();
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Two Images to a Texture

Postby Algernon » Thu Sep 18, 2014 12:20 am

The latest script is returning a 'call on uncallable object' error at line 40 - the timer.start() entry. Would it be an appropriate short-term solution, while I'm thinking my way through getting a repository up, to simply provide a snapshot of the aircraft as it stands at the moment, with the model adapted for this purpose, in my dropbox? Then at least the physical 3D framework is there to experiment on...
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

Re: Two Images to a Texture

Postby Hooray » Thu Sep 18, 2014 12:24 am

sorry, that's certainly my mistake - I didn't test anything I added there, and I don't have Philosopher's mental capacity to simply maintain a copy of the complete Nasal engine (parser/VM) running in my head :mrgreen: , will check the code and hopefully fix it shortly - but I shouldn't need your aircraft to fix my mistakes ... again, sorry.

EDIT: fixed:
Code: Select all

# start those two timers to hide/show the dirt texture with 2 second delays
timer_hide.start();
timer_show.start();
 
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Two Images to a Texture

Postby Algernon » Thu Sep 18, 2014 2:26 am

No problem at all :) Now works like a charm. I've had a glance through a few of the files in data/Nasal/canvas but can't see anything suggesting a function for altering the transparency yet - will pick it up again tomorrow.
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

Re: Two Images to a Texture

Postby Hooray » Thu Sep 18, 2014 5:24 am

To be honest, I don't exactly remember the details, and I cannot seem to find anything in the CanvasImage code - but if I remember correctly, there's some kind of "blend-*" property, will need to ask TheTom if/how this works currently and if it is supported per element or only per canvas (in which case,we'd have to use another nested Canvas to make this work unfortunately). We'll see what TheTom has to say.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Two Images to a Texture

Postby Algernon » Thu Sep 18, 2014 7:48 am

This may be what we're looking for: http://wiki.flightgear.org/Canvas_Image#fill
Algernon
FGUK - A FlightGear community in the United Kingdom and Republic of Ireland
User avatar
Algernon
 
Posts: 498
Joined: Sun Jun 27, 2010 3:55 pm
Callsign: G-ALGY
Version: 3.0
OS: W7U

PreviousNext

Return to Canvas

Who is online

Users browsing this forum: No registered users and 15 guests