Merge remote-tracking branch 'upstream/master'

This commit is contained in:
James B. Pollack 2015-10-09 10:40:56 -07:00
commit 987f8ad8ad
34 changed files with 513 additions and 180 deletions

View file

@ -39,8 +39,6 @@
const QString ASSIGNMENT_CLIENT_TARGET_NAME = "assignment-client"; const QString ASSIGNMENT_CLIENT_TARGET_NAME = "assignment-client";
const long long ASSIGNMENT_REQUEST_INTERVAL_MSECS = 1 * 1000; const long long ASSIGNMENT_REQUEST_INTERVAL_MSECS = 1 * 1000;
int hifiSockAddrMeta = qRegisterMetaType<HifiSockAddr>("HifiSockAddr");
AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QString assignmentPool, AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QString assignmentPool,
quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname, quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
quint16 assignmentServerPort, quint16 assignmentMonitorPort) : quint16 assignmentServerPort, quint16 assignmentMonitorPort) :

View file

@ -305,15 +305,12 @@
var elParticleSections = document.querySelectorAll(".particle-section"); var elParticleSections = document.querySelectorAll(".particle-section");
allSections.push(elParticleSections); allSections.push(elParticleSections);
var elParticleIsEmitting = document.getElementById("property-particle-is-emitting");
var elParticleMaxParticles = document.getElementById("property-particle-maxparticles"); var elParticleMaxParticles = document.getElementById("property-particle-maxparticles");
var elParticleLifeSpan = document.getElementById("property-particle-lifespan"); var elParticleLifeSpan = document.getElementById("property-particle-lifespan");
var elParticleEmitRate = document.getElementById("property-particle-emit-rate"); var elParticleEmitRate = document.getElementById("property-particle-emit-rate");
var elParticleEmitDirectionX = document.getElementById("property-particle-emit-direction-x");
var elParticleEmitDirectionY = document.getElementById("property-particle-emit-direction-y");
var elParticleEmitDirectionZ = document.getElementById("property-particle-emit-direction-z");
var elParticleEmitStrength = document.getElementById("property-particle-emit-strength");
var elParticleLocalGravity = document.getElementById("property-particle-localgravity");
var elParticleRadius = document.getElementById("property-particle-radius"); var elParticleRadius = document.getElementById("property-particle-radius");
var elParticleTextures = document.getElementById("property-particle-textures");
var elTextSections = document.querySelectorAll(".text-section"); var elTextSections = document.querySelectorAll(".text-section");
allSections.push(elTextSections); allSections.push(elTextSections);
@ -511,7 +508,7 @@
elColorSection.style.display = 'none'; elColorSection.style.display = 'none';
} }
if (properties.type == "Model" || properties.type == "ParticleEffect") { if (properties.type == "Model") {
for (var i = 0; i < elModelSections.length; i++) { for (var i = 0; i < elModelSections.length; i++) {
elModelSections[i].style.display = 'block'; elModelSections[i].style.display = 'block';
} }
@ -529,7 +526,7 @@
elModelAnimationHold.checked = properties.animation.hold; elModelAnimationHold.checked = properties.animation.hold;
elModelAnimationStartAutomatically.checked = properties.animation.startAutomatically; elModelAnimationStartAutomatically.checked = properties.animation.startAutomatically;
elModelTextures.value = properties.textures; elModelTextures.value = properties.textures;
elModelOriginalTextures.value = properties.originalTextures; elModelOriginalTextures.value = properties.originalTextures;
} else if (properties.type == "Web") { } else if (properties.type == "Web") {
for (var i = 0; i < elWebSections.length; i++) { for (var i = 0; i < elWebSections.length; i++) {
elWebSections[i].style.display = 'block'; elWebSections[i].style.display = 'block';
@ -617,15 +614,13 @@
elParticleSections[i].style.display = 'block'; elParticleSections[i].style.display = 'block';
} }
elParticleIsEmitting.checked = properties.isEmitting;
elParticleMaxParticles.value = properties.maxParticles; elParticleMaxParticles.value = properties.maxParticles;
elParticleLifeSpan.value = properties.lifespan.toFixed(2); elParticleLifeSpan.value = properties.lifespan.toFixed(2);
elParticleEmitRate.value = properties.emitRate.toFixed(1); elParticleEmitRate.value = properties.emitRate.toFixed(1);
elParticleEmitDirectionX.value = properties.emitDirection.x.toFixed(2);
elParticleEmitDirectionY.value = properties.emitDirection.y.toFixed(2);
elParticleEmitDirectionZ.value = properties.emitDirection.z.toFixed(2);
elParticleEmitStrength.value = properties.emitStrength.toFixed(2);
elParticleLocalGravity.value = properties.localGravity.toFixed(2);
elParticleRadius.value = properties.particleRadius.toFixed(3); elParticleRadius.value = properties.particleRadius.toFixed(3);
elParticleTextures.value = properties.textures;
} else if (properties.type == "PolyVox") { } else if (properties.type == "PolyVox") {
for (var i = 0; i < elPolyVoxSections.length; i++) { for (var i = 0; i < elPolyVoxSections.length; i++) {
elPolyVoxSections[i].style.display = 'block'; elPolyVoxSections[i].style.display = 'block';
@ -758,17 +753,12 @@
elWebSourceURL.addEventListener('change', createEmitTextPropertyUpdateFunction('sourceUrl')); elWebSourceURL.addEventListener('change', createEmitTextPropertyUpdateFunction('sourceUrl'));
elParticleIsEmitting.addEventListener('change', createEmitCheckedPropertyUpdateFunction('isEmitting'));
elParticleMaxParticles.addEventListener('change', createEmitNumberPropertyUpdateFunction('maxParticles')); elParticleMaxParticles.addEventListener('change', createEmitNumberPropertyUpdateFunction('maxParticles'));
elParticleLifeSpan.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifespan')); elParticleLifeSpan.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifespan'));
elParticleEmitRate.addEventListener('change', createEmitNumberPropertyUpdateFunction('emitRate')); elParticleEmitRate.addEventListener('change', createEmitNumberPropertyUpdateFunction('emitRate'));
var particleEmitDirectionChangeFunction = createEmitVec3PropertyUpdateFunctionWithMultiplier(
'emitDirection', elParticleEmitDirectionX, elParticleEmitDirectionY, elParticleEmitDirectionZ, DEGREES_TO_RADIANS);
elParticleEmitDirectionX.addEventListener('change', particleEmitDirectionChangeFunction);
elParticleEmitDirectionY.addEventListener('change', particleEmitDirectionChangeFunction);
elParticleEmitDirectionZ.addEventListener('change', particleEmitDirectionChangeFunction);
elParticleEmitStrength.addEventListener('change', createEmitNumberPropertyUpdateFunction('emitStrength'));
elParticleLocalGravity.addEventListener('change', createEmitNumberPropertyUpdateFunction('localGravity'));
elParticleRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('particleRadius')); elParticleRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('particleRadius'));
elParticleTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures'));
elModelURL.addEventListener('change', createEmitTextPropertyUpdateFunction('modelURL')); elModelURL.addEventListener('change', createEmitTextPropertyUpdateFunction('modelURL'));
elShapeType.addEventListener('change', createEmitTextPropertyUpdateFunction('shapeType')); elShapeType.addEventListener('change', createEmitTextPropertyUpdateFunction('shapeType'));
@ -1335,13 +1325,13 @@
<div class="model-section property"> <div class="model-section property">
<div class="label">Textures</div> <div class="label">Textures</div>
<div class="value"> <div class="value">
<textarea id="property-model-textures" value='asdfasdf'></textarea> <textarea id="property-model-textures" value=''></textarea>
</div> </div>
</div> </div>
<div class="model-section property"> <div class="model-section property">
<div class="label">Original Textures</div> <div class="label">Original Textures</div>
<div class="value"> <div class="value">
<textarea id="property-model-original-textures" readonly value='asdfasdf'></textarea> <textarea id="property-model-original-textures" readonly value=''></textarea>
</div> </div>
</div> </div>
@ -1362,6 +1352,12 @@
<label>Particle</label> <label>Particle</label>
</div> </div>
<div class="particle-section property">
<span class="label">Is Emitting</span>
<span class="value">
<input type='checkbox' id="property-particle-is-emitting">
</span>
</div>
<div class="particle-section property"> <div class="particle-section property">
<div class="label">Max Particles</div> <div class="label">Max Particles</div>
<div class="value"> <div class="value">
@ -1380,30 +1376,16 @@
<input type='number' id="property-particle-emit-rate" min="0" step="0.5"> <input type='number' id="property-particle-emit-rate" min="0" step="0.5">
</div> </div>
</div> </div>
<div class="particle-section property">
<div class="label">Particle Emission Direction</div>
<div class="value">
<div class="input-area">X <input class="coord" type='number' id="property-particle-emit-direction-x"></div>
<div class="input-area">Y <input class="coord" type='number' id="property-particle-emit-direction-y"></div>
<div class="input-area">Z <input class="coord" type='number' id="property-particle-emit-direction-z"></div>
</div>
</div>
<div class="particle-section property">
<div class="label">Particle Emission Strength</div>
<div class="value">
<input type='number' id="property-particle-emit-strength" min="0" step="0.1">
</div>
</div>
<div class="particle-section property">
<div class="label">Particle Local Gravity</div>
<div class="value">
<input class="coord" type='number' id="property-particle-localgravity" step="0.05">
</div>
</div>
<div class="particle-section property"> <div class="particle-section property">
<div class="label">Particle Radius</div> <div class="label">Particle Radius</div>
<div class="value"> <div class="value">
<input class="coord" type='number' id="property-particle-radius" min="0" step="0.005"> <input class="coord" type='number' id="property-particle-radius" min="0" step="0.005">
</div>
</div>
<div class="particle-section property">
<div class="label">Textures</div>
<div class="value">
<textarea id="property-particle-textures" value=''></textarea>
</div> </div>
</div> </div>

View file

@ -13,8 +13,8 @@ Script.include("../../utilities.js");
var scriptURL = Script.resolvePath('pingPongGun.js'); var scriptURL = Script.resolvePath('pingPongGun.js');
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun.fbx?123' var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun.fbx'
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun_collision_hull.obj?123'; var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun_collision_hull.obj';
var center = Vec3.sum(Vec3.sum(MyAvatar.position, { var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0, x: 0,

View file

@ -0,0 +1,154 @@
// createTargets.js
//
// Script Type: Entity Spawner
// Created by James B. Pollack on 9/30/2015
// Copyright 2015 High Fidelity, Inc.
//
// This script creates targets that fall down when you shoot them and then automatically reset to their original position.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */
Script.include("../../utilities.js");
Script.include("../../libraries/utils.js");
var scriptURL = Script.resolvePath('wallTarget.js');
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,
});
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: scriptURL
};
targets.push(Entities.addEntity(targetProperties));
}
}
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: scriptURL
};
targets[index] = Entities.addEntity(targetProperties);
}
});
}
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 atEnd() {
Script.clearInterval(distanceCheckInterval);
deleteTargets();
}
Script.scriptEnding.connect(atEnd);

View file

@ -14,6 +14,7 @@
Script.include("../../libraries/utils.js"); Script.include("../../libraries/utils.js");
var SHOOTING_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/ping_pong_gun/pong_sound.wav'; var SHOOTING_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/ping_pong_gun/pong_sound.wav';
var PING_PONG_BALL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_ball.fbx';
function PingPongGun() { function PingPongGun() {
return; return;
@ -23,7 +24,7 @@
var RELOAD_THRESHOLD = 0.95; var RELOAD_THRESHOLD = 0.95;
var GUN_TIP_FWD_OFFSET =-0.35; var GUN_TIP_FWD_OFFSET =-0.35;
var GUN_TIP_UP_OFFSET = 0.040; var GUN_TIP_UP_OFFSET = 0.040;
var GUN_FORCE = 9; var GUN_FORCE = 5;
var BALL_RESTITUTION = 0.6; var BALL_RESTITUTION = 0.6;
var BALL_LINEAR_DAMPING = 0.4; var BALL_LINEAR_DAMPING = 0.4;
var BALL_GRAVITY = { var BALL_GRAVITY = {
@ -115,7 +116,10 @@
forwardVec = Vec3.multiply(forwardVec, GUN_FORCE); forwardVec = Vec3.multiply(forwardVec, GUN_FORCE);
var properties = { var properties = {
type: 'Sphere', // type: 'Model',
// modelURL:PING_PONG_BALL_URL,
shapeType:'sphere',
type:'Sphere',
color: BALL_COLOR, color: BALL_COLOR,
dimensions: BALL_DIMENSIONS, dimensions: BALL_DIMENSIONS,
linearDamping: BALL_LINEAR_DAMPING, linearDamping: BALL_LINEAR_DAMPING,

View file

@ -0,0 +1,56 @@
// wallTarget.js
//
// Script Type: Entity
// Created by James B. Pollack @imgntn on 9/21/2015
// Copyright 2015 High Fidelity, Inc.
//
// This script resets an object to its original position when it stops moving after a collision
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */
(function() {
function Target() {
return;
}
Target.prototype = {
hasPlayedSound: false,
preload: function(entityID) {
this.entityID = entityID;
var SOUND_URL = "http://hifi-public.s3.amazonaws.com/sounds/Clay_Pigeon_02.L.wav";
this.hitSound = SoundCache.getSound(SOUND_URL);
},
collisionWithEntity: function(me, otherEntity) {
var position = Entities.getEntityProperties(me, "position").position;
Entities.editEntity(me, {
gravity: {
x: 0,
y: -9.8,
z: 0
},
velocity: {
x: 0,
y: -0.01,
z: 0
}
});
if (this.hasPlayedSound === false) {
this.audioInjector = Audio.playSound(this.hitSound, {
position: position,
volume: 0.5
});
this.hasPlayedSound = true;
}
}
};
// entity scripts always need to return a newly constructed object of our type
return new Target();
});

View file

@ -215,7 +215,7 @@ bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) c
} }
bool JointState::translationIsDefault(const glm::vec3& translation, float tolerance) const { bool JointState::translationIsDefault(const glm::vec3& translation, float tolerance) const {
return glm::distance(_defaultTranslation * _unitsScale, translation * _unitsScale) < tolerance; return glm::distance(_defaultTranslation * _unitsScale, translation) < tolerance;
} }
glm::quat JointState::getDefaultRotationInParentFrame() const { glm::quat JointState::getDefaultRotationInParentFrame() const {

View file

@ -287,6 +287,7 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll) {
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
int rotationSentCount = 0; int rotationSentCount = 0;
unsigned char* beforeRotations = destinationBuffer;
#endif #endif
_lastSentJointData.resize(_jointData.size()); _lastSentJointData.resize(_jointData.size());
@ -335,6 +336,7 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll) {
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
int translationSentCount = 0; int translationSentCount = 0;
unsigned char* beforeTranslations = destinationBuffer;
#endif #endif
float maxTranslationDimension = 0.0; float maxTranslationDimension = 0.0;
@ -387,10 +389,15 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll) {
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
if (sendAll) { if (sendAll) {
qDebug() << "SENDING -- rotations:" << rotationSentCount << "translations:" << translationSentCount qDebug() << "AvatarData::toByteArray" << cullSmallChanges << sendAll
<< "rotations:" << rotationSentCount << "translations:" << translationSentCount
<< "largest:" << maxTranslationDimension << "largest:" << maxTranslationDimension
<< "radix:" << translationCompressionRadix << "radix:" << translationCompressionRadix
<< "size:" << (int)(destinationBuffer - startPosition); << "size:"
<< (beforeRotations - startPosition) << "+"
<< (beforeTranslations - beforeRotations) << "+"
<< (destinationBuffer - beforeTranslations) << "="
<< (destinationBuffer - startPosition);
} }
#endif #endif
@ -409,7 +416,8 @@ void AvatarData::doneEncoding(bool cullSmallChanges) {
_lastSentJointData[i].rotation = data.rotation; _lastSentJointData[i].rotation = data.rotation;
} }
} }
}
if (_lastSentJointData[i].translation != data.translation) {
if (!cullSmallChanges || if (!cullSmallChanges ||
glm::distance(data.translation, _lastSentJointData[i].translation) > AVATAR_MIN_TRANSLATION) { glm::distance(data.translation, _lastSentJointData[i].translation) > AVATAR_MIN_TRANSLATION) {
if (data.translationSet) { if (data.translationSet) {

View file

@ -313,6 +313,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
CHECK_PROPERTY_CHANGE(PROP_TEXT_COLOR, textColor); CHECK_PROPERTY_CHANGE(PROP_TEXT_COLOR, textColor);
CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_COLOR, backgroundColor); CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_COLOR, backgroundColor);
CHECK_PROPERTY_CHANGE(PROP_SHAPE_TYPE, shapeType); CHECK_PROPERTY_CHANGE(PROP_SHAPE_TYPE, shapeType);
CHECK_PROPERTY_CHANGE(PROP_EMITTING_PARTICLES, isEmitting);
CHECK_PROPERTY_CHANGE(PROP_MAX_PARTICLES, maxParticles); CHECK_PROPERTY_CHANGE(PROP_MAX_PARTICLES, maxParticles);
CHECK_PROPERTY_CHANGE(PROP_LIFESPAN, lifespan); CHECK_PROPERTY_CHANGE(PROP_LIFESPAN, lifespan);
CHECK_PROPERTY_CHANGE(PROP_EMIT_RATE, emitRate); CHECK_PROPERTY_CHANGE(PROP_EMIT_RATE, emitRate);
@ -424,6 +425,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
// Particles only // Particles only
if (_type == EntityTypes::ParticleEffect) { if (_type == EntityTypes::ParticleEffect) {
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_EMITTING_PARTICLES, isEmitting);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MAX_PARTICLES, maxParticles); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MAX_PARTICLES, maxParticles);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LIFESPAN, lifespan); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_LIFESPAN, lifespan);
COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_EMIT_RATE, emitRate); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_EMIT_RATE, emitRate);
@ -1118,6 +1120,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
APPEND_ENTITY_PROPERTY(PROP_ACTION_DATA, properties.getActionData()); APPEND_ENTITY_PROPERTY(PROP_ACTION_DATA, properties.getActionData());
APPEND_ENTITY_PROPERTY(PROP_ALPHA, properties.getAlpha()); APPEND_ENTITY_PROPERTY(PROP_ALPHA, properties.getAlpha());
} }
if (propertyCount > 0) { if (propertyCount > 0) {
int endOfEntityItemData = packetData->getUncompressedByteOffset(); int endOfEntityItemData = packetData->getUncompressedByteOffset();
@ -1472,6 +1475,7 @@ void EntityItemProperties::markAllChanged() {
_backgroundColorChanged = true; _backgroundColorChanged = true;
_shapeTypeChanged = true; _shapeTypeChanged = true;
_isEmittingChanged = true;
_maxParticlesChanged = true; _maxParticlesChanged = true;
_lifespanChanged = true; _lifespanChanged = true;
_emitRateChanged = true; _emitRateChanged = true;

View file

@ -329,7 +329,7 @@ EntityItemProperties ParticleEffectEntityItem::getProperties(EntityPropertyFlags
COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(alpha, getAlpha); COPY_ENTITY_PROPERTY_TO_PROPERTIES(alpha, getAlpha);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(glowLevel, getGlowLevel); COPY_ENTITY_PROPERTY_TO_PROPERTIES(glowLevel, getGlowLevel);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType); COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType); // FIXME - this doesn't appear to get used
COPY_ENTITY_PROPERTY_TO_PROPERTIES(maxParticles, getMaxParticles); COPY_ENTITY_PROPERTY_TO_PROPERTIES(maxParticles, getMaxParticles);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(lifespan, getLifespan); COPY_ENTITY_PROPERTY_TO_PROPERTIES(lifespan, getLifespan);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(isEmitting, getIsEmitting); COPY_ENTITY_PROPERTY_TO_PROPERTIES(isEmitting, getIsEmitting);

View file

@ -1512,7 +1512,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
} }
extracted.mesh.isEye = (maxJointIndex == geometry.leftEyeJointIndex || maxJointIndex == geometry.rightEyeJointIndex); extracted.mesh.isEye = (maxJointIndex == geometry.leftEyeJointIndex || maxJointIndex == geometry.rightEyeJointIndex);
buildModelMesh(extracted, url); buildModelMesh(extracted.mesh, url);
if (extracted.mesh.isEye) { if (extracted.mesh.isEye) {
if (maxJointIndex == geometry.leftEyeJointIndex) { if (maxJointIndex == geometry.leftEyeJointIndex) {

View file

@ -388,7 +388,7 @@ public:
ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex); ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex);
QHash<QString, ExtractedMesh> meshes; QHash<QString, ExtractedMesh> meshes;
void buildModelMesh(ExtractedMesh& extracted, const QString& url); static void buildModelMesh(FBXMesh& extractedMesh, const QString& url);
FBXTexture getTexture(const QString& textureID); FBXTexture getTexture(const QString& textureID);

View file

@ -386,11 +386,11 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn
return data.extracted; return data.extracted;
} }
void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) { void FBXReader::buildModelMesh(FBXMesh& extractedMesh, const QString& url) {
static QString repeatedMessage = LogHandler::getInstance().addRepeatedMessageRegex("buildModelMesh failed -- .*"); static QString repeatedMessage = LogHandler::getInstance().addRepeatedMessageRegex("buildModelMesh failed -- .*");
unsigned int totalSourceIndices = 0; unsigned int totalSourceIndices = 0;
foreach(const FBXMeshPart& part, extracted.mesh.parts) { foreach(const FBXMeshPart& part, extractedMesh.parts) {
totalSourceIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size()); totalSourceIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size());
} }
@ -399,18 +399,18 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) {
return; return;
} }
if (extracted.mesh.vertices.size() == 0) { if (extractedMesh.vertices.size() == 0) {
qCDebug(modelformat) << "buildModelMesh failed -- no vertices, url = " << url; qCDebug(modelformat) << "buildModelMesh failed -- no vertices, url = " << url;
return; return;
} }
FBXMesh& fbxMesh = extracted.mesh; FBXMesh& fbxMesh = extractedMesh;
model::MeshPointer mesh(new model::Mesh()); model::MeshPointer mesh(new model::Mesh());
// Grab the vertices in a buffer // Grab the vertices in a buffer
auto vb = std::make_shared<gpu::Buffer>(); auto vb = std::make_shared<gpu::Buffer>();
vb->setData(extracted.mesh.vertices.size() * sizeof(glm::vec3), vb->setData(extractedMesh.vertices.size() * sizeof(glm::vec3),
(const gpu::Byte*) extracted.mesh.vertices.data()); (const gpu::Byte*) extractedMesh.vertices.data());
gpu::BufferView vbv(vb, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ)); gpu::BufferView vbv(vb, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ));
mesh->setVertexBuffer(vbv); mesh->setVertexBuffer(vbv);
@ -486,7 +486,7 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) {
unsigned int totalIndices = 0; unsigned int totalIndices = 0;
foreach(const FBXMeshPart& part, extracted.mesh.parts) { foreach(const FBXMeshPart& part, extractedMesh.parts) {
totalIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size()); totalIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size());
} }
@ -502,10 +502,10 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) {
int offset = 0; int offset = 0;
std::vector< model::Mesh::Part > parts; std::vector< model::Mesh::Part > parts;
if (extracted.mesh.parts.size() > 1) { if (extractedMesh.parts.size() > 1) {
indexNum = 0; indexNum = 0;
} }
foreach(const FBXMeshPart& part, extracted.mesh.parts) { foreach(const FBXMeshPart& part, extractedMesh.parts) {
model::Mesh::Part modelPart(indexNum, 0, 0, model::Mesh::TRIANGLES); model::Mesh::Part modelPart(indexNum, 0, 0, model::Mesh::TRIANGLES);
if (part.quadTrianglesIndices.size()) { if (part.quadTrianglesIndices.size()) {
@ -545,5 +545,5 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) {
// model::Box box = // model::Box box =
mesh->evalPartBound(0); mesh->evalPartBound(0);
extracted.mesh._mesh = mesh; extractedMesh._mesh = mesh;
} }

View file

@ -532,6 +532,8 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
mesh.meshExtents.addPoint(vertex); mesh.meshExtents.addPoint(vertex);
geometry.meshExtents.addPoint(vertex); geometry.meshExtents.addPoint(vertex);
} }
FBXReader::buildModelMesh(mesh, url.toString());
// fbxDebugDump(geometry); // fbxDebugDump(geometry);
} catch(const std::exception& e) { } catch(const std::exception& e) {
qCDebug(modelformat) << "OBJ reader fail: " << e.what(); qCDebug(modelformat) << "OBJ reader fail: " << e.what();

View file

@ -205,6 +205,13 @@ void Batch::setViewportTransform(const Vec4i& viewport) {
_params.push_back(cacheData(sizeof(Vec4i), &viewport)); _params.push_back(cacheData(sizeof(Vec4i), &viewport));
} }
void Batch::setDepthRangeTransform(float nearDepth, float farDepth) {
ADD_COMMAND(setDepthRangeTransform);
_params.push_back(farDepth);
_params.push_back(nearDepth);
}
void Batch::setPipeline(const PipelinePointer& pipeline) { void Batch::setPipeline(const PipelinePointer& pipeline) {
ADD_COMMAND(setPipeline); ADD_COMMAND(setPipeline);

View file

@ -187,6 +187,7 @@ public:
void setProjectionTransform(const Mat4& proj); void setProjectionTransform(const Mat4& proj);
// Viewport is xy = low left corner in framebuffer, zw = width height of the viewport, expressed in pixels // Viewport is xy = low left corner in framebuffer, zw = width height of the viewport, expressed in pixels
void setViewportTransform(const Vec4i& viewport); void setViewportTransform(const Vec4i& viewport);
void setDepthRangeTransform(float nearDepth, float farDepth);
// Pipeline Stage // Pipeline Stage
void setPipeline(const PipelinePointer& pipeline); void setPipeline(const PipelinePointer& pipeline);
@ -285,6 +286,7 @@ public:
COMMAND_setViewTransform, COMMAND_setViewTransform,
COMMAND_setProjectionTransform, COMMAND_setProjectionTransform,
COMMAND_setViewportTransform, COMMAND_setViewportTransform,
COMMAND_setDepthRangeTransform,
COMMAND_setPipeline, COMMAND_setPipeline,
COMMAND_setStateBlendFactor, COMMAND_setStateBlendFactor,

View file

@ -14,11 +14,12 @@
out vec2 varTexCoord0; out vec2 varTexCoord0;
void main(void) { void main(void) {
const float depth = 1.0;
const vec4 UNIT_QUAD[4] = vec4[4]( const vec4 UNIT_QUAD[4] = vec4[4](
vec4(-1.0, -1.0, 0.0, 1.0), vec4(-1.0, -1.0, depth, 1.0),
vec4(1.0, -1.0, 0.0, 1.0), vec4(1.0, -1.0, depth, 1.0),
vec4(-1.0, 1.0, 0.0, 1.0), vec4(-1.0, 1.0, depth, 1.0),
vec4(1.0, 1.0, 0.0, 1.0) vec4(1.0, 1.0, depth, 1.0)
); );
vec4 pos = UNIT_QUAD[gl_VertexID]; vec4 pos = UNIT_QUAD[gl_VertexID];

View file

@ -35,6 +35,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
(&::gpu::GLBackend::do_setViewTransform), (&::gpu::GLBackend::do_setViewTransform),
(&::gpu::GLBackend::do_setProjectionTransform), (&::gpu::GLBackend::do_setProjectionTransform),
(&::gpu::GLBackend::do_setViewportTransform), (&::gpu::GLBackend::do_setViewportTransform),
(&::gpu::GLBackend::do_setDepthRangeTransform),
(&::gpu::GLBackend::do_setPipeline), (&::gpu::GLBackend::do_setPipeline),
(&::gpu::GLBackend::do_setStateBlendFactor), (&::gpu::GLBackend::do_setStateBlendFactor),

View file

@ -314,6 +314,7 @@ protected:
void do_setViewTransform(Batch& batch, uint32 paramOffset); void do_setViewTransform(Batch& batch, uint32 paramOffset);
void do_setProjectionTransform(Batch& batch, uint32 paramOffset); void do_setProjectionTransform(Batch& batch, uint32 paramOffset);
void do_setViewportTransform(Batch& batch, uint32 paramOffset); void do_setViewportTransform(Batch& batch, uint32 paramOffset);
void do_setDepthRangeTransform(Batch& batch, uint32 paramOffset);
void initTransform(); void initTransform();
void killTransform(); void killTransform();
@ -339,6 +340,7 @@ protected:
Transform _view; Transform _view;
Mat4 _projection; Mat4 _projection;
Vec4i _viewport{ 0, 0, 1, 1 }; Vec4i _viewport{ 0, 0, 1, 1 };
Vec2 _depthRange{ 0.0f, 1.0f };
bool _invalidModel{true}; bool _invalidModel{true};
bool _invalidView{false}; bool _invalidView{false};
bool _invalidProj{false}; bool _invalidProj{false};

View file

@ -45,10 +45,21 @@ void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) {
glViewport(vp.x, vp.y, vp.z, vp.w); glViewport(vp.x, vp.y, vp.z, vp.w);
// The Viewport is tagged invalid because the CameraTransformUBO is not up to date and willl need update on next drawcall // The Viewport is tagged invalid because the CameraTransformUBO is not up to date and will need update on next drawcall
_transform._invalidViewport = true; _transform._invalidViewport = true;
} }
void GLBackend::do_setDepthRangeTransform(Batch& batch, uint32 paramOffset) {
Vec2 depthRange(batch._params[paramOffset + 0]._float, batch._params[paramOffset + 1]._float);
if ((depthRange.x != _transform._depthRange.x) || (depthRange.y != _transform._depthRange.y)) {
_transform._depthRange = depthRange;
glDepthRangef(depthRange.x, depthRange.y);
}
}
void GLBackend::initTransform() { void GLBackend::initTransform() {
glGenBuffers(1, &_transform._objectBuffer); glGenBuffers(1, &_transform._objectBuffer);
glGenBuffers(1, &_transform._cameraBuffer); glGenBuffers(1, &_transform._cameraBuffer);
@ -75,6 +86,8 @@ void GLBackend::syncTransformStateCache() {
glGetIntegerv(GL_VIEWPORT, (GLint*) &_transform._viewport); glGetIntegerv(GL_VIEWPORT, (GLint*) &_transform._viewport);
glGetFloatv(GL_DEPTH_RANGE, (GLfloat*)&_transform._depthRange);
Mat4 modelView; Mat4 modelView;
auto modelViewInv = glm::inverse(modelView); auto modelViewInv = glm::inverse(modelView);
_transform._view.evalFromRawMatrix(modelViewInv); _transform._view.evalFromRawMatrix(modelViewInv);

View file

@ -16,7 +16,7 @@
#include "HifiSockAddr.h" #include "HifiSockAddr.h"
#include "NetworkLogging.h" #include "NetworkLogging.h"
static int hifiSockAddrMetaTypeId = qMetaTypeId<HifiSockAddr>(); static int hifiSockAddrMetaTypeId = qRegisterMetaType<HifiSockAddr>();
HifiSockAddr::HifiSockAddr() : HifiSockAddr::HifiSockAddr() :
_address(), _address(),

View file

@ -94,6 +94,6 @@ namespace std {
QHostAddress getLocalAddress(); QHostAddress getLocalAddress();
Q_DECLARE_METATYPE(HifiSockAddr) Q_DECLARE_METATYPE(HifiSockAddr);
#endif // hifi_HifiSockAddr_h #endif // hifi_HifiSockAddr_h

View file

@ -501,7 +501,7 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
LimitedNodeList::flagTimeForConnectionStep(LimitedNodeList::AddedAudioMixer); LimitedNodeList::flagTimeForConnectionStep(LimitedNodeList::AddedAudioMixer);
} }
SharedNodePointer newNodePointer(newNode); SharedNodePointer newNodePointer(newNode, &QObject::deleteLater);
_nodeHash.insert(UUIDNodePair(newNode->getUUID(), newNodePointer)); _nodeHash.insert(UUIDNodePair(newNode->getUUID(), newNodePointer));

View file

@ -60,8 +60,6 @@ const QHostAddress DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME = QHostAddress::Lo
const QString USERNAME_UUID_REPLACEMENT_STATS_KEY = "$username"; const QString USERNAME_UUID_REPLACEMENT_STATS_KEY = "$username";
class HifiSockAddr;
using namespace tbb; using namespace tbb;
typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair; typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair;
typedef concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash; typedef concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash;

View file

@ -150,6 +150,8 @@ void PacketList::preparePackets(MessageNumber messageNumber) {
} }
} }
const qint64 PACKET_LIST_WRITE_ERROR = -1;
qint64 PacketList::writeData(const char* data, qint64 maxSize) { qint64 PacketList::writeData(const char* data, qint64 maxSize) {
auto sizeRemaining = maxSize; auto sizeRemaining = maxSize;
@ -176,26 +178,41 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
// We need to try and pull the first part of the segment out to our new packet // We need to try and pull the first part of the segment out to our new packet
// check now to see if this is an unsupported write // check now to see if this is an unsupported write
int numBytesToEnd = _currentPacket->bytesAvailableForWrite(); int segmentSize = _currentPacket->pos() - _segmentStartIndex;
if ((newPacket->size() - numBytesToEnd) < sizeRemaining) { if (segmentSize + sizeRemaining > newPacket->getPayloadCapacity()) {
// this is an unsupported case - the segment is bigger than the size of an individual packet // this is an unsupported case - the segment is bigger than the size of an individual packet
// but the PacketList is not going to be sent ordered // but the PacketList is not going to be sent ordered
qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is" qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is"
<< "larger than the payload size."; << "larger than the payload size.";
Q_ASSERT(false); Q_ASSERT(false);
// we won't be writing this new data to the packet
// go back before the current segment and return -1 to indicate error
_currentPacket->seek(_segmentStartIndex);
_currentPacket->setPayloadSize(_segmentStartIndex);
return PACKET_LIST_WRITE_ERROR;
} else {
// copy from currentPacket where the segment started to the beginning of the newPacket
newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize);
// shrink the current payload to the actual size of the packet
_currentPacket->setPayloadSize(_segmentStartIndex);
// the current segment now starts at the beginning of the new packet
_segmentStartIndex = _extendedHeader.size();
} }
}
int segmentSize = _currentPacket->pos() - _segmentStartIndex;
if (sizeRemaining > newPacket->getPayloadCapacity()) {
// copy from currentPacket where the segment started to the beginning of the newPacket // this is an unsupported case - attempting to write a block of data larger
newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize); // than the capacity of a new packet in an unordered PacketList
qDebug() << "Error in PacketList::writeData - attempted to write data to an unordered packet that is"
// the current segment now starts at the beginning of the new packet << "larger than the payload size.";
_segmentStartIndex = _extendedHeader.size(); Q_ASSERT(false);
// shrink the current payload to the actual size of the packet return PACKET_LIST_WRITE_ERROR;
_currentPacket->setPayloadSize(_segmentStartIndex);
} }
// move the current packet to our list of packets // move the current packet to our list of packets

View file

@ -355,11 +355,12 @@ bool SendQueue::maybeResendPacket() {
// we found the packet - grab it // we found the packet - grab it
auto& resendPacket = *(it->second); auto& resendPacket = *(it->second);
// send it off
sendPacket(resendPacket);
// unlock the sent packets // unlock the sent packets
sentLocker.unlock(); sentLocker.unlock();
// send it off
sendPacket(resendPacket);
emit packetRetransmitted(); emit packetRetransmitted();
// Signal that we did resend a packet // Signal that we did resend a packet

View file

@ -31,8 +31,8 @@ Socket::Socket(QObject* parent) :
QObject(parent), QObject(parent),
_synTimer(new QTimer(this)) _synTimer(new QTimer(this))
{ {
qRegisterMetaType<Packet*>(); qRegisterMetaType<Packet*>("Packet*");
qRegisterMetaType<PacketList*>(); qRegisterMetaType<PacketList*>("PacketList*");
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams); connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);

View file

@ -35,9 +35,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) {
_frameBufferSize = frameBufferSize; _frameBufferSize = frameBufferSize;
_primaryFramebufferFull.reset(); _primaryFramebufferFull.reset();
_primaryFramebufferDepthColor.reset(); _primaryFramebufferDepthColor.reset();
_primaryFramebufferStencilColor.reset();
_primaryDepthTexture.reset(); _primaryDepthTexture.reset();
_primaryStencilTexture.reset();
_primaryColorTexture.reset(); _primaryColorTexture.reset();
_primaryNormalTexture.reset(); _primaryNormalTexture.reset();
_primarySpecularTexture.reset(); _primarySpecularTexture.reset();
@ -49,7 +47,6 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) {
void FramebufferCache::createPrimaryFramebuffer() { void FramebufferCache::createPrimaryFramebuffer() {
_primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create());
_primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create());
_primaryFramebufferStencilColor = gpu::FramebufferPointer(gpu::Framebuffer::create());
auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
auto width = _frameBufferSize.width(); auto width = _frameBufferSize.width();
@ -66,20 +63,14 @@ void FramebufferCache::createPrimaryFramebuffer() {
_primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture); _primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture);
_primaryFramebufferStencilColor->setRenderBuffer(0, _primaryColorTexture); // auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH);
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH);
_primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler));
auto stencilFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format
_primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler));
_primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
_primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat);
_selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler));
_selfieFramebuffer->setRenderBuffer(0, tex); _selfieFramebuffer->setRenderBuffer(0, tex);
@ -99,13 +90,6 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() {
return _primaryFramebufferDepthColor; return _primaryFramebufferDepthColor;
} }
gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferStencilColor() {
if (!_primaryFramebufferStencilColor) {
createPrimaryFramebuffer();
}
return _primaryFramebufferStencilColor;
}
gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() {
if (!_primaryDepthTexture) { if (!_primaryDepthTexture) {
createPrimaryFramebuffer(); createPrimaryFramebuffer();
@ -113,13 +97,6 @@ gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() {
return _primaryDepthTexture; return _primaryDepthTexture;
} }
gpu::TexturePointer FramebufferCache::getPrimaryStencilTexture() {
if (!_primaryStencilTexture) {
createPrimaryFramebuffer();
}
return _primaryStencilTexture;
}
gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() {
if (!_primaryColorTexture) { if (!_primaryColorTexture) {
createPrimaryFramebuffer(); createPrimaryFramebuffer();

View file

@ -31,10 +31,8 @@ public:
/// used for scene rendering. /// used for scene rendering.
gpu::FramebufferPointer getPrimaryFramebuffer(); gpu::FramebufferPointer getPrimaryFramebuffer();
gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); gpu::FramebufferPointer getPrimaryFramebufferDepthColor();
gpu::FramebufferPointer getPrimaryFramebufferStencilColor();
gpu::TexturePointer getPrimaryDepthTexture(); gpu::TexturePointer getPrimaryDepthTexture();
gpu::TexturePointer getPrimaryStencilTexture();
gpu::TexturePointer getPrimaryColorTexture(); gpu::TexturePointer getPrimaryColorTexture();
gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimaryNormalTexture();
gpu::TexturePointer getPrimarySpecularTexture(); gpu::TexturePointer getPrimarySpecularTexture();
@ -60,9 +58,8 @@ private:
gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferFull;
gpu::FramebufferPointer _primaryFramebufferDepthColor; gpu::FramebufferPointer _primaryFramebufferDepthColor;
gpu::FramebufferPointer _primaryFramebufferStencilColor;
gpu::TexturePointer _primaryDepthTexture; gpu::TexturePointer _primaryDepthTexture;
gpu::TexturePointer _primaryStencilTexture;
gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryColorTexture;
gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primaryNormalTexture;
gpu::TexturePointer _primarySpecularTexture; gpu::TexturePointer _primarySpecularTexture;

View file

@ -37,22 +37,17 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon
RenderArgs* args = renderContext->args; RenderArgs* args = renderContext->args;
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
auto primaryFboStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferStencilColor();
auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor(); auto primaryFbo = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
batch.enableStereo(false); batch.enableStereo(false);
batch.setViewportTransform(args->_viewport); batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport); batch.setStateScissorRect(args->_viewport);
batch.setFramebuffer(primaryFboStencil);
batch.clearFramebuffer(
gpu::Framebuffer::BUFFER_STENCIL,
vec4(vec3(0), 1), 1.0, 0.0, true);
batch.setFramebuffer(primaryFbo); batch.setFramebuffer(primaryFbo);
batch.clearFramebuffer( batch.clearFramebuffer(
gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_COLOR0 |
gpu::Framebuffer::BUFFER_DEPTH, gpu::Framebuffer::BUFFER_DEPTH |
gpu::Framebuffer::BUFFER_STENCIL,
vec4(vec3(0), 1), 1.0, 0.0, true); vec4(vec3(0), 1), 1.0, 0.0, true);
}); });
} }
@ -313,7 +308,8 @@ const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() {
gpu::Shader::makeProgram((*program)); gpu::Shader::makeProgram((*program));
auto state = std::make_shared<gpu::State>(); auto state = std::make_shared<gpu::State>();
state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); state->setDepthTest(true, false, gpu::LESS_EQUAL);
state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_REPLACE));
state->setColorWriteMask(0); state->setColorWriteMask(0);
_opaquePipeline.reset(gpu::Pipeline::create(program, state)); _opaquePipeline.reset(gpu::Pipeline::create(program, state));
@ -330,9 +326,8 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren
doInBatch(args->_context, [=](gpu::Batch& batch) { doInBatch(args->_context, [=](gpu::Batch& batch) {
args->_batch = &batch; args->_batch = &batch;
auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferStencilColor(); auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
auto primaryDepth = DependencyManager::get<FramebufferCache>()->getPrimaryDepthTexture();
batch.enableStereo(false); batch.enableStereo(false);
batch.setFramebuffer(primaryFboColorDepthStencil); batch.setFramebuffer(primaryFboColorDepthStencil);
@ -340,7 +335,6 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren
batch.setStateScissorRect(args->_viewport); batch.setStateScissorRect(args->_viewport);
batch.setPipeline(getOpaquePipeline()); batch.setPipeline(getOpaquePipeline());
batch.setResourceTexture(0, primaryDepth);
batch.draw(gpu::TRIANGLE_STRIP, 4); batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(0, nullptr); batch.setResourceTexture(0, nullptr);
@ -367,12 +361,12 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const
doInBatch(args->_context, [=](gpu::Batch& batch) { doInBatch(args->_context, [=](gpu::Batch& batch) {
args->_batch = &batch; args->_batch = &batch;
auto primaryFboColorStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferStencilColor(); auto primaryFboColorDepthStencil = DependencyManager::get<FramebufferCache>()->getPrimaryFramebufferDepthColor();
auto primaryFboFull = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer(); auto primaryFboFull = DependencyManager::get<FramebufferCache>()->getPrimaryFramebuffer();
batch.enableSkybox(true); batch.enableSkybox(true);
batch.setFramebuffer(primaryFboColorStencil); batch.setFramebuffer(primaryFboColorDepthStencil);
batch.setViewportTransform(args->_viewport); batch.setViewportTransform(args->_viewport);
batch.setStateScissorRect(args->_viewport); batch.setStateScissorRect(args->_viewport);

View file

@ -12,13 +12,5 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
in vec2 varTexCoord0;
uniform sampler2D depthTexture;
void main(void) { void main(void) {
float depth = texture(depthTexture, varTexCoord0.xy).r;
if (depth >= 1.0) {
discard;
}
} }

View file

@ -10,7 +10,7 @@
// //
(function () { (function() {
var _this; var _this;
@ -22,13 +22,13 @@
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");
ResetSwitch = function () { ResetSwitch = function() {
_this = this; _this = this;
}; };
ResetSwitch.prototype = { ResetSwitch.prototype = {
clickReleaseOnEntity: function (entityId, mouseEvent) { clickReleaseOnEntity: function(entityId, mouseEvent) {
if (!mouseEvent.isLeftButton) { if (!mouseEvent.isLeftButton) {
return; return;
} }
@ -36,26 +36,22 @@
}, },
startNearGrabNonColliding: function () { startNearGrabNonColliding: function() {
this.triggerReset(); this.triggerReset();
}, },
startFarGrabNonColliding: function () { triggerReset: function() {
this.triggerReset();
},
triggerReset: function () {
MasterReset(); MasterReset();
}, },
preload: function (entityID) { preload: function(entityID) {
this.entityID = entityID; this.entityID = entityID;
} }
}; };
MasterReset = function () { MasterReset = function() {
var resetKey = "resetMe"; var resetKey = "resetMe";
var GRABBABLE_DATA_KEY = "grabbableKey"; var GRABBABLE_DATA_KEY = "grabbableKey";
@ -145,7 +141,7 @@
function deleteAllToys() { function deleteAllToys() {
var entities = Entities.findEntities(MyAvatar.position, 100); var entities = Entities.findEntities(MyAvatar.position, 100);
entities.forEach(function (entity) { entities.forEach(function(entity) {
//params: customKey, id, defaultValue //params: customKey, id, defaultValue
var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe;
if (shouldReset === true) { if (shouldReset === true) {
@ -330,14 +326,14 @@
function testBallDistanceFromStart() { function testBallDistanceFromStart() {
var resetCount = 0; var resetCount = 0;
collidingBalls.forEach(function (ball, index) { collidingBalls.forEach(function(ball, index) {
var currentPosition = Entities.getEntityProperties(ball, "position").position; var currentPosition = Entities.getEntityProperties(ball, "position").position;
var originalPosition = originalBallPositions[index]; var originalPosition = originalBallPositions[index];
var distance = Vec3.subtract(originalPosition, currentPosition); var distance = Vec3.subtract(originalPosition, currentPosition);
var length = Vec3.length(distance); var length = Vec3.length(distance);
if (length > RESET_DISTANCE) { if (length > RESET_DISTANCE) {
Script.setTimeout(function () { Script.setTimeout(function() {
var newPosition = Entities.getEntityProperties(ball, "position").position; var newPosition = Entities.getEntityProperties(ball, "position").position;
var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition)); var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition));
if (moving < MINIMUM_MOVE_LENGTH) { if (moving < MINIMUM_MOVE_LENGTH) {

View file

@ -24,28 +24,17 @@ function createHiddenMasterSwitch() {
type: "Box", type: "Box",
name: "Master Switch", name: "Master Switch",
script: hiddenEntityScriptURL, script: hiddenEntityScriptURL,
dimensions: { dimensions: {x: 0.7, y: 0.2, z: 0.1},
x: 0.2, position: {x: 543.9, y: 496.05, z: 502.43},
y: 0.2, rotation: Quat.fromPitchYawRollDegrees(0, 33, 0),
z: 0.2 visible: false
},
color: {
red: 42,
green: 36,
blue: 30
},
position: {
x: 554,
y: 495.5,
z: 503.2
}
}); });
} }
var entities = Entities.findEntities(MyAvatar.position, 100); var entities = Entities.findEntities(MyAvatar.position, 100);
entities.forEach(function (entity) { entities.forEach(function(entity) {
//params: customKey, id, defaultValue //params: customKey, id, defaultValue
var name = Entities.getEntityProperties(entity, "name").name var name = Entities.getEntityProperties(entity, "name").name
if (name === "Master Switch") { if (name === "Master Switch") {

View file

@ -21,10 +21,11 @@ var pingPongScriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/pingP
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');
MasterReset = function () { MasterReset = function() {
var resetKey = "resetMe"; var resetKey = "resetMe";
var GRABBABLE_DATA_KEY = "grabbableKey"; var GRABBABLE_DATA_KEY = "grabbableKey";
@ -109,12 +110,14 @@ MasterReset = function () {
z: 503.91 z: 503.91
}); });
createTargets();
} }
function deleteAllToys() { function deleteAllToys() {
var entities = Entities.findEntities(MyAvatar.position, 100); var entities = Entities.findEntities(MyAvatar.position, 100);
entities.forEach(function (entity) { entities.forEach(function(entity) {
//params: customKey, id, defaultValue //params: customKey, id, defaultValue
var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe;
if (shouldReset === true) { if (shouldReset === true) {
@ -299,14 +302,14 @@ MasterReset = function () {
function testBallDistanceFromStart() { function testBallDistanceFromStart() {
var resetCount = 0; var resetCount = 0;
collidingBalls.forEach(function (ball, index) { collidingBalls.forEach(function(ball, index) {
var currentPosition = Entities.getEntityProperties(ball, "position").position; var currentPosition = Entities.getEntityProperties(ball, "position").position;
var originalPosition = originalBallPositions[index]; var originalPosition = originalBallPositions[index];
var distance = Vec3.subtract(originalPosition, currentPosition); var distance = Vec3.subtract(originalPosition, currentPosition);
var length = Vec3.length(distance); var length = Vec3.length(distance);
if (length > RESET_DISTANCE) { if (length > RESET_DISTANCE) {
Script.setTimeout(function () { Script.setTimeout(function() {
var newPosition = Entities.getEntityProperties(ball, "position").position; var newPosition = Entities.getEntityProperties(ball, "position").position;
var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition)); var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition));
if (moving < MINIMUM_MOVE_LENGTH) { if (moving < MINIMUM_MOVE_LENGTH) {
@ -341,6 +344,141 @@ MasterReset = function () {
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,
});
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
};
targets.push(Entities.addEntity(targetProperties));
}
}
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
};
targets[index] = Entities.addEntity(targetProperties);
}
});
}
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";