我有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}
组中的每个元素只应在生成的数组中出现一次。 我该如何处理这个问题?
答案 0 :(得分:0)
您应该考虑做这样的事情(请记住这是伪代码):
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
答案 1 :(得分:0)
这就是我这样做的,它的maxscript代码分析了可以拥有其他多种材料的多种材料,并从每个ID创建新材料。也许我对第一次行动有点不清楚。
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
)