jscastro76 / threebox

A Three.js plugin for Mapbox GL JS, with support for animations and advanced 3D rendering.
Other
562 stars 148 forks source link

Collision detection is not working for custom model loaded using `tb.loadObj` #338

Closed jianbocui closed 2 years ago

jianbocui commented 2 years ago

Threebox version: Version 2.2.6

Question

Hi There,

In the game example, I want to detect if the car intercepts with a loaded model either in the same layer as the truck or on a different layer using truck.addEventListener('ObjectChanged', onObjectChanged, false);, here is my example code , but the onObjectChanged doesn't detect anything when it intercept with the object

Screen Shot 2022-03-18 at 5 14 06 pm Screen Shot 2022-03-18 at 5 13 40 pm

jscastro76 commented 2 years ago

You're mixing concepts, first, the object is not changing when it moves neither if it intercepts any other object models. So the event handler you're adding is not being fired. Second, the fill-extrusions created by Mapbox are not "visible" for Three.js raycaster, so you won't be able to detect that collisions because both objects are different 3D elements created by 2 different 3D frameworks. If what you want is to detect collisions between different objects, I recommend you to first check how detect collisions should be done in three.js without mapbox and threebox, and then implement it in your scenario.