[osg-users] Getting the height of a 3DS node

Robert Osfield robert.osfield at gmail.com
Sat Mar 10 04:05:00 PST 2018


HI Adrian,

On 10 March 2018 at 04:11, Adrian Jelffs <adrian.jelffs at makai.com> wrote:
> Hello,
>
> I am loading a 3DS file in to my scene and I need to find out the height of the object. I want to place some text above the object which moves with a fixed offset but I don't always know the size of the object.
>
> I am currently loading it like this:
>
> _myNode = osgDB::readNodeFile("adrian.3ds");
>
> I thought I could do something like this but hf always returns NULL.
>
> osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile("adrian.3ds");
>
> float height = hf->getSkirtHeight();

HeightField's are specific type of scene graph object but not one that
is ever loaded with a 3ds scene.  A 3ds scene graph will just contain
groups, geometry and stateset's.  Also SkirtHeight is not the actual
height of HeightField, it's the just the size of the skirt used for
hiding gaps between adjacent tiles.  HeightField is really just about
defining heights for terrain tiles.  I can only guess you've been just
searching around in the OSG code base for references to heights and
followed the wrong trail.  For the particular you want
osg::HeightField is not at all relevant.

When positioning objects in the scene graph relative to each other you
need to have a number of different routes you can take.  The easiest
would be to place the your text alongside the _myNode subgraph, I
presume you have added this to the main scene graph such as adding it
to a Group, so you'd add the Text to this same Group.

The next bit is local positioning to place the test above the _myNode
subgraph, to do this do:

    osg::BoundingSphere bs = _myNode->getBound();
    text->setPosition(bs.center()+osg::Vec3d(0.0, 0.0, bs.radius()));


Robert.


More information about the osg-users mailing list