[Closed] [SOLVED] Scripted controller self reference mystery on animated spline
@domos
Hehe, true true, but that is mainly for testing purposes
@Serejah
That works great up until you set the spline to rendering “Enable in viewport”. The self reference issue then pops up. However, It did render when I animated the helper and only set “Enable in renderer”, so there is that to play with!
@Eugine_M
I have a very similar solution to what you have made here, using a Custom attribute with functions. However, try to render a sequence of frames and you will notice that the spline is only rendered in it’s initial state. As far as I know, custom attributes are not re-evaluated after render start (not sure if that is the right terminology, but it’s something like that)
I know this is another issue I didn’t mention before, but one that I ran into and started this whole self reference exploration. If you know a way to force an update of the spline on each rendered frame, then that would solve a lot of my problems.
I not worked with renders at all. So yes, CA not update by render sequence (some kind of bug)… i think good idea – is bake spline animation when you need render. just put function in CA and call it when you need bake (in prerender callback or by hands). after you can do same to clear keys.
I also tried adding a separate renderable spline modifier to your sollution but that causes a crash.
I think what you suggest is the best solution at the moment yes. I’ll try and see if I can wrap up a bake spline animation into the CA
What if you disable ref messages for a moment of shape update? No errors now, but still not working with renderable spline mod
(
delete objects
gc()
p1 = point name:#pt_1 pos:[50,25,0]
p2 = point name:#pt_2 pos:[-50,25,0]
rect = Rectangle width:100 length:50
convertToSplineShape rect
animate on
(
at time 30f
(
p1.pos = [100,55,0]
p2.pos = [-50,-50,0]
rect.pos = [15,25,-50]
)
)
rect.render_displayRenderMesh = true
rect.render_sides.controller = float_script()
rect.render_sides.controller.addobject "owner" (reftargmonitor reftarg:rect)
rect.render_sides.controller.addNode "p1" p1
rect.render_sides.controller.addNode "p2" p2
rect.render_sides.controller.script = "
self = owner.reftarg
setKnotPoint self 1 1 p1.pos
setKnotPoint self 1 2 p2.pos
disableRefMsgs()
updateShape self
enableRefMsgs()
12
"
)
Ah, but that is one step closer to what I need. Funny to see the message below it in the help files though, “USE WITH EXTREME CAUTION”
But that whole chapter in the help file is interesting. I wonder if “notifydependents” could be used to force an update somehow. Not enough time to fiddle at the moment.
I was just now trying to add an attribute holder modifier and set some attributes for the spline animation behaviour, but the original object spline doesn’t update properly then. Just as you mentioned above with the renderable spline modifier.
Still really appreciate you guys thinking along here, I feel like I’m getting close to what I need
This is not the good way to animate splines (bind spline knots).
The best solution is to use the SimpleSpline plugin, but it was not available for earlier versions of MAX.
As an old school solution I would recommend something like this:
delete objects
with redraw off
(
global sp = line name:#spline wirecolor:green
sp.vertexTicks = on
addnewspline sp
numpts = 3
pp = for k=0.0 to numpts - 1 collect
(
pos = [k*40,0,0]
addknot sp 1 #smooth #curve pos
t = 1 - k/(numpts-1)
col = orange * t + yellow * (1 - t)
p = point name:(uniquename "p_") pos:pos wirecolor:col
)
updateshape sp
animatevertex sp #all
master = sp.baseobject[#master]
for k=0 to (numknots sp 1) - 1 do
(
c = master[k*3+1].controller = point3_xyz()
c = master[k*3+3].controller = point3_xyz()
s = master[k*3+2].controller = point3_script()
s.addnode "self" sp
s.addnode "target" pp[k+1]
s.setexpression "if isvalidnode target and isvalidnode self then (target.pos * self.transform) else [0,0,0]"
)
)
(as it was already suggested above)
you guys were right, animating the knots is a very good way to properly get an animated spline rendered. I went for a solution with a stored #prerender and #postrender callbacks that will animate the keys upon start of render, and will remove the keys once the render is done.
I might go for a more compacted approach and set the keys directly as you suggest above Denis, but for now I will go with this setup.
Thanks for all the help all of you