Board index FlightGear Development Canvas

Need advice on how to place a canvas on a submodel  Topic is solved

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.

Need advice on how to place a canvas on a submodel

Postby TheEagle » Mon Dec 13, 2021 10:49 pm

I want to place a canvas on a 3D instrument of my aircraft. I have already read about canvas.addPlacement which seems pretty simple, but I have no idea where to put it. Normally you'd just put it into a Nasal file, include thta in the -set.xml nasal section, and be done. But the problem here is that my aircraft is made like a tree: In the -set file I include the XML file of the main aircraft model, which loads the fuselage .ac file, and adds seats, the panel, etc. by <model> tags. The panel in turn is also an XML file which adds the instruments. Each of the instruments of course is also an XML file including an AC file as it needs to be animated (knobs etc.). Now I want to put a canvas on one of these instruments which is loaded by the panel file which is loaded by the main model file, and I have no idea where to put the canvas creation and placement function. If I just put it in it's own Nasal file and include that in the set file, will the canvas system be able to find the object in the instrument file included by the panel file included by the aircraft file ?
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3414
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby wkitty42 » Tue Dec 14, 2021 12:02 am

can you not load it in the instrument's file since it belongs to that instrument?
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Tue Dec 14, 2021 12:17 am

How would I load a Nasal file in the instrument's XML file ?
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3414
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby wlbragg » Tue Dec 14, 2021 12:57 am

There are numerous examples in the c172p aircraft or shuttle and well as many others.

Code: Select all
    <nasal>
        <script>

        </script>
    </nasal>
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Tue Dec 14, 2021 1:01 am

I mean, if I have the canvas code in, say, Aircraft/c210-family/Nasal/chronometer.nas, how would I load that file inside the instrument's XML file ? I always thought you can only do that from the -set file.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3414
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby Maerchenprinz » Tue Dec 14, 2021 2:00 am

Hi!

When you have something like that in the nasal section of your *-set.xml:
Code: Select all
<nasal>
 <instruments>
  <file>Aircraft/c210-family/Nasal/chronometer.nas</file>
  <file>Aircraft/c210-family/Nasal/somethingelse.nas</file>
 </instruments>
</nasal>

then you can simply add something like that into the chronometer.xml:
Code: Select all
<nasal>
     <script>
      instruments.SomeFunctionInsideInstruments();
     </script>
</nasal>

instruments.SomeFunctionInsideInstruments can be any function from the files inside the <instruments> tags of your nasal section.
As simple as that! Isn't FG great?!

Ciao,

Adrian
User avatar
Maerchenprinz
 
Posts: 306
Joined: Thu Mar 15, 2007 6:24 pm
Location: Bochum, it's better, much better than you think!
Callsign: Adrian

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Tue Dec 14, 2021 2:40 am

Well, I could have thought of that myself - one last question (the main one) - will the canvas.addPlacement function put the canvas on any object in the scene graph which matches the given texture name / object name / parent name ? I thought only the top level fuselage file would be searched, and the instruments would be ignored if they aren't part of the top level fuselage AC file ?
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3414
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel  

Postby Maerchenprinz » Tue Dec 14, 2021 3:04 am

Uhmmm... Long time ago when I last wrote some canvas stuff...
As the function in this example is called from the chronometer.xml that loads the .ac file as well, it should only apply to the object/mesh in that .ac file.
I'm not sure though (see the "Uhmmmm" part above).
You can maybe just give it a try and look at the result. When you see "lighthouses in the sun" (great song title btw) or similar, you know that something's wrong! :P

Ciao,

Adrian
User avatar
Maerchenprinz
 
Posts: 306
Joined: Thu Mar 15, 2007 6:24 pm
Location: Bochum, it's better, much better than you think!
Callsign: Adrian

Re: Need advice on how to place a canvas on a submodel

Postby benih » Tue Dec 14, 2021 7:52 am

If you need a working example, investigate the davtron clock in the c182s. There i paint a canvas to revert the Clock
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Need advice on how to place a canvas on a submodel

Postby wkitty42 » Tue Dec 14, 2021 1:14 pm

TheEagle wrote in Tue Dec 14, 2021 1:01 am:I mean, if I have the canvas code in, say, Aircraft/c210-family/Nasal/chronometer.nas, how would I load that file inside the instrument's XML file ? I always thought you can only do that from the -set file.

AFAIK you can load stuff from any nasal or xml file...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Tue Jan 18, 2022 7:36 pm

So, I have created a file radios.nas, in there I have this code:
Code: Select all
var ComNavFreqDisplay = {
   new: func(deviceNode) {
      var obj = {
         parents: [ComNavFreqDisplay],
         _canvas: canvas.new({"size": [256, 96], "view": [256, 96]}),
         poweredNode: deviceNode.getNode("powered", 1),
         selectedMhzNode: deviceNode.getNode("frequencies/selected-mhz"),
      };
      
      return obj;
   },
   init: func() {
      me.display = me._canvas.createGroup();
      
      me.display.background = me.display.createChild("path")
                  .setColor(0, 0, 0)
                  .rect(0, 0, 256, 128);
      
      me.display.text = me.display.createChild("text")
                  .setAlignment("right-center")
                  .setFont("DSEG/DSEG7/Classic-MINI/DSEG7ClassicMini-Regular.ttf")
                  .setFontSize(80)
                  .setColor(1, 0.7, 0.7);
      
      setlistener(me.poweredNode, me.update);
      setlistener(me.selectedMhzNode, me.update);
      
      me._canvas.addPlacement({"node": "COMFreqDisplay"});
      me.update();
   },
   update: func() {
      if (me.poweredNode.getBoolValue()) {
         me.display.text.show();
      } else {
         me.display.text.hide();
      }
      
      me.display.text.setText(me.selectedMhzNode.getValue());
   },
};

var com1FreqDisplay = ComNavFreqDisplay.new(props.globals.getNode("/instrumentation/comm[0]"));
com1FreqDisplay.init();


The code is loaded by
Code: Select all
    <sim>
        ....
        <nasal>
            <p210n>
                <file>Nasal/radios.nas</file>
                .....
            </p210n>
        </nasal>
        ....
    </sim>

and runs fine without errors, also I can find my canvas in /canvas/by-index/canvas[3], yet it does not appear on the model, and /canvas/by-index/canvas[3]/placement/statusmsg is "No match". The model structure is as follows:
  • Models/p210n.xml (main model from /sim/model/path)
  • loads Models/Interior/p210n-interior.xml
  • loads Models/Interior/Panel/p210n-panel.xml
  • loads Models/Interior/Panel/Avionics/com-nav/com-nav-1.xml
  • which is the XML file for Models/Interior/Panel/Avionics/com-nav/com-nav.ac
  • which has an object called COMFreqDisplay
  • which has an 1x1 black texture

Now, what could I possibly be doing wrong ? AFAICS the structure is the same as for the Davtron clock.
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3414
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby Necolatis » Tue Jan 18, 2022 9:11 pm

Many times this si not enough:

Code: Select all
me._canvas.addPlacement({"node": "COMFreqDisplay"});


You also need the texture name that its model uses:

Code: Select all
me._canvas.addPlacement({"node": "COMFreqDisplay", "texture":"freq.png"});
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Tue Jan 18, 2022 10:43 pm

Nope, /canvas/by-index/texture[3]/placement/status-msg still shows No match when adding "texture": "dummy.png" to the hash (that's my 1x1 pixel texture=
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3414
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby TheEagle » Tue Jan 18, 2022 10:56 pm

If I change node to Fuselage, status-msg shows Ok. But for one the canvas isn't showing on the fuselage, and also I want it to be shown on the display of my radio and not on the fuselage ! :roll:
Cessna 210 (Wiki)
My other aircraft: my wiki profile !
Other: FGTools (GitHub)
World tour: View on SkyVector
Please consider donating $1 / €1 to help me finance a new camera !
User avatar
TheEagle
 
Posts: 3414
Joined: Sat May 01, 2021 3:27 pm
Location: France
Pronouns: You, he
Callsign: F-EAGLE
IRC name: none
Version: Git next
OS: Ubuntu Studio 22.04

Re: Need advice on how to place a canvas on a submodel

Postby Necolatis » Wed Jan 19, 2022 12:43 am

Do you have nay other Object in the entire aircraft that have the name COMFreqDisplay, perhaps?
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Next

Return to Canvas

Who is online

Users browsing this forum: No registered users and 4 guests