Canvas SVG parser: Difference between revisions

m
http://forum.flightgear.org/search.php?st=0&sk=t&sd=d&sr=posts&keywords=%22svg.nas%22
No edit summary
m (http://forum.flightgear.org/search.php?st=0&sk=t&sd=d&sr=posts&keywords=%22svg.nas%22)
Line 27: Line 27:
   | date  = Mar 28th, 2016
   | date  = Mar 28th, 2016
   | added  = Mar 28th, 2016
   | added  = Mar 28th, 2016
  | script_version = 0.25
  }}
</ref>
* a Canvas represents an actual OpenGL texture (2D)
*  is hardware-accelerated
*  is using OSG for most of its features
*  there is an actual scenegraph
*  uses Nasal instead of ECMAScript/JavaScript
A FlightGear Canvas is primarily a property tree in the main property tree, where attributes of the texture, and each element, are mapped to "listeners" (or updated via polling).
Internally, this will dispatch events/notifications to the current texture/event.
A Canvas in texture is an invisible offscreen rendering context (RTT/FBO) - it is made visible by adding a so called "placement" to the main FlightGear scenegraph, where the static texture will be replaced with one of the dynamic Canvas textures.
A FlightGear Canvas supports events for UI purposes, so that listeners can be registered for events like "mouseover" etc.
The Canvas scenegraph is a special thing, its root is always a Canvas group - each group can have an arbitrary number of children added, i.e. other elements (or other groups).
The primary Canvas elements are 1) raster images, 2) osgText nodes, 3) map, 4) groups and 5) OpenVG paths.
The FlightGear Canvas system does not understand SVG images - instead, it is using the OpenVG back-end to translate a subset of SVG/XML to Canvas properties by mapping those to OpenVG primitives.
There are many features that are not supported by this SVG parser (svg.nas), but it is written in Nasal and can be easily extended to also support other features, e.g. support for raster images and/or nested SVG images.
Apart from OpenVG, there's no lower level drawing support (think pixels).
<ref>{{cite web
  | url    = http://forum.flightgear.org/viewtopic.php?p=277769#p277769
  | title  = <nowiki>Re: Canvas documentation</nowiki>
  | author = <nowiki>Hooray</nowiki>
  | date  = Feb 27th, 2016
  | added  = Feb 27th, 2016
  | script_version = 0.25
  }}
</ref>
for the supported commands, refer to $FG_ROOT/Nasal/canvas/api.nas and the segments listed in the canvas.Path hash (OpenVG should support arc/circle paths, not sure if those are currently made available or not)
For reference, you can look up the corresponding ShivaVG/OpenVG examples on the web, all primitives listed in api.nas should also be supported by the Canvas/ShivaVG implementation.
BTW: Once you know how to draw a circle using OpenVG paths, you can also extend svg.nas to parse the &lt;circle&gt; tag
<ref> {{cite web
  | url    = http://forum.flightgear.org/viewtopic.php?p=280009#p280009
  | title  = <nowiki>Re: Drawing a circle</nowiki>
  | author = <nowiki>Hooray</nowiki>
  | date  = Mar 20th, 2016
  | added  = Mar 20th, 2016
   | script_version = 0.25
   | script_version = 0.25
   }}
   }}