[Closed] Block colours
Has anyone ever seen a script or plugin that can turn bitmap textures into diffuse colours by averaging the texture?
My specific need is that I have a lego character built using the really great Legolizer plugin, but I’m looking for a quick way to colour the seperate blocks other than doing it one-by-one!
I haven’t turned up anything in the search or on Google, so I’m hoping someone here might be able to help me out. I’m using Max 2010 x64
Thanks
could you please explain the situation a little better? do you have a lot of block objects that you want a material created for each one with its own color? or one object with a lot of elements, that you want a big multi/subobject material created for?
fn getAVGColor map = (
--INToolsFN.getAVGColor meditmaterials[1].diffusemap
local result = blue as color
if map != undefined do (
bmp=rendermap map size:[1,1] filter:true
pixel= ((getpixels bmp [0,0] 1)[1])
result=(color pixel.r pixel.g pixel.b pixel.a)
)
result
)
do you need a code or an algorithm?
the algorithm is not very complicated:
1. For every node render self-diffuse to texture with flatten UVW mapping.
(for speckled textures use biggest texture filter)
2. Using the rendered texture get the color in the center of every MAP face of every GEO element.
3. Using collected MAP face colors and area of corresponded GEO faces as weight calculate the average color of the element.
That's it.
To get more accurate result it’s better to tessellate the mesh before calculation.
there is an another idea:
- Using Vertex Paint modifier bake Diffuse per face.
- Using face colors and face area as weight calculate the average color of the element.
yes… I like it better. It’s less accurate but simpler.
Thanks for helping.
The specific situation is this:
This is made from individual blocks, but a single bitmap texture. I am hoping to get the average colour of each block & generate a solid diffuse colour.
So far, my efforts have resulted in the entire bitmap being averaged – giving me a single colour for everything.
Dude it worked!
It’s probably going to take a day to do the whole thing, but the vertex paint solution worked a treat.
Thanks
try(destroydialog solidCols)catch()
fn getAvgColor o chan =
(
local cols=#()
local theBMP=o.material.diffuseMap.bitmap
for i = 1 to (meshop.getnummapverts o.mesh chan) do
(
local UVvert=meshop.getMapVert o.mesh chan i
local thecoords=[(mod UVvert[1] 1)*(theBMP.width-1),(1-(mod UVvert[2] 1))*(theBMP.height-1)]
local thePix=getPixels theBMP thecoords 1
append cols thePix[1]
)
local sum=black
for c = 1 to cols.count do sum+=cols[c]
sum=sum/cols.count
)
rollout solidCols "Block colors"
(
spinner mapChan "Map Channel" type:#integer range:[1,100,1]
button convertIt "Convert selected to solid"
on convertIt pressed do if selection.count>0 do
(
for o in selection where (classof o.material==standardmaterial) and (classof o.material.diffusemap==bitmaptex) do
(
print o.name
o.material= standardmaterial diffuse:(getAvgColor o mapChan.value)
)
)
)
createDialog solidCols
another method I tried, just for the learning experience. requires that the materials have a standard material with a diffuse bitmap texture. That texture must also be on default coordinates. It samples the color at each vertex of each selected object and averages that, creating a new material with that color and assigns it to that object.
A smarter way would be to rebake that color into the vertex colors of each object and use just one material with a vertex color map, but I don’t have time right now to do it.
the color of diffuse texture might not be the same as the color of the material diffuse.