View Full Version : Getting an object location

12-06-2016, 07:59 AM
I'm feeling a little frustrated right now. I am trying to get the 3D position of an object within an exported OSGB scene. I know the name of my object; I've called it target. I can even find this object using the following snippet of code:

for nodeName in WholeEnviroment.getNodeNames():
if(nodeName == 'Target'):
node = WholeEnviroment.getChild(nodeName)
print node

However, when I attempt to extract the 3D information for this, I get either the following two results:

print node.getPosition()

Return value: [0, 0, -0]

print node.getPosition(viz.ABS_GLOBAL)

Return value: [0.0, 2.7850825786590576, -8.960569381713867]

Neither are correct. The correct position of this object is [-11.54891, 2.32127, -16.42012].

I am able to use viz.pick to select the object and I get the correct position which is great. However, viz.pick() seems to return the lowest level of an object (the material name in this instance).

Why am I unable to get a sensible value from simply specifying the node name? I'm either missing something very obvious or it's just another annoying quirk of Vizard.

This is how the structure of this node looks like in Vizard inspector: http://prntscr.com/dg30pa

12-06-2016, 11:08 AM
Are there multiple sub-parts with the same name? Are you able to attach the model here or upload (http://www.worldviz.com/upload/) for us to look at? Using the viz.ABS_GLOBAL flag should work.

12-06-2016, 11:22 AM
Hi Jeff,

Thanks for the speedy reply. I've uploaded the model using the link provided (1677024). The target object is called "target".

12-06-2016, 11:39 AM
Try using either the node.getTransform (http://docs.worldviz.com/vizard/#commands/node3d/getTransform.htm) command or the node.getChild (http://docs.worldviz.com/vizard/#commands/node3d/getChild.htm) command with the viz.CHILD_REPLACE_TRANSFORM flag:

import viz

scene = viz.addChild('scene.osgb')

#Get a linkable for controlling a sub-transform of the node
target = scene.getTransform('Target')

#Create a new Vizard <node3d> object from the underlying scene graph node
#target = scene.getChild('Target',flags=viz.CHILD_REPLACE_TR ANSFORM)

print target.getPosition(viz.ABS_GLOBAL)

01-10-2017, 04:43 AM
i got a pretty similar problem, so i just add this here and hope you can help me
i want to locate both arms from my avatar, to get the distance from the Grabbing point (grabber is attached to avatars arms) to the object i want to grab.

ground = viz.addChild('ground_gray.osgb')
Heizung = viz.addChild('heiz1.osgb')
pyramid = vizshape.addPyramid(base=(0.2,0.2),height=0.2,pos=[-0.5,1.7,1],alpha=0.7)
torus = vizshape.addTorus(radius=0.1,tubeRadius=0.015,axis =vizshape.AXIS_X, pos=[0,1.7,1])
box = vizshape.addCube(size=0.1, pos=[0.5,1.7,1],alpha=0.8)
shapes = [Heizung,pyramid,torus,box]
these are my objects i want to grab and ground which is the base of the world

basicly what i want to do is to get the locations of both the box, pyramid, and torus shapes and from the grabber tool from my vizconnect program and give them out