Merge branch 'master' of https://github.com/highfidelity/hifi into temp0

This commit is contained in:
Sam Gateau 2014-12-05 13:38:30 -08:00
commit c49b753c98
10 changed files with 512 additions and 483 deletions

View file

@ -13,18 +13,13 @@
// //
var numButterflies = 20; var numButterflies = 25;
function getRandomFloat(min, max) { function getRandomFloat(min, max) {
return Math.random() * (max - min) + min; return Math.random() * (max - min) + min;
} }
// Multiply vector by scalar
function vScalarMult(v, s) {
var rval = { x: v.x * s, y: v.y * s, z: v.z * s };
return rval;
}
// Create a random vector with individual lengths between a,b // Create a random vector with individual lengths between a,b
function randVector(a, b) { function randVector(a, b) {
@ -32,50 +27,36 @@ function randVector(a, b) {
return rval; return rval;
} }
// Returns a vector which is fraction of the way between a and b
function vInterpolate(a, b, fraction) {
var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction };
return rval;
}
var startTimeInSeconds = new Date().getTime() / 1000; var startTimeInSeconds = new Date().getTime() / 1000;
var NATURAL_SIZE_OF_BUTTERFLY = { x: 1.76, y: 0.825, z: 0.20 }; var NATURAL_SIZE_OF_BUTTERFLY = { x: 1.0, y: 0.4, z: 0.2 };
var lifeTime = 600; // lifetime of the butterflies in seconds
var range = 3.0; // Over what distance in meters do you want the flock to fly around var lifeTime = 3600; // One hour lifespan
var range = 5.0; // Over what distance in meters do you want the flock to fly around
var frame = 0; var frame = 0;
var CHANCE_OF_MOVING = 0.9;
var BUTTERFLY_GRAVITY = 0;
var BUTTERFLY_FLAP_SPEED = 0.5;
var BUTTERFLY_VELOCITY = 0.55;
var DISTANCE_IN_FRONT_OF_ME = 1.5; var DISTANCE_IN_FRONT_OF_ME = 1.5;
var DISTANCE_ABOVE_ME = 1.5; var DISTANCE_ABOVE_ME = 1.5;
var flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum( var FIXED_LOCATION = false;
if (!FIXED_LOCATION) {
var flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME), Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME),
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME))); Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)));
} else {
var flockPosition = { x: 4999.6, y: 4986.5, z: 5003.5 };
}
// set these pitch, yaw, roll to the needed values to orient the model as you want it
var pitchInDegrees = 270.0;
var yawInDegrees = 0.0;
var rollInDegrees = 0.0;
var pitchInRadians = pitchInDegrees / 180.0 * Math.PI;
var yawInRadians = yawInDegrees / 180.0 * Math.PI;
var rollInRadians = rollInDegrees / 180.0 * Math.PI;
var rotation = Quat.fromPitchYawRollDegrees(pitchInDegrees, yawInDegrees, rollInDegrees);//experimental
// This is our butterfly object // This is our butterfly object
function defineButterfly(entityID, targetPosition) { function defineButterfly(entityID, targetPosition) {
this.entityID = entityID; this.entityID = entityID;
this.previousFlapOffset = 0;
this.targetPosition = targetPosition; this.targetPosition = targetPosition;
this.moving = false;
} }
// Array of butterflies // Array of butterflies
var butterflies = []; var butterflies = [];
function addButterfly() { function addButterfly() {
// Decide the size of butterfly // Decide the size of butterfly
var color = { red: 100, green: 100, blue: 100 }; var color = { red: 100, green: 100, blue: 100 };
@ -88,26 +69,24 @@ function addButterfly() {
size = MINSIZE + Math.random() * RANGESIZE; size = MINSIZE + Math.random() * RANGESIZE;
var dimensions = Vec3.multiply(NATURAL_SIZE_OF_BUTTERFLY, (size / maxSize)); var dimensions = Vec3.multiply(NATURAL_SIZE_OF_BUTTERFLY, (size / maxSize));
flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum( var GRAVITY = -0.2;
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME), var newFrameRate = 20 + Math.random() * 30;
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)));
var properties = { var properties = {
type: "Model", type: "Model",
lifetime: lifeTime, lifetime: lifeTime,
position: Vec3.sum(randVector(-range, range), flockPosition), position: Vec3.sum(randVector(-range, range), flockPosition),
velocity: { x: 0, y: 0.0, z: 0 }, rotation: Quat.fromPitchYawRollDegrees(-80 + Math.random() * 20, Math.random() * 360.0, 0.0),
gravity: { x: 0, y: 1.0, z: 0 }, velocity: { x: 0, y: 0, z: 0 },
damping: 0.1, gravity: { x: 0, y: GRAVITY, z: 0 },
damping: 0.9999,
dimensions: dimensions, dimensions: dimensions,
color: color, color: color,
rotation: rotation,
animationURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx", animationURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx",
animationIsPlaying: true, animationSettings: "{\"firstFrame\":0,\"fps\":" + newFrameRate + ",\"frameIndex\":0,\"hold\":false,\"lastFrame\":10000,\"loop\":true,\"running\":true,\"startAutomatically\":false}",
modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx" modelURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/models/content/butterfly/butterfly.fbx"
}; };
butterflies.push(new defineButterfly(Entities.addEntity(properties), properties.position)); butterflies.push(Entities.addEntity(properties));
} }
// Generate the butterflies // Generate the butterflies
@ -116,117 +95,34 @@ for (var i = 0; i < numButterflies; i++) {
} }
// Main update function // Main update function
function updateButterflies(deltaTime) { function updateButterflies(deltaTime) {
// Check to see if we've been running long enough that our butterflies are dead
var nowTimeInSeconds = new Date().getTime() / 1000;
if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) {
Script.stop();
return;
}
frame++; frame++;
// Only update every third frame because we don't need to do it too quickly // Only update every third frame because we don't need to do it too quickly
if ((frame % 3) == 0) { if ((frame % 3) == 0) {
flockPosition = Vec3.sum(MyAvatar.position,Vec3.sum(Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_ABOVE_ME),
Vec3.multiply(Quat.getFront(MyAvatar.orientation), DISTANCE_IN_FRONT_OF_ME)));
// Update all the butterflies // Update all the butterflies
var CHANCE_OF_IMPULSE = 0.04;
for (var i = 0; i < numButterflies; i++) { for (var i = 0; i < numButterflies; i++) {
entityID = Entities.identifyEntity(butterflies[i].entityID); if (Math.random() < CHANCE_OF_IMPULSE) {
butterflies[i].entityID = entityID; var properties = Entities.getEntityProperties(butterflies[i]);
var properties = Entities.getEntityProperties(entityID); if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
Entities.editEntity(butterflies[i], { position: flockPosition } );
if (properties.position.y > flockPosition.y + getRandomFloat(0.0,0.3)){ //0.3 //ceiling } else if (properties.velocity.y < 0.0) {
properties.gravity.y = - 3.0; // If falling, Create a new direction and impulse
properties.damping.y = 1.0; var HORIZ_SCALE = 0.50;
properties.velocity.y = 0; var VERT_SCALE = 0.50;
properties.velocity.x = properties.velocity.x; var newHeading = Math.random() * 360.0;
properties.velocity.z = properties.velocity.z; var newVelocity = Vec3.multiply(HORIZ_SCALE, Quat.getFront(Quat.fromPitchYawRollDegrees(0.0, newHeading, 0.0)));
if (properties.velocity.x < 0.5){ newVelocity.y = (Math.random() + 0.5) * VERT_SCALE;
butterflies[i].moving = false; Entities.editEntity(butterflies[i], { rotation: Quat.fromPitchYawRollDegrees(-80 + Math.random() * 20, newHeading, (Math.random() - 0.5) * 10),
} velocity: newVelocity } );
if (properties.velocity.z < 0.5){
butterflies[i].moving = false;
}
}
if (properties.velocity.y <= -0.2) {
properties.velocity.y = 0.22;
properties.velocity.x = properties.velocity.x;
properties.velocity.z = properties.velocity.z;
}
if (properties.position.y < flockPosition.y - getRandomFloat(0.0,0.3)) { //-0.3 // floor
properties.velocity.y = 0.9;
properties.gravity.y = - 4.0;
properties.velocity.x = properties.velocity.x;
properties.velocity.z = properties.velocity.z;
if (properties.velocity.x < 0.5){
butterflies[i].moving = false;
}
if (properties.velocity.z < 0.5){
butterflies[i].moving = false;
}
}
// Begin movement by getting a target
if (butterflies[i].moving == false) {
if (Math.random() < CHANCE_OF_MOVING) {
var targetPosition = Vec3.sum(randVector(-range, range), flockPosition);
if (targetPosition.x < 0) {
targetPosition.x = 0;
}
if (targetPosition.y < 0) {
targetPosition.y = 0;
}
if (targetPosition.z < 0) {
targetPosition.z = 0;
}
if (targetPosition.x > TREE_SCALE) {
targetPosition.x = TREE_SCALE;
}
if (targetPosition.y > TREE_SCALE) {
targetPosition.y = TREE_SCALE;
}
if (targetPosition.z > TREE_SCALE) {
targetPosition.z = TREE_SCALE;
}
butterflies[i].targetPosition = targetPosition;
butterflies[i].moving = true;
} }
} }
}
// If we are moving, move towards the target // Check to see if we've been running long enough that our butterflies are dead
if (butterflies[i].moving) { var nowTimeInSeconds = new Date().getTime() / 1000;
if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) {
var holding = properties.velocity.y; Script.stop();
return;
var desiredVelocity = Vec3.subtract(butterflies[i].targetPosition, properties.position);
desiredVelocity = vScalarMult(Vec3.normalize(desiredVelocity), BUTTERFLY_VELOCITY);
properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.5);
properties.velocity.y = holding ;
// If we are near the target, we should get a new target
var halfLargestDimension = Vec3.length(properties.dimensions) / 2.0;
if (Vec3.length(Vec3.subtract(properties.position, butterflies[i].targetPosition)) < (halfLargestDimension)) {
butterflies[i].moving = false;
}
var yawRads = Math.atan2(properties.velocity.z, properties.velocity.x);
yawRads = yawRads + Math.PI / 2.0;
var newOrientation = Quat.fromPitchYawRollRadians(pitchInRadians, yawRads, rollInRadians);
properties.rotation = newOrientation;
}
// Use a cosine wave offset to make it look like its flapping.
var offset = Math.cos(nowTimeInSeconds * BUTTERFLY_FLAP_SPEED) * (halfLargestDimension);
properties.position.y = properties.position.y + (offset - butterflies[i].previousFlapOffset);
// Change position relative to previous offset.
butterflies[i].previousFlapOffset = offset;
Entities.editEntity(entityID, properties);
} }
} }
} }
@ -237,6 +133,6 @@ Script.update.connect(updateButterflies);
// Delete our little friends if script is stopped // Delete our little friends if script is stopped
Script.scriptEnding.connect(function() { Script.scriptEnding.connect(function() {
for (var i = 0; i < numButterflies; i++) { for (var i = 0; i < numButterflies; i++) {
Entities.deleteEntity(butterflies[i].entityID); Entities.deleteEntity(butterflies[i]);
} }
}); });

