CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 03-25-2013, 12:00 AM   #1
AlexeyGapon
Veteran
 
AlexeyGapon's Avatar
portfolio
Alexey Gapon
Kiev, Ukraine
 
Join Date: Mar 2013
Posts: 41
Send a message via ICQ to AlexeyGapon
Float_Script() instead of Lookat_constraint ()

Hello. Very glad to be on this forum. Since there is the opportunity to talk with professionals from around the world.
I am working on a complex rig. It will consist of a set of splines and points. The problem is in the fact that I can not use a "lookat" controller. Because 3d max starts very slow when the count of the objects with this controller become very large. I found that using of the float_script () controller do not slow 3d max and i can use it for my rig. But i have a problem with correct algorithm. Can somebody help me with this problem i need scripts for float_script() controllers to achieve the same result as the LookAt_Constraint () with such parameters as:

Will retype parameters here if something will be wrong with the image in couple of years.

Keep Inital Offset - false
LookAt Axis - X

"Select Upnode"
World - false upnode - SomeNode

"Upnode control"
LookAt - false
AxisAlignment - true
"Source/Upnode Alignment"
Sourse Axis - Z
uligned to upnode Axis - Z
 
Old 03-26-2013, 07:24 PM   #2
MZ
Expert
 
MZ's Avatar
portfolio
Mehdi Zangeneh
Animation TD
Bina Film
Tehran, Iran
 
Join Date: Sep 2007
Posts: 338
I suggest you to use IK solver instead of float script.
__________________
http://3dcutout.com/
 
Old 03-26-2013, 08:59 PM   #3
AlexeyGapon
Veteran
 
AlexeyGapon's Avatar
portfolio
Alexey Gapon
Kiev, Ukraine
 
Join Date: Mar 2013
Posts: 41
Send a message via ICQ to AlexeyGapon
Could you show an exmple?
 
Old 03-26-2013, 11:04 PM   #4
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
first of all the float_script controller can't replace rotation controller. so you have to use rotation_script at least.
second... script controller will be slower for sure than lookat controller. it needs some math, almost the same as lookat does do, but written on mxs instead of c++
and third... what does slow mean in your case? i don't think that 100 lookat controllers can drammatically slow down a performance.
 
Old 03-27-2013, 08:27 AM   #5
AlexeyGapon
Veteran
 
AlexeyGapon's Avatar
portfolio
Alexey Gapon
Kiev, Ukraine
 
Join Date: Mar 2013
Posts: 41
Send a message via ICQ to AlexeyGapon
Quote:
Originally Posted by denisT
first of all the float_script controller can't replace rotation controller. so you have to use rotation_script at least.
second... script controller will be slower for sure than lookat controller. it needs some math, almost the same as lookat does do, but written on mxs instead of c++
and third... what does slow mean in your case? i don't think that 100 lookat controllers can drammatically slow down a performance.


In my case i mean that i can`t select non part of the rig. If i will try to select the Point helper or a Spline or something else it takes more then 20 minutes to make this Point selected. I found that using scripts controllers do not lead to this result.
 
Old 03-27-2013, 05:01 PM   #6
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
Quote:
Originally Posted by AlexeyGapon
In my case i mean that i can`t select non part of the rig. If i will try to select the Point helper or a Spline or something else it takes more then 20 minutes to make this Point selected. I found that using scripts controllers do not lead to this result.

how many lookat controllers do you have in the scene?
it seems like something broken in your max installation or in your rig.
as you can see from this snippet:
Code:
fn setLookAtPointControl point target = ( c = point.controller.rotation.controller = createinstance LookAt_Constraint viewline_length_abs:off lookat_vector_length:0 c.appendTarget target 100 c.upnode_world = off c.pickUpNode = target c ) delete objects max create mode count = 1000 with redraw off, undo off for k=0 to count-1 do ( p = point pos:[k,0,0] size:10 wirecolor:orange t = dummy pos:[k,20,0] boxsize:[10,10,10] setLookAtPointControl p t )

everything works with expected performance.
 
Old 03-27-2013, 08:14 PM   #7
AlexeyGapon
Veteran
 
AlexeyGapon's Avatar
portfolio
Alexey Gapon
Kiev, Ukraine
 
Join Date: Mar 2013
Posts: 41
Send a message via ICQ to AlexeyGapon
Greate style of code writing thank you. Yes you are right if there are only two nodes points and targets the count of LookAt constraints can be very large. But i have 2 big splines controlled with skin modifier. On that two big splines i put 63 splines (for example $SimpleSpline_01, .._02, .._03..., _63) with 3 vertexes. The first vertex of each "SimpleSpline"is on the first spline the last vertex is on the second spline there coordinates i calculate form path() constraint from big splines. Then Each $SimpleSpline has 12-21 points with lookat constraint and every point use next point on that spline as the LookAt target. At the position of every last vertex of each SimpleSpline has a point with LookAt Controller and this point use next SimpleSpline last vertex Point as the LookAt target.

