最近完成了法线传递转顶点色工具,其中需要将顶点色转回法线做验证,涉及将GeoVertID转为MapVertID(同一个几何顶点id对应不同的断开的面有不同的映射id,用于记录自己在该断开面的uv位置和法线方向),转换流程如下:
-
找到该几何点所有几何面
-
获取该几何点在几何面中的索引
-
获取该几何面所有的映射点ID
-
通过2的索引获取几何点对应的映射点ID
代码如下:
TargetGeoVertTexVerts= #()
TargetFacesTexVertColors = #()
VertIndicies = #()
TexVertColors = #()
--获得顶点的法线列表
local baVertNormals = #{}
theEditNorm.convertVertexSelection #{iVert} baVertNormals node:theNode
TargetFaces = polyop.getFacesUsingVert theNode #{iVert} as array --找到该几何点所有面
-- 通过面查找几何点的所有映射点的index
for f in TargetFaces do
(
FaceVerts = polyop.getFaceVerts theNode f -- 获取面的所有几何点
GeoVertIndex = (finditem FaceVerts iVert) -- 获取查找几何点的索引
FaceTexVerts = polyOp.getMapface theNode 0 f -- 获取面的所有映射点
append TargetGeoVertTexVerts FaceTexVerts[GeoVertIndex] -- 获取面对应几何点的映射点
)
format "TargetGeoVertTexVerts:%\n" TargetGeoVertTexVerts