View file

@ -160,102 +160,102 @@
elLocked.checked = properties.locked; elLocked.checked = properties.locked;
if (properties.locked) { if (properties.locked) {
disableChildren(document.getElementById("properties"), 'input'); disableChildren(document.getElementById("properties-table"), 'input');
elLocked.removeAttribute('disabled'); elLocked.removeAttribute('disabled');
} else { } else {
enableChildren(document.getElementById("properties"), 'input'); enableChildren(document.getElementById("properties-table"), 'input');
}
elVisible.checked = properties.visible; elVisible.checked = properties.visible;
elPositionX.value = properties.position.x.toFixed(2); elPositionX.value = properties.position.x.toFixed(2);
elPositionY.value = properties.position.y.toFixed(2); elPositionY.value = properties.position.y.toFixed(2);
elPositionZ.value = properties.position.z.toFixed(2); elPositionZ.value = properties.position.z.toFixed(2);
elDimensionsX.value = properties.dimensions.x.toFixed(2); elDimensionsX.value = properties.dimensions.x.toFixed(2);
elDimensionsY.value = properties.dimensions.y.toFixed(2); elDimensionsY.value = properties.dimensions.y.toFixed(2);
elDimensionsZ.value = properties.dimensions.z.toFixed(2); elDimensionsZ.value = properties.dimensions.z.toFixed(2);
elRegistrationX.value = properties.registrationPoint.x.toFixed(2); elRegistrationX.value = properties.registrationPoint.x.toFixed(2);
elRegistrationY.value = properties.registrationPoint.y.toFixed(2); elRegistrationY.value = properties.registrationPoint.y.toFixed(2);
elRegistrationZ.value = properties.registrationPoint.z.toFixed(2); elRegistrationZ.value = properties.registrationPoint.z.toFixed(2);
elLinearVelocityX.value = properties.velocity.x.toFixed(2); elLinearVelocityX.value = properties.velocity.x.toFixed(2);
elLinearVelocityY.value = properties.velocity.y.toFixed(2); elLinearVelocityY.value = properties.velocity.y.toFixed(2);
elLinearVelocityZ.value = properties.velocity.z.toFixed(2); elLinearVelocityZ.value = properties.velocity.z.toFixed(2);
elLinearDamping.value = properties.damping.toFixed(2); elLinearDamping.value = properties.damping.toFixed(2);
elAngularVelocityX.value = properties.angularVelocity.x.toFixed(2); elAngularVelocityX.value = properties.angularVelocity.x.toFixed(2);
elAngularVelocityY.value = properties.angularVelocity.y.toFixed(2); elAngularVelocityY.value = properties.angularVelocity.y.toFixed(2);
elAngularVelocityZ.value = properties.angularVelocity.z.toFixed(2); elAngularVelocityZ.value = properties.angularVelocity.z.toFixed(2);
elAngularDamping.value = properties.angularDamping.toFixed(2); elAngularDamping.value = properties.angularDamping.toFixed(2);
elGravityX.value = properties.gravity.x.toFixed(2); elGravityX.value = properties.gravity.x.toFixed(2);
elGravityY.value = properties.gravity.y.toFixed(2); elGravityY.value = properties.gravity.y.toFixed(2);
elGravityZ.value = properties.gravity.z.toFixed(2); elGravityZ.value = properties.gravity.z.toFixed(2);
elMass.value = properties.mass.toFixed(2); elMass.value = properties.mass.toFixed(2);
elIgnoreForCollisions.checked = properties.ignoreForCollisions; elIgnoreForCollisions.checked = properties.ignoreForCollisions;
elCollisionsWillMove.checked = properties.collisionsWillMove; elCollisionsWillMove.checked = properties.collisionsWillMove;
elLifetime.value = properties.lifetime; elLifetime.value = properties.lifetime;
if (properties.type != "Box") { if (properties.type != "Box") {
elBoxSection.style.display = 'none'; elBoxSection.style.display = 'none';
} else { } else {
elBoxSection.style.display = 'block'; elBoxSection.style.display = 'block';
elBoxColorRed.value = properties.color.red; elBoxColorRed.value = properties.color.red;
elBoxColorGreen.value = properties.color.green; elBoxColorGreen.value = properties.color.green;
elBoxColorBlue.value = properties.color.blue; elBoxColorBlue.value = properties.color.blue;
} }
if (properties.type != "Model") { if (properties.type != "Model") {
elModelSection.style.display = 'none'; elModelSection.style.display = 'none';
} else { } else {
elModelSection.style.display = 'block'; elModelSection.style.display = 'block';
elModelURL.value = properties.modelURL; elModelURL.value = properties.modelURL;
elModelAnimationURL.value = properties.animationURL; elModelAnimationURL.value = properties.animationURL;
elModelAnimationPlaying.checked = properties.animationIsPlaying; elModelAnimationPlaying.checked = properties.animationIsPlaying;
elModelAnimationFPS.value = properties.animationFPS; elModelAnimationFPS.value = properties.animationFPS;
} }
if (properties.type != "Text") { if (properties.type != "Text") {
elTextSection.style.display = 'none'; elTextSection.style.display = 'none';
} else { } else {
elTextSection.style.display = 'block'; elTextSection.style.display = 'block';
elTextText.value = properties.text; elTextText.value = properties.text;
elTextLineHeight.value = properties.lineHeight; elTextLineHeight.value = properties.lineHeight;
elTextTextColorRed.value = properties.textColor.red; elTextTextColorRed.value = properties.textColor.red;
elTextTextColorGreen.value = properties.textColor.green; elTextTextColorGreen.value = properties.textColor.green;
elTextTextColorBlue.value = properties.textColor.blue; elTextTextColorBlue.value = properties.textColor.blue;
elTextBackgroundColorRed.value = properties.backgroundColor.red; elTextBackgroundColorRed.value = properties.backgroundColor.red;
elTextBackgroundColorGreen.value = properties.backgroundColor.green; elTextBackgroundColorGreen.value = properties.backgroundColor.green;
elTextBackgroundColorBlue.value = properties.backgroundColor.blue; elTextBackgroundColorBlue.value = properties.backgroundColor.blue;
} }
if (properties.type != "Light") { if (properties.type != "Light") {
elLightSection.style.display = 'none'; elLightSection.style.display = 'none';
} else { } else {
elLightSection.style.display = 'block'; elLightSection.style.display = 'block';
elLightDiffuseRed.value = properties.diffuseColor.red; elLightDiffuseRed.value = properties.diffuseColor.red;
elLightDiffuseGreen.value = properties.diffuseColor.green; elLightDiffuseGreen.value = properties.diffuseColor.green;
elLightDiffuseBlue.value = properties.diffuseColor.blue; elLightDiffuseBlue.value = properties.diffuseColor.blue;
elLightAmbientRed.value = properties.ambientColor.red; elLightAmbientRed.value = properties.ambientColor.red;
elLightAmbientGreen.value = properties.ambientColor.green; elLightAmbientGreen.value = properties.ambientColor.green;
elLightAmbientBlue.value = properties.ambientColor.blue; elLightAmbientBlue.value = properties.ambientColor.blue;
elLightSpecularRed.value = properties.specularColor.red; elLightSpecularRed.value = properties.specularColor.red;
elLightSpecularGreen.value = properties.specularColor.green; elLightSpecularGreen.value = properties.specularColor.green;
elLightSpecularBlue.value = properties.specularColor.blue; elLightSpecularBlue.value = properties.specularColor.blue;
elLightConstantAttenuation.value = properties.constantAttenuation; elLightConstantAttenuation.value = properties.constantAttenuation;
elLightLinearAttenuation.value = properties.linearAttenuation; elLightLinearAttenuation.value = properties.linearAttenuation;
elLightQuadraticAttenuation.value = properties.quadraticAttenuation; elLightQuadraticAttenuation.value = properties.quadraticAttenuation;
elLightExponent.value = properties.exponent; elLightExponent.value = properties.exponent;
elLightCutoff.value = properties.cutoff; elLightCutoff.value = properties.cutoff;
}
} }
} }
} }
@ -345,7 +345,7 @@
elModelAnimationPlaying.addEventListener('change', createEmitCheckedPropertyUpdateFunction('animationIsPlaying')); elModelAnimationPlaying.addEventListener('change', createEmitCheckedPropertyUpdateFunction('animationIsPlaying'));
elModelAnimationFPS.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFPS')); elModelAnimationFPS.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFPS'));
elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex')); elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex'));
elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text')); elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text'));
elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight')); elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight'));
@ -361,6 +361,50 @@
elTextBackgroundColorGreen.addEventListener('change', textBackgroundColorChangeFunction); elTextBackgroundColorGreen.addEventListener('change', textBackgroundColorChangeFunction);
elTextBackgroundColorBlue.addEventListener('change', textBackgroundColorChangeFunction); elTextBackgroundColorBlue.addEventListener('change', textBackgroundColorChangeFunction);
var resizing = false;
var startX = 0;
var originalWidth = 0;
var resizeHandleWidth = 10;
var col1 = document.querySelector("#col-label");
document.body.addEventListener('mousemove', function(event) {
if (resizing) {
var dX = event.x - startX;
col1.style.width = (originalWidth + dX) + "px";
}
});
document.body.addEventListener('mouseup', function(event) {
resizing = false;
});
document.body.addEventListener('mouseleave', function(event) {
resizing = false;
});
var els = document.querySelectorAll("#properties-table td");
for (var i = 0; i < els.length; i++) {
var el = els[i];
el.addEventListener('mousemove', function(event) {
if (!resizing) {
var distance = this.offsetWidth - event.offsetX;
if (distance < resizeHandleWidth) {
document.body.style.cursor = "ew-resize";
} else {
document.body.style.cursor = "initial";
}
}
});
el.addEventListener('mousedown', function(event) {
var distance = this.offsetWidth - event.offsetX;
if (distance < resizeHandleWidth) {
startX = event.x;
originalWidth = this.offsetWidth;
resizing = true;
target = this;
}
});
}
} }
</script> </script>
</head> </head>
@ -368,272 +412,269 @@
<div class="section-header"> <div class="section-header">
<label>Entity Properties</label> <label>Entity Properties</label>
</div> </div>
<div id="properties" class="grid-section"> <table id="properties-table">
<div class="property-section"> <colgroup>
<label>Type</label> <col id="col-label">
<span> <col>
<label id="property-type"></input> </colgroup>
</span> <tr>
</div> <td class="label">
Type
<div class="property-section"> </td>
<label>Locked</label> <td>
<span> <label id="property-type"></label>
</td>
</tr>
<tr>
<td class="label">Locked</td>
<td>
<input type='checkbox' id="property-locked"> <input type='checkbox' id="property-locked">
</span> </td>
</div> </tr>
<div class="property-section"> <tr>
<label>Visible</label> <td class="label">Visible</td>
<span> <td>
<input type='checkbox' id="property-visible"> <input type='checkbox' id="property-visible">
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Position</label> <td class="label">Position</td>
<span> <td>
X <input class="coord" type='number' id="property-pos-x"></input> <div class="input-area">X <input class="coord" type='number' id="property-pos-x"></input></div>
Y <input class="coord" type='number' id="property-pos-y"></input> <div class="input-area">Y <input class="coord" type='number' id="property-pos-y"></input></div>
Z <input class="coord" type='number' id="property-pos-z"></input> <div class="input-area">Z <input class="coord" type='number' id="property-pos-z"></input></div>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Registration</label> <td class="label">Registration</td>
<span> <td>
X <input class="coord" type='number' id="property-reg-x"></input> <div class="input-area">X <input class="coord" type='number' id="property-reg-x"></input></div>
Y <input class="coord" type='number' id="property-reg-y"></input> <div class="input-area">Y <input class="coord" type='number' id="property-reg-y"></input></div>
Z <input class="coord" type='number' id="property-reg-z"></input> <div class="input-area">Z <input class="coord" type='number' id="property-reg-z"></input></div>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Width</label> <td class="label">Width</td>
<span> <td>
<input class="coord" type='number' id="property-dim-x"></input> <input class="coord" type='number' id="property-dim-x"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Height</label> <td class="label">Height</td>
<span> <td>
<input class="coord" type='number' id="property-dim-y"></input> <input class="coord" type='number' id="property-dim-y"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Depth</label> <td class="label">Depth</td>
<span> <td>
<input class="coord" type='number' id="property-dim-z"></input> <input class="coord" type='number' id="property-dim-z"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Linear</label> <td class="label">Linear</td>
<span> <td>
X <input class="coord" type='number' id="property-lvel-x"></input> <div class="input-area">X <input class="coord" type='number' id="property-lvel-x"></input></div>
Y <input class="coord" type='number' id="property-lvel-y"></input> <div class="input-area">Y <input class="coord" type='number' id="property-lvel-y"></input></div>
Z <input class="coord" type='number' id="property-lvel-z"></input> <div class="input-area">Z <input class="coord" type='number' id="property-lvel-z"></input></div>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Linear Damping</label> <td class="label">Linear Damping</td>
<span> <td>
<input class="coord" type='number' id="property-ldamping"></input> <input class="coord" type='number' id="property-ldamping"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Angular</label> <td class="label">Angular</td>
<span> <td>
Pitch <input class="coord" type='number' id="property-avel-x"></input> <div class="input-area">Pitch <input class="coord" type='number' id="property-avel-x"></input></div>
Roll <input class="coord" type='number' id="property-avel-z"></input> <div class="input-area">Yaw <input class="coord" type='number' id="property-avel-y"></input></div>
Yaw <input class="coord" type='number' id="property-avel-y"></input> <div class="input-area">Roll <input class="coord" type='number' id="property-avel-z"></input></div>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Angular Damping</label> <td class="label">Angular Damping</td>
<span> <td>
<input class="coord" type='number' id="property-adamping"></input> <input class="coord" type='number' id="property-adamping"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Gravity</label> <td class="label">Gravity</td>
<span> <td>
X <input class="coord" type='number' id="property-grav-x"></input> <div class="input-area">X <input class="coord" type='number' id="property-grav-x"></input></div>
Y <input class="coord" type='number' id="property-grav-y"></input> <div class="input-area">Y <input class="coord" type='number' id="property-grav-y"></input></div>
Z <input class="coord" type='number' id="property-grav-z"></input> <div class="input-area">Z <input class="coord" type='number' id="property-grav-z"></input></div>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Mass</label> <td class="label">Mass</td>
<span> <td>
<input type='number' id="property-mass"></input> <input type='number' id="property-mass"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Ignore For Collisions</label> <td class="label">Ignore For Collisions</td>
<span> <td>
<input type='checkbox' id="property-ignore-for-collisions"></input> <input type='checkbox' id="property-ignore-for-collisions"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Collisions Will Move</label> <td class="label">Collisions Will Move</td>
<span> <td>
<input type='checkbox' id="property-collisions-will-move"></input> <input type='checkbox' id="property-collisions-will-move"></input>
</span> </td>
</div> <tr>
<div class="property-section"> <tr>
<label>Lifetime</label> <td class="label">Lifetime</td>
<span> <td>
<input type='number' id="property-lifetime"></input> <input type='number' id="property-lifetime"></input>
</span> </td>
</div> <tr>
<div id="box-section" class="multi-property-section"> <tr>
<div class="property-section"> <td class="label">Color</td>
<label>Color</label> <td>
<span> <div class="input-area">Red <input class="coord" type='number' id="property-box-red"></input></div>
Red <input class="coord" type='number' id="property-box-red"></input> <div class="input-area">Green <input class="coord" type='number' id="property-box-green"></input></div>
Green <input class="coord" type='number' id="property-box-green"></input> <div class="input-area">Blue <input class="coord" type='number' id="property-box-blue"></input></div>
Blue <input class="coord" type='number' id="property-box-blue"></input> </td>
</span> <tr>
</div>
</div>
<div id="model-section" class="multi-property-section">
<div class="property-section">
<label>Model URL</label>
<span>
<input type="text" id="property-model-url"></input>
</span>
</div>
<div class="property-section">
<label>Animation URL</label>
<span>
<input type="text" id="property-model-animation-url"></input>
</span>
</div>
<div class="property-section">
<label>Animation Playing</label>
<span>
<input type='checkbox' id="property-model-animation-playing">
</span>
</div>
<div class="property-section">
<label>Animation FPS</label>
<span>
<input class="coord" type='number' id="property-model-animation-fps"></input>
</span>
</div>
<div class="property-section">
<label>Animation Frame</label>
<span>
<input class="coord" type='number' id="property-model-animation-frame"></input>
</span>
</div>
</div>
<div id="text-section" class="multi-property-section"> <tr>
<div class="property-section"> <td class="label">Model URL</td>
<label>Text</label> <td>
<span> <input type="text" id="property-model-url"></input>
<input type="text" id="property-text-text"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Animation URL</td>
<label>Line Height</label> <td>
<span> <input type="text" id="property-model-animation-url"></input>
<input class="coord" type='number' id="property-text-line-height"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Animation Playing</td>
<label>Text Color</label> <td>
<span> <input type='checkbox' id="property-model-animation-playing">
Red <input class="coord" type='number' id="property-text-text-color-red"></input> </td>
Green <input class="coord" type='number' id="property-text-text-color-green"></input> <tr>
Blue <input class="coord" type='number' id="property-text-text-color-blue"></input> <tr>
</span> <td class="label">Animation FPS</td>
</div> <td>
<div class="property-section"> <input class="coord" type='number' id="property-model-animation-fps"></input>
<label>Background Color</label> </td>
<span> <tr>
Red <input class="coord" type='number' id="property-text-background-color-red"></input> <tr>
Green <input class="coord" type='number' id="property-text-background-color-green"></input> <td class="label">Animation Frame</td>
Blue <input class="coord" type='number' id="property-text-background-color-blue"></input> <td>
</span> <input class="coord" type='number' id="property-model-animation-frame"></input>
</div> </td>
</div> <tr>
<tr>
<td class="label">Text</td>
<td>
<input type="text" id="property-text-text"></input>
</td>
<tr>
<tr>
<td class="label">Line Height</td>
<td>
<input class="coord" type='number' id="property-text-line-height"></input>
</td>
<tr>
<tr>
<td class="label">Text Color</td>
<td>
<div class="input-area">Red <input class="coord" type='number' id="property-text-text-color-red"></input></div>
<div class="input-area">Green <input class="coord" type='number' id="property-text-text-color-green"></input></div>
<div class="input-area">Blue <input class="coord" type='number' id="property-text-text-color-blue"></input></div>
</td>
<tr>
<tr>
<td class="label">Background Color</td>
<td>
<div class="input-area">Red <input class="coord" type='number' id="property-text-background-color-red"></input></div>
<div class="input-area">Green <input class="coord" type='number' id="property-text-background-color-green"></input></div>
<div class="input-area">Blue <input class="coord" type='number' id="property-text-background-color-blue"></input></div>
</td>
<tr>
<div id="light-section" class="multi-property-section"> <tr>
<div class="property-section"> <td class="label">Spot Light</td>
<label>Spot Light</label> <td>
<span> <input type='checkbox' id="property-light-spot-light">
<input type='checkbox' id="property-light-spot-light"> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Diffuse</td>
<label>Diffuse</label> <td>
<span> <div class="input-area">Red <input class="coord" type='number' id="property-light-diffuse-red"></input></div>
Red <input class="coord" type='number' id="property-light-diffuse-red"></input> <div class="input-area">Green <input class="coord" type='number' id="property-light-diffuse-green"></input></div>
Green <input class="coord" type='number' id="property-light-diffuse-green"></input> <div class="input-area">Blue <input class="coord" type='number' id="property-light-diffuse-blue"></input></div>
Blue <input class="coord" type='number' id="property-light-diffuse-blue"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Ambient</td>
<label>Ambient</label> <td>
<span> <div class="input-area">Red <input class="coord" type='number' id="property-light-ambient-red"></input></div>
Red <input class="coord" type='number' id="property-light-ambient-red"></input> <div class="input-area">Green <input class="coord" type='number' id="property-light-ambient-green"></input></div>
Green <input class="coord" type='number' id="property-light-ambient-green"></input> <div class="input-area">Blue <input class="coord" type='number' id="property-light-ambient-blue"></input></div>
Blue <input class="coord" type='number' id="property-light-ambient-blue"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Specular</td>
<label>Specular</label> <td>
<span> <div class="input-area">Red <input class="coord" type='number' id="property-light-specular-red"></input></div>
Red <input class="coord" type='number' id="property-light-specular-red"></input> <div class="input-area">Green <input class="coord" type='number' id="property-light-specular-green"></input></div>
Green <input class="coord" type='number' id="property-light-specular-green"></input> <div class="input-area">Blue <input class="coord" type='number' id="property-light-specular-blue"></input></div>
Blue <input class="coord" type='number' id="property-light-specular-blue"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Constant Attenuation</td>
<label>Constant Attenuation</label> <td>
<span> <input class="coord" type='number' id="property-light-constant-attenuation"></input>
<input class="coord" type='number' id="property-light-constant-attenuation"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Linear Attenuation</td>
<label>Linear Attenuation</label> <td>
<span> <input class="coord" type='number' id="property-light-linear-attenuation"></input>
<input class="coord" type='number' id="property-light-linear-attenuation"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Quadratic Attenuation</td>
<label>Quadratic Attenuation</label> <td>
<span> <input class="coord" type='number' id="property-light-quadratic-attenuation"></input>
<input class="coord" type='number' id="property-light-quadratic-attenuation"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Exponent</td>
<label>Exponent</label> <td>
<span> <input class="coord" type='number' id="property-light-exponent"></input>
<input class="coord" type='number' id="property-light-exponent"></input> </td>
</span> <tr>
</div> <tr>
<div class="property-section"> <td class="label">Cutoff (degrees)</td>
<label>Cutoff (degrees)</label> <td>
<span> <input class="coord" type='number' id="property-light-cutoff"></input>
<input class="coord" type='number' id="property-light-cutoff"></input> </td>
</span> <tr>
</div> </table>
</div>
</div>
</body> </body>
</html> </html>

