From 5e8cad683e168d64f81f1e3498d9623d1f6ad064 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 30 Oct 2015 09:15:42 -0700 Subject: [PATCH 01/59] Playing with the gamma correction --- libraries/gpu/src/gpu/GLBackendOutput.cpp | 1 + libraries/model/src/model/TextureMap.cpp | 2 +- .../src/DeferredLightingEffect.cpp | 37 +++++++++++++++++-- .../render-utils/src/FramebufferCache.cpp | 22 +++++++++++ libraries/render-utils/src/FramebufferCache.h | 7 ++++ .../src/directional_skybox_light.slf | 3 ++ 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 2bcd7e31d8..3ada131266 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -194,6 +194,7 @@ void GLBackend::resetOutputStage() { _output._drawFBO = 0; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } + // glEnable(GL_FRAMEBUFFER_SRGB); } void GLBackend::do_setFramebuffer(Batch& batch, uint32 paramOffset) { diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index d443522a6f..fc8f42351c 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -119,7 +119,7 @@ gpu::Texture* TextureUsage::create2DTextureFromImage(const QImage& srcImage, con if ((image.width() > 0) && (image.height() > 0)) { // bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); - bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); + bool isLinearRGB = false; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE); gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); gpu::Element formatMip = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB)); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 57e3129ef8..977c4caea8 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -143,7 +143,37 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { { //auto VSFS = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); //auto PSBlit = gpu::StandardShaderLib::getDrawTexturePS(); - auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); + const char BlitTextureGamma_frag[] = R"SCRIBE(#version 410 core + // Generated on Sat Oct 24 09:34:37 2015 + // + // Draw texture 0 fetched at texcoord.xy + // + // Created by Sam Gateau on 6/22/2015 + // Copyright 2015 High Fidelity, Inc. + // + // Distributed under the Apache License, Version 2.0. + // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + // + + + uniform sampler2D colorMap; + + in vec2 varTexCoord0; + out vec4 outFragColor; + + void main(void) { + outFragColor = texture(colorMap, varTexCoord0); + if (gl_FragCoord.x > 1000) { + outFragColor.xyz = pow( outFragColor.xyz , vec3(1.0/2.2) ); + } + } + + )SCRIBE"; + auto blitPS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(BlitTextureGamma_frag))); + + //auto blitProgram = gpu::StandardShaderLib::getProgram(gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS, gpu::StandardShaderLib::getDrawTexturePS); + auto blitVS = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); + auto blitProgram = gpu::ShaderPointer(gpu::Shader::createProgram(blitVS, blitPS)); gpu::Shader::makeProgram(*blitProgram); auto blitState = std::make_shared(); blitState->setBlendFunction(true, @@ -375,7 +405,8 @@ void DeferredLightingEffect::render(RenderArgs* args) { QSize framebufferSize = framebufferCache->getFrameBufferSize(); // binding the first framebuffer - _copyFBO = framebufferCache->getFramebuffer(); + // _copyFBO = framebufferCache->getFramebuffer(); + _copyFBO = framebufferCache->getBeautyFramebuffer(); batch.setFramebuffer(_copyFBO); // Clearing it @@ -712,7 +743,7 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { args->_context->render(batch); }); - framebufferCache->releaseFramebuffer(_copyFBO); + // framebufferCache->releaseFramebuffer(_copyFBO); } void DeferredLightingEffect::setupTransparent(RenderArgs* args, int lightBufferUnit) { diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 5907d3fa27..59cc4eae66 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -41,6 +41,8 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _primarySpecularTexture.reset(); _selfieFramebuffer.reset(); _cachedFramebuffers.clear(); + _beautyTexture.reset(); + _beautyFramebuffer.reset(); } } @@ -74,6 +76,12 @@ void FramebufferCache::createPrimaryFramebuffer() { _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); + + + _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); +// _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); + _beautyFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _beautyFramebuffer->setRenderBuffer(0, _beautyTexture); } gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { @@ -118,6 +126,20 @@ gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { return _primarySpecularTexture; } +gpu::FramebufferPointer FramebufferCache::getBeautyFramebuffer() { + if (!_beautyFramebuffer) { + createPrimaryFramebuffer(); + } + return _beautyFramebuffer; +} + +gpu::TexturePointer FramebufferCache::getBeautyTexture() { + if (!_beautyTexture) { + createPrimaryFramebuffer(); + } + return _beautyTexture; +} + gpu::FramebufferPointer FramebufferCache::getFramebuffer() { if (_cachedFramebuffers.isEmpty()) { _cachedFramebuffers.push_back(gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_RGBA_32, _frameBufferSize.width(), _frameBufferSize.height()))); diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index e9a1bbf8e8..3fcfd54a6f 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -37,6 +37,9 @@ public: gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); + gpu::TexturePointer getBeautyTexture(); + gpu::FramebufferPointer getBeautyFramebuffer(); + /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); @@ -64,6 +67,10 @@ private: gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primarySpecularTexture; + + gpu::TexturePointer _beautyTexture; + gpu::FramebufferPointer _beautyFramebuffer; + gpu::FramebufferPointer _shadowFramebuffer; gpu::FramebufferPointer _selfieFramebuffer; diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index ca3efef047..6c4c8bf4ef 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -48,4 +48,7 @@ void main(void) { _fragColor = vec4(color, frag.normalVal.a); } + if (gl_FragCoord.y > 500) { + _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); + } } From ba56519354ded68afb666be18ecff96c1ebe91e7 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 16 Nov 2015 21:41:13 -0800 Subject: [PATCH 02/59] something happens --- libraries/gpu/src/gpu/GLBackendOutput.cpp | 2 +- libraries/gpu/src/gpu/GLBackendTexture.cpp | 79 +++++++++++++++++++ libraries/model/src/model/Material.h | 2 +- .../src/DeferredLightingEffect.cpp | 8 +- .../render-utils/src/FramebufferCache.cpp | 25 +++--- libraries/render-utils/src/FramebufferCache.h | 8 +- .../src/directional_ambient_light.slf | 4 + 7 files changed, 106 insertions(+), 22 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 3ada131266..93f2b998bb 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -194,7 +194,7 @@ void GLBackend::resetOutputStage() { _output._drawFBO = 0; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } - // glEnable(GL_FRAMEBUFFER_SRGB); + glEnable(GL_FRAMEBUFFER_SRGB); } void GLBackend::do_setFramebuffer(Batch& batch, uint32 paramOffset) { diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 71c5a83331..3a2323b8cc 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -117,6 +117,45 @@ public: break; case gpu::RGBA: texel.internalFormat = GL_RGBA; + switch (dstFormat.getType()) { + case gpu::UINT32: + case gpu::NUINT32: { + texel.internalFormat = GL_RGBA32UI; + break; + } + case gpu::INT32: + case gpu::NINT32: { + texel.internalFormat = GL_RGBA32I; + break; + } + case gpu::FLOAT: { + texel.internalFormat = GL_RGBA32F; + break; + } + case gpu::UINT16: + case gpu::NUINT16: { + texel.internalFormat = GL_RGBA16UI; + break; + } + case gpu::INT16: + case gpu::NINT16: { + texel.internalFormat = GL_RGBA16I; + break; + } + case gpu::HALF: { + texel.internalFormat = GL_RGBA16F; + break; + } + case gpu::UINT8: + case gpu::INT8: + case gpu::NUINT8: + case gpu::NINT8: { + break; + } + case gpu::NUM_TYPES: { // quiet compiler + Q_UNREACHABLE(); + } + } break; case gpu::SRGB: texel.internalFormat = GL_SRGB; @@ -240,6 +279,46 @@ public: break; case gpu::RGBA: texel.internalFormat = GL_RGBA; + switch (dstFormat.getType()) { + case gpu::UINT32: + case gpu::NUINT32: { + texel.internalFormat = GL_RGBA32UI; + break; + } + case gpu::INT32: + case gpu::NINT32: { + texel.internalFormat = GL_RGBA32I; + break; + } + case gpu::FLOAT: { + texel.internalFormat = GL_RGBA32F; + break; + } + case gpu::UINT16: + case gpu::NUINT16: { + texel.internalFormat = GL_RGBA16UI; + break; + } + case gpu::INT16: + case gpu::NINT16: { + texel.internalFormat = GL_RGBA16I; + break; + } + case gpu::HALF: { + texel.internalFormat = GL_RGBA16F; + break; + } + case gpu::UINT8: + case gpu::INT8: + case gpu::NUINT8: + case gpu::NINT8: { + break; + } + case gpu::NUM_TYPES: { // quiet compiler + Q_UNREACHABLE(); + } + } + break; case gpu::SRGB: texel.internalFormat = GL_SRGB; diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index b0725d9908..b1780e9e8a 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -242,7 +242,7 @@ public: float _gloss{0.1f}; Color _emissive{0.0f}; float _spare0{0.0f}; - glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4 + glm::vec4 _spareVec4{0.0f}; // for alignment lighting, Material size == Mat4x4 Schema() {} }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 977c4caea8..597e1daedc 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -370,7 +370,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu } void DeferredLightingEffect::prepare(RenderArgs* args) { - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); batch.setStateScissorRect(args->_viewport); @@ -387,7 +387,7 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { gpu::FramebufferPointer _copyFBO; void DeferredLightingEffect::render(RenderArgs* args) { - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { // Allocate the parameters buffer used by all the deferred shaders if (!_deferredTransformBuffer[0]._buffer) { @@ -406,7 +406,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { // binding the first framebuffer // _copyFBO = framebufferCache->getFramebuffer(); - _copyFBO = framebufferCache->getBeautyFramebuffer(); + _copyFBO = framebufferCache->getLightingFramebuffer(); batch.setFramebuffer(_copyFBO); // Clearing it @@ -713,7 +713,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { void DeferredLightingEffect::copyBack(RenderArgs* args) { auto framebufferCache = DependencyManager::get(); - gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); QSize framebufferSize = framebufferCache->getFrameBufferSize(); diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 59cc4eae66..3faee3cc09 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -41,8 +41,8 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _primarySpecularTexture.reset(); _selfieFramebuffer.reset(); _cachedFramebuffers.clear(); - _beautyTexture.reset(); - _beautyFramebuffer.reset(); + _lightingTexture.reset(); + _lightingFramebuffer.reset(); } } @@ -78,10 +78,11 @@ void FramebufferCache::createPrimaryFramebuffer() { _selfieFramebuffer->setRenderBuffer(0, tex); - _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); -// _beautyTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); - _beautyFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); - _beautyFramebuffer->setRenderBuffer(0, _beautyTexture); + // _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); + _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); + // _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::HALF, gpu::RGBA), width, height, defaultSampler)); + _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); } gpu::FramebufferPointer FramebufferCache::getPrimaryFramebuffer() { @@ -126,18 +127,18 @@ gpu::TexturePointer FramebufferCache::getPrimarySpecularTexture() { return _primarySpecularTexture; } -gpu::FramebufferPointer FramebufferCache::getBeautyFramebuffer() { - if (!_beautyFramebuffer) { +gpu::FramebufferPointer FramebufferCache::getLightingFramebuffer() { + if (!_lightingFramebuffer) { createPrimaryFramebuffer(); } - return _beautyFramebuffer; + return _lightingFramebuffer; } -gpu::TexturePointer FramebufferCache::getBeautyTexture() { - if (!_beautyTexture) { +gpu::TexturePointer FramebufferCache::getLightingTexture() { + if (!_lightingTexture) { createPrimaryFramebuffer(); } - return _beautyTexture; + return _lightingTexture; } gpu::FramebufferPointer FramebufferCache::getFramebuffer() { diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index 3fcfd54a6f..ba7496cf49 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -37,8 +37,8 @@ public: gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); - gpu::TexturePointer getBeautyTexture(); - gpu::FramebufferPointer getBeautyFramebuffer(); + gpu::TexturePointer getLightingTexture(); + gpu::FramebufferPointer getLightingFramebuffer(); /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); @@ -68,8 +68,8 @@ private: gpu::TexturePointer _primarySpecularTexture; - gpu::TexturePointer _beautyTexture; - gpu::FramebufferPointer _beautyFramebuffer; + gpu::TexturePointer _lightingTexture; + gpu::FramebufferPointer _lightingFramebuffer; gpu::FramebufferPointer _shadowFramebuffer; diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 52ecc71a14..b83f06ee12 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -47,4 +47,8 @@ void main(void) { frag.gloss); _fragColor = vec4(color, frag.normalVal.a); } + + if (gl_FragCoord.y > 500) { + _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); + } } From d1847136b8c18272e808846d9d4306953387cacf Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 2 Dec 2015 16:15:03 -0800 Subject: [PATCH 03/59] Clean up --- libraries/model/src/model/Material.h | 2 +- libraries/render-utils/src/DeferredLightingEffect.cpp | 4 ++-- libraries/render-utils/src/FramebufferCache.cpp | 4 ++-- libraries/script-engine/src/ScriptEngine.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/model/src/model/Material.h b/libraries/model/src/model/Material.h index b1780e9e8a..b0725d9908 100755 --- a/libraries/model/src/model/Material.h +++ b/libraries/model/src/model/Material.h @@ -242,7 +242,7 @@ public: float _gloss{0.1f}; Color _emissive{0.0f}; float _spare0{0.0f}; - glm::vec4 _spareVec4{0.0f}; // for alignment lighting, Material size == Mat4x4 + glm::vec4 _spareVec4{0.0f}; // for alignment beauty, Material size == Mat4x4 Schema() {} }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 597e1daedc..30d83c489b 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -370,7 +370,7 @@ void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radiu } void DeferredLightingEffect::prepare(RenderArgs* args) { - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); batch.setStateScissorRect(args->_viewport); @@ -387,7 +387,7 @@ void DeferredLightingEffect::prepare(RenderArgs* args) { gpu::FramebufferPointer _copyFBO; void DeferredLightingEffect::render(RenderArgs* args) { - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { // Allocate the parameters buffer used by all the deferred shaders if (!_deferredTransformBuffer[0]._buffer) { diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index 3faee3cc09..cf8b20dc36 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -78,8 +78,8 @@ void FramebufferCache::createPrimaryFramebuffer() { _selfieFramebuffer->setRenderBuffer(0, tex); - // _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); - _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); + _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA), width, height, defaultSampler)); + //_lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::SRGBA), width, height, defaultSampler)); // _lightingTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::HALF, gpu::RGBA), width, height, defaultSampler)); _lightingFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); _lightingFramebuffer->setRenderBuffer(0, _lightingTexture); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 49009a3ad2..c40634af37 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -82,7 +82,7 @@ void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) { } Q_DECLARE_METATYPE(controller::InputController*) -static int inputControllerPointerId = qRegisterMetaType(); +//static int inputControllerPointerId = qRegisterMetaType(); QScriptValue inputControllerToScriptValue(QScriptEngine *engine, controller::InputController* const &in) { return engine->newQObject(in); From 4fcf207a6a6b96858c9c99b687129fa115c2c7c0 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 2 Dec 2015 16:49:39 -0800 Subject: [PATCH 04/59] Back pedaling? --- libraries/render-utils/src/DeferredLightingEffect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 30d83c489b..d7d434be97 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -713,7 +713,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { void DeferredLightingEffect::copyBack(RenderArgs* args) { auto framebufferCache = DependencyManager::get(); - gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); QSize framebufferSize = framebufferCache->getFrameBufferSize(); From fb7943efae6b77f521a278a80b777e8b5e0d4745 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Feb 2016 12:24:10 -0800 Subject: [PATCH 05/59] new start --- .../DomainContent/Home/fishTank/flock.js | 182 ++++++++++++++++++ .../DomainContent/Home/fishTank/tank.js | 72 +++++++ 2 files changed, 254 insertions(+) create mode 100644 unpublishedScripts/DomainContent/Home/fishTank/flock.js create mode 100644 unpublishedScripts/DomainContent/Home/fishTank/tank.js diff --git a/unpublishedScripts/DomainContent/Home/fishTank/flock.js b/unpublishedScripts/DomainContent/Home/fishTank/flock.js new file mode 100644 index 0000000000..b6f5789aff --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/fishTank/flock.js @@ -0,0 +1,182 @@ +// +// flockOfFish.js +// examples +// +// Philip Rosedale +// Copyright 2016 High Fidelity, Inc. +// Fish smimming around in a space in front of you +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + +var LIFETIME = 300; // Fish live for 5 minutes +var NUM_FISH = 20; +var TANK_WIDTH = 3.0; +var TANK_HEIGHT = 1.0; +var FISH_WIDTH = 0.03; +var FISH_LENGTH = 0.15; +var MAX_SIGHT_DISTANCE = 0.8; +var MIN_SEPARATION = 0.15; +var AVOIDANCE_FORCE = 0.2; +var COHESION_FORCE = 0.05; +var ALIGNMENT_FORCE = 0.05; +var SWIMMING_FORCE = 0.05; +var SWIMMING_SPEED = 1.5; + +var fishLoaded = false; +var fish = []; + +var lowerCorner = { x: 0, y: 0, z: 0 }; +var upperCorner = { x: 0, y: 0, z: 0 }; + +function randomVector(scale) { + return { x: Math.random() * scale - scale / 2.0, y: Math.random() * scale - scale / 2.0, z: Math.random() * scale - scale / 2.0 }; +} + +function updateFish(deltaTime) { + if (!Entities.serversExist() || !Entities.canRez()) { + return; + } + if (!fishLoaded) { + loadFish(NUM_FISH); + fishLoaded = true; + return; + } + + var averageVelocity = { x: 0, y: 0, z: 0 }; + var averagePosition = { x: 0, y: 0, z: 0 }; + var birdPositionsCounted = 0; + var birdVelocitiesCounted = 0; + + // First pre-load an array with properties on all the other fish so our per-fish loop + // isn't doing it. + var flockProperties = []; + for (var i = 0; i < fish.length; i++) { + var otherProps = Entities.getEntityProperties(fish[i].entityId, ["position", "velocity", "rotation"]); + flockProperties.push(otherProps); + } + + for (var i = 0; i < fish.length; i++) { + if (fish[i].entityId) { + // Get only the properties we need, because that is faster + var properties = flockProperties[i]; + // If fish has been deleted, bail + if (properties.id != fish[i].entityId) { + fish[i].entityId = false; + return; + } + + // Store old values so we can check if they have changed enough to update + var velocity = { x: properties.velocity.x, y: properties.velocity.y, z: properties.velocity.z }; + var position = { x: properties.position.x, y: properties.position.y, z: properties.position.z }; + averageVelocity = { x: 0, y: 0, z: 0 }; + averagePosition = { x: 0, y: 0, z: 0 }; + + var othersCounted = 0; + for (var j = 0; j < fish.length; j++) { + if (i != j) { + // Get only the properties we need, because that is faster + var otherProps = flockProperties[j]; + var separation = Vec3.distance(properties.position, otherProps.position); + if (separation < MAX_SIGHT_DISTANCE) { + averageVelocity = Vec3.sum(averageVelocity, otherProps.velocity); + averagePosition = Vec3.sum(averagePosition, otherProps.position); + othersCounted++; + } + if (separation < MIN_SEPARATION) { + var pushAway = Vec3.multiply(Vec3.normalize(Vec3.subtract(properties.position, otherProps.position)), AVOIDANCE_FORCE); + velocity = Vec3.sum(velocity, pushAway); + } + } + } + + if (othersCounted > 0) { + averageVelocity = Vec3.multiply(averageVelocity, 1.0 / othersCounted); + averagePosition = Vec3.multiply(averagePosition, 1.0 / othersCounted); + // Alignment: Follow group's direction and speed + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(averageVelocity), Vec3.length(velocity)), ALIGNMENT_FORCE); + // Cohesion: Steer towards center of flock + var towardCenter = Vec3.subtract(averagePosition, position); + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardCenter), Vec3.length(velocity)), COHESION_FORCE); + } + + // Try to swim at a constant speed + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(velocity), SWIMMING_SPEED), SWIMMING_FORCE); + + // Keep fish in their 'tank' + if (position.x < lowerCorner.x) { + position.x = lowerCorner.x; + velocity.x *= -1.0; + } else if (position.x > upperCorner.x) { + position.x = upperCorner.x; + velocity.x *= -1.0; + } + if (position.y < lowerCorner.y) { + position.y = lowerCorner.y; + velocity.y *= -1.0; + } else if (position.y > upperCorner.y) { + position.y = upperCorner.y; + velocity.y *= -1.0; + } + if (position.z < lowerCorner.z) { + position.z = lowerCorner.z; + velocity.z *= -1.0; + } else if (position.z > upperCorner.z) { + position.z = upperCorner.z; + velocity.z *= -1.0; + } + + // Orient in direction of velocity + var rotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, velocity); + var VELOCITY_FOLLOW_RATE = 0.30; + + // Only update properties if they have changed, to save bandwidth + var MIN_POSITION_CHANGE_FOR_UPDATE = 0.001; + if (Vec3.distance(properties.position, position) < MIN_POSITION_CHANGE_FOR_UPDATE) { + Entities.editEntity(fish[i].entityId, { velocity: velocity, rotation: Quat.mix(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) }); + } else { + Entities.editEntity(fish[i].entityId, { position: position, velocity: velocity, rotation: Quat.slerp(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) }); + } + } + } +} + +// Connect a call back that happens every frame +Script.update.connect(updateFish); + +// Delete our little friends if script is stopped +Script.scriptEnding.connect(function() { + for (var i = 0; i < fish.length; i++) { + Entities.deleteEntity(fish[i].entityId); + } +}); + +var STARTING_FRACTION = 0.25; +function loadFish(howMany) { + var center = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2 * TANK_WIDTH)); + lowerCorner = { x: center.x - TANK_WIDTH / 2, y: center.y, z: center.z - TANK_WIDTH / 2 }; + upperCorner = { x: center.x + TANK_WIDTH / 2, y: center.y + TANK_HEIGHT, z: center.z + TANK_WIDTH / 2 }; + + for (var i = 0; i < howMany; i++) { + var position = { + x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.x - lowerCorner.x) * STARTING_FRACTION, + y: lowerCorner.y + (upperCorner.y - lowerCorner.y) / 2.0 + (Math.random() - 0.5) * (upperCorner.y - lowerCorner.y) * STARTING_FRACTION, + z: lowerCorner.z + (upperCorner.z - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.z - lowerCorner.z) * STARTING_FRACTION + }; + + fish.push({ + entityId: Entities.addEntity({ + type: "Box", + position: position, + rotation: { x: 0, y: 0, z: 0, w: 1 }, + dimensions: { x: FISH_WIDTH, y: FISH_WIDTH, z: FISH_LENGTH }, + velocity: { x: SWIMMING_SPEED, y: SWIMMING_SPEED, z: SWIMMING_SPEED }, + damping: 0.0, + dynamic: false, + lifetime: LIFETIME, + color: { red: 0, green: 255, blue: 255 } + }) + }); + } +} diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js new file mode 100644 index 0000000000..56d892c2e9 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -0,0 +1,72 @@ +(function() { + + function FishTank() { + _this = this; + } + + FishTank.prototype = { + + preload: function(entityID) { + print("preload"); + this.entityID = entityID; + //we only need to do this once since tank is static + _this.currentProperties = Entities.getEntityProperties(entityID); + Script.update.connect(this.update) + }, + + unload: function() { + + }, + + update: function() { + _this.updateWithoutSort(); + }, + + updateWithSort: function() { + var avatars = AvatarList.getAvatarIdentifiers(); + var distances = []; + avatars.forEach(function(avatar) { + var _avatar = AvatarList.getAvatar(avatar); + var distanceFromTank = Vec3.distance(_this.currentProperties.position, _avatar.position); + distances.push([distanceFromTank, avatar]); + }) + var sortedDistances = distances.sort(function(a, b) { + return a[0] - b[0] + }); + //only the closest person should run the update loop + if (sortedDistances[0][1] !== MyAvatar.sessionUUID) { + return; + } else { + + } + }, + + updateWithoutSort: function() { + var avatars = AvatarList.getAvatarIdentifiers(); + var minDistance = 100000; + var closest; + print('AVATARS' + avatars) + avatars.forEach(function(avatar) { + var _avatar = AvatarList.getAvatar(avatar); + var distanceFromTank = Vec3.distance(_this.currentProperties.position, _avatar.position); + if (distanceFromTank < minDistance) { + minDistance = distanceFromTank; + closest = avatar; + } + }) + //only the closest person should run the update loop + // print('closest:', closest) + // print('me', MyAvatar.sessionUUID) + if (closest !== MyAvatar.sessionUUID) { + //print('not me') + return; + } else { + print('i should run this entity because im closest:' + _this.entityID) + } + } + + + }; + + return new FishTank(); +}); \ No newline at end of file From 19a72871ac12efaf497f83a0eef6d3fcb2d26d9c Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Feb 2016 17:17:15 -0800 Subject: [PATCH 06/59] fishes run by an entity with a handoff --- .../Home/fishTank/createFishTank.js | 53 +++ .../DomainContent/Home/fishTank/tank.js | 415 ++++++++++++++++-- 2 files changed, 420 insertions(+), 48 deletions(-) create mode 100644 unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js new file mode 100644 index 0000000000..f2cbc95246 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -0,0 +1,53 @@ +var fishtank; + +var TANK_DIMENSIONS = { + x: 1, + y: 1, + z: 2 +}; + +var TANK_WIDTH = 3.0; +var TANK_HEIGHT = 1.0; + +var DEBUG_COLOR = { + red: 255, + green: 0, + blue: 255 +} + +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2 * TANK_WIDTH)); + +var TANK_POSITION = center; + +var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) + +function createFishTank() { + var tankProperties = { + name: 'hifi-home-fishtank', + type: 'Box', + dimensions: TANK_DIMENSIONS, + position: TANK_POSITION, + color: DEBUG_COLOR, + collisionless: true, + script: TANK_SCRIPT, + userData: JSON.stringify({ + 'hifi-home-fishtank': { + fishLoaded: false + }, + grabbableKey: { + grabbable: false + } + }), + visible:false + } + + fishTank = Entities.addEntity(tankProperties); +} + +function cleanup() { + Entities.deleteEntity(fishTank); +} + +createFishTank(); + +Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 56d892c2e9..d6ca635c7c 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -1,72 +1,391 @@ (function() { + Script.include('../../../../examples/libraries/virtualBaton.js?' + Math.random()); + Script.include('../../../../examples/libraries/utils.js?' + Math.random()); + var baton; + var iOwn = false; + var _entityID; + var _this; + var connected = false; + function FishTank() { _this = this; } - FishTank.prototype = { + function startUpdate() { + print('START UPDATE!!') + iOwn = true; + Script.update.connect(_this.update); + connected = true; + } + function stopUpdateAndReclaim() { + print('i released the object ' + _entityID) + iOwn = false; + baton.claim(startUpdate, stopUpdateAndReclaim); + if (connected === true) { + Script.update.disconnect(_this.update); + } + } + + FishTank.prototype = { + fish:null, + findFishInTank: function() { + + // print('looking for a fish. in the tank') + var res = Entities.findEntities(_this.currentProperties.position, 8); + var fish = []; + + res.forEach(function(f) { + var props = Entities.getEntityProperties(f, 'name'); + if (props.name.indexOf('hifi-fishtank-fish') > -1) { + fish.push(f); + } + }) + + print('fish? ' + fish.length) + return fish; + }, + initialize: function(entityID) { + print('JBP nav button should initialize' + entityID) + var properties = Entities.getEntityProperties(entityID); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + _this.initTimeout = Script.setTimeout(function() { + print('JBP no user data yet, try again in one second') + _this.initialize(entityID); + }, 1000) + + } else { + + print('JBP userdata before parse attempt' + properties.userData) + _this.userData = null; + try { + _this.userData = JSON.parse(properties.userData); + } catch (err) { + print('JBP error parsing json'); + print('JBP properties are:' + properties.userData); + return; + } + print('after parse') + _this.currentProperties = Entities.getEntityProperties(entityID); + baton = virtualBaton({ + batonName: 'io.highfidelity.fishtank:' + entityID, // One winner for each entity + }); + + stopUpdateAndReclaim(); + + } + }, preload: function(entityID) { print("preload"); this.entityID = entityID; - //we only need to do this once since tank is static - _this.currentProperties = Entities.getEntityProperties(entityID); - Script.update.connect(this.update) + _entityID = entityID; + this.initialize(entityID); + this.initTimeout = null; + }, unload: function() { + if (baton) { + baton.release(function() {}); + } + if (connected === true) { + Script.update.disconnect(_this.update); + } }, update: function() { - _this.updateWithoutSort(); - }, - - updateWithSort: function() { - var avatars = AvatarList.getAvatarIdentifiers(); - var distances = []; - avatars.forEach(function(avatar) { - var _avatar = AvatarList.getAvatar(avatar); - var distanceFromTank = Vec3.distance(_this.currentProperties.position, _avatar.position); - distances.push([distanceFromTank, avatar]); - }) - var sortedDistances = distances.sort(function(a, b) { - return a[0] - b[0] - }); - //only the closest person should run the update loop - if (sortedDistances[0][1] !== MyAvatar.sessionUUID) { - return; - } else { - - } - }, - - updateWithoutSort: function() { - var avatars = AvatarList.getAvatarIdentifiers(); - var minDistance = 100000; - var closest; - print('AVATARS' + avatars) - avatars.forEach(function(avatar) { - var _avatar = AvatarList.getAvatar(avatar); - var distanceFromTank = Vec3.distance(_this.currentProperties.position, _avatar.position); - if (distanceFromTank < minDistance) { - minDistance = distanceFromTank; - closest = avatar; - } - }) - //only the closest person should run the update loop - // print('closest:', closest) - // print('me', MyAvatar.sessionUUID) - if (closest !== MyAvatar.sessionUUID) { - //print('not me') - return; - } else { - print('i should run this entity because im closest:' + _this.entityID) + if (iOwn === false) { + return } + //print('i am the owner!') + //do stuff + updateFish(); } - }; + // + // flockOfFish.js + // examples + // + // Philip Rosedale + // Copyright 2016 High Fidelity, Inc. + // Fish smimming around in a space in front of you + // + // Distributed under the Apache License, Version 2.0. + // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + var FISHTANK_USERDATA_KEY = 'hifi-home-fishtank' + + var LIFETIME = 300; // Fish live for 5 minutes + var NUM_FISH = 20; + var TANK_WIDTH = 3.0; + var TANK_HEIGHT = 1.0; + var FISH_WIDTH = 0.03; + var FISH_LENGTH = 0.15; + var MAX_SIGHT_DISTANCE = 0.8; + var MIN_SEPARATION = 0.15; + var AVOIDANCE_FORCE = 0.2; + var COHESION_FORCE = 0.05; + var ALIGNMENT_FORCE = 0.05; + var SWIMMING_FORCE = 0.05; + var SWIMMING_SPEED = 1.5; + + var fishLoaded = false; + var fish = []; + + var lowerCorner = { + x: 0, + y: 0, + z: 0 + }; + var upperCorner = { + x: 0, + y: 0, + z: 0 + }; + + function randomVector(scale) { + return { + x: Math.random() * scale - scale / 2.0, + y: Math.random() * scale - scale / 2.0, + z: Math.random() * scale - scale / 2.0 + }; + } + + function updateFish(deltaTime) { + + if (!Entities.serversExist() || !Entities.canRez()) { + return; + } + print('has fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) + if (_this.userData['hifi-home-fishtank'].fishLoaded === false) { + print('NO FISH NO FISH NO FISH') + loadFish(NUM_FISH); + setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, { + fishLoaded: true + }); + _this.userData['hifi-home-fishtank'].fishLoaded = true; + _this.fish = _this.findFishInTank(); + return; + } + else{ + if(this.fish===null){ + _this.fish = _this.findFishInTank(); + } + + } + // if (!fishLoaded) { + // fishLoaded = true; + // loadFish(NUM_FISH); + // setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, { + // fishLoaded: true + // }); + // _this.userData['hifi-home-fishtank'].fishLoaded=true; + // _this.fish = _this.findFishInTank(); + // return; + // } + + + var fish = _this.fish; + var averageVelocity = { + x: 0, + y: 0, + z: 0 + }; + var averagePosition = { + x: 0, + y: 0, + z: 0 + }; + var birdPositionsCounted = 0; + var birdVelocitiesCounted = 0; + + // First pre-load an array with properties on all the other fish so our per-fish loop + // isn't doing it. + var flockProperties = []; + for (var i = 0; i < fish.length; i++) { + var otherProps = Entities.getEntityProperties(fish[i], ["position", "velocity", "rotation"]); + flockProperties.push(otherProps); + } + + for (var i = 0; i < fish.length; i++) { + if (fish[i]) { + // Get only the properties we need, because that is faster + var properties = flockProperties[i]; + // If fish has been deleted, bail + if (properties.id != fish[i]) { + fish[i] = false; + return; + } + + // Store old values so we can check if they have changed enough to update + var velocity = { + x: properties.velocity.x, + y: properties.velocity.y, + z: properties.velocity.z + }; + var position = { + x: properties.position.x, + y: properties.position.y, + z: properties.position.z + }; + averageVelocity = { + x: 0, + y: 0, + z: 0 + }; + averagePosition = { + x: 0, + y: 0, + z: 0 + }; + + var othersCounted = 0; + for (var j = 0; j < fish.length; j++) { + if (i != j) { + // Get only the properties we need, because that is faster + var otherProps = flockProperties[j]; + var separation = Vec3.distance(properties.position, otherProps.position); + if (separation < MAX_SIGHT_DISTANCE) { + averageVelocity = Vec3.sum(averageVelocity, otherProps.velocity); + averagePosition = Vec3.sum(averagePosition, otherProps.position); + othersCounted++; + } + if (separation < MIN_SEPARATION) { + var pushAway = Vec3.multiply(Vec3.normalize(Vec3.subtract(properties.position, otherProps.position)), AVOIDANCE_FORCE); + velocity = Vec3.sum(velocity, pushAway); + } + } + } + + if (othersCounted > 0) { + averageVelocity = Vec3.multiply(averageVelocity, 1.0 / othersCounted); + averagePosition = Vec3.multiply(averagePosition, 1.0 / othersCounted); + // Alignment: Follow group's direction and speed + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(averageVelocity), Vec3.length(velocity)), ALIGNMENT_FORCE); + // Cohesion: Steer towards center of flock + var towardCenter = Vec3.subtract(averagePosition, position); + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardCenter), Vec3.length(velocity)), COHESION_FORCE); + } + + // Try to swim at a constant speed + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(velocity), SWIMMING_SPEED), SWIMMING_FORCE); + + // Keep fish in their 'tank' + if (position.x < lowerCorner.x) { + position.x = lowerCorner.x; + velocity.x *= -1.0; + } else if (position.x > upperCorner.x) { + position.x = upperCorner.x; + velocity.x *= -1.0; + } + if (position.y < lowerCorner.y) { + position.y = lowerCorner.y; + velocity.y *= -1.0; + } else if (position.y > upperCorner.y) { + position.y = upperCorner.y; + velocity.y *= -1.0; + } + if (position.z < lowerCorner.z) { + position.z = lowerCorner.z; + velocity.z *= -1.0; + } else if (position.z > upperCorner.z) { + position.z = upperCorner.z; + velocity.z *= -1.0; + } + + // Orient in direction of velocity + var rotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, velocity); + var VELOCITY_FOLLOW_RATE = 0.30; + + // Only update properties if they have changed, to save bandwidth + var MIN_POSITION_CHANGE_FOR_UPDATE = 0.001; + if (Vec3.distance(properties.position, position) < MIN_POSITION_CHANGE_FOR_UPDATE) { + Entities.editEntity(fish[i], { + velocity: velocity, + rotation: Quat.mix(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) + }); + } else { + Entities.editEntity(fish[i], { + position: position, + velocity: velocity, + rotation: Quat.slerp(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) + }); + } + } + } + } + + var STARTING_FRACTION = 0.25; + + function loadFish(howMany) { + print('LOADING FISH: ' + howMany) + // var center = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2 * TANK_WIDTH)); + + + var center = _this.currentProperties.position; + + lowerCorner = { + x: center.x - (TANK_WIDTH / 2), + y: center.y, + z: center.z - (TANK_WIDTH / 2) + }; + upperCorner = { + x: center.x + (TANK_WIDTH / 2), + y: center.y + TANK_HEIGHT, + z: center.z + (TANK_WIDTH / 2) + }; + + var fish = []; + + for (var i = 0; i < howMany; i++) { + var position = { + x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.x - lowerCorner.x) * STARTING_FRACTION, + y: lowerCorner.y + (upperCorner.y - lowerCorner.y) / 2.0 + (Math.random() - 0.5) * (upperCorner.y - lowerCorner.y) * STARTING_FRACTION, + z: lowerCorner.z + (upperCorner.z - lowerCorner.z) / 2.0 + (Math.random() - 0.5) * (upperCorner.z - lowerCorner.z) * STARTING_FRACTION + }; + + + fish.push( + Entities.addEntity({ + name: 'hifi-fishtank-fish' + _this.entityID, + type: "Box", + position: position, + rotation: { + x: 0, + y: 0, + z: 0, + w: 1 + }, + dimensions: { + x: FISH_WIDTH, + y: FISH_WIDTH, + z: FISH_LENGTH + }, + // velocity: { + // x: SWIMMING_SPEED, + // y: SWIMMING_SPEED, + // z: SWIMMING_SPEED + // }, + damping: 0.1, + dynamic: false, + lifetime: LIFETIME, + color: { + red: 0, + green: 255, + blue: 255 + } + }) + ); + + + } + print('initial fish::' + fish.length) + } + + return new FishTank(); }); \ No newline at end of file From 03a4de4f9234dd5ccfcf0a312d1377b948844f48 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Feb 2016 18:10:12 -0800 Subject: [PATCH 07/59] branch --- .../Home/fishTank/createFishTank.js | 17 +- .../DomainContent/Home/fishTank/flock.js | 182 ------------------ .../DomainContent/Home/fishTank/tank.js | 74 ++++--- 3 files changed, 60 insertions(+), 213 deletions(-) delete mode 100644 unpublishedScripts/DomainContent/Home/fishTank/flock.js diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index f2cbc95246..ddcf0e870a 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,13 +1,13 @@ var fishtank; var TANK_DIMENSIONS = { - x: 1, - y: 1, - z: 2 + x: 1.3393, + y: 1.3515, + z: 3.5914 }; -var TANK_WIDTH = 3.0; -var TANK_HEIGHT = 1.0; +var TANK_WIDTH = TANK_DIMENSIONS.z; +var TANK_HEIGHT = TANK_DIMENSIONS.y; var DEBUG_COLOR = { red: 255, @@ -21,10 +21,13 @@ var TANK_POSITION = center; var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) +var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx"; + function createFishTank() { var tankProperties = { name: 'hifi-home-fishtank', - type: 'Box', + type: 'Model', + modelURL:TANK_MODEL_URL, dimensions: TANK_DIMENSIONS, position: TANK_POSITION, color: DEBUG_COLOR, @@ -38,7 +41,7 @@ function createFishTank() { grabbable: false } }), - visible:false + visible:true } fishTank = Entities.addEntity(tankProperties); diff --git a/unpublishedScripts/DomainContent/Home/fishTank/flock.js b/unpublishedScripts/DomainContent/Home/fishTank/flock.js deleted file mode 100644 index b6f5789aff..0000000000 --- a/unpublishedScripts/DomainContent/Home/fishTank/flock.js +++ /dev/null @@ -1,182 +0,0 @@ -// -// flockOfFish.js -// examples -// -// Philip Rosedale -// Copyright 2016 High Fidelity, Inc. -// Fish smimming around in a space in front of you -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - - -var LIFETIME = 300; // Fish live for 5 minutes -var NUM_FISH = 20; -var TANK_WIDTH = 3.0; -var TANK_HEIGHT = 1.0; -var FISH_WIDTH = 0.03; -var FISH_LENGTH = 0.15; -var MAX_SIGHT_DISTANCE = 0.8; -var MIN_SEPARATION = 0.15; -var AVOIDANCE_FORCE = 0.2; -var COHESION_FORCE = 0.05; -var ALIGNMENT_FORCE = 0.05; -var SWIMMING_FORCE = 0.05; -var SWIMMING_SPEED = 1.5; - -var fishLoaded = false; -var fish = []; - -var lowerCorner = { x: 0, y: 0, z: 0 }; -var upperCorner = { x: 0, y: 0, z: 0 }; - -function randomVector(scale) { - return { x: Math.random() * scale - scale / 2.0, y: Math.random() * scale - scale / 2.0, z: Math.random() * scale - scale / 2.0 }; -} - -function updateFish(deltaTime) { - if (!Entities.serversExist() || !Entities.canRez()) { - return; - } - if (!fishLoaded) { - loadFish(NUM_FISH); - fishLoaded = true; - return; - } - - var averageVelocity = { x: 0, y: 0, z: 0 }; - var averagePosition = { x: 0, y: 0, z: 0 }; - var birdPositionsCounted = 0; - var birdVelocitiesCounted = 0; - - // First pre-load an array with properties on all the other fish so our per-fish loop - // isn't doing it. - var flockProperties = []; - for (var i = 0; i < fish.length; i++) { - var otherProps = Entities.getEntityProperties(fish[i].entityId, ["position", "velocity", "rotation"]); - flockProperties.push(otherProps); - } - - for (var i = 0; i < fish.length; i++) { - if (fish[i].entityId) { - // Get only the properties we need, because that is faster - var properties = flockProperties[i]; - // If fish has been deleted, bail - if (properties.id != fish[i].entityId) { - fish[i].entityId = false; - return; - } - - // Store old values so we can check if they have changed enough to update - var velocity = { x: properties.velocity.x, y: properties.velocity.y, z: properties.velocity.z }; - var position = { x: properties.position.x, y: properties.position.y, z: properties.position.z }; - averageVelocity = { x: 0, y: 0, z: 0 }; - averagePosition = { x: 0, y: 0, z: 0 }; - - var othersCounted = 0; - for (var j = 0; j < fish.length; j++) { - if (i != j) { - // Get only the properties we need, because that is faster - var otherProps = flockProperties[j]; - var separation = Vec3.distance(properties.position, otherProps.position); - if (separation < MAX_SIGHT_DISTANCE) { - averageVelocity = Vec3.sum(averageVelocity, otherProps.velocity); - averagePosition = Vec3.sum(averagePosition, otherProps.position); - othersCounted++; - } - if (separation < MIN_SEPARATION) { - var pushAway = Vec3.multiply(Vec3.normalize(Vec3.subtract(properties.position, otherProps.position)), AVOIDANCE_FORCE); - velocity = Vec3.sum(velocity, pushAway); - } - } - } - - if (othersCounted > 0) { - averageVelocity = Vec3.multiply(averageVelocity, 1.0 / othersCounted); - averagePosition = Vec3.multiply(averagePosition, 1.0 / othersCounted); - // Alignment: Follow group's direction and speed - velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(averageVelocity), Vec3.length(velocity)), ALIGNMENT_FORCE); - // Cohesion: Steer towards center of flock - var towardCenter = Vec3.subtract(averagePosition, position); - velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardCenter), Vec3.length(velocity)), COHESION_FORCE); - } - - // Try to swim at a constant speed - velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(velocity), SWIMMING_SPEED), SWIMMING_FORCE); - - // Keep fish in their 'tank' - if (position.x < lowerCorner.x) { - position.x = lowerCorner.x; - velocity.x *= -1.0; - } else if (position.x > upperCorner.x) { - position.x = upperCorner.x; - velocity.x *= -1.0; - } - if (position.y < lowerCorner.y) { - position.y = lowerCorner.y; - velocity.y *= -1.0; - } else if (position.y > upperCorner.y) { - position.y = upperCorner.y; - velocity.y *= -1.0; - } - if (position.z < lowerCorner.z) { - position.z = lowerCorner.z; - velocity.z *= -1.0; - } else if (position.z > upperCorner.z) { - position.z = upperCorner.z; - velocity.z *= -1.0; - } - - // Orient in direction of velocity - var rotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, velocity); - var VELOCITY_FOLLOW_RATE = 0.30; - - // Only update properties if they have changed, to save bandwidth - var MIN_POSITION_CHANGE_FOR_UPDATE = 0.001; - if (Vec3.distance(properties.position, position) < MIN_POSITION_CHANGE_FOR_UPDATE) { - Entities.editEntity(fish[i].entityId, { velocity: velocity, rotation: Quat.mix(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) }); - } else { - Entities.editEntity(fish[i].entityId, { position: position, velocity: velocity, rotation: Quat.slerp(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) }); - } - } - } -} - -// Connect a call back that happens every frame -Script.update.connect(updateFish); - -// Delete our little friends if script is stopped -Script.scriptEnding.connect(function() { - for (var i = 0; i < fish.length; i++) { - Entities.deleteEntity(fish[i].entityId); - } -}); - -var STARTING_FRACTION = 0.25; -function loadFish(howMany) { - var center = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2 * TANK_WIDTH)); - lowerCorner = { x: center.x - TANK_WIDTH / 2, y: center.y, z: center.z - TANK_WIDTH / 2 }; - upperCorner = { x: center.x + TANK_WIDTH / 2, y: center.y + TANK_HEIGHT, z: center.z + TANK_WIDTH / 2 }; - - for (var i = 0; i < howMany; i++) { - var position = { - x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.x - lowerCorner.x) * STARTING_FRACTION, - y: lowerCorner.y + (upperCorner.y - lowerCorner.y) / 2.0 + (Math.random() - 0.5) * (upperCorner.y - lowerCorner.y) * STARTING_FRACTION, - z: lowerCorner.z + (upperCorner.z - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.z - lowerCorner.z) * STARTING_FRACTION - }; - - fish.push({ - entityId: Entities.addEntity({ - type: "Box", - position: position, - rotation: { x: 0, y: 0, z: 0, w: 1 }, - dimensions: { x: FISH_WIDTH, y: FISH_WIDTH, z: FISH_LENGTH }, - velocity: { x: SWIMMING_SPEED, y: SWIMMING_SPEED, z: SWIMMING_SPEED }, - damping: 0.0, - dynamic: false, - lifetime: LIFETIME, - color: { red: 0, green: 255, blue: 255 } - }) - }); - } -} diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index d6ca635c7c..c61cd2ea16 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -29,7 +29,7 @@ } FishTank.prototype = { - fish:null, + fish: null, findFishInTank: function() { // print('looking for a fish. in the tank') @@ -56,7 +56,7 @@ }, 1000) } else { - + print('JBP userdata before parse attempt' + properties.userData) _this.userData = null; try { @@ -121,8 +121,14 @@ var LIFETIME = 300; // Fish live for 5 minutes var NUM_FISH = 20; - var TANK_WIDTH = 3.0; - var TANK_HEIGHT = 1.0; + var TANK_DIMENSIONS = { + x: 1.3393, + y: 1.3515, + z: 3.5914 + }; + + var TANK_WIDTH = TANK_DIMENSIONS.z; + var TANK_HEIGHT = TANK_DIMENSIONS.y; var FISH_WIDTH = 0.03; var FISH_LENGTH = 0.15; var MAX_SIGHT_DISTANCE = 0.8; @@ -133,14 +139,18 @@ var SWIMMING_FORCE = 0.05; var SWIMMING_SPEED = 1.5; + var FISH_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-1.fbx"; + + var FISH_MODEL_TWO_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-2.fbx"; + var fishLoaded = false; - var fish = []; var lowerCorner = { x: 0, y: 0, z: 0 }; + var upperCorner = { x: 0, y: 0, @@ -160,9 +170,13 @@ if (!Entities.serversExist() || !Entities.canRez()) { return; } - print('has fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) + + print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) + + if (_this.userData['hifi-home-fishtank'].fishLoaded === false) { - print('NO FISH NO FISH NO FISH') + //no fish in the user data + loadFish(NUM_FISH); setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, { fishLoaded: true @@ -170,38 +184,51 @@ _this.userData['hifi-home-fishtank'].fishLoaded = true; _this.fish = _this.findFishInTank(); return; - } - else{ - if(this.fish===null){ + } else { + + //fish in userdata already + if (_this.fish === null) { + _this.fish = _this.findFishInTank(); - } + } } - // if (!fishLoaded) { - // fishLoaded = true; - // loadFish(NUM_FISH); - // setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, { - // fishLoaded: true - // }); - // _this.userData['hifi-home-fishtank'].fishLoaded=true; - // _this.fish = _this.findFishInTank(); - // return; - // } var fish = _this.fish; + print('how many fish do i find?'+fish.length) + + if (fish.length === 0) { + print('no fish...') + return + }; + var averageVelocity = { x: 0, y: 0, z: 0 }; + var averagePosition = { x: 0, y: 0, z: 0 }; + var birdPositionsCounted = 0; var birdVelocitiesCounted = 0; + var center = _this.currentProperties.position; + + lowerCorner = { + x: center.x - (TANK_WIDTH / 2), + y: center.y, + z: center.z - (TANK_WIDTH / 2) + }; + upperCorner = { + x: center.x + (TANK_WIDTH / 2), + y: center.y + TANK_HEIGHT, + z: center.z + (TANK_WIDTH / 2) + }; // First pre-load an array with properties on all the other fish so our per-fish loop // isn't doing it. @@ -323,8 +350,6 @@ function loadFish(howMany) { print('LOADING FISH: ' + howMany) - // var center = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2 * TANK_WIDTH)); - var center = _this.currentProperties.position; @@ -352,7 +377,8 @@ fish.push( Entities.addEntity({ name: 'hifi-fishtank-fish' + _this.entityID, - type: "Box", + type: "Model", + modelURL: fish.length % 2 === 0 ? FISH_MODEL_URL : FISH_MODEL_TWO_URL, position: position, rotation: { x: 0, From c362b779aeeae3fc4760f6786fed26c895e3f9a5 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Feb 2016 18:20:27 -0800 Subject: [PATCH 08/59] fish size --- .../DomainContent/Home/fishTank/tank.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index c61cd2ea16..406f991ca5 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -188,7 +188,6 @@ //fish in userdata already if (_this.fish === null) { - _this.fish = _this.findFishInTank(); } @@ -386,11 +385,11 @@ z: 0, w: 1 }, - dimensions: { - x: FISH_WIDTH, - y: FISH_WIDTH, - z: FISH_LENGTH - }, + // dimensions: { + // x: FISH_WIDTH, + // y: FISH_WIDTH, + // z: FISH_LENGTH + // }, // velocity: { // x: SWIMMING_SPEED, // y: SWIMMING_SPEED, From 35831856ea76ab0ce0f68f58add9f0c5f536eae3 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Feb 2016 18:25:05 -0800 Subject: [PATCH 09/59] prints --- unpublishedScripts/DomainContent/Home/fishTank/tank.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 406f991ca5..b6a10748e0 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -96,6 +96,7 @@ }, update: function() { + print('AM I THE OWNER??'+iOwn); if (iOwn === false) { return } @@ -171,7 +172,7 @@ return; } - print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) + // print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) if (_this.userData['hifi-home-fishtank'].fishLoaded === false) { From cf6d78b26eba13d6c96c261274a6e8971086bed2 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Feb 2016 18:29:10 -0800 Subject: [PATCH 10/59] disconnect --- unpublishedScripts/DomainContent/Home/fishTank/tank.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index b6a10748e0..a56bd28652 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -15,8 +15,9 @@ function startUpdate() { print('START UPDATE!!') iOwn = true; - Script.update.connect(_this.update); connected = true; + Script.update.connect(_this.update); + } function stopUpdateAndReclaim() { @@ -89,9 +90,9 @@ if (baton) { baton.release(function() {}); } - if (connected === true) { + Script.update.disconnect(_this.update); - } + }, From 2958030d5a1b631ae0ec77f34640e2cc929ef7cd Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 23 Feb 2016 18:58:51 -0800 Subject: [PATCH 11/59] clean --- .../DomainContent/Home/fishTank/tank.js | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index a56bd28652..423b337d93 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -17,20 +17,24 @@ iOwn = true; connected = true; Script.update.connect(_this.update); - + } function stopUpdateAndReclaim() { print('i released the object ' + _entityID) iOwn = false; - baton.claim(startUpdate, stopUpdateAndReclaim); if (connected === true) { + connected = false; Script.update.disconnect(_this.update); } + baton.claim(startUpdate, stopUpdateAndReclaim); + } FishTank.prototype = { fish: null, + tankLocked: false, + findFishInTank: function() { // print('looking for a fish. in the tank') @@ -39,7 +43,7 @@ res.forEach(function(f) { var props = Entities.getEntityProperties(f, 'name'); - if (props.name.indexOf('hifi-fishtank-fish') > -1) { + if (props.name.indexOf('hifi-fishtank-fish' + _this.entityID) > -1) { fish.push(f); } }) @@ -47,8 +51,9 @@ print('fish? ' + fish.length) return fish; }, + initialize: function(entityID) { - print('JBP nav button should initialize' + entityID) + print('JBP fishtank initialize' + entityID) var properties = Entities.getEntityProperties(entityID); if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { _this.initTimeout = Script.setTimeout(function() { @@ -77,6 +82,7 @@ } }, + preload: function(entityID) { print("preload"); this.entityID = entityID; @@ -87,17 +93,17 @@ }, unload: function() { + print(' UNLOAD') + Script.update.disconnect(_this.update); if (baton) { + print('BATON RELEASE ') baton.release(function() {}); } - - Script.update.disconnect(_this.update); - }, update: function() { - print('AM I THE OWNER??'+iOwn); + print('AM I THE OWNER??' + iOwn); if (iOwn === false) { return } @@ -168,7 +174,9 @@ } function updateFish(deltaTime) { - + if (_this.tankLocked === true) { + return; + } if (!Entities.serversExist() || !Entities.canRez()) { return; } @@ -178,7 +186,7 @@ if (_this.userData['hifi-home-fishtank'].fishLoaded === false) { //no fish in the user data - + _this.tankLocked = true; loadFish(NUM_FISH); setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, { fishLoaded: true @@ -197,7 +205,7 @@ var fish = _this.fish; - print('how many fish do i find?'+fish.length) + print('how many fish do i find?' + fish.length) if (fish.length === 0) { print('no fish...') @@ -411,6 +419,7 @@ } print('initial fish::' + fish.length) + _this.tankLocked = false; } From 96f5ff5fbda2a0f3158e111f9735d222f731181f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sun, 28 Feb 2016 21:05:36 -0800 Subject: [PATCH 12/59] switching computers --- .../DomainContent/Home/fishTank/tank.js | 84 ++++++++++++++----- 1 file changed, 62 insertions(+), 22 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 423b337d93..031508197b 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -2,31 +2,36 @@ Script.include('../../../../examples/libraries/virtualBaton.js?' + Math.random()); Script.include('../../../../examples/libraries/utils.js?' + Math.random()); + + //only one person should simulate the tank at a time -- we pass around a virtual baton var baton; var iOwn = false; var _entityID; var _this; var connected = false; + var TANK_SEARCH_RADIUS = 5; + function FishTank() { _this = this; } function startUpdate() { - print('START UPDATE!!') + //when the baton is claimed; iOwn = true; connected = true; Script.update.connect(_this.update); - } function stopUpdateAndReclaim() { + //when the baton is released; print('i released the object ' + _entityID) iOwn = false; if (connected === true) { connected = false; Script.update.disconnect(_this.update); } + //hook up callbacks to the baton baton.claim(startUpdate, stopUpdateAndReclaim); } @@ -35,16 +40,43 @@ fish: null, tankLocked: false, + combinedEntitySearch: function() { + var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); + var attractorList = []; + var fishList = []; + results.forEach(function(entity) { + var properties = Entities.getEntityProperties(entity, 'name'); + if (properties.name.indexOf('hifi-fishtank-attractor' + _this.entityID) > -1) { + attractorList.push(entity); + } + if (properties.name.indexOf('hifi-fishtank-fish' + _this.entityID) > -1) { + fishList.push(entity); + } + }); + + }, + + findAttractors: function() { + var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); + var attractorList = []; + + results.forEach(function(attractor) { + var properties = Entities.getEntityProperties(attractor, 'name'); + if (properties.name.indexOf('hifi-fishtank-attractor' + _this.entityID) > -1) { + fishList.push(attractor); + } + }) + }, + findFishInTank: function() { + // print('looking for a fish in the tank') + var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); + var fishList = []; - // print('looking for a fish. in the tank') - var res = Entities.findEntities(_this.currentProperties.position, 8); - var fish = []; - - res.forEach(function(f) { - var props = Entities.getEntityProperties(f, 'name'); - if (props.name.indexOf('hifi-fishtank-fish' + _this.entityID) > -1) { - fish.push(f); + results.forEach(function(fish) { + var properties = Entities.getEntityProperties(fish, 'name'); + if (properties.name.indexOf('hifi-fishtank-fish' + _this.entityID) > -1) { + fishList.push(fish); } }) @@ -147,24 +179,16 @@ var SWIMMING_FORCE = 0.05; var SWIMMING_SPEED = 1.5; + var THROTTLE = false; + var THROTTLE_RATE = 100; + var sinceLastUpdate = 0; + var FISH_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-1.fbx"; var FISH_MODEL_TWO_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-2.fbx"; var fishLoaded = false; - var lowerCorner = { - x: 0, - y: 0, - z: 0 - }; - - var upperCorner = { - x: 0, - y: 0, - z: 0 - }; - function randomVector(scale) { return { x: Math.random() * scale - scale / 2.0, @@ -174,6 +198,7 @@ } function updateFish(deltaTime) { + if (_this.tankLocked === true) { return; } @@ -181,6 +206,17 @@ return; } + + if (THROTTLE === true) { + sinceLastUpdate = sinceLastUpdate + deltaTime * 100; + if (sinceLastUpdate > THROTTLE_RATE) { + sinceLastUpdate = 0; + } else { + return; + } + } + + // print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) @@ -305,6 +341,10 @@ // Cohesion: Steer towards center of flock var towardCenter = Vec3.subtract(averagePosition, position); velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardCenter), Vec3.length(velocity)), COHESION_FORCE); + + //attractors + //[position, radius, force] + } // Try to swim at a constant speed From c05849714b4daac1640a4e773a024ec6f7b440c7 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 29 Feb 2016 16:21:43 -0800 Subject: [PATCH 13/59] bubbles etc --- .../Home/fishTank/bubbleSystemProperties.json | 47 +++++++ .../Home/fishTank/createFishTank.js | 120 +++++++++++++++++- .../DomainContent/Home/fishTank/tank.js | 77 ++++++++--- 3 files changed, 223 insertions(+), 21 deletions(-) create mode 100644 unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json diff --git a/unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json b/unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json new file mode 100644 index 0000000000..07626c0fc5 --- /dev/null +++ b/unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json @@ -0,0 +1,47 @@ +{ + "color": {}, + "isEmitting": 1, + "maxParticles": 1880, + "lifespan": 1.6, + "emitRate": 10, + "emitSpeed": 0.025, + "speedSpread": 0.025, + "emitOrientation": { + "x": 0, + "y": 0.5, + "z": 0.5, + "w": 0 + }, + "emitDimensions": { + "x": -0.2, + "y": 1.2000000000000002, + "z": 0 + }, + "polarStart": 0, + "polarFinish": 0, + "azimuthStart": 0.2, + "azimuthFinish": 0.1, + "emitAcceleration": { + "x": 0, + "y": 0.4, + "z": 0 + }, + "accelerationSpread": { + "x": 0.1, + "y": 0.1, + "z": 0.1 + }, + "particleRadius": 0.02, + "radiusSpread": 0, + "radiusStart": 0.043, + "radiusFinish": 0.02, + "colorSpread": {}, + "colorStart": {}, + "colorFinish": {}, + "alpha": 0.2, + "alphaSpread": 0, + "alphaStart": 0.3, + "alphaFinish": 0, + "emitterShouldTrail": 0, + "textures": "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/bubble-white.png" +} \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index ddcf0e870a..2be512764e 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,4 +1,4 @@ -var fishtank; +var fishtank, bubbleSystem, bubbleSound; var TANK_DIMENSIONS = { x: 1.3393, @@ -23,11 +23,18 @@ var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx"; +var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.2; +var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.2; +var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.2; + +var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav"; +var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); + function createFishTank() { var tankProperties = { name: 'hifi-home-fishtank', type: 'Model', - modelURL:TANK_MODEL_URL, + modelURL: TANK_MODEL_URL, dimensions: TANK_DIMENSIONS, position: TANK_POSITION, color: DEBUG_COLOR, @@ -35,22 +42,127 @@ function createFishTank() { script: TANK_SCRIPT, userData: JSON.stringify({ 'hifi-home-fishtank': { - fishLoaded: false + fishLoaded: false, + bubbleSystem: null, + bubbleSound: null, + attractors: null, }, grabbableKey: { grabbable: false } }), - visible:true + visible: true } fishTank = Entities.addEntity(tankProperties); } +function createBubbleSystem() { + + var tankProperties = Entities.getEntityProperties(fishTank); + var bubbleProperties = { + "color": {}, + "isEmitting": 1, + "maxParticles": 1880, + "lifespan": 1.6, + "emitRate": 10, + "emitSpeed": 0.025, + "speedSpread": 0.025, + "emitOrientation": { + "x": 0, + "y": 0.5, + "z": 0.5, + "w": 0 + }, + "emitDimensions": { + "x": -0.2, + "y": 1.2000000000000002, + "z": 0 + }, + "polarStart": 0, + "polarFinish": 0, + "azimuthStart": 0.2, + "azimuthFinish": 0.1, + "emitAcceleration": { + "x": 0, + "y": 0.4, + "z": 0 + }, + "accelerationSpread": { + "x": 0.1, + "y": 0.1, + "z": 0.1 + }, + "particleRadius": 0.02, + "radiusSpread": 0, + "radiusStart": 0.043, + "radiusFinish": 0.02, + "colorSpread": {}, + "colorStart": {}, + "colorFinish": {}, + "alpha": 0.2, + "alphaSpread": 0, + "alphaStart": 0.3, + "alphaFinish": 0, + "emitterShouldTrail": 0, + "textures": "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/bubble-white.png" + }; + + bubbleProperties.type = "ParticleEffect"; + bubbleProperties.collisionless = true; + + var upVector = Quat.getRight(tankProperties.rotation); + var frontVector = Quat.getRight(tankProperties.rotation); + var rightVector = Quat.getRight(tankProperties.rotation); + + var upOffset = Vec3.multiply(upVector, BUBBLE_SYSTEM_VERTICAL_OFFSET); + var frontOffset = Vec3.multiply(frontVector, BUBBLE_SYSTEM_FORWARD_OFFSET); + var rightOffset = Vec3.multiply(rightVector, BUBBLE_SYSTEM_LATERAL_OFFSET); + + var finalOffset = Vec3.sum(center, upOffset); + finalOffset = Vec3.sum(finalOffset, frontOffset); + finalOffset = Vec3.sum(finalOffset, rightOffset); + + bubbleProperties.position = finalOffset; + + bubbleSystem = Entities.addEntity(bubbleProperties); +} + +function createBubbleSound() { + var bubbleSystemProperties = Entities.getEntityProperties(bubbleSystem); + var audioProperties = { + volume: 0.2, + position: position + }; + + Audio.playSound(bubbleSound, audioProperties); + +} + function cleanup() { Entities.deleteEntity(fishTank); } createFishTank(); +// createBubbleSystem(); + +// createBubbleSound(); + +// createAttractors(); + +var attractors = [] + //@position,radius,strength + + + +function createAttractor(position, radius, strength) { + return { + position: position, + radius: radius, + strength: strength + }; +} + + Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 031508197b..02250a53d8 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -80,8 +80,8 @@ } }) - print('fish? ' + fish.length) - return fish; + print('fish? ' + fishList.length) + return fishList; }, initialize: function(entityID) { @@ -135,13 +135,56 @@ }, update: function() { - print('AM I THE OWNER??' + iOwn); + //print('AM I THE OWNER??' + iOwn); if (iOwn === false) { return } - //print('i am the owner!') - //do stuff + print('i am the owner!') + //do stuff updateFish(); + }, + debugLookSpot: null, + createDebugLookAtCube: function() { + var cubePosition = { + x: 0, + y: 0, + z: 0 + }; + var cubeSize = 0.03; + _this.debugLookAtCube = Overlays.addOverlay("cube", { + position: cubePosition, + size: cubeSize, + color: { + red: 0, + green: 255, + blue: 0 + }, + alpha: 1, + solid: false + }); + }, + updateDebugLookAtCube: function() { + var lookAt3D = HMD.getHUDLookAtPosition3D(); + _this.lookAt3D = lookAt3D; + Overlays.editOverlay(_this.debugLookAtCube, { + position: lookAt3D + }); + }, + seeIfOwnerIsLookingAtTheTank: function(origin,direction) { + // var cameraPosition = Camera.getPosition(); + // var cameraOrientation = Camera.getOrientation(); + var pickRay = { + origin: origin, + direction: direction + }; + var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID], []) + + if (intersection.intersects && intersection.entityID = _this.entityID) { + + print('looking at the tank!! ' + JSON.stringify(intersection.intersection)); + + var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); + } } }; @@ -160,24 +203,24 @@ var FISHTANK_USERDATA_KEY = 'hifi-home-fishtank' var LIFETIME = 300; // Fish live for 5 minutes - var NUM_FISH = 20; + var NUM_FISH = 8; var TANK_DIMENSIONS = { x: 1.3393, y: 1.3515, z: 3.5914 }; - var TANK_WIDTH = TANK_DIMENSIONS.z; - var TANK_HEIGHT = TANK_DIMENSIONS.y; + var TANK_WIDTH = TANK_DIMENSIONS.z / 3; + var TANK_HEIGHT = TANK_DIMENSIONS.y / 3; var FISH_WIDTH = 0.03; var FISH_LENGTH = 0.15; var MAX_SIGHT_DISTANCE = 0.8; var MIN_SEPARATION = 0.15; - var AVOIDANCE_FORCE = 0.2; - var COHESION_FORCE = 0.05; - var ALIGNMENT_FORCE = 0.05; + var AVOIDANCE_FORCE = 0.3; + var COHESION_FORCE = 0.025; + var ALIGNMENT_FORCE = 0.025; var SWIMMING_FORCE = 0.05; - var SWIMMING_SPEED = 1.5; + var SWIMMING_SPEED = 0.5; var THROTTLE = false; var THROTTLE_RATE = 100; @@ -403,14 +446,14 @@ var center = _this.currentProperties.position; lowerCorner = { - x: center.x - (TANK_WIDTH / 2), + x: center.x - (_this.currentProperties.dimensions.z / 2), y: center.y, - z: center.z - (TANK_WIDTH / 2) + z: center.z - (_this.currentProperties.dimensions.z / 2) }; upperCorner = { - x: center.x + (TANK_WIDTH / 2), - y: center.y + TANK_HEIGHT, - z: center.z + (TANK_WIDTH / 2) + x: center.x + (_this.currentProperties.dimensions.z / 2), + y: center.y + _this.currentProperties.dimensions.y, + z: center.z + (_this.currentProperties.dimensions.z / 2) }; var fish = []; From 42ec6de512d6e8574514158e8f2accda2348a623 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 29 Feb 2016 18:23:20 -0800 Subject: [PATCH 14/59] starts --- .../DomainContent/Home/fishTank/tank.js | 108 ++++++++++++------ 1 file changed, 71 insertions(+), 37 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 02250a53d8..e3b0c503a7 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -12,6 +12,18 @@ var TANK_SEARCH_RADIUS = 5; + var INTERSECT_COLOR = { + red: 255, + green: 0, + blue: 255 + } + + var NO_INTERSECT_COLOR = { + red: 0, + green: 255, + blue: 0 + } + function FishTank() { _this = this; } @@ -127,6 +139,7 @@ unload: function() { print(' UNLOAD') Script.update.disconnect(_this.update); + _this.overlayLineOff(); if (baton) { print('BATON RELEASE ') baton.release(function() {}); @@ -139,51 +152,69 @@ if (iOwn === false) { return } - print('i am the owner!') - //do stuff + // print('i am the owner!') + //do stuff updateFish(); + _this.seeIfOwnerIsLookingAtTheTank(); }, - debugLookSpot: null, - createDebugLookAtCube: function() { - var cubePosition = { - x: 0, - y: 0, - z: 0 - }; - var cubeSize = 0.03; - _this.debugLookAtCube = Overlays.addOverlay("cube", { - position: cubePosition, - size: cubeSize, - color: { - red: 0, - green: 255, - blue: 0 - }, - alpha: 1, - solid: false - }); + + overlayLine: null, + + overlayLineOn: function(closePoint, farPoint, color) { + print('closePoint: ' + JSON.stringify(closePoint)); + print('farPoint: ' + JSON.stringify(farPoint)); + if (_this.overlayLine === null) { + var lineProperties = { + lineWidth: 5, + start: closePoint, + end: farPoint, + color: color, + ignoreRayIntersection: true, // always ignore this + visible: true, + alpha: 1 + }; + this.overlayLine = Overlays.addOverlay("line3d", lineProperties); + + } else { + var success = Overlays.editOverlay(_this.overlayLine, { + lineWidth: 5, + start: closePoint, + end: farPoint, + color: color, + visible: true, + ignoreRayIntersection: true, // always ignore this + alpha: 1 + }); + } }, - updateDebugLookAtCube: function() { - var lookAt3D = HMD.getHUDLookAtPosition3D(); - _this.lookAt3D = lookAt3D; - Overlays.editOverlay(_this.debugLookAtCube, { - position: lookAt3D - }); + + overlayLineOff: function() { + if (_this.overlayLine !== null) { + Overlays.deleteOverlay(this.overlayLine); + } + _this.overlayLine = null; }, - seeIfOwnerIsLookingAtTheTank: function(origin,direction) { - // var cameraPosition = Camera.getPosition(); - // var cameraOrientation = Camera.getOrientation(); + + overlayLineDistance: 3, + + seeIfOwnerIsLookingAtTheTank: function() { + var cameraPosition = Camera.getPosition(); + var cameraOrientation = Camera.getOrientation(); + + var front = Quat.getFront(cameraOrientation); var pickRay = { - origin: origin, - direction: direction + origin: cameraPosition, + direction: front }; - var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID], []) - if (intersection.intersects && intersection.entityID = _this.entityID) { + _this.overlayLineOn(pickRay.origin, Vec3.sum(pickRay.origin, Vec3.multiply(front, _this.overlayLineDistance)), INTERSECT_COLOR); - print('looking at the tank!! ' + JSON.stringify(intersection.intersection)); + var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); - var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); + // print('INTERSCTION::: ' + JSON.stringify(intersection)); + + if (intersection.intersects && intersection.entityID === _this.entityID) { + print('intersecting a tank') } } @@ -284,7 +315,7 @@ var fish = _this.fish; - print('how many fish do i find?' + fish.length) + // print('how many fish do i find?' + fish.length) if (fish.length === 0) { print('no fish...') @@ -505,6 +536,9 @@ _this.tankLocked = false; } + Script.scriptEnding.connect(function() { + Script.update.disconnect(_this.update); + }) return new FishTank(); }); \ No newline at end of file From ba2e97796838116a05d2591c6d9a05ca0cba9763 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 1 Mar 2016 10:53:50 -0800 Subject: [PATCH 15/59] fish swim to where youre looking --- .../Home/fishTank/createFishTank.js | 35 +++--- .../DomainContent/Home/fishTank/tank.js | 104 ++++++++++-------- 2 files changed, 71 insertions(+), 68 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 2be512764e..56b9ea16c0 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -27,6 +27,12 @@ var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.2; var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.2; var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.2; +var BUBBLE_SYSTEM_DIMENSIONS = { + x: TANK_DIMENSIONS.x / 8, + y: TANK_DIMENSIONS.y, + z: TANK_DIMENSIONS.z / 8 +} + var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav"; var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); @@ -109,7 +115,7 @@ function createBubbleSystem() { }; bubbleProperties.type = "ParticleEffect"; - bubbleProperties.collisionless = true; + bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS; var upVector = Quat.getRight(tankProperties.rotation); var frontVector = Quat.getRight(tankProperties.rotation); @@ -126,13 +132,14 @@ function createBubbleSystem() { bubbleProperties.position = finalOffset; bubbleSystem = Entities.addEntity(bubbleProperties); + createBubbleSound(finalOffset); } -function createBubbleSound() { - var bubbleSystemProperties = Entities.getEntityProperties(bubbleSystem); +function createBubbleSound(position) { var audioProperties = { volume: 0.2, - position: position + position: position, + loop: true }; Audio.playSound(bubbleSound, audioProperties); @@ -145,24 +152,8 @@ function cleanup() { createFishTank(); -// createBubbleSystem(); - -// createBubbleSound(); - -// createAttractors(); - -var attractors = [] - //@position,radius,strength - - - -function createAttractor(position, radius, strength) { - return { - position: position, - radius: radius, - strength: strength - }; -} +createBubbleSystem(); +createBubbleSound(); Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index e3b0c503a7..e003c1d487 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -18,12 +18,6 @@ blue: 255 } - var NO_INTERSECT_COLOR = { - red: 0, - green: 255, - blue: 0 - } - function FishTank() { _this = this; } @@ -42,6 +36,7 @@ if (connected === true) { connected = false; Script.update.disconnect(_this.update); + _this.clearLookAttractor(); } //hook up callbacks to the baton baton.claim(startUpdate, stopUpdateAndReclaim); @@ -51,35 +46,10 @@ FishTank.prototype = { fish: null, tankLocked: false, - - combinedEntitySearch: function() { - var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); - var attractorList = []; - var fishList = []; - results.forEach(function(entity) { - var properties = Entities.getEntityProperties(entity, 'name'); - if (properties.name.indexOf('hifi-fishtank-attractor' + _this.entityID) > -1) { - attractorList.push(entity); - } - if (properties.name.indexOf('hifi-fishtank-fish' + _this.entityID) > -1) { - fishList.push(entity); - } - }); - - }, - - findAttractors: function() { - var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); - var attractorList = []; - - results.forEach(function(attractor) { - var properties = Entities.getEntityProperties(attractor, 'name'); - if (properties.name.indexOf('hifi-fishtank-attractor' + _this.entityID) > -1) { - fishList.push(attractor); - } - }) - }, - + hasLookAttractor: false, + lookAttractor: null, + overlayLine: null, + overlayLineDistance: 3, findFishInTank: function() { // print('looking for a fish in the tank') var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); @@ -146,10 +116,9 @@ } }, - update: function() { - //print('AM I THE OWNER??' + iOwn); if (iOwn === false) { + //exit if we're not supposed to be simulating the fish return } // print('i am the owner!') @@ -158,11 +127,8 @@ _this.seeIfOwnerIsLookingAtTheTank(); }, - overlayLine: null, overlayLineOn: function(closePoint, farPoint, color) { - print('closePoint: ' + JSON.stringify(closePoint)); - print('farPoint: ' + JSON.stringify(farPoint)); if (_this.overlayLine === null) { var lineProperties = { lineWidth: 5, @@ -195,7 +161,7 @@ _this.overlayLine = null; }, - overlayLineDistance: 3, + seeIfOwnerIsLookingAtTheTank: function() { var cameraPosition = Camera.getPosition(); @@ -211,10 +177,51 @@ var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); - // print('INTERSCTION::: ' + JSON.stringify(intersection)); + if (intersection.intersects && intersection.entityID === _this.entityID) { + print('intersecting a tank') + print('intersection:: ' + JSON.stringify(intersection)); + if (_this.hasLookAttractor === false) { + _this.createLookAttractor(); + } else if (_this.hasLookAttractor === true) { + _this.updateLookAttractor(); + } + } else { + if (_this.hasLookAttractor === true) { + clearLookAttractor(); + } + } + }, + //look attractors could be private to the tank... + createLookAttractor: function(position) { + _this.lookAttractor = position; + }, + updateLookAttractor: function(position) { + _this.lookAttractor = position; + }, + clearLookAttractor: function() { + _this.hasLookAttractor = false; + _this.lookAttractor = null; + }, + createLookAttractorEntity: function() { + + }, + findLookAttractorEntities: function() { + + }, + seeIfAnyoneIsLookingAtTheTank: function() { + + // get avatars + // get their positions + // get their gazes + // check for intersection + // add attractor for closest person (?) + + var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); if (intersection.intersects && intersection.entityID === _this.entityID) { print('intersecting a tank') + + print('intersection:: ' + JSON.stringify(intersection)); } } @@ -250,8 +257,10 @@ var AVOIDANCE_FORCE = 0.3; var COHESION_FORCE = 0.025; var ALIGNMENT_FORCE = 0.025; + var LOOK_ATTRACTOR_FORCE = 0.030; var SWIMMING_FORCE = 0.05; var SWIMMING_SPEED = 0.5; + var FISH_DAMPING = 0.25; var THROTTLE = false; var THROTTLE_RATE = 100; @@ -293,7 +302,6 @@ // print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) - if (_this.userData['hifi-home-fishtank'].fishLoaded === false) { //no fish in the user data _this.tankLocked = true; @@ -334,8 +342,6 @@ z: 0 }; - var birdPositionsCounted = 0; - var birdVelocitiesCounted = 0; var center = _this.currentProperties.position; lowerCorner = { @@ -419,6 +425,12 @@ //attractors //[position, radius, force] + if (_this.hasLookAttractor === true) { + var attractorPosition = _this.lookAttractor; + var towardAttractor = Vec3.subtract(attractorPosition, position); + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardAttractor), Vec3.length(velocity)), LOOK_ATTRACTOR_FORCE); + } + } // Try to swim at a constant speed @@ -519,7 +531,7 @@ // y: SWIMMING_SPEED, // z: SWIMMING_SPEED // }, - damping: 0.1, + damping: FISH_DAMPING, dynamic: false, lifetime: LIFETIME, color: { From 24da3b101954fbdc0d150d7d399fb0d47ff1416b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 1 Mar 2016 12:02:07 -0800 Subject: [PATCH 16/59] cleanup and parenting --- .../DomainContent/Home/fishTank/createFishTank.js | 1 + .../DomainContent/Home/fishTank/tank.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 56b9ea16c0..2f8899b49b 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -115,6 +115,7 @@ function createBubbleSystem() { }; bubbleProperties.type = "ParticleEffect"; + bubbleProperties.parentID = fishTank; bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS; var upVector = Quat.getRight(tankProperties.rotation); diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index e003c1d487..c7e59eefc1 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -109,7 +109,9 @@ unload: function() { print(' UNLOAD') Script.update.disconnect(_this.update); - _this.overlayLineOff(); + if (WANT_LOOK_DEBUG === true) { + _this.overlayLineOff(); + } if (baton) { print('BATON RELEASE ') baton.release(function() {}); @@ -173,7 +175,10 @@ direction: front }; - _this.overlayLineOn(pickRay.origin, Vec3.sum(pickRay.origin, Vec3.multiply(front, _this.overlayLineDistance)), INTERSECT_COLOR); + if (WANT_LOOK_DEBUG === true) { + _this.overlayLineOn(pickRay.origin, Vec3.sum(pickRay.origin, Vec3.multiply(front, _this.overlayLineDistance)), INTERSECT_COLOR); + + }; var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); @@ -262,6 +267,8 @@ var SWIMMING_SPEED = 0.5; var FISH_DAMPING = 0.25; + var WANT_LOOK_DEBUG = false; + var THROTTLE = false; var THROTTLE_RATE = 100; var sinceLastUpdate = 0; @@ -515,6 +522,7 @@ type: "Model", modelURL: fish.length % 2 === 0 ? FISH_MODEL_URL : FISH_MODEL_TWO_URL, position: position, + parentID: _this.entityID, rotation: { x: 0, y: 0, From 1bcd85d106b38476425a0d161996071db81257ee Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 1 Mar 2016 17:44:21 -0800 Subject: [PATCH 17/59] only look attractor if close --- .../Home/fishTank/createFishTank.js | 92 +++++++-- .../DomainContent/Home/fishTank/tank.js | 187 ++++++++++++++---- 2 files changed, 232 insertions(+), 47 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 2f8899b49b..3671030948 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,5 +1,6 @@ -var fishtank, bubbleSystem, bubbleSound; +var fishtank, bubbleSystem, bubbleSound, bubbleInjector; +var CLEANUP = true; var TANK_DIMENSIONS = { x: 1.3393, y: 1.3515, @@ -15,7 +16,7 @@ var DEBUG_COLOR = { blue: 255 } -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2 * TANK_WIDTH)); +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 1 * TANK_WIDTH)); var TANK_POSITION = center; @@ -23,9 +24,9 @@ var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx"; -var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.2; -var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.2; -var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.2; +var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.0; +var BUBBLE_SYSTEM_LATERAL_OFFSET = TANK_DIMENSIONS.x - 0.25; +var BUBBLE_SYSTEM_VERTICAL_OFFSET = -1; var BUBBLE_SYSTEM_DIMENSIONS = { x: TANK_DIMENSIONS.x / 8, @@ -65,7 +66,7 @@ function createFishTank() { function createBubbleSystem() { - var tankProperties = Entities.getEntityProperties(fishTank); + var tankProperties = Entities.getEntityProperties(fishtank); var bubbleProperties = { "color": {}, "isEmitting": 1, @@ -130,31 +131,100 @@ function createBubbleSystem() { finalOffset = Vec3.sum(finalOffset, frontOffset); finalOffset = Vec3.sum(finalOffset, rightOffset); + print('final bubble offset:: ' + JSON.stringify(finalOffset)); bubbleProperties.position = finalOffset; bubbleSystem = Entities.addEntity(bubbleProperties); - createBubbleSound(finalOffset); + // createBubbleSound(finalOffset); } function createBubbleSound(position) { var audioProperties = { - volume: 0.2, + volume: 1, position: position, loop: true }; - Audio.playSound(bubbleSound, audioProperties); + bubbleInjector = Audio.playSound(bubbleSound, audioProperties); } function cleanup() { Entities.deleteEntity(fishTank); + Entities.deleteEntity(bubbleSystem); + bubbleInjector.stop(); + bubbleInjector = null; } +function createInnerContainer(){ + var containerProps = { + name:"hifi-home-fishtank-inner-container", + type:'Box', + color:{ + red:0, + green:0, + blue:255 + }, + dimensions:{ + + } + }; +} + +function createEntitiesAtCorners() { + + var bounds = Entities.getEntityProperties(fishTank, "boundingBox").boundingBox; + + var lowerProps = { + name:'hifi-home-fishtank-lower-corner', + type: "Box", + dimensions: { + x: 0.2, + y: 0.2, + z: 0.2 + }, + color: { + red: 255, + green: 0, + blue: 0 + }, + collisionless: true, + position: bounds.brn + } + + var upperProps = { + name:'hifi-home-fishtank-upper-corner', + type: "Box", + dimensions: { + x: 0.2, + y: 0.2, + z: 0.2 + }, + color: { + red: 0, + green: 255, + blue: 0 + }, + collisionless: true, + position:bounds.tfl + } + + var lowerCorner = Entities.addEntity(lowerProps); + var upperCorner = Entities.addEntity(upperProps); + print('CORNERS :::' + JSON.stringify(upperCorner) ) + print('CORNERS :::' + JSON.stringify(lowerCorner) ) +} + + createFishTank(); createBubbleSystem(); -createBubbleSound(); +createEntitiesAtCorners(); +//createBubbleSound(); -Script.scriptEnding.connect(cleanup); \ No newline at end of file + + +if (CLEANUP === true) { + Script.scriptEnding.connect(cleanup); +} \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index c7e59eefc1..bc56229ad8 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -11,6 +11,8 @@ var connected = false; var TANK_SEARCH_RADIUS = 5; + var WANT_LOOK_DEBUG_LINE = false; + var WANT_LOOK_DEBUG_SPHERE = true; var INTERSECT_COLOR = { red: 255, @@ -50,8 +52,9 @@ lookAttractor: null, overlayLine: null, overlayLineDistance: 3, + debugSphere: null, findFishInTank: function() { - // print('looking for a fish in the tank') + print('looking for a fish in the tank') var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); var fishList = []; @@ -109,7 +112,7 @@ unload: function() { print(' UNLOAD') Script.update.disconnect(_this.update); - if (WANT_LOOK_DEBUG === true) { + if (WANT_LOOK_DEBUG_LINE === true) { _this.overlayLineOff(); } if (baton) { @@ -129,6 +132,43 @@ _this.seeIfOwnerIsLookingAtTheTank(); }, + debugSphereOn: function(position) { + if (_this.debugSphere !== null) { + Entities.editEntity(_this.debugSphere, { + visible: true + }) + return; + } + var sphereProperties = { + type: 'Sphere', + parentID: _this.entityID, + dimensions: { + x: 0.1, + y: 0.1, + z: 0.1, + }, + color: INTERSECT_COLOR, + position: position, + collisionless: true + } + _this.debugSphere = Entities.addEntity(sphereProperties); + }, + + updateDebugSphere: function(position) { + Entities.editEntity(_this.debugSphere, { + visible:true, + position: position + }) + }, + + debugSphereOff: function() { + // Entities.deleteEntity(_this.debugSphere); + Entities.editEntity(_this.debugSphere, { + visible: false + }) + //_this.debugSphere = null; + + }, overlayLineOn: function(closePoint, farPoint, color) { if (_this.overlayLine === null) { @@ -175,33 +215,59 @@ direction: front }; - if (WANT_LOOK_DEBUG === true) { + if (WANT_LOOK_DEBUG_LINE === true) { _this.overlayLineOn(pickRay.origin, Vec3.sum(pickRay.origin, Vec3.multiply(front, _this.overlayLineDistance)), INTERSECT_COLOR); }; + var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); if (intersection.intersects && intersection.entityID === _this.entityID) { - print('intersecting a tank') - print('intersection:: ' + JSON.stringify(intersection)); + //print('intersecting a tank') + if (WANT_LOOK_DEBUG_SPHERE === true) { + if (_this.debugSphere === null) { + _this.debugSphereOn(intersection.intersection); + } else { + _this.updateDebugSphere(intersection.intersection); + } + } + print('INT DIST: ' + intersection.distance); + if (intersection.distance > 1.5) { + print('NOT CLOSE ENOUGH TO THE TANK') + if (WANT_LOOK_DEBUG_SPHERE === true) { + _this.debugSphereOff(); + } + return + } + // print('intersection:: ' + JSON.stringify(intersection)); if (_this.hasLookAttractor === false) { - _this.createLookAttractor(); + _this.createLookAttractor(intersection.intersection, intersection.distance); } else if (_this.hasLookAttractor === true) { - _this.updateLookAttractor(); + _this.updateLookAttractor(intersection.intersection, intersection.distance); } } else { if (_this.hasLookAttractor === true) { - clearLookAttractor(); + _this.clearLookAttractor(); + } + if (WANT_LOOK_DEBUG_SPHERE === true) { + _this.debugSphereOff(); } } }, //look attractors could be private to the tank... - createLookAttractor: function(position) { - _this.lookAttractor = position; + createLookAttractor: function(position, distance) { + _this.lookAttractor = { + position: position, + distance: distance + }; + _this.hasLookAttractor = true; }, - updateLookAttractor: function(position) { - _this.lookAttractor = position; + updateLookAttractor: function(position, distance) { + _this.lookAttractor = { + position: position, + distance: distance + }; }, clearLookAttractor: function() { _this.hasLookAttractor = false; @@ -253,30 +319,29 @@ z: 3.5914 }; - var TANK_WIDTH = TANK_DIMENSIONS.z / 3; - var TANK_HEIGHT = TANK_DIMENSIONS.y / 3; + var TANK_WIDTH = TANK_DIMENSIONS.z / 2; + var TANK_HEIGHT = TANK_DIMENSIONS.y / 2; var FISH_WIDTH = 0.03; var FISH_LENGTH = 0.15; - var MAX_SIGHT_DISTANCE = 0.8; + var MAX_SIGHT_DISTANCE = 1.5; var MIN_SEPARATION = 0.15; - var AVOIDANCE_FORCE = 0.3; + var AVOIDANCE_FORCE = 0.32; var COHESION_FORCE = 0.025; var ALIGNMENT_FORCE = 0.025; - var LOOK_ATTRACTOR_FORCE = 0.030; + var LOOK_ATTRACTOR_FORCE = 0.029; var SWIMMING_FORCE = 0.05; var SWIMMING_SPEED = 0.5; var FISH_DAMPING = 0.25; - var WANT_LOOK_DEBUG = false; - var THROTTLE = false; var THROTTLE_RATE = 100; var sinceLastUpdate = 0; - var FISH_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-1.fbx"; - - var FISH_MODEL_TWO_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-2.fbx"; + // var FISH_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-1.fbx"; + // var FISH_MODEL_TWO_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Fish-2.fbx"; + var FISH_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/goodfish5.fbx"; + var FISH_MODEL_TWO_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/goodfish5.fbx"; var fishLoaded = false; function randomVector(scale) { @@ -287,6 +352,44 @@ }; } + function createEntitiesAtCorners(lower, upper) { + var lowerProps = { + type: "box", + dimensions: { + x: 0.2, + y: 0.2, + z: 0.2 + }, + color: { + red: 255, + green: 0, + blue: 0 + }, + collisionless: true, + position: lower + } + + var upperProps = { + type: "box", + dimensions: { + x: 0.2, + y: 0.2, + z: 0.2 + }, + color: { + red: 0, + green: 255, + blue: 0 + }, + collisionless: true, + position: upper + } + + _this.lowerCorner = Entities.addEntity(lowerProps); + _this.upperCorner = Entities.addEntity(upperProps); + + } + function updateFish(deltaTime) { if (_this.tankLocked === true) { @@ -317,7 +420,9 @@ fishLoaded: true }); _this.userData['hifi-home-fishtank'].fishLoaded = true; - _this.fish = _this.findFishInTank(); + Script.setTimeout(function() { + _this.fish = _this.findFishInTank(); + }, 2000) return; } else { @@ -330,10 +435,10 @@ var fish = _this.fish; - // print('how many fish do i find?' + fish.length) + // print('how many fish do i find?' + fish.length) if (fish.length === 0) { - print('no fish...') + // print('no fish...') return }; @@ -362,6 +467,8 @@ z: center.z + (TANK_WIDTH / 2) }; + //createEntitiesAtCorners(lowerCorner,upperCorner); + // First pre-load an array with properties on all the other fish so our per-fish loop // isn't doing it. var flockProperties = []; @@ -432,12 +539,15 @@ //attractors //[position, radius, force] - if (_this.hasLookAttractor === true) { - var attractorPosition = _this.lookAttractor; - var towardAttractor = Vec3.subtract(attractorPosition, position); - velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardAttractor), Vec3.length(velocity)), LOOK_ATTRACTOR_FORCE); - } + + } + + if (_this.hasLookAttractor === true) { + //print('has a look attractor, so use it') + var attractorPosition = _this.lookAttractor.position; + var towardAttractor = Vec3.subtract(attractorPosition, position); + velocity = Vec3.mix(velocity, Vec3.multiply(Vec3.normalize(towardAttractor), Vec3.length(velocity)), LOOK_ATTRACTOR_FORCE); } // Try to swim at a constant speed @@ -470,6 +580,10 @@ var rotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, velocity); var VELOCITY_FOLLOW_RATE = 0.30; + var safeEuler = Quat.safeEulerAngles(rotation); + + + // Only update properties if they have changed, to save bandwidth var MIN_POSITION_CHANGE_FOR_UPDATE = 0.001; if (Vec3.distance(properties.position, position) < MIN_POSITION_CHANGE_FOR_UPDATE) { @@ -523,12 +637,13 @@ modelURL: fish.length % 2 === 0 ? FISH_MODEL_URL : FISH_MODEL_TWO_URL, position: position, parentID: _this.entityID, - rotation: { - x: 0, - y: 0, - z: 0, - w: 1 - }, + // rotation: { + // x: 0, + // y: 0, + // z: 0, + // w: 1 + // }, + // type: "Box", // dimensions: { // x: FISH_WIDTH, // y: FISH_WIDTH, From 5cb792183e23442047557d9a9809ded0daef5e36 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 1 Mar 2016 17:51:05 -0800 Subject: [PATCH 18/59] start inner tank --- .../Home/fishTank/createFishTank.js | 2 ++ .../DomainContent/Home/fishTank/tank.js | 32 +++++++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 3671030948..7d9f2cf977 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -7,6 +7,8 @@ var TANK_DIMENSIONS = { z: 3.5914 }; +var INNER_TANK_SCALE = 0.8; +var INNER_TANK_DIMENSIONS = Vec3.multiply(INNER_TANK_SCALE,TANK_DIMENSIONS); var TANK_WIDTH = TANK_DIMENSIONS.z; var TANK_HEIGHT = TANK_DIMENSIONS.y; diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index bc56229ad8..cc845ea63e 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -156,7 +156,7 @@ updateDebugSphere: function(position) { Entities.editEntity(_this.debugSphere, { - visible:true, + visible: true, position: position }) }, @@ -164,9 +164,9 @@ debugSphereOff: function() { // Entities.deleteEntity(_this.debugSphere); Entities.editEntity(_this.debugSphere, { - visible: false - }) - //_this.debugSphere = null; + visible: false + }) + //_this.debugSphere = null; }, @@ -232,12 +232,10 @@ _this.updateDebugSphere(intersection.intersection); } } - print('INT DIST: ' + intersection.distance); if (intersection.distance > 1.5) { - print('NOT CLOSE ENOUGH TO THE TANK') - if (WANT_LOOK_DEBUG_SPHERE === true) { - _this.debugSphereOff(); - } + if (WANT_LOOK_DEBUG_SPHERE === true) { + _this.debugSphereOff(); + } return } // print('intersection:: ' + JSON.stringify(intersection)); @@ -454,18 +452,10 @@ z: 0 }; - var center = _this.currentProperties.position; - - lowerCorner = { - x: center.x - (TANK_WIDTH / 2), - y: center.y, - z: center.z - (TANK_WIDTH / 2) - }; - upperCorner = { - x: center.x + (TANK_WIDTH / 2), - y: center.y + TANK_HEIGHT, - z: center.z + (TANK_WIDTH / 2) - }; + //var center = _this.currentProperties.position; + var bounds = Entities.getEntityProperties(_this.entityID, "boundingBox").boundingBox; + lowerCorner = bounds.brn; + upperCorner = bounds.tfl; //createEntitiesAtCorners(lowerCorner,upperCorner); From 87e13543c29356b8e65ce47673aa96ad0770baf9 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 1 Mar 2016 19:14:41 -0800 Subject: [PATCH 19/59] use inner container for tank --- .../Home/fishTank/createFishTank.js | 170 +++++++++++++----- .../DomainContent/Home/fishTank/tank.js | 62 ++----- 2 files changed, 138 insertions(+), 94 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 7d9f2cf977..92a21ff15b 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,4 +1,4 @@ -var fishtank, bubbleSystem, bubbleSound, bubbleInjector; +var fishTank, bubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner; var CLEANUP = true; var TANK_DIMENSIONS = { @@ -7,8 +7,9 @@ var TANK_DIMENSIONS = { z: 3.5914 }; -var INNER_TANK_SCALE = 0.8; -var INNER_TANK_DIMENSIONS = Vec3.multiply(INNER_TANK_SCALE,TANK_DIMENSIONS); +var INNER_TANK_SCALE = 0.7; +var INNER_TANK_DIMENSIONS = Vec3.multiply(INNER_TANK_SCALE, TANK_DIMENSIONS); +INNER_TANK_DIMENSIONS.y = INNER_TANK_DIMENSIONS.y -0.25; var TANK_WIDTH = TANK_DIMENSIONS.z; var TANK_HEIGHT = TANK_DIMENSIONS.y; @@ -26,9 +27,10 @@ var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx"; -var BUBBLE_SYSTEM_FORWARD_OFFSET = 0.0; -var BUBBLE_SYSTEM_LATERAL_OFFSET = TANK_DIMENSIONS.x - 0.25; -var BUBBLE_SYSTEM_VERTICAL_OFFSET = -1; +var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x - 0.05; +//depth of tank +var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.15; +var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.5; var BUBBLE_SYSTEM_DIMENSIONS = { x: TANK_DIMENSIONS.x / 8, @@ -39,6 +41,7 @@ var BUBBLE_SYSTEM_DIMENSIONS = { var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav"; var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); + function createFishTank() { var tankProperties = { name: 'hifi-home-fishtank', @@ -49,17 +52,6 @@ function createFishTank() { color: DEBUG_COLOR, collisionless: true, script: TANK_SCRIPT, - userData: JSON.stringify({ - 'hifi-home-fishtank': { - fishLoaded: false, - bubbleSystem: null, - bubbleSound: null, - attractors: null, - }, - grabbableKey: { - grabbable: false - } - }), visible: true } @@ -68,8 +60,9 @@ function createFishTank() { function createBubbleSystem() { - var tankProperties = Entities.getEntityProperties(fishtank); + var tankProperties = Entities.getEntityProperties(fishTank); var bubbleProperties = { + "name": 'hifi-home-fishtank-bubbles', "color": {}, "isEmitting": 1, "maxParticles": 1880, @@ -121,15 +114,15 @@ function createBubbleSystem() { bubbleProperties.parentID = fishTank; bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS; - var upVector = Quat.getRight(tankProperties.rotation); - var frontVector = Quat.getRight(tankProperties.rotation); + var upVector = Quat.getUp(tankProperties.rotation); + var frontVector = Quat.getFront(tankProperties.rotation); var rightVector = Quat.getRight(tankProperties.rotation); var upOffset = Vec3.multiply(upVector, BUBBLE_SYSTEM_VERTICAL_OFFSET); var frontOffset = Vec3.multiply(frontVector, BUBBLE_SYSTEM_FORWARD_OFFSET); var rightOffset = Vec3.multiply(rightVector, BUBBLE_SYSTEM_LATERAL_OFFSET); - var finalOffset = Vec3.sum(center, upOffset); + var finalOffset = Vec3.sum(tankProperties.position, upOffset); finalOffset = Vec3.sum(finalOffset, frontOffset); finalOffset = Vec3.sum(finalOffset, rightOffset); @@ -137,7 +130,7 @@ function createBubbleSystem() { bubbleProperties.position = finalOffset; bubbleSystem = Entities.addEntity(bubbleProperties); - // createBubbleSound(finalOffset); + // createBubbleSound(finalOffset); } function createBubbleSound(position) { @@ -151,35 +144,37 @@ function createBubbleSound(position) { } -function cleanup() { - Entities.deleteEntity(fishTank); - Entities.deleteEntity(bubbleSystem); - bubbleInjector.stop(); - bubbleInjector = null; -} +function createInnerContainer(position) { + + var tankProperties = Entities.getEntityProperties(fishTank); -function createInnerContainer(){ var containerProps = { - name:"hifi-home-fishtank-inner-container", - type:'Box', - color:{ - red:0, - green:0, - blue:255 + name: "hifi-home-fishtank-inner-container", + type: 'Box', + color: { + red: 0, + green: 0, + blue: 255 }, - dimensions:{ - - } + parentID: fishTank, + dimensions: INNER_TANK_DIMENSIONS, + position: tankProperties.position, + visible: false, + collisionless: true, + dynamic:false }; + + innerContainer = Entities.addEntity(containerProps); } function createEntitiesAtCorners() { - var bounds = Entities.getEntityProperties(fishTank, "boundingBox").boundingBox; + var bounds = Entities.getEntityProperties(innerContainer, "boundingBox").boundingBox; var lowerProps = { - name:'hifi-home-fishtank-lower-corner', + name: 'hifi-home-fishtank-lower-corner', type: "Box", + parentID: fishTank, dimensions: { x: 0.2, y: 0.2, @@ -195,8 +190,9 @@ function createEntitiesAtCorners() { } var upperProps = { - name:'hifi-home-fishtank-upper-corner', + name: 'hifi-home-fishtank-upper-corner', type: "Box", + parentID: fishTank, dimensions: { x: 0.2, y: 0.2, @@ -208,25 +204,105 @@ function createEntitiesAtCorners() { blue: 0 }, collisionless: true, - position:bounds.tfl + position: bounds.tfl } - var lowerCorner = Entities.addEntity(lowerProps); - var upperCorner = Entities.addEntity(upperProps); - print('CORNERS :::' + JSON.stringify(upperCorner) ) - print('CORNERS :::' + JSON.stringify(lowerCorner) ) + lowerCorner = Entities.addEntity(lowerProps); + upperCorner = Entities.addEntity(upperProps); + print('CORNERS :::' + JSON.stringify(upperCorner)) + print('CORNERS :::' + JSON.stringify(lowerCorner)) } createFishTank(); +createInnerContainer(); + createBubbleSystem(); createEntitiesAtCorners(); -//createBubbleSound(); +createBubbleSound(); + +var customKey = 'hifi-home-fishtank'; +var id = fishTank; +print('FISH TANK ID AT START:: '+id) +var data = { + fishLoaded: false, + bubbleSystem: bubbleSystem, + bubbleSound: bubbleSound, + corners: { + brn: lowerCorner, + tfl: upperCorner + }, + innerContainer: innerContainer, + + } + // print('DATA AT CREATE IS:::' + JSON.stringify(data)); +setEntityCustomData(customKey, id, data); +setEntityCustomData('grabbableKey', id, { + grabbable: false +}); + +function cleanup() { + Entities.deleteEntity(fishTank); + Entities.deleteEntity(bubbleSystem); + Entities.deleteEntity(innerContainer); + bubbleInjector.stop(); + bubbleInjector = null; +} if (CLEANUP === true) { Script.scriptEnding.connect(cleanup); +} + +// Copyright 2016 High Fidelity, Inc. +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +function setEntityUserData(id, data) { + var json = JSON.stringify(data) + Entities.editEntity(id, { + userData: json + }); +} + +// FIXME do non-destructive modification of the existing user data +function getEntityUserData(id) { + var results = null; + var properties = Entities.getEntityProperties(id, "userData"); + if (properties.userData) { + try { + results = JSON.parse(properties.userData); + } catch (err) { + // print('error parsing json'); + // print('properties are:'+ properties.userData); + } + } + return results ? results : {}; +} + + +// Non-destructively modify the user data of an entity. +function setEntityCustomData(customKey, id, data) { + var userData = getEntityUserData(id); + if (data == null) { + delete userData[customKey]; + } else { + userData[customKey] = data; + } + setEntityUserData(id, userData); +} + +function getEntityCustomData(customKey, id, defaultValue) { + var userData = getEntityUserData(id); + if (undefined != userData[customKey]) { + return userData[customKey]; + } else { + return defaultValue; + } } \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index cc845ea63e..a835922ece 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -26,6 +26,7 @@ function startUpdate() { //when the baton is claimed; + print('trying to claim the object' + _entityID) iOwn = true; connected = true; Script.update.connect(_this.update); @@ -111,7 +112,9 @@ unload: function() { print(' UNLOAD') - Script.update.disconnect(_this.update); + if (connected === true) { + Script.update.disconnect(_this.update); + } if (WANT_LOOK_DEBUG_LINE === true) { _this.overlayLineOff(); } @@ -123,7 +126,8 @@ }, update: function() { if (iOwn === false) { - //exit if we're not supposed to be simulating the fish + print('i dont own') + //exit if we're not supposed to be simulating the fish return } // print('i am the owner!') @@ -221,9 +225,10 @@ }; - var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); - - if (intersection.intersects && intersection.entityID === _this.entityID) { + // var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); + var userData = JSON.parse(_this.currentProperties.userData); + var intersection = Entities.findRayIntersection(pickRay, true, [userData['hifi-home-fishtank'].innerContainer],[_this.entityID]); + if (intersection.intersects && intersection.entityID === userData['hifi-home-fishtank'].innerContainer) { //print('intersecting a tank') if (WANT_LOOK_DEBUG_SPHERE === true) { if (_this.debugSphere === null) { @@ -232,7 +237,7 @@ _this.updateDebugSphere(intersection.intersection); } } - if (intersection.distance > 1.5) { + if (intersection.distance > LOOK_ATTRACTOR_DISTANCE) { if (WANT_LOOK_DEBUG_SPHERE === true) { _this.debugSphereOff(); } @@ -327,6 +332,7 @@ var COHESION_FORCE = 0.025; var ALIGNMENT_FORCE = 0.025; var LOOK_ATTRACTOR_FORCE = 0.029; + var LOOK_ATTRACTOR_DISTANCE = 1.75; var SWIMMING_FORCE = 0.05; var SWIMMING_SPEED = 0.5; var FISH_DAMPING = 0.25; @@ -350,45 +356,8 @@ }; } - function createEntitiesAtCorners(lower, upper) { - var lowerProps = { - type: "box", - dimensions: { - x: 0.2, - y: 0.2, - z: 0.2 - }, - color: { - red: 255, - green: 0, - blue: 0 - }, - collisionless: true, - position: lower - } - - var upperProps = { - type: "box", - dimensions: { - x: 0.2, - y: 0.2, - z: 0.2 - }, - color: { - red: 0, - green: 255, - blue: 0 - }, - collisionless: true, - position: upper - } - - _this.lowerCorner = Entities.addEntity(lowerProps); - _this.upperCorner = Entities.addEntity(upperProps); - - } - function updateFish(deltaTime) { + // print('update loop') if (_this.tankLocked === true) { return; @@ -408,11 +377,12 @@ } - // print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) + // print('has userdata fish??' + _this.userData['hifi-home-fishtank'].fishLoaded) if (_this.userData['hifi-home-fishtank'].fishLoaded === false) { //no fish in the user data _this.tankLocked = true; + print('NO FISH YET SO LOAD EM!!!') loadFish(NUM_FISH); setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, { fishLoaded: true @@ -457,8 +427,6 @@ lowerCorner = bounds.brn; upperCorner = bounds.tfl; - //createEntitiesAtCorners(lowerCorner,upperCorner); - // First pre-load an array with properties on all the other fish so our per-fish loop // isn't doing it. var flockProperties = []; From cd233165e7612bf258bf6368054ec1b4f95ac3d0 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 1 Mar 2016 19:41:05 -0800 Subject: [PATCH 20/59] whitelist and blacklist inner contianer and corner entities --- .../DomainContent/Home/fishTank/createFishTank.js | 6 ++++-- .../DomainContent/Home/fishTank/tank.js | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 92a21ff15b..141665523f 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -9,7 +9,7 @@ var TANK_DIMENSIONS = { var INNER_TANK_SCALE = 0.7; var INNER_TANK_DIMENSIONS = Vec3.multiply(INNER_TANK_SCALE, TANK_DIMENSIONS); -INNER_TANK_DIMENSIONS.y = INNER_TANK_DIMENSIONS.y -0.25; +INNER_TANK_DIMENSIONS.y = INNER_TANK_DIMENSIONS.y -0.4; var TANK_WIDTH = TANK_DIMENSIONS.z; var TANK_HEIGHT = TANK_DIMENSIONS.y; @@ -238,7 +238,7 @@ var data = { innerContainer: innerContainer, } - // print('DATA AT CREATE IS:::' + JSON.stringify(data)); +print('DATA AT CREATE IS:::' + JSON.stringify(data)); setEntityCustomData(customKey, id, data); setEntityCustomData('grabbableKey', id, { grabbable: false @@ -248,6 +248,8 @@ function cleanup() { Entities.deleteEntity(fishTank); Entities.deleteEntity(bubbleSystem); Entities.deleteEntity(innerContainer); + Entities.deleteEntity(lowerCorner); + Entities.deleteEntity(upperCorner); bubbleInjector.stop(); bubbleInjector = null; } diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index a835922ece..2f4ebc24a3 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -225,10 +225,15 @@ }; - // var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); var userData = JSON.parse(_this.currentProperties.userData); - var intersection = Entities.findRayIntersection(pickRay, true, [userData['hifi-home-fishtank'].innerContainer],[_this.entityID]); - if (intersection.intersects && intersection.entityID === userData['hifi-home-fishtank'].innerContainer) { + + var brn = userData['hifi-home-fishtank']['corners'].brn; + var tfl = userData['hifi-home-fishtank']['corners'].tfl; + var innerContainer = userData['hifi-home-fishtank'].innerContainer; + + var intersection = Entities.findRayIntersection(pickRay, true, [innerContainer], [_this.entityID, brn, tfl]); + + if (intersection.intersects && intersection.entityID === innerContainer) { //print('intersecting a tank') if (WANT_LOOK_DEBUG_SPHERE === true) { if (_this.debugSphere === null) { @@ -422,7 +427,6 @@ z: 0 }; - //var center = _this.currentProperties.position; var bounds = Entities.getEntityProperties(_this.entityID, "boundingBox").boundingBox; lowerCorner = bounds.brn; upperCorner = bounds.tfl; From 3f146a734b3a11a1719b96316a61cd46bdcf686b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 1 Mar 2016 19:46:39 -0800 Subject: [PATCH 21/59] user inner tank for bounds --- unpublishedScripts/DomainContent/Home/fishTank/tank.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 2f4ebc24a3..1fc174d4fb 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -426,8 +426,9 @@ y: 0, z: 0 }; - - var bounds = Entities.getEntityProperties(_this.entityID, "boundingBox").boundingBox; + var userData = JSON.parse(_this.currentProperties.userData); + var innerContainer = userData['hifi-home-fishtank']['innerContainer']; + var bounds = Entities.getEntityProperties(innerContainer, "boundingBox").boundingBox; lowerCorner = bounds.brn; upperCorner = bounds.tfl; From e3d44c4e2724440e8d86d83f7e7472cd9f6ab1e8 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 4 Mar 2016 14:22:57 -0800 Subject: [PATCH 22/59] add urchin and rocks --- .../Home/fishTank/createFishTank.js | 124 ++++++++++++++---- 1 file changed, 99 insertions(+), 25 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 141665523f..e84cab2a68 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,4 +1,4 @@ -var fishTank, bubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner; +var fishTank, bubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; var CLEANUP = true; var TANK_DIMENSIONS = { @@ -9,7 +9,7 @@ var TANK_DIMENSIONS = { var INNER_TANK_SCALE = 0.7; var INNER_TANK_DIMENSIONS = Vec3.multiply(INNER_TANK_SCALE, TANK_DIMENSIONS); -INNER_TANK_DIMENSIONS.y = INNER_TANK_DIMENSIONS.y -0.4; +INNER_TANK_DIMENSIONS.y = INNER_TANK_DIMENSIONS.y - 0.4; var TANK_WIDTH = TANK_DIMENSIONS.z; var TANK_HEIGHT = TANK_DIMENSIONS.y; @@ -27,7 +27,7 @@ var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx"; -var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x - 0.05; +var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x ; //depth of tank var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.15; var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.5; @@ -41,6 +41,31 @@ var BUBBLE_SYSTEM_DIMENSIONS = { var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav"; var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); +var URCHIN_FORWARD_OFFSET =-TANK_DIMENSIONS.x; +//depth of tank +var URCHIN_LATERAL_OFFSET = 0.15; +var URCHIN_VERTICAL_OFFSET = -0.4; + +var URCHIN_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Urchin.fbx'; + +var URCHIN_DIMENSIONS = { + x: 0.35, + y: 0.35, + z: 0.35 +} + +var ROCKS_FORWARD_OFFSET = (TANK_DIMENSIONS.x/2)-0.75; +//depth of tank +var ROCKS_LATERAL_OFFSET = 0.05; +var ROCKS_VERTICAL_OFFSET = -0.45; + +var ROCK_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Aquarium-Rocks-2.fbx'; + +var ROCK_DIMENSIONS = { + x: 0.88, + y: 0.33, + z: 2.9 +} function createFishTank() { var tankProperties = { @@ -114,23 +139,32 @@ function createBubbleSystem() { bubbleProperties.parentID = fishTank; bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS; + var finalOffset = getOffsetFromTankCenter(BUBBLE_SYSTEM_VERTICAL_OFFSET, BUBBLE_SYSTEM_FORWARD_OFFSET, BUBBLE_SYSTEM_LATERAL_OFFSET); + + bubbleProperties.position = finalOffset; + + bubbleSystem = Entities.addEntity(bubbleProperties); + createBubbleSound(finalOffset); +} + + +function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET) { + + var tankProperties = Entities.getEntityProperties(fishTank); + var upVector = Quat.getUp(tankProperties.rotation); var frontVector = Quat.getFront(tankProperties.rotation); var rightVector = Quat.getRight(tankProperties.rotation); - var upOffset = Vec3.multiply(upVector, BUBBLE_SYSTEM_VERTICAL_OFFSET); - var frontOffset = Vec3.multiply(frontVector, BUBBLE_SYSTEM_FORWARD_OFFSET); - var rightOffset = Vec3.multiply(rightVector, BUBBLE_SYSTEM_LATERAL_OFFSET); + var upOffset = Vec3.multiply(upVector, VERTICAL_OFFSET); + var frontOffset = Vec3.multiply(frontVector, FORWARD_OFFSET); + var rightOffset = Vec3.multiply(rightVector, LATERAL_OFFSET); var finalOffset = Vec3.sum(tankProperties.position, upOffset); finalOffset = Vec3.sum(finalOffset, frontOffset); finalOffset = Vec3.sum(finalOffset, rightOffset); - - print('final bubble offset:: ' + JSON.stringify(finalOffset)); - bubbleProperties.position = finalOffset; - - bubbleSystem = Entities.addEntity(bubbleProperties); - // createBubbleSound(finalOffset); + print('final offset is: ' + finalOffset) + return finalOffset } function createBubbleSound(position) { @@ -161,7 +195,7 @@ function createInnerContainer(position) { position: tankProperties.position, visible: false, collisionless: true, - dynamic:false + dynamic: false }; innerContainer = Entities.addEntity(containerProps); @@ -186,7 +220,8 @@ function createEntitiesAtCorners() { blue: 0 }, collisionless: true, - position: bounds.brn + position: bounds.brn, + visible:false } var upperProps = { @@ -204,7 +239,8 @@ function createEntitiesAtCorners() { blue: 0 }, collisionless: true, - position: bounds.tfl + position: bounds.tfl, + visible:false } lowerCorner = Entities.addEntity(lowerProps); @@ -213,6 +249,38 @@ function createEntitiesAtCorners() { print('CORNERS :::' + JSON.stringify(lowerCorner)) } +function createRocks() { + var finalPosition = getOffsetFromTankCenter(ROCKS_VERTICAL_OFFSET, ROCKS_FORWARD_OFFSET, ROCKS_LATERAL_OFFSET); + + var properties = { + name: 'hifi-home-fishtank-rock', + type: 'Model', + parentID: fishTank, + modelURL: ROCK_MODEL_URL, + position: finalPosition, + dimensions: ROCK_DIMENSIONS + } + + rocks = Entities.addEntity(properties); +} + +function createUrchin() { + var finalPosition = getOffsetFromTankCenter(URCHIN_VERTICAL_OFFSET, URCHIN_FORWARD_OFFSET, URCHIN_LATERAL_OFFSET); + + var properties = { + name: 'hifi-home-fishtank-urchin', + type: 'Model', + parentID: fishTank, + modelURL: URCHIN_MODEL_URL, + position: finalPosition, + shapeType: 'Sphere', + dimensions: URCHIN_DIMENSIONS + } + + urchin = Entities.addEntity(properties); + +} + createFishTank(); @@ -224,20 +292,24 @@ createEntitiesAtCorners(); createBubbleSound(); +createUrchin(); + +createRocks(); + var customKey = 'hifi-home-fishtank'; var id = fishTank; -print('FISH TANK ID AT START:: '+id) +print('FISH TANK ID AT START:: ' + id) var data = { - fishLoaded: false, - bubbleSystem: bubbleSystem, - bubbleSound: bubbleSound, - corners: { - brn: lowerCorner, - tfl: upperCorner - }, - innerContainer: innerContainer, + fishLoaded: false, + bubbleSystem: bubbleSystem, + bubbleSound: bubbleSound, + corners: { + brn: lowerCorner, + tfl: upperCorner + }, + innerContainer: innerContainer, - } +} print('DATA AT CREATE IS:::' + JSON.stringify(data)); setEntityCustomData(customKey, id, data); setEntityCustomData('grabbableKey', id, { @@ -250,6 +322,8 @@ function cleanup() { Entities.deleteEntity(innerContainer); Entities.deleteEntity(lowerCorner); Entities.deleteEntity(upperCorner); + Entities.deleteEntity(urchin); + Entities.deleteEntity(rocks); bubbleInjector.stop(); bubbleInjector = null; } From 691c0c7d24115c0368b34f7c1aa3503c41482f91 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 4 Mar 2016 17:29:22 -0800 Subject: [PATCH 23/59] gofish! --- .../Home/fishTank/createFishTank.js | 34 +++-- .../DomainContent/Home/fishTank/tank.js | 142 +++++++++++++----- 2 files changed, 127 insertions(+), 49 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index e84cab2a68..f52a56563d 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -43,8 +43,8 @@ var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); var URCHIN_FORWARD_OFFSET =-TANK_DIMENSIONS.x; //depth of tank -var URCHIN_LATERAL_OFFSET = 0.15; -var URCHIN_VERTICAL_OFFSET = -0.4; +var URCHIN_LATERAL_OFFSET = -0.15; +var URCHIN_VERTICAL_OFFSET = -0.37; var URCHIN_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Urchin.fbx'; @@ -56,8 +56,8 @@ var URCHIN_DIMENSIONS = { var ROCKS_FORWARD_OFFSET = (TANK_DIMENSIONS.x/2)-0.75; //depth of tank -var ROCKS_LATERAL_OFFSET = 0.05; -var ROCKS_VERTICAL_OFFSET = -0.45; +var ROCKS_LATERAL_OFFSET = 0.0; +var ROCKS_VERTICAL_OFFSET = (-TANK_DIMENSIONS.y/2)+0.25; var ROCK_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Aquarium-Rocks-2.fbx'; @@ -144,7 +144,7 @@ function createBubbleSystem() { bubbleProperties.position = finalOffset; bubbleSystem = Entities.addEntity(bubbleProperties); - createBubbleSound(finalOffset); + //createBubbleSound(finalOffset); } @@ -169,7 +169,7 @@ function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET function createBubbleSound(position) { var audioProperties = { - volume: 1, + volume: 0, position: position, loop: true }; @@ -297,8 +297,8 @@ createUrchin(); createRocks(); var customKey = 'hifi-home-fishtank'; -var id = fishTank; -print('FISH TANK ID AT START:: ' + id) + + var data = { fishLoaded: false, bubbleSystem: bubbleSystem, @@ -310,11 +310,19 @@ var data = { innerContainer: innerContainer, } -print('DATA AT CREATE IS:::' + JSON.stringify(data)); -setEntityCustomData(customKey, id, data); -setEntityCustomData('grabbableKey', id, { - grabbable: false -}); + +//fisthank initialize has a different UUID than the model that i see +Script.setTimeout(function(){ + print('CREATE TIMEOUT!!!') + print('TANK AT CREATE IS::: '+ fishTank) + print('DATA AT CREATE IS:::' + JSON.stringify(data)); + +setEntityCustomData(customKey, fishTank, data); +// setEntityCustomData('grabbableKey', id, { +// grabbable: false +// }); +},2000) + function cleanup() { Entities.deleteEntity(fishTank); diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 1fc174d4fb..5bcb4c99a8 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -1,7 +1,6 @@ (function() { Script.include('../../../../examples/libraries/virtualBaton.js?' + Math.random()); - Script.include('../../../../examples/libraries/utils.js?' + Math.random()); //only one person should simulate the tank at a time -- we pass around a virtual baton var baton; @@ -71,16 +70,22 @@ }, initialize: function(entityID) { - print('JBP fishtank initialize' + entityID) - var properties = Entities.getEntityProperties(entityID); - if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + var properties = Entities.getEntityProperties(entityID) + + if (properties.hasOwnProperty('userData') === false || properties.userData.length === 0) { _this.initTimeout = Script.setTimeout(function() { - print('JBP no user data yet, try again in one second') + if (properties.hasOwnProperty('userData')) { + print('JBP has user data property') + } + if (properties.userData.length === 0) { + print('JBP user data length is zero') + } + + print('JBP try again in one second') _this.initialize(entityID); }, 1000) } else { - print('JBP userdata before parse attempt' + properties.userData) _this.userData = null; try { @@ -106,6 +111,9 @@ this.entityID = entityID; _entityID = entityID; this.initialize(entityID); + // if(_this.initTimeout!==null){ + // Script.clearTimeout(_this.initTimeout) + // } this.initTimeout = null; }, @@ -124,7 +132,8 @@ } }, - update: function() { + update: function(deltaTime) { + if (iOwn === false) { print('i dont own') //exit if we're not supposed to be simulating the fish @@ -132,7 +141,7 @@ } // print('i am the owner!') //do stuff - updateFish(); + updateFish(deltaTime); _this.seeIfOwnerIsLookingAtTheTank(); }, @@ -166,11 +175,9 @@ }, debugSphereOff: function() { - // Entities.deleteEntity(_this.debugSphere); Entities.editEntity(_this.debugSphere, { - visible: false - }) - //_this.debugSphere = null; + visible: false + }) }, @@ -224,12 +231,9 @@ }; - - var userData = JSON.parse(_this.currentProperties.userData); - - var brn = userData['hifi-home-fishtank']['corners'].brn; - var tfl = userData['hifi-home-fishtank']['corners'].tfl; - var innerContainer = userData['hifi-home-fishtank'].innerContainer; + var brn = _this.userData['hifi-home-fishtank']['corners'].brn; + var tfl = _this.userData['hifi-home-fishtank']['corners'].tfl; + var innerContainer = _this.userData['hifi-home-fishtank'].innerContainer; var intersection = Entities.findRayIntersection(pickRay, true, [innerContainer], [_this.entityID, brn, tfl]); @@ -329,18 +333,24 @@ var TANK_WIDTH = TANK_DIMENSIONS.z / 2; var TANK_HEIGHT = TANK_DIMENSIONS.y / 2; - var FISH_WIDTH = 0.03; - var FISH_LENGTH = 0.15; + + var FISH_DIMENSIONS = { + x: 0.0149, + y: 0.02546, + z: 0.0823 + } + var MAX_SIGHT_DISTANCE = 1.5; var MIN_SEPARATION = 0.15; - var AVOIDANCE_FORCE = 0.32; + var AVOIDANCE_FORCE = 0.032; var COHESION_FORCE = 0.025; var ALIGNMENT_FORCE = 0.025; var LOOK_ATTRACTOR_FORCE = 0.029; var LOOK_ATTRACTOR_DISTANCE = 1.75; var SWIMMING_FORCE = 0.05; var SWIMMING_SPEED = 0.5; - var FISH_DAMPING = 0.25; + var FISH_DAMPING = 0.55; + var FISH_ANGULAR_DAMPING = 0.55; var THROTTLE = false; var THROTTLE_RATE = 100; @@ -389,9 +399,18 @@ _this.tankLocked = true; print('NO FISH YET SO LOAD EM!!!') loadFish(NUM_FISH); - setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, { - fishLoaded: true - }); + var data = { + fishLoaded: true, + bubbleSystem: _this.userData['hifi-home-fishtank'].bubbleSystem, + bubbleSound: _this.userData['hifi-home-fishtank'].bubbleSound, + corners: { + brn: _this.userData['hifi-home-fishtank'].lowerCorner, + tfl: _this.userData['hifi-home-fishtank'].upperCorner + }, + innerContainer: _this.userData['hifi-home-fishtank'].innerContainer, + + } + setEntityCustomData(FISHTANK_USERDATA_KEY, _this.entityID, data); _this.userData['hifi-home-fishtank'].fishLoaded = true; Script.setTimeout(function() { _this.fish = _this.findFishInTank(); @@ -426,6 +445,8 @@ y: 0, z: 0 }; + + var userData = JSON.parse(_this.currentProperties.userData); var innerContainer = userData['hifi-home-fishtank']['innerContainer']; var bounds = Entities.getEntityProperties(innerContainer, "boundingBox").boundingBox; @@ -541,18 +562,26 @@ // Orient in direction of velocity var rotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, velocity); + + var mixedRotation =Quat.mix(properties.rotation, rotation, VELOCITY_FOLLOW_RATE); var VELOCITY_FOLLOW_RATE = 0.30; var safeEuler = Quat.safeEulerAngles(rotation); + safeEuler.z = safeEuler.z *= 0.925; + var newQuat = Quat.fromPitchYawRollDegrees(safeEuler.x, safeEuler.y, safeEuler.z); + + var finalQuat = Quat.multiply(rotation, newQuat); + + // Only update properties if they have changed, to save bandwidth var MIN_POSITION_CHANGE_FOR_UPDATE = 0.001; if (Vec3.distance(properties.position, position) < MIN_POSITION_CHANGE_FOR_UPDATE) { Entities.editEntity(fish[i], { velocity: velocity, - rotation: Quat.mix(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) + rotation: mixedRotation }); } else { Entities.editEntity(fish[i], { @@ -607,17 +636,14 @@ // w: 1 // }, // type: "Box", - // dimensions: { - // x: FISH_WIDTH, - // y: FISH_WIDTH, - // z: FISH_LENGTH - // }, - // velocity: { - // x: SWIMMING_SPEED, - // y: SWIMMING_SPEED, - // z: SWIMMING_SPEED - // }, + dimensions: FISH_DIMENSIONS, + velocity: { + x: SWIMMING_SPEED, + y: SWIMMING_SPEED, + z: SWIMMING_SPEED + }, damping: FISH_DAMPING, + angularDamping: FISH_ANGULAR_DAMPING, dynamic: false, lifetime: LIFETIME, color: { @@ -638,5 +664,49 @@ Script.update.disconnect(_this.update); }) + + function setEntityUserData(id, data) { + var json = JSON.stringify(data) + Entities.editEntity(id, { + userData: json + }); + } + + // FIXME do non-destructive modification of the existing user data + function getEntityUserData(id) { + var results = null; + var properties = Entities.getEntityProperties(id, "userData"); + if (properties.userData) { + try { + results = JSON.parse(properties.userData); + } catch (err) { + // print('error parsing json'); + // print('properties are:'+ properties.userData); + } + } + return results ? results : {}; + } + + + // Non-destructively modify the user data of an entity. + function setEntityCustomData(customKey, id, data) { + var userData = getEntityUserData(id); + if (data == null) { + delete userData[customKey]; + } else { + userData[customKey] = data; + } + setEntityUserData(id, userData); + } + + function getEntityCustomData(customKey, id, defaultValue) { + var userData = getEntityUserData(id); + if (undefined != userData[customKey]) { + return userData[customKey]; + } else { + return defaultValue; + } + } + return new FishTank(); }); \ No newline at end of file From 3929af7187b60d06a6c3855e1f805f372c970bcc Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 4 Mar 2016 18:01:32 -0800 Subject: [PATCH 24/59] fishtweaks --- .../DomainContent/Home/fishTank/tank.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 5bcb4c99a8..599502ef70 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -262,9 +262,6 @@ if (_this.hasLookAttractor === true) { _this.clearLookAttractor(); } - if (WANT_LOOK_DEBUG_SPHERE === true) { - _this.debugSphereOff(); - } } }, //look attractors could be private to the tank... @@ -345,9 +342,9 @@ var AVOIDANCE_FORCE = 0.032; var COHESION_FORCE = 0.025; var ALIGNMENT_FORCE = 0.025; - var LOOK_ATTRACTOR_FORCE = 0.029; + var LOOK_ATTRACTOR_FORCE = 0.02; var LOOK_ATTRACTOR_DISTANCE = 1.75; - var SWIMMING_FORCE = 0.05; + var SWIMMING_FORCE = 0.025; var SWIMMING_SPEED = 0.5; var FISH_DAMPING = 0.55; var FISH_ANGULAR_DAMPING = 0.55; @@ -540,54 +537,54 @@ // Keep fish in their 'tank' if (position.x < lowerCorner.x) { position.x = lowerCorner.x; - velocity.x *= -1.0; + velocity.x *= -0.15 } else if (position.x > upperCorner.x) { position.x = upperCorner.x; - velocity.x *= -1.0; - } + velocity.x *= -0.15 } if (position.y < lowerCorner.y) { position.y = lowerCorner.y; - velocity.y *= -1.0; + velocity.y *= -0.15 } else if (position.y > upperCorner.y) { position.y = upperCorner.y; - velocity.y *= -1.0; + velocity.y *= -0.15 } if (position.z < lowerCorner.z) { position.z = lowerCorner.z; - velocity.z *= -1.0; + velocity.z *= -0.15 } else if (position.z > upperCorner.z) { position.z = upperCorner.z; - velocity.z *= -1.0; + velocity.z *= -0.15 } // Orient in direction of velocity var rotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, velocity); - var mixedRotation =Quat.mix(properties.rotation, rotation, VELOCITY_FOLLOW_RATE); + var mixedRotation = Quat.mix(properties.rotation, rotation, VELOCITY_FOLLOW_RATE); var VELOCITY_FOLLOW_RATE = 0.30; - var safeEuler = Quat.safeEulerAngles(rotation); + var slerpedRotation = Quat.slerp(properties.rotation, rotation, VELOCITY_FOLLOW_RATE); + var safeEuler = Quat.safeEulerAngles(rotation); safeEuler.z = safeEuler.z *= 0.925; + //note: a we want the fish to both rotate toward its velocity and not roll over, and also not pitch more than 30 degrees positive or negative (not doing that last bit right quite yet) var newQuat = Quat.fromPitchYawRollDegrees(safeEuler.x, safeEuler.y, safeEuler.z); - var finalQuat = Quat.multiply(rotation, newQuat); + var finalQuat = Quat.slerp(slerpedRotation, newQuat, 0.5); - // Only update properties if they have changed, to save bandwidth var MIN_POSITION_CHANGE_FOR_UPDATE = 0.001; if (Vec3.distance(properties.position, position) < MIN_POSITION_CHANGE_FOR_UPDATE) { Entities.editEntity(fish[i], { velocity: velocity, - rotation: mixedRotation + rotation: finalQuat }); } else { Entities.editEntity(fish[i], { position: position, velocity: velocity, - rotation: Quat.slerp(properties.rotation, rotation, VELOCITY_FOLLOW_RATE) + rotation: finalQuat }); } } From 2740391c3b1c33e8c5bfc2efd30570b1cf7e31e0 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 4 Mar 2016 18:17:09 -0800 Subject: [PATCH 25/59] end of day --- .../Home/fishTank/createFishTank.js | 32 +++++++++---------- .../DomainContent/Home/fishTank/tank.js | 5 +-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index f52a56563d..31a5d7058c 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -27,7 +27,7 @@ var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx"; -var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x ; +var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x; //depth of tank var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.15; var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.5; @@ -41,7 +41,7 @@ var BUBBLE_SYSTEM_DIMENSIONS = { var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav"; var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); -var URCHIN_FORWARD_OFFSET =-TANK_DIMENSIONS.x; +var URCHIN_FORWARD_OFFSET = -TANK_DIMENSIONS.x; //depth of tank var URCHIN_LATERAL_OFFSET = -0.15; var URCHIN_VERTICAL_OFFSET = -0.37; @@ -54,10 +54,10 @@ var URCHIN_DIMENSIONS = { z: 0.35 } -var ROCKS_FORWARD_OFFSET = (TANK_DIMENSIONS.x/2)-0.75; +var ROCKS_FORWARD_OFFSET = (TANK_DIMENSIONS.x / 2) - 0.75; //depth of tank var ROCKS_LATERAL_OFFSET = 0.0; -var ROCKS_VERTICAL_OFFSET = (-TANK_DIMENSIONS.y/2)+0.25; +var ROCKS_VERTICAL_OFFSET = (-TANK_DIMENSIONS.y / 2) + 0.25; var ROCK_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Aquarium-Rocks-2.fbx'; @@ -103,7 +103,7 @@ function createBubbleSystem() { }, "emitDimensions": { "x": -0.2, - "y": 1.2000000000000002, + "y": 1.6000000000000002, "z": 0 }, "polarStart": 0, @@ -144,7 +144,7 @@ function createBubbleSystem() { bubbleProperties.position = finalOffset; bubbleSystem = Entities.addEntity(bubbleProperties); - //createBubbleSound(finalOffset); + createBubbleSound(finalOffset); } @@ -169,7 +169,7 @@ function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET function createBubbleSound(position) { var audioProperties = { - volume: 0, + volume: 1, position: position, loop: true }; @@ -221,7 +221,7 @@ function createEntitiesAtCorners() { }, collisionless: true, position: bounds.brn, - visible:false + visible: false } var upperProps = { @@ -240,7 +240,7 @@ function createEntitiesAtCorners() { }, collisionless: true, position: bounds.tfl, - visible:false + visible: false } lowerCorner = Entities.addEntity(lowerProps); @@ -312,16 +312,16 @@ var data = { } //fisthank initialize has a different UUID than the model that i see -Script.setTimeout(function(){ +Script.setTimeout(function() { print('CREATE TIMEOUT!!!') - print('TANK AT CREATE IS::: '+ fishTank) + print('TANK AT CREATE IS::: ' + fishTank) print('DATA AT CREATE IS:::' + JSON.stringify(data)); -setEntityCustomData(customKey, fishTank, data); -// setEntityCustomData('grabbableKey', id, { -// grabbable: false -// }); -},2000) + setEntityCustomData(customKey, fishTank, data); + // setEntityCustomData('grabbableKey', id, { + // grabbable: false + // }); +}, 2000) function cleanup() { diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 599502ef70..0f42a000be 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -11,7 +11,7 @@ var TANK_SEARCH_RADIUS = 5; var WANT_LOOK_DEBUG_LINE = false; - var WANT_LOOK_DEBUG_SPHERE = true; + var WANT_LOOK_DEBUG_SPHERE = false; var INTERSECT_COLOR = { red: 255, @@ -540,7 +540,8 @@ velocity.x *= -0.15 } else if (position.x > upperCorner.x) { position.x = upperCorner.x; - velocity.x *= -0.15 } + velocity.x *= -0.15 + } if (position.y < lowerCorner.y) { position.y = lowerCorner.y; velocity.y *= -0.15 From 5f9b64444cdb63351a94c1f880881ef33d38029f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 7 Mar 2016 10:19:21 -0800 Subject: [PATCH 26/59] second bubble system, quieter noise --- .../Home/fishTank/createFishTank.js | 76 ++++++++++++++++++- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 31a5d7058c..53338a978e 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,4 +1,4 @@ -var fishTank, bubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; +var fishTank, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; var CLEANUP = true; var TANK_DIMENSIONS = { @@ -103,7 +103,7 @@ function createBubbleSystem() { }, "emitDimensions": { "x": -0.2, - "y": 1.6000000000000002, + "y": TANK_DIMENSIONS.y, "z": 0 }, "polarStart": 0, @@ -147,6 +147,71 @@ function createBubbleSystem() { createBubbleSound(finalOffset); } +function createSecondBubbleSystem() { + + var tankProperties = Entities.getEntityProperties(fishTank); + var bubbleProperties = { + "name": 'hifi-home-fishtank-bubbles', + "color": {}, + "isEmitting": 1, + "maxParticles": 1880, + "lifespan": 1.6, + "emitRate": 10, + "emitSpeed": 0.025, + "speedSpread": 0.025, + "emitOrientation": { + "x": 0, + "y": 0.5, + "z": 0.5, + "w": 0 + }, + "emitDimensions": { + "x": -0.4, + "y": TANK_DIMENSIONS.y, + "z": 0 + }, + "polarStart": 0, + "polarFinish": 0, + "azimuthStart": 0.2, + "azimuthFinish": 0.1, + "emitAcceleration": { + "x": 0, + "y": 0.4, + "z": 0 + }, + "accelerationSpread": { + "x": 0.1, + "y": 0.1, + "z": 0.1 + }, + "particleRadius": 0.02, + "radiusSpread": 0, + "radiusStart": 0.043, + "radiusFinish": 0.02, + "colorSpread": {}, + "colorStart": {}, + "colorFinish": {}, + "alpha": 0.2, + "alphaSpread": 0, + "alphaStart": 0.3, + "alphaFinish": 0, + "emitterShouldTrail": 0, + "textures": "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/bubble-white.png" + }; + + bubbleProperties.type = "ParticleEffect"; + bubbleProperties.parentID = fishTank; + bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS; + + var finalOffset = getOffsetFromTankCenter(BUBBLE_SYSTEM_VERTICAL_OFFSET, BUBBLE_SYSTEM_FORWARD_OFFSET, BUBBLE_SYSTEM_LATERAL_OFFSET - 0.076); + + bubbleProperties.position = finalOffset; + + secondBubbleSystem = Entities.addEntity(bubbleProperties); + +} + + function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET) { @@ -169,7 +234,7 @@ function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET function createBubbleSound(position) { var audioProperties = { - volume: 1, + volume: 0.05, position: position, loop: true }; @@ -288,9 +353,11 @@ createInnerContainer(); createBubbleSystem(); +createSecondBubbleSystem(); + createEntitiesAtCorners(); -createBubbleSound(); + createUrchin(); @@ -327,6 +394,7 @@ Script.setTimeout(function() { function cleanup() { Entities.deleteEntity(fishTank); Entities.deleteEntity(bubbleSystem); + Entities.deleteEntity(secondBubbleSystem); Entities.deleteEntity(innerContainer); Entities.deleteEntity(lowerCorner); Entities.deleteEntity(upperCorner); From 70fd3559eab58961bcde08bd5cb0cd96998f479b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 7 Mar 2016 11:43:59 -0800 Subject: [PATCH 27/59] cleanup; --- .../Home/fishTank/bubbleSystemProperties.json | 47 ----------------- .../Home/fishTank/createFishTank.js | 6 +-- .../DomainContent/Home/fishTank/tank.js | 50 +++++++------------ 3 files changed, 20 insertions(+), 83 deletions(-) delete mode 100644 unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json diff --git a/unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json b/unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json deleted file mode 100644 index 07626c0fc5..0000000000 --- a/unpublishedScripts/DomainContent/Home/fishTank/bubbleSystemProperties.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "color": {}, - "isEmitting": 1, - "maxParticles": 1880, - "lifespan": 1.6, - "emitRate": 10, - "emitSpeed": 0.025, - "speedSpread": 0.025, - "emitOrientation": { - "x": 0, - "y": 0.5, - "z": 0.5, - "w": 0 - }, - "emitDimensions": { - "x": -0.2, - "y": 1.2000000000000002, - "z": 0 - }, - "polarStart": 0, - "polarFinish": 0, - "azimuthStart": 0.2, - "azimuthFinish": 0.1, - "emitAcceleration": { - "x": 0, - "y": 0.4, - "z": 0 - }, - "accelerationSpread": { - "x": 0.1, - "y": 0.1, - "z": 0.1 - }, - "particleRadius": 0.02, - "radiusSpread": 0, - "radiusStart": 0.043, - "radiusFinish": 0.02, - "colorSpread": {}, - "colorStart": {}, - "colorFinish": {}, - "alpha": 0.2, - "alphaSpread": 0, - "alphaStart": 0.3, - "alphaFinish": 0, - "emitterShouldTrail": 0, - "textures": "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/bubble-white.png" -} \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 53338a978e..3227513f60 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,6 +1,6 @@ var fishTank, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; -var CLEANUP = true; +var CLEANUP = false; var TANK_DIMENSIONS = { x: 1.3393, y: 1.3515, @@ -228,7 +228,6 @@ function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET var finalOffset = Vec3.sum(tankProperties.position, upOffset); finalOffset = Vec3.sum(finalOffset, frontOffset); finalOffset = Vec3.sum(finalOffset, rightOffset); - print('final offset is: ' + finalOffset) return finalOffset } @@ -310,8 +309,7 @@ function createEntitiesAtCorners() { lowerCorner = Entities.addEntity(lowerProps); upperCorner = Entities.addEntity(upperProps); - print('CORNERS :::' + JSON.stringify(upperCorner)) - print('CORNERS :::' + JSON.stringify(lowerCorner)) + } function createRocks() { diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 0f42a000be..0f059b3919 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -25,7 +25,7 @@ function startUpdate() { //when the baton is claimed; - print('trying to claim the object' + _entityID) + // print('trying to claim the object' + _entityID) iOwn = true; connected = true; Script.update.connect(_this.update); @@ -33,7 +33,7 @@ function stopUpdateAndReclaim() { //when the baton is released; - print('i released the object ' + _entityID) + // print('i released the object ' + _entityID) iOwn = false; if (connected === true) { connected = false; @@ -54,7 +54,7 @@ overlayLineDistance: 3, debugSphere: null, findFishInTank: function() { - print('looking for a fish in the tank') + // print('looking for a fish in the tank') var results = Entities.findEntities(_this.currentProperties.position, TANK_SEARCH_RADIUS); var fishList = []; @@ -65,7 +65,7 @@ } }) - print('fish? ' + fishList.length) + // print('fish? ' + fishList.length) return fishList; }, @@ -75,27 +75,27 @@ if (properties.hasOwnProperty('userData') === false || properties.userData.length === 0) { _this.initTimeout = Script.setTimeout(function() { if (properties.hasOwnProperty('userData')) { - print('JBP has user data property') + // print('has user data property') } if (properties.userData.length === 0) { - print('JBP user data length is zero') + // print('user data length is zero') } - print('JBP try again in one second') + // print('try again in one second') _this.initialize(entityID); }, 1000) } else { - print('JBP userdata before parse attempt' + properties.userData) + // print('userdata before parse attempt' + properties.userData) _this.userData = null; try { _this.userData = JSON.parse(properties.userData); } catch (err) { - print('JBP error parsing json'); - print('JBP properties are:' + properties.userData); + // print('error parsing json'); + // print('properties are:' + properties.userData); return; } - print('after parse') + // print('after parse') _this.currentProperties = Entities.getEntityProperties(entityID); baton = virtualBaton({ batonName: 'io.highfidelity.fishtank:' + entityID, // One winner for each entity @@ -107,19 +107,16 @@ }, preload: function(entityID) { - print("preload"); + // print("preload"); this.entityID = entityID; _entityID = entityID; this.initialize(entityID); - // if(_this.initTimeout!==null){ - // Script.clearTimeout(_this.initTimeout) - // } this.initTimeout = null; }, unload: function() { - print(' UNLOAD') + // print(' UNLOAD') if (connected === true) { Script.update.disconnect(_this.update); } @@ -127,7 +124,7 @@ _this.overlayLineOff(); } if (baton) { - print('BATON RELEASE ') + // print('BATON RELEASE ') baton.release(function() {}); } @@ -135,8 +132,8 @@ update: function(deltaTime) { if (iOwn === false) { - print('i dont own') - //exit if we're not supposed to be simulating the fish + // print('i dont own') + //exit if we're not supposed to be simulating the fish return } // print('i am the owner!') @@ -214,8 +211,6 @@ _this.overlayLine = null; }, - - seeIfOwnerIsLookingAtTheTank: function() { var cameraPosition = Camera.getPosition(); var cameraOrientation = Camera.getOrientation(); @@ -228,7 +223,6 @@ if (WANT_LOOK_DEBUG_LINE === true) { _this.overlayLineOn(pickRay.origin, Vec3.sum(pickRay.origin, Vec3.multiply(front, _this.overlayLineDistance)), INTERSECT_COLOR); - }; var brn = _this.userData['hifi-home-fishtank']['corners'].brn; @@ -264,7 +258,6 @@ } } }, - //look attractors could be private to the tank... createLookAttractor: function(position, distance) { _this.lookAttractor = { position: position, @@ -296,13 +289,6 @@ // check for intersection // add attractor for closest person (?) - var intersection = Entities.findRayIntersection(pickRay, true, [_this.entityID]); - - if (intersection.intersects && intersection.entityID === _this.entityID) { - print('intersecting a tank') - - print('intersection:: ' + JSON.stringify(intersection)); - } } }; @@ -595,7 +581,7 @@ var STARTING_FRACTION = 0.25; function loadFish(howMany) { - print('LOADING FISH: ' + howMany) + // print('LOADING FISH: ' + howMany) var center = _this.currentProperties.position; @@ -654,7 +640,7 @@ } - print('initial fish::' + fish.length) + // print('initial fish::' + fish.length) _this.tankLocked = false; } From fdaa1f9ded4ce70d1b55d8a0c5bfe6994a696bb6 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 7 Mar 2016 11:45:38 -0800 Subject: [PATCH 28/59] cleanup by default --- .../DomainContent/Home/fishTank/createFishTank.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 3227513f60..465e411c8b 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,6 +1,6 @@ var fishTank, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; -var CLEANUP = false; +var CLEANUP = true; var TANK_DIMENSIONS = { x: 1.3393, y: 1.3515, From 249d88b619aa1bf26ac33bda3e15990e7e0a60ae Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 7 Mar 2016 19:59:27 -0800 Subject: [PATCH 29/59] add base to fishtank --- .../Home/fishTank/createFishTank.js | 64 +++++++++++++++---- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 465e411c8b..56a6f3d745 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,12 +1,19 @@ -var fishTank, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; +var fishTank, tankBase, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; var CLEANUP = true; +// var TANK_DIMENSIONS = { +// x: 1.3393, +// y: 1.3515, +// z: 3.5914 +// }; + var TANK_DIMENSIONS = { - x: 1.3393, - y: 1.3515, - z: 3.5914 + x: 0.8212, + y: 0.8116, + z: 2.1404 }; + var INNER_TANK_SCALE = 0.7; var INNER_TANK_DIMENSIONS = Vec3.multiply(INNER_TANK_SCALE, TANK_DIMENSIONS); INNER_TANK_DIMENSIONS.y = INNER_TANK_DIMENSIONS.y - 0.4; @@ -25,12 +32,24 @@ var TANK_POSITION = center; var TANK_SCRIPT = Script.resolvePath('tank.js?' + Math.random()) -var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquarium-6.fbx"; +var TANK_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquariumTank.fbx"; -var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x; +var TANK_BASE_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquariumBase.fbx'; + +var TANK_BASE_COLLISION_HULL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/aquariumBase.obj' + +var TANK_BASE_DIMENSIONS = { + x: 0.8599, + y: 1.8450, + z: 2.1936 +}; + +var BASE_VERTICAL_OFFSET=0.42; + +var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x+0.06; //depth of tank -var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.15; -var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.5; +var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.025; +var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.25; var BUBBLE_SYSTEM_DIMENSIONS = { x: TANK_DIMENSIONS.x / 8, @@ -44,7 +63,7 @@ var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); var URCHIN_FORWARD_OFFSET = -TANK_DIMENSIONS.x; //depth of tank var URCHIN_LATERAL_OFFSET = -0.15; -var URCHIN_VERTICAL_OFFSET = -0.37; +var URCHIN_VERTICAL_OFFSET = -0.17; var URCHIN_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Urchin.fbx'; @@ -54,7 +73,7 @@ var URCHIN_DIMENSIONS = { z: 0.35 } -var ROCKS_FORWARD_OFFSET = (TANK_DIMENSIONS.x / 2) - 0.75; +var ROCKS_FORWARD_OFFSET = 0; //depth of tank var ROCKS_LATERAL_OFFSET = 0.0; var ROCKS_VERTICAL_OFFSET = (-TANK_DIMENSIONS.y / 2) + 0.25; @@ -62,9 +81,9 @@ var ROCKS_VERTICAL_OFFSET = (-TANK_DIMENSIONS.y / 2) + 0.25; var ROCK_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Aquarium-Rocks-2.fbx'; var ROCK_DIMENSIONS = { - x: 0.88, + x: 0.707, y: 0.33, - z: 2.9 + z: 1.64 } function createFishTank() { @@ -344,6 +363,23 @@ function createUrchin() { } +function createTankBase() { + var properties = { + name: 'hifi-home-fishtank-base', + type: 'Model', + modelURL: TANK_BASE_MODEL_URL, + parentID: fishTank, + shapeType: 'compound', + compoundShapeURL: TANK_BASE_COLLISION_HULL, + position: { + x:TANK_POSITION.x, + y:TANK_POSITION.y-BASE_VERTICAL_OFFSET, + z:TANK_POSITION.z + } + } + tankBase = Entities.addEntity(properties); +} + createFishTank(); @@ -355,12 +391,11 @@ createSecondBubbleSystem(); createEntitiesAtCorners(); - - createUrchin(); createRocks(); +createTankBase(); var customKey = 'hifi-home-fishtank'; @@ -391,6 +426,7 @@ Script.setTimeout(function() { function cleanup() { Entities.deleteEntity(fishTank); + Entities.deleteEntity(tankBase); Entities.deleteEntity(bubbleSystem); Entities.deleteEntity(secondBubbleSystem); Entities.deleteEntity(innerContainer); From 645f0da280f9e5f2ef96d2fe169cb829f44af2b7 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 8 Mar 2016 13:50:04 -0800 Subject: [PATCH 30/59] code cleanupo --- .../Home/fishTank/createFishTank.js | 98 +++---------------- 1 file changed, 13 insertions(+), 85 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 56a6f3d745..59e3372750 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,11 +1,6 @@ var fishTank, tankBase, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; var CLEANUP = true; -// var TANK_DIMENSIONS = { -// x: 1.3393, -// y: 1.3515, -// z: 3.5914 -// }; var TANK_DIMENSIONS = { x: 0.8212, @@ -44,9 +39,9 @@ var TANK_BASE_DIMENSIONS = { z: 2.1936 }; -var BASE_VERTICAL_OFFSET=0.42; +var BASE_VERTICAL_OFFSET = 0.42; -var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x+0.06; +var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x + 0.06; //depth of tank var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.025; var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.25; @@ -102,12 +97,11 @@ function createFishTank() { fishTank = Entities.addEntity(tankProperties); } -function createBubbleSystem() { +function createBubbleSystems() { var tankProperties = Entities.getEntityProperties(fishTank); var bubbleProperties = { "name": 'hifi-home-fishtank-bubbles', - "color": {}, "isEmitting": 1, "maxParticles": 1880, "lifespan": 1.6, @@ -143,9 +137,6 @@ function createBubbleSystem() { "radiusSpread": 0, "radiusStart": 0.043, "radiusFinish": 0.02, - "colorSpread": {}, - "colorStart": {}, - "colorFinish": {}, "alpha": 0.2, "alphaSpread": 0, "alphaStart": 0.3, @@ -161,75 +152,14 @@ function createBubbleSystem() { var finalOffset = getOffsetFromTankCenter(BUBBLE_SYSTEM_VERTICAL_OFFSET, BUBBLE_SYSTEM_FORWARD_OFFSET, BUBBLE_SYSTEM_LATERAL_OFFSET); bubbleProperties.position = finalOffset; - bubbleSystem = Entities.addEntity(bubbleProperties); + + bubbleProperties.position.z += -0.076; + secondBubbleSystem = Entities.addEntity(bubbleProperties) + createBubbleSound(finalOffset); } -function createSecondBubbleSystem() { - - var tankProperties = Entities.getEntityProperties(fishTank); - var bubbleProperties = { - "name": 'hifi-home-fishtank-bubbles', - "color": {}, - "isEmitting": 1, - "maxParticles": 1880, - "lifespan": 1.6, - "emitRate": 10, - "emitSpeed": 0.025, - "speedSpread": 0.025, - "emitOrientation": { - "x": 0, - "y": 0.5, - "z": 0.5, - "w": 0 - }, - "emitDimensions": { - "x": -0.4, - "y": TANK_DIMENSIONS.y, - "z": 0 - }, - "polarStart": 0, - "polarFinish": 0, - "azimuthStart": 0.2, - "azimuthFinish": 0.1, - "emitAcceleration": { - "x": 0, - "y": 0.4, - "z": 0 - }, - "accelerationSpread": { - "x": 0.1, - "y": 0.1, - "z": 0.1 - }, - "particleRadius": 0.02, - "radiusSpread": 0, - "radiusStart": 0.043, - "radiusFinish": 0.02, - "colorSpread": {}, - "colorStart": {}, - "colorFinish": {}, - "alpha": 0.2, - "alphaSpread": 0, - "alphaStart": 0.3, - "alphaFinish": 0, - "emitterShouldTrail": 0, - "textures": "http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/bubble-white.png" - }; - - bubbleProperties.type = "ParticleEffect"; - bubbleProperties.parentID = fishTank; - bubbleProperties.dimensions = BUBBLE_SYSTEM_DIMENSIONS; - - var finalOffset = getOffsetFromTankCenter(BUBBLE_SYSTEM_VERTICAL_OFFSET, BUBBLE_SYSTEM_FORWARD_OFFSET, BUBBLE_SYSTEM_LATERAL_OFFSET - 0.076); - - bubbleProperties.position = finalOffset; - - secondBubbleSystem = Entities.addEntity(bubbleProperties); - -} - function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET) { @@ -372,22 +302,20 @@ function createTankBase() { shapeType: 'compound', compoundShapeURL: TANK_BASE_COLLISION_HULL, position: { - x:TANK_POSITION.x, - y:TANK_POSITION.y-BASE_VERTICAL_OFFSET, - z:TANK_POSITION.z - } + x: TANK_POSITION.x, + y: TANK_POSITION.y - BASE_VERTICAL_OFFSET, + z: TANK_POSITION.z + }, + dimensions: TANK_BASE_DIMENSIONS } tankBase = Entities.addEntity(properties); } - createFishTank(); createInnerContainer(); -createBubbleSystem(); - -createSecondBubbleSystem(); +createBubbleSystems(); createEntitiesAtCorners(); From d4fd9d4157b5e42fe80d5a8f2b6c36f3f4a482c6 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 8 Mar 2016 13:55:28 -0800 Subject: [PATCH 31/59] Update tank.js --- unpublishedScripts/DomainContent/Home/fishTank/tank.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 0f059b3919..a25b3066fe 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -1,6 +1,6 @@ (function() { - Script.include('../../../../examples/libraries/virtualBaton.js?' + Math.random()); + Script.include('../../../../examples/libraries/virtualBaton.js'); //only one person should simulate the tank at a time -- we pass around a virtual baton var baton; @@ -693,4 +693,4 @@ } return new FishTank(); -}); \ No newline at end of file +}); From 3a5f7f1cbed4a3345a4103ff191f9c9d98459377 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 9 Mar 2016 09:19:01 -0800 Subject: [PATCH 32/59] cleanup and headers --- .../Home/fishTank/createFishTank.js | 30 ++++++++--------- .../DomainContent/Home/fishTank/tank.js | 33 +++++++++++++------ 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 59e3372750..c1ceaeef02 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,3 +1,16 @@ +// +// createTank.js +// +// +// created by James b. Pollack @imgntn on 3/9/2016 +// Copyright 2016 High Fidelity, Inc. +// +// Adds a fish tank and base, decorations, particle bubble systems, and a bubble sound. Attaches a script that does fish swimming. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + var fishTank, tankBase, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; var CLEANUP = true; @@ -42,7 +55,6 @@ var TANK_BASE_DIMENSIONS = { var BASE_VERTICAL_OFFSET = 0.42; var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x + 0.06; -//depth of tank var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.025; var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.25; @@ -56,7 +68,6 @@ var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/ var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); var URCHIN_FORWARD_OFFSET = -TANK_DIMENSIONS.x; -//depth of tank var URCHIN_LATERAL_OFFSET = -0.15; var URCHIN_VERTICAL_OFFSET = -0.17; @@ -69,7 +80,6 @@ var URCHIN_DIMENSIONS = { } var ROCKS_FORWARD_OFFSET = 0; -//depth of tank var ROCKS_LATERAL_OFFSET = 0.0; var ROCKS_VERTICAL_OFFSET = (-TANK_DIMENSIONS.y / 2) + 0.25; @@ -160,8 +170,6 @@ function createBubbleSystems() { createBubbleSound(finalOffset); } - - function getOffsetFromTankCenter(VERTICAL_OFFSET, FORWARD_OFFSET, LATERAL_OFFSET) { var tankProperties = Entities.getEntityProperties(fishTank); @@ -308,6 +316,7 @@ function createTankBase() { }, dimensions: TANK_BASE_DIMENSIONS } + tankBase = Entities.addEntity(properties); } @@ -324,8 +333,8 @@ createUrchin(); createRocks(); createTankBase(); -var customKey = 'hifi-home-fishtank'; +var customKey = 'hifi-home-fishtank'; var data = { fishLoaded: false, @@ -339,16 +348,8 @@ var data = { } -//fisthank initialize has a different UUID than the model that i see Script.setTimeout(function() { - print('CREATE TIMEOUT!!!') - print('TANK AT CREATE IS::: ' + fishTank) - print('DATA AT CREATE IS:::' + JSON.stringify(data)); - setEntityCustomData(customKey, fishTank, data); - // setEntityCustomData('grabbableKey', id, { - // grabbable: false - // }); }, 2000) @@ -385,7 +386,6 @@ function setEntityUserData(id, data) { }); } -// FIXME do non-destructive modification of the existing user data function getEntityUserData(id) { var results = null; var properties = Entities.getEntityProperties(id, "userData"); diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index a25b3066fe..0ddff57343 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -1,3 +1,16 @@ +// +// tank.js +// +// +// created by James b. Pollack @imgntn on 3/9/2016 +// Copyright 2016 High Fidelity, Inc. +// +// looks for fish to swim around, if there are none it makes some. adds an attractor where the person simulating it is looking. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + (function() { Script.include('../../../../examples/libraries/virtualBaton.js'); @@ -293,16 +306,16 @@ }; - // - // flockOfFish.js - // examples - // - // Philip Rosedale - // Copyright 2016 High Fidelity, Inc. - // Fish smimming around in a space in front of you - // - // Distributed under the Apache License, Version 2.0. - // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +// flockOfFish.js +// examples +// +// Philip Rosedale +// Copyright 2016 High Fidelity, Inc. +// Fish smimming around in a space in front of you +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html var FISHTANK_USERDATA_KEY = 'hifi-home-fishtank' From 4af37668047ab36ae95ff2f563293e7e97a8719a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Mar 2016 14:28:26 -0800 Subject: [PATCH 33/59] Don't reset sensors when initializing or changing display plugins. This should fix the issue with the Oculus starting up with the UI aligned to the HMD on your desk, rather then the configured default sitting pose. --- interface/src/Application.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 660e597752..654e58c170 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -3287,6 +3288,14 @@ void Application::update(float deltaTime) { // update sensorToWorldMatrix for rendering camera. myAvatar->updateSensorToWorldMatrix(); + + // AJT: TODO: make this a menu item. + const bool DRAW_SENSOR_TO_WORLD_MATRIX = true; + if (DRAW_SENSOR_TO_WORLD_MATRIX) { + // draw the origin of the room in world space. + glm::mat4 m = myAvatar->getSensorToWorldMatrix(); + DebugDraw::getInstance().addMarker("room", glmExtractRotation(m), extractTranslation(m), glm::vec4(1)); + } } @@ -4811,7 +4820,7 @@ void Application::updateDisplayMode() { } } emit activeDisplayPluginChanged(); - resetSensors(); + Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); } From 5df616be37406f5385ec5f58965501c55438dcd2 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Wed, 9 Mar 2016 16:24:08 -0800 Subject: [PATCH 34/59] OpenVR: More usable UI Sphere overlay location Also, added a debug option to display SensorToWorld matrix in Developer > Avatar menu. --- interface/src/Application.cpp | 8 -------- interface/src/Menu.cpp | 2 ++ interface/src/Menu.h | 1 + interface/src/avatar/MyAvatar.cpp | 12 ++++++++++++ interface/src/avatar/MyAvatar.h | 2 ++ plugins/openvr/src/OpenVrDisplayPlugin.cpp | 17 ++++++++++++++++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 654e58c170..d575160f99 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3288,14 +3288,6 @@ void Application::update(float deltaTime) { // update sensorToWorldMatrix for rendering camera. myAvatar->updateSensorToWorldMatrix(); - - // AJT: TODO: make this a menu item. - const bool DRAW_SENSOR_TO_WORLD_MATRIX = true; - if (DRAW_SENSOR_TO_WORLD_MATRIX) { - // draw the origin of the room in world space. - glm::mat4 m = myAvatar->getSensorToWorldMatrix(); - DebugDraw::getInstance().addMarker("room", glmExtractRotation(m), extractTranslation(m), glm::vec4(1)); - } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index d605516380..919ee0f3c3 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -471,6 +471,8 @@ Menu::Menu() { avatar, SLOT(setUseAnimPreAndPostRotations(bool))); addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableInverseKinematics, 0, true, avatar, SLOT(setEnableInverseKinematics(bool))); + addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderSensorToWorldMatrix, 0, false, + avatar, SLOT(setEnableDebugDrawSensorToWorldMatrix(bool))); addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::KeyboardMotorControl, Qt::CTRL | Qt::SHIFT | Qt::Key_K, true, avatar, SLOT(updateMotionBehaviorFromMenu()), diff --git a/interface/src/Menu.h b/interface/src/Menu.h index fb00416af0..8ffd7efb36 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -144,6 +144,7 @@ namespace MenuOption { const QString RenderResolutionHalf = "1/2"; const QString RenderResolutionThird = "1/3"; const QString RenderResolutionQuarter = "1/4"; + const QString RenderSensorToWorldMatrix = "Show SensorToWorld Matrix"; const QString ResetAvatarSize = "Reset Avatar Size"; const QString ResetSensors = "Reset Sensors"; const QString RunningScripts = "Running Scripts..."; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 397627434f..a5b69f2be6 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -442,6 +442,10 @@ void MyAvatar::updateSensorToWorldMatrix() { _sensorToWorldMatrix = desiredMat * glm::inverse(_bodySensorMatrix); lateUpdatePalms(); + + if (_enableDebugDrawSensorToWorldMatrix) { + DebugDraw::getInstance().addMarker("sensorToWorldMatrix", glmExtractRotation(_sensorToWorldMatrix), extractTranslation(_sensorToWorldMatrix), glm::vec4(1)); + } } // Update avatar head rotation with sensor data @@ -695,6 +699,14 @@ void MyAvatar::setEnableDebugDrawPosition(bool isEnabled) { } } +void MyAvatar::setEnableDebugDrawSensorToWorldMatrix(bool isEnabled) { + _enableDebugDrawSensorToWorldMatrix = isEnabled; + + if (!isEnabled) { + DebugDraw::getInstance().removeMarker("sensorToWorldMatrix"); + } +} + void MyAvatar::setEnableMeshVisible(bool isEnabled) { render::ScenePointer scene = qApp->getMain3DScene(); _skeletonModel.setVisibleInScene(isEnabled, scene); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 731cba8153..8e5c1796b1 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -267,6 +267,7 @@ public slots: void setEnableDebugDrawDefaultPose(bool isEnabled); void setEnableDebugDrawAnimPose(bool isEnabled); void setEnableDebugDrawPosition(bool isEnabled); + void setEnableDebugDrawSensorToWorldMatrix(bool isEnabled); bool getEnableMeshVisible() const { return _skeletonModel.isVisible(); } void setEnableMeshVisible(bool isEnabled); void setUseAnimPreAndPostRotations(bool isEnabled); @@ -429,6 +430,7 @@ private: bool _enableDebugDrawDefaultPose { false }; bool _enableDebugDrawAnimPose { false }; + bool _enableDebugDrawSensorToWorldMatrix { false }; AudioListenerMode _audioListenerMode; glm::vec3 _customListenPosition; diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index e5708572f6..57a896dd4d 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -68,6 +68,21 @@ void OpenVrDisplayPlugin::activate() { _compositor = vr::VRCompositor(); Q_ASSERT(_compositor); HmdDisplayPlugin::activate(); + + // set up default sensor space such that the UI overlay will align with the front of the room. + auto chaperone = vr::VRChaperone(); + if (chaperone) { + float const UI_RADIUS = 1.0f; + float const UI_HEIGHT = 1.6f; + float const UI_Z_OFFSET = 0.5; + + float xSize, zSize; + chaperone->GetPlayAreaSize(&xSize, &zSize); + glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); + _sensorResetMat = glm::inverse(createMatFromQuatAndPos(Quaternions::Y_180, uiPos)); + } else { + qDebug() << "OpenVR: error could not get chaperone pointer"; + } } void OpenVrDisplayPlugin::deactivate() { @@ -115,7 +130,7 @@ glm::mat4 OpenVrDisplayPlugin::getHeadPose(uint32_t frameIndex) const { #endif vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; - _system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, predictedSecondsFromNow, predictedTrackedDevicePose, vr::k_unMaxTrackedDeviceCount); + _system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseStanding, predictedSecondsFromNow, predictedTrackedDevicePose, vr::k_unMaxTrackedDeviceCount); // copy and process predictedTrackedDevicePoses for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) { From 40fbe2d1e5dd8b36db967babe346be57bde4dbf3 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 17:33:07 -0800 Subject: [PATCH 35/59] Reuse procedurals on entities --- .../entities-renderer/src/RenderableBoxEntityItem.cpp | 7 ++++--- .../entities-renderer/src/RenderableSphereEntityItem.cpp | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 671043813e..58d9b6b391 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -31,7 +31,9 @@ EntityItemPointer RenderableBoxEntityItem::factory(const EntityItemID& entityID, void RenderableBoxEntityItem::setUserData(const QString& value) { if (value != getUserData()) { BoxEntityItem::setUserData(value); - _procedural.reset(); + if (_procedural) { + _procedural->parse(value); + } } } @@ -40,7 +42,6 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { Q_ASSERT(getType() == EntityTypes::Box); Q_ASSERT(args->_batch); - if (!_procedural) { _procedural.reset(new Procedural(this->getUserData())); _procedural->_vertexSource = simple_vert; @@ -62,7 +63,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { } batch.setModelTransform(transToCenter); // we want to include the scale as well - if (_procedural && _procedural->ready()) { + if (_procedural->ready()) { _procedural->prepare(batch, getPosition(), getDimensions()); auto color = _procedural->getColor(cubeColor); batch._glColor4f(color.r, color.g, color.b, color.a); diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index b5867fb1ee..78ff77ce89 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -36,7 +36,9 @@ EntityItemPointer RenderableSphereEntityItem::factory(const EntityItemID& entity void RenderableSphereEntityItem::setUserData(const QString& value) { if (value != getUserData()) { SphereEntityItem::setUserData(value); - _procedural.reset(); + if (_procedural) { + _procedural->parse(value); + } } } From f35ab590441f420510d5dc27a1f02a5c0818eb65 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 9 Mar 2016 17:36:45 -0800 Subject: [PATCH 36/59] adjust bubbles and add a treasure chest --- .../Home/fishTank/createFishTank.js | 67 ++++++++++++++----- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js index 59e3372750..9360ab5ed1 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/createFishTank.js @@ -1,4 +1,4 @@ -var fishTank, tankBase, bubbleSystem, secondBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, rocks; +var fishTank, tankBase, bubbleSystem, secondBubbleSystem, thirdBubbleSystem, innerContainer, bubbleInjector, lowerCorner, upperCorner, urchin, treasure, rocks; var CLEANUP = true; @@ -44,7 +44,7 @@ var BASE_VERTICAL_OFFSET = 0.42; var BUBBLE_SYSTEM_FORWARD_OFFSET = TANK_DIMENSIONS.x + 0.06; //depth of tank var BUBBLE_SYSTEM_LATERAL_OFFSET = 0.025; -var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.25; +var BUBBLE_SYSTEM_VERTICAL_OFFSET = -0.30; var BUBBLE_SYSTEM_DIMENSIONS = { x: TANK_DIMENSIONS.x / 8, @@ -55,17 +55,17 @@ var BUBBLE_SYSTEM_DIMENSIONS = { var BUBBLE_SOUND_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/Sounds/aquarium_small.L.wav"; var bubbleSound = SoundCache.getSound(BUBBLE_SOUND_URL); -var URCHIN_FORWARD_OFFSET = -TANK_DIMENSIONS.x; +var URCHIN_FORWARD_OFFSET = TANK_DIMENSIONS.x-0.35; //depth of tank -var URCHIN_LATERAL_OFFSET = -0.15; -var URCHIN_VERTICAL_OFFSET = -0.17; +var URCHIN_LATERAL_OFFSET = -0.05; +var URCHIN_VERTICAL_OFFSET = -0.12; var URCHIN_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Urchin.fbx'; var URCHIN_DIMENSIONS = { - x: 0.35, - y: 0.35, - z: 0.35 + x: 0.4, + y: 0.4, + z: 0.4 } var ROCKS_FORWARD_OFFSET = 0; @@ -81,6 +81,19 @@ var ROCK_DIMENSIONS = { z: 1.64 } +var TREASURE_FORWARD_OFFSET = -TANK_DIMENSIONS.x; +var TREASURE_LATERAL_OFFSET = -0.15; +var TREASURE_VERTICAL_OFFSET = -0.23; + +var TREASURE_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/DomainContent/Home/fishTank/Treasure-Chest2-SM.fbx'; + +var TREASURE_DIMENSIONS = { + x: 0.1199, + y: 0.1105, + z: 0.1020 +} + + function createFishTank() { var tankProperties = { name: 'hifi-home-fishtank', @@ -125,18 +138,18 @@ function createBubbleSystems() { "azimuthFinish": 0.1, "emitAcceleration": { "x": 0, - "y": 0.4, + "y": 0.3, "z": 0 }, "accelerationSpread": { - "x": 0.1, - "y": 0.1, - "z": 0.1 + "x": 0.01, + "y": 0.01, + "z": 0.01 }, - "particleRadius": 0.02, + "particleRadius": 0.005, "radiusSpread": 0, - "radiusStart": 0.043, - "radiusFinish": 0.02, + "radiusStart": 0.01, + "radiusFinish": 0.01, "alpha": 0.2, "alphaSpread": 0, "alphaStart": 0.3, @@ -154,9 +167,12 @@ function createBubbleSystems() { bubbleProperties.position = finalOffset; bubbleSystem = Entities.addEntity(bubbleProperties); - bubbleProperties.position.z += -0.076; + bubbleProperties.position.x += -0.076; secondBubbleSystem = Entities.addEntity(bubbleProperties) + bubbleProperties.position.x += -0.076; + thirdBubbleSystem = Entities.addEntity(bubbleProperties) + createBubbleSound(finalOffset); } @@ -293,6 +309,22 @@ function createUrchin() { } +function createTreasureChest() { + var finalPosition = getOffsetFromTankCenter(TREASURE_VERTICAL_OFFSET, TREASURE_FORWARD_OFFSET, TREASURE_LATERAL_OFFSET); + + var properties = { + name: 'hifi-home-fishtank-treasure-chest', + type: 'Model', + parentID: fishTank, + modelURL: TREASURE_MODEL_URL, + position: finalPosition, + dimensions: TREASURE_DIMENSIONS, + rotation:Quat.fromPitchYawRollDegrees(10,-45,10) + } + + treasure = Entities.addEntity(properties); +} + function createTankBase() { var properties = { name: 'hifi-home-fishtank-base', @@ -324,6 +356,8 @@ createUrchin(); createRocks(); createTankBase(); + +createTreasureChest(); var customKey = 'hifi-home-fishtank'; @@ -357,6 +391,7 @@ function cleanup() { Entities.deleteEntity(tankBase); Entities.deleteEntity(bubbleSystem); Entities.deleteEntity(secondBubbleSystem); + Entities.deleteEntity(thirdBubbleSystem); Entities.deleteEntity(innerContainer); Entities.deleteEntity(lowerCorner); Entities.deleteEntity(upperCorner); From 5f1b8805cf76d9b7ef96341ac58a8a49e9a4c3df Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Mar 2016 17:37:51 -0800 Subject: [PATCH 37/59] Removed unnecessary include --- interface/src/Application.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 426efbd914..66662a7500 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -69,7 +69,6 @@ #include #include #include -#include #include #include #include From 4c3f374f02002d3d39ec17de8a131142af539e13 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 10 Mar 2016 15:10:44 +1300 Subject: [PATCH 38/59] Update HiFi glyphs font file Has some new, soon to be used characters, but no other changes. --- interface/resources/fonts/hifi-glyphs.ttf | Bin 18804 -> 21164 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/interface/resources/fonts/hifi-glyphs.ttf b/interface/resources/fonts/hifi-glyphs.ttf index 3e8e5e5b908dc5d7535e90a290bc9ab477b87f02..1bd380bc49d4ec7366663a32eb00cc04ecfd80dd 100644 GIT binary patch delta 2941 zcma)8ZHQb~8GgUcIrq-Y&dwxr?@Z0t?%er6*KF6lbLTcmH#V50ZfM%r#9Ete(#=P+ zN_Mhz*Vy_s6;$v8l}s%Z{3BA@f}l_^fKK$ih0o=EsbCxbGue^QvPp<>q zUjvY1S#k()2JbW-*>NwB`UzDmt3 z)a^gXEN2G$@snZcwim}9KXeZ6f$a0*TjR`@WU9Q>NM z;bVh8^G=zYKXrP5@{K`Byuml+=cQdY#=bxH_V}~o|B7nScK}}Qm_7UZ1kb?$mvIrk z4&Md9x{KNu>#@4l>R#dl@ zFrH3>=`^fbomUN~({7S>bsX5B5>9uMPP@}q!*md4ulwy*JJRLCIE<&eGuUaldMoL4 zr^AZH$3#$sJxeUbqA43eDdvd^r94qFPmEkFj*PINuw%<2UZLPwG9uQZr9#1MF@i+- z;>}6O$Y{2hLIEvO-&o1!<@0Aschu^&8diqxs4H60n4E3H%jdnD`w?BZ$RwMQkxM=k zQL$)@FtXg*j|f|KhR~uh#Ue73Un0tT=nDOrJ4)qRtzH8F3n?`56~h7~eik?>N4LVOXST>L zjHj#NE5x!zm^N;+|8v+}2O{Ek6p7zHT|{|A@ZTi7tvIsvovkCqZ7f8>4_8b+SC}j0 z@_kczn1yiic_C&r&l`nDveB*EZAN?xN7vpJ&k!>i57Rml;lvgeT6?!vE|6 zdi5$cW_x&L?Rw_fZ}ghYW~0$)tQ~1I8cl38n`_tAfQ{AJ)vJT+gI*J~C%pu(7 zCgDo}XTHS`Dj}a7P~_tvQVq z)m;&t-GPx-X)Bq;q*WiKp`kT{aS#UGSAFAzm0m4N&sr@H5*8*wLL?Mo!yYNOj`Kc?&6<7xHFyJ4oPt?^tqS8# z3StFy1Ek7M3c?*3NRv23sG^8$g0=zoh9!wB)u8(q=UEaFWX;-G%Yukl5;0lMH&Yg* zzK#@v2}2|vqs?+5i>!6v@7?RMCz=X5?qsPc`a*0qmjZcc**UQA47`9}#FMZc?t#Z) z8D4}}0n#KYqSp3*i6w~xCAoh)^&7I;iK?4SSeXT0BmJD8v96JXJ@Sz~@{omCjLjJ{Qm7Vft{}|DSkD$*!OuBD>yyFeNtg4i zuFo!Si3yD_UQr=pMG+Auh_U9SJT*4qqd9wm|>_pGujX`41Hs=`6uDZ})kYI$^|9M;OEQWP5ITjB$tPo72B{`HF*Y_a z)o5fVsscPaJbwW~9%?Y?f8u@IGkEIYB<>l!c<@JfX0ZRzFN^qDd<0M896pMt@bt^? z9lDz*z2);OE1&CKST-w9%r7q#E}i-O`Lip#FFbMS3rlo%(WQHKFD_rcz~|0iprt1V UQ?om8esKTnhYGh2opZ zM8SnC2X|SC;zqC#(14(b)QtsEapzt)?o zKr)$5PiLk30|sg1FHg7plB~v zS}i1G1_6JubZ!1k-5LPYh|Y`8NzaByH~Fd9Q|jPKJQvX02> iBe`ddja*!6=hW`~XAmgbD|^GPAARuNb^rHNYxTd~O>`>& From 42d27557a11ed30db5c1869c87c72fabce0cae1b Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Wed, 9 Mar 2016 18:42:03 -0800 Subject: [PATCH 39/59] OpenVR: remove 180 y rotation for UI bounds. Turns out the room I was using was misconfigured. --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 57a896dd4d..83c834161b 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -79,7 +79,7 @@ void OpenVrDisplayPlugin::activate() { float xSize, zSize; chaperone->GetPlayAreaSize(&xSize, &zSize); glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); - _sensorResetMat = glm::inverse(createMatFromQuatAndPos(Quaternions::Y_180, uiPos)); + _sensorResetMat = glm::inverse(createMatFromQuatAndPos(glm::quat(), uiPos)); } else { qDebug() << "OpenVR: error could not get chaperone pointer"; } From 4022474b48e1eef6c267b79ae65a95b4135f05ae Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 17:33:19 -0800 Subject: [PATCH 40/59] Constrain procedural updates to render thread --- .../procedural/src/procedural/Procedural.cpp | 153 +++++++++++------- .../procedural/src/procedural/Procedural.h | 46 ++++-- 2 files changed, 132 insertions(+), 67 deletions(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index b1e4bd53ed..f7c4a783aa 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -69,74 +69,108 @@ Procedural::Procedural(const QString& userDataJson) { } void Procedural::parse(const QString& userDataJson) { - _enabled = false; auto proceduralData = getProceduralData(userDataJson); - if (proceduralData.isObject()) { - parse(proceduralData.toObject()); - } + // Instead of parsing, prep for a parse on the rendering thread + // This will be called by Procedural::ready + _proceduralData = proceduralData.toObject(); + _proceduralDataDirty = true; } -void Procedural::parse(const QJsonObject& proceduralData) { - // grab the version number - { - auto version = proceduralData[VERSION_KEY]; - if (version.isDouble()) { - _version = (uint8_t)(floor(version.toDouble())); - } +bool Procedural::parseVersion(const QJsonValue& version) { + if (version.isDouble()) { + _version = (uint8_t)(floor(version.toDouble())); + } else { + // All unversioned shaders default to V1 + _version = 1; + } + return (_version == 1 || _version == 2); +} + +bool Procedural::parseUrl(const QUrl& shaderUrl) { + if (!shaderUrl.isValid()) { + qWarning() << "Invalid shader URL: " << shaderUrl; + return false; } - // Get the path to the shader - { - QString shaderUrl = proceduralData[URL_KEY].toString(); - shaderUrl = ResourceManager::normalizeURL(shaderUrl); - _shaderUrl = QUrl(shaderUrl); - if (!_shaderUrl.isValid()) { - qWarning() << "Invalid shader URL: " << shaderUrl; - return; - } - - if (_shaderUrl.isLocalFile()) { - _shaderPath = _shaderUrl.toLocalFile(); - qDebug() << "Shader path: " << _shaderPath; - if (!QFile(_shaderPath).exists()) { - return; - } - } else { - qDebug() << "Shader url: " << _shaderUrl; - _networkShader = ShaderCache::instance().getShader(_shaderUrl); - } + if (_shaderUrl == shaderUrl) { + return true; } - // Grab any custom uniforms - { - auto uniforms = proceduralData[UNIFORMS_KEY]; - if (uniforms.isObject()) { - _parsedUniforms = uniforms.toObject(); + _shaderUrl = shaderUrl; + + if (_shaderUrl.isLocalFile()) { + _shaderPath = _shaderUrl.toLocalFile(); + qDebug() << "Shader path: " << _shaderPath; + if (!QFile(_shaderPath).exists()) { + return false;; } + } else { + qDebug() << "Shader url: " << _shaderUrl; + _networkShader = ShaderCache::instance().getShader(_shaderUrl); } - // Grab any textures - { - auto channels = proceduralData[CHANNELS_KEY]; - if (channels.isArray()) { - auto textureCache = DependencyManager::get(); - _parsedChannels = channels.toArray(); - size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size()); - for (size_t i = 0; i < channelCount; ++i) { - QString url = _parsedChannels.at((int)i).toString(); - _channels[i] = textureCache->getTexture(QUrl(url)); - } - } + return true; +} + +bool Procedural::parseUniforms(const QJsonObject& uniforms) { + if (_parsedUniforms != uniforms) { + _parsedUniforms = uniforms; + _uniformsDirty = true; + } + + return true; +} + +bool Procedural::parseTextures(const QJsonArray& channels) { + if (_parsedChannels != channels) { + _parsedChannels = channels; + + auto textureCache = DependencyManager::get(); + size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size()); + for (size_t i = 0; i < channelCount; ++i) { + QString url = _parsedChannels.at((int)i).toString(); + _channels[i] = textureCache->getTexture(QUrl(url)); + } + + _channelsDirty = true; + } + + return true; +} + +void Procedural::parse(QJsonObject proceduralData) { + _enabled = false; + + if (proceduralData.isEmpty()) { + return; + } + + auto version = proceduralData[VERSION_KEY]; + auto shaderUrl = proceduralData[URL_KEY].toString(); + shaderUrl = ResourceManager::normalizeURL(shaderUrl); + auto uniforms = proceduralData[UNIFORMS_KEY].toObject(); + auto channels = proceduralData[CHANNELS_KEY].toArray(); + + if (parseVersion(proceduralData[VERSION_KEY]) && + parseUrl(shaderUrl) && + parseUniforms(uniforms) && + parseTextures(channels)) { + _enabled = true; } - _enabled = true; } bool Procedural::ready() { + // Load any changes to the procedural + if (_proceduralDataDirty) { + parse(_proceduralData); + _proceduralDataDirty = false; + } + if (!_enabled) { return false; } - // Do we have a network or local shader + // Do we have a network or local shader, and if so, is it loaded? if (_shaderPath.isEmpty() && (!_networkShader || !_networkShader->isLoaded())) { return false; } @@ -160,15 +194,14 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm QFile file(_shaderPath); file.open(QIODevice::ReadOnly); _shaderSource = QTextStream(&file).readAll(); - _pipelineDirty = true; + _shaderDirty = true; _shaderModified = lastModified; } } else if (_networkShader && _networkShader->isLoaded()) { _shaderSource = _networkShader->_source; } - if (!_pipeline || _pipelineDirty) { - _pipelineDirty = true; + if (!_pipeline || _shaderDirty) { if (!_vertexShader) { _vertexShader = gpu::Shader::createVertex(_vertexSource); } @@ -214,11 +247,15 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm batch.setPipeline(_pipeline); - if (_pipelineDirty) { - _pipelineDirty = false; + if (_shaderDirty || _uniformsDirty) { setupUniforms(); } + if (_shaderDirty || _uniformsDirty || _channelsDirty) { + setupChannels(_shaderDirty || _uniformsDirty); + } + + _shaderDirty = _uniformsDirty = _channelsDirty = false; for (auto lambda : _uniforms) { lambda(batch); @@ -359,8 +396,14 @@ void Procedural::setupUniforms() { batch._glUniform(_standardUniformSlots[POSITION], _entityPosition); }); } +} +void Procedural::setupChannels(bool shouldCreate) { if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[CHANNEL_RESOLUTION]) { + if (!shouldCreate) { + // Instead of modifying the last element, just remove and recreate it. + _uniforms.pop_back(); + } _uniforms.push_back([=](gpu::Batch& batch) { vec3 channelSizes[MAX_PROCEDURAL_TEXTURE_CHANNELS]; for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 1b02fbd435..41493664b1 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -28,27 +28,24 @@ const size_t MAX_PROCEDURAL_TEXTURE_CHANNELS{ 4 }; // FIXME better encapsulation // FIXME better mechanism for extending to things rendered using shaders other than simple.slv struct Procedural { +public: static QJsonValue getProceduralData(const QString& proceduralJson); Procedural(const QString& userDataJson); void parse(const QString& userDataJson); - void parse(const QJsonObject&); + bool ready(); void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size); - void setupUniforms(); + glm::vec4 getColor(const glm::vec4& entityColor); - bool _enabled{ false }; - uint8_t _version{ 1 }; + bool _enabled { false }; + uint8_t _version { 1 }; std::string _vertexSource; std::string _fragmentSource; - QString _shaderSource; - QString _shaderPath; - QUrl _shaderUrl; - quint64 _shaderModified{ 0 }; - bool _pipelineDirty{ true }; + gpu::StatePointer _state; enum StandardUniforms { DATE, @@ -60,23 +57,48 @@ struct Procedural { NUM_STANDARD_UNIFORMS }; - int32_t _standardUniformSlots[NUM_STANDARD_UNIFORMS]; - +protected: + // Procedural metadata uint64_t _start{ 0 }; int32_t _frameCount{ 0 }; + + // Rendering object descriptions, from userData + QJsonObject _proceduralData; + QString _shaderSource; + QString _shaderPath; + QUrl _shaderUrl; + quint64 _shaderModified { 0 }; NetworkShaderPointer _networkShader; QJsonObject _parsedUniforms; QJsonArray _parsedChannels; + bool _proceduralDataDirty { true }; + bool _shaderDirty { true }; + bool _uniformsDirty { true }; + bool _channelsDirty { true }; + // Rendering objects UniformLambdas _uniforms; + int32_t _standardUniformSlots[NUM_STANDARD_UNIFORMS]; NetworkTexturePointer _channels[MAX_PROCEDURAL_TEXTURE_CHANNELS]; gpu::PipelinePointer _pipeline; gpu::ShaderPointer _vertexShader; gpu::ShaderPointer _fragmentShader; gpu::ShaderPointer _shader; - gpu::StatePointer _state; + + // Entity metadata glm::vec3 _entityDimensions; glm::vec3 _entityPosition; + +private: + // This should only be called from the render thread, as it shares data with Procedural::prepare + void parse(QJsonObject); + bool parseVersion(const QJsonValue& version); + bool parseUrl(const QUrl& url); + bool parseUniforms(const QJsonObject& uniforms); + bool parseTextures(const QJsonArray& channels); + + void setupUniforms(); + void setupChannels(bool shouldCreate); }; #endif From 74e1d322215e67244ea22823565758fcb2aa19b6 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 17:48:24 -0800 Subject: [PATCH 41/59] Reuse procedural on skybox --- .../src/EntityTreeRenderer.cpp | 7 +----- .../procedural/src/procedural/Procedural.cpp | 3 +++ .../procedural/src/procedural/Procedural.h | 7 +++--- .../src/procedural/ProceduralSkybox.cpp | 23 ++++++++----------- .../src/procedural/ProceduralSkybox.h | 6 ++--- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 44c3146b41..421213151a 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -341,12 +341,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetUserData()) { userData = zone->getUserData(); - auto procedural = std::make_shared(userData); - if (procedural->_enabled) { - skybox->setProcedural(procedural); - } else { - skybox->setProcedural(ProceduralPointer()); - } + skybox->setProcedural(userData); } if (zone->getSkyboxProperties().getURL().isEmpty()) { skybox->setCubemap(gpu::TexturePointer()); diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index f7c4a783aa..cc9e5841ed 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -62,6 +62,9 @@ QJsonValue Procedural::getProceduralData(const QString& proceduralJson) { return doc.object()[PROCEDURAL_USER_DATA_KEY]; } +Procedural::Procedural() { + _state = std::make_shared(); +} Procedural::Procedural(const QString& userDataJson) { parse(userDataJson); diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 41493664b1..0d602eab4f 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -31,6 +31,7 @@ struct Procedural { public: static QJsonValue getProceduralData(const QString& proceduralJson); + Procedural(); Procedural(const QString& userDataJson); void parse(const QString& userDataJson); @@ -39,7 +40,6 @@ public: glm::vec4 getColor(const glm::vec4& entityColor); - bool _enabled { false }; uint8_t _version { 1 }; std::string _vertexSource; @@ -59,8 +59,9 @@ public: protected: // Procedural metadata - uint64_t _start{ 0 }; - int32_t _frameCount{ 0 }; + bool _enabled { false }; + uint64_t _start { 0 }; + int32_t _frameCount { 0 }; // Rendering object descriptions, from userData QJsonObject _proceduralData; diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 167d49cbaf..f3ee08dd7a 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -19,6 +19,10 @@ #include "ProceduralSkybox_frag.h" ProceduralSkybox::ProceduralSkybox() : model::Skybox() { + _procedural._vertexSource = ProceduralSkybox_vert; + _procedural._fragmentSource = ProceduralSkybox_frag; + // Adjust the pipeline state for background using the stencil test + _procedural._state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } ProceduralSkybox::ProceduralSkybox(const ProceduralSkybox& skybox) : @@ -27,14 +31,8 @@ ProceduralSkybox::ProceduralSkybox(const ProceduralSkybox& skybox) : } -void ProceduralSkybox::setProcedural(const ProceduralPointer& procedural) { - _procedural = procedural; - if (_procedural) { - _procedural->_vertexSource = ProceduralSkybox_vert; - _procedural->_fragmentSource = ProceduralSkybox_frag; - // Adjust the pipeline state for background using the stencil test - _procedural->_state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); - } +void ProceduralSkybox::setProcedural(const QString& userData) { + _procedural.parse(userData); } void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { @@ -42,12 +40,10 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) con } void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const ProceduralSkybox& skybox) { - if (!(skybox._procedural)) { + if (!(skybox._procedural.ready())) { skybox.updateDataBuffer(); Skybox::render(batch, viewFrustum, skybox); - } - - if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) { + } else { gpu::TexturePointer skymap = skybox.getCubemap(); // FIXME: skymap->isDefined may not be threadsafe assert(skymap && skymap->isDefined()); @@ -62,8 +58,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setModelTransform(Transform()); // only for Mac batch.setResourceTexture(0, skybox.getCubemap()); - skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1)); + skybox._procedural.prepare(batch, glm::vec3(0), glm::vec3(1)); batch.draw(gpu::TRIANGLE_STRIP, 4); } } - diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.h b/libraries/procedural/src/procedural/ProceduralSkybox.h index 057a1ccc74..37cc2baaaf 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.h +++ b/libraries/procedural/src/procedural/ProceduralSkybox.h @@ -17,8 +17,6 @@ #include "Procedural.h" -typedef std::shared_ptr ProceduralPointer; - class ProceduralSkybox: public model::Skybox { public: ProceduralSkybox(); @@ -26,13 +24,13 @@ public: ProceduralSkybox& operator= (const ProceduralSkybox& skybox); virtual ~ProceduralSkybox() {}; - void setProcedural(const ProceduralPointer& procedural); + void setProcedural(const QString& userData); virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; static void render(gpu::Batch& batch, const ViewFrustum& frustum, const ProceduralSkybox& skybox); protected: - ProceduralPointer _procedural; + mutable Procedural _procedural; }; typedef std::shared_ptr< ProceduralSkybox > ProceduralSkyboxPointer; From 153f7fc3aa9088fffdcc22b3524a0877da9aa996 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Thu, 10 Mar 2016 09:45:47 -0800 Subject: [PATCH 42/59] OpenVR: adjusted translation of UI sphere overlay --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 83c834161b..b86a7f9ebc 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -78,7 +78,7 @@ void OpenVrDisplayPlugin::activate() { float xSize, zSize; chaperone->GetPlayAreaSize(&xSize, &zSize); - glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); + glm::vec3 uiPos(0.0f, UI_HEIGHT, UI_RADIUS - (0.5f * zSize) - UI_Z_OFFSET); _sensorResetMat = glm::inverse(createMatFromQuatAndPos(glm::quat(), uiPos)); } else { qDebug() << "OpenVR: error could not get chaperone pointer"; From 1640314076cf29cf6f51b28499322dc0c9743201 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 10:12:22 -0800 Subject: [PATCH 43/59] Use one procedural for skybox (avoid copies) --- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 2 +- .../procedural/src/procedural/ProceduralSkybox.cpp | 10 ---------- libraries/procedural/src/procedural/ProceduralSkybox.h | 4 +--- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 421213151a..5cf1b1548a 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -341,7 +341,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptrgetUserData()) { userData = zone->getUserData(); - skybox->setProcedural(userData); + skybox->parse(userData); } if (zone->getSkyboxProperties().getURL().isEmpty()) { skybox->setCubemap(gpu::TexturePointer()); diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index f3ee08dd7a..9c311acb3d 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -25,16 +25,6 @@ ProceduralSkybox::ProceduralSkybox() : model::Skybox() { _procedural._state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } -ProceduralSkybox::ProceduralSkybox(const ProceduralSkybox& skybox) : - model::Skybox(skybox), - _procedural(skybox._procedural) { - -} - -void ProceduralSkybox::setProcedural(const QString& userData) { - _procedural.parse(userData); -} - void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { ProceduralSkybox::render(batch, frustum, (*this)); } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.h b/libraries/procedural/src/procedural/ProceduralSkybox.h index 37cc2baaaf..e817ce271d 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.h +++ b/libraries/procedural/src/procedural/ProceduralSkybox.h @@ -20,11 +20,9 @@ class ProceduralSkybox: public model::Skybox { public: ProceduralSkybox(); - ProceduralSkybox(const ProceduralSkybox& skybox); - ProceduralSkybox& operator= (const ProceduralSkybox& skybox); virtual ~ProceduralSkybox() {}; - void setProcedural(const QString& userData); + void parse(const QString& userData) { _procedural.parse(userData); } virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; static void render(gpu::Batch& batch, const ViewFrustum& frustum, const ProceduralSkybox& skybox); From 9b89e46e65eb4b80d13d2cfbaadc4f36e123c924 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 10:12:55 -0800 Subject: [PATCH 44/59] Make procedural userData thread-safe --- libraries/procedural/src/procedural/Procedural.cpp | 2 ++ libraries/procedural/src/procedural/Procedural.h | 1 + 2 files changed, 3 insertions(+) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index cc9e5841ed..6cf9f05372 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -75,6 +75,7 @@ void Procedural::parse(const QString& userDataJson) { auto proceduralData = getProceduralData(userDataJson); // Instead of parsing, prep for a parse on the rendering thread // This will be called by Procedural::ready + std::lock_guard lock(_proceduralDataMutex); _proceduralData = proceduralData.toObject(); _proceduralDataDirty = true; } @@ -165,6 +166,7 @@ void Procedural::parse(QJsonObject proceduralData) { bool Procedural::ready() { // Load any changes to the procedural if (_proceduralDataDirty) { + std::lock_guard lock(_proceduralDataMutex); parse(_proceduralData); _proceduralDataDirty = false; } diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 0d602eab4f..75872ca2bc 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -65,6 +65,7 @@ protected: // Rendering object descriptions, from userData QJsonObject _proceduralData; + std::mutex _proceduralDataMutex; QString _shaderSource; QString _shaderPath; QUrl _shaderUrl; From 4a78300607e5fbff34313e34edd17404064ea849 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 10 Mar 2016 10:20:17 -0800 Subject: [PATCH 45/59] MyAvatar: Allow user to raise hands directly overhead. Previously we were using a infinitely tall vertical cylinder to push hand IK targets out of the body, this had the side-effect of preventing the hands from being raised over the head. Now, we collide against the same 3d capsule used by the physics system for avatar collisions. --- interface/src/avatar/SkeletonModel.cpp | 3 ++ libraries/animation/src/Rig.cpp | 39 ++++++++------------- libraries/animation/src/Rig.h | 2 ++ libraries/physics/src/CharacterController.h | 2 ++ tests/shared/src/GeometryUtilTests.cpp | 12 +++++++ tests/shared/src/GeometryUtilTests.h | 1 + 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index e4c98215c2..711ed17231 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -144,7 +144,10 @@ void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { } else { handParams.isRightEnabled = false; } + handParams.bodyCapsuleRadius = myAvatar->getCharacterController()->getCapsuleRadius(); + handParams.bodyCapsuleHalfHeight = myAvatar->getCharacterController()->getCapsuleHalfHeight(); + handParams.bodyCapsuleLocalOffset = myAvatar->getCharacterController()->getCapsuleLocalOffset(); _rig->updateFromHandParameters(handParams, deltaTime); diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 02968e3665..4e7564472c 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -1073,7 +1074,6 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { if (_animSkeleton && _animNode) { const float HAND_RADIUS = 0.05f; - const float BODY_RADIUS = params.bodyCapsuleRadius; const float MIN_LENGTH = 1.0e-4f; // project the hips onto the xz plane. @@ -1082,23 +1082,20 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { if (hipsIndex >= 0) { hipsTrans = _internalPoseSet._absolutePoses[hipsIndex].trans; } - const glm::vec2 bodyCircleCenter(hipsTrans.x, hipsTrans.z); + const float bodyCapsuleRadius = params.bodyCapsuleRadius; + const glm::vec3 bodyCapsuleCenter = hipsTrans - params.bodyCapsuleLocalOffset; + const glm::vec3 bodyCapsuleStart = bodyCapsuleCenter - glm::vec3(0, params.bodyCapsuleHalfHeight, 0); + const glm::vec3 bodyCapsuleEnd = bodyCapsuleCenter + glm::vec3(0, params.bodyCapsuleHalfHeight, 0); if (params.isLeftEnabled) { - // project the hand position onto the xz plane. - glm::vec2 handCircleCenter(params.leftPosition.x, params.leftPosition.z); - - // check for 2d overlap of the hand and body circles. - auto circleToCircle = handCircleCenter - bodyCircleCenter; - const float circleToCircleLength = glm::length(circleToCircle); - const float penetrationDistance = HAND_RADIUS + BODY_RADIUS - circleToCircleLength; - if (penetrationDistance > 0.0f && circleToCircleLength > MIN_LENGTH) { - // push the hands out of the body - handCircleCenter += penetrationDistance * glm::normalize(circleToCircle); + // prevent the hand IK targets from intersecting the body capsule + glm::vec3 handPosition = params.leftPosition; + glm::vec3 displacement(glm::vec3::_null); + if (findSphereCapsulePenetration(handPosition, HAND_RADIUS, bodyCapsuleStart, bodyCapsuleEnd, bodyCapsuleRadius, displacement)) { + handPosition -= displacement; } - glm::vec3 handPosition(handCircleCenter.x, params.leftPosition.y, handCircleCenter.y); _animVars.set("leftHandPosition", handPosition); _animVars.set("leftHandRotation", params.leftOrientation); _animVars.set("leftHandType", (int)IKTarget::Type::RotationAndPosition); @@ -1110,19 +1107,13 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { if (params.isRightEnabled) { - // project the hand position onto the xz plane. - glm::vec2 handCircleCenter(params.rightPosition.x, params.rightPosition.z); - - // check for 2d overlap of the hand and body circles. - auto circleToCircle = handCircleCenter - bodyCircleCenter; - const float circleToCircleLength = glm::length(circleToCircle); - const float penetrationDistance = HAND_RADIUS + BODY_RADIUS - circleToCircleLength; - if (penetrationDistance > 0.0f && circleToCircleLength > MIN_LENGTH) { - // push the hands out of the body - handCircleCenter += penetrationDistance * glm::normalize(circleToCircle); + // prevent the hand IK targets from intersecting the body capsule + glm::vec3 handPosition = params.rightPosition; + glm::vec3 displacement(glm::vec3::_null); + if (findSphereCapsulePenetration(handPosition, HAND_RADIUS, bodyCapsuleStart, bodyCapsuleEnd, bodyCapsuleRadius, displacement)) { + handPosition -= displacement; } - glm::vec3 handPosition(handCircleCenter.x, params.rightPosition.y, handCircleCenter.y); _animVars.set("rightHandPosition", handPosition); _animVars.set("rightHandRotation", params.rightOrientation); _animVars.set("rightHandType", (int)IKTarget::Type::RotationAndPosition); diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index 3d5d44b844..50313d10e7 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -68,6 +68,8 @@ public: bool isLeftEnabled; bool isRightEnabled; float bodyCapsuleRadius; + float bodyCapsuleHalfHeight; + glm::vec3 bodyCapsuleLocalOffset; glm::vec3 leftPosition = glm::vec3(); // rig space glm::quat leftOrientation = glm::quat(); // rig space (z forward) glm::vec3 rightPosition = glm::vec3(); // rig space diff --git a/libraries/physics/src/CharacterController.h b/libraries/physics/src/CharacterController.h index a8543d6070..d3c7405353 100644 --- a/libraries/physics/src/CharacterController.h +++ b/libraries/physics/src/CharacterController.h @@ -79,6 +79,8 @@ public: glm::vec3 getLinearVelocity() const; float getCapsuleRadius() const { return _radius; } + float getCapsuleHalfHeight() const { return _halfHeight; } + glm::vec3 getCapsuleLocalOffset() const { return _shapeLocalOffset; } enum class State { Ground = 0, diff --git a/tests/shared/src/GeometryUtilTests.cpp b/tests/shared/src/GeometryUtilTests.cpp index 7ba22ec13d..289ac9a0a9 100644 --- a/tests/shared/src/GeometryUtilTests.cpp +++ b/tests/shared/src/GeometryUtilTests.cpp @@ -212,3 +212,15 @@ void GeometryUtilTests::testTwistSwingDecomposition() { } +void GeometryUtilTests::testSphereCapsulePenetration() { + glm::vec3 sphereCenter(1.5, 0.0, 0.0); + float sphereRadius = 1.0f; + glm::vec3 capsuleStart(0.0f, -10.0f, 0.0f); + glm::vec3 capsuleEnd(0.0f, 10.0f, 0.0f); + float capsuleRadius = 1.0f; + + glm::vec3 penetration(glm::vec3::_null); + bool hit = findSphereCapsulePenetration(sphereCenter, sphereRadius, capsuleStart, capsuleEnd, capsuleRadius, penetration); + QCOMPARE(hit, true); + QCOMPARE_WITH_ABS_ERROR(penetration, glm::vec3(-0.5f, 0.0f, 0.0f), EPSILON); +} diff --git a/tests/shared/src/GeometryUtilTests.h b/tests/shared/src/GeometryUtilTests.h index daf740dcd3..b6340cd8cf 100644 --- a/tests/shared/src/GeometryUtilTests.h +++ b/tests/shared/src/GeometryUtilTests.h @@ -21,6 +21,7 @@ private slots: void testLocalRayRectangleIntersection(); void testWorldRayRectangleIntersection(); void testTwistSwingDecomposition(); + void testSphereCapsulePenetration(); }; float getErrorDifference(const float& a, const float& b); From c05e996913a8c2b829b26bc26e9df39cfdaa1a66 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 10 Mar 2016 10:38:49 -0800 Subject: [PATCH 46/59] remove lifetime --- unpublishedScripts/DomainContent/Home/fishTank/tank.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/Home/fishTank/tank.js b/unpublishedScripts/DomainContent/Home/fishTank/tank.js index 0ddff57343..206a3fec12 100644 --- a/unpublishedScripts/DomainContent/Home/fishTank/tank.js +++ b/unpublishedScripts/DomainContent/Home/fishTank/tank.js @@ -642,7 +642,7 @@ damping: FISH_DAMPING, angularDamping: FISH_ANGULAR_DAMPING, dynamic: false, - lifetime: LIFETIME, + // lifetime: LIFETIME, color: { red: 0, green: 255, From 64042327eca3e3bff21b4ca17c937d30b6e555f1 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 11:08:15 -0800 Subject: [PATCH 47/59] Use version tmp var --- libraries/procedural/src/procedural/Procedural.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 6cf9f05372..9670b66676 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -155,7 +155,7 @@ void Procedural::parse(QJsonObject proceduralData) { auto uniforms = proceduralData[UNIFORMS_KEY].toObject(); auto channels = proceduralData[CHANNELS_KEY].toArray(); - if (parseVersion(proceduralData[VERSION_KEY]) && + if (parseVersion(version) && parseUrl(shaderUrl) && parseUniforms(uniforms) && parseTextures(channels)) { From 6ed1ad10a1d7c322ceda9d2ec0db31507bbdf097 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 10 Mar 2016 12:12:24 -0800 Subject: [PATCH 48/59] remove hmdDefaults and hmdControls scripts, since they are borked --- examples/hmdControls.js | 285 ---------------------------------------- examples/hmdDefaults.js | 17 --- 2 files changed, 302 deletions(-) delete mode 100644 examples/hmdControls.js delete mode 100644 examples/hmdDefaults.js diff --git a/examples/hmdControls.js b/examples/hmdControls.js deleted file mode 100644 index e5e7d4aca8..0000000000 --- a/examples/hmdControls.js +++ /dev/null @@ -1,285 +0,0 @@ -// -// hmdControls.js -// examples -// -// Created by Sam Gondelman on 6/17/15 -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -var MOVE_DISTANCE = 2.0; -var PITCH_INCREMENT = 0.5; // degrees -var pitchChange = 0; // degrees -var YAW_INCREMENT = 0.5; // degrees -var VR_YAW_INCREMENT = 15.0; // degrees -var yawChange = 0; -var BOOM_SPEED = 0.5; -var THRESHOLD = 0.2; - -var CAMERA_UPDATE_TIME = 0.5; -var yawTimer = CAMERA_UPDATE_TIME; - -var shifted = false; -var SHIFT_UPDATE_TIME = 0.5; -var shiftTimer = SHIFT_UPDATE_TIME; -var SHIFT_MAG = 4.0; - -var warpActive = false; -var WARP_UPDATE_TIME = .5; -var warpTimer = WARP_UPDATE_TIME; - -var warpPosition = { x: 0, y: 0, z: 0 }; - -var WARP_SPHERE_SIZE = 1; -var warpSphere = Overlays.addOverlay("sphere", { - position: { x: 0, y: 0, z: 0 }, - size: WARP_SPHERE_SIZE, - color: { red: 0, green: 255, blue: 0 }, - alpha: 1.0, - solid: true, - visible: false, -}); - -var WARP_LINE_HEIGHT = 10; -var warpLine = Overlays.addOverlay("line3d", { - start: { x: 0, y: 0, z:0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 0, green: 255, blue: 255}, - alpha: 1, - lineWidth: 5, - visible: false, -}); - -var velocity = { x: 0, y: 0, z: 0 }; -var VERY_LONG_TIME = 1000000.0; - -var active = HMD.active; -var prevVRMode = HMD.active; - -var hmdControls = (function () { - - function onKeyPressEvent(event) { - if (event.text == 'g' && event.isMeta) { - active = !active; - } - } - - function findAction(name) { - var actions = Controller.getAllActions(); - for (var i = 0; i < actions.length; i++) { - if (actions[i].actionName == name) { - return i; - } - } - // If the action isn't found, it will default to the first available action - return 0; - } - - function onActionEvent(action, state) { - if (!active) { - return; - } - if (state < THRESHOLD) { - if (action == findAction("YAW_LEFT") || action == findAction("YAW_RIGHT")) { - yawTimer = CAMERA_UPDATE_TIME; - } else if (action == findAction("PITCH_UP") || action == findAction("PITCH_DOWN")) { - pitchTimer = CAMERA_UPDATE_TIME; - } - return; - } - switch (action) { - case findAction("LONGITUDINAL_BACKWARD"): - var direction = {x: 0.0, y: 0.0, z:1.0}; - direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - velocity = Vec3.sum(velocity, direction); - break; - case findAction("LONGITUDINAL_FORWARD"): - var direction = {x: 0.0, y: 0.0, z:-1.0}; - direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - velocity = Vec3.sum(velocity, direction); - break; - case findAction("LATERAL_LEFT"): - var direction = {x:-1.0, y: 0.0, z: 0.0} - direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - velocity = Vec3.sum(velocity, direction); - break; - case findAction("LATERAL_RIGHT"): - var direction = {x:1.0, y: 0.0, z: 0.0}; - direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - velocity = Vec3.sum(velocity, direction); - break; - case findAction("VERTICAL_DOWN"): - var direction = {x: 0.0, y: -1.0, z: 0.0}; - direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - velocity = Vec3.sum(velocity, direction); - break; - case findAction("VERTICAL_UP"): - var direction = {x: 0.0, y: 1.0, z: 0.0}; - direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - velocity = Vec3.sum(velocity, direction); - break; - case findAction("YAW_LEFT"): - if (yawTimer < 0.0 && HMD.active) { - yawChange = yawChange + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); - yawTimer = CAMERA_UPDATE_TIME; - } else if (!HMD.active) { - yawChange = yawChange + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); - } - break; - case findAction("YAW_RIGHT"): - if (yawTimer < 0.0 && HMD.active) { - yawChange = yawChange - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); - yawTimer = CAMERA_UPDATE_TIME; - } else if (!HMD.active) { - yawChange = yawChange - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); - } - break; - case findAction("PITCH_DOWN"): - if (!HMD.active) { - pitchChange = pitchChange - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT); - } - break; - case findAction("PITCH_UP"): - if (!HMD.active) { - pitchChange = pitchChange + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT); - } - break; - case findAction("SHIFT"): // speed up - if (shiftTimer < 0.0) { - shifted = !shifted; - shiftTimer = SHIFT_UPDATE_TIME; - } - break; - case findAction("ACTION1"): // start/end warp - if (warpTimer < 0.0) { - warpActive = !warpActive; - if (!warpActive) { - finishWarp(); - } - warpTimer = WARP_UPDATE_TIME; - } - break; - case findAction("ACTION2"): // cancel warp - warpActive = false; - Overlays.editOverlay(warpSphere, { - visible: false, - }); - Overlays.editOverlay(warpLine, { - visible: false, - }); - default: - break; - } - } - - function update(dt) { - if (prevVRMode != HMD.active) { - active = HMD.active; - prevVRMode = HMD.active; - } - - if (yawTimer >= 0.0) { - yawTimer = yawTimer - dt; - } - if (shiftTimer >= 0.0) { - shiftTimer = shiftTimer - dt; - } - if (warpTimer >= 0.0) { - warpTimer = warpTimer - dt; - } - - if (warpActive) { - updateWarp(); - } - - if (active) { - Controller.captureActionEvents(); - - MyAvatar.bodyYaw = MyAvatar.bodyYaw + yawChange; - MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + pitchChange)); - yawChange = 0; - pitchChange = 0; - - MyAvatar.motorVelocity = velocity; - MyAvatar.motorTimescale = 0.0; - velocity = { x: 0, y: 0, z: 0 }; - } else { - Controller.releaseActionEvents(); - yawChange = 0; - pitchChange = 0; - MyAvatar.motorVelocity = {x:0.0, y:0.0, z:0.0} - MyAvatar.motorTimescale = VERY_LONG_TIME; - } - } - - function updateWarp() { - var look = Quat.getFront(Camera.getOrientation()); - var pitch = Math.asin(look.y); - - // Get relative to looking straight down - pitch += Math.PI / 2; - - // Scale up - pitch *= 2; - var distance = pitch * pitch * pitch; - - var warpDirection = Vec3.normalize({ x: look.x, y: 0, z: look.z }); - warpPosition = Vec3.multiply(warpDirection, distance); - warpPosition = Vec3.sum(MyAvatar.position, warpPosition); - - // Commented out until ray picking can be fixed - // var pickRay = { - // origin: Vec3.sum(warpPosition, WARP_PICK_OFFSET), - // direction: { x: 0, y: -1, z: 0 } - // }; - - // var intersection = Entities.findRayIntersection(pickRay); - - // if (intersection.intersects && intersection.distance < WARP_PICK_MAX_DISTANCE) { - // // Warp 1 meter above the object - this is an approximation - // // TODO Get the actual offset to the Avatar's feet and plant them to - // // the object. - // warpPosition = Vec3.sum(intersection.intersection, { x: 0, y: 1, z:0 }); - // } - - // Adjust overlays to match warp position - Overlays.editOverlay(warpSphere, { - position: warpPosition, - visible: true, - }); - Overlays.editOverlay(warpLine, { - start: warpPosition, - end: Vec3.sum(warpPosition, { x: 0, y: WARP_LINE_HEIGHT, z: 0 }), - visible: true, - }); - } - - function finishWarp() { - Overlays.editOverlay(warpSphere, { - visible: false, - }); - Overlays.editOverlay(warpLine, { - visible: false, - }); - MyAvatar.position = warpPosition; - } - - function setUp() { - Controller.keyPressEvent.connect(onKeyPressEvent); - - Controller.actionEvent.connect(onActionEvent); - - Script.update.connect(update); - } - - function tearDown() { - Controller.releaseActionEvents(); - MyAvatar.motorVelocity = {x:0.0, y:0.0, z:0.0} - MyAvatar.motorTimescale = VERY_LONG_TIME; - } - - setUp(); - Script.scriptEnding.connect(tearDown); -}()); \ No newline at end of file diff --git a/examples/hmdDefaults.js b/examples/hmdDefaults.js deleted file mode 100644 index 2b5f333644..0000000000 --- a/examples/hmdDefaults.js +++ /dev/null @@ -1,17 +0,0 @@ -// -// hmdDefaults.js -// examples -// -// Created by David Rowe on 6 Mar 2015. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.load("progress.js"); -Script.load("lobby.js"); -Script.load("notifications.js"); -Script.load("controllers/oculus/goTo.js"); -Script.load("hmdControls.js"); -//Script.load("scripts.js"); // Not created yet From 9351d5edcae27541fcadad867c86210b75173fdb Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 10 Mar 2016 12:55:01 -0800 Subject: [PATCH 49/59] Rig: warning fix & comments --- libraries/animation/src/Rig.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 4e7564472c..bca90b242a 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -1074,14 +1074,13 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { if (_animSkeleton && _animNode) { const float HAND_RADIUS = 0.05f; - const float MIN_LENGTH = 1.0e-4f; - - // project the hips onto the xz plane. int hipsIndex = indexOfJoint("Hips"); glm::vec3 hipsTrans; if (hipsIndex >= 0) { hipsTrans = _internalPoseSet._absolutePoses[hipsIndex].trans; } + + // Use this capsule to represent the avatar body. const float bodyCapsuleRadius = params.bodyCapsuleRadius; const glm::vec3 bodyCapsuleCenter = hipsTrans - params.bodyCapsuleLocalOffset; const glm::vec3 bodyCapsuleStart = bodyCapsuleCenter - glm::vec3(0, params.bodyCapsuleHalfHeight, 0); From 6d11dd465ca50b2a7fffaf00b3da4dee5c0753a2 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 10 Mar 2016 13:12:09 -0800 Subject: [PATCH 50/59] Application: reset avatar on displayMode change but not HMD sensor. --- interface/src/Application.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 66662a7500..795145ca5c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4857,6 +4857,9 @@ void Application::updateDisplayMode() { } emit activeDisplayPluginChanged(); + // reset the avatar, to set head and hand palms back to a resonable default pose. + getMyAvatar()->reset(false); + Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); } From 509abbf1d43e959c4ff8f67da819db99ddc04c07 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 10 Mar 2016 13:31:27 -0800 Subject: [PATCH 51/59] remove inspect.js from default scripts --- examples/defaultScripts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index 2c024c5bf0..ab3ff956d4 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -13,7 +13,6 @@ Script.load("progress.js"); Script.load("edit.js"); Script.load("marketplace.js"); Script.load("selectAudioDevice.js"); -Script.load("inspect.js"); Script.load("notifications.js"); Script.load("users.js"); Script.load("controllers/handControllerGrab.js"); From 1e96c9e2cac06a6cc0809a5ccef248003a302809 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 14:03:37 -0800 Subject: [PATCH 52/59] Merging back with master --- libraries/render-utils/src/directional_ambient_light.slf | 4 ---- libraries/render-utils/src/directional_skybox_light.slf | 3 --- 2 files changed, 7 deletions(-) diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 34040025a4..e1ec0d3ef0 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -49,8 +49,4 @@ void main(void) { frag.roughness); _fragColor = vec4(color, frag.normalVal.a); } - - if (gl_FragCoord.y > 500) { - _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); - } } diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index 373cbd2442..9e24a5f585 100755 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -51,7 +51,4 @@ void main(void) { _fragColor = vec4(color, frag.normalVal.a); } - if (gl_FragCoord.y > 500) { - _fragColor.xyz = pow(_fragColor.xyz, vec3(2.2)); - } } From f97c7b00defbe9c8333e82e53d8ad5fce61ca4d6 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 14:06:07 -0800 Subject: [PATCH 53/59] Removing old modifications --- libraries/gpu/src/gpu/GLBackendOutput.cpp | 1 - libraries/gpu/src/gpu/GLBackendTexture.cpp | 39 ---------------------- 2 files changed, 40 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 26754ba652..37a10e670b 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -209,7 +209,6 @@ void GLBackend::resetOutputStage() { _output._drawFBO = 0; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); } - glEnable(GL_FRAMEBUFFER_SRGB); } void GLBackend::do_setFramebuffer(Batch& batch, size_t paramOffset) { diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 5cf3b50f64..a70904a4bf 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -117,45 +117,6 @@ public: break; case gpu::RGBA: texel.internalFormat = GL_RGBA; - switch (dstFormat.getType()) { - case gpu::UINT32: - case gpu::NUINT32: { - texel.internalFormat = GL_RGBA32UI; - break; - } - case gpu::INT32: - case gpu::NINT32: { - texel.internalFormat = GL_RGBA32I; - break; - } - case gpu::FLOAT: { - texel.internalFormat = GL_RGBA32F; - break; - } - case gpu::UINT16: - case gpu::NUINT16: { - texel.internalFormat = GL_RGBA16UI; - break; - } - case gpu::INT16: - case gpu::NINT16: { - texel.internalFormat = GL_RGBA16I; - break; - } - case gpu::HALF: { - texel.internalFormat = GL_RGBA16F; - break; - } - case gpu::UINT8: - case gpu::INT8: - case gpu::NUINT8: - case gpu::NINT8: { - break; - } - case gpu::NUM_TYPES: { // quiet compiler - Q_UNREACHABLE(); - } - } break; case gpu::SRGB: texel.internalFormat = GL_SRGB; From ad7d5679323ddc93e2e2c9486de894d012491336 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 14:09:34 -0800 Subject: [PATCH 54/59] Fixing the overlay renderItem access issue --- interface/src/ui/overlays/Base3DOverlay.cpp | 19 ++++++++++++++++++- interface/src/ui/overlays/Overlays.cpp | 13 ------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 0cba089256..94533137ad 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -13,6 +13,7 @@ #include #include +#include "Application.h" const float DEFAULT_LINE_WIDTH = 1.0f; @@ -38,15 +39,17 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) : _drawInFront(base3DOverlay->_drawInFront) { } - void Base3DOverlay::setProperties(const QVariantMap& properties) { Overlay::setProperties(properties); + bool needRenderItemUpdate = false; + auto drawInFront = properties["drawInFront"]; if (drawInFront.isValid()) { bool value = drawInFront.toBool(); setDrawInFront(value); + needRenderItemUpdate = true; } auto position = properties["position"]; @@ -60,16 +63,19 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) { } if (position.isValid()) { setPosition(vec3FromVariant(position)); + needRenderItemUpdate = true; } if (properties["lineWidth"].isValid()) { setLineWidth(properties["lineWidth"].toFloat()); + needRenderItemUpdate = true; } auto rotation = properties["rotation"]; if (rotation.isValid()) { setRotation(quatFromVariant(rotation)); + needRenderItemUpdate = true; } if (properties["isSolid"].isValid()) { @@ -100,6 +106,17 @@ void Base3DOverlay::setProperties(const QVariantMap& properties) { if (properties["ignoreRayIntersection"].isValid()) { setIgnoreRayIntersection(properties["ignoreRayIntersection"].toBool()); } + + // Communicate changes to the renderItem if needed + if (needRenderItemUpdate) { + auto itemID = getRenderItemID(); + if (render::Item::isValidID(itemID)) { + render::ScenePointer scene = qApp->getMain3DScene(); + render::PendingChanges pendingChanges; + pendingChanges.updateItem(itemID); + scene->enqueuePendingChanges(pendingChanges); + } + } } QVariant Base3DOverlay::getProperty(const QString& property) { diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index f003b0316e..1179fbaa50 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -233,19 +233,6 @@ bool Overlays::editOverlay(unsigned int id, const QVariant& properties) { if (thisOverlay) { thisOverlay->setProperties(properties.toMap()); - if (thisOverlay->is3D()) { - auto itemID = thisOverlay->getRenderItemID(); - if (render::Item::isValidID(itemID)) { - render::ScenePointer scene = qApp->getMain3DScene(); - const render::Item& item = scene->getItem(itemID); - if (item.getKey() != render::payloadGetKey(thisOverlay)) { - render::PendingChanges pendingChanges; - pendingChanges.updateItem(itemID); - scene->enqueuePendingChanges(pendingChanges); - } - } - } - return true; } return false; From 3944a7f297a822537fa26277bd808a38ac103a06 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 15:03:20 -0800 Subject: [PATCH 55/59] Exposing thread safe number of allocated items for a ascene --- libraries/render/src/render/Scene.cpp | 13 +++++++++++++ libraries/render/src/render/Scene.h | 13 ++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 0cdd736fee..feaf8562d7 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -48,6 +48,10 @@ ItemID Scene::allocateID() { return _IDAllocator.fetch_add(1); } +bool Scene::isAllocatedID(const ItemID& id) { + return Item::isValidID(id) && (id < _numAllocatedItems.load()); +} + /// Enqueue change batch to the scene void Scene::enqueuePendingChanges(const PendingChanges& pendingChanges) { _changeQueueMutex.lock(); @@ -79,8 +83,17 @@ void Scene::processPendingChangesQueue() { } // Now we know for sure that we have enough items in the array to // capture anything coming from the pendingChanges + + // resets and potential NEW items resetItems(consolidatedPendingChanges._resetItems, consolidatedPendingChanges._resetPayloads); + + // Update the numItemsAtomic counter AFTER the reset changes went through + _numAllocatedItems.exchange(maxID); + + // updates updateItems(consolidatedPendingChanges._updatedItems, consolidatedPendingChanges._updateFunctors); + + // removes removeItems(consolidatedPendingChanges._removedItems); // ready to go back to rendering activities diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 40c0baca60..b2eac380ad 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -60,19 +60,25 @@ public: // This call is thread safe, can be called from anywhere to allocate a new ID ItemID allocateID(); + // Check that the ID is valid and allocated for this scene, this a threadsafe call + bool isAllocatedID(const ItemID& id); + + // THis is the total number of allocated items, this a threadsafe call + size_t getNumItems() const { return _numAllocatedItems.load(); } + // Enqueue change batch to the scene void enqueuePendingChanges(const PendingChanges& pendingChanges); // Process the penging changes equeued void processPendingChangesQueue(); + // This next call are NOT threadsafe, you have to call them from the correct thread to avoid any potential issues + // Access a particular item form its ID // WARNING, There is No check on the validity of the ID, so this could return a bad Item const Item& getItem(const ItemID& id) const { return _items[id]; } - size_t getNumItems() const { return _items.size(); } - - // Access the spatialized items + // Access the spatialized items const ItemSpatialTree& getSpatialTree() const { return _masterSpatialTree; } // Access non-spatialized items (overlays, backgrounds) @@ -81,6 +87,7 @@ public: protected: // Thread safe elements that can be accessed from anywhere std::atomic _IDAllocator{ 1 }; // first valid itemID will be One + std::atomic _numAllocatedItems{ 1 }; // num of allocated items, matching the _items.size() std::mutex _changeQueueMutex; PendingChangesQueue _changeQueue; From 505ae71e30fa4c571f690b6af1fb8f7819e93e4d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 15:22:19 -0800 Subject: [PATCH 56/59] Pass px userData by const ref --- libraries/procedural/src/procedural/Procedural.cpp | 2 +- libraries/procedural/src/procedural/Procedural.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 9670b66676..11df332c5c 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -142,7 +142,7 @@ bool Procedural::parseTextures(const QJsonArray& channels) { return true; } -void Procedural::parse(QJsonObject proceduralData) { +void Procedural::parse(const QJsonObject& proceduralData) { _enabled = false; if (proceduralData.isEmpty()) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 75872ca2bc..cac3f782e4 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -93,7 +93,7 @@ protected: private: // This should only be called from the render thread, as it shares data with Procedural::prepare - void parse(QJsonObject); + void parse(const QJsonObject&); bool parseVersion(const QJsonValue& version); bool parseUrl(const QUrl& url); bool parseUniforms(const QJsonObject& uniforms); From a88f22fa3c33795a3e193fb4294c9ef932f67f41 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 10 Mar 2016 15:58:04 -0800 Subject: [PATCH 57/59] Removing white spaces --- libraries/render/src/render/Scene.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index b2eac380ad..b7cfc367b8 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -78,7 +78,7 @@ public: // WARNING, There is No check on the validity of the ID, so this could return a bad Item const Item& getItem(const ItemID& id) const { return _items[id]; } - // Access the spatialized items + // Access the spatialized items const ItemSpatialTree& getSpatialTree() const { return _masterSpatialTree; } // Access non-spatialized items (overlays, backgrounds) From 11867aa71ddd900e72a07131b96423e6e493fe8a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 20:03:31 -0800 Subject: [PATCH 58/59] Compile shaders to their own folders --- cmake/macros/AutoScribeShader.cmake | 6 + cmake/macros/LinkHifiLibraries.cmake | 10 +- interface/src/Stars.cpp | 8 +- .../src/RenderableBoxEntityItem.cpp | 4 +- .../src/RenderableSphereEntityItem.cpp | 4 +- tests/shaders/src/main.cpp | 118 +++++++++--------- 6 files changed, 72 insertions(+), 78 deletions(-) diff --git a/cmake/macros/AutoScribeShader.cmake b/cmake/macros/AutoScribeShader.cmake index 6dc4899d29..29a53e7737 100755 --- a/cmake/macros/AutoScribeShader.cmake +++ b/cmake/macros/AutoScribeShader.cmake @@ -46,6 +46,9 @@ function(AUTOSCRIBE_SHADER SHADER_FILE) set(SHADER_TARGET ${SHADER_TARGET}_frag.h) endif() + # Put shaders in an isolated place + set(SHADER_TARGET "shaders/${TARGET_NAME}/${SHADER_TARGET}") + # Target dependant Custom rule on the SHADER_FILE if (APPLE) set(GLPROFILE MAC_GL) @@ -105,4 +108,7 @@ macro(AUTOSCRIBE_SHADER_LIB) list(APPEND AUTOSCRIBE_SHADER_LIB_SRC ${SHADER_SOURCE_FILES}) list(APPEND AUTOSCRIBE_SHADER_LIB_SRC ${AUTOSCRIBE_SHADER_SRC}) + # Link library shaders, if they exist + include_directories("${CMAKE_CURRENT_BINARY_DIR}/shaders/${TARGET_NAME}") + endmacro() diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index ed37256b10..3767dc7131 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -19,20 +19,14 @@ macro(LINK_HIFI_LIBRARIES) endif () include_directories("${HIFI_LIBRARY_DIR}/${HIFI_LIBRARY}/src") + include_directories("${CMAKE_BINARY_DIR}/libraries/${HIFI_LIBRARY}/shaders") add_dependencies(${TARGET_NAME} ${HIFI_LIBRARY}) # link the actual library - it is static so don't bubble it up target_link_libraries(${TARGET_NAME} ${HIFI_LIBRARY}) - - # ask the library what its include dependencies are and link them - get_target_property(LINKED_TARGET_DEPENDENCY_INCLUDES ${HIFI_LIBRARY} DEPENDENCY_INCLUDES) - - if(LINKED_TARGET_DEPENDENCY_INCLUDES) - list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) - endif() endforeach() setup_memory_debugger() -endmacro(LINK_HIFI_LIBRARIES) \ No newline at end of file +endmacro(LINK_HIFI_LIBRARIES) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 3305cc4f3b..a0283f0efd 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -22,11 +22,11 @@ #include #include -#include -#include +#include +#include -#include -#include +#include +#include //static const float TILT = 0.23f; static const float TILT = 0.0f; diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 671043813e..e53b77a4dc 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -19,8 +19,8 @@ #include #include -#include "../render-utils/simple_vert.h" -#include "../render-utils/simple_frag.h" +#include +#include EntityItemPointer RenderableBoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItemPointer entity{ new RenderableBoxEntityItem(entityID) }; diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index b5867fb1ee..135e29cc48 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -19,8 +19,8 @@ #include #include -#include "../render-utils/simple_vert.h" -#include "../render-utils/simple_frag.h" +#include +#include // Sphere entities should fit inside a cube entity of the same size, so a sphere that has dimensions 1x1x1 // is a half unit sphere. However, the geometry cache renders a UNIT sphere, so we need to scale down. diff --git a/tests/shaders/src/main.cpp b/tests/shaders/src/main.cpp index ddc7ad6540..82c5583f53 100644 --- a/tests/shaders/src/main.cpp +++ b/tests/shaders/src/main.cpp @@ -23,83 +23,77 @@ #include #include -#include "../model/Skybox_vert.h" -#include "../model/Skybox_frag.h" +#include +#include +#include +#include -#include "simple_vert.h" -#include "simple_frag.h" -#include "simple_textured_frag.h" -#include "simple_textured_emisive_frag.h" +#include +#include -#include "deferred_light_vert.h" -#include "deferred_light_limited_vert.h" +#include +#include +#include -#include "directional_light_frag.h" +#include +#include -#include "directional_ambient_light_frag.h" +#include +#include -#include "directional_skybox_light_frag.h" +#include +#include +#include +#include +#include +#include +#include +#include -#include "point_light_frag.h" -#include "spot_light_frag.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "standardTransformPNTC_vert.h" -#include "standardDrawTexture_frag.h" +#include +#include +#include +#include -#include "model_vert.h" -#include "model_shadow_vert.h" -#include "model_normal_map_vert.h" -#include "model_lightmap_vert.h" -#include "model_lightmap_normal_map_vert.h" -#include "skin_model_vert.h" -#include "skin_model_shadow_vert.h" -#include "skin_model_normal_map_vert.h" +#include +#include -#include "model_frag.h" -#include "model_shadow_frag.h" -#include "model_normal_map_frag.h" -#include "model_normal_specular_map_frag.h" -#include "model_specular_map_frag.h" -#include "model_lightmap_frag.h" -#include "model_lightmap_normal_map_frag.h" -#include "model_lightmap_normal_specular_map_frag.h" -#include "model_lightmap_specular_map_frag.h" -#include "model_translucent_frag.h" +#include +#include -#include "untextured_particle_frag.h" -#include "untextured_particle_vert.h" -#include "textured_particle_frag.h" -#include "textured_particle_vert.h" +#include +#include +#include +#include +#include -#include "hit_effect_vert.h" -#include "hit_effect_frag.h" +#include +#include +#include +#include +#include +#include -#include "overlay3D_vert.h" -#include "overlay3D_frag.h" +#include +#include -#include "Skybox_vert.h" -#include "Skybox_frag.h" +#include +#include -#include "stars_vert.h" -#include "stars_frag.h" -#include "starsGrid_frag.h" - -#include "DrawTransformUnitQuad_vert.h" -#include "DrawTexcoordRectTransformUnitQuad_vert.h" -#include "DrawViewportQuadTransformTexcoord_vert.h" -#include "DrawTexture_frag.h" -#include "DrawTextureOpaque_frag.h" -#include "DrawColoredTexture_frag.h" - -#include "sdf_text3D_vert.h" -#include "sdf_text3D_frag.h" - -#include "paintStroke_vert.h" -#include "paintStroke_frag.h" - -#include "polyvox_vert.h" -#include "polyvox_frag.h" +#include +#include // Create a simple OpenGL window that renders text in various ways class QTestWindow : public QWindow { From 243fbf82993adcd85a83dcdcbd71bfb860e8e9b9 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 20:37:24 -0800 Subject: [PATCH 59/59] Specify and create shaders folder --- cmake/macros/AutoScribeShader.cmake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmake/macros/AutoScribeShader.cmake b/cmake/macros/AutoScribeShader.cmake index 29a53e7737..f51455e9d4 100755 --- a/cmake/macros/AutoScribeShader.cmake +++ b/cmake/macros/AutoScribeShader.cmake @@ -46,8 +46,7 @@ function(AUTOSCRIBE_SHADER SHADER_FILE) set(SHADER_TARGET ${SHADER_TARGET}_frag.h) endif() - # Put shaders in an isolated place - set(SHADER_TARGET "shaders/${TARGET_NAME}/${SHADER_TARGET}") + set(SHADER_TARGET "${SHADERS_DIR}/${SHADER_TARGET}") # Target dependant Custom rule on the SHADER_FILE if (APPLE) @@ -90,10 +89,14 @@ macro(AUTOSCRIBE_SHADER_LIB) file(GLOB_RECURSE SHADER_INCLUDE_FILES src/*.slh) file(GLOB_RECURSE SHADER_SOURCE_FILES src/*.slv src/*.slf) + #make the shader folder + set(SHADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/shaders/${TARGET_NAME}") + file(MAKE_DIRECTORY ${SHADERS_DIR}) + #message(${SHADER_INCLUDE_FILES}) foreach(SHADER_FILE ${SHADER_SOURCE_FILES}) AUTOSCRIBE_SHADER(${SHADER_FILE} ${SHADER_INCLUDE_FILES}) - file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${AUTOSCRIBE_SHADER_RETURN}" AUTOSCRIBE_GENERATED_FILE) + file(TO_CMAKE_PATH "${AUTOSCRIBE_SHADER_RETURN}" AUTOSCRIBE_GENERATED_FILE) list(APPEND AUTOSCRIBE_SHADER_SRC ${AUTOSCRIBE_GENERATED_FILE}) endforeach() #message(${AUTOSCRIBE_SHADER_SRC}) @@ -109,6 +112,6 @@ macro(AUTOSCRIBE_SHADER_LIB) list(APPEND AUTOSCRIBE_SHADER_LIB_SRC ${AUTOSCRIBE_SHADER_SRC}) # Link library shaders, if they exist - include_directories("${CMAKE_CURRENT_BINARY_DIR}/shaders/${TARGET_NAME}") + include_directories("${SHADERS_DIR}") endmacro()