Reputation: 25
I want to create a TetrahedronGeometry
by using polyedronGeometry()
, but it failed to work there is nothing in the scene.
var vertices = [
[1, 0, 1],
[1, 0, -1],
[-1, 0, -1],
[-1, 0, 1],
[0, 1, 0]
];
var faces = [
[0, 1, 2, 3],
[0, 1, 4],
[1, 2, 4],
[2, 3, 4],
[3, 0, 4]
];
var geometry = new THREE.PolyhedronGeometry(vertices, faces);
var material = new THREE.MeshBasicMaterial({color: 0x00ff00});
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
Upvotes: 0
Views: 172
Reputation: 803
First Look at the documentation for PolyhedronGeometry. You are not following spec in sending it faces/vertices.
Vertices
as an argument is supposed to be an array of floats, not an array of arrays. so [[#.#,#.#,#.#],[....]]
is incorrect because each entry of Vertices
is an array, not a float. but [#,#,#,#,#,#,#, .....]
will work. same is true with faces
it reads [0,1,2,1,2,3,2,3,4]
as 3 separate faces. you don't need to break them up into their own arrays.
Second, you try to slip a quad into the faces
which expects triangles. So you need to break [0, 1, 2, 3]
into 0,1,2,1,2,3
.
Third, you don't define the size in PolyhedronGeometry
, I think it defaults to 1 which should be fine, but in case you're making a scene of massive/tiny scale you might need to set this yourself to make sure that it's visible and that the camera is not inside it. I can't see your camera definition, so that could be a factor.
Last, for debugging, I would change
new THREE.MeshBasicMaterial({color: 0x00ff00});
for:
new THREE.MeshBasicMaterial({color: 0x00ff00,side:THREE.DoubleSide});
so that just in case your winding order is incorrect, you can at least see whether you're creating the correct geometry and faces. Once you have something on screen, then you can turn off doubleside and debug the winding.
Upvotes: 1