How to remove position_script()?

Become a member of the CGSociety

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

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 09 September 2012   #16
Is it possible position_xyz()/float_script() to work in local coordinates of the objects?
The example below work only with world coordinates. If I rotate the objects, then select $pXplus and move it in local space the rest of the objects move in the world space.
This addition does not work:

 x.addConstant "centerObjTM" (centerObj.transform)
    x.setexpression "in coordsys centerObjTM (obj01.pos.x + obj02.pos.x)/2"   



(
   	global rol_test
   	try(destroyDialog rol_test)catch()
   	rollout rol_test ""
   	(
   		local pXplus = undefined
   		local pXminus = undefined
   		local pYplus = undefined
   		local pYminus = undefined
   		local pZplus = undefined
   		local pZminus = undefined
   		
   		button btn_start "Start"
   		
   		function AddPositionScript centerObj obj01 obj02 lock:#xyz =
   		(	
   			p = centerObj.pos.controller = position_xyz()
   			x = p[1].controller = float_script()
   			x.addobject "obj01" (NodeTransformMonitor node:obj01)
   			x.addobject "obj02" (NodeTransformMonitor node:obj02)
   			x.addConstant "centerObjTM" (centerObj.transform)
   			x.setexpression "in coordsys centerObjTM (obj01.pos.x + obj02.pos.x)/2"			
   		)
   		
   		function ObjPosChanged =
   		(
   			deleteAllChangeHandlers id:#ObjPosChangedID
   			if selection.count == 1 do
   			(
   				case selection[1] of
   				(
   					(pXplus): 
   					(
   						for m in #(pYplus,pYminus,pZplus,pZminus) do
   							AddPositionScript m pXplus pXminus lock:#x
   					)
   				)
   			)			
   		)
   		
   		on btn_start pressed do
   		(
   			pXplus = point name:"pXplus" pos:[50,0,25]
   			pXminus = point name:"pXminus" pos:[-50,0,25]
   			pYplus = point name:"pYplus" pos:[0,50,25]
   			pYminus = point name:"pYminus" pos:[0,-50,25]
   			pZplus = point name:"pZplus" pos:[0,0,0]
   			pZminus = point name:"pZminus" pos:[0,0,50]
   			
   			deleteAllChangeHandlers id:#ObjPosChangedID
   			callbacks.removescripts id:#ObjPosChangedID			
   			callbacks.addscript #selectionSetChanged "rol_test.ObjPosChanged()" id:#ObjPosChangedID	
   		)
   		
   		on rol_test close do
   		(
   			deleteAllChangeHandlers id:#ObjPosChangedID
   			callbacks.removescripts id:#ObjPosChangedID
   		)
   	)
   	createdialog rol_test 
   )
 
Old 09 September 2012   #17
Originally Posted by miauu: Is it possible position_xyz()/float_script() to work in local coordinates of the objects?
The example below work only with world coordinates. If I rotate the objects, then select $pXplus and move it in local space the rest of the objects move in the world space.

i don't understand what you want to get.
post a picture that shows how the nodes should move, it might make the issue clearer.
 
Old 09 September 2012   #18
All objects are rotated at arbitrary angle.
With when cosntruct the objects are moved correctly - they follow the selected object using its local X axis.
With position_xyz/float_Script() the objects are moved in the world space(Xaxis).
As you can see when I select the object, that I want to move the objects in the center are aligned on the world X axis.
Whan I need the objects to be movd with position_xyz/float_Script() but to use the selected object local X axis(as with the when cosntruct).
 
Old 09 September 2012   #19
it's clear now. let me think how it can be scripted...
 
Old 09 September 2012   #20
Originally Posted by denisT: it's clear now. let me think how it can be scripted...


 delete objects
 p1 = point name:"p1" pos:[-20,0,0]
 p2 = point name:"p2" pos:[20,0,0]
 p0 = dummy name:"p0" pos:[0,0,0]
 
 -- XY constraint, Z freet:
 p = p0.pos.controller = position_list()
 s = p.available.controller = position_script()
 p.active = 1
 lockedtracksman.setlocks on #(p[1][1],p[1][2]) #(p[1],p[1]) #(1,2) off
 
 s.addobject "p0" p0.rotation.controller
 s.addobject "p1" (NodeTransformMonitor node:p1)
 s.addobject "p2" (NodeTransformMonitor node:p2)
 s.setexpression "(p1.pos + p2.pos)*[0.5,0.5,0]*p0.value"
 
 
Old 09 September 2012   #21
Thank you for this solution. I learned a lot from you in this thread.
My script still not work as I want.



