View Full Version : cant get my head around pickPoint
abyjoe 05072008, 12:37 AM i am using pickpoint to pick a vertice but the x,y,z values it returns are different to what the coordinate system shows and is dependant on the viewport its picked from.... i need to do some calculations on vertex positions and need the pickpoint to return the actual coordinate 


erilaz
05072008, 12:57 AM
Could it be something to do with the fact that pickPoint always returns coordinates in worldspace?
abyjoe
05072008, 10:58 AM
is there a way to change that so it doesnt always return world space coordinates... or can I change the coordinate from world space to something else....
IkerCLoN
05072008, 12:53 PM
You can switch from global positions to parentbased positions using this:
localTM = objectTM * inverse (parentTM)
abyjoe
05072008, 07:44 PM
here is the script I am trying to modify (EdgeStraighten from scriptspot)  but it doesnt work properly i believe so i dont understand how to fix it in the first place...
all i want is from perspective view if i select few verts and then use pickpoint to select another two end verts... all the selected verts should align properly in x,y and z respective to the verts selected by pickpoint.... Any help would be greatly appreciated
macroScript VEPerfectCurve
ButtonText:"V/E Perfect Curve"
Category:"Frontier Tools"
icon:#("Splines",1)
Tooltip:"Make Vertices / Edges Perfect Curve"
(
function calc_pointpos pos points=
(
p1 = points[1]
p3 = points[2]
p2 = pos
k = (distance p1 p3)
a = (distance p1 p2)
b = (distance p2 p3)
m = (a^2b^2+k^2)/(k+k)
n = km
new = [0,0,0]
new.x = (n*p1.x+m*p3.x)/(n+m)
new.y = (n*p1.y+m*p3.y)/(n+m)
new.z = (n*p1.z+m*p3.z)/(n+m)
return new
)
function pick_points =
(
local savesnap=snapMode.active
snapMode.active=true
points_arry=#()
p1 = undefined
p3 = undefined
p1 = pickPoint snap:#3d
if classof p1 == point3 then
p3 = pickPoint snap:#3d rubberBand:p1
points_arry = #(p1,p3)
snapMode.active=false
return points_arry
)
function edges2vertex edges_arry polyObj =
(
vert_arry=#()
edges_arry = edges_arry as array
for k = 1 to edges_arry.count do
(
v = polyOp.getEdgeVerts polyObj edges_arry[k]
append vert_arry v[1]
append vert_arry v[2]
)
vert_arry = vert_arry as bitarray
vert_arry = vert_arry as array
return vert_arry
)
function get_vertex points polyObj =
(
vert_arry=#()
sl = getSelectionLevel polyObj
vert_arry = case sl of
(
#vertex:polyop.getVertSelection polyObj
#edge:edges2vertex (polyop.getEdgeSelection polyObj) polyObj
default:#()
)
vert_arry = vert_arry as array
return vert_arry
)
function set_vertex points sel_arry obj polyObj=
(
undo on
(
for k = 1 to sel_arry.count do
(
pos = polyOp.getVert polyObj sel_arry[k] node:obj
print (pos.x as string + "  " + pos.y as string + "  " + pos.z as string)
print "_______________________________"
newpos = calc_pointpos pos points
polyOp.setVert polyObj sel_arry[k] newpos node:obj
)
) undo
)
if selection.count == 1 then
(
 Gets the type of object i.e. Editable Poly / Mesh.
polyObj = $.baseobject
if classof polyObj == Editable_Poly then
(
setWaitCursor()
with redraw off
obj=$
if (getSelectionLevel polyObj) == #vertex or (getSelectionLevel polyObj) == #edge then
(
 Check if the Edge Constraints are on  Returns 0 if its
cur_const = getProperty polyobj #constrainType
setProperty polyobj #constrainType 0
points = pick_points()
if classof points[1] == point3 and classof points[2] == point3 do
(
verts = get_vertex points polyObj
if verts.count != 0 then
(
set_vertex points verts obj polyObj
 bug?!
 max move
)
else
(
messagebox "Select Some Vertex Or Edges" title:"Straighten edge"
)
)
setArrowCursor()
setProperty polyobj #constrainType cur_const
)
else
(
messagebox "Activate Vertex/Edge subobject level" title:"Straighten edge"
)
)
else
(
messagebox "Select Editable Poly Object" title:"Straighten edge"
)
)
else
(
messagebox "Select Editable Poly Object" title:"Straighten edge"
)
)
JHaywood
05082008, 08:37 PM
I can't tell you offhand why it's not working as expected. But the idea of picking the end points manually seems unnecessary. You should be able to pick the end verts in a row of selected verts or edges through script. Just do a check to find the two verts that only have one of the other selected verts in common, if that makes sense.
abyjoe
05092008, 08:22 AM
ok great... I will have a look into that... thanks for pointing out
davestewart
05092008, 09:22 AM
Hey Abhishek,
Just a quickie, but you could simplify your points calculation in this bit:
new = [0,0,0]
new.x = (n*p1.x+m*p3.x)/(n+m)
new.y = (n*p1.y+m*p3.y)/(n+m)
new.z = (n*p1.z+m*p3.z)/(n+m)
return new
(n * p1 + m * p3) / (n + m)
EDIT: Actually just checked and it runs in a quarter of the time. Nice :)
Also, miss out the "return new" statement; just end with that calculation (the function will run faster)
Cheers,
Dave
CGTalk Moderation
05092008, 09:22 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.