Itoo Software Forum

Forest Pack => Forest Pro (*) => Topic started by: DrunkenMaster on March 22, 2023, 05:59:20 PM

Title: Copy effects parameters using maxscript
Post by: DrunkenMaster on March 22, 2023, 05:59:20 PM
Is there a way to copy parameters from effects rollout from one forest object to another ?
Or load .eff(.xml) file by max script ?

And how id values are generated in effects code for example:
<parameter id="{b76523ef-388a-e54e-bfdd-da989ed43e70}" name="DisplacementMap" description="" type="texmap"/>

I noticed that id value is rando each time. In .eff preset file I can see one value but then I load it is not the same, I can see that in maxscript listener.

I'm trying to write a script that creates specific effects in effects rollout with specified parameters and expressions. In other words  one click solution for loading .eff preset, without opening effects editor.
Example:

Code: [Select]
$Forest001.efidlist.count = 1
$.efidlist[1] = ""
$.efnamelist.count = 1
$.efnamelist[1] = ""
$.efxmllist.count = 1
$.efxmllist[1] = ""
$.efenablelist.count = 1
$.efidlist[1] = "{e4bd53e7-0563-bc44-400b-3c480684628b}"
$.efnamelist[1] = "Effect1"


$.efpatype[1] = 3
$.efpaeffid[1] = "{e4bd53e7-0563-bc44-400b-3c480684628b}"
$.efpaeffid[2] = "{e4bd53e7-0563-bc44-400b-3c480684628b}"
$.efpaeffid[3] = "{e4bd53e7-0563-bc44-400b-3c480684628b}"
$.efpafloatmax[3] = 1e+07
$.efpaeffid[4] = "{e4bd53e7-0563-bc44-400b-3c480684628b}"
$.efpanumtype[4] = 3
$.efpaeffid[5] = "{e4bd53e7-0563-bc44-400b-3c480684628b}"
$.efpanumtype[5] = 3
$.efpatype[6] = 4
$.efpaeffid[6] = "{e4bd53e7-0563-bc44-400b-3c480684628b}"
$.efnamelist[1] = "Follow Displaced Surface (Value)"


$.efxmllist[1] =
"<effect version=\""+"500"+"\">"+
"<expression>vector tintColor = evaluateTexture(DisplacementMap,fpItem.distUVW);"+
"real zOffset = (tintColor.x*DisplaceAmount)+DisplaceShift;"+
"vector vec = fpItem.position+(fpItem.surfNormal*zOffset);"+
"fpItem.position=vec;"+

"real Range = AltitudeMax-AltitudeMin;"+
"real NormalisedZPosition = min(1,(fpItem.position.z-AltitudeMin)/Range);"+
"fpItem.scale = if(fpItem.position.z&lt;=AltitudeMin,fpItem.scale*evaluateCurve(ScaleCurve, 0),"+
"if(fpItem.position.z&gt;=AltitudeMax,fpItem.scale*evaluateCurve(ScaleCurve, 1.0),fpItem.scale*evaluateCurve(ScaleCurve, NormalisedZPosition)));</expression>"+
"<parameter id=\""+"{9f3ea037-7ec5-68b7-2d62-d821240115f8}"+"\" "+"name=\""+"DisplacementMap"+"\" "+"description= \""+ "\" "+"type=\""+"texmap"+"\""+"/>"+
"</effect>"
Title: Re: Copy effects parameters using maxscript
Post by: DrunkenMaster on March 22, 2023, 07:51:37 PM
Ok I can store .xml code in reference forest object and copy expressions like this:
Code: [Select]
$.efxmllist[1] = ($ForestREF.efxmllist[1])
That is half way there.
But how can I copy parameters ?
This doesn't work:
Code: [Select]
$.efpatype[1] = 3
$.efpaeffid[1] = "{99dff3ff-547f-fce4-e1d6-97dbf61cc98b}"
$.efxmllist[1] = $ForestREF.efxmllist[1]
Title: Re: Copy effects parameters using maxscript
Post by: iToo on March 24, 2023, 09:00:00 AM
Hi,

