64 lines
No EOL
2 KiB
JavaScript
64 lines
No EOL
2 KiB
JavaScript
(function () {
|
|
|
|
var entityID;
|
|
var overlayID;
|
|
|
|
var HALF = 0.5;
|
|
var CREATE_OVERLAY_DIMENSIONS_OFFSET = 0.02;
|
|
var OVERLAY_ALPHA = 1.0;
|
|
|
|
function CreateOverlayOverEntity () {
|
|
|
|
}
|
|
|
|
CreateOverlayOverEntity.prototype = {
|
|
preload: function (id) {
|
|
entityID = id;
|
|
|
|
var entityProperties = Entities.getEntityProperties(entityID, ["position", "registrationPoint", "dimensions", "rotation"])
|
|
|
|
var position = entityProperties.position;
|
|
var registrationPoint = entityProperties.registrationPoint;
|
|
var dimensions = entityProperties.dimensions;
|
|
var rotation = entityProperties.rotation;
|
|
|
|
var localOffset = {
|
|
x: -1 * (registrationPoint.x - HALF) * dimensions.x,
|
|
y: -1 * (registrationPoint.y - HALF) * dimensions.y,
|
|
z: -1 * (registrationPoint.z - HALF) * dimensions.z
|
|
};
|
|
|
|
var worldOffset = Vec3.multiplyQbyV(rotation, localOffset);
|
|
var worldPosition = Vec3.sum(position, worldOffset);
|
|
|
|
// create visible cube
|
|
overlayID = Overlays.addOverlay("cube", {
|
|
position: {
|
|
x: worldPosition.x,
|
|
y: worldPosition.y,
|
|
z: worldPosition.z
|
|
},
|
|
rotation: rotation,
|
|
dimensions: {
|
|
x: dimensions.x + CREATE_OVERLAY_DIMENSIONS_OFFSET,
|
|
y: dimensions.y + CREATE_OVERLAY_DIMENSIONS_OFFSET,
|
|
z: dimensions.z + CREATE_OVERLAY_DIMENSIONS_OFFSET
|
|
},
|
|
solid: true,
|
|
alpha: OVERLAY_ALPHA,
|
|
parentID: entityID
|
|
});
|
|
},
|
|
|
|
unload: function () {
|
|
/*
|
|
if (overlayID) {
|
|
Overlays.deleteOverlay(overlayID);
|
|
overlayID = null;
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
|
|
return new CreateOverlayOverEntity();
|
|
}); |