2

你好 Python 和 Stack 社区。

首先,让我说我是一个 3d 人,而不是一个代码人。所以谢谢理解...

确切的问题:我必须根据点到多个对象的距离生成渐变图

这是我的问题的简单预览 Preview_C4D

我的基本代码如下:

import c4d
#Welcome to the world of Python
warray = [0.0]
def main():
    global warray
    wtag = op[c4d.ID_USERDATA,1]  #drag vertex map from user data panel
    obj = wtag.GetObject()    #the object of the vertex map
    pts = obj.GetAllPoints()
    cnt = len(pts)
    null = op.GetObject()
    nullpos =  null.GetMg().off  #vector magnitude from matrix
    minDistance = op[c4d.ID_USERDATA,4]  #drag slider map from user data panel
    maxDistance = op[c4d.ID_USERDATA,5]  #drag slider map from user data panel
   
    
    if len(warray) != cnt:
        diff = cnt - len(warray)
        warray.extend([0.0]*diff)
    
    for  x in xrange(cnt): #remapping in the range 0-1
        point = pts[x]
        distance = (nullpos - point).GetLength()
        warray[x] = c4d.utils.RangeMap(distance,minDistance,maxDistance,1,0,False)
        if warray[x] > 1:
            warray[x] = 1.0
        elif warray[x] < 0:
            warray[x] = 0.0
    wtag.SetAllHighlevelData(warray)  #bake the new vertex map

现在假设我有一个包含多个对象的列表:

parent = doc.SearchObject('parent')
    
    
    list1 = parent.GetChildren() # list of cubes under parent
    count = len(list1)
    for a in range(list):
      obj = list1[a]
      distance = ?

所以我被困在这里,因为我无法弄清楚如何将新值与旧值合并。简而言之,我需要一个循环来评估列表中每个对象的点值,然后将它们加在一起。我就是无法正确拨号。

因此,如果有人可以提供帮助,我将不胜感激。

问候

4

0 回答 0