View file

@ -17,15 +17,6 @@ body {
user-select: none; user-select: none;
} }
input {
line-height: 2;
}
.input-left {
display: inline-block;
width: 20px;
}
.color-box { .color-box {
display: inline-block; display: inline-block;
width: 20px; width: 20px;
@ -63,7 +54,6 @@ input {
.property-section label { .property-section label {
font-weight: bold; font-weight: bold;
vertical-align: middle;
} }
.property-section span { .property-section span {
@ -89,9 +79,10 @@ input[type=button] {
font-size: .9em; font-size: .9em;
} }
input.coord { input {
width: 6em; padding: 2px;
height: 2em; border: 1px solid #999;
background-color: #eee;
} }
table#entity-table { table#entity-table {
@ -105,7 +96,7 @@ table#entity-table {
cursor: pointer; cursor: pointer;
} }
tr.selected { #entity-table tr.selected {
background-color: #AAA; background-color: #AAA;
} }
@ -130,3 +121,48 @@ th#entity-type {
th#entity-url { th#entity-url {
} }
div.input-area {
display: inline-block;
}
input {
}
table#properties-table {
border: none;
border-collapse: collapse;
width: 100%;
background-color: #efefef;
font-family: Arial;
font-size: 12px;
table-layout: fixed;
}
#properties-table tr {
border-bottom: 1px solid #e5e5e5;
}
#properties-table td.label {
padding-right: 10px;
border-right: 1px solid #999;
text-align: right;
font-weight: bold;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
height: 1.2em;
}
#properties-table td {
padding: 5px 0px 5px 10px;
}
col#col-label {
width: 130px;
}

45
examples/orbitingSound.js Normal file
View file

@ -0,0 +1,45 @@
//
// orbitingSound.js
// examples
//
// Created by Philip Rosedale on December 4, 2014
// Copyright 2014 High Fidelity, Inc.
//
// An object playing a sound appears and circles you, changing brightness with the audio playing.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var RADIUS = 2.0;
var orbitCenter = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.getOrientation()), RADIUS));
var time = 0;
var SPEED = 1.0;
var currentPosition = { x: 0, y: 0, z: 0 };
var trailingLoudness = 0.0;
var soundClip = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Tabla+Loops/Tabla1.wav");
var properties = {
type: "Box",
position: orbitCenter,
dimensions: { x: 0.25, y: 0.25, z: 0.25 },
color: { red: 100, green: 0, blue : 0 }
};
var objectId = Entities.addEntity(properties);
var sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volume: 0.5 });
function update(deltaTime) {
time += deltaTime;
currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS };
trailingLoudness = 0.9 * trailingLoudness + 0.1 * Audio.getLoudness(sound);
Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } );
Audio.setInjectorOptions(sound, { position: currentPosition });
}
Script.scriptEnding.connect(function() {
Entities.deleteEntity(objectId);
Audio.stopInjector(sound);
});
Script.update.connect(update);

