Changing textureunit bitmap extension from script.

ahmadi

24-08-2010 20:48:26

Hi
I want access to filename of all of my scene material textureunits and change extension of filenames.
Because i want rename all of my .png textures to .dds and its hard that i do it manually in 120 materials!
my code to now is:

fn fixDDSFn mtl =
(
if (mtl!=undefined) then
(
--messagebox mtl.alpha
--s=mtl.bitmap
--messagebox s
)
)



macroScript removeMaterialsSpaces
category:"Lioric Ogre Tools"
tooltip:"fixDDSFn"
buttontext:"fixDDSFn"
(
on execute do (
try (
for i in selection do (
mtl = i.material
if mtl != undefined do
if classOf mtl ==oFusion_Material do
(
if (mtl.mtl_mat1.mtl_mat1!=undefined) then
(
fixDDSFn mtl.mtl_mat1.mtl_mat1.mtl_mat1
fixDDSFn mtl.mtl_mat1.mtl_mat1.mtl_mat2
fixDDSFn mtl.mtl_mat1.mtl_mat1.mtl_mat3
fixDDSFn mtl.mtl_mat1.mtl_mat1.mtl_mat4
)
if (mtl.mtl_mat1.mtl_mat2!=undefined) then
(
fixDDSFn mtl.mtl_mat1.mtl_mat2.mtl_mat1
fixDDSFn mtl.mtl_mat1.mtl_mat2.mtl_mat2
fixDDSFn mtl.mtl_mat1.mtl_mat2.mtl_mat3
fixDDSFn mtl.mtl_mat1.mtl_mat2.mtl_mat4
)
if (mtl.mtl_mat1.mtl_mat3!=undefined) then
(
fixDDSFn mtl.mtl_mat1.mtl_mat3.mtl_mat1
fixDDSFn mtl.mtl_mat1.mtl_mat3.mtl_mat2
fixDDSFn mtl.mtl_mat1.mtl_mat3.mtl_mat3
fixDDSFn mtl.mtl_mat1.mtl_mat3.mtl_mat4
)
if (mtl.mtl_mat1.mtl_mat4!=undefined) then
(
fixDDSFn mtl.mtl_mat1.mtl_mat4.mtl_mat1
fixDDSFn mtl.mtl_mat1.mtl_mat4.mtl_mat2
fixDDSFn mtl.mtl_mat1.mtl_mat4.mtl_mat3
fixDDSFn mtl.mtl_mat1.mtl_mat4.mtl_mat4
)
if (mtl.mtl_mat2!=undefined) then
(
fixDDSFn mtl.mtl_mat2.mtl_mat1
fixDDSFn mtl.mtl_mat2.mtl_mat2
fixDDSFn mtl.mtl_mat2.mtl_mat3
fixDDSFn mtl.mtl_mat2.mtl_mat4
)

)
)

)
catch (

)
)
)


Note : A solution in OgreMax :http://www.ogremax.com/node/205
Thank you for any help.

Lioric

26-08-2010 17:25:45

To access any of the 32 texture units you can use the "textureUnits" member array of the oFusion Pass
object (not using the "mtl_matN" members), as this:

"yourMaterial.mtl_mat1.mtl_mat1.textureUnits[1] = oFusion_TextureUnit()"

This will create and assign a new TextureUnit in "yourMaterial" (in the
first Technique, first Pass) at the index 1 of the texture units array
(first texture unit of that pass)

You can assign up to 32 texture units in each pass:

"yourMaterial.mtl_mat1.mtl_mat1.textureUnits[5] = anExistingTexUnitObject"

This will assign an existing Texture Units in the index 5 of the TexUnit
array (the fifth texture unit of that pass)

"texUnit = yourMaterial.mtl_mat1.mtl_mat1.textureUnits[1]"

Gets the first TextureUnit form the First Techinque and Pass from "yourMaterial" and puts its in "texUnit" variable

Note on Ce: As this feature was introduced on January 2009, I dont know if that made it into Ce version, I will have to review it

ahmadi

26-08-2010 20:01:09


"yourMaterial.mtl_mat1.mtl_mat1.textureUnits[1] = oFusion_TextureUnit()"
This will create and assign a new TextureUnit in "yourMaterial" (in the
first Technique, first Pass) at the index 1 of the texture units array
(first texture unit of that pass)

How can i set filename of this new textureunit!?
And how can i retrieve filename of an existing textureunit!?
Because i want change extension of existing texture unit to .dds.

Thank you for your attention and response

Lioric

26-08-2010 21:56:13

Just use the "textureName" member, as in:

texUnit = yourMaterial.mtl_mat1.mtl_mat1.textureUnits[1]

texUnit.textureName = "imageFile.dds"

As posted above, I dont know if this was included in Ce, if not, notify me and I will provide you with another solution