Commit 4b0e8a80 authored by amandaghassaei's avatar amandaghassaei
Browse files

buffergeo

parent 3538b51e
...@@ -97,12 +97,10 @@ function init() { ...@@ -97,12 +97,10 @@ function init() {
threeView = initThreeView(); threeView = initThreeView();
var geo = new THREE.Geometry(); var geo = new THREE.BufferGeometry();
geo.dynamic = true; geo.dynamic = true;
particlesVertices = geo.vertices; particlesVertices = new Float32Array(numParticles*3);
for (var i=0;i<numParticles;i++){ geo.addAttribute('position', new THREE.BufferAttribute(particlesVertices, 3));
geo.vertices.push(new THREE.Vector3());
}
particles = new THREE.Points(geo, new THREE.PointsMaterial({size:0.04, opacity: 0.5, transparent: false, depthTest : false, color:0x000033})); particles = new THREE.Points(geo, new THREE.PointsMaterial({size:0.04, opacity: 0.5, transparent: false, depthTest : false, color:0x000033}));
threeView.scene.add(particles); threeView.scene.add(particles);
...@@ -119,7 +117,8 @@ function setThree(){ ...@@ -119,7 +117,8 @@ function setThree(){
var vertex = new THREE.Vector3(Math.random()*actualWidth, Math.random()*actualHeight, 0); var vertex = new THREE.Vector3(Math.random()*actualWidth, Math.random()*actualHeight, 0);
particleData[i*4] = vertex.x; particleData[i*4] = vertex.x;
particleData[i*4+1] = vertex.y; particleData[i*4+1] = vertex.y;
particles.geometry.vertices[i].set(vertex.x, vertex.y, 0); particlesVertices[3*i] = vertex.x;
particlesVertices[3*i+1] = vertex.y;
} }
particles.position.set(-actualWidth/2, -actualHeight/2, 0); particles.position.set(-actualWidth/2, -actualHeight/2, 0);
threeView.render(); threeView.render();
...@@ -231,10 +230,10 @@ function render(){ ...@@ -231,10 +230,10 @@ function render(){
GPU.readPixels(0, 0, particlesTextureDim * vectorLength, particlesTextureDim, pixels); GPU.readPixels(0, 0, particlesTextureDim * vectorLength, particlesTextureDim, pixels);
var parsedPixels = new Float32Array(pixels.buffer); var parsedPixels = new Float32Array(pixels.buffer);
for (var i=0;i<numParticles;i++){ for (var i=0;i<numParticles;i++){
particlesVertices[i].x = parsedPixels[vectorLength*i]; particlesVertices[3*i] = parsedPixels[vectorLength*i];
particlesVertices[i].y = parsedPixels[vectorLength*i+1]; particlesVertices[3*i+1] = parsedPixels[vectorLength*i+1];
} }
particles.geometry.verticesNeedUpdate = true; particles.geometry.attributes.position.needsUpdate = true;
threeView.render(); threeView.render();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment