AWS Thinkbox Discussion Forums

"External" Update Call for Magma Modifier

So I just ran into something I thought might be helpful.

I created a PRT Volume with a simple MagmaMod to control the color with an exposed vector->color swatch. I copied the object a bunch of times and cycle through each giving them their own unique color via the exposed swatch. None of the colors would update in the viewport UNTIL i opened each MagmaMod and hit the manual update button.

By any chance, is it conceivable that when there are params exposed (or not for that matter) the “Update” call could be exposed too? I mean I suppose “Auto” is good, heck expose that too :slight_smile:

It is not the Modifier that needs updating. In the case of PRT objects, all modifiers are run by the base object (don’t ask!) :slight_smile:
So all you have to do is request an update of the PRT Volume, and the modifier (if set to Auto), will update too.

If you would look at the code behind the “Update” button in MagmaFlow, you will find that it is simply changing a property in the Magma modifier to fool Max’ validity interval that something changed and it should update…
In fact, the code looks like this:

magma.autoUpdate = magma.autoUpdate

The more it rains, the more it rains… :laughing:

This does not work completely with PRT Loaders because they have a dedicated viewport cache that keeps the particles. So the Update button in Magma also has this line:

local theNodes = for i in refs.dependentNodes magma where classof i.baseobject == KrakatoaPRTLoader do try(i.delegate.InvalidateObjectSpaceCache())catch()
This forces any PRT Loaders to drop their cache if they contain the given MagmaModifier (where ‘magma’ is the .MagmaHolder of the actual modifier)

So if you want to update a Magma modifier with a MAXScript, you can simply tell it to set autoUpdate to its own value.
And setting autoUpdate to true will enable the >AUTO button, obviously…
The code would look like

theMagmaMod.MagmaHolder.autoUpdate = theMagmaMod.MagmaHolder.autoUpdate

where theMagmaMod is a variable containing the Magma modifier you added.
Or, if you know it is the top modifier of the currently selected object, you can say

$.modifiers[1].MagmaHolder.autoUpdate = $.modifiers[1].MagmaHolder.autoUpdate

To set all Magma modifiers to Auto update, you could say

macroScript MagmaAutoOn category:"Krakatoa Tools" ( for o in objects do for m in o.modifiers where classof m == MagmaModifier do m.MagmaHolder.autoUpdate = true )
You could make a button on a toolbar that runs that code if you want to force all scene Magmas to auto-update with one click.

Alternatively, you can make a second icon with the code

macroScript MagmaUpdate category:"Krakatoa Tools"
(
  for o in objects do 
  (
    for m in o.modifiers where classof m == MagmaModifier do 
    (
      m.MagmaHolder.autoUpdate = m.MagmaHolder.autoUpdate
      for i in refs.dependentNodes m.MagmaHolder where classof i.baseobject == KrakatoaPRTLoader do 
        try(i.delegate.InvalidateObjectSpaceCache())catch()
    )
  )
)

which will perform an UPDATE of the modifiers without turning Auto on.

LOL so true :smiley:

Perfect enough for me! Thanks, I feel some UI work for me coming on. :slight_smile:

You can replace the loop through objects and modifiers with

for m in getClassInstances magmaModifier do m.MagmaHolder.autoUpdate = m.MagmaHolder.autoUpdate
The two versions do the same, but this one here uses an internal loop to find the magma instances, so it might be faster, and it looks cleaner, too.

I just learned something very useful there! Thanks :slight_smile:

Privacy | Site terms | Cookie preferences