1

Are there any errors is this code? I am using a new version of Chrome to test on. I've written a similar program that displays a wireframe cube, with no issues. It ran well. I'm thinking I may have written or structured my code incorrectly.

var scene = new THREE.Scene(); 
var camera = new THREE.PerspectiveCamera(50,window.innerWidth/window.innerHeight, 1, 10000); 
var renderer = new THREE.WebGLRenderer(); 
  renderer.setSize(window.innerWidth, window.innerHeight); 
  document.body.appendChild(renderer.domElement); 

// create the particle variables
var particleCount = 1000;
var particles = new THREE.Geometry();
var pMaterial = new THREE.ParticleBasicMaterial({
  color: 'red',
  size: 20
});

// create the individual particles
for (var p = 0; p < particleCount; p++) {
  var pX = Math.random()*500 - 250;
  var pY = Math.random()*500 - 250;
  var pZ = Math.random()*500 - 250;
  var particle = new THREE.Vertex(
    new THREE.Vector3(pX, pY, pZ)
  );
  particles.vertices.push(particle);
}

// create the particle system
var particleSystem = new THREE.ParticleSystem(
  particles,
  pMaterial);

// add the particle system to the scene
scene.add(particleSystem);

function render() {
  particleSystem.rotation.y += 0.01;
  renderer.render(scene, camera);
  requestAnimationFrame(render);
}
render();

I'm not seeing any results, so to speak - just a black canvas element on the page.

2
  • It would help if you would say what results you see and how that differs from what you expect. To know if there are any (syntax) erors in your code check the browser console. Commented Dec 14, 2014 at 8:51
  • I'm not seeing any results, so to speak - just a black canvas element on the page. Commented Dec 14, 2014 at 8:52

1 Answer 1

3

Your code looks outdated -- as if you copied something from the net, or from an outdated book.

Update to the current version of three.js, and learn from the current three.js examples.

Create your particles like so:

var particle = new THREE.Vector3( pX, pY, pZ );

Also, ParticleSystem is now PointCloud, and ParticleBasicMaterial is now PointCloudMaterial.

three.js r.69

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.