View file

@ -2910,7 +2910,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr
// transform by eye offset // transform by eye offset
// load the view frustum // load the view frustum
loadViewFrustum(whichCamera, _viewFrustum); loadViewFrustum(whichCamera, _displayViewFrustum);
// flip x if in mirror mode (also requires reversing winding order for backface culling) // flip x if in mirror mode (also requires reversing winding order for backface culling)
if (whichCamera.getMode() == CAMERA_MODE_MIRROR) { if (whichCamera.getMode() == CAMERA_MODE_MIRROR) {
@ -3184,7 +3184,7 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
// allow 3DTV/Oculus to override parameters from camera // allow 3DTV/Oculus to override parameters from camera
_viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); _displayViewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
if (OculusManager::isConnected()) { if (OculusManager::isConnected()) {
OculusManager::overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); OculusManager::overrideOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);

View file

@ -196,6 +196,7 @@ public:
const AudioReflector* getAudioReflector() const { return &_audioReflector; } const AudioReflector* getAudioReflector() const { return &_audioReflector; }
Camera* getCamera() { return &_myCamera; } Camera* getCamera() { return &_myCamera; }
ViewFrustum* getViewFrustum() { return &_viewFrustum; } ViewFrustum* getViewFrustum() { return &_viewFrustum; }
ViewFrustum* getDisplayViewFrustum() { return &_displayViewFrustum; }
ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; } ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; }
VoxelImporter* getVoxelImporter() { return &_voxelImporter; } VoxelImporter* getVoxelImporter() { return &_voxelImporter; }
VoxelSystem* getVoxels() { return &_voxels; } VoxelSystem* getVoxels() { return &_voxels; }
@ -517,6 +518,7 @@ private:
ViewFrustum _viewFrustum; // current state of view frustum, perspective, orientation, etc. ViewFrustum _viewFrustum; // current state of view frustum, perspective, orientation, etc.
ViewFrustum _lastQueriedViewFrustum; /// last view frustum used to query octree servers (voxels) ViewFrustum _lastQueriedViewFrustum; /// last view frustum used to query octree servers (voxels)
ViewFrustum _displayViewFrustum;
ViewFrustum _shadowViewFrustum; ViewFrustum _shadowViewFrustum;
quint64 _lastQueriedTime; quint64 _lastQueriedTime;

View file

@ -192,7 +192,7 @@ static const float EIGHT_BIT_MAXIMUM_RECIPROCAL = 1.0f / EIGHT_BIT_MAXIMUM;
void MetavoxelSystem::render() { void MetavoxelSystem::render() {
// update the frustum // update the frustum
ViewFrustum* viewFrustum = Application::getInstance()->getViewFrustum(); ViewFrustum* viewFrustum = Application::getInstance()->getDisplayViewFrustum();
_frustum.set(viewFrustum->getFarTopLeft(), viewFrustum->getFarTopRight(), viewFrustum->getFarBottomLeft(), _frustum.set(viewFrustum->getFarTopLeft(), viewFrustum->getFarTopRight(), viewFrustum->getFarBottomLeft(),
viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(), viewFrustum->getFarBottomRight(), viewFrustum->getNearTopLeft(), viewFrustum->getNearTopRight(),
viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight()); viewFrustum->getNearBottomLeft(), viewFrustum->getNearBottomRight());
@ -1953,7 +1953,7 @@ private:
BufferRenderVisitor::BufferRenderVisitor(const AttributePointer& attribute) : BufferRenderVisitor::BufferRenderVisitor(const AttributePointer& attribute) :
MetavoxelVisitor(QVector<AttributePointer>() << attribute), MetavoxelVisitor(QVector<AttributePointer>() << attribute),
_order(encodeOrder(Application::getInstance()->getViewFrustum()->getDirection())), _order(encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
_containmentDepth(INT_MAX) { _containmentDepth(INT_MAX) {
} }

View file

@ -232,8 +232,8 @@ void DeferredLightingEffect::render() {
// enlarge the scales slightly to account for tesselation // enlarge the scales slightly to account for tesselation
const float SCALE_EXPANSION = 0.05f; const float SCALE_EXPANSION = 0.05f;
const glm::vec3& eyePoint = Application::getInstance()->getViewFrustum()->getPosition(); const glm::vec3& eyePoint = Application::getInstance()->getDisplayViewFrustum()->getPosition();
float nearRadius = glm::distance(eyePoint, Application::getInstance()->getViewFrustum()->getNearTopLeft()); float nearRadius = glm::distance(eyePoint, Application::getInstance()->getDisplayViewFrustum()->getNearTopLeft());
if (!_pointLights.isEmpty()) { if (!_pointLights.isEmpty()) {
_pointLight.bind(); _pointLight.bind();

View file

@ -85,6 +85,13 @@ bool AudioScriptingInterface::isInjectorPlaying(AudioInjector* injector) {
return (injector != NULL); return (injector != NULL);
} }
void AudioScriptingInterface::setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions) {
AudioInjectorOptions optionsCopy = injectorOptions;
if (injector) {
injector->setOptions(optionsCopy);
}
}
float AudioScriptingInterface::getLoudness(AudioInjector* injector) { float AudioScriptingInterface::getLoudness(AudioInjector* injector) {
if (injector) { if (injector) {
return injector->getLoudness(); return injector->getLoudness();

View file

@ -35,6 +35,8 @@ public slots:
void stopInjector(AudioInjector* injector); void stopInjector(AudioInjector* injector);
bool isInjectorPlaying(AudioInjector* injector); bool isInjectorPlaying(AudioInjector* injector);
void setInjectorOptions(AudioInjector* injector, const AudioInjectorOptions& injectorOptions);
void injectorStopped(); void injectorStopped();
signals: signals: