Hi Everyone,

I am trying to implement bins filling algorithm by allowing user to create freehand polygon by drawing lines and then making shape geometry from points/vertices of lines. Then trying to add the bin meshes in scene using min and max of the drawn polygon. After that, I am trying to keep the bins meshes that have collision with drawn polygon and are not interesting with lines.

However, the shape polygon to plane collision doesnt seems to work as expected. It always returns true. which causes all bins loading.

Can someone help me in detecting correct collision in this case?

Here is the code i am using

```
var polygonPoints = pointsArr;//polygon points array
//Polygon region geometry
var extrudeSettings = { depth: 8, bevelEnabled: true, bevelSegments: 2, steps: 2, bevelSize: 1, bevelThickness: 1 };
var polygonShape = new THREE.Shape(polygonPoints);
var polygonGeometry = new THREE.ExtrudeBufferGeometry(polygonShape, extrudeSettings);
var polygonMesh = new THREE.Mesh(polygonGeometry , new THREE.MeshPhongMaterial({ color: 0xf08000 }));
scene.add(polygonMesh);
//bins geometry
var planeGeometry = new THREE.PlaneGeometry(binPaneSize.x, binPaneSize.y);
var planematerial = new THREE.MeshBasicMaterial({ color: 0xffff00, side: THREE.DoubleSide });
var binMesh = new THREE.Mesh(planeGeometry, planematerial);
var polygonOutBounds = {
minX: Math.min.apply(Math, polygonPoints.map(function (o) { return o.x; })),
minY: Math.min.apply(Math, polygonPoints.map(function (o) { return o.y; })),
maxX: Math.max.apply(Math, polygonPoints.map(function (o) { return o.x; })),
maxY: Math.max.apply(Math, polygonPoints.map(function (o) { return o.y; }))
};
for (var i = polygonOutBounds.minX; i < polygonOutBounds.maxX; i += binPaneSize.x + binPaneOffset.x) {
for (var j = polygonOutBounds.minY; j < polygonOutBounds.maxY; j += binPaneSize.y + binPaneOffset.y) {
console.log(i + " - " + j);
var _binMesh = binMesh.clone();
scene.add(_binMesh);
_binMesh.position.set(i, j, 2);
if (!WebglEngine.DetectCollisionOfObjects(polygonMesh,_binMesh )) {
console.log('test');
scene.remove(_binMesh);
}
}
}
```

Function for collision detection.

```
DetectCollisionOfObjects: function (object1, object2) {
object1.geometry.computeBoundingBox(); //not needed if its already calculated
object2.geometry.computeBoundingBox();
object1.updateMatrixWorld();
object2.updateMatrixWorld();
var obj1 = object1.geometry.boundingBox.clone();
obj1.applyMatrix4(object1.matrixWorld);
var obj2 = object2.geometry.boundingBox.clone();
obj2.applyMatrix4(object2.matrixWorld);
return obj1.intersectsBox(obj2);
},
```