PDA

View Full Version : Fast way to name diffuseMap for mutiple textures


erilaz
03-31-2005, 01:13 AM
Here's a quick outline of what I'm doing:

We have a cycling animation that swaps textures in game (12 textures for the same sequence of animation), and presently I manually create an editpoly grid to hold all 12 textures so they preload in game beforehand, cloning and renaming textures accordingly. (eg. Car01, car02 etc). Each texture sits on a different polygon, then the grid is deleted after load.

I've coded up a script to handle this automatically, but there doesn't seem to be a straightforward way to rename the map-level of the material. Here's how I do it presently:

$.EditablePoly.SetSelection #Face #{i}
if i<10 then newMatN = baseName + "0"+ (i as string) else newMatN = baseName + (i as string)
$.material = standard name:newMatN diffuseMap:baseMap
if i<10 then newMapN = baseMapName + "0"+ (i as string) else newMapN = baseMapName + (i as string)
$.material.diffusemap.name = newMapN

The only problem is when it cycles around, it tries to rename the overall material diffuse map, rather than the one I've just assigned to the polygon, which doesn't exist, because assigning textures in this way creates a multisub material.

Any clues? I'm sure there's an easier way to handle assigning the diffuseMap name with this method.

Bobo
03-31-2005, 02:31 AM
When you try to assign to a selection of faces, Max tries to automatically create a MultiSub material. How about changing the face material IDs via the script, then simply generating a MultiMaterial() material with 12 sub-materials, assigning a texture to each sub-material diffuse slot, then assigning the MultiMaterial to the plane?

In that case, the object must not even be selected in the Modify panel to do the job!

Of course, in your case, you could rename the maps and materials BEFORE assigning them.
Also, is baseMap an INSTANCE of the same bitmap? I would expect that you would assign a unique one to each material...

Bobo
03-31-2005, 02:43 AM
When you try to assign to a selection of faces, Max tries to automatically create a MultiSub material. How about changing the face material IDs via the script, then simply generating a MultiMaterial() material with 12 sub-materials, assigning a texture to each sub-material diffuse slot, then assigning the MultiMaterial to the plane?


Here is an example:


theBitmapFiles = #("","","","","","","","","","","","") --enter the bitmap paths here!
p = plane lengthsegs:3 widthsegs:4 --create a plane with 12 segs
convertToPoly p --make it a polygonal mesh
for f = 1 to 12 do polyOp.setFaceMatID p f f --set each poly to different MatID
theMat = multiMaterial numsubs:12 --create a Multi/Sub material with 12 slots
for f = 1 to 12 do --go through them
(
theName = ("Car" + (if f < 10 then "0" else "") + f as string) --define the name
theSubMat = standard name:theName diffuse:(random black white) --create a standard material
theSubMat.diffusemap = bitmaptexture name:theName filename:theBitmapFiles[f] --assing a bitmap texture with same name and path from the array
theMat[f] = theSubMat --assing to the f-th slot of the Multi/Sub material
)
p.material = theMat --assing the Multi/Sub to the object
-- because the diffuse colors were randomized, you should see 12 color faces on the plane
-- add the paths to the array in the beginning and the bitmaps will be assigned...

erilaz
03-31-2005, 03:06 AM
Thanks Bobo! That's far more straightforward!:D

erilaz
03-31-2005, 03:26 AM
Still one small problem. I assign the first material in the multisub to be the original texture I want to base the names off, and there's no problem there. When I go through and do the loop to create the materials and diffuseMaps though, the original diffuseMap name of the first texture gets renamed to the last diffuseMap in the series. Am I instancing somewhere by mistake?

Bobo
03-31-2005, 04:28 PM
Still one small problem. I assign the first material in the multisub to be the original texture I want to base the names off, and there's no problem there. When I go through and do the loop to create the materials and diffuseMaps though, the original diffuseMap name of the first texture gets renamed to the last diffuseMap in the series. Am I instancing somewhere by mistake?

I am pretty sure you are instancing - I mentioned it in another post.
If you are using a base map to create all sub-maps, you would have to assign COPIES of that map, not instances. Just use the COPY function in front of the bitmap on the right hand side of the assignment. Using the original bitmap stored in the variable will ALWAYS assign as instance (this is the implicit behaviour when assinging materials, maps, modifiers etc. from a class instance stored in a variable - you always get an instance! No wonder these objects are called "class instances" ;) )

CGTalk Moderation
03-31-2005, 04:28 PM
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.