Hi,
Many thanks for the great JS port of recast navigation. I’ve been exploring the examples and attempted to add multiple obstacles to the docs example “Adding a door to a navigation mesh”:
https://playground.babylonjs.com/#WCSDE1
Adding multiple obstacles works wonders, but you aren’t able to remove a specific obstacle later. The reason seems to be that creating multiple obstacles returns the same pointer.
It’s easy to reproduce this bug with the following code:
var obstacle = null;
var obstacle2 = null;
var obstacleMesh;
var toggleObstacle = function(scene, navigationPlugin) {
if (!obstacle)
{
obstacle = navigationPlugin.addCylinderObstacle(new BABYLON.Vector3(0,-1,0), 1, 2);
obstacle2 = navigationPlugin.addCylinderObstacle(new BABYLON.Vector3(2,-1,0), 1, 2);
obstacleMesh = BABYLON.MeshBuilder.CreateBox("cube", { size: 1 }, scene);
obstacleMesh.scaling.x = 0.5;
obstacleMesh.scaling.z = 2;
var matObstacle = new BABYLON.StandardMaterial('matObstacle', scene);
matObstacle.diffuseColor = new BABYLON.Color3(0.7,0.3,0.3);
obstacleMesh.material = matObstacle;
obstacleMesh.position = new BABYLON.Vector3(0, 0.5, 0);
} else {
console.log(obstacle, obstacle2);
navigationPlugin.removeObstacle(obstacle);
obstacleMesh.dispose();
obstacle = null;
}
In the console both obstacle and obstacle2 hold the same pointer:
dtObstacleRef {ptr: 23572} dtObstacleRef {ptr: 23572}
Attempting to remove the first obstacle will result in removing the second one. The pointer for the first obstacle has been lost somehow. I’ve been studying the recastjs plugin on how to resolve this, without success so far.