Notifications
Clear all

[Closed] Float_Script() instead of Lookat_constraint ()

i don’t have max to check right now myself… maybe anyone can make the same test but without setting a target as UpNode. is it the same result?

With 10 points it works fine. But with 20 points i tried to select one and 3D MAX crashed.
Very unexpected Bug (((

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

try to comment –disablerefmsgs and –enablerefmsgs

(@alexeygapon)
Joined: 11 months ago

Posts: 0

After that it works fine with 1000 points and i could select any of them without any problems. With 10000 points max crashed trying to create them but i think it is limitation of my computer not 3d studio. So it seems that the bug is in the “UpNode”.

I am sorry max crashed with 1000 too. With 200 works fine. And in Upnode “world” = false works fine too. But if try to set the “Upnode” 12- is the maximum that works.

this result is what i was expecting…
see what’s going on.
we have four points… the 1st looks at 2nd, 2nd looks at 3rd, 3rd looks at 4th
if we don’t use up vector our ‘look at’ depends on only target’s position. but if we use up vector it depends on target’s rotation too.
so get 1st rotation we have to get 2nd first, but get 2nd we have to get 3rd…
so without up vector we have the order of evaluation: 1-2-3
with up vector: 1-2-3-1, 2-3-2, 3.
and it’s a good scenario! the bad scenario is (and it’s more likely) if every next in the dependency chain controller sends propagated notification to all dependents. something is about factorial of number of chain members… for 20 members it’s 2432902008176640000

1 Reply
(@alexeygapon)
Joined: 11 months ago

Posts: 0

Oh… that is very unexpected too. Thank you for explanation! So is it possible to solwe this problem and use lookAt somehow? Or the only way is using the script controllers?

Felix Joleanes has a flippingless “look-at” script controller tutorial. Here on his site:

http://joleanes.com/tutorials/flippingless/flippingless_02.php

He goes thru all the math.

Thank you very much i will check this out!
Oh! It is just what i am looking for!


	theTargetVector=(Target.transform.position * Inverse Parent.transform)-NodePos.value
	theAxis=Normalize (cross theTargetVector [1,0,0])
	theAngle=acos (dot (Normalize theTargetVector) [1,0,0])
	Quat theAngle theAxis

But i need some modifications, could somebody help with it? Spine02 should have the same orientation on X axis as the Target has.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

code above is ok but…

well… here is the math:


fn addLookAtScript source target useasup:off = 
(
	c = source.rotation.controller = Rotation_Script()
	c.addnode "source" source
	c.addnode "target" target

	ss = ""
	ss += "front = normalize (target.pos - source.pos)
" 
	ss += "side = normalize (cross " + (if useasup then "target.transform[3]" else "[0,0,1]") + " front)
" 
	ss += "up = normalize (cross front side)
" 
	ss += "(matrix3 front side up [0,0,0]) as quat
" 

	c.setexpression ss
	c
)	

delete objects
source = point pos:[0,0,0] axistripod:on wirecolor:orange
target = dummy pos:[30,0,0] 

addLookAtScript source target useasup:on

if source and target have parents the code has to be slightly modified

200 works well… 400 crashes. probably it’s something about the depth of recursion.


fn addLookAtScript source target useasup:off = 
(
	c = source.rotation.controller = Rotation_Script()
	c.addnode "source" source
	c.addnode "target" target

	ss = ""
	ss += "front = normalize (target.transform[4] - source.pos)
" 
	ss += "side = normalize (cross " + (if useasup then "target.transform[3]" else "[0,0,1]") + " front)
" 
	ss += "up = normalize (cross front side)
" 
	ss += "(matrix3 front side up [0,0,0]) as quat
" 

	c.setexpression ss
	c
)	

disableRefMsgs()
delete objects 
gc()
max create mode
count = 200
animationrange = interval 0 100
with redraw off, undo off 
(
	path = circle radius:200
	addmodifier path (Bend axis:0 angle:90)
	converttosplineshape path
	
	pp = for k=0 to count-1 collect
	(
		p = point pos:[k,0,0] size:10 axistripod:off wirecolor:orange
		p.pos.controller = createinstance Path_Constraint path:path percent:((k+1)*100./count) follow:off
		p
	)
	for k=1 to pp.count while not keyboard.escpressed do 
	(
		if k < pp.count do addLookAtScript pp[k] pp[k+1] useasup:on
	)
)
enableRefMsgs()

the problem is – this construction is leaking badly in memory. read my old posts about scrip_controller leaking…

but this construction has ‘pseudo’ circular dependency too. if you will try to change a controller of any point you will never see the end… but selection works well…

Thank You denisT you helped a lot!!! I will try this code today!

 MZ1

fn IKLookAt Obj Target =
(
Pt = Point Name:(“LookAtPt”)
Pt.transform = Target.transform
Pt.parent = Obj
LookAtIK = IKSys.ikChain Obj Pt “IKHISolver”
LookAtIK.name = “LookAtIK”
LookAtIK.parent = Target
)
IKLookAt (teapot pos:[0,0,0]) (teapot pos:[0,0,100])

Page 2 / 2