OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Getting the height of a 3DS node


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11909

PostPosted: Sat Mar 10, 2018 12:09 pm    Post subject:
Getting the height of a 3DS node
Reply with quote

HI Adrian,

On 10 March 2018 at 04:11, Adrian Jelffs <> wrote:
Quote:
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.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
adrianj
Newbie


Joined: 19 Jan 2018
Posts: 14

PostPosted: Tue Mar 13, 2018 2:13 am    Post subject:
Reply with quote

Hi Robert,

Awesome, this works great! Thank you for steering me in the right direction.

osg::BoundingSphere bs = _myNode->getBound();

Is there anything that can get just the height of the node? In my case the node is quite long but not very tall so using a sphere places my text much further away than necessary.

Many thanks for your help!

Cheers,

Adrian
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11909

PostPosted: Tue Mar 13, 2018 9:03 am    Post subject:
Getting the height of a 3DS node
Reply with quote

HI Adrian,

On 13 March 2018 at 02:13, Adrian Jelffs <> wrote:
Quote:
Awesome, this works great! Thank you for steering me in the right direction.

osg::BoundingSphere bs = _myNode->getBound();

Is there anything that can get just the height of the node? In my case the node is quite long but not very tall so using a sphere places my text much further away than necessary.

A generic subgraph/node doesn't have a "height". The various
polygons/lines/points within the subgraph will have various heights,
all depending upon the model you have.

If you scene is axis aligned then potentially you could use the
osg::ComputeBoundsVisitor that computes a tightly bound bounding box
around a subgraph, this will have small extents than the bounding
sphere's.

Robert.


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Leaking memory on node removal Tini General 1 Fri May 25, 2018 6:48 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:39 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:30 pm View latest post
No new posts Leaking memory on node removal Tini General 0 Fri May 25, 2018 6:27 pm View latest post
No new posts EXTERNAL: Re: Getting the combined ma... Rowley, Marlin R General 0 Tue May 08, 2018 3:25 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP