组项组合,不重复
Combinations of group items, no repeating
我有 3 组项目,我想生成如下例所示的数组:
Group 1 = {m1, m2, m3}
Group 2 = {m4, m5}
Group 3 = {m6, m7, m8, m9}
{m1, m4, m6}
{m2, m5, m7}
{m3, null, m8}
{null, null, m9}
组中的每个元素在生成的数组中只应出现一次。
我该如何解决这个问题?
你应该考虑做这样的事情(记住这是伪代码):
group1 = {m1, m2, m3}
group2 = {m4, m5}
group3 = {m6, m7, m8, m9}
len1 = group1.size
len2 = group2.size
len3 = group3.size
max = max(len1, len2, len3)
combination = {}
for i from 0 to max:
combination = {}
if(group1(i) exists)
combination.add(group1(i))
else combination.add("null")
if(group2(i) exists)
combination.add(group2(i))
else combination.add("null")
if(group3(i) exists)
combination.add(group3(i))
else combination.add("null")
print combination
我就是这样做的,它的 maxscript 代码分析了 multi-material 可以有其他 multi-materials,并从每个 ID 创建新的 materials。也许我在第一个问题中有点不清楚对此感到抱歉。
local maxSubID = amax arrayNumSubs --it is the count of the array with highest number of items.
for maxSubCounter = 1 to maxSubID do
(
tmpMat = multimaterial numsubs:mainMatIDs
for subCounter = 1 to mainMatIDs do
(
if (rootMat[subCounter] != undefined) then
(
tmpMat[subCounter] = rootMat[subCounter][maxSubCounter]
)else
(
tmpMat[subCounter] = undefined
)
)
append materialsToApply tmpMat
)
我有 3 组项目,我想生成如下例所示的数组:
Group 1 = {m1, m2, m3}
Group 2 = {m4, m5}
Group 3 = {m6, m7, m8, m9}
{m1, m4, m6}
{m2, m5, m7}
{m3, null, m8}
{null, null, m9}
组中的每个元素在生成的数组中只应出现一次。 我该如何解决这个问题?
你应该考虑做这样的事情(记住这是伪代码):
group1 = {m1, m2, m3}
group2 = {m4, m5}
group3 = {m6, m7, m8, m9}
len1 = group1.size
len2 = group2.size
len3 = group3.size
max = max(len1, len2, len3)
combination = {}
for i from 0 to max:
combination = {}
if(group1(i) exists)
combination.add(group1(i))
else combination.add("null")
if(group2(i) exists)
combination.add(group2(i))
else combination.add("null")
if(group3(i) exists)
combination.add(group3(i))
else combination.add("null")
print combination
我就是这样做的,它的 maxscript 代码分析了 multi-material 可以有其他 multi-materials,并从每个 ID 创建新的 materials。也许我在第一个问题中有点不清楚对此感到抱歉。
local maxSubID = amax arrayNumSubs --it is the count of the array with highest number of items.
for maxSubCounter = 1 to maxSubID do
(
tmpMat = multimaterial numsubs:mainMatIDs
for subCounter = 1 to mainMatIDs do
(
if (rootMat[subCounter] != undefined) then
(
tmpMat[subCounter] = rootMat[subCounter][maxSubCounter]
)else
(
tmpMat[subCounter] = undefined
)
)
append materialsToApply tmpMat
)