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.
112 lines
4 KiB
JavaScript
112 lines
4 KiB
JavaScript
// testAvatarEnterLeaveZone.js
|
|
//
|
|
// Creates a ModelEntityItem with an enterLeave entityScript on it.
|
|
// Moves entity around such that MyAvatar goes in/out of intersection.
|
|
// We expect to receive Enter/Leave events accordingly, which trigger a sound.
|
|
|
|
var rezDistance = 5.0;
|
|
var rezOrientation = MyAvatar.orientation;
|
|
var forward = Quat.getFront(rezOrientation);
|
|
var forwardOffset = Vec3.multiply(rezDistance, forward);
|
|
var rezPosition = Vec3.sum(MyAvatar.position, forwardOffset);
|
|
var rezDimensions = { x: 4.0, y: 7.0, z: 4.0 };
|
|
var rezRegistrationPoint = { x: 0.35, y: 0.62, z: 0.43 };
|
|
var rezCollidesWith = "dynamic"; // not with myAvatar
|
|
var rezLifetime = 120;
|
|
|
|
|
|
var properties = {
|
|
type: "Model",
|
|
name: "model",
|
|
modelURL: "http://localhost/~andrew/models/droplet.obj",
|
|
compoundShapeURL: "http://localhost/~andrew/models/droplet.obj",
|
|
//modelURL: "http://localhost/~andrew/models/box-maya.fbx",
|
|
//compoundShapeURL: "http://localhost/~andrew/models/box-maya.fbx",
|
|
//modelURL: "http://localhost/~andrew/models/box-blender.fbx",
|
|
//compoundShapeURL: "http://localhost/~andrew/models/box-blender.fbx",
|
|
shapeType: "compound",
|
|
script: "https://s3.amazonaws.com/andrew/test/js/entityScripts/playSoundOnEnterOrLeave.js",
|
|
position: rezPosition,
|
|
rotation: rezOrientation,
|
|
dimensions: rezDimensions,
|
|
registrationPoint: rezRegistrationPoint,
|
|
collidesWith: rezCollidesWith,
|
|
lifetime: rezLifetime
|
|
};
|
|
|
|
var entity = Entities.addEntity(properties);
|
|
|
|
// these are the normalizedLocalPoints we will test:
|
|
// pairs of points inside/outside the
|
|
var delta = 0.01;
|
|
var halfSide = 0.5;
|
|
var normalizedLocalPoints = [
|
|
// center/outside-corner
|
|
{ x: 0, y: 0, z: 0 },
|
|
{ x: halfSide + delta, y: halfSide + delta, z: halfSide + delta },
|
|
// x-axis
|
|
{ x: halfSide - delta, y: 0, z: 0 },
|
|
{ x: halfSide + delta, y: 0, z: 0 },
|
|
{ x: -halfSide + delta, y: 0, z: 0 },
|
|
{ x: -halfSide - delta, y: 0, z: 0 },
|
|
// y-axis
|
|
{ x: 0, y: halfSide - delta, z: 0 },
|
|
{ x: 0, y: halfSide + delta, z: 0 },
|
|
{ x: 0, y: -halfSide + delta, z: 0 },
|
|
{ x: 0, y: -halfSide - delta, z: 0 },
|
|
// z-axis
|
|
{ x: 0, y: 0, z: halfSide - delta },
|
|
{ x: 0, y: 0, z: halfSide + delta },
|
|
{ x: 0, y: 0, z: -halfSide + delta },
|
|
{ x: 0, y: 0, z: -halfSide - delta }
|
|
];
|
|
|
|
// for each "normalized local" Point compute an entityPositioin that will move it such that MyAvatar
|
|
// is at the transformed-to-world Point
|
|
//
|
|
// worldPoint = entityPosition + entityOrientation * (entityDimensions .* (normalizedCenter - registrationPoint) + normalizedPoint)
|
|
//
|
|
// avatarPosition = worldPoint
|
|
//
|
|
// entityPosition = avatarPosition - entityOrientation * (entityDimensions .* (normalizedCenter - registrationPoint) + normalizedPoint)
|
|
//
|
|
var testPoints = [];
|
|
var myAvatarPosition = MyAvatar.position;
|
|
var localCenter = { x: 0.5 - rezRegistrationPoint.x, y: 0.5 - rezRegistrationPoint.y, z: 0.5 - rezRegistrationPoint.z };
|
|
var numPoints = normalizedLocalPoints.length;
|
|
for (var i = 0; i < numPoints; ++i) {
|
|
var point = normalizedLocalPoints[i];
|
|
var offsetPoint = Vec3.sum(localCenter, point);
|
|
var scaledPoint = {
|
|
x: rezDimensions.x * offsetPoint.x,
|
|
y: rezDimensions.y * offsetPoint.y,
|
|
z: rezDimensions.z * offsetPoint.z };
|
|
var rotatedPoint = Vec3.multiplyQbyV(rezOrientation, scaledPoint);
|
|
var entityPosition = Vec3.subtract(myAvatarPosition, rotatedPoint);
|
|
testPoints.push(entityPosition);
|
|
}
|
|
|
|
var testDelay = 2000;
|
|
var intervalHandle = Script.setInterval(function() { }, testDelay);
|
|
Script.clearInterval(intervalHandle);
|
|
intervalHandle = null;
|
|
|
|
var testIndex = 0;
|
|
var testNextPoint = function () {
|
|
var p = { position: rezPosition };
|
|
if (testIndex < testPoints.length) {
|
|
p.position = testPoints[testIndex];
|
|
testIndex++;
|
|
} else {
|
|
Script.clearInterval(intervalHandle);
|
|
intervalHandle = null;
|
|
}
|
|
Entities.editEntity(entity, p);
|
|
}
|
|
|
|
intervalHandle = Script.setInterval(testNextPoint, testDelay);
|
|
|
|
var onEndScript = function() {
|
|
Entities.deleteEntity(entity);
|
|
};
|
|
Script.scriptEnding.connect(onEndScript);
|