I wonder if it is possible to do the same thing that is incorporated in script controllers but do it in wire parameters.🤔
I ask the question because when using many controllers with script controller you can feel the slowdown in the viewer, and I'm only using it on one character. I don't want to imagine what can happen with 2 or 3 characters with script controllers in scene.
All inferring that wire parameters is faster "I don't know yet, that's why the question to compare".
Solved! Go to Solution.
Solved by denisT.MaxDoctor. Go to Solution.
Solved by denisT.MaxDoctor. Go to Solution.
First of all you have to optimize the code you use in Script controller.
If the code after optimization is still slow you can try to find better solution (expression controller, wire, constraints, etc.)
let's look at your current script:
v = v_pos.value
if v.z < f0 then z = v.z * 0.2 - f0 else if v.z > f0 then z = v.z * 0.01 - f0 else z = 0
if v.x < f0 then z = -v.x * 0.2 - f0 else if v.x > f0 then z = -v.x * 0.2 - f0 else x = 0
if v.y < f0 then z = v.y * -5.0 - f0 else if v.y > f0 then y = -v.y * 5 - f0 else y = 0
[x, y, z]
is it not the same as:
v = v_pos.value
x = if v.x != f0 then -0.2 else 0
y = if v.y != f0 then -5.0 else 0
z = if v.z < f0 then 0.2 else if v.z > 0 then 0.01 else 0
v * [x,y,z] - f0
or:
v = v_pos.value
v.x = if v.x != f0 then -0.2 * v.x else 0
v.y = if v.y != f0 then -5.0 * v.y else 0
v.z = if v.z < f0 then 0.2 * v.z else if v.z > 0 then 0.01 * v.z else 0
v - f0
Second, you need to think about how often your script controller is called. It is called by time changing and when other objects that the controller depends on change ... so you should minimize the number of calls.
do you think it's slow?
delete objects
d = dummy name:#source
p = point name:#target size:30 wirecolor:red
s = d.pos.controller = position_script()
s.addconstant #f0 [0,0,0]
s.addobject #v_pos p.pos.controller
s.setexpression \
@"
v = v_pos.value
v.x = if v.x != f0.x then -0.2 * v.x else 0
v.y = if v.y != f0.y then -5.0 * v.y else 0
v.z = if v.z < f0.z then 0.2 * v.z else if v.z > 0 then 0.01 * v.z else 0
v - f0
"
(
t0 = timestamp()
h0 = heapfree
for k=1 to 10000 do
(
at time k d.pos
)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
)
When you post a code snippet and the code matters, please do so in plain text. The "image" code takes time to read and retype correctly. Sometimes this can be the reason for me just not answer ...
Look at this snippet:
fn getscriptpos v_pos f0:[0,0,0] =
(
v = v_pos --.value
v.x = if v.x != f0.x then -0.2 * v.x else 0
v.y = if v.y != f0.y then -5.0 * v.y else 0
v.z = if v.z < f0.z then 0.2 * v.z else if v.z > 0 then 0.01 * v.z else 0
v - f0
)
delete objects
d = dummy name:#source
p = point name:#target size:30 wirecolor:red
paramWire.connect p.transform.controller[#Position] d.transform.controller[#Position] "getscriptpos Position"
(
t0 = timestamp()
h0 = heapfree
for k=1 to 10000 do
(
at time k d.pos
)
format "time:% heap:%\n" (timestamp() - t0) (h0 - heapfree)
)
Is "wire" controller faster than the script controller? Yes, it is. In general...
But looking into this example we can see that the "wiring" is used in the most convenient case, instead of the script which is used in its general case. The difference is not very significant in order to unnecessarily complicate the code, taking into account possible refinement and debugging of the code.
I look at this code and it's from another planet!
This is incredible, I have never seen such a thing. I am very surprised.😲
It's hard to tell what is wrong with your setup without seeing the code and the setup itself, but perhaps the snippet below will help you as an example and give you ideas of connections:
delete objects
m = dummy name:#master boxsize:[50,50,50]
p0 = point name:#target_0 pos:[-100, 0,0,0] wirecolor:red parent:m
p1 = point name:#target_1 pos:[100, 0,0,0] wirecolor:orange parent:m
d = dummy name:#source_0
s = sphere name:#source_1 wirecolor:yellow radius:20
cc = d.pos.controller = createinstance position_list
c = cc.available.controller = position_xyz()
cc.setname 1 "Zero Position"
paramWire.connect m.transform.controller[#Position] cc[#Zero_Position] "Position"
c = cc.available.controller = position_xyz()
cc.setname 2 "Target_0"
paramWire.connect p0.transform.controller[#Position] cc[#Target_0] "Position/2"
c = cc.available.controller = position_xyz()
cc.setname 3 "Target_1"
paramWire.connect p1.transform.controller[#Position] cc[#Target_1] "Position/2"
paramWire.connect d.transform.controller[#Position] s.transform.controller[#Position] "Position"
I was referring to the code you published yesterday, if I want to do the same but connecting position inside a position list, the 2 objects contain a position list and inside are connected positions by wire parameters.
Object---PositionList---PositionXYZ <-----connect the controller within the list to another object that also contains a position list
fn getscriptpos v_pos f0:[0,0,0] =
(
v = v_pos --.value
v.x = if v.x != f0.x then -0.2 * v.x else 0
v.y = if v.y != f0.y then -5.0 * v.y else 0
v.z = if v.z < f0.z then 0.2 * v.z else if v.z > 0 then 0.01 * v.z else 0
v - f0
)
delete objects
d = dummy name:#source
p = point name:#target size:30 wirecolor:red
paramWire.connect p.transform.controller[#Position] d.transform.controller[#Position] "getscriptpos Position"
do it manually first, and check the MAXScript listener output for right syntax and subanim names.
As an example, what I show in the image does not work.
I can not connect it if they are in the list of controllers.
As shown in the figure, you are trying to connect a controller from the Position List and an already connected position controller. You cannot do this because each controller (subanim) can only be wired once as driven. But 'wired' controller can be connected with another controller as a driver.
SUCCEED:
control_a -> control_b
control_b -> control_c
FAILED:
control_a -> control_b
control_c -> control_b
(you must disconnect control_b to be able to connect it with control_c)
Can't find what you're looking for? Ask the community or share your knowledge.