From 7a7b16f0a2e8fda5f38e1cbd34295c2983c7ce31 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 7 Oct 2015 18:16:58 -0700 Subject: [PATCH 01/27] wall targets --- .../toys/ping_pong_gun/createPingPongGun.js | 4 +- examples/toys/ping_pong_gun/createTargets.js | 154 ++++++++++++++++++ examples/toys/ping_pong_gun/pingPongGun.js | 8 +- examples/toys/ping_pong_gun/wallTarget.js | 49 ++++++ 4 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 examples/toys/ping_pong_gun/createTargets.js create mode 100644 examples/toys/ping_pong_gun/wallTarget.js diff --git a/examples/toys/ping_pong_gun/createPingPongGun.js b/examples/toys/ping_pong_gun/createPingPongGun.js index cf56d6f790..cfeaba7f4e 100644 --- a/examples/toys/ping_pong_gun/createPingPongGun.js +++ b/examples/toys/ping_pong_gun/createPingPongGun.js @@ -13,8 +13,8 @@ Script.include("../../utilities.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 COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun_collision_hull.obj?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'; var center = Vec3.sum(Vec3.sum(MyAvatar.position, { x: 0, diff --git a/examples/toys/ping_pong_gun/createTargets.js b/examples/toys/ping_pong_gun/createTargets.js new file mode 100644 index 0000000000..ffc008c7a2 --- /dev/null +++ b/examples/toys/ping_pong_gun/createTargets.js @@ -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.03, + y: 0.21, + z: 0.21 +}; + +var VERTICAL_SPACING = 0.3; +var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.25; +var center = Vec3.sum(Vec3.sum(MyAvatar.position, { + x: 0, + y: 0.5, + z: 0 +}), Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); + + +var startPosition = { + x: 548.68, + y: 497.30, + z: 509.74 +} + +// var rotation = Quat.fromPitchYawRollDegrees(0, -54, 0.0); + +// var startPosition = center; + +var targetIntervalClearer = Entities.addEntity({ + name: 'Target Interval Clearer - delete me to clear', + type: 'Box', + position: startPosition, + dimensions: { + x: 1, + y: 1, + z: 1 + }, + visible: 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 zSpacing = (i % TARGETS_PER_ROW) * HORIZONTAL_SPACING + (row * HORIZONTAL_SPACING / 2); + var position = { + x: startPosition.x, + y: startPosition.y - (row * VERTICAL_SPACING), + z: startPosition.z - zSpacing + }; + + 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() { + print('TEST TARGET DISTANCE FROM START') + var resetCount = 0; + 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) { + print('SHOULD RESET THIS! at ' + originalPositions[index]) + 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); \ No newline at end of file diff --git a/examples/toys/ping_pong_gun/pingPongGun.js b/examples/toys/ping_pong_gun/pingPongGun.js index 1b5973c8bb..1e87eb76ce 100644 --- a/examples/toys/ping_pong_gun/pingPongGun.js +++ b/examples/toys/ping_pong_gun/pingPongGun.js @@ -14,6 +14,7 @@ Script.include("../../libraries/utils.js"); 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() { return; @@ -23,7 +24,7 @@ var RELOAD_THRESHOLD = 0.95; var GUN_TIP_FWD_OFFSET =-0.35; var GUN_TIP_UP_OFFSET = 0.040; - var GUN_FORCE = 9; + var GUN_FORCE = 5; var BALL_RESTITUTION = 0.6; var BALL_LINEAR_DAMPING = 0.4; var BALL_GRAVITY = { @@ -115,7 +116,10 @@ forwardVec = Vec3.multiply(forwardVec, GUN_FORCE); var properties = { - type: 'Sphere', + // type: 'Model', + // modelURL:PING_PONG_BALL_URL, + shapeType:'sphere', + type:'Sphere', color: BALL_COLOR, dimensions: BALL_DIMENSIONS, linearDamping: BALL_LINEAR_DAMPING, diff --git a/examples/toys/ping_pong_gun/wallTarget.js b/examples/toys/ping_pong_gun/wallTarget.js new file mode 100644 index 0000000000..cca35e5d6c --- /dev/null +++ b/examples/toys/ping_pong_gun/wallTarget.js @@ -0,0 +1,49 @@ +// 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() { + var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target'; + var defaultTargetData = { + originalPosition: null + }; + + var _this; + function Target() { + _this=this; + return; + } + + Target.prototype = { + preload: function(entityID) { + this.entityID = entityID; + var targetData = getEntityCustomData(TARGET_USER_DATA_KEY, entityID, defaultTargetData); + this.originalPosition=targetData.originalPosition; + print('TARGET ORIGINAL POSITION:::'+targetData.originalPosition.x); + }, + collisionWithEntity: function(me, otherEntity) { + Entities.editEntity(me, { + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + velocity: { + x: 0, + y: -0.01, + z: 0 + } + }) + } + }; + + // entity scripts always need to return a newly constructed object of our type + return new Target(); +}); \ No newline at end of file From a2ca1c033dc77010673c71fcc5034739e174b73f Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 7 Oct 2015 19:04:03 -0700 Subject: [PATCH 02/27] FIxing the rear view mirror issue with background and fooling around with Lighting equations --- libraries/fbx/src/FBXReader_Material.cpp | 2 +- libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv | 9 +++++---- libraries/render-utils/src/DeferredBufferWrite.slh | 6 +++--- libraries/render-utils/src/DeferredGlobalLight.slh | 3 ++- libraries/render-utils/src/DeferredLighting.slh | 7 +++++-- libraries/render-utils/src/FramebufferCache.cpp | 12 ++++++++---- libraries/render-utils/src/RenderDeferredTask.cpp | 12 +++++++----- libraries/render-utils/src/drawOpaqueStencil.slf | 11 +++++++---- 8 files changed, 38 insertions(+), 24 deletions(-) diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index e947a0356e..2f15efbc91 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -146,7 +146,7 @@ void FBXReader::consolidateFBXMaterials() { // FIXME: Do not use the Specular Factor yet as some FBX models have it set to 0 // metallic *= material.specularFactor; material._material->setMetallic(metallic); - material._material->setGloss(material.shininess); + material._material->setGloss(material.shininess / 100.0f); if (material.opacity <= 0.0f) { material._material->setOpacity(1.0f); diff --git a/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv b/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv index 60ab0bd7dd..1426ae48fd 100644 --- a/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv +++ b/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv @@ -14,11 +14,12 @@ out vec2 varTexCoord0; void main(void) { + const float depth = 1.0; const vec4 UNIT_QUAD[4] = vec4[4]( - vec4(-1.0, -1.0, 0.0, 1.0), - vec4(1.0, -1.0, 0.0, 1.0), - vec4(-1.0, 1.0, 0.0, 1.0), - vec4(1.0, 1.0, 0.0, 1.0) + vec4(-1.0, -1.0, depth, 1.0), + vec4(1.0, -1.0, depth, 1.0), + vec4(-1.0, 1.0, depth, 1.0), + vec4(1.0, 1.0, depth, 1.0) ); vec4 pos = UNIT_QUAD[gl_VertexID]; diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 1c1330f0c0..e8a589c323 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -53,7 +53,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, _fragColor0 = vec4(diffuse.rgb, alpha); _fragColor1 = vec4(bestFitNormal(normal), 1.0); - _fragColor2 = vec4(specular, shininess / 128.0); + _fragColor2 = vec4(specular, shininess); } void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { @@ -64,7 +64,7 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s _fragColor0 = vec4(diffuse.rgb, alpha); //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); _fragColor1 = vec4(bestFitNormal(normal), 0.5); - _fragColor2 = vec4(emissive, shininess / 128.0); + _fragColor2 = vec4(emissive, shininess); } void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { @@ -74,7 +74,7 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec _fragColor0 = vec4(diffuse.rgb, alpha); // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - // _fragColor2 = vec4(specular, shininess / 128.0); + // _fragColor2 = vec4(specular, shininess); } <@endif@> diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 983b8002f7..40428c5a4e 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -131,7 +131,8 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 positi color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); - return color; + // return color; + return shading.rgb; } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index 888742bb18..af13a17575 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -30,8 +30,11 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp float shlickPower = (1.0 - dot(fragLightDir,halfDir)); float shlickPower2 = shlickPower * shlickPower; float shlickPower5 = shlickPower2 * shlickPower2 * shlickPower; - vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5); - vec3 reflect = specularPower * schlick; + // vec3 fresnel = specular + (1.0 - specular) * shlickPower5; + vec3 fresnel = vec3( 0.1 + (1.0 - 0.1) * shlickPower5 ); + + // vec3 reflect = specularPower * fresnel; + vec3 reflect = fresnel; return vec4(reflect, diffuse); } diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 7b20a3696a..543078a4bd 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -68,17 +68,21 @@ void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferStencilColor->setRenderBuffer(0, _primaryColorTexture); - auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); + // 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 _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)); + // auto stencilFormat = gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::DEPTH_STENCIL); // Depth24_Stencil8 texel format + auto stencilFormat = depthFormat; + // _primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler)); + _primaryStencilTexture = _primaryDepthTexture; _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); - _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); + // _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); + _primaryFramebufferStencilColor = _primaryFramebufferDepthColor; _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 0f79dc8b8d..a85cd3fbca 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -44,15 +44,16 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - batch.setFramebuffer(primaryFboStencil); + /* batch.setFramebuffer(primaryFboStencil); batch.clearFramebuffer( gpu::Framebuffer::BUFFER_STENCIL, vec4(vec3(0), 1), 1.0, 0.0, true); - + */ batch.setFramebuffer(primaryFbo); batch.clearFramebuffer( 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); }); } @@ -313,7 +314,8 @@ const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() { gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - 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); _opaquePipeline.reset(gpu::Pipeline::create(program, state)); @@ -340,7 +342,7 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren batch.setStateScissorRect(args->_viewport); batch.setPipeline(getOpaquePipeline()); - batch.setResourceTexture(0, primaryDepth); + // batch.setResourceTexture(0, primaryDepth); batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(0, nullptr); diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf index 14feda21e9..033c2fec5a 100644 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -14,11 +14,14 @@ in vec2 varTexCoord0; -uniform sampler2D depthTexture; - +//uniform sampler2D depthTexture; +out vec4 outFragColor; void main(void) { - float depth = texture(depthTexture, varTexCoord0.xy).r; +/* float depth = texture(depthTexture, varTexCoord0.xy).r; if (depth >= 1.0) { discard; - } + }*/ + + outFragColor = vec4(1.0); + } From 02a24712caa119ba7822698d44149e8f10b5f149 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 7 Oct 2015 19:52:29 -0700 Subject: [PATCH 03/27] fix isEmitting property for particle effects, cleaned up some particle property editing in edit.js --- examples/edit.js | 2 +- examples/html/entityProperties.html | 75 +++++++++---------- .../entities/src/EntityItemProperties.cpp | 4 + 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 0a1f31f0d7..98ad21f4e2 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1275,7 +1275,7 @@ PropertiesTool = function(opts) { webView.eventBridge.emitScriptEvent(JSON.stringify(data)); }); - webView.eventBridge.webEventReceived.connect(function(data) { + webView.eventBridge.webEventReceived.connect(function (data) { data = JSON.parse(data); if (data.type == "print") { if (data.message) { diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 268e95010c..ac46272a4d 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -305,14 +305,10 @@ var elParticleSections = document.querySelectorAll(".particle-section"); allSections.push(elParticleSections); + var elParticleIsEmitting = document.getElementById("property-particle-is-emitting"); var elParticleMaxParticles = document.getElementById("property-particle-maxparticles"); var elParticleLifeSpan = document.getElementById("property-particle-lifespan"); 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 elTextSections = document.querySelectorAll(".text-section"); @@ -511,7 +507,7 @@ elColorSection.style.display = 'none'; } - if (properties.type == "Model" || properties.type == "ParticleEffect") { + if (properties.type == "Model") { for (var i = 0; i < elModelSections.length; i++) { elModelSections[i].style.display = 'block'; } @@ -617,15 +613,38 @@ elParticleSections[i].style.display = 'block'; } + elParticleIsEmitting.checked = properties.isEmitting; elParticleMaxParticles.value = properties.maxParticles; elParticleLifeSpan.value = properties.lifespan.toFixed(2); 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); + + /* + COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(colorSpread, getColorSpread); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(colorStart, getColorStart); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(colorFinish, getColorFinish); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(alphaSpread, getAlphaSpread); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(alphaStart, getAlphaStart); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(alphaFinish, getAlphaFinish); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures); + // float emitSpeed + // float speedSpread + // quat emitOrientation + // vec3 emitDimensions + // float emitRadiusStart + // float polarStart + // float polarFinish + // float azimuthStart + // float azimuthFinish + // vec3 emitAcceleration + // vec3 accelerationSpread + // float radiusStart + // float radiusSpread?? + // float radiusFinish + // float RadiusSpread + */ + } else if (properties.type == "PolyVox") { for (var i = 0; i < elPolyVoxSections.length; i++) { elPolyVoxSections[i].style.display = 'block'; @@ -758,16 +777,10 @@ elWebSourceURL.addEventListener('change', createEmitTextPropertyUpdateFunction('sourceUrl')); + elParticleIsEmitting.addEventListener('change', createEmitCheckedPropertyUpdateFunction('isEmitting')); elParticleMaxParticles.addEventListener('change', createEmitNumberPropertyUpdateFunction('maxParticles')); elParticleLifeSpan.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifespan')); 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')); elModelURL.addEventListener('change', createEmitTextPropertyUpdateFunction('modelURL')); @@ -1362,6 +1375,12 @@ +
+ Is Emitting + + + +
Max Particles
@@ -1380,26 +1399,6 @@
-
-
Particle Emission Direction
-
-
X
-
Y
-
Z
-
-
-
-
Particle Emission Strength
-
- -
-
-
-
Particle Local Gravity
-
- -
-
Particle Radius
diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index b17ca41e9b..62d7e69202 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -313,6 +313,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_TEXT_COLOR, textColor); CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_COLOR, backgroundColor); 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_LIFESPAN, lifespan); CHECK_PROPERTY_CHANGE(PROP_EMIT_RATE, emitRate); @@ -424,6 +425,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool // Particles only 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_LIFESPAN, lifespan); 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_ALPHA, properties.getAlpha()); } + if (propertyCount > 0) { int endOfEntityItemData = packetData->getUncompressedByteOffset(); @@ -1472,6 +1475,7 @@ void EntityItemProperties::markAllChanged() { _backgroundColorChanged = true; _shapeTypeChanged = true; + _isEmittingChanged = true; _maxParticlesChanged = true; _lifespanChanged = true; _emitRateChanged = true; From bb10d8a7d5d7deaa6295e5f54016415647076384 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 7 Oct 2015 20:08:30 -0700 Subject: [PATCH 04/27] more work on rationalizing particle properties --- examples/html/entityProperties.html | 29 ++++++++++++------- .../entities/src/ParticleEffectEntityItem.cpp | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index ac46272a4d..dcb49477d8 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -310,6 +310,7 @@ var elParticleLifeSpan = document.getElementById("property-particle-lifespan"); var elParticleEmitRate = document.getElementById("property-particle-emit-rate"); var elParticleRadius = document.getElementById("property-particle-radius"); + var elParticleTextures = document.getElementById("property-particle-textures"); var elTextSections = document.querySelectorAll(".text-section"); allSections.push(elTextSections); @@ -525,7 +526,7 @@ elModelAnimationHold.checked = properties.animation.hold; elModelAnimationStartAutomatically.checked = properties.animation.startAutomatically; elModelTextures.value = properties.textures; - elModelOriginalTextures.value = properties.originalTextures; + elModelOriginalTextures.value = properties.originalTextures; } else if (properties.type == "Web") { for (var i = 0; i < elWebSections.length; i++) { elWebSections[i].style.display = 'block'; @@ -618,16 +619,16 @@ elParticleLifeSpan.value = properties.lifespan.toFixed(2); elParticleEmitRate.value = properties.emitRate.toFixed(1); elParticleRadius.value = properties.particleRadius.toFixed(3); + elParticleTextures.value = properties.textures; - /* - COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(colorSpread, getColorSpread); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(colorStart, getColorStart); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(colorFinish, getColorFinish); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(alphaSpread, getAlphaSpread); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(alphaStart, getAlphaStart); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(alphaFinish, getAlphaFinish); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(textures, getTextures); + // FIXME - these are other particle properties we could support in the editor + // shapeType // ??? + // color colorSpread + // color colorStart + // color colorFinish + // float alphaSpread + // float alphaStart + // float alphaFinish // float emitSpeed // float speedSpread // quat emitOrientation @@ -643,7 +644,6 @@ // float radiusSpread?? // float radiusFinish // float RadiusSpread - */ } else if (properties.type == "PolyVox") { for (var i = 0; i < elPolyVoxSections.length; i++) { @@ -782,6 +782,7 @@ elParticleLifeSpan.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifespan')); elParticleEmitRate.addEventListener('change', createEmitNumberPropertyUpdateFunction('emitRate')); elParticleRadius.addEventListener('change', createEmitNumberPropertyUpdateFunction('particleRadius')); + elParticleTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures')); elModelURL.addEventListener('change', createEmitTextPropertyUpdateFunction('modelURL')); elShapeType.addEventListener('change', createEmitTextPropertyUpdateFunction('shapeType')); @@ -1405,6 +1406,12 @@
+
+
Textures
+
+ +
+
diff --git a/libraries/entities/src/ParticleEffectEntityItem.cpp b/libraries/entities/src/ParticleEffectEntityItem.cpp index d04f192f80..f6ed4a06ab 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.cpp +++ b/libraries/entities/src/ParticleEffectEntityItem.cpp @@ -329,7 +329,7 @@ EntityItemProperties ParticleEffectEntityItem::getProperties(EntityPropertyFlags COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); COPY_ENTITY_PROPERTY_TO_PROPERTIES(alpha, getAlpha); 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(lifespan, getLifespan); COPY_ENTITY_PROPERTY_TO_PROPERTIES(isEmitting, getIsEmitting); From c7049bad398558cf3aa38a333a8695ba07f18e39 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 09:32:05 -0700 Subject: [PATCH 05/27] Backing up on any changes regarding shading, focus on the rearr view mirror and stencil bug --- libraries/fbx/src/FBXReader_Material.cpp | 2 +- libraries/render-utils/src/DeferredBufferWrite.slh | 6 +++--- libraries/render-utils/src/DeferredGlobalLight.slh | 3 +-- libraries/render-utils/src/DeferredLighting.slh | 7 ++----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index 2f15efbc91..e947a0356e 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -146,7 +146,7 @@ void FBXReader::consolidateFBXMaterials() { // FIXME: Do not use the Specular Factor yet as some FBX models have it set to 0 // metallic *= material.specularFactor; material._material->setMetallic(metallic); - material._material->setGloss(material.shininess / 100.0f); + material._material->setGloss(material.shininess); if (material.opacity <= 0.0f) { material._material->setOpacity(1.0f); diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index e8a589c323..1c1330f0c0 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -53,7 +53,7 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, _fragColor0 = vec4(diffuse.rgb, alpha); _fragColor1 = vec4(bestFitNormal(normal), 1.0); - _fragColor2 = vec4(specular, shininess); + _fragColor2 = vec4(specular, shininess / 128.0); } void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { @@ -64,7 +64,7 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s _fragColor0 = vec4(diffuse.rgb, alpha); //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); _fragColor1 = vec4(bestFitNormal(normal), 0.5); - _fragColor2 = vec4(emissive, shininess); + _fragColor2 = vec4(emissive, shininess / 128.0); } void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { @@ -74,7 +74,7 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec _fragColor0 = vec4(diffuse.rgb, alpha); // _fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - // _fragColor2 = vec4(specular, shininess); + // _fragColor2 = vec4(specular, shininess / 128.0); } <@endif@> diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 40428c5a4e..983b8002f7 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -131,8 +131,7 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 positi color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light); - // return color; - return shading.rgb; + return color; } <@endfunc@> diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index af13a17575..888742bb18 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -30,11 +30,8 @@ vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 sp float shlickPower = (1.0 - dot(fragLightDir,halfDir)); float shlickPower2 = shlickPower * shlickPower; float shlickPower5 = shlickPower2 * shlickPower2 * shlickPower; - // vec3 fresnel = specular + (1.0 - specular) * shlickPower5; - vec3 fresnel = vec3( 0.1 + (1.0 - 0.1) * shlickPower5 ); - - // vec3 reflect = specularPower * fresnel; - vec3 reflect = fresnel; + vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5); + vec3 reflect = specularPower * schlick; return vec4(reflect, diffuse); } From 39f2241eacc812507e06eb792c8adca27607cf38 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 8 Oct 2015 09:46:43 -0700 Subject: [PATCH 06/27] fix coding standard issue --- examples/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/edit.js b/examples/edit.js index 98ad21f4e2..0a1f31f0d7 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -1275,7 +1275,7 @@ PropertiesTool = function(opts) { webView.eventBridge.emitScriptEvent(JSON.stringify(data)); }); - webView.eventBridge.webEventReceived.connect(function (data) { + webView.eventBridge.webEventReceived.connect(function(data) { data = JSON.parse(data); if (data.type == "print") { if (data.message) { From b7f52ea542ac3f456dab3f9a8877c15e0a76100b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 8 Oct 2015 10:11:21 -0700 Subject: [PATCH 07/27] Moved entity reset switch, fixed some style issues --- unpublishedScripts/hiddenEntityReset.js | 24 +++++++++------------- unpublishedScripts/immediateClientReset.js | 21 +++++-------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index 90e4bc1bf8..a9e97db518 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -10,7 +10,7 @@ // -(function () { +(function() { var _this; @@ -22,13 +22,13 @@ var dollScriptURL = Script.resolvePath("../examples/toys/doll/doll.js"); var lightsScriptURL = Script.resolvePath("../examples/toys/lightSwitch.js"); - ResetSwitch = function () { + ResetSwitch = function() { _this = this; }; ResetSwitch.prototype = { - clickReleaseOnEntity: function (entityId, mouseEvent) { + clickReleaseOnEntity: function(entityId, mouseEvent) { if (!mouseEvent.isLeftButton) { return; } @@ -36,26 +36,22 @@ }, - startNearGrabNonColliding: function () { + startNearGrabNonColliding: function() { this.triggerReset(); }, - startFarGrabNonColliding: function () { - this.triggerReset(); - }, - - triggerReset: function () { + triggerReset: function() { MasterReset(); }, - preload: function (entityID) { + preload: function(entityID) { this.entityID = entityID; } }; - MasterReset = function () { + MasterReset = function() { var resetKey = "resetMe"; var GRABBABLE_DATA_KEY = "grabbableKey"; @@ -145,7 +141,7 @@ function deleteAllToys() { var entities = Entities.findEntities(MyAvatar.position, 100); - entities.forEach(function (entity) { + entities.forEach(function(entity) { //params: customKey, id, defaultValue var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; if (shouldReset === true) { @@ -330,14 +326,14 @@ function testBallDistanceFromStart() { var resetCount = 0; - collidingBalls.forEach(function (ball, index) { + collidingBalls.forEach(function(ball, index) { var currentPosition = Entities.getEntityProperties(ball, "position").position; var originalPosition = originalBallPositions[index]; var distance = Vec3.subtract(originalPosition, currentPosition); var length = Vec3.length(distance); if (length > RESET_DISTANCE) { - Script.setTimeout(function () { + Script.setTimeout(function() { var newPosition = Entities.getEntityProperties(ball, "position").position; var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition)); if (moving < MINIMUM_MOVE_LENGTH) { diff --git a/unpublishedScripts/immediateClientReset.js b/unpublishedScripts/immediateClientReset.js index 89464b8c6b..0a2e9383a2 100644 --- a/unpublishedScripts/immediateClientReset.js +++ b/unpublishedScripts/immediateClientReset.js @@ -24,28 +24,17 @@ function createHiddenMasterSwitch() { type: "Box", name: "Master Switch", script: hiddenEntityScriptURL, - dimensions: { - x: 0.2, - y: 0.2, - z: 0.2 - }, - color: { - red: 42, - green: 36, - blue: 30 - }, - position: { - x: 554, - y: 495.5, - z: 503.2 - } + dimensions: {x: 0.7, y: 0.2, z: 0.1}, + position: {x: 543.9, y: 496.05, z: 502.43}, + rotation: Quat.fromPitchYawRollDegrees(0, 33, 0), + visible: false }); } var entities = Entities.findEntities(MyAvatar.position, 100); -entities.forEach(function (entity) { +entities.forEach(function(entity) { //params: customKey, id, defaultValue var name = Entities.getEntityProperties(entity, "name").name if (name === "Master Switch") { From 3db148f3dcbd5882877dc924a793f03414783f70 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 8 Oct 2015 11:13:52 -0700 Subject: [PATCH 08/27] fix obj model meshes --- libraries/fbx/src/FBXReader.cpp | 2 +- libraries/fbx/src/FBXReader.h | 2 +- libraries/fbx/src/FBXReader_Mesh.cpp | 20 ++++++++++---------- libraries/fbx/src/OBJReader.cpp | 2 ++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 4b3b3b0fea..ca9f126cba 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -1512,7 +1512,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } extracted.mesh.isEye = (maxJointIndex == geometry.leftEyeJointIndex || maxJointIndex == geometry.rightEyeJointIndex); - buildModelMesh(extracted, url); + buildModelMesh(extracted.mesh, url); if (extracted.mesh.isEye) { if (maxJointIndex == geometry.leftEyeJointIndex) { diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index c0cbf5fb18..0af7b28136 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -388,7 +388,7 @@ public: ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex); QHash meshes; - void buildModelMesh(ExtractedMesh& extracted, const QString& url); + static void buildModelMesh(FBXMesh& extractedMesh, const QString& url); FBXTexture getTexture(const QString& textureID); diff --git a/libraries/fbx/src/FBXReader_Mesh.cpp b/libraries/fbx/src/FBXReader_Mesh.cpp index 097862ef38..dbada15588 100644 --- a/libraries/fbx/src/FBXReader_Mesh.cpp +++ b/libraries/fbx/src/FBXReader_Mesh.cpp @@ -386,11 +386,11 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn 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 -- .*"); unsigned int totalSourceIndices = 0; - foreach(const FBXMeshPart& part, extracted.mesh.parts) { + foreach(const FBXMeshPart& part, extractedMesh.parts) { totalSourceIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size()); } @@ -399,18 +399,18 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) { return; } - if (extracted.mesh.vertices.size() == 0) { + if (extractedMesh.vertices.size() == 0) { qCDebug(modelformat) << "buildModelMesh failed -- no vertices, url = " << url; return; } - FBXMesh& fbxMesh = extracted.mesh; + FBXMesh& fbxMesh = extractedMesh; model::MeshPointer mesh(new model::Mesh()); // Grab the vertices in a buffer auto vb = std::make_shared(); - vb->setData(extracted.mesh.vertices.size() * sizeof(glm::vec3), - (const gpu::Byte*) extracted.mesh.vertices.data()); + vb->setData(extractedMesh.vertices.size() * sizeof(glm::vec3), + (const gpu::Byte*) extractedMesh.vertices.data()); gpu::BufferView vbv(vb, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ)); mesh->setVertexBuffer(vbv); @@ -486,7 +486,7 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) { unsigned int totalIndices = 0; - foreach(const FBXMeshPart& part, extracted.mesh.parts) { + foreach(const FBXMeshPart& part, extractedMesh.parts) { totalIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size()); } @@ -502,10 +502,10 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) { int offset = 0; std::vector< model::Mesh::Part > parts; - if (extracted.mesh.parts.size() > 1) { + if (extractedMesh.parts.size() > 1) { 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); if (part.quadTrianglesIndices.size()) { @@ -545,5 +545,5 @@ void FBXReader::buildModelMesh(ExtractedMesh& extracted, const QString& url) { // model::Box box = mesh->evalPartBound(0); - extracted.mesh._mesh = mesh; + extractedMesh._mesh = mesh; } diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJReader.cpp index a9275e2d4a..835bb1a9b6 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJReader.cpp @@ -532,6 +532,8 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping, mesh.meshExtents.addPoint(vertex); geometry.meshExtents.addPoint(vertex); } + + FBXReader::buildModelMesh(mesh, url.toString()); // fbxDebugDump(geometry); } catch(const std::exception& e) { qCDebug(modelformat) << "OBJ reader fail: " << e.what(); From 6921e0f0222ca0c6b0e0d4fc98cfd72d4710bb0c Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 8 Oct 2015 11:38:02 -0700 Subject: [PATCH 09/27] Aligned targets on wall in toybox --- examples/toys/ping_pong_gun/createTargets.js | 53 ++++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/examples/toys/ping_pong_gun/createTargets.js b/examples/toys/ping_pong_gun/createTargets.js index ffc008c7a2..65ca203599 100644 --- a/examples/toys/ping_pong_gun/createTargets.js +++ b/examples/toys/ping_pong_gun/createTargets.js @@ -29,7 +29,10 @@ var TARGET_DIMENSIONS = { }; var VERTICAL_SPACING = 0.3; -var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.25; +var NUM_ROWS = 2; +var NUM_COLUMNS = 3; +var spacingVector = {x: 1.4, y: 0, z: -0.93}; +var HORIZONTAL_SPACING = Vec3.multiply(Vec3.normalize(spacingVector), 0.5); var center = Vec3.sum(Vec3.sum(MyAvatar.position, { x: 0, y: 0.5, @@ -64,34 +67,30 @@ var targets = []; var originalPositions = []; function addTargets() { - var i; + var i, rowIndex, columnIndex; var row = -1; - for (i = 0; i < NUMBER_OF_TARGETS; i++) { - if (i % TARGETS_PER_ROW === 0) { - row++; + var rotation = Quat.fromPitchYawRollDegrees(-80, -48, -11); + for (rowIndex = 0; rowIndex < NUM_ROWS; rowIndex++) { + for (columnIndex = 0; columnIndex < NUM_COLUMNS; columnIndex++) { + + var position = Vec3.sum(startPosition, Vec3.multiply(HORIZONTAL_SPACING, columnIndex)); + + 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)); } - - var zSpacing = (i % TARGETS_PER_ROW) * HORIZONTAL_SPACING + (row * HORIZONTAL_SPACING / 2); - var position = { - x: startPosition.x, - y: startPosition.y - (row * VERTICAL_SPACING), - z: startPosition.z - zSpacing - }; - - 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)); + startPosition = Vec3.sum(startPosition, {x: 0, y: VERTICAL_SPACING, z: 0}); } } From a8d162248176d49b5490d4cf782cbecdc1b4deff Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 8 Oct 2015 11:47:54 -0700 Subject: [PATCH 10/27] CR feedback --- examples/html/entityProperties.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index dcb49477d8..1bf3458efd 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -1349,13 +1349,13 @@
Textures
- +
Original Textures
- +
@@ -1403,13 +1403,13 @@
Particle Radius
- +
Textures
- +
From f1410269909e31fccc5d7c1ab545b0350e027289 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 8 Oct 2015 11:48:48 -0700 Subject: [PATCH 11/27] CR feedback --- examples/html/entityProperties.html | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/examples/html/entityProperties.html b/examples/html/entityProperties.html index 1bf3458efd..97d8fe4729 100644 --- a/examples/html/entityProperties.html +++ b/examples/html/entityProperties.html @@ -621,30 +621,6 @@ elParticleRadius.value = properties.particleRadius.toFixed(3); elParticleTextures.value = properties.textures; - // FIXME - these are other particle properties we could support in the editor - // shapeType // ??? - // color colorSpread - // color colorStart - // color colorFinish - // float alphaSpread - // float alphaStart - // float alphaFinish - // float emitSpeed - // float speedSpread - // quat emitOrientation - // vec3 emitDimensions - // float emitRadiusStart - // float polarStart - // float polarFinish - // float azimuthStart - // float azimuthFinish - // vec3 emitAcceleration - // vec3 accelerationSpread - // float radiusStart - // float radiusSpread?? - // float radiusFinish - // float RadiusSpread - } else if (properties.type == "PolyVox") { for (var i = 0; i < elPolyVoxSections.length; i++) { elPolyVoxSections[i].style.display = 'block'; From dff598ebd16c9806493c7a521b9f102a5585788d Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 12:06:09 -0700 Subject: [PATCH 12/27] clening and getting ready for pr --- libraries/gpu/src/gpu/Batch.cpp | 7 +++++++ libraries/gpu/src/gpu/Batch.h | 2 ++ libraries/gpu/src/gpu/GLBackend.h | 2 ++ libraries/gpu/src/gpu/GLBackendTransform.cpp | 15 ++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 966182c7d3..c3e186a630 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -205,6 +205,13 @@ void Batch::setViewportTransform(const 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) { ADD_COMMAND(setPipeline); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index e1b76e2e81..deb70f7a68 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -187,6 +187,7 @@ public: void setProjectionTransform(const Mat4& proj); // Viewport is xy = low left corner in framebuffer, zw = width height of the viewport, expressed in pixels void setViewportTransform(const Vec4i& viewport); + void setDepthRangeTransform(float nearDepth, float farDepth); // Pipeline Stage void setPipeline(const PipelinePointer& pipeline); @@ -285,6 +286,7 @@ public: COMMAND_setViewTransform, COMMAND_setProjectionTransform, COMMAND_setViewportTransform, + COMMAND_setDepthRangeTransform, COMMAND_setPipeline, COMMAND_setStateBlendFactor, diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index e01dbcd0dc..9cb988a431 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -314,6 +314,7 @@ protected: void do_setViewTransform(Batch& batch, uint32 paramOffset); void do_setProjectionTransform(Batch& batch, uint32 paramOffset); void do_setViewportTransform(Batch& batch, uint32 paramOffset); + void do_setDepthRangeTransform(Batch& batch, uint32 paramOffset); void initTransform(); void killTransform(); @@ -339,6 +340,7 @@ protected: Transform _view; Mat4 _projection; Vec4i _viewport{ 0, 0, 1, 1 }; + Vec2 _depthRange{ 0.0f, 1.0f }; bool _invalidModel{true}; bool _invalidView{false}; bool _invalidProj{false}; diff --git a/libraries/gpu/src/gpu/GLBackendTransform.cpp b/libraries/gpu/src/gpu/GLBackendTransform.cpp index 5e16421c6a..963cab778f 100755 --- a/libraries/gpu/src/gpu/GLBackendTransform.cpp +++ b/libraries/gpu/src/gpu/GLBackendTransform.cpp @@ -45,10 +45,21 @@ void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) { 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; } +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() { glGenBuffers(1, &_transform._objectBuffer); glGenBuffers(1, &_transform._cameraBuffer); @@ -75,6 +86,8 @@ void GLBackend::syncTransformStateCache() { glGetIntegerv(GL_VIEWPORT, (GLint*) &_transform._viewport); + glGetFloatv(GL_DEPTH_RANGE, (GLfloat*)&_transform._depthRange); + Mat4 modelView; auto modelViewInv = glm::inverse(modelView); _transform._view.evalFromRawMatrix(modelViewInv); From 8ce3ee0d60f6d00586f7ce1426251b494e5a5d1e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 8 Oct 2015 13:22:43 -0700 Subject: [PATCH 13/27] have nodes be cleaned up on the NL thread --- libraries/networking/src/LimitedNodeList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index d4b15c323b..75d42f55cb 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -501,7 +501,7 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t LimitedNodeList::flagTimeForConnectionStep(LimitedNodeList::AddedAudioMixer); } - SharedNodePointer newNodePointer(newNode); + SharedNodePointer newNodePointer(newNode, &QObject::deleteLater); _nodeHash.insert(UUIDNodePair(newNode->getUUID(), newNodePointer)); From dc4f987a2eba41ba560301aa138ab88db28d2287 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 8 Oct 2015 15:29:42 -0700 Subject: [PATCH 14/27] fix segmented write logic in PacketList --- libraries/networking/src/udt/PacketList.cpp | 44 ++++++++++++++------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index ffe2b3eeba..c6b554f237 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -176,26 +176,42 @@ 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 // check now to see if this is an unsupported write - int numBytesToEnd = _currentPacket->bytesAvailableForWrite(); - - if ((newPacket->size() - numBytesToEnd) < sizeRemaining) { + int segmentSize = _currentPacket->pos() - _segmentStartIndex; + + if (segmentSize + sizeRemaining > newPacket->getPayloadCapacity()) { // 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 qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is" << "larger than the payload size."; 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 -1; + } else { + // copy from currentPacket where the segment started to the beginning of the newPacket + newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize); + + // the current segment now starts at the beginning of the new packet + _segmentStartIndex = _extendedHeader.size(); + + // shrink the current payload to the actual size of the packet + _currentPacket->setPayloadSize(_segmentStartIndex); } - - int segmentSize = _currentPacket->pos() - _segmentStartIndex; - - // copy from currentPacket where the segment started to the beginning of the newPacket - newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize); - - // the current segment now starts at the beginning of the new packet - _segmentStartIndex = _extendedHeader.size(); - - // shrink the current payload to the actual size of the packet - _currentPacket->setPayloadSize(_segmentStartIndex); + } + + if (sizeRemaining > newPacket->getPayloadCapacity()) { + // this is an unsupported case - attempting to write a block of data larger + // 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" + << "larger than the payload size."; + Q_ASSERT(false); + + // return -1 to indicate error + return -1; } // move the current packet to our list of packets From 519df1565a519f5c5d09c03796e3f9e56f60f76c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 8 Oct 2015 15:33:21 -0700 Subject: [PATCH 15/27] fix comment format in PacketList --- libraries/networking/src/udt/PacketList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index c6b554f237..1ef27410cd 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -185,8 +185,8 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { << "larger than the payload size."; 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 + // 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); From 0d9421a65e6ba66ae5cdb4ceb1e48068c8028ffd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 8 Oct 2015 15:40:49 -0700 Subject: [PATCH 16/27] constantize the PacketList write error --- libraries/networking/src/udt/PacketList.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index 1ef27410cd..28c0a034c7 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -150,6 +150,8 @@ void PacketList::preparePackets(MessageNumber messageNumber) { } } +const qint64 PACKET_LIST_WRITE_ERROR = -1; + qint64 PacketList::writeData(const char* data, qint64 maxSize) { auto sizeRemaining = maxSize; @@ -190,7 +192,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { _currentPacket->seek(_segmentStartIndex); _currentPacket->setPayloadSize(_segmentStartIndex); - return -1; + 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); @@ -210,8 +212,7 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { << "larger than the payload size."; Q_ASSERT(false); - // return -1 to indicate error - return -1; + return PACKET_LIST_WRITE_ERROR; } // move the current packet to our list of packets From aa2a8edc6f332154aafa68c6eff5002a6fd348a0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 8 Oct 2015 15:44:18 -0700 Subject: [PATCH 17/27] use _segmentStartIndex before changing its value --- libraries/networking/src/udt/PacketList.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index 28c0a034c7..09d8628a1c 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -197,11 +197,11 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) { // copy from currentPacket where the segment started to the beginning of the newPacket newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize); - // the current segment now starts at the beginning of the new packet - _segmentStartIndex = _extendedHeader.size(); - // 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(); } } From 62728aa507c8d5378f5f47d18952e86b487eb4de Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 8 Oct 2015 16:16:11 -0700 Subject: [PATCH 18/27] alignments --- examples/toys/ping_pong_gun/createTargets.js | 79 ++++++++++---------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/examples/toys/ping_pong_gun/createTargets.js b/examples/toys/ping_pong_gun/createTargets.js index 65ca203599..eb4eaf70e3 100644 --- a/examples/toys/ping_pong_gun/createTargets.js +++ b/examples/toys/ping_pong_gun/createTargets.js @@ -19,8 +19,8 @@ var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_g var RESET_DISTANCE = 1; var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target'; -var NUMBER_OF_TARGETS = 6; -var TARGETS_PER_ROW = 3; +var NUMBER_OF_TARGETS = 8; +var TARGETS_PER_ROW = 4; var TARGET_DIMENSIONS = { x: 0.03, @@ -28,16 +28,8 @@ var TARGET_DIMENSIONS = { z: 0.21 }; -var VERTICAL_SPACING = 0.3; -var NUM_ROWS = 2; -var NUM_COLUMNS = 3; -var spacingVector = {x: 1.4, y: 0, z: -0.93}; -var HORIZONTAL_SPACING = Vec3.multiply(Vec3.normalize(spacingVector), 0.5); -var center = Vec3.sum(Vec3.sum(MyAvatar.position, { - x: 0, - y: 0.5, - z: 0 -}), Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); +var VERTICAL_SPACING = 0.5; +var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.5; var startPosition = { @@ -49,17 +41,21 @@ var startPosition = { // var rotation = Quat.fromPitchYawRollDegrees(0, -54, 0.0); // var startPosition = center; +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: { - x: 1, - y: 1, - z: 1 + dimensions: TARGET_DIMENSIONS, + color: { + red: 0, + green: 255, + blue: 0 }, + rotation:rotation, visible: false, + collisionsWillMove: false, ignoreForCollisions: true, }) var targets = []; @@ -67,34 +63,37 @@ var targets = []; var originalPositions = []; function addTargets() { - var i, rowIndex, columnIndex; + var i; var row = -1; - var rotation = Quat.fromPitchYawRollDegrees(-80, -48, -11); - for (rowIndex = 0; rowIndex < NUM_ROWS; rowIndex++) { - for (columnIndex = 0; columnIndex < NUM_COLUMNS; columnIndex++) { - - var position = Vec3.sum(startPosition, Vec3.multiply(HORIZONTAL_SPACING, columnIndex)); - - 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)); + for (i = 0; i < NUMBER_OF_TARGETS; i++) { + if (i % TARGETS_PER_ROW === 0) { + row++; } - startPosition = Vec3.sum(startPosition, {x: 0, y: VERTICAL_SPACING, z: 0}); + + 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); + + print('position::: ' + JSON.stringify(position)); + 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() { print('TEST TARGET DISTANCE FROM START') var resetCount = 0; @@ -115,7 +114,7 @@ function testTargetDistanceFromStart() { dimensions: TARGET_DIMENSIONS, compoundShapeURL: COLLISION_HULL_URL, position: originalPositions[index], - // rotation:rotation, + rotation: rotation, script: scriptURL }; From bad5ea7d53ae5de7757655f2060d1600f6c46ac5 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 16:47:33 -0700 Subject: [PATCH 19/27] grouping the depth and stencil buffer into a single buffer --- libraries/gpu/src/gpu/GLBackend.cpp | 1 + .../render-utils/src/FramebufferCache.cpp | 31 ++----------------- libraries/render-utils/src/FramebufferCache.h | 5 +-- .../render-utils/src/RenderDeferredTask.cpp | 16 +++------- 4 files changed, 8 insertions(+), 45 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 37135ccd98..19edbaee5f 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -35,6 +35,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setViewTransform), (&::gpu::GLBackend::do_setProjectionTransform), (&::gpu::GLBackend::do_setViewportTransform), + (&::gpu::GLBackend::do_setDepthRangeTransform), (&::gpu::GLBackend::do_setPipeline), (&::gpu::GLBackend::do_setStateBlendFactor), diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 543078a4bd..5907d3fa27 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -35,9 +35,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _frameBufferSize = frameBufferSize; _primaryFramebufferFull.reset(); _primaryFramebufferDepthColor.reset(); - _primaryFramebufferStencilColor.reset(); _primaryDepthTexture.reset(); - _primaryStencilTexture.reset(); _primaryColorTexture.reset(); _primaryNormalTexture.reset(); _primarySpecularTexture.reset(); @@ -49,7 +47,6 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferFull = 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 width = _frameBufferSize.width(); @@ -66,24 +63,14 @@ void FramebufferCache::createPrimaryFramebuffer() { _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 _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 - auto stencilFormat = depthFormat; - // _primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler)); - _primaryStencilTexture = _primaryDepthTexture; - + _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); - - // _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); - _primaryFramebufferStencilColor = _primaryFramebufferDepthColor; - + _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); _selfieFramebuffer->setRenderBuffer(0, tex); @@ -103,13 +90,6 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { return _primaryFramebufferDepthColor; } -gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferStencilColor() { - if (!_primaryFramebufferStencilColor) { - createPrimaryFramebuffer(); - } - return _primaryFramebufferStencilColor; -} - gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { if (!_primaryDepthTexture) { createPrimaryFramebuffer(); @@ -117,13 +97,6 @@ gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { return _primaryDepthTexture; } -gpu::TexturePointer FramebufferCache::getPrimaryStencilTexture() { - if (!_primaryStencilTexture) { - createPrimaryFramebuffer(); - } - return _primaryStencilTexture; -} - gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { if (!_primaryColorTexture) { createPrimaryFramebuffer(); diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index 8951ceee80..e9a1bbf8e8 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -31,10 +31,8 @@ public: /// used for scene rendering. gpu::FramebufferPointer getPrimaryFramebuffer(); gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); - gpu::FramebufferPointer getPrimaryFramebufferStencilColor(); gpu::TexturePointer getPrimaryDepthTexture(); - gpu::TexturePointer getPrimaryStencilTexture(); gpu::TexturePointer getPrimaryColorTexture(); gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); @@ -60,9 +58,8 @@ private: gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferDepthColor; - gpu::FramebufferPointer _primaryFramebufferStencilColor; + gpu::TexturePointer _primaryDepthTexture; - gpu::TexturePointer _primaryStencilTexture; gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primarySpecularTexture; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index a85cd3fbca..73a487c2df 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -37,18 +37,12 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { - auto primaryFboStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); auto primaryFbo = DependencyManager::get()->getPrimaryFramebufferDepthColor(); batch.enableStereo(false); batch.setViewportTransform(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.clearFramebuffer( gpu::Framebuffer::BUFFER_COLOR0 | @@ -332,9 +326,8 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); - auto primaryDepth = DependencyManager::get()->getPrimaryDepthTexture(); - + auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); + batch.enableStereo(false); batch.setFramebuffer(primaryFboColorDepthStencil); @@ -342,7 +335,6 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren batch.setStateScissorRect(args->_viewport); batch.setPipeline(getOpaquePipeline()); - // batch.setResourceTexture(0, primaryDepth); batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(0, nullptr); @@ -369,12 +361,12 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto primaryFboColorStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); + auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); batch.enableSkybox(true); - batch.setFramebuffer(primaryFboColorStencil); + batch.setFramebuffer(primaryFboColorDepthStencil); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); From 3897716ff5730c0f3ffb21c963599857be7366ff Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 8 Oct 2015 17:49:55 -0700 Subject: [PATCH 20/27] Simplifying the DrawOpaqueStencil Pixel shader --- libraries/render-utils/src/drawOpaqueStencil.slf | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf index 033c2fec5a..43e9c5c27a 100644 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -12,16 +12,5 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -in vec2 varTexCoord0; - -//uniform sampler2D depthTexture; -out vec4 outFragColor; void main(void) { -/* float depth = texture(depthTexture, varTexCoord0.xy).r; - if (depth >= 1.0) { - discard; - }*/ - - outFragColor = vec4(1.0); - } From 1c2f86f8b72c47e71519e060541c5d1cbb5a8d82 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 8 Oct 2015 17:50:22 -0700 Subject: [PATCH 21/27] Fix for sending translation for non-animated joints. Only the JointState._defaultTranslation needs to be multiplied by the unitScale in JointState::translationIsDefault(). This was incorrectly flagging some non-animated joints as animated. --- libraries/animation/src/JointState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/animation/src/JointState.cpp b/libraries/animation/src/JointState.cpp index 28416b315d..5bc88ad57f 100644 --- a/libraries/animation/src/JointState.cpp +++ b/libraries/animation/src/JointState.cpp @@ -215,7 +215,7 @@ bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) c } 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 { From ad6fdc813f7013a4388188743178b9d31bce1af8 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 8 Oct 2015 17:50:41 -0700 Subject: [PATCH 22/27] alignment, targets, sounds, master script --- examples/toys/ping_pong_gun/createTargets.js | 25 ++-- examples/toys/ping_pong_gun/wallTarget.js | 28 ++-- unpublishedScripts/masterReset.js | 144 ++++++++++++++++++- 3 files changed, 170 insertions(+), 27 deletions(-) diff --git a/examples/toys/ping_pong_gun/createTargets.js b/examples/toys/ping_pong_gun/createTargets.js index eb4eaf70e3..9851451bc5 100644 --- a/examples/toys/ping_pong_gun/createTargets.js +++ b/examples/toys/ping_pong_gun/createTargets.js @@ -19,16 +19,16 @@ var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_g var RESET_DISTANCE = 1; var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target'; -var NUMBER_OF_TARGETS = 8; -var TARGETS_PER_ROW = 4; +var NUMBER_OF_TARGETS = 6; +var TARGETS_PER_ROW = 3; var TARGET_DIMENSIONS = { - x: 0.03, - y: 0.21, - z: 0.21 + x: 0.06, + y: 0.42, + z: 0.42 }; -var VERTICAL_SPACING = 0.5; +var VERTICAL_SPACING =TARGET_DIMENSIONS.y+ 0.5; var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.5; @@ -38,9 +38,6 @@ var startPosition = { z: 509.74 } -// var rotation = Quat.fromPitchYawRollDegrees(0, -54, 0.0); - -// var startPosition = center; var rotation = Quat.fromPitchYawRollDegrees(0,-55.25,0); var targetIntervalClearer = Entities.addEntity({ @@ -76,8 +73,8 @@ function addTargets() { var position = Vec3.sum(startPosition, multiplier); position.y = startPosition.y-(row*VERTICAL_SPACING); - print('position::: ' + JSON.stringify(position)); originalPositions.push(position); + var targetProperties = { name: 'Target', type: 'Model', @@ -90,21 +87,23 @@ function addTargets() { rotation: rotation, script: scriptURL }; + targets.push(Entities.addEntity(targetProperties)); } } function testTargetDistanceFromStart() { - print('TEST TARGET DISTANCE FROM START') - var resetCount = 0; 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) { - print('SHOULD RESET THIS! at ' + originalPositions[index]) + Entities.deleteEntity(target); + var targetProperties = { name: 'Target', type: 'Model', diff --git a/examples/toys/ping_pong_gun/wallTarget.js b/examples/toys/ping_pong_gun/wallTarget.js index cca35e5d6c..15b1b55362 100644 --- a/examples/toys/ping_pong_gun/wallTarget.js +++ b/examples/toys/ping_pong_gun/wallTarget.js @@ -10,25 +10,21 @@ // /*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() { - var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target'; - var defaultTargetData = { - originalPosition: null - }; - var _this; + function Target() { - _this=this; return; } Target.prototype = { + hasPlayedSound: false, preload: function(entityID) { this.entityID = entityID; - var targetData = getEntityCustomData(TARGET_USER_DATA_KEY, entityID, defaultTargetData); - this.originalPosition=targetData.originalPosition; - print('TARGET ORIGINAL POSITION:::'+targetData.originalPosition.x); + 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, @@ -40,7 +36,19 @@ y: -0.01, z: 0 } - }) + }); + + if (this.hasPlayedSound === false) { + print('PLAY SOUND!!!') + this.audioInjector = Audio.playSound(this.hitSound, { + position: position, + volume: 0.5 + }); + + this.hasPlayedSound = true; + + } + } }; diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 89f9fd3e1e..f5b6d18744 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -21,10 +21,11 @@ var pingPongScriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/pingP var wandScriptURL = Script.resolvePath("../examples/toys/bubblewand/wand.js"); var dollScriptURL = Script.resolvePath("../examples/toys/doll/doll.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 GRABBABLE_DATA_KEY = "grabbableKey"; @@ -109,12 +110,14 @@ MasterReset = function () { z: 503.91 }); + createTargets(); + } function deleteAllToys() { var entities = Entities.findEntities(MyAvatar.position, 100); - entities.forEach(function (entity) { + entities.forEach(function(entity) { //params: customKey, id, defaultValue var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; if (shouldReset === true) { @@ -299,14 +302,14 @@ MasterReset = function () { function testBallDistanceFromStart() { var resetCount = 0; - collidingBalls.forEach(function (ball, index) { + collidingBalls.forEach(function(ball, index) { var currentPosition = Entities.getEntityProperties(ball, "position").position; var originalPosition = originalBallPositions[index]; var distance = Vec3.subtract(originalPosition, currentPosition); var length = Vec3.length(distance); if (length > RESET_DISTANCE) { - Script.setTimeout(function () { + Script.setTimeout(function() { var newPosition = Entities.getEntityProperties(ball, "position").position; var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition)); if (moving < MINIMUM_MOVE_LENGTH) { @@ -341,6 +344,139 @@ MasterReset = function () { 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) { var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx"; From 772ea16c71fd042fcd371f14d3647f36698a1ca9 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 8 Oct 2015 17:52:33 -0700 Subject: [PATCH 23/27] cleanup --- examples/toys/ping_pong_gun/createTargets.js | 19 +++++++++++-------- unpublishedScripts/masterReset.js | 8 +++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/toys/ping_pong_gun/createTargets.js b/examples/toys/ping_pong_gun/createTargets.js index 9851451bc5..22329f90f0 100644 --- a/examples/toys/ping_pong_gun/createTargets.js +++ b/examples/toys/ping_pong_gun/createTargets.js @@ -28,7 +28,7 @@ var TARGET_DIMENSIONS = { z: 0.42 }; -var VERTICAL_SPACING =TARGET_DIMENSIONS.y+ 0.5; +var VERTICAL_SPACING = TARGET_DIMENSIONS.y + 0.5; var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.5; @@ -36,9 +36,9 @@ var startPosition = { x: 548.68, y: 497.30, z: 509.74 -} +}; -var rotation = Quat.fromPitchYawRollDegrees(0,-55.25,0); +var rotation = Quat.fromPitchYawRollDegrees(0, -55.25, 0); var targetIntervalClearer = Entities.addEntity({ name: 'Target Interval Clearer - delete me to clear', @@ -50,11 +50,12 @@ var targetIntervalClearer = Entities.addEntity({ green: 255, blue: 0 }, - rotation:rotation, + rotation: rotation, visible: false, collisionsWillMove: false, ignoreForCollisions: true, -}) +}); + var targets = []; var originalPositions = []; @@ -62,19 +63,21 @@ 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 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); + position.y = startPosition.y - (row * VERTICAL_SPACING); originalPositions.push(position); - + var targetProperties = { name: 'Target', type: 'Model', diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index f5b6d18744..c7fcd69e30 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -368,7 +368,7 @@ MasterReset = function() { x: 548.68, y: 497.30, z: 509.74 - } + }; var rotation = Quat.fromPitchYawRollDegrees(0, -55.25, 0); @@ -386,7 +386,8 @@ MasterReset = function() { visible: false, collisionsWillMove: false, ignoreForCollisions: true, - }) + }); + var targets = []; var originalPositions = []; @@ -395,6 +396,7 @@ MasterReset = function() { var i; var row = -1; for (i = 0; i < NUMBER_OF_TARGETS; i++) { + if (i % TARGETS_PER_ROW === 0) { row++; } @@ -404,7 +406,7 @@ MasterReset = function() { var multiplier = Vec3.multiply(spacer, vHat); var position = Vec3.sum(startPosition, multiplier); position.y = startPosition.y - (row * VERTICAL_SPACING); - + originalPositions.push(position); var targetProperties = { From 1332b8bef699400431228c93edfbe43425599db0 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 8 Oct 2015 17:58:58 -0700 Subject: [PATCH 24/27] remove logging --- examples/toys/ping_pong_gun/wallTarget.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/toys/ping_pong_gun/wallTarget.js b/examples/toys/ping_pong_gun/wallTarget.js index 15b1b55362..26e8d320a8 100644 --- a/examples/toys/ping_pong_gun/wallTarget.js +++ b/examples/toys/ping_pong_gun/wallTarget.js @@ -39,7 +39,6 @@ }); if (this.hasPlayedSound === false) { - print('PLAY SOUND!!!') this.audioInjector = Audio.playSound(this.hitSound, { position: position, volume: 0.5 From 1cd76bb93778f52b970d2aa1d16a557d1c5a8980 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 8 Oct 2015 18:17:24 -0700 Subject: [PATCH 25/27] fix for registration of meta types in Socket --- assignment-client/src/AssignmentClient.cpp | 2 -- libraries/networking/src/HifiSockAddr.cpp | 2 +- libraries/networking/src/HifiSockAddr.h | 2 +- libraries/networking/src/LimitedNodeList.h | 2 -- libraries/networking/src/udt/Socket.cpp | 4 ++-- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 708589c32f..f4f98114d0 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -39,8 +39,6 @@ const QString ASSIGNMENT_CLIENT_TARGET_NAME = "assignment-client"; const long long ASSIGNMENT_REQUEST_INTERVAL_MSECS = 1 * 1000; -int hifiSockAddrMeta = qRegisterMetaType("HifiSockAddr"); - AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QString assignmentPool, quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname, quint16 assignmentServerPort, quint16 assignmentMonitorPort) : diff --git a/libraries/networking/src/HifiSockAddr.cpp b/libraries/networking/src/HifiSockAddr.cpp index 7774cdd93c..e6c2f2985a 100644 --- a/libraries/networking/src/HifiSockAddr.cpp +++ b/libraries/networking/src/HifiSockAddr.cpp @@ -16,7 +16,7 @@ #include "HifiSockAddr.h" #include "NetworkLogging.h" -static int hifiSockAddrMetaTypeId = qMetaTypeId(); +static int hifiSockAddrMetaTypeId = qRegisterMetaType(); HifiSockAddr::HifiSockAddr() : _address(), diff --git a/libraries/networking/src/HifiSockAddr.h b/libraries/networking/src/HifiSockAddr.h index d678f93ac0..cb5d0acc12 100644 --- a/libraries/networking/src/HifiSockAddr.h +++ b/libraries/networking/src/HifiSockAddr.h @@ -94,6 +94,6 @@ namespace std { QHostAddress getLocalAddress(); -Q_DECLARE_METATYPE(HifiSockAddr) +Q_DECLARE_METATYPE(HifiSockAddr); #endif // hifi_HifiSockAddr_h diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 40c5390c7e..2488b0cf8c 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -60,8 +60,6 @@ const QHostAddress DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME = QHostAddress::Lo const QString USERNAME_UUID_REPLACEMENT_STATS_KEY = "$username"; -class HifiSockAddr; - using namespace tbb; typedef std::pair UUIDNodePair; typedef concurrent_unordered_map NodeHash; diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 50f2e67007..bc34c6e294 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -31,8 +31,8 @@ Socket::Socket(QObject* parent) : QObject(parent), _synTimer(new QTimer(this)) { - qRegisterMetaType(); - qRegisterMetaType(); + qRegisterMetaType("Packet*"); + qRegisterMetaType("PacketList*"); connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams); From 14ad1ed6be6749266a4620c9286e74da104cd73e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 8 Oct 2015 18:37:09 -0700 Subject: [PATCH 26/27] fix bug in AvatarData::toByteArray related code. this was causing a few joint translations that hadn't changed to be sent --- libraries/avatars/src/AvatarData.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 84bf4bec7b..a9ff9541ea 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -287,6 +287,7 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll) { #ifdef WANT_DEBUG int rotationSentCount = 0; + unsigned char* beforeRotations = destinationBuffer; #endif _lastSentJointData.resize(_jointData.size()); @@ -335,6 +336,7 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll) { #ifdef WANT_DEBUG int translationSentCount = 0; + unsigned char* beforeTranslations = destinationBuffer; #endif float maxTranslationDimension = 0.0; @@ -387,10 +389,15 @@ QByteArray AvatarData::toByteArray(bool cullSmallChanges, bool sendAll) { #ifdef WANT_DEBUG if (sendAll) { - qDebug() << "SENDING -- rotations:" << rotationSentCount << "translations:" << translationSentCount + qDebug() << "AvatarData::toByteArray" << cullSmallChanges << sendAll + << "rotations:" << rotationSentCount << "translations:" << translationSentCount << "largest:" << maxTranslationDimension << "radix:" << translationCompressionRadix - << "size:" << (int)(destinationBuffer - startPosition); + << "size:" + << (beforeRotations - startPosition) << "+" + << (beforeTranslations - beforeRotations) << "+" + << (destinationBuffer - beforeTranslations) << "=" + << (destinationBuffer - startPosition); } #endif @@ -409,7 +416,8 @@ void AvatarData::doneEncoding(bool cullSmallChanges) { _lastSentJointData[i].rotation = data.rotation; } } - + } + if (_lastSentJointData[i].translation != data.translation) { if (!cullSmallChanges || glm::distance(data.translation, _lastSentJointData[i].translation) > AVATAR_MIN_TRANSLATION) { if (data.translationSet) { From 8985427516e8f280dbc98fc42e18729c4d8a4a08 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 8 Oct 2015 19:47:15 -0700 Subject: [PATCH 27/27] maintain sent packets lock while re-sending packet --- libraries/networking/src/udt/SendQueue.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index d7e3bb2b65..01175d0a94 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -355,11 +355,12 @@ bool SendQueue::maybeResendPacket() { // we found the packet - grab it auto& resendPacket = *(it->second); + // send it off + sendPacket(resendPacket); + // unlock the sent packets sentLocker.unlock(); - // send it off - sendPacket(resendPacket); emit packetRetransmitted(); // Signal that we did resend a packet