I found that using Octree would penetrate inside TubeGeometry

for example file games_fps.html.
I created a TubeGeometry. and set worldOctree.fromGraphNode()

This is the code I added

// other code
container.appendChild( stats.domElement );

// line 87
let points = [new THREE.Vector3(0, 0, 0 ), new THREE.Vector3(10, 0, 0), new THREE.Vector3(30, 0, 2)]
let curvePoints = new THREE.CatmullRomCurve3(points)

const tubeGeometry = new THREE.TubeGeometry(curvePoints, 64, 2, 8, false)
const tubeMaterial = new THREE.MeshBasicMaterial({
    color: 0xffffff,
    side: THREE.DoubleSide 

const tubeMesh = new THREE.Mesh(tubeGeometry, tubeMaterial)

const GRAVITY = 30;
// other code

// other code
loader.load('collision-world.glb', (gltf) => {
   scene.add( gltf.scene );
   worldOctree.fromGraphNode( gltf.scene );

Actually, when I am inside the tube, it can pass through the tube and when I press A or D.

May I ask if this is the correct expectation。

I have no idea what is your expectation. Octrees do not represent a shape precisely, they are generally used to split the space into smaller fragments, so that searching/raycasting/processing becomes much faster.

My suggestion is to visualize the octree and see whether it matches your expectation.

import { OctreeHelper } from "three/addons/helpers/OctreeHelper.js";

// other code

loader.load('collision-world.glb', (gltf) => {
   // other code
   scene.add( new OctreeHelper( worldOctree, 'crimson' ) ); // octree visualization

In the video I uploaded, you can see that you can pass through it while moving.

If I want to stay inside the tubegeometry without passing through, how do I achieve it.

I have tried using canon.js, but it cannot fully handle my geometry.

One way to do this is with raytracing. You have an invisible short ray, and you move in the direction of the ray only when there is no obstacle. I tried with a tube geometry and this approach works fine from both outside and inside the tube. Most likely there is some bug in your implementation. WIth proper debugging and tracing you may find it.

Also, I believe octree can speed up raycast intersection. I have never used it, so the video above is with raycasting without octrees.

1 Like

I have written three implementation methods (Octree, Raycaster, CANNON), among which Raycaster is also implemented because I need to set the movement speed. When I use Raycaster, if the speed is too fast, it will also pass through。

I will share the editable code later