And if i will create more then 10 SimpleSplines and more then 8 helper points on each SimpleSpline i can`t use LookAt controllers for Points wich situated on the last vertexes positions. But i can use script Controllers I tried more then 1000 SimpleSplines and it run with good performance.
Code:
function fnCreateScriptControllerYaxis node_LookAtTarget node_Obj = ( str_Script = "" array_line = #() str_NewLine = "\n" array_line [1] = "node_LookAtTarget=$" + node_LookAtTarget.name array_line [2] = "if (node_LookAtTarget != undefined) then (" array_line [3] = " node_Obj=$" + node_Obj.name array_line [4] = " dependsOn node_LookAtTarget.pos.controller node_Obj.pos.controller" array_line [5] = " x=node_Obj.pos.x - node_LookAtTarget.pos.x" array_line [6] = " z=node_Obj.pos.z - node_LookAtTarget.pos.z" array_line [7] = " a=atan(x/z)" array_line [8] = " if z < 0 then degToRad(a - 90) else degToRad (a + 90) " array_line [9] = " ) else 0" with redraw off, undo off for i = 1 to array_line.count do str_Script += array_line[i] + str_NewLine str_Script ) function fnCreateScriptControllerXaxis node_LookAtTarget node_Obj = ( str_Script = "" array_line = #() str_NewLine = "\n" array_line [1] = "node_LookAtTarget=$" + node_LookAtTarget.name array_line [2] = "if (node_LookAtTarget != undefined) then (" array_line [3] = " node_Obj=$" + node_Obj.name array_line [4] = " dependsOn node_LookAtTarget.pos.controller node_Obj.pos.controller" array_line [5] = " y=node_Obj.pos.y - node_LookAtTarget.pos.y" array_line [6] = " z=node_Obj.pos.z - node_LookAtTarget.pos.z" array_line [7] = " a=atan(z/y)" array_line [8] = " if y < 0 then degToRad(a + 90) else degToRad (a - 90) " array_line [9] = " ) else 0" with redraw off, undo off for i = 1 to array_line.count do str_Script += array_line[i] + str_NewLine str_Script ) function fnCreateBasePoints node_baseSpline node_targetSpline int_Rows int_Columns = ( array_PointsArray = #() string_ScriptControllerYaxis = "" string_ScriptControllerXaxis = "" with redraw off, undo off ( for i = 1 to int_Rows do array_PointsArray = append array_PointsArray #() for j = 1 to int_Columns do ( array_PointsArray [1] [j] = fnCreateNewBasePoint ("FB_Point_Base_" + (fnGetStrCount j)) array_PointsArray [int_Rows] [j] = fnCreateNewBasePoint ("FB_Point_Target_" + (fnGetStrCount j)) array_PointsArray [1] [j].transform.controller.position.controller = fnCreateNewPathControllerForBasePoints node_baseSpline 1 j int_Columns array_PointsArray [int_Rows] [j].transform.controller.position.controller = fnCreateNewPathControllerForBasePoints node_targetSpline 1 j int_Columns deleteKeys array_PointsArray [1] [j] #allKeys deleteKeys array_PointsArray [int_Rows] [j] #allKeys ) for j = 0 to int_Columns - 2 do ( --array_PointsArray [int_Rows] [int_Columns-j].transform.controller.rotation.controller = fnCreateNewLookAtContForBasePoints ( array_PointsArray [int_Rows][int_Columns - j - 1]) - can`t use it for more then 15 splines -- target node base node string_ScriptControllerYaxis = fnCreateScriptControllerYaxis array_PointsArray [int_Rows][int_Columns - j - 1] /*-*/ array_PointsArray [int_Rows] [int_Columns-j] --print "ScriopController = " --print string_ScriptController array_PointsArray [int_Rows] [int_Columns-j].transform.controller.rotation.controller = Euler_XYZ() array_PointsArray [int_Rows] [int_Columns-j].transform.controller.rotation.controller[2].controller = float_script() array_PointsArray [int_Rows] [int_Columns-j].transform.controller.rotation.controller[2].controller.script = string_ScriptControllerYaxis ) -- for for i = 1 to int_Columns do ( -- target node base node string_ScriptControllerXaxis = fnCreateScriptControllerXaxis array_PointsArray [1] [i] /*-*/ array_PointsArray [int_Rows] [i] array_PointsArray [int_Rows] [i].transform.controller.rotation.controller[1].controller = float_script() array_PointsArray [int_Rows] [i].transform.controller.rotation.controller[1].controller.script = string_ScriptControllerXaxis array_PointsArray [int_Rows] [i].transform.controller.rotation.controller[3].controller = float_script() array_PointsArray [int_Rows] [i].transform.controller.rotation.controller[3].controller.script = "0" )-- for )-- UNDO end gc () /*return*/ array_PointsArray )



