mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 00:56:17 +02:00
Added targets to entity switch reset
This commit is contained in:
parent
9d949da19c
commit
948b37d681
2 changed files with 165 additions and 3 deletions
|
@ -21,6 +21,7 @@
|
||||||
var wandScriptURL = Script.resolvePath("../examples/toys/bubblewand/wand.js");
|
var wandScriptURL = Script.resolvePath("../examples/toys/bubblewand/wand.js");
|
||||||
var dollScriptURL = Script.resolvePath("../examples/toys/doll/doll.js");
|
var dollScriptURL = Script.resolvePath("../examples/toys/doll/doll.js");
|
||||||
var lightsScriptURL = Script.resolvePath("../examples/toys/lightSwitch.js");
|
var lightsScriptURL = Script.resolvePath("../examples/toys/lightSwitch.js");
|
||||||
|
var targetsScriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/wallTarget.js');
|
||||||
|
|
||||||
ResetSwitch = function() {
|
ResetSwitch = function() {
|
||||||
_this = this;
|
_this = this;
|
||||||
|
@ -136,6 +137,8 @@
|
||||||
z: 503.91
|
z: 503.91
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createTargets();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteAllToys() {
|
function deleteAllToys() {
|
||||||
|
@ -368,6 +371,153 @@
|
||||||
var distanceCheckInterval = Script.setInterval(testBallDistanceFromStart, 1000);
|
var distanceCheckInterval = Script.setInterval(testBallDistanceFromStart, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createTargets() {
|
||||||
|
|
||||||
|
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx';
|
||||||
|
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target_collision_hull.obj';
|
||||||
|
|
||||||
|
var RESET_DISTANCE = 1;
|
||||||
|
var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target';
|
||||||
|
var NUMBER_OF_TARGETS = 6;
|
||||||
|
var TARGETS_PER_ROW = 3;
|
||||||
|
|
||||||
|
var TARGET_DIMENSIONS = {
|
||||||
|
x: 0.06,
|
||||||
|
y: 0.42,
|
||||||
|
z: 0.42
|
||||||
|
};
|
||||||
|
|
||||||
|
var VERTICAL_SPACING = TARGET_DIMENSIONS.y + 0.5;
|
||||||
|
var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.5;
|
||||||
|
|
||||||
|
|
||||||
|
var startPosition = {
|
||||||
|
x: 548.68,
|
||||||
|
y: 497.30,
|
||||||
|
z: 509.74
|
||||||
|
};
|
||||||
|
|
||||||
|
var rotation = Quat.fromPitchYawRollDegrees(0, -55.25, 0);
|
||||||
|
|
||||||
|
var targetIntervalClearer = Entities.addEntity({
|
||||||
|
name: 'Target Interval Clearer - delete me to clear',
|
||||||
|
type: 'Box',
|
||||||
|
position: startPosition,
|
||||||
|
dimensions: TARGET_DIMENSIONS,
|
||||||
|
color: {
|
||||||
|
red: 0,
|
||||||
|
green: 255,
|
||||||
|
blue: 0
|
||||||
|
},
|
||||||
|
rotation: rotation,
|
||||||
|
visible: false,
|
||||||
|
collisionsWillMove: false,
|
||||||
|
ignoreForCollisions: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setEntityCustomData(resetKey, targetIntervalClearer, {
|
||||||
|
resetMe: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var targets = [];
|
||||||
|
|
||||||
|
var originalPositions = [];
|
||||||
|
|
||||||
|
function addTargets() {
|
||||||
|
var i;
|
||||||
|
var row = -1;
|
||||||
|
for (i = 0; i < NUMBER_OF_TARGETS; i++) {
|
||||||
|
|
||||||
|
if (i % TARGETS_PER_ROW === 0) {
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var vHat = Quat.getFront(rotation);
|
||||||
|
var spacer = HORIZONTAL_SPACING * (i % TARGETS_PER_ROW) + (row * HORIZONTAL_SPACING / 2);
|
||||||
|
var multiplier = Vec3.multiply(spacer, vHat);
|
||||||
|
var position = Vec3.sum(startPosition, multiplier);
|
||||||
|
position.y = startPosition.y - (row * VERTICAL_SPACING);
|
||||||
|
|
||||||
|
originalPositions.push(position);
|
||||||
|
|
||||||
|
var targetProperties = {
|
||||||
|
name: 'Target',
|
||||||
|
type: 'Model',
|
||||||
|
modelURL: MODEL_URL,
|
||||||
|
shapeType: 'compound',
|
||||||
|
collisionsWillMove: true,
|
||||||
|
dimensions: TARGET_DIMENSIONS,
|
||||||
|
compoundShapeURL: COLLISION_HULL_URL,
|
||||||
|
position: position,
|
||||||
|
rotation: rotation,
|
||||||
|
script: targetsScriptURL
|
||||||
|
};
|
||||||
|
var target = Entities.addEntity(targetProperties);
|
||||||
|
targets.push(target);
|
||||||
|
setEntityCustomData(resetKey, target, {
|
||||||
|
resetMe: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTargetDistanceFromStart() {
|
||||||
|
targets.forEach(function(target, index) {
|
||||||
|
|
||||||
|
var currentPosition = Entities.getEntityProperties(target, "position").position;
|
||||||
|
var originalPosition = originalPositions[index];
|
||||||
|
var distance = Vec3.subtract(originalPosition, currentPosition);
|
||||||
|
var length = Vec3.length(distance);
|
||||||
|
|
||||||
|
if (length > RESET_DISTANCE) {
|
||||||
|
|
||||||
|
Entities.deleteEntity(target);
|
||||||
|
|
||||||
|
var targetProperties = {
|
||||||
|
name: 'Target',
|
||||||
|
type: 'Model',
|
||||||
|
modelURL: MODEL_URL,
|
||||||
|
shapeType: 'compound',
|
||||||
|
collisionsWillMove: true,
|
||||||
|
dimensions: TARGET_DIMENSIONS,
|
||||||
|
compoundShapeURL: COLLISION_HULL_URL,
|
||||||
|
position: originalPositions[index],
|
||||||
|
rotation: rotation,
|
||||||
|
script: targetsScriptURL
|
||||||
|
};
|
||||||
|
var target = Entities.addEntity(targetProperties);
|
||||||
|
targets[index] = target;
|
||||||
|
setEntityCustomData(resetKey, target, {
|
||||||
|
resetMe: true
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function deleteEntity(entityID) {
|
||||||
|
if (entityID === targetIntervalClearer) {
|
||||||
|
deleteTargets();
|
||||||
|
Script.clearInterval(distanceCheckInterval);
|
||||||
|
Entities.deletingEntity.disconnect(deleteEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteTargets() {
|
||||||
|
while (targets.length > 0) {
|
||||||
|
Entities.deleteEntity(targets.pop());
|
||||||
|
}
|
||||||
|
Entities.deleteEntity(targetIntervalClearer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Entities.deletingEntity.connect(deleteEntity);
|
||||||
|
var distanceCheckInterval = Script.setInterval(testTargetDistanceFromStart, 1000);
|
||||||
|
|
||||||
|
addTargets();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function createCat(position) {
|
function createCat(position) {
|
||||||
|
|
||||||
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx";
|
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx";
|
||||||
|
|
|
@ -388,6 +388,11 @@ MasterReset = function() {
|
||||||
ignoreForCollisions: true,
|
ignoreForCollisions: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setEntityCustomData(resetKey, targetIntervalClearer, {
|
||||||
|
resetMe: true
|
||||||
|
});
|
||||||
|
|
||||||
var targets = [];
|
var targets = [];
|
||||||
|
|
||||||
var originalPositions = [];
|
var originalPositions = [];
|
||||||
|
@ -421,8 +426,11 @@ MasterReset = function() {
|
||||||
rotation: rotation,
|
rotation: rotation,
|
||||||
script: targetsScriptURL
|
script: targetsScriptURL
|
||||||
};
|
};
|
||||||
|
var target = Entities.addEntity(targetProperties);
|
||||||
targets.push(Entities.addEntity(targetProperties));
|
targets.push(target);
|
||||||
|
setEntityCustomData(resetKey, target, {
|
||||||
|
resetMe: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,8 +458,12 @@ MasterReset = function() {
|
||||||
rotation: rotation,
|
rotation: rotation,
|
||||||
script: targetsScriptURL
|
script: targetsScriptURL
|
||||||
};
|
};
|
||||||
|
var target = Entities.addEntity(targetProperties);
|
||||||
|
targets[index] = target;
|
||||||
|
setEntityCustomData(resetKey, target, {
|
||||||
|
resetMe: true
|
||||||
|
});
|
||||||
|
|
||||||
targets[index] = Entities.addEntity(targetProperties);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue