Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

81
Views
Threejs Raycast Intersects empty with scene.children. What am I doing wrong?

Post 1) I am trying to detect all objects viewable by the camera so I can reposition them to the starting position once they are out of view. I am aiming for an infinite waterfall effect that reuses the existing objects. I really don't why intersects is empty and it works if I raycast for individual objects while looping through scene.children but this will lead to very bad performance because it is in the animation loop.

Thanks for any help

Post 2) I have changed over to frustrum culling but frustum.containsPoint(scene.children[index]) always returns true even when objects are clearly out of camera view.

Again any help is appreciated

camera.updateMatrix();
  camera.updateMatrixWorld();

  var frustum = new THREE.Frustum();
  var projScreenMatrix = new THREE.Matrix4();
  projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);

  // frustum.setFromProjectionMatrix(camera.projectionMatrix);
  frustum.setFromProjectionMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));

  for (let index = 0; index < scene.children.length; index++) {
    scene.children[index].updateMatrix(); // make sure plane's local matrix is updated
    scene.children[index].updateMatrixWorld();

    if (frustum.containsPoint(scene.children[index])) {
      //stuff happens...
      if (scene.children[index].name === "coin") {
        scene.children[index].rotation.x += 0.01;
        scene.children[index].position.y -= 0.1;
      }
      // console.log("mesh in view Frustrum");
    } else {
      console.log("mesh not in view Frustrum");
    }
  }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I am trying to detect all objects viewable by the camera

You don't need raycasting for this. Instead, setup an instance of Frustum based on the projection and view matrix of your camera via setFromProjectionMatrix(). In the next step, use intersectsObject() to detect whether a 3D object is inside the camera's view frustum (the viewable area of the 3D scene) or not.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!