Maxscript & Reaction Manager

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 10 October 2012   #1
Maxscript & Reaction Manager

Hello everybody

I have searching the net but didn't found any answer to my question, so i try posting here.
I want to create by using maxscript a reaction between a slider in a custom attribute and multiple weights of constraints ...

I have tried this code :
ikReactor = Float_Reactor()
fkReactor = Float_Reactor()
MyObj.rotation.controller[2].weight[1].controller = fkReactor
MyObj.rotation.controller[2].weight[2].controller = ikReactor
ikReactor.reactions.reactTo d.modifiers[1].fkik.controller
fkReactor.reactions.reactTo d.modifiers[1].fkik.controller
ikReactor.reactions.setName 1 "IK"
fkReactor.reactions.setName 1 "FK"

and here what i've got so far :

But what I want is to have both reactor in the 2 states "FK" & "IK" and I couldn't manage to have that. I didn't find the command to add 2 controllers in the same state. I only be able to create some new state each time.
Here is what I would want to have :


I don't know if I'm clear but if someone could help me, I would appreciate much !!
Thanks in advance
__________________
Remi
_______________________
http://www.edmondremi.com
 
Old 10 October 2012   #2
You have to use 'createstate' command by memory. By the way, reaction manager is buggy, slow and a pian to use. If you r scritping something, avoid it. there is always a solution that doesn't use it. I have wriiten a script that does everyhing recion manger does using sript expressions.
 
Old 10 October 2012   #3
thks for anwering me, this command doesn't seem to work.
Yeah the reaction manager seem to be very tricky to use by scripting.

As you did, I was wondering if it will not be better to script this reaction.
But even if I have chosen a simple example here, i will have also to do some reactions with 3 or more states for each controller depending on the value of the slider.
So by the way, I haven't found how to set by script several values to reach and just interpolate between these different states...
__________________
Remi
_______________________
http://www.edmondremi.com
 
Old 10 October 2012   #4
Yes, its called 'createreaction'. Also use 'setReactionState' Thats all you need basically. Its all there in the MXS help. Scripting RM isn't that difficult, it's just that if speed is imortant, then use script expressions. I don't see any need for reaction manager, I once scripted an entire facial animation rig using it and then I had to rewrite it all using script controllers when I discovered that it was too clunky and slow.
If you want to interpolate, you can use bezier function...but this is a little more advanced.
By the way, I'm puzzled why you'd search the net before searching the mxs help...

Last edited by floatingworld : 10 October 2012 at 12:24 PM.
 
Old 10 October 2012   #5
Of course I have searched the mxs help before searching the net and before posting here !
As I said, I was only able to create some new state each time.
I meant, I was using these commands "createreaction" or "setreactionstate"; but for example what results by using this method is :
ikReactor = Float_Reactor()
fkReactor = Float_Reactor()
MyObj.rotation.controller[2].weight[1].controller = fkReactor
MyObj.rotation.controller[2].weight[2].controller = ikReactor
ikReactor.reactions.reactTo d.modifiers[1].fkik.controller
fkReactor.reactions.reactTo d.modifiers[1].fkik.controller
ikReactor.reactions.setName 1 "IK"
fkReactor.reactions.setName 1 "FK"
createreaction ikReactor
setReactionState ikReactor 1 80
setReactionState ikReactor 2 50
ikReactor.reactions.setName 2 "FK"




and not only one state "IK" and one state "FK"...

I know reactions slow down the whole thing, but i will not have so many to set up. And as you said, defining a bezier function is a little bit advanced
__________________
Remi
_______________________
http://www.edmondremi.com
 
Old 10 October 2012   #6
instead of :
createreaction ikreactor
setReactionState ikReactor 1 80
setReactionState ikReactor 2 50

try:
createreaction ikreactor
setReactionState ikReactor 1 80
createreaction ikreactor
setReactionState ikReactor 2 50;

At least that's what i did in my ancient script that worked, at least.
I don't know if the order makes any difference anyway.
I mean - forget about trying to get things to look like they do in the reaction manager UI. I gave up on that, by memory.
As long as it works, who cares about getting things to look like they do in the UI window. RM is dodgy anwyays...

Last edited by floatingworld : 10 October 2012 at 01:18 PM.
 
Old 10 October 2012   #7
the reaction manager itself and the reactor controller is very buggy. i had many issues with it. like: #garbage data in the dialog, #loosing connections on undo/redo, #loosing connections with merge, etc.
so i recommend to not use it.
here is a sample how to do 'blend' control using the parameter wiring:

blendAttr = attributes blendAttr 
(
	parameters params rollout:params
	(
		blend type:#float default:50 animatable:on ui:(ui_blend_sl,ui_blend_sp)
	)
	rollout params "Parameters"
	(
		slider ui_blend_sl range:[0,100,50] type:#float width:102 align:#left offset:[-10,-10] across:2
		spinner ui_blend_sp range:[0,100,50] type:#float fieldwidth:46 align:#right offset:[6,0]
	)
	on create do
	(
		blend.controller = Bezier_Float() 
	)
)
delete objects

t1 = dummy name:"target1" pos:[-20,0,0] boxsize:[5,5,5]
t2 = dummy name:"target2" pos:[20,0,0] boxsize:[5,5,5]
s0 = dummy name:"source" pos:[0,0,0] boxsize:[10,10,10] isselected:on
custattributes.add s0 blendAttr baseobject:on
	
c = s0.position.controller = Position_Constraint()
c.appendTarget t1 50 
c.appendTarget t2 50
paramWire.connect s0.baseobject.blendAttr[#blend] c[1] "Blend"
paramWire.connect s0.baseobject.blendAttr[#blend] c[2] "100.0-Blend"
 
Old 10 October 2012   #8
The thing is if i try smthg like that :

ikReactor = Float_Reactor()
MyObj.rotation.controller[2].weight[2].controller = ikReactor
ikReactor.reactions.reactTo $dfsd_foot_ctrl_R.modifiers[1].fkik.controller
createreaction ikreactor
setReactionState ikReactor 1 80
createreaction ikreactor
setReactionState ikReactor 2 50


the result looks like that because when I assign the controller, a first state is automatically created :
__________________
Remi
_______________________
http://www.edmondremi.com
 
Old 10 October 2012   #9
Yeah - what denis said. he's the man when it comes to mxs.
Forget about the UI. RM is buggy.

edit***
Is the rig behaving as expected or not? Check values in listener

Last edited by floatingworld : 10 October 2012 at 01:49 PM.
 
Old 10 October 2012   #10
yes the UI is really buggy, doesn't matter. It's gonna be a total mess but who cares ...

Denis thanks for your script. Working very well, and could be very useful for me. But it works for two targets in this example. But if I have got 3 or more targets, how should you blend the positions ?
__________________
Remi
_______________________
http://www.edmondremi.com
 
Old 10 October 2012   #11
With 3 targets, I have tried this :
paramWire.connect s0.baseobject.blendAttr[#blend] c[1] "if Blend<=50.0 then(100.0-2*Blend)else(0.0)"
paramWire.connect s0.baseobject.blendAttr[#blend] c[2] "if Blend<50 then(2*Blend)else(if Blend>50 then(100-2*(Blend-50))else(100))"
paramWire.connect s0.baseobject.blendAttr[#blend] c[3] "if Blend>=50.0 then(2*Blend-100)else(0.0)"


It seems to work correctly, but for 4 or more, it's gonna be tricky , or is there a simple way ?
__________________
Remi
_______________________
http://www.edmondremi.com
 
Old 10 October 2012   #12
Originally Posted by TiSna: But if I have got 3 or more targets, how should you blend the positions ?


  undo on, redraw off
  (
  	delete objects
  	
  	t1 = dummy name:"target1" pos:[-20,0,0] boxsize:[5,5,5]
  	t2 = dummy name:"target2" pos:[0,-20,0] boxsize:[5,5,5]
  	t3 = dummy name:"target3" pos:[20,0,0] boxsize:[5,5,5]
  	t4 = dummy name:"target4" pos:[0,20,0] boxsize:[5,5,5]
  	s0 = dummy name:"source" pos:[0,0,0] boxsize:[10,10,10] isselected:on
  	custattributes.add s0 blendAttr baseobject:on
  		
  	c = s0.position.controller = Position_Constraint()
  	c.appendTarget t1 100 
  	c.appendTarget t2 0
  	c.appendTarget t3 0
  	c.appendTarget t4 0
  	paramWire.connect s0.baseobject.blendAttr[#blend] c[1] "100-3*Blend"
  	paramWire.connect s0.baseobject.blendAttr[#blend] c[2] "100-3*abs(Blend-100./3)"
  	paramWire.connect s0.baseobject.blendAttr[#blend] c[3] "100-3*abs(Blend-200./3)"
  	paramWire.connect s0.baseobject.blendAttr[#blend] c[4] "3*(Blend-200./3)"
  	ok
  )
  


and why do you think that the reactor controller can solve this task easier?

Last edited by denisT : 10 October 2012 at 02:47 PM.
 
Old 10 October 2012   #13
YEAHH !!! thank you very much for that, I would be able to adapt it perfectly in my case.

I thought using MR would have been easier, because for some reactions, it would not have been weights to target, but some given rotations for example. That's why I thought it would be easier to define them in MR and assign each value to a %of the slider
__________________
Remi
_______________________
http://www.edmondremi.com
 
Old 10 October 2012   #14
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.
 
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 12:56 AM.


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