我开始给一个基本的体素类型脚本一个镜头,它会在与一个点相邻的 6 个方向上查看 n 在任何旁边没有任何东西的边上绘制一个平面。然后我可以组合这些平面,它会制作一个对象。
当它都是一个对象时,这很好用,但是如果对象之间有空间,它仍然会将它们组合为一个对象。有了坐标列表,(x,y,z)
我将如何根据连接的内容对其进行拆分?我能想到的唯一方法是非常繁重的处理,并且会在构建对象时检查对象周围的每个可用空间,直到没有剩余空间,但我想可能应该有更好的方法。
作为记录,这实际上不会用于任何事情,只是为了好玩,看看我能不能做到
import pymel.core as py
directions = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]]
grid = {}
grid[(0,0,0)] = 1
grid[(1,0,0)] = 0
grid[(-1,0,0)] = 1
grid[(0,1,0)] = 1
for originalCoordinate in grid.keys():
adjacentCoordinates = [tuple( sum( j ) for j in zip( i, originalCoordinate ) ) for i in directions]
blockHere = grid[originalCoordinate]
if blockHere:
for newCoordinate in adjacentCoordinates:
if not grid.get( newCoordinate, 0 ):
newDirection = tuple( i[1]-i[0] for i in zip( originalCoordinate, newCoordinate ) )
newSide = py.polyPlane( width = 1, height = 1, sx = 1, sy = 1 )[0]
sideLocation = list( originalCoordinate )
sideRotation = [0, 0, 0]
if newDirection[0]:
if newDirection[0] > 0:
print originalCoordinate, "Facing X"
sideLocation[0] += 0.5
sideRotation[2] += -90
else:
print originalCoordinate, "Facing -X"
sideLocation[0] += -0.5
sideRotation[2] += 90
if newDirection[1]:
if newDirection[1] > 0:
print originalCoordinate, "Facing Y"
sideLocation[1] += 0.5
sideLocation[1] += 0
else:
print originalCoordinate, "Facing -Y"
sideLocation[1] += -0.5
sideLocation[1] += 180
if newDirection[2]:
if newDirection[2] > 0:
sideLocation[2] += 0.5
sideRotation[0] += 90
print originalCoordinate, "Facing Z"
else:
sideLocation[2] += -0.5
sideRotation[0] += -90
print originalCoordinate, "Facing -Z"
py.move( newSide, sideLocation )
py.rotate( newSide, sideRotation )