如何获得 AABB 顶点的三角形?
How to get triangles for AABB verts?
我正在尝试渲染立方体来代表 AABB。为此,我需要立方体和 'cells' 或三角形的顶点。我的 AABB 结构看起来像 [vec3Min, vec3Max]
。我能够得到
使用以下
的立方体的 8 个顶点
export function vertsFromAABB(aabb){
const min = aabb[0];
const max = aabb[1];
return [
// min Y axis verts
min,
[max[0],min[1],min[2]],
[max[0],min[1],max[2]],
[min[1],min[1],max[2]],
// max Y axis verts
max,
[min[0],max[1],max[2]],
[min[0],max[1],min[0]],
[max[0],max[1],min[0]]
];
}
我现在需要从这组顶点中获取三角形索引。单元格应该是顶点索引数组,例如 [[0,1,2],[1,2,3], ...]
编辑更新
我已经修复了评论中建议的最后 2 个版本。对于看起来像
的单元格,我有一个正在进行的功能
export function cellsFromAABBVerts(aabbVerts){
return [
// Top quad triangles
[0,1,2],
[1,2,3],
// Side?
[2,3,4],
[3,4,5],
// Bottom quad triangles
[4,5,6],
[5,6,7],
];
}
如果你想像你的长方体,像这样:
那么推导三角形索引就非常简单了:
[
[ 0, 1, 2 ],
[ 0, 2, 3 ],
[ 6, 5, 4 ],
[ 6, 4, 7 ],
[ 1, 7, 4 ],
[ 1, 4, 2 ],
[ 0, 3, 5 ],
[ 0, 5, 6 ],
[ 0, 6, 7 ],
[ 0, 7, 1 ],
[ 2, 4, 5 ],
[ 2, 5, 3 ]
]
我正在尝试渲染立方体来代表 AABB。为此,我需要立方体和 'cells' 或三角形的顶点。我的 AABB 结构看起来像 [vec3Min, vec3Max]
。我能够得到
使用以下
export function vertsFromAABB(aabb){
const min = aabb[0];
const max = aabb[1];
return [
// min Y axis verts
min,
[max[0],min[1],min[2]],
[max[0],min[1],max[2]],
[min[1],min[1],max[2]],
// max Y axis verts
max,
[min[0],max[1],max[2]],
[min[0],max[1],min[0]],
[max[0],max[1],min[0]]
];
}
我现在需要从这组顶点中获取三角形索引。单元格应该是顶点索引数组,例如 [[0,1,2],[1,2,3], ...]
编辑更新
我已经修复了评论中建议的最后 2 个版本。对于看起来像
的单元格,我有一个正在进行的功能export function cellsFromAABBVerts(aabbVerts){
return [
// Top quad triangles
[0,1,2],
[1,2,3],
// Side?
[2,3,4],
[3,4,5],
// Bottom quad triangles
[4,5,6],
[5,6,7],
];
}
如果你想像你的长方体,像这样:
那么推导三角形索引就非常简单了:
[
[ 0, 1, 2 ],
[ 0, 2, 3 ],
[ 6, 5, 4 ],
[ 6, 4, 7 ],
[ 1, 7, 4 ],
[ 1, 4, 2 ],
[ 0, 3, 5 ],
[ 0, 5, 6 ],
[ 0, 6, 7 ],
[ 0, 7, 1 ],
[ 2, 4, 5 ],
[ 2, 5, 3 ]
]