The script:
(
 	global rol_test
 	try(destroyDialog rol_test)catch()
 	rollout rol_test ""
 	(		
 		local pXplus = undefined
 		local pXminus = undefined
 		local pYplus = undefined
 		local pYminus = undefined
 		local pZplus = undefined
 		local pZminus = undefined
 		
 		button btn_start "Start"
 		
 		function AddPositionScript p0 p1 p2 =
 		(	
 			-- XY constraint, Z freet:
 			p = p0.pos.controller = position_list()
 			s = p.available.controller = position_script()
 			p.active = 1
 			lockedtracksman.setlocks on #(p[1][1],p[1][2]) #(p[1],p[1]) #(1,2) off
 			
 			s.addobject "p0" p0.rotation.controller
 			s.addobject "p1" (NodeTransformMonitor node:p1)
 			s.addobject "p2" (NodeTransformMonitor node:p2)
 			s.setexpression "(p1.pos + p2.pos)*[0.5,0.5,0]*p0.value"			
 		)
 		
 		function ObjPosChanged =
 		(
 			deleteAllChangeHandlers id:#ObjPosChangedID
 			if selection.count == 1 do
 			(
 				case selection[1] of
 				(
 					(pXplus): 
 					(
 						for m in #(pYplus,pYminus,pZplus,pZminus) do
 							AddPositionScript m pXplus pXminus
 					)
 				)
 			)			
 		)
 		
 		on btn_start pressed do
 		(
 			if selection.count == 1 then
 			(
 				--	get the selected object
 				local curObj = selection[1]
 				local objLocalBBox = nodeLocalBoundingBox curObj 
 				local tm = curObj.objectTransform
 				local bmin = objLocalBBox[1]*(inverse tm) 
 				local bmax = objLocalBBox[2]*(inverse tm)
 				local center = ((bmin + bmax)/2)				
 				
 				pXplus = point name:"pXplus"
 				pXminus = point name:"pXminus"
 				pYplus = point name:"pYplus"
 				pYminus = point name:"pYminus"
 				pZplus = point name:"pZplus"
 				pZminus = point name:"pZminus"
 				
 				mArr = #(pXplus,pXminus,pYplus,pYminus,pZplus,pZminus)
 				for m in mArr do
 				(
 					m.transform = curObj.transform
 					m.scale = [1,1,1]
 				)
 				pXplus.pos = ([bmax.x,center.y,center.z]*(tm))
 				pXminus.pos = ([bmin.x,center.y,center.z]*(tm))
 				pYplus.pos = ([center.x,bmax.y,center.z]*(tm))
 				pYminus.pos = ([center.x,bmin.y,center.z]*(tm))
 				pZplus.pos = ([center.x,center.y,bmax.z]*(tm))
 				pZminus.pos = ([center.x,center.y,bmin.z]*(tm))				
 				
 				setTransformLockFlags  pXplus #{2..9}
 				setTransformLockFlags  pXminus #{2..9}
 				setTransformLockFlags  pYplus #{1,3..9}
 				setTransformLockFlags  pYminus #{1,3..9}
 				setTransformLockFlags  pZplus #{1,2,4..9}
 				setTransformLockFlags  pZminus #{1,2,4..9}
 				--
 				deleteAllChangeHandlers id:#ObjPosChangedID
 				callbacks.removescripts id:#ObjPosChangedID			
 				callbacks.addscript #selectionSetChanged "rol_test.ObjPosChanged()" id:#ObjPosChangedID					
 			)	
 		)
 		
 		on rol_test close do
 		(
 			deleteAllChangeHandlers id:#ObjPosChangedID
 			callbacks.removescripts id:#ObjPosChangedID
 			delete helpers
 		)
 	)
 	createdialog rol_test 
 )
 
Old 09 September 2012   #22
the thing that you have shown last time is a position constraint by 50/50

 delete objects
 p1 = point name:"p1" pos:[-20,0,0]
 p2 = point name:"p2" pos:[20,0,0]
 p0 = dummy name:"p0" pos:[0,0,10]
 
about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)

 p = p0.position.controller = position_constraint relative:on
 p.appendTarget p1 50
 p.appendTarget p2 50
 

Last edited by denisT : 09 September 2012 at 06:37 PM.
 
Old 09 September 2012   #23
Thank you, Denis.
This makes the code shorter and works as I want.

I have some more questions
1) - can I use position constraint achive the result from the code below?
(the two points follow only the X or Y)
(
 	delete objects
 	p1 = point name:"p1" pos:[-20,0,0]
 	p2 = point name:"p2" pos:[20,20,0]
 	p0 = dummy name:"p0" pos:[20,0,0]
 	
 -- 	about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)
 	
 	--	can this be achieved with position_constraint
 	p1.parent = p2.parent = p0
 	setInheritanceFlags p1 #{2} keepPos:true
 	setInheritanceFlags p2 #{1} keepPos:true
 )


2) setInheritanceFlags works only with world coordinates or I miss something? If you uncoment the
about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)

the p1 and p2 will follow the world X and Y coordinates of p0.
 
Old 09 September 2012   #24
Originally Posted by miauu: I have some more questions
1) - can I use position constraint achive the result from the code below?
(the two points follow only the X or Y)

2) setInheritanceFlags works only with world coordinates or I miss something?


1) here is how to do it:

set redraw off

delete objects
p1 = point name:"p1" pos:[-20,0,0]
p2 = point name:"p2" pos:[20,0,0]
p0 = dummy name:"p0" pos:[0,0,10]

about [0,0,0] rotate #(p0,p1,p2) (eulerangles 0 0 45)

a = p0.pos.controller
p = p0.pos.controller = createinstance position_list
c = p.available.controller = position_constraint()
f = p.available.controller = a
p.active = 2

lockedtracksman.setlocks on #(f[1],f[2]) #(f,f) #(1,2) off

c.appendTarget p1 50
c.appendTarget p2 50

set redraw on


2) do you mean TransformLockFlags? for InheritanceFlags the coordinate system doesn't make sense.
 
Old 09 September 2012   #25
BTW... what you are making looks like a manipulator for me. why is it not a manipulator?
 
Old 09 September 2012   #26
I meaned TransformLockFlags.
It is a kind of manipulator. I started with scriptedManipulators, but with no success.
 
Old 09 September 2012   #27
Originally Posted by miauu: I meaned TransformLockFlags.
It is a kind of manipulator. I started with scriptedManipulators, but with no success.

I saw somethihg here http://forums.cgsociety.org/showthr...mpleManipulator
__________________
Looking in the right side. [bgaTools]
 
Old 09 September 2012   #28
Originally Posted by miauu: I meaned TransformLockFlags.
It is a kind of manipulator. I started with scriptedManipulators, but with no success.

TransformLockFlags lock only possibility to change transformation in world space using Transform Gizmo. They don't really lock controllers. You still be able to change the transform any other way than using gizmo.
 
Old 09 September 2012   #29
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed 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 09:52 PM.


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