Another script...another newbie problem!
I'm trying to develop a script that let me change diffuse texture of a certain material.
I started studying Joe Gunn old script "face switcher": this script change material ID (but first we need to create a multiamterial with a lot of submaterials with different textures), while I think it's faster to have only one material and change its texture.
The script let you choose a directory to sort bitmap from, create thumbnails and...nothing.
The scope is to change material texture clicking on the corresponding thumbnail and to create a keyframe for material diffuse slot.
This is my result:
try(destroyDialog ::texchange)catch()
rollout texchange"TEXTURE CHANGE"
(
--interface
button btnSetD "Set Dir:" pos:[5,5] width:50 height:20 toolTip:"directory immagini"
edittext Fdir "" pos:[55,5] width:100 height:20
button btn01 "01" pos:[5,30] width:30 height:30
button btn02 "02" offset:[-30,-35] width:30 height:30
button btn03 "03" offset:[0,-35] width:30 height:30
button btn04 "04" offset:[30,-35] width:30 height:30
button btn05 "05" offset:[60,-35] width:30 height:30
--choose bitmap path
on btnSetD pressed do
(
local curpath = Fdir.text
local newPath = getSavePath initialDir:(curpath) caption:"Select the path where your Face Images are located"
if newPath != undefined then
--create thumbnails
(
Fdir.text = newpath
btn01.images = #(Fdir.text + "\01.png", Fdir.text + "\01.png", 1, 1, 1, 1, 1)
btn02.images = #(Fdir.text + "\02.png", Fdir.text + "\02.png", 1, 1, 1, 1, 1)
btn03.images = #(Fdir.text + "\03.png", Fdir.text + "\03.png", 1, 1, 1, 1, 1)
btn04.images = #(Fdir.text + "\04.png", Fdir.text + "\04.png", 1, 1, 1, 1, 1)
btn05.images = #(Fdir.text + "\05.png", Fdir.text + "\05.png", 1, 1, 1, 1, 1)
)
)
--actions
on btn01 pressed do
(
--and here the problem... load 1st thumbnail image to object material
)
on btn02 pressed do
(
--same, and so on...
)
)
createdialog texchange 160 200 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)
I hope to have been clear enought... any idea?
Comments (27)
Comment policy
This work fine for me!!! THANKS!!!
You are Awasome!
Great job!!!
Could you please share this script? I would be very useful.
thank you very much
Thanks!
It could be a good tool, but I really need some help to finish it because it's full of bugs!!
Here the complete and commented code (I forget something... but some time has passed, sorry).
I have attacherd a zip file containing the script, a simple scene (max 2010) and 2 textures just to speed up testing process.
Attachments
EUREKA!
It works!
...with my stupid $ and vraymaterial, but it works!!
Now I have to make it works with multimaterial and create keyframe automatically :)
Just try
with animate on (selection[1].material.texmap_diffuse.clipu = 0.4)
.
Perfect on vraymtl, but does not work on multisub material :(
I already post example how to manage nested VRayMtl inside any material (Multimaterial, Blend, VRayBlend, VRayLight etc.)
.
Yup,
and your advice have produced good results :)
Did I worked well?
:)
Yep. I will explain line by line
-- on button is pressed check first if selection exists
on btn03 pressed do if selection.count != 0 do
(
-- check if first item in selection have assigned material
if (mtl = selection[1].mat) != undefined do
(
-- collect all VRayMtl instance in targeted object material
-- this material can be multimaterial or any other that have VRayMtl nested inside
-- in this case I overide "mtl" variable
-- at first this variable is selection material and then array of VRayMtl's
mtl = getClassInstances VRayMtl target:mtl
-- check if array is not empty
if mtl.count != 0 do
-- check if first material in array have texturemap in diffuse slot
if isKindOf (map = mtl[1].texmap_diffuse) bitmaptex do with animate on (map.clipu = 0.4)
-- the rest you get it already ;)
)
)
.
Wow, something I understood, something I missed :)
Last step is to set created keyframes to step with some
but all my attempts are failed.
Try this
on btn03 pressed do if selection.count != 0 do
(
if (mtl = selection[1].mat) != undefined do
(
mtl = getClassInstances VRayMtl target:mtl
if mtl.count != 0 do if isKindOf (map = mtl[1].texmap_diffuse) bitmaptex do
(
with animate on (map.clipu = 0.4)
map.clipu.controller.keys[1].inTangentType = map.clipu.controller.keys[1].outTangentType = #step
)
)
)
.
Almost right, with your code the 1st keyframe is stepped, while the others are not.
With
works well!
Yep.
In this example I used first object in selection, first material in array and
of course first key
:)
.
One problem solved, another discovered (::disappointed::)
As a dialog works fine.
Converted into a scripted plugin works too.
But I will have more than one character in my scene and I prefer to use this tool as a modifier: if I apply it to two objects with 2 different material it works, but button thumbnails are the same even if I pick 2 different directories (with different images).
Is a local variable (path) problem?
.
Path names in EditText disappered also...
Now I fix it with:
they are also saved with scene and restored on open....
but no way to fix thumbnails problem :(
Any idea?
By using below method you can avoid any error.
I hope that you understand what i wrote.
If not then just read mxs help.
.
If I wrote:
it works, but obviously is not what I need... it should be something like this:
but my knowledge stops here...
YEP!
I find a solution... is it the right one?
Better use "selection[1]" then "$" sign ei
on btn01 pressed do if selection.count != 0 do
(
if isKindOf (mtl = selection[1].mat) VRayMtl do
mtl.texmap_diffuse.filename = (Fdir.text + "\01.png")
)
.
You rock!
Thanks, I'm learning a lot from you in these days.
It works fine with a vraymaterial, but does not work (nor mine do) if vraymtl is a submat of a multimaterial...
It's easy to implement this to works with any material that include VRayMtl but
you need to decide which VRayMtl must be changed.
Let say you have multimaterial with 10 sub-materials that is assigned to one object. Which sub-mat you want to have switch operation?
.
It's the same.. let's say submat 1
on btn01 pressed do if selection.count != 0 do
(
if (mtl = selection[1].mat) != undefined do
(
mtl = getClassInstances VRayMtl target:mtl
if mtl.count != 0 do
if isKindOf (map = mtl[1].texmap_diffuse) bitmaptex do map.filename = (Fdir.text + "\01.png")
)
)
.
Yes, You are the man!
And now the nice part, I need to keyframe my bitmap change, but I'm not sure it is possible...I just realized that, right?
It's not posible but...
You can use "Mix" procedural map. Put two maps and use mix amount to switch between these. Also this parameter can be animated for sure
.
Uff...I know!
With mix map I can only mix up two maps.. I need more, at least 10.
I have the idea, but I need help to develop it.
1. We have a folder with 2 textures, each with 5 images side by side
2. First texture is lowres, to use for buttons thumbnail (to sort with .images array, and this is done)
3. Second texture is highres: now I put this texture in diffuse slot of my material, and then with buttons from 1 to 5 I will change its cropping and placement (btn01->place 0 crop 0.2, btn02->place 0.2 crop 0.2, btn03->place 0.4 crop 0.2, btn04->place 0.6 crop 0.2, btn05->place 0.8 crop 0.2), crating keyframes.
Is it a good idea?
I think that this is not possible with mxs, but not sure.