This is code from my script. I tried to copy result using script controllers. But something wrong with math.

Last edited by AlexeyGapon : 03-27-2013 at 08:21 PM.
 
Old 03-27-2013, 08:51 PM   #8
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
i still think that something is wrong in your lookat setup. probably some 'pseudo' circular dependencies. which cause a lot of notifications...
 
Old 03-27-2013, 09:03 PM   #9
AlexeyGapon
Veteran
 
AlexeyGapon's Avatar
portfolio
Alexey Gapon
Kiev, Ukraine
 
Join Date: Mar 2013
Posts: 41
Send a message via ICQ to AlexeyGapon
In result it should be something like editable patch with points as bones but with lookat controllers
 
Old 03-27-2013, 09:33 PM   #10
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
Quote:
Originally Posted by denisT
i still think that something is wrong in your lookat setup. probably some 'pseudo' circular dependencies. which cause a lot of notifications...


it seems like you are right, and i'm wrong. there is something in LookAt_Constraint that causes some weird dependencies.
here is a sample that works to 10 points, and doesn't work for 20 already.
Code:
fn setLookAtPointControl point target = ( c = point.controller.rotation.controller = createinstance LookAt_Constraint viewline_length_abs:off lookat_vector_length:0 c.appendTarget target 100 c.upnode_world = off c.pickUpNode = target c ) disableRefMsgs() delete objects gc() max create mode count = 10 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 wirecolor:orange p.pos.controller = createinstance Path_Constraint path:path percent:((k+1)*100./count) follow:off p --setLookAtPointControl p t ) for k=1 to pp.count while not keyboard.escpressed do ( if k < pp.count do setLookAtPointControl pp[k] pp[k+1] ) ) enableRefMsgs()

create points and try to select any of them... for 10 points it's OK, for 20 it's very slow, for 50 it's infinity...
 
Old 03-27-2013, 09:45 PM   #11
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
... and the similar test works fine for 200 points and LookAt transform:
Code:
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 ( point pos:[k,0,0] size:10 wirecolor:orange ) for k=1 to pp.count while not keyboard.escpressed do ( if k < pp.count do pp[k].target = pp[k+1] pp[k].pos.controller = createinstance Path_Constraint path:path percent:(k*100./count) follow:off ) )


i looks like a bug in LookAt_Constraint controller.
 
Old 03-27-2013, 09:47 PM   #12
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
so... script controller is definitely slower than lookat_constraint but it works!
it's good to know about the lookat_constraint limitation. i have never got it before.
 
Old 03-27-2013, 10:08 PM   #13
AlexeyGapon
Veteran
 
AlexeyGapon's Avatar
portfolio
Alexey Gapon
Kiev, Ukraine
 
Join Date: Mar 2013
Posts: 41
Send a message via ICQ to AlexeyGapon
I didn`t think that it will be a problem (lookat) but it is (((. 50 - infiniti - you are right. But still could you help me with the maths? Because this two functions creates script controllers but the points are over rotated. ((
 
Old 03-27-2013, 10:18 PM   #14
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,424
Send a message via ICQ to denisT
Quote:
Originally Posted by denisT
it seems like you are right, and i'm wrong. there is something in LookAt_Constraint that causes some weird dependencies.
here is a sample that works to 10 points, and doesn't work for 20 already.
Code:
fn setLookAtPointControl point target = ( c = point.controller.rotation.controller = createinstance LookAt_Constraint viewline_length_abs:off lookat_vector_length:0 c.appendTarget target 100 --c.upnode_world = off --c.pickUpNode = target c ) disableRefMsgs() delete objects gc() max create mode count = 10 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 wirecolor:orange p.pos.controller = createinstance Path_Constraint path:path percent:((k+1)*100./count) follow:off p --setLookAtPointControl p t ) for k=1 to pp.count while not keyboard.escpressed do ( if k < pp.count do setLookAtPointControl pp[k] pp[k+1] ) ) enableRefMsgs()

create points and try to select any of them... for 10 points it's OK, for 20 it's very slow, for 50 it's infinity...


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?
 
Old 03-27-2013, 10:49 PM   #15
AlexeyGapon
Veteran
 
AlexeyGapon's Avatar
portfolio
Alexey Gapon
Kiev, Ukraine
 
Join Date: Mar 2013
Posts: 41
Send a message via ICQ to AlexeyGapon
With 10 points it works fine. But with 20 points i tried to select one and 3D MAX crashed.
Very unexpected Bug (((

Last edited by AlexeyGapon : 03-27-2013 at 10:52 PM.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:31 AM.


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