给场景中的每个对象一个独特的wirecolor?

时间:2012-01-18 13:25:20

标签: max 3ds maxscript

知道要执行此操作的任何脚本或代码吗?

我见过几个随机颜色,但我需要确保没有两个对象具有相同的线色..

谢谢! =)

1 个答案:

答案 0 :(得分:1)

我不知道,但写一个并不难。

在这里,希望它会按照您的预期行事:

fn shuffle &arr =
(
    local temp, swapIndex, counter = arr.count + 1
    while counter > 1 do
    (
        swapIndex = random 1 (counter -= 1)
        temp = arr[counter]
        arr[counter] = arr[swapIndex]
        arr[swapIndex] = temp
    )
    OK
)

fn incrementCounters &r &g &b step =
(
    if (b += step) > 256 do
    (
        b = 1
        if (g += step) > 256 do
        (
            g = 1
            if (r += step) > 256 do r = 1
        )
    )
)

fn assignRandomWirecolor objs simple:true =
(
    local stepCount = objs.count^(double 1/3) + 1
    local step = 255./stepCount
    local redArr = #(0) + #{1..255}
    local greenArr = copy redArr #noMap
    local blueArr = copy redArr #noMap
    local r = local g = local b = 1

    if simple then
    (
        shuffle &redArr
        shuffle &greenArr
        shuffle &blueArr
    )
    else shuffle &sel -- slower with many objects

    for obj in objs do
    (
        obj.wirecolor = [redArr[int(r)], greenArr[int(g)], blueArr[int(b)]]
        incrementCounters &r &g &b step
    )
)


sel = selection as array
clearSelection()
assignRandomWirecolor sel --simple:false --> if simple is not so cool, try the other option
select sel

当然这一切都取决于你想要用它的目的,这只是一种通用的方法,因此它可能不适合那个确切的任务。如果是这种情况,您可以提供更多详细信息,我会进行一些调整。