Get one objects position in another object's coordinate system?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

 
Thread Tools Search this Thread Display Modes
  5 Days Ago
Get one objects position in another object's coordinate system?

Is there a way in mel or python in maya to get one object's position in the coordinate system of another object? I have a camera in a scene that may be rotated in any direction and am trying to measure the distance in its local Z axis to the vertexes of various objects in the scene. This obviously needs to be fast, since it will likely be run thousands of times across the scene.

In Maxscript the command would be something like " in coordsys $camera (" , but I have yet to find something like this in Maya. If there's no direct command to do this, does anyone have a way to calculate it using matrix math?
 
  4 Days Ago
I'm not aware of anything as succint as your maxScript example, but something like this might do the trick!


import maya.OpenMaya as om

mSel = om.MSelectionList()
mSel.add('myCam')
dagPath = om.MDagPath()
mSel.getDagPath(0, dagPath)

invMatrix = dagPath.inclusiveMatrixInverse()

mSel.add('myMesh')
mSel.getDagPath(1, dagPath)
iter = om.MItMeshVertex(dagPath)

# Storage for positions
points = om.MPointArray()
points.setLength(iter.count())

while not iter.isDone():
   # Multiply each vertex world position by cam inverse matrix
   points.set( iter.position(om.MSpace.kWorld) * invMatrix, iter.index())
   iter.next()

# Check points
for i in range(points.length()):
   p = points[i]
   print p.x, p.y, p.z
__________________
vimeo
blog
 
  3 Days Ago
That works perfect thank you so much!!
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:16 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.