PDA

View Full Version : Instance Materials via script?


Rick Stirling
04-03-2008, 04:30 PM
I want to create instances of textures maps from one material slot to another. I'm using custom game shaders (I can query and set maps and values, no isse), and I'd like to set the diffuse/specular/normal maps of these to be instances of my standard material. Currently they are just copies - I loop through all my standard materials and copy the filenames into the relevent slots of my custom material.

After making sure it can be done manually in the material editor, I've come undone at the script stage. When I drag and drop the textures I'm given the option of creating a copy or creating an instance.

ZeBoxx2
04-03-2008, 04:49 PM
instancing a map is easy, you just point straight to the map you want to instance. For example:


-- instance a map
standardMaterialB.diffuseMap = standardMaterialA.diffuseMap

-- copy a map
standardMaterialB.diffuseMap = copy standardMaterialA.diffuseMap


The 'difficult' part is getting the "standardMaterialX.diffuseMap" bits, but the macro recorder should have those for you

Rick Stirling
04-03-2008, 04:56 PM
Ah! It's so simple really! I've been doing it the hard way, storing filenames and paths...

Thanks so much, I'll give that a whirl, and possible update some other scripts too.

Rick Stirling
04-07-2008, 11:13 AM
That worked a treat. I'll have to write some functions, and make it work with our game shaders, but it's working:

-- Instance Textures

-- Test variables, use in loop later
matidfrom = 2
matidto = 4

subid = 2 -- upper garment


-- TO slot = FROM slot
meditMaterials[matidto].materialList[subid].diffuseMap = meditMaterials[matidfrom].materialList[subid].diffuseMap



Changing the upper garment diffuse texture in material 2 or 4 changes it in the other one too.

CGTalk Moderation
04-07-2008, 11:13 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.