Notifications
Clear all

[Closed] Obj transform data changes in structure

I stuck with one problem and can’t resolve it.
There a two spheres in scene with some distance between then . I want to move Sphere001 by Z let’s say a 10 units and Sphere002 start to move 5 units with When callback.

The problem is that Sphere002 start to move too much, cos for some reason initial sphere position value in structure start to change. In my case “objTInitial” value start to grow up.

If find the way to avoid this problem – write transform data as String, and then assemble matrix from string. In that’s case it’s work like it should, but it require lot of unnecessary calculations.


(
	--delete all handlers
	deleteAllChangeHandlers  id:#JB_when_cb
	
	structObjHolder = #() --hold structure
	struct obj_struct (onode,objTInitial)
	
	--save sphere1 initial transfroms 
	spere1InitTransform = $Sphere001.transform
	--create structure
	append structObjHolder  (obj_struct onode:$Sphere002 objTInitial:$Sphere002.transform)
	
	--add event handler
	when transform $Sphere001 change id:#JB_when_cb  do 
	(
		--find how object is transformed
		cObjT = $Sphere001.transform.translationpart - spere1InitTransform.translationpart
		for obj in structObjHolder do 
		(
			
			obj.onode.transform = translate (obj.objTInitial) (cObjT * 0.5)
			
			format "objTInitial: %
 "  structObjHolder[1].objTInitial
			
		) --end for
	) --end when 
)


20 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

that’s definitely a task to wire controllers… do you want me to show a sample?


delete objects
target = point pos:[20,0,0] size:10 wirecolor:orange
source = point pos:[0,0,0] size:10 wirecolor:green
paramwire.connect target.pos.controller[3] source.pos.controller[3] "z_position*0.5" 

another solution is a scripted controller… wanna see?


delete objects
target = point pos:[20,0,0] size:10 wirecolor:orange
source = point pos:[0,0,0] size:10 wirecolor:green
c = source.pos.controller[3].controller = float_script()
c.addtarget "target_z" target.pos.controller[3]
c.setexpression "target_z*0.5"

Two spheres i made for example to not post all code.
What i want is Object Soft selection – like in Maya and Xsi.
So it require a local and center selection transformation – Pos, Rot, Scale by some falloff.
I thought about wires but at first try want to make with direct transformations.
Thanks for snippets:)

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

ask the right questions… well. that’s a task for scripted transform… hmm… but i don’t want to give it to you for free. it will be too easy. hmm… what can we do? ok. i will show only position part of the script. wanna see?


delete objects
target = point pos:[20,0,0] size:10 wirecolor:orange
source = point pos:[0,0,0] size:10 wirecolor:green
c = source.transform.controller = transform_script()
c.addconstant "init_tm" source.transform
c.addtarget "target_tm" target[#transform]
c.setexpression "init_tm * (translate (target_tm.rotation as matrix3) (target_tm.pos*0.5))"

if you wanna know how to do it for whole matrix3 try to find my post about “how to blend two matrices”…

Actually i ask right
The questions about -Why values in Structure changed.
Definetly it’s work fine with rebuild Matrix3 from string. Cos this for modeling purpose i don’t want to use any controllers if possiible.
Thanks for help i keep in mind you solutions.

now you’ve asked right…
here is an answer to your right question


 delete objects
 
 node1 = point pos:[20,0,0] size:10 wirecolor:orange
 node2 = point pos:[0,0,0] size:10 wirecolor:green
 
 tm1
 tm2
 deleteallchangehandlers id:#soft_transform 
 fn holdTransform target source &tm1: &tm2: = if target.isselected and not source.isselected do 
 (
 	tm1 = target.transform
 	tm2 = source.transform
 )
 fn softTransform target source &tm1: &tm2: = if target.isselected and not source.isselected do
 (
 	tm = target.transform * (inverse tm1)
 	source.transform = tm2 * (translate (tm.rotation as matrix3) (tm.position*0.5))
 )
 
 when select node1 change id:#soft_transform node do holdTransform node node2 tm1:&tm1 tm2:&tm2
 when select node2 change id:#soft_transform node do holdTransform node node1 tm1:&tm2 tm2:&tm1
 
 when transform node1 change id:#soft_transform node do softTransform node node2 tm1:tm1 tm2:tm2
 when transform node2 change id:#soft_transform node do softTransform node node1 tm1:tm2 tm2:tm1
 
 
 
 

of course 0.5 has to be replaced with some factor based on an initial distance between source and target

but as i said … you have to blend matrices, not just simply multiply.

Page 1 / 2