Hello Guys, I’m new here and just start to learn threejs
I create a react map component that can create a buffergeometry based on array of 3D point (new THREE.PointsMaterial) inputted.
this function create buffer geometry, but when I see from top, some faces, some left and right faces and especially top face doesnt show. If it looked from bottom, all faces showed Anyone can help me?
Blockquote
var newHeight = 1;
var newVertices = ;
var twoDPositions = ;
var normalnya = ‘’;
for(let v = 0; v<titikObjek.length; v++){
var g
if(v+1 == titikObjek.length){
g=0
} else {
g= v+1
}
var verticeGeometrynya = titikObjek[v].geometry._bufferGeometry.attributes.position.array;
var verticeGeometrynyaPlusSatu = titikObjek[g].geometry._bufferGeometry.attributes.position.array;
//calculate normal IF DOT POINTS SAME IN X AXIS THEN
if(verticeGeometrynyaPlusSatu[0]===verticeGeometrynya[0]){
normalnya = [ -1, 0, 0] // IT WOULD BE LEFT OR RIGHT, I PUT IT ON RIGHT
} else {
normalnya = [ 0, 0, -1]// THE DOT POINTS CROSSING IN Z SO IT WILL BE EITHER //FRONT OR BACK I PUT IT FRONT
}
newVertices.push({pos: [verticeGeometrynya[0], verticeGeometrynya[1], verticeGeometrynya[2]], norm: normalnya})
newVertices.push({pos: [verticeGeometrynyaPlusSatu[0], verticeGeometrynyaPlusSatu[1], verticeGeometrynyaPlusSatu[2]], norm: normalnya})
newVertices.push({pos: [verticeGeometrynya[0], newHeight, verticeGeometrynya[2]], norm: normalnya})
newVertices.push({pos: [verticeGeometrynya[0], newHeight, verticeGeometrynya[2]], norm: normalnya})
newVertices.push({pos: [verticeGeometrynyaPlusSatu[0], verticeGeometrynyaPlusSatu[1], verticeGeometrynyaPlusSatu[2]], norm: normalnya})
newVertices.push({pos: [verticeGeometrynyaPlusSatu[0], newHeight, verticeGeometrynyaPlusSatu[2]], norm: normalnya})
//for TWO D
twoDPositions.push(new THREE.Vector2(verticeGeometrynya[0], verticeGeometrynya[2]))
}
var holes = [];
var angles = THREE.ShapeUtils.triangulateShape( twoDPositions, holes );
//make a top face
for(let r = 0; r < angles.length; r++) {
newVertices.push({pos: [twoDPositions[angles[r][0]].x, newHeight, twoDPositions[angles[r][0]].y], norm: [ 0, 1, 0]})
newVertices.push({pos: [twoDPositions[angles[r][1]].x, newHeight, twoDPositions[angles[r][1]].y], norm: [ 0, 1, 0]})
newVertices.push({pos: [twoDPositions[angles[r][2]].x, newHeight, twoDPositions[angles[r][2]].y], norm: [ 0, 1, 0]})
}
//make a bottom face
for(let p = 0; p < angles.length; p++) {
newVertices.push({pos: [twoDPositions[angles[p][0]].x, 0, twoDPositions[angles[p][0]].y], norm: [ 0, -1, 0]})
newVertices.push({pos: [twoDPositions[angles[p][1]].x, 0, twoDPositions[angles[p][1]].y], norm: [ 0, -1, 0]})
newVertices.push({pos: [twoDPositions[angles[p][2]].x, 0, twoDPositions[angles[p][2]].y], norm: [ 0, -1, 0]})
}
const newPositions = [];
const newNormals = [];
for (const newVertex of newVertices) {
newPositions.push(...newVertex.pos);
newNormals.push(...newVertex.norm)
}
var newGeometry = new THREE.BufferGeometry();
newGeometry.addAttribute(
'position',
new THREE.BufferAttribute(new Float32Array(newPositions), 3));
newGeometry.addAttribute(
'normal',
new THREE.BufferAttribute(new Float32Array(newNormals), 3));
// newGeometry.computeVertexNormals()
// newGeometry.normalizeNormals()
// newGeometry.computeBoundingBox()
var newMaterial = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
var newMesh = new THREE.Mesh( newGeometry, newMaterial );
this.scene.add(newMesh)