简体   繁体   English

使用THREE.js创建自定义网格

[英]Creating a custom mesh with THREE.js

I have attempted to create a custom mesh with Three.js using the following code: 我尝试使用以下代码使用Three.js创建自定义网格:

var geom = new THREE.Geometry();

//geom verts

geom.vertices.push(new THREE.Vector3(-1,-1,-1));
geom.vertices.push(new THREE.Vector3(0,-1,-1));
geom.vertices.push(new THREE.Vector3(-1,0,-1));
geom.vertices.push(new THREE.Vector3(0,0,-1));

//faces
geom.faces.push(new THREE.Face3(0,1,2));
geom.faces.push(new THREE.Face3(1,2,3));

When I render the object, only one of the triangles renders (the first one). 渲染对象时,只有一个三角形(第一个)渲染。 If someone could tell me what is wrong (or a guide to creating custom meshes without blender), that would be awesome. 如果有人可以告诉我哪里出了问题(或没有搅拌器的自定义网格创建指南),那就太好了。

Try calling geom.computeFaceNormals(); 尝试调用geom.computeFaceNormals(); after adding the vertices and faces. 在添加顶点和面之后。

The face winding is different, for the first triangle its anti-clockwise and for the second triangle it is clock-wise. 面绕组不同,第一个三角形为逆时针方向,第二个三角形为顺时针方向。 You can solve the problem in two different ways - 您可以通过两种不同的方式解决问题-

1) Provide the vertices in right order - 1)按正确的顺序提供顶点-

geom.faces.push(new THREE.Face3(0,1,2));
geom.faces.push(new THREE.Face3(1,3,2));

2) Render both side of the triangle. 2)渲染三角形的两边。

var material = new MeshBasicMaterial({side: THREE.DoubleSide});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM