content/hifi-public/eric/whiteboard/eraserEntityScript.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

114 lines
No EOL
4 KiB
JavaScript

//
// eraserEntityScript.js
// examples/homeContent/eraserEntityScript
//
// Created by Eric Levin on 2/17/15.
// Copyright 2016 High Fidelity, Inc.
//
// This entity script provides logic for an object with attached script to erase nearby marker strokes
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
(function() {
Script.include('https://hifi-public.s3.amazonaws.com/eric/whiteboard/utils.js');
var TRIGGER_CONTROLS = [
Controller.Standard.LT,
Controller.Standard.RT,
];
var _this;
Eraser = function() {
_this = this;
_this.ERASER_TRIGGER_THRESHOLD = 0.2;
_this.STROKE_NAME = "home_polyline_markerStroke";
_this.ERASER_TO_STROKE_SEARCH_RADIUS = 0.7;
_this.ERASER_RESET_WAIT_TIME = 3000;
};
Eraser.prototype = {
startEquip: function(id, params) {
_this.equipped = true;
_this.hand = params[0] == "left" ? 0 : 1;
// We really only need to grab position of marker strokes once, and then just check to see if eraser comes near enough to those strokes
Overlays.editOverlay(_this.searchSphere, {
visible: true
});
},
continueEquip: function() {
_this.eraserPosition = Entities.getEntityProperties(_this.entityID, "position").position;
Overlays.editOverlay(_this.searchSphere, {
position: _this.eraserPosition
});
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[_this.hand]);
if (_this.triggerValue > _this.ERASER_TRIGGER_THRESHOLD) {
_this.continueHolding();
}
},
continueHolding: function() {
var strokeIDs = Entities.findEntities(_this.eraserPosition, _this.ERASER_TO_STROKE_SEARCH_RADIUS);
// Create a map of stroke entities and their positions
strokeIDs.forEach(function(strokeID) {
var strokeProps = Entities.getEntityProperties(strokeID, ["position", "name"]);
if (strokeProps.name === _this.STROKE_NAME && Vec3.distance(_this.eraserPosition, strokeProps.position) < _this.ERASER_TO_STROKE_SEARCH_RADIUS) {
Entities.deleteEntity(strokeID);
}
});
},
releaseEquip: function() {
Overlays.editOverlay(_this.searchSphere, {
visible: false
});
},
collisionWithEntity: function(myID, otherID, collision) {
var otherProps = Entities.getEntityProperties(otherID);
if (otherProps.name === 'home_model_homeset') {
var userData = getEntityUserData(_this.entityID);
Entities.editEntity(_this.entityID, {
position: userData.originalPosition,
rotation: userData.originalRotation,
velocity: {
x: 0,
y: -0.01,
z: 0
},
angularVelocity: {
x: 0,
y: 0,
z: 0
}
});
}
},
preload: function(entityID) {
_this.entityID = entityID;
_this.searchSphere = Overlays.addOverlay('sphere', {
size: _this.ERASER_TO_STROKE_SEARCH_RADIUS,
color: {
red: 200,
green: 10,
blue: 10
},
alpha: 0.2,
solid: true,
visible: false
})
},
unload: function() {
Overlays.deleteOverlay(_this.searchSphere);
}
};
// entity scripts always need to return a newly constructed object of our type
return new Eraser();
});