Effects are stored in the following parameters:

efidlist : unique ID identifier, generated randomly
efnamelist : name
efxmllist : effect code in XML format
efenablelist : on/off
efselspeclist : Apply to models (on/off)
efspeclist : List of IDs for models

And parameters are stored here:

efpaid : parameter ID
efpaeffid : effect ID (from efidlist)
efpatype : type of parameter
efpaname : name
efpalimit : limit enabled
efpadesc : description
efpanumtype : type for numeric parameters
efpaintval : integer value
efpaintmin : integer minimum
efpaintmax : integer maximum
efpaintdef : integer default value
efpafloatval : float value
efpafloatmin : float minimum
efpafloatmax : float maximum
efpafloatdef : float default value
efpaunitval : units value
efpaunitmin : units minimum
efpaunitmax : units maximum
efpaunitdef : units default value
efpainode : object
efpaspline : spline
efpacontref : controller reference
efpacontanim : controller ID
efpacontype : controller type
efpatexmap : texture map
efpacurve : curve

As you can see, all parameters are stored together in the second list.
To identify what is the effect of each parameter, "efpaeffid" is used, which must correspont with "efidlist".

All IDs generated randomly, so they are unique.
When an effect is loaded from the .eff preset, a new ID is generated. This is done to avoid duplicates, in case you add a same effect multiple times.

On the other hand, each parameter has an unique ID as well, stored at "efpaid". But these cannot be changed, because are referenced in the XML code.
As far as i remember, the effect ID is not stored in the .eff file. I think what you see are the parameter IDs.

I hope that helps.

Title: Re: Copy effects parameters using maxscript
Post by: DrunkenMaster on March 24, 2023, 10:04:14 AM
Thank you,

Yes it helps. But I still can't create working parameters by script, and I can't understand why...

The following code generates texture parameter, but it has no functionality it jus appears in parameters rollout like placeholder with no texture slot available. And it's not visible in effects editor...

Example:
Code: [Select]
$.efpaid="{3f90ed1f-73c5-1d7b-6645-3aefad3565e9}"
$.efpaeffid="{00e2193d-7c7e-e035-4882-244a6de99648}"
$.efpatype[1]=3
$.efpaname[1] = "Texmap1"
$.efpatexmap[1]= Bitmaptexture fileName:"C:\test.jpg"

See attached image for result.

All I need now is create working parameters by script.
Title: Re: Copy effects parameters using maxscript
Post by: DrunkenMaster on March 24, 2023, 11:40:42 AM
It would be really nice to be able to load whole effects presets from file, with parameters and everything, like this:
Code: [Select]
file = "C:/test.eff"

FXString = ""

fs = openFile file
while not eof fs do(
   l = readline fs
   FXString = FXString + l
)
close fs

$.efxmllist[1] = FXString
Title: Re: Copy effects parameters using maxscript
Post by: DrunkenMaster on March 24, 2023, 06:26:09 PM
Ok I got it

Here is an example for creating parameter, in case someone else is interested:

Code: [Select]

FXid = $.efidlist[1]
$.efpaeffid[1] = FXid
$.efpaid[1] = "{28f4162f-cd3e-0c0a-bab2-5594d26d023j}"-- Random ID
$.efpatype[1]=3
$.efpaname[1] = "Texmap1"


file = "C:/FP_TEST.eff" -- Loading expressions from file
/*
-------CODE INSIDE TEST.eff -------
"<?xml version="1.0"?>
<effect version="500" title="" description="" thumbnail="" url="">
    <expression></expression>
    <parameter id="{28f4162f-cd3e-0c0a-bab2-5594d26d023j} name="Texmap1" description="" type="texmap"/>
</effect>
"
*/

FXString = ""

fs = openFile file
while not eof fs do(
   l = readline fs
   FXString = FXString + l
)
close fs

$.efxmllist[1] = FXString


And here is a function for generating GUID strings:
Code: [Select]

fn ranodmUUID=
(
FXGuid = (dotnetclass "System.Guid").NewGuid()
FXGuid.ToString()
)