0
我使用three.js圖書館在WebGL中編碼,我想使用着色器。我的對象是三個.Mesh對象。THREE.MESH對象的一些面不顯示
要使用着色器,我創建了三個緩衝區來傳輸信息給着色器。
- VerticesArray其中包含對象的所有頂點。
- NormalsArray包含點的所有法線。
- IndicesArray其中包含verticesArray中頂點的排名。 (面是三角形,所以三個索引鏈接同一個面的三個頂點)。
要創建提綱陣列我這樣做:
this.mesh = new THREE.Mesh(
new THREE.SphereGeometry(15, 15, 15),
new THREE.MeshLambertMaterial({ color: 0xF40029 })
);
this.vertices = new Array();
for(var i = 0 ; i < this.mesh.geometry.vertices.length ; i++){
this.vertices.push(this.mesh.geometry.vertices[i].x);
this.vertices.push(this.mesh.geometry.vertices[i].y);
this.vertices.push(this.mesh.geometry.vertices[i].z);
}
this.normals = new Array();
for(var i = 0 ; i < this.mesh.geometry.faces.length ; i++){
this.normals[this.mesh.geometry.faces[i].a*3] = this.mesh.geometry.faces[i].vertexNormals[0].x;
this.normals[this.mesh.geometry.faces[i].a*3+1] = this.mesh.geometry.faces[i].vertexNormals[0].y;
this.normals[this.mesh.geometry.faces[i].a*3+2] = this.mesh.geometry.faces[i].vertexNormals[0].z;
this.normals[this.mesh.geometry.faces[i].b*3] = this.mesh.geometry.faces[i].vertexNormals[1].x;
this.normals[this.mesh.geometry.faces[i].b*3+1] = this.mesh.geometry.faces[i].vertexNormals[1].y;
this.normals[this.mesh.geometry.faces[i].b*3+2] = this.mesh.geometry.faces[i].vertexNormals[1].z;
this.normals[this.mesh.geometry.faces[i].c*3] = this.mesh.geometry.faces[i].vertexNormals[2].x;
this.normals[this.mesh.geometry.faces[i].c*3+1] = this.mesh.geometry.faces[i].vertexNormals[2].y;
this.normals[this.mesh.geometry.faces[i].c*3+2] = this.mesh.geometry.faces[i].vertexNormals[2].z;
}
this.indices = new Array();
for(var i = 0 ; i < this.mesh.geometry.faces.length ; i++){
this.indices.push(this.mesh.geometry.faces[i].a);
this.indices.push(this.mesh.geometry.faces[i].b);
this.indices.push(this.mesh.geometry.faces[i].c);
}
this.vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.vertices), gl.STATIC_DRAW);
this.normalBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.normalBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.normals), gl.STATIC_DRAW);
this.indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), gl.STREAM_DRAW);
this.indexCount = this.indices.length;
在這一步,我有一個奇怪的問題,在顯示器上,我可以看到我的兩個科目,但不顯示一些面孔。
你有解決我的問題的想法嗎?
我們可以在下面的圖片上看到我的問題。 我顯示兩個球。 http://img341.imageshack.us/img341/1094/ballsk.jpg
感謝您的回覆。