我正在使用Three.js 基于用户提供的边数来程序生成常规N字符.长期目标是将其作为渲染多面体棱镜的第一步.
我正在使用此处讨论的解决方案来计算N字形的顶点.
然后我使用这里讨论的技术在N -gon 上生成面.
我第一次尝试生成必要的Geometry对象导致以下内容,在添加到Mesh后似乎没有呈现任何内容:
function createGeometry (n, circumradius) {
var geometry = new THREE.Geometry(),
vertices = [],
faces = [],
x;
// Generate the vertices of the n-gon.
for (x = 1; x <= n; x++) {
geometry.vertices.push(new THREE.Vector3(
circumradius * Math.sin((Math.PI / n) + (x * ((2 * Math.PI)/ n))),
circumradius * Math.cos((Math.PI / n) + (x * ((2 * Math.PI)/ n))),
0
));
}
// Generate …Run Code Online (Sandbox Code Playgroud)