我正试图用Python为Blender编写一个自定义出口商。但是,我在弄清楚如何使用Python的原生排序实现按照我需要的方式排序我的顶点时遇到了一些困难。
基本上,我需要导出顶点,这样它们就可以形成这样的网格,假设V是双倍的。
V V V V V
V V V V V
V V V V V
V V V V V我正在编写的"engine“根据上面显示的顶点映射中的位置自动检索坐标的X和Z值。V表示Y坐标。因此,这5乘5的顶点地图将创建一个4×4面网格。
然而,在混合器中,顶点似乎是针对网格的每个面单独排序的,而不是像我这样的格式。因此,为了导出它,我需要顺序的坐标首先是深度(Y坐标在搅拌器),然后是宽度(X坐标在搅拌器)。它必须像SQL查询一样运行,其中给定的第一个参数相对于第二个参数优先。
下面是我当前代码的样子
#!BPY
"""
Name: 'VaV Export'
Blender: 269
Group: 'Export'
Tooltip: 'Export to VaV file format'
"""
import Blender
import bpy
class Coordinate:
def __init__(self, posX, posY):
self.posX = posX
self.posY = posY
def sortX(self, other):
if posX < other.posX:
return 1
def sortY(self, other):
if posY < other.posY:
return 1
def write(filename):
out = open(filename, "w")
terraindata = bpy.data.meshes["Terrain"]
vertices = terraindata.vertices
vertices = sorted(vertices, key = lambda x: x.co.y, reverse = True)
vertices = sorted(vertices, key = lambda x: x.co.x, reverse = False)
print(vertices)
Blender.Window.FileSelector(write, "Export")对sorted()的第一个调用成功地根据深度(Y)对其进行了排序。但是,第二个对排序的调用会扰乱订单(正如预期的那样)。我怎样才能修改这两种情况,而不让第二种情况发生呢?
谢谢你提前给我时间!
发布于 2014-02-26 21:59:40
变化
vertices = sorted(vertices, key = lambda x: x.co.y, reverse = True)至
vertices = sorted(vertices, key = lambda x: (x.co.y, x.co.x), reverse = True)应该这么做的...and。
https://stackoverflow.com/questions/22053746
复制相似问题