Howto:Extending Canvas to support rendering 3D models: Difference between revisions

Jump to navigation Jump to search
Line 88: Line 88:


== Turning the filename into a property ==
== Turning the filename into a property ==
So far, we really only have a proof-of-concept loading a hard-coded 3D model from disk and adding this to a Canvas scene-graph.
However, to be really useful, the file name should not be hard-coded, but should be just a property living in the sub-tree of the corresponding Canvas element, which is what we're going to implement next. Again, it makes sense to look at existing/similar use-cases in FlightGear, and specifically the corresponding subsystem, i.e. Canvas in this case - for that, we can simply look  at the implementation of CanvasImage, which already supports the notion of a "filename", which will update the whole element once modified:
https://gitorious.org/fg/simgear/source/ca7acb1f2cb10e4a8db2434642f44f2eb23cce6e:simgear/canvas/elements/CanvasImage.cxx#L613
<syntaxhighlight lang="cpp">
if( name == "file" )
        SG_LOG(SG_GL, SG_WARN, "'file' is deprecated. Use 'src' instead");
</syntaxhighlight>
As can be seen here, the general idea is to use the <code>::childChanged(SGPropertyNode* child)</code> method to look for supported nodes and process updates accordingly. The main thing to keep in mind here is that Canvas/SimGear don't know anything about FlightGear-specific APIs, which is why the CanvasSystemAdapter needs to be used, and called, to expose/access the corresponding APIs:
https://gitorious.org/fg/simgear/source/ca7acb1f2cb10e4a8db2434642f44f2eb23cce6e:simgear/canvas/elements/CanvasImage.cxx#L680
<syntaxhighlight lang="cpp">
Canvas::getSystemAdapter()
          ->getHTTPClient()
          ->load(url)
          // TODO handle capture of 'this'
          ->done(this, &Image::handleImageLoadDone);
</syntaxhighlight>
== Using ProxyNode ==
== Using ProxyNode ==
== Adding a PositionAttitudeTransform ==
== Adding a PositionAttitudeTransform ==

Navigation menu