Notifications
Clear all

[Closed] PFlow – Create and Apply Materials on the fly

Hello Maxscript guys,

I need your help to see if my script idea is feasible.

In fact, i try to make a crowd system for stadium or concert. They move on place.
I use PFlow to distribute the characters on the ground.
I want to write a script in PFlow to create and apply a material on each character.
But, i want the script to mix the texture maps to create more variations of characters.

I have two approach for it :

Approach 1 :
I have several separate maps files for Head/Skin tone, Shirt, Trousers and Shoes packed in folders and material IDs on the faces corresponding to the parts of the body.

PFlow script just create a Multi/Sub Material, choose the texture map files and apply the material to the mesh.
The script would act like this :
– On the particle Mesh
– Create a Multi/Sub Material
– Random select the maps file in the folders for each part of the character and put them in the Multi/Sub Material slots at the right Material ID.
– Apply the material to the Particle mesh.
I’m affraid of this way, because if i generate 4000 characters, i will get 4000 Multi/Sub materials. I think is a bit too much for the memory.

Approach 2 :
I have several texture maps files, each for the entire character body. One texture file can textured entirely one character. I create one unique Multi/Sub Material with all my texture maps in it. That means a MSub Material with 20 or more ID slots with a texture map in each.
All face IDs of the character are already set : 1 for the head/Hands/Skin tone, 2 for the Shirt, 3 for Trousers and 4 for Shoes.
The PFlow script just modify the material ID of the faces corresponding to the selected part faces.
The script can act like this :
- On the particle mesh.
- Select "Head/Hand/Skin Tone" faces by ID (1)
- Randomly select an ID number from 1 to Multi/Sub Material.count
- Apply the random ID to the Head/Hand/Skin Tone" faces in the particle Mesh.
- Deselect the faces.
- Select "Shirt" faces by ID (2)
- Randomly select an ID number from 1 to Multi/Sub Material.count
- Apply the random ID to the Shirt faces in the particle Mesh.
- Deselect the faces.
- Select the "Trousers" Faces by ID (3)
- Randomly select an ID number from 1 to Multi/Sub Material.count
- And So on...
After passing through all Faces IDs, Go to the following particle Mesh and do the same.
I think this way is a bit better for memory... or not. I don't know.

Do you think one of this two approaches is feasible in PFlow ?

Thanks for your help.
Cheers.
5 Replies

Fairly sure the Material Dynamic operator will cycle through random material Ids for you so no reason for a script
http://docs.autodesk.com/3DSMAX/15/ENU/3ds-Max-Help/index.html?url=files/GUID-8A5EF550-CF8A-4467-B73A-AED6414CD256.htm,topicNumber=d30e192488

Edit. Maybe this is for changing within an event but it’s possible to assign/cycle material I’d without a script.

Yep sorry use Material frequency

Thank you very much hotknife.

I fact i never use the Material Dynamic and the Material Frequency before.
This tools are very useful. I have now one character in my scene and the PFlow system duplicate him on a plane and randomly apply material on each of them. Very useful.
With this approach, i just need to have a lot of permuted maps and just 15 or 20 animated characters as references in my scene.

But do you know if there is a way to get and set faces ID in a particle mesh with maxscript ?

I think 16G or 32G memory will be feasible to two approaches,but the speed is real worry.If 4000 characters not use 4000 KIND material,use globle varible will speed up.
like:globle M_1=…your material…
globle M_2…
and use <void>setParticleMtlIndex <index>particleIndex <index>materialIndex in your Pflow script.

1 Reply
(@veenibiz)
Joined: 10 months ago

Posts: 0

I have a 16G system but my render servers are 4G. So i need to save some memory.
Thank you for your replies.

So i found a way to get my characters and change their face ID like in the approach 2.
In fact, i snapshot the mesh and i get access to the face ID of the trimesh.
It take more time to duplicate the object but i get access to the faces ID.

Here is the code :


   vMesh = snapshotasmesh $Object_A --Snapshot the object
   setFaceMatID vMesh 10 1 --Change the ID of the face 10 of the vMesh to 1
   pCont.particleShape = vMesh --Apply the mesh to the particleShape
   

The only thing is to have the “Object_A” in the center of the world to have the right pivot position. I don’t find the way to place the pivot of the trimesh. I don’t know if the trimesh have a pivot point.
A way is to move the object_A in the center of the world before snaphot it and replace it to his location but this way add additional computations for the system. I prefer look if there is an other way.