HI, I am trying to use the two scripts shape-world.js & shape.js for VR gaze input.
In my scene, the shape-world.js script is attached to the root and shape.js script to various entities in the scene that I want to interact with.
When I disable (through this.entity.enabled = false) any object that has the shape.js attached to it, the shape-world.js script throws up an error.
Uncaught TypeError: Cannot read property ‘indexOf’ of undefined
I’m guessing this is because the _removeItem() function cannot access the entity I have just set to enabled = false?
Is it necessary to remove a pickableEntity or shape from the array if the parent entity is not enabled already? What is the correct way of setting enable=false; on entities with shape.js attached to them?
Thanks.
Varun
p.s Here is the _removeItem() function from shape-world.js:
ShapeWorld.prototype._removeItem = function (entity) {
var i = this._items.indexOf(entity);
if (i >= 0) {
this._pickableEntities.splice(i, 1);
this._pickableShapes.splice(i, 1);
}
};
ShapeWorld.prototype.removeItem = function (entity) {
var i = this._items.indexOf(entity);
if (i >= 0) {
this._pickableEntities.splice(i, 1);
this._pickableShapes.splice(i, 1);
}
};
Should be:
ShapeWorld.prototype.removeItem = function (entity) {
var i = this._pickableEntities.indexOf(entity);
if (i >= 0) {
this._pickableEntities.splice(i, 1);
this._pickableShapes.splice(i, 1);
}
};
_pickableEntities is an array of the entity that has the core logic of that object (i.e The one that should be receiving the events from shapeWorld.js) and _pickableShapes is the array of shapes to cast against.
This is because the shape can be a child of the entity that has the visual representation and the entity logic.
The two arrays should be in sync with each other so the index would be the same for both.
In hindsight, what I could have done/should have done is add another property to the shape to reference the entity and that way, I could have a compound of shapes pointing to the same entity and only have one array of shapes in shapeWorld.js.