diff --git a/BUILD.md b/BUILD.md index 3d3a4d055b..fe0459e7db 100644 --- a/BUILD.md +++ b/BUILD.md @@ -75,5 +75,5 @@ In the examples below the variable $NAME would be replaced by the name of the de ####Devices -You can support external input/output devices such as Oculus Rift, Leap Motion, Faceshift, PrioVR, MIDI, Razr Hydra and more by adding each individual SDK in the visible building path. Refer to the readme file available in each device folder in [interface/external/](interface/external) for the detailed explanation of the requirements to use the device. +You can support external input/output devices such as Oculus Rift, Leap Motion, Faceshift, MIDI, Razr Hydra and more by adding each individual SDK in the visible building path. Refer to the readme file available in each device folder in [interface/external/](interface/external) for the detailed explanation of the requirements to use the device. diff --git a/BUILD_WIN.md b/BUILD_WIN.md index df50fd82c8..39252ec4f2 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -14,18 +14,14 @@ Or you can start a regular command prompt and then run: If using Visual Studio 2013 and building as a Visual Studio 2013 project you need the Windows 8 SDK which you should already have as part of installing Visual Studio 2013. You should be able to see it at `C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86`. -####nmake & msbuild +####nmake -Some of the external projects may require nmake and msbuild to compile and install. If they are not installed at the locations listed below, please ensure that both are in your PATH so CMake can find them when required. +Some of the external projects may require nmake to compile and install. If it is not installed at the location listed below, please ensure that it is in your PATH so CMake can find it when required. We expect nmake.exe to be located at the following path. C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin -We expect msbuild.exe to be located at the following path. - - C:\Program Files (x86)\MSBUILD\12.0\Bin - ###Qt You can use the online installer or the offline installer. If you use the offline installer, be sure to select the "OpenGL" version. diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index c545262967..d56db7aace 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -44,7 +44,7 @@ Agent::Agent(const QByteArray& packet) : // be the parent of the script engine so it gets moved when we do _scriptEngine.setParent(this); - _scriptEngine.getEntityScriptingInterface()->setPacketSender(&_entityEditSender); + DependencyManager::get()->setPacketSender(&_entityEditSender); DependencyManager::set(); DependencyManager::set(); @@ -68,8 +68,8 @@ void Agent::readPendingDatagrams() { // PacketType_JURISDICTION, first byte is the node type... switch (receivedPacket[headerBytes]) { case NodeType::EntityServer: - _scriptEngine.getEntityScriptingInterface()->getJurisdictionListener()-> - queueReceivedPacket(matchedNode, receivedPacket); + DependencyManager::get()->getJurisdictionListener()-> + queueReceivedPacket(matchedNode, receivedPacket); break; } } @@ -211,10 +211,12 @@ void Agent::run() { _scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get().data()); + auto entityScriptingInterface = DependencyManager::get(); + _scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer); - _entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener()); + _entityViewer.setJurisdictionListener(entityScriptingInterface->getJurisdictionListener()); _entityViewer.init(); - _scriptEngine.getEntityScriptingInterface()->setEntityTree(_entityViewer.getTree()); + entityScriptingInterface->setEntityTree(_entityViewer.getTree()); _scriptEngine.setScriptContents(scriptContents); _scriptEngine.run(); diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 86680d2f03..fba96c4967 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QStri DependencyManager::registerInheritance(); auto addressManager = DependencyManager::set(); auto nodeList = DependencyManager::set(NodeType::Unassigned); + auto entityScriptingInterface = DependencyManager::set(); // make up a uuid for this child so the parent can tell us apart. This id will be changed // when the domain server hands over an assignment. diff --git a/cmake/externals/bullet/CMakeLists.txt b/cmake/externals/bullet/CMakeLists.txt index d08ceb11b9..e3610997d1 100644 --- a/cmake/externals/bullet/CMakeLists.txt +++ b/cmake/externals/bullet/CMakeLists.txt @@ -14,21 +14,12 @@ endif () include(ExternalProject) -if (WIN32) - if (UPPER_CMAKE_BUILD_TYPE MATCHES DEBUG) - set(MSBUILD_CONFIGURATION Debug) - else () - set(MSBUILD_CONFIGURATION Release) - endif () - - find_program(MSBUILD_COMMAND msbuild PATHS "C:/Program Files (x86)/MSBUILD/12.0/Bin") - +if (WIN32) ExternalProject_Add( ${EXTERNAL_NAME} URL https://bullet.googlecode.com/files/bullet-2.82-r2704.zip URL_MD5 f5e8914fc9064ad32e0d62d19d33d977 - CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 - BUILD_COMMAND ${MSBUILD_COMMAND} ALL_BUILD.vcxproj /p:Configuration=${MSBUILD_CONFIGURATION} + CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 LOG_DOWNLOAD 1 LOG_CONFIGURE 1 LOG_BUILD 1 @@ -66,28 +57,22 @@ elseif (WIN32) endif () if (DEFINED BULLET_LIB_EXT) - if (NOT WIN32 OR UPPER_CMAKE_BUILD_TYPE MATCHES RELEASE) - set(_PRESENT_LIB_TYPE RELEASE) - set(_MISSING_LIB_TYPE DEBUG) - else () - set(_PRESENT_LIB_TYPE DEBUG) - set(_MISSING_LIB_TYPE RELEASE) - set(_LIB_NAME_SUFFIX _Debug) - endif () + set(_BULLET_LIB_PAIRS "DYNAMICS_LIBRARY\;BulletDynamics" "COLLISION_LIBRARY\;BulletCollision" "MATH_LIBRARY\;LinearMath" "SOFTBODY_LIBRARY\;BulletSoftBody") - set(${EXTERNAL_NAME_UPPER}_DYNAMICS_LIBRARY_${_PRESENT_LIB_TYPE} ${BULLET_LIB_DIR}/${LIB_PREFIX}BulletDynamics${_LIB_NAME_SUFFIX}.${BULLET_LIB_EXT} CACHE FILEPATH "Bullet dynamics ${_PRESENT_LIB_TYPE} library location") - set(${EXTERNAL_NAME_UPPER}_DYNAMICS_LIBRARY_${_MISSING_LIB_TYPE} "" CACHE FILEPATH "Bullet dynamics ${_MISSING_LIB_TYPE} library location") - - set(${EXTERNAL_NAME_UPPER}_COLLISION_LIBRARY_${_PRESENT_LIB_TYPE} ${BULLET_LIB_DIR}/${LIB_PREFIX}BulletCollision${_LIB_NAME_SUFFIX}.${BULLET_LIB_EXT} CACHE FILEPATH "Bullet collision ${_PRESENT_LIB_TYPE} library location") - set(${EXTERNAL_NAME_UPPER}_COLLISION_LIBRARY_${_MISSING_LIB_TYPE} "" CACHE FILEPATH "Bullet collision ${_MISSING_LIB_TYPE} library location") - - set(${EXTERNAL_NAME_UPPER}_MATH_LIBRARY_${_PRESENT_LIB_TYPE} ${BULLET_LIB_DIR}/${LIB_PREFIX}LinearMath${_LIB_NAME_SUFFIX}.${BULLET_LIB_EXT} CACHE FILEPATH "Bullet math ${_PRESENT_LIB_TYPE} library location") - set(${EXTERNAL_NAME_UPPER}_MATH_LIBRARY_${_MISSING_LIB_TYPE} "" CACHE FILEPATH "Bullet math ${_MISSING_LIB_TYPE} library location") - - set(${EXTERNAL_NAME_UPPER}_SOFTBODY_LIBRARY_${_PRESENT_LIB_TYPE} ${BULLET_LIB_DIR}/${LIB_PREFIX}BulletSoftBody${_LIB_NAME_SUFFIX}.${BULLET_LIB_EXT} CACHE FILEPATH "Bullet softbody ${_PRESENT_LIB_TYPE} library location") - set(${EXTERNAL_NAME_UPPER}_SOFTBODY_LIBRARY_${_MISSING_LIB_TYPE} "" CACHE FILEPATH "Bullet softbody ${_MISSING_LIB_TYPE} library location") + foreach(_LIB_PAIR ${_BULLET_LIB_PAIRS}) + list(GET _LIB_PAIR 0 _LIB_VAR_NAME) + list(GET _LIB_PAIR 1 _LIB_NAME) + + set(${EXTERNAL_NAME_UPPER}_${_LIB_VAR_NAME}_RELEASE ${BULLET_LIB_DIR}/${LIB_PREFIX}${_LIB_NAME}.${BULLET_LIB_EXT} CACHE FILEPATH "${_LIB_NAME} release library location") + + if (WIN32) + set(${EXTERNAL_NAME_UPPER}_${_LIB_VAR_NAME}_DEBUG ${BULLET_LIB_DIR}/${LIB_PREFIX}${_LIB_NAME}_Debug.${BULLET_LIB_EXT} CACHE FILEPATH "${_LIB_NAME} debug library location") + else () + set(${EXTERNAL_NAME_UPPER}_${_LIB_VAR_NAME}_DEBUG "" CACHE FILEPATH "${_LIB_NAME} debug library location") + endif () + endforeach() endif () -if (DEFINED ${EXTERNAL_NAME_UPPER}_DYNAMICS_LIBRARY_${_PRESENT_LIB_TYPE}) +if (DEFINED ${EXTERNAL_NAME_UPPER}_DYNAMICS_LIBRARY_RELEASE) set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIR ${INSTALL_DIR}/include/bullet CACHE PATH "Path to bullet include directory") endif () \ No newline at end of file diff --git a/cmake/externals/qxmpp/CMakeLists.txt b/cmake/externals/qxmpp/CMakeLists.txt new file mode 100644 index 0000000000..9165da115f --- /dev/null +++ b/cmake/externals/qxmpp/CMakeLists.txt @@ -0,0 +1,74 @@ +set(EXTERNAL_NAME qxmpp) + +# we need to find qmake inside QT_DIR +find_program(QMAKE_COMMAND NAME qmake PATHS ${QT_DIR}/bin $ENV{QTTOOLDIR} NO_DEFAULT_PATH) + +if (NOT QMAKE_COMMAND) + message(FATAL_ERROR "Could not find qmake. Qxmpp cannot be compiled without qmake.") +endif () + +if (ANDROID) + set(ANDROID_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DANDROID_NATIVE_API_LEVEL=19") +endif () + +if (WIN32) + find_program(PLATFORM_BUILD_COMMAND nmake PATHS "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin") + + if (NOT PLATFORM_BUILD_COMMAND) + message(FATAL_ERROR "You asked CMake to grap QXmpp and build it, but nmake was not found. Please make sure the folder containing nmake.exe is in your PATH.") + endif () +else () + find_program(PLATFORM_BUILD_COMMAND make) +endif () + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + URL http://qxmpp.googlecode.com/files/qxmpp-0.7.6.tar.gz + URL_MD5 ee45a97313306ded2ff0f6618a3ed1e1 + BUILD_IN_SOURCE 1 + PATCH_COMMAND patch -p2 -t -N --verbose < ${CMAKE_CURRENT_SOURCE_DIR}/qxmpp.patch + CONFIGURE_COMMAND ${QMAKE_COMMAND} PREFIX= + BUILD_COMMAND ${PLATFORM_BUILD_COMMAND} + INSTALL_COMMAND ${PLATFORM_BUILD_COMMAND} install + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) + +if (CMAKE_GENERATOR STREQUAL Xcode) + find_program(DITTO_COMMAND ditto) + + ExternalProject_Add_Step( + ${EXTERNAL_NAME} + copy-from-xcode-install + COMMENT "Copying from /tmp/hifi.dst${INSTALL_DIR} to move install to proper location" + COMMAND ${DITTO_COMMAND} /tmp/hifi.dst${INSTALL_DIR} ${INSTALL_DIR} + DEPENDEES install + LOG 1 + ) +endif () + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE FILEPATH "Path to Qxmpp include directory") + +set(_LIB_DIR ${INSTALL_DIR}/lib) + +if (WIN32) + set(_LIB_EXT "0.lib") + + set(${EXTERNAL_NAME_UPPER}_DLL_PATH ${_LIB_DIR} CACHE PATH "Location of QXmpp DLL") +else () + if (APPLE) + set(_LIB_EXT ".dylib") + else () + set(_LIB_EXT ".so") + endif () + + set(_LIB_PREFIX "lib") +endif () + +set(${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE ${_LIB_DIR}/${_LIB_PREFIX}qxmpp${_LIB_EXT} CACHE FILEPATH "Path to QXmpp release library") +set(${EXTERNAL_NAME_UPPER}_LIBRARY_DEBUG "" CACHE FILEPATH "Path to QXmpp debug library") diff --git a/cmake/macros/AutoScribeShader.cmake b/cmake/macros/AutoScribeShader.cmake index 8b221c8c59..51b6b205e8 100755 --- a/cmake/macros/AutoScribeShader.cmake +++ b/cmake/macros/AutoScribeShader.cmake @@ -15,12 +15,21 @@ function(AUTOSCRIBE_SHADER SHADER_FILE) list(APPEND SHADER_INCLUDE_FILES ${includeFile}) endforeach() - #Extract the unique include shader paths foreach(SHADER_INCLUDE ${SHADER_INCLUDE_FILES}) get_filename_component(INCLUDE_DIR ${SHADER_INCLUDE} PATH) list(APPEND SHADER_INCLUDES_PATHS ${INCLUDE_DIR}) endforeach() + + + #Extract the unique include shader paths + set(INCLUDES ${HIFI_LIBRARIES_SHADER_INCLUDE_FILES}) + #message(Hifi for includes ${INCLUDES}) + foreach(EXTRA_SHADER_INCLUDE ${INCLUDES}) + list(APPEND SHADER_INCLUDES_PATHS ${EXTRA_SHADER_INCLUDE}) + endforeach() + list(REMOVE_DUPLICATES SHADER_INCLUDES_PATHS) + #message(ready for includes ${SHADER_INCLUDES_PATHS}) # make the scribe include arguments set(SCRIBE_INCLUDES) @@ -64,6 +73,17 @@ endfunction() macro(AUTOSCRIBE_SHADER_LIB) + + file(RELATIVE_PATH RELATIVE_LIBRARY_DIR_PATH ${CMAKE_CURRENT_SOURCE_DIR} "${HIFI_LIBRARY_DIR}") + foreach(HIFI_LIBRARY ${ARGN}) + #if (NOT TARGET ${HIFI_LIBRARY}) + # file(GLOB_RECURSE HIFI_LIBRARIES_SHADER_INCLUDE_FILES ${RELATIVE_LIBRARY_DIR_PATH}/${HIFI_LIBRARY}/src/) + #endif () + + #file(GLOB_RECURSE HIFI_LIBRARIES_SHADER_INCLUDE_FILES ${HIFI_LIBRARY_DIR}/${HIFI_LIBRARY}/src/*.slh) + list(APPEND HIFI_LIBRARIES_SHADER_INCLUDE_FILES ${HIFI_LIBRARY_DIR}/${HIFI_LIBRARY}/src) + endforeach() + #message(${HIFI_LIBRARIES_SHADER_INCLUDE_FILES}) file(GLOB_RECURSE SHADER_INCLUDE_FILES src/*.slh) file(GLOB_RECURSE SHADER_SOURCE_FILES src/*.slv src/*.slf) diff --git a/cmake/modules/FindPrioVR.cmake b/cmake/modules/FindPrioVR.cmake deleted file mode 100644 index 691ba85689..0000000000 --- a/cmake/modules/FindPrioVR.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# Try to find the PrioVR library -# -# You must provide a PRIOVR_ROOT_DIR which contains lib and include directories -# -# Once done this will define -# -# PRIOVR_FOUND - system found PrioVR -# PRIOVR_INCLUDE_DIRS - the PrioVR include directory -# PRIOVR_LIBRARIES - Link this to use PrioVR -# -# Created on 5/12/2014 by Andrzej Kapolka -# Copyright (c) 2014 High Fidelity -# - -find_path(PRIOVR_INCLUDE_DIRS yei_skeletal_api.h ${PRIOVR_ROOT_DIR}/include) - -if (WIN32) - find_library(PRIOVR_LIBRARIES Skeletal_API.lib ${PRIOVR_ROOT_DIR}/lib) -endif (WIN32) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(PrioVR DEFAULT_MSG PRIOVR_INCLUDE_DIRS PRIOVR_LIBRARIES) - -mark_as_advanced(PRIOVR_INCLUDE_DIRS PRIOVR_LIBRARIES) \ No newline at end of file diff --git a/examples/editEntities.js b/examples/editEntities.js index ef6472e4b8..a0f3cdc167 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -81,6 +81,8 @@ var SETTING_INSPECT_TOOL_ENABLED = "inspectToolEnabled"; var SETTING_AUTO_FOCUS_ON_SELECT = "autoFocusOnSelect"; var SETTING_EASE_ON_FOCUS = "cameraEaseOnFocus"; +var INSUFFICIENT_PERMISSIONS_ERROR_MSG = "You do not have the necessary permissions to edit on this domain." + var modelURLs = [ HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Alder.fbx", HIFI_PUBLIC_BUCKET + "models/entities/2-Terrain:%20Bush1.fbx", @@ -177,25 +179,29 @@ var toolBar = (function () { that.setActive = function(active) { if (active != isActive) { - isActive = active; - if (!isActive) { - entityListTool.setVisible(false); - gridTool.setVisible(false); - grid.setEnabled(false); - propertiesTool.setVisible(false); - selectionManager.clearSelections(); - cameraManager.disable(); + if (active && !Entities.canAdjustLocks()) { + Window.alert(INSUFFICIENT_PERMISSIONS_ERROR_MSG); } else { - hasShownPropertiesTool = false; - cameraManager.enable(); - entityListTool.setVisible(true); - gridTool.setVisible(true); - grid.setEnabled(true); - propertiesTool.setVisible(true); - Window.setFocus(); + isActive = active; + if (!isActive) { + entityListTool.setVisible(false); + gridTool.setVisible(false); + grid.setEnabled(false); + propertiesTool.setVisible(false); + selectionManager.clearSelections(); + cameraManager.disable(); + } else { + hasShownPropertiesTool = false; + cameraManager.enable(); + entityListTool.setVisible(true); + gridTool.setVisible(true); + grid.setEnabled(true); + propertiesTool.setVisible(true); + Window.setFocus(); + } } } - toolBar.selectTool(activeButton, active); + toolBar.selectTool(activeButton, isActive); }; var RESIZE_INTERVAL = 50; @@ -400,6 +406,12 @@ var toolBar = (function () { that.setActive(false); }); + Entities.canAdjustLocksChanged.connect(function(canAdjustLocks) { + if (isActive && !canAdjustLocks) { + that.setActive(false); + } + }); + that.cleanup = function () { toolBar.cleanup(); }; diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 74afc7b208..ded37e8915 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -2,7 +2,7 @@ set(TARGET_NAME interface) project(${TARGET_NAME}) # set a default root dir for each of our optional externals if it was not passed -set(OPTIONAL_EXTERNALS "Faceshift" "LibOVR" "PrioVR" "Sixense" "LeapMotion" "RtMidi" "SDL2" "RSSDK") +set(OPTIONAL_EXTERNALS "Faceshift" "LibOVR" "Sixense" "LeapMotion" "RtMidi" "SDL2" "RSSDK") foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE) if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR) diff --git a/interface/external/priovr/readme.txt b/interface/external/priovr/readme.txt deleted file mode 100644 index 202a90cf12..0000000000 --- a/interface/external/priovr/readme.txt +++ /dev/null @@ -1,16 +0,0 @@ - -Instructions for adding the PrioVR driver to Interface -Andrzej Kapolka, May 12, 2014 - -1. Download and install the YEI drivers from https://www.yeitechnology.com/yei-3-space-sensor-software-suite. If using - Window 8+, follow the workaround instructions at http://forum.yeitechnology.com/viewtopic.php?f=3&t=24. - -2. Get the PrioVR skeleton API, open ts_c_api2_priovr2/visual_studio/ThreeSpace_API_2/ThreeSpace_API_2.sln - in Visual Studio, and build it. - -3. Copy ts_c_api2_priovr2/visual_studio/ThreeSpace_API_2/Skeletal_API/yei_skeletal_api.h to interface/external/priovr/include, - ts_c_api2_priovr2/visual_studio/ThreeSpace_API_2/Debug/Skeletal_API.lib to interface/external/priovr/lib, and - ts_c_api2_priovr2/visual_studio/ThreeSpace_API_2/Debug/*.dll to your path. - -4. Delete your build directory, run cmake and build, and you should be all set. - diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fe41621dc1..81d625d01a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -241,6 +241,7 @@ bool setupEssentials(int& argc, char** argv) { auto dialogsManager = DependencyManager::set(); auto bandwidthRecorder = DependencyManager::set(); auto resouceCacheSharedItems = DependencyManager::set(); + auto entityScriptingInterface = DependencyManager::set(); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) auto speechRecognizer = DependencyManager::set(); #endif @@ -1766,8 +1767,10 @@ void Application::init() { tree->setSimulation(&_physicsEngine); _physicsEngine.init(&_entityEditSender); + auto entityScriptingInterface = DependencyManager::get(); + connect(&_physicsEngine, &EntitySimulation::entityCollisionWithEntity, - ScriptEngine::getEntityScriptingInterface(), &EntityScriptingInterface::entityCollisionWithEntity); + entityScriptingInterface.data(), &EntityScriptingInterface::entityCollisionWithEntity); // connect the _entityCollisionSystem to our EntityTreeRenderer since that's what handles running entity scripts connect(&_physicsEngine, &EntitySimulation::entityCollisionWithEntity, @@ -1775,7 +1778,7 @@ void Application::init() { // connect the _entities (EntityTreeRenderer) to our script engine's EntityScriptingInterface for firing // of events related clicking, hovering over, and entering entities - _entities.connectSignalsToSlots(ScriptEngine::getEntityScriptingInterface()); + _entities.connectSignalsToSlots(entityScriptingInterface.data()); _entityClipboardRenderer.init(); _entityClipboardRenderer.setViewFrustum(getViewFrustum()); @@ -2045,7 +2048,6 @@ void Application::update(float deltaTime) { } SixenseManager::getInstance().update(deltaTime); JoystickScriptingInterface::getInstance().update(); - _prioVR.update(deltaTime); } // Dispatch input events @@ -2545,7 +2547,9 @@ void Application::updateShadowMap() { glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * glm::mat4_cast(inverseRotation)); // update the shadow view frustum - _shadowViewFrustum.setPosition(rotation * ((minima + maxima) * 0.5f)); + // glm::vec3 shadowFrustumCenter = glm::vec3((minima.x + maxima.x) * 0.5f, (minima.y + maxima.y) * 0.5f, (minima.z + maxima.z) * 0.5f); + glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f); + _shadowViewFrustum.setPosition(shadowFrustumCenter); _shadowViewFrustum.setOrientation(rotation); _shadowViewFrustum.setOrthographic(true); _shadowViewFrustum.setWidth(maxima.x - minima.x); @@ -2575,8 +2579,10 @@ void Application::updateShadowMap() { // this is what is used for rendering the Entities and avatars Transform viewTransform; viewTransform.setRotation(rotation); + // viewTransform.postTranslate(shadowFrustumCenter); setViewTransform(viewTransform); + glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt @@ -3107,7 +3113,6 @@ void Application::resetSensors() { OculusManager::reset(); - _prioVR.reset(); //_leapmotion.reset(); QScreen* currentScreen = _window->windowHandle()->screen(); @@ -3441,8 +3446,9 @@ void joystickFromScriptValue(const QScriptValue &object, Joystick* &out) { void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scriptEngine) { // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so // we can use the same ones from the application. - scriptEngine->getEntityScriptingInterface()->setPacketSender(&_entityEditSender); - scriptEngine->getEntityScriptingInterface()->setEntityTree(_entities.getTree()); + auto entityScriptingInterface = DependencyManager::get(); + entityScriptingInterface->setPacketSender(&_entityEditSender); + entityScriptingInterface->setEntityTree(_entities.getTree()); // AvatarManager has some custom types AvatarManager::registerMetaTypes(scriptEngine); diff --git a/interface/src/Application.h b/interface/src/Application.h index 4a8e712d30..8ea55059fe 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -51,7 +51,6 @@ #include "Stars.h" #include "avatar/Avatar.h" #include "avatar/MyAvatar.h" -#include "devices/PrioVR.h" #include "devices/SixenseManager.h" #include "scripting/ControllerScriptingInterface.h" #include "ui/BandwidthDialog.h" @@ -182,7 +181,6 @@ public: MetavoxelSystem* getMetavoxels() { return &_metavoxels; } EntityTreeRenderer* getEntities() { return &_entities; } Environment* getEnvironment() { return &_environment; } - PrioVR* getPrioVR() { return &_prioVR; } QUndoStack* getUndoStack() { return &_undoStack; } MainWindow* getWindow() { return _window; } OctreeQuery& getOctreeQuery() { return _octreeQuery; } @@ -490,8 +488,6 @@ private: MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be) - PrioVR _prioVR; - Camera _myCamera; // My view onto the world Camera _mirrorCamera; // Cammera for mirror view QRect _mirrorViewRect; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 467f63ccef..cac071a677 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -77,7 +77,8 @@ Avatar::Avatar() : _moving(false), _collisionGroups(0), _initialized(false), - _shouldRenderBillboard(true) + _shouldRenderBillboard(true), + _voiceSphereID(GeometryCache::UNKNOWN_ID) { // we may have been created in the network thread, but we live in the main thread moveToThread(Application::getInstance()->thread()); @@ -366,7 +367,7 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool // render body if (Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) { - renderBody(renderMode, postLighting, glowLevel); + renderBody(frustum, renderMode, postLighting, glowLevel); } if (!postLighting && renderMode != SHADOW_RENDER_MODE) { @@ -438,8 +439,13 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); glScalef(height, height, height); + + if (_voiceSphereID == GeometryCache::UNKNOWN_ID) { + _voiceSphereID = DependencyManager::get()->allocateID(); + } DependencyManager::get()->renderSphere(sphereRadius, 15, 15, - glm::vec4(SPHERE_COLOR[0], SPHERE_COLOR[1], SPHERE_COLOR[2], 1.0f - angle / MAX_SPHERE_ANGLE)); + glm::vec4(SPHERE_COLOR[0], SPHERE_COLOR[1], SPHERE_COLOR[2], 1.0f - angle / MAX_SPHERE_ANGLE), true, + _voiceSphereID); glPopMatrix(); } @@ -471,7 +477,7 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const { return glm::angleAxis(angle * proportion, axis); } -void Avatar::renderBody(RenderMode renderMode, bool postLighting, float glowLevel) { +void Avatar::renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, bool postLighting, float glowLevel) { Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; { @@ -488,11 +494,13 @@ void Avatar::renderBody(RenderMode renderMode, bool postLighting, float glowLeve if (postLighting) { getHand()->render(false, modelRenderMode); } else { - _skeletonModel.render(1.0f, modelRenderMode); - renderAttachments(renderMode); + RenderArgs args; + args._viewFrustum = renderFrustum; + _skeletonModel.render(1.0f, modelRenderMode, &args); + renderAttachments(renderMode, &args); } } - getHead()->render(1.0f, modelRenderMode, postLighting); + getHead()->render(1.0f, renderFrustum, modelRenderMode, postLighting); } bool Avatar::shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const { @@ -519,11 +527,11 @@ void Avatar::simulateAttachments(float deltaTime) { } } -void Avatar::renderAttachments(RenderMode renderMode) { +void Avatar::renderAttachments(RenderMode renderMode, RenderArgs* args) { Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; foreach (Model* model, _attachmentModels) { - model->render(1.0f, modelRenderMode); + model->render(1.0f, modelRenderMode, args); } } diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 72b7ecf93a..432d8ad3ab 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -223,11 +223,11 @@ protected: float calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD); void renderDisplayName(); - virtual void renderBody(RenderMode renderMode, bool postLighting, float glowLevel = 0.0f); + virtual void renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, bool postLighting, float glowLevel = 0.0f); virtual bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const; void simulateAttachments(float deltaTime); - virtual void renderAttachments(RenderMode renderMode); + virtual void renderAttachments(RenderMode renderMode, RenderArgs* args); virtual void updateJointMappings(); @@ -243,6 +243,8 @@ private: float getBillboardSize() const; static int _jointConesID; + + int _voiceSphereID; }; #endif // hifi_Avatar_h diff --git a/interface/src/avatar/FaceModel.cpp b/interface/src/avatar/FaceModel.cpp index 3523cb2176..c80772ef49 100644 --- a/interface/src/avatar/FaceModel.cpp +++ b/interface/src/avatar/FaceModel.cpp @@ -39,6 +39,8 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) { setPupilDilation(_owningHead->getPupilDilation()); setBlendshapeCoefficients(_owningHead->getBlendshapeCoefficients()); + invalidCalculatedMeshBoxes(); + if (isActive()) { setOffset(-_geometry->getFBXGeometry().neckPivot); Model::simulateInternal(deltaTime); diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index a6458c7a22..b90b693139 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -243,13 +243,15 @@ void Head::relaxLean(float deltaTime) { _deltaLeanForward *= relaxationFactor; } -void Head::render(float alpha, Model::RenderMode mode, bool postLighting) { +void Head::render(float alpha, ViewFrustum* renderFrustum, Model::RenderMode mode, bool postLighting) { if (postLighting) { if (_renderLookatVectors) { renderLookatVectors(_leftEyePosition, _rightEyePosition, getCorrectedLookAtPosition()); } } else { - _faceModel.render(alpha, mode); + RenderArgs args; + args._viewFrustum = renderFrustum; + _faceModel.render(alpha, mode, &args); } } diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 6c53c2d7aa..5465d74172 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -40,7 +40,7 @@ public: void init(); void reset(); void simulate(float deltaTime, bool isMine, bool billboard = false); - void render(float alpha, Model::RenderMode mode, bool postLighting); + void render(float alpha, ViewFrustum* renderFrustum, Model::RenderMode mode, bool postLighting); void setScale(float scale); void setPosition(glm::vec3 position) { _position = position; } void setAverageLoudness(float averageLoudness) { _averageLoudness = averageLoudness; } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 8c4ea73775..9c83942439 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -294,12 +294,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) { return; } - if (Application::getInstance()->getPrioVR()->hasHeadRotation()) { - estimatedRotation = glm::degrees(safeEulerAngles(Application::getInstance()->getPrioVR()->getHeadRotation())); - estimatedRotation.x *= -1.0f; - estimatedRotation.z *= -1.0f; - - } else if (OculusManager::isConnected()) { + if (OculusManager::isConnected()) { estimatedPosition = OculusManager::getRelativePosition(); estimatedPosition.x *= -1.0f; _trackedHeadPosition = estimatedPosition; @@ -349,13 +344,6 @@ void MyAvatar::updateFromTrackers(float deltaTime) { } head->setDeltaRoll(estimatedRotation.z); - // the priovr can give us exact lean - if (Application::getInstance()->getPrioVR()->isActive()) { - glm::vec3 eulers = glm::degrees(safeEulerAngles(Application::getInstance()->getPrioVR()->getTorsoRotation())); - head->setLeanSideways(eulers.z); - head->setLeanForward(eulers.x); - return; - } // Update torso lean distance based on accelerometer data const float TORSO_LENGTH = 0.5f; glm::vec3 relativePosition = estimatedPosition - glm::vec3(0.0f, -TORSO_LENGTH, 0.0f); @@ -1079,7 +1067,7 @@ void MyAvatar::attach(const QString& modelURL, const QString& jointName, const g Avatar::attach(modelURL, jointName, translation, rotation, scale, allowDuplicates, useSaved); } -void MyAvatar::renderBody(RenderMode renderMode, bool postLighting, float glowLevel) { +void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, bool postLighting, float glowLevel) { if (!(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) { return; // wait until both models are loaded } @@ -1088,15 +1076,17 @@ void MyAvatar::renderBody(RenderMode renderMode, bool postLighting, float glowLe Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; if (!postLighting) { - _skeletonModel.render(1.0f, modelRenderMode); - renderAttachments(renderMode); + RenderArgs args; + args._viewFrustum = renderFrustum; + _skeletonModel.render(1.0f, modelRenderMode, &args); + renderAttachments(renderMode, &args); } // Render head so long as the camera isn't inside it const Camera *camera = Application::getInstance()->getCamera(); const glm::vec3 cameraPos = camera->getPosition(); if (shouldRenderHead(cameraPos, renderMode)) { - getHead()->render(1.0f, modelRenderMode, postLighting); + getHead()->render(1.0f, renderFrustum, modelRenderMode, postLighting); } if (postLighting) { getHand()->render(true, modelRenderMode); @@ -1887,9 +1877,9 @@ void MyAvatar::onToggleRagdoll() { } } -void MyAvatar::renderAttachments(RenderMode renderMode) { +void MyAvatar::renderAttachments(RenderMode renderMode, RenderArgs* args) { if (Application::getInstance()->getCamera()->getMode() != CAMERA_MODE_FIRST_PERSON || renderMode == MIRROR_RENDER_MODE) { - Avatar::renderAttachments(renderMode); + Avatar::renderAttachments(renderMode, args); return; } const FBXGeometry& geometry = _skeletonModel.getGeometry()->getFBXGeometry(); @@ -1899,7 +1889,7 @@ void MyAvatar::renderAttachments(RenderMode renderMode) { for (int i = 0; i < _attachmentData.size(); i++) { const QString& jointName = _attachmentData.at(i).jointName; if (jointName != headJointName && jointName != "Head") { - _attachmentModels.at(i)->render(1.0f, modelRenderMode); + _attachmentModels.at(i)->render(1.0f, modelRenderMode, args); } } } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index ae392268f0..4255f40712 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -38,7 +38,7 @@ public: void updateFromTrackers(float deltaTime); void render(const glm::vec3& cameraPosition, RenderMode renderMode = NORMAL_RENDER_MODE, bool postLighting = false); - void renderBody(RenderMode renderMode, bool postLighting, float glowLevel = 0.0f); + void renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, bool postLighting, float glowLevel = 0.0f); bool shouldRenderHead(const glm::vec3& cameraPosition, RenderMode renderMode) const; void renderDebugBodyPoints(); @@ -187,7 +187,7 @@ signals: void transformChanged(); protected: - virtual void renderAttachments(RenderMode renderMode); + virtual void renderAttachments(RenderMode renderMode, RenderArgs* args); private: float _turningKeyPressTime; diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 6e207f9703..fa9846fd7d 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -106,21 +106,6 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { } const FBXGeometry& geometry = _geometry->getFBXGeometry(); - PrioVR* prioVR = Application::getInstance()->getPrioVR(); - if (prioVR->isActive()) { - for (int i = 0; i < prioVR->getJointRotations().size(); i++) { - int humanIKJointIndex = prioVR->getHumanIKJointIndices().at(i); - if (humanIKJointIndex == -1) { - continue; - } - int jointIndex = geometry.humanIKJointIndices.at(humanIKJointIndex); - if (jointIndex != -1) { - JointState& state = _jointStates[jointIndex]; - state.setRotationInBindFrame(prioVR->getJointRotations().at(i), PALM_PRIORITY); - } - } - return; - } // find the left and rightmost active palms int leftPalmIndex, rightPalmIndex; @@ -294,7 +279,7 @@ void SkeletonModel::updateJointState(int index) { } void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, JointState& state) { - if (!_owningAvatar->isMyAvatar() || Application::getInstance()->getPrioVR()->isActive()) { + if (!_owningAvatar->isMyAvatar()) { return; } // get the rotation axes in joint space and use them to adjust the rotation diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp deleted file mode 100644 index 428c223eb7..0000000000 --- a/interface/src/devices/PrioVR.cpp +++ /dev/null @@ -1,224 +0,0 @@ -// -// PrioVR.cpp -// interface/src/devices -// -// Created by Andrzej Kapolka on 5/12/14. -// Copyright 2014 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 -// - -#include -#include - -#include -#include -#include -#include - -#include "Application.h" -#include "PrioVR.h" -#include "scripting/JoystickScriptingInterface.h" - -#ifdef HAVE_PRIOVR -const unsigned int SERIAL_LIST[] = { 0x00000001, 0x00000000, 0x00000008, 0x00000009, 0x0000000A, - 0x0000000C, 0x0000000D, 0x0000000E, 0x00000004, 0x00000005, 0x00000010, 0x00000011 }; -const unsigned char AXIS_LIST[] = { 9, 43, 37, 37, 37, 13, 13, 13, 52, 52, 28, 28 }; -const int LIST_LENGTH = sizeof(SERIAL_LIST) / sizeof(SERIAL_LIST[0]); - -const char* JOINT_NAMES[] = { "Neck", "Spine", "LeftArm", "LeftForeArm", "LeftHand", "RightArm", - "RightForeArm", "RightHand", "LeftUpLeg", "LeftLeg", "RightUpLeg", "RightLeg" }; - -static int indexOfHumanIKJoint(const char* jointName) { - for (int i = 0;; i++) { - QByteArray humanIKJoint = HUMANIK_JOINTS[i]; - if (humanIKJoint.isEmpty()) { - return -1; - } - if (humanIKJoint == jointName) { - return i; - } - } -} - -static void setPalm(float deltaTime, int index) { - MyAvatar* avatar = DependencyManager::get()->getMyAvatar(); - Hand* hand = avatar->getHand(); - PalmData* palm; - bool foundHand = false; - for (size_t j = 0; j < hand->getNumPalms(); j++) { - if (hand->getPalms()[j].getSixenseID() == index) { - palm = &(hand->getPalms()[j]); - foundHand = true; - } - } - if (!foundHand) { - PalmData newPalm(hand); - hand->getPalms().push_back(newPalm); - palm = &(hand->getPalms()[hand->getNumPalms() - 1]); - palm->setSixenseID(index); - } - - palm->setActive(true); - - // Read controller buttons and joystick into the hand - const QString PRIO_JOYSTICK_NAME = "PrioVR"; - Joystick* prioJoystick = JoystickScriptingInterface::getInstance().joystickWithName(PRIO_JOYSTICK_NAME); - if (prioJoystick) { - const QVector axes = prioJoystick->getAxes(); - const QVector buttons = prioJoystick->getButtons(); - - if (axes.size() >= 4 && buttons.size() >= 4) { - if (index == LEFT_HAND_INDEX) { - palm->setControllerButtons(buttons[1] ? BUTTON_FWD : 0); - palm->setTrigger(buttons[0] ? 1.0f : 0.0f); - palm->setJoystick(axes[0], -axes[1]); - - } else { - palm->setControllerButtons(buttons[3] ? BUTTON_FWD : 0); - palm->setTrigger(buttons[2] ? 1.0f : 0.0f); - palm->setJoystick(axes[2], -axes[3]); - } - } - } - - // NOTE: this math is done in the worl-frame with unecessary complexity. - // TODO: transfom this to stay in the model-frame. - glm::vec3 position; - glm::quat rotation; - SkeletonModel* skeletonModel = &DependencyManager::get()->getMyAvatar()->getSkeletonModel(); - int jointIndex; - glm::quat inverseRotation = glm::inverse(DependencyManager::get()->getMyAvatar()->getOrientation()); - if (index == LEFT_HAND_INDEX) { - jointIndex = skeletonModel->getLeftHandJointIndex(); - skeletonModel->getJointRotationInWorldFrame(jointIndex, rotation); - rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, PI_OVER_TWO, 0.0f)); - - } else { - jointIndex = skeletonModel->getRightHandJointIndex(); - skeletonModel->getJointRotationInWorldFrame(jointIndex, rotation); - rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, -PI_OVER_TWO, 0.0f)); - } - skeletonModel->getJointPositionInWorldFrame(jointIndex, position); - position = inverseRotation * (position - skeletonModel->getTranslation()); - - palm->setRawRotation(rotation); - - // Compute current velocity from position change - glm::vec3 rawVelocity; - if (deltaTime > 0.0f) { - rawVelocity = (position - palm->getRawPosition()) / deltaTime; - } else { - rawVelocity = glm::vec3(0.0f); - } - palm->setRawVelocity(rawVelocity); - palm->setRawPosition(position); - - // Store the one fingertip in the palm structure so we can track velocity - const float FINGER_LENGTH = 0.3f; // meters - const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH); - const glm::vec3 newTipPosition = position + rotation * FINGER_VECTOR; - glm::vec3 oldTipPosition = palm->getTipRawPosition(); - if (deltaTime > 0.0f) { - palm->setTipVelocity((newTipPosition - oldTipPosition) / deltaTime); - } else { - palm->setTipVelocity(glm::vec3(0.0f)); - } - palm->setTipPosition(newTipPosition); -} -#endif - -PrioVR::PrioVR() { -#ifdef HAVE_PRIOVR - char jointsDiscovered[LIST_LENGTH]; - _skeletalDevice = yei_setUpPrioVRSensors(0x00000000, const_cast(SERIAL_LIST), - const_cast(AXIS_LIST), jointsDiscovered, LIST_LENGTH, YEI_TIMESTAMP_SYSTEM); - if (!_skeletalDevice) { - return; - } - _jointRotations.resize(LIST_LENGTH); - _lastJointRotations.resize(LIST_LENGTH); - for (int i = 0; i < LIST_LENGTH; i++) { - _humanIKJointIndices.append(jointsDiscovered[i] ? indexOfHumanIKJoint(JOINT_NAMES[i]) : -1); - } -#endif -} - -PrioVR::~PrioVR() { -#ifdef HAVE_PRIOVR - if (_skeletalDevice) { - yei_stopStreaming(_skeletalDevice); - } -#endif -} - -const int HEAD_ROTATION_INDEX = 0; - -bool PrioVR::hasHeadRotation() const { - return _humanIKJointIndices.size() > HEAD_ROTATION_INDEX && _humanIKJointIndices.at(HEAD_ROTATION_INDEX) != -1; -} - -glm::quat PrioVR::getHeadRotation() const { - return _jointRotations.size() > HEAD_ROTATION_INDEX ? _jointRotations.at(HEAD_ROTATION_INDEX) : glm::quat(); -} - -glm::quat PrioVR::getTorsoRotation() const { - const int TORSO_ROTATION_INDEX = 1; - return _jointRotations.size() > TORSO_ROTATION_INDEX ? _jointRotations.at(TORSO_ROTATION_INDEX) : glm::quat(); -} - -void PrioVR::update(float deltaTime) { -#ifdef HAVE_PRIOVR - if (!_skeletalDevice) { - return; - } - PerformanceTimer perfTimer("PrioVR"); - unsigned int timestamp; - yei_getLastStreamDataAll(_skeletalDevice, (char*)_jointRotations.data(), - _jointRotations.size() * sizeof(glm::quat), ×tamp); - - // convert to our expected coordinate system, average with last rotations to smooth - for (int i = 0; i < _jointRotations.size(); i++) { - _jointRotations[i].y *= -1.0f; - _jointRotations[i].z *= -1.0f; - - glm::quat lastRotation = _lastJointRotations.at(i); - _lastJointRotations[i] = _jointRotations.at(i); - _jointRotations[i] = safeMix(lastRotation, _jointRotations.at(i), 0.5f); - } - - // convert the joysticks into palm data - setPalm(deltaTime, LEFT_HAND_INDEX); - setPalm(deltaTime, RIGHT_HAND_INDEX); -#endif -} - -void PrioVR::reset() { -#ifdef HAVE_PRIOVR - if (!_skeletalDevice) { - return; - } - connect(Application::getInstance(), SIGNAL(renderingOverlay()), SLOT(renderCalibrationCountdown())); - _calibrationCountdownStarted = QDateTime::currentDateTime(); -#endif -} - -void PrioVR::renderCalibrationCountdown() { -#ifdef HAVE_PRIOVR - const int COUNTDOWN_SECONDS = 3; - int secondsRemaining = COUNTDOWN_SECONDS - _calibrationCountdownStarted.secsTo(QDateTime::currentDateTime()); - if (secondsRemaining == 0) { - yei_tareSensors(_skeletalDevice); - Application::getInstance()->disconnect(this); - return; - } - static TextRenderer* textRenderer = TextRenderer::getInstance(MONO_FONT_FAMILY, 18, QFont::Bold, - false, TextRenderer::OUTLINE_EFFECT, 2); - QByteArray text = "Assume T-Pose in " + QByteArray::number(secondsRemaining) + "..."; - auto glCanvas = Application::getInstance()->getGLWidget(); - textRenderer->draw((glCanvas->width() - textRenderer->computeExtent(text.constData()).x) / 2, - glCanvas->height() / 2, - text, glm::vec4(1,1,1,1)); -#endif -} diff --git a/interface/src/devices/PrioVR.h b/interface/src/devices/PrioVR.h deleted file mode 100644 index bb563bf807..0000000000 --- a/interface/src/devices/PrioVR.h +++ /dev/null @@ -1,65 +0,0 @@ -// -// PrioVR.h -// interface/src/devices -// -// Created by Andrzej Kapolka on 5/12/14. -// Copyright 2014 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 -// - -#ifndef hifi_PrioVR_h -#define hifi_PrioVR_h - -#include -#include -#include - -#include - -#ifdef HAVE_PRIOVR -extern "C" { -#include -} -#endif - -/// Handles interaction with the PrioVR skeleton tracking suit. -class PrioVR : public QObject { - Q_OBJECT - -public: - - PrioVR(); - virtual ~PrioVR(); - - bool isActive() const { return !_jointRotations.isEmpty(); } - - bool hasHeadRotation() const; - - glm::quat getHeadRotation() const; - glm::quat getTorsoRotation() const; - - const QVector& getHumanIKJointIndices() const { return _humanIKJointIndices; } - const QVector& getJointRotations() const { return _jointRotations; } - - void update(float deltaTime); - void reset(); - -private slots: - - void renderCalibrationCountdown(); - -private: -#ifdef HAVE_PRIOVR - YEI_Device_Id _skeletalDevice; -#endif - - QVector _humanIKJointIndices; - QVector _jointRotations; - QVector _lastJointRotations; - - QDateTime _calibrationCountdownStarted; -}; - -#endif // hifi_PrioVR_h diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 46f9ff6f55..25f4275222 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -348,8 +348,14 @@ void EntityTreeRenderer::leaveAllEntities() { void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode, RenderArgs::RenderSide renderSide) { if (_tree && !_shuttingDown) { Model::startScene(renderSide); - RenderArgs args = { this, _viewFrustum, getSizeScale(), getBoundaryLevelAdjust(), renderMode, renderSide, + + ViewFrustum* frustum = (renderMode == RenderArgs::SHADOW_RENDER_MODE) ? + _viewState->getShadowViewFrustum() : _viewState->getCurrentViewFrustum(); + + RenderArgs args = { this, frustum, getSizeScale(), getBoundaryLevelAdjust(), renderMode, renderSide, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + _tree->lockForRead(); _tree->recurseTreeWithOperation(renderOperation, &args); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 0ee2e243f9..10ed98b0fa 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -19,6 +19,8 @@ EntityScriptingInterface::EntityScriptingInterface() : _nextCreatorTokenID(0), _entityTree(NULL) { + auto nodeList = DependencyManager::get(); + connect(nodeList.data(), &NodeList::canAdjustLocksChanged, this, &EntityScriptingInterface::canAdjustLocksChanged); } void EntityScriptingInterface::queueEntityMessage(PacketType packetType, diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 6b02d6db0a..bac018f2ae 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -48,7 +49,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra /// handles scripting of Entity commands from JS passed to assigned clients -class EntityScriptingInterface : public OctreeScriptingInterface { +class EntityScriptingInterface : public OctreeScriptingInterface, public Dependency { Q_OBJECT public: EntityScriptingInterface(); @@ -111,6 +112,8 @@ public slots: signals: void entityCollisionWithEntity(const EntityItemID& idA, const EntityItemID& idB, const Collision& collision); + void canAdjustLocksChanged(bool canAdjustLocks); + void mousePressOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); void mouseMoveOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); void mouseReleaseOnEntity(const EntityItemID& entityItemID, const MouseEvent& event); diff --git a/libraries/gpu/CMakeLists.txt b/libraries/gpu/CMakeLists.txt index 7b1d6e743a..4a23631dfb 100644 --- a/libraries/gpu/CMakeLists.txt +++ b/libraries/gpu/CMakeLists.txt @@ -1,5 +1,7 @@ set(TARGET_NAME gpu) +AUTOSCRIBE_SHADER_LIB(gpu) + # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index b15ee4fe29..ddbc76fce6 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -153,10 +153,10 @@ void Batch::setViewTransform(const Transform& view) { _params.push_back(_transforms.cache(view)); } -void Batch::setProjectionTransform(const Transform& proj) { +void Batch::setProjectionTransform(const Mat4& proj) { ADD_COMMAND(setProjectionTransform); - _params.push_back(_transforms.cache(proj)); + _params.push_back(cacheData(sizeof(Mat4), &proj)); } void Batch::setUniformBuffer(uint32 slot, const BufferPointer& buffer, Offset offset, Offset size) { diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 0657eacd6e..310cd9fe16 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -53,6 +53,11 @@ enum Primitive { NUM_PRIMITIVES, }; +enum ReservedSlot { + TRANSFORM_OBJECT_SLOT = 6, + TRANSFORM_CAMERA_SLOT = 7, +}; + class Batch { public: typedef Stream::Slot Slot; @@ -89,7 +94,7 @@ public: // with the ModelTransformu to create the equivalent of the glModelViewMatrix void setModelTransform(const Transform& model); void setViewTransform(const Transform& view); - void setProjectionTransform(const Transform& proj); + void setProjectionTransform(const Mat4& proj); // Shader Stage void setUniformBuffer(uint32 slot, const BufferPointer& buffer, Offset offset, Offset size); diff --git a/libraries/render-utils/src/Config.slh b/libraries/gpu/src/gpu/Config.slh old mode 100755 new mode 100644 similarity index 90% rename from libraries/render-utils/src/Config.slh rename to libraries/gpu/src/gpu/Config.slh index b431b671a6..b17bd7b2b8 --- a/libraries/render-utils/src/Config.slh +++ b/libraries/gpu/src/gpu/Config.slh @@ -8,8 +8,8 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html !> -<@if not CONFIG_SLH@> -<@def CONFIG_SLH@> +<@if not GPU_CONFIG_SLH@> +<@def GPU_CONFIG_SLH@> <@if GLPROFILE == PC_GL @> <@def VERSION_HEADER #version 330 compatibility@> diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 8140c91bf6..8955010f50 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -29,6 +29,21 @@ class Batch; class Backend { public: + class TransformObject { + public: + Mat4 _model; + Mat4 _modelInverse; + }; + + class TransformCamera { + public: + Mat4 _view; + Mat4 _viewInverse; + Mat4 _projectionViewUntranslated; + Mat4 _projection; + Vec4 _viewport; + }; + template< typename T > static void setGPUObject(const Buffer& buffer, T* bo) { buffer.setGPUObject(reinterpret_cast(bo)); diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 6274c294ec..cbf90384ce 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -11,6 +11,7 @@ #ifndef hifi_gpu_Format_h #define hifi_gpu_Format_h +#include #include namespace gpu { @@ -24,6 +25,12 @@ typedef char int8; typedef uint32 Offset; +typedef glm::mat4 Mat4; +typedef glm::mat3 Mat3; +typedef glm::vec4 Vec4; +typedef glm::vec3 Vec3; +typedef glm::vec2 Vec2; + // Description of a scalar type enum Type { diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 34ca47f300..0afc1b1204 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -73,28 +73,32 @@ GLBackend::GLBackend() : _input(), _transform() { - + initTransform(); } GLBackend::~GLBackend() { - + killTransform(); } -void GLBackend::renderBatch(Batch& batch) { +void GLBackend::render(Batch& batch) { + uint32 numCommands = batch.getCommands().size(); const Batch::Commands::value_type* command = batch.getCommands().data(); const Batch::CommandOffsets::value_type* offset = batch.getCommandOffsets().data(); - GLBackend backend; - for (unsigned int i = 0; i < numCommands; i++) { CommandCall call = _commandCalls[(*command)]; - (backend.*(call))(batch, *offset); + (this->*(call))(batch, *offset); command++; offset++; } } +void GLBackend::renderBatch(Batch& batch) { + GLBackend backend; + backend.render(batch); +} + void GLBackend::checkGLError() { GLenum error = glGetError(); if (!error) { @@ -386,18 +390,93 @@ void GLBackend::do_setViewTransform(Batch& batch, uint32 paramOffset) { } void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) { - _transform._projection = batch._transforms.get(batch._params[paramOffset]._uint); + memcpy(&_transform._projection, batch.editData(batch._params[paramOffset]._uint), sizeof(Mat4)); _transform._invalidProj = true; } +void GLBackend::initTransform() { +#if defined(Q_OS_WIN) + glGenBuffers(1, &_transform._transformObjectBuffer); + glGenBuffers(1, &_transform._transformCameraBuffer); + + glBindBuffer(GL_UNIFORM_BUFFER, _transform._transformObjectBuffer); + glBufferData(GL_UNIFORM_BUFFER, sizeof(_transform._transformObject), (const void*) &_transform._transformObject, GL_DYNAMIC_DRAW); + + glBindBuffer(GL_UNIFORM_BUFFER, _transform._transformCameraBuffer); + glBufferData(GL_UNIFORM_BUFFER, sizeof(_transform._transformCamera), (const void*) &_transform._transformCamera, GL_DYNAMIC_DRAW); + + + glBindBuffer(GL_UNIFORM_BUFFER, 0); +#else +#endif +} + +void GLBackend::killTransform() { +#if defined(Q_OS_WIN) + glDeleteBuffers(1, &_transform._transformObjectBuffer); + glDeleteBuffers(1, &_transform._transformCameraBuffer); +#else +#endif +} void GLBackend::updateTransform() { + // Check all the dirty flags and update the state accordingly if (_transform._invalidProj) { - // TODO: implement the projection matrix assignment to gl state - /* if (_transform._lastMode != GL_PROJECTION) { + _transform._transformCamera._projection = _transform._projection; + } + + if (_transform._invalidView) { + _transform._view.getInverseMatrix(_transform._transformCamera._view); + _transform._view.getMatrix(_transform._transformCamera._viewInverse); + } + + if (_transform._invalidModel) { + _transform._model.getMatrix(_transform._transformObject._model); + _transform._model.getInverseMatrix(_transform._transformObject._modelInverse); + } + + if (_transform._invalidView || _transform._invalidProj) { + Mat4 viewUntranslated = _transform._transformCamera._view; + viewUntranslated[3] = Vec4(0.0f, 0.0f, 0.0f, 1.0f); + _transform._transformCamera._projectionViewUntranslated = _transform._transformCamera._projection * viewUntranslated; + } + + if (_transform._invalidView || _transform._invalidProj) { +#if defined(Q_OS_WIN) + glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_CAMERA_SLOT, 0); + glBindBuffer(GL_ARRAY_BUFFER, _transform._transformCameraBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(_transform._transformCamera), (const void*) &_transform._transformCamera, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + CHECK_GL_ERROR(); +#endif + } + + if (_transform._invalidModel) { +#if defined(Q_OS_WIN) + glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_OBJECT_SLOT, 0); + glBindBuffer(GL_ARRAY_BUFFER, _transform._transformObjectBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(_transform._transformObject), (const void*) &_transform._transformObject, GL_DYNAMIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + CHECK_GL_ERROR(); +#endif + } + +#if defined(Q_OS_WIN) + glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_OBJECT_SLOT, _transform._transformObjectBuffer); + glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_CAMERA_SLOT, _transform._transformCameraBuffer); + CHECK_GL_ERROR(); +#endif + + +#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) + // Do it again for fixed pipeline until we can get rid of it + if (_transform._invalidProj) { + if (_transform._lastMode != GL_PROJECTION) { glMatrixMode(GL_PROJECTION); _transform._lastMode = GL_PROJECTION; } - CHECK_GL_ERROR();*/ + glLoadMatrixf(reinterpret_cast< const GLfloat* >(&_transform._projection)); + + CHECK_GL_ERROR(); } if (_transform._invalidModel || _transform._invalidView) { @@ -430,10 +509,11 @@ void GLBackend::updateTransform() { } } CHECK_GL_ERROR(); - - _transform._invalidModel = false; - _transform._invalidView = false; } +#endif + + // Flags are clean + _transform._invalidView = _transform._invalidProj = _transform._invalidModel = false; } void GLBackend::do_setUniformBuffer(Batch& batch, uint32 paramOffset) { diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 806ba0b1eb..49d139d727 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -27,10 +27,13 @@ public: GLBackend(); ~GLBackend(); + void render(Batch& batch); + static void renderBatch(Batch& batch); static void checkGLError(); + class GLBuffer : public GPUObject { public: @@ -113,11 +116,17 @@ protected: void do_setViewTransform(Batch& batch, uint32 paramOffset); void do_setProjectionTransform(Batch& batch, uint32 paramOffset); + void initTransform(); + void killTransform(); void updateTransform(); struct TransformStageState { + TransformObject _transformObject; + TransformCamera _transformCamera; + GLuint _transformObjectBuffer; + GLuint _transformCameraBuffer; Transform _model; Transform _view; - Transform _projection; + Mat4 _projection; bool _invalidModel; bool _invalidView; bool _invalidProj; @@ -125,12 +134,14 @@ protected: GLenum _lastMode; TransformStageState() : + _transformObjectBuffer(0), + _transformCameraBuffer(0), _model(), _view(), _projection(), _invalidModel(true), _invalidView(true), - _invalidProj(true), + _invalidProj(false), _lastMode(GL_TEXTURE) {} } _transform; diff --git a/libraries/gpu/src/gpu/GLBackendShared.h b/libraries/gpu/src/gpu/GLBackendShared.h index f0f691f708..1853573522 100644 --- a/libraries/gpu/src/gpu/GLBackendShared.h +++ b/libraries/gpu/src/gpu/GLBackendShared.h @@ -49,7 +49,7 @@ static const GLenum _elementTypeToGLType[NUM_TYPES]= { GL_UNSIGNED_BYTE }; -//#define CHECK_GL_ERROR() ::gpu::GLBackend::checkGLError() -#define CHECK_GL_ERROR() +#define CHECK_GL_ERROR() ::gpu::GLBackend::checkGLError() +//#define CHECK_GL_ERROR() #endif diff --git a/libraries/gpu/src/gpu/Transform.slh b/libraries/gpu/src/gpu/Transform.slh new file mode 100644 index 0000000000..9578177826 --- /dev/null +++ b/libraries/gpu/src/gpu/Transform.slh @@ -0,0 +1,95 @@ + +<@if not GPU_TRANSFORM_STATE_SLH@> +<@def GPU_TRANSFORM_STATE_SLH@> + +struct TransformObject { + mat4 _model; + mat4 _modelInverse; +}; + +struct TransformCamera { + mat4 _view; + mat4 _viewInverse; + mat4 _projectionViewUntranslated; + mat4 _projection; + vec4 _viewport; +}; + +vec4 transformModelToClipPos(TransformCamera camera, TransformObject object, vec4 pos) { +<@if GLPROFILE == MAC_GL@> + return gl_ModelViewProjectionMatrix * pos; +<@elif GLPROFILE == PC_GL@> + vec4 epos = (object._model * pos) + vec4(-pos.w * camera._viewInverse[3].xyz, 0.0); + return camera._projectionViewUntranslated * epos; + // Equivalent to the following but hoppefully a bit more accurate + // return camera._projection * camera._view * object._model * pos; + +<@endif@> +} + +vec3 transformModelToEyeDir(TransformCamera camera, TransformObject object, vec3 dir) { +<@if GLPROFILE == MAC_GL@> + return gl_NormalMatrix * dir; +<@elif GLPROFILE == PC_GL@> + vec3 mr0 = vec3(object._modelInverse[0].x, object._modelInverse[1].x, object._modelInverse[2].x); + vec3 mr1 = vec3(object._modelInverse[0].y, object._modelInverse[1].y, object._modelInverse[2].y); + vec3 mr2 = vec3(object._modelInverse[0].z, object._modelInverse[1].z, object._modelInverse[2].z); + + vec3 mvc0 = vec3(dot(camera._viewInverse[0].xyz, mr0), dot(camera._viewInverse[0].xyz, mr1), dot(camera._viewInverse[0].xyz, mr2)); + vec3 mvc1 = vec3(dot(camera._viewInverse[1].xyz, mr0), dot(camera._viewInverse[1].xyz, mr1), dot(camera._viewInverse[1].xyz, mr2)); + vec3 mvc2 = vec3(dot(camera._viewInverse[2].xyz, mr0), dot(camera._viewInverse[2].xyz, mr1), dot(camera._viewInverse[2].xyz, mr2)); + + vec3 result = vec3(dot(mvc0, dir), dot(mvc1, dir), dot(mvc2, dir)); + + return result; +<@endif@> +} + +<@if GLPROFILE == PC_GL@> +uniform transformObjectBuffer { + TransformObject object; +}; +TransformObject getTransformObject() { + return object; +} + +uniform transformCameraBuffer { + TransformCamera camera; +}; +TransformCamera getTransformCamera() { + return camera; +} +<@elif GLPROFILE == MAC_GL@> +TransformObject getTransformObject() { + TransformObject object; + return object; +} + +TransformCamera getTransformCamera() { + TransformCamera camera; + return camera; +} +<@else@> + +TransformObject getTransformObject() { + TransformObject object; + return object; +} + +TransformCamera getTransformCamera() { + TransformCamera camera; + return camera; +} + +<@endif@> + + +<@endif@> diff --git a/libraries/model/CMakeLists.txt b/libraries/model/CMakeLists.txt index c62b29599f..278c40c435 100755 --- a/libraries/model/CMakeLists.txt +++ b/libraries/model/CMakeLists.txt @@ -1,4 +1,6 @@ set(TARGET_NAME model) + +AUTOSCRIBE_SHADER_LIB(gpu) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library() diff --git a/libraries/render-utils/src/Light.slh b/libraries/model/src/model/Light.slh old mode 100755 new mode 100644 similarity index 93% rename from libraries/render-utils/src/Light.slh rename to libraries/model/src/model/Light.slh index abb9fb6c2a..fc17e94050 --- a/libraries/render-utils/src/Light.slh +++ b/libraries/model/src/model/Light.slh @@ -8,8 +8,8 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html !> -<@if not LIGHT_SLH@> -<@def LIGHT_SLH@> +<@if not MODEL_LIGHT_SLH@> +<@def MODEL_LIGHT_SLH@> struct Light { vec4 _position; diff --git a/libraries/render-utils/src/Material.slh b/libraries/model/src/model/Material.slh old mode 100755 new mode 100644 similarity index 88% rename from libraries/render-utils/src/Material.slh rename to libraries/model/src/model/Material.slh index 86c6049ec6..9ea269f214 --- a/libraries/render-utils/src/Material.slh +++ b/libraries/model/src/model/Material.slh @@ -8,8 +8,8 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html !> -<@if not MATERIAL_SLH@> -<@def MATERIAL_SLH@> +<@if not MODEL_MATERIAL_SLH@> +<@def MODEL_MATERIAL_SLH@> struct Material { vec4 _diffuse; @@ -26,10 +26,10 @@ float getMaterialShininess(Material m) { return m._specular.a; } <@if GLPROFILE == PC_GL@> uniform materialBuffer { - Material mat; + Material _mat; }; Material getMaterial() { - return mat; + return _mat; } <@elif GLPROFILE == MAC_GL@> uniform vec4 materialBuffer[2]; diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index faa90b79bf..cf5b2eef27 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -96,6 +96,13 @@ void LimitedNodeList::setSessionUUID(const QUuid& sessionUUID) { } } +void LimitedNodeList::setThisNodeCanAdjustLocks(bool canAdjustLocks) { + if (_thisNodeCanAdjustLocks != canAdjustLocks) { + _thisNodeCanAdjustLocks = canAdjustLocks; + emit canAdjustLocksChanged(canAdjustLocks); + } +} + QUdpSocket& LimitedNodeList::getDTLSSocket() { if (!_dtlsSocket) { // DTLS socket getter called but no DTLS socket exists, create it now diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index 1c395f1c7f..85db739cda 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -84,8 +84,8 @@ public: const QUuid& getSessionUUID() const { return _sessionUUID; } void setSessionUUID(const QUuid& sessionUUID); - bool getThisNodeCanAdjustLocks() { return _thisNodeCanAdjustLocks; } - void setThisNodeCanAdjustLocks(bool canAdjustLocks) { _thisNodeCanAdjustLocks = canAdjustLocks; } + bool getThisNodeCanAdjustLocks() const { return _thisNodeCanAdjustLocks; } + void setThisNodeCanAdjustLocks(bool canAdjustLocks); void rebindNodeSocket(); QUdpSocket& getNodeSocket() { return _nodeSocket; } @@ -196,6 +196,8 @@ signals: void localSockAddrChanged(const HifiSockAddr& localSockAddr); void publicSockAddrChanged(const HifiSockAddr& publicSockAddr); + void canAdjustLocksChanged(bool canAdjustLocks); + void dataSent(const quint8 channel_type, const int bytes); void dataReceived(const quint8 channel_type, const int bytes); diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index 81ce31d767..fac017218d 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -577,6 +577,10 @@ void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom // compute our dimensions the usual way float hheight = _nearClip * tanf(_fieldOfView * 0.5f * RADIANS_PER_DEGREE); float hwidth = _aspectRatio * hheight; + if (isOrthographic()) { + hheight = getHeight(); + hwidth = getWidth(); + } // get our frustum corners in view space glm::mat4 eyeMatrix = glm::mat4_cast(glm::inverse(_eyeOffsetOrientation)) * glm::translate(-_eyeOffsetPosition); @@ -866,4 +870,20 @@ float ViewFrustum::distanceToCamera(const glm::vec3& point) const { return distanceToPoint; } +void ViewFrustum::evalProjectionMatrix(glm::mat4& proj) const { + if (isOrthographic()) { + glm::vec3 frustumCenter = glm::inverse( _orientation) * _position; + + proj = glm::ortho(frustumCenter.x -0.5f * getWidth(), + frustumCenter.x +0.5f * getWidth(), + frustumCenter.y -0.5f * getHeight(), + frustumCenter.y +0.5f * getHeight(), + -getFarClip(), -getNearClip()); + } else { + float left, right, bottom, top, near, far; + glm::vec4 clip0, clip1; + computeOffAxisFrustum(left, right, bottom, top, near, far, clip0, clip1); + proj = glm::perspective(glm::radians(getFieldOfView()), getAspectRatio(), getNearClip(), getFarClip()); + } +} diff --git a/libraries/octree/src/ViewFrustum.h b/libraries/octree/src/ViewFrustum.h index c40bc37652..a74140b94f 100644 --- a/libraries/octree/src/ViewFrustum.h +++ b/libraries/octree/src/ViewFrustum.h @@ -124,6 +124,7 @@ public: float distanceToCamera(const glm::vec3& point) const; + void evalProjectionMatrix(glm::mat4& proj) const; private: // Used for keyhole calculations ViewFrustum::location pointInKeyhole(const glm::vec3& point) const; diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 5737d8e4c1..caabff44cf 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET_NAME render-utils) -AUTOSCRIBE_SHADER_LIB() +AUTOSCRIBE_SHADER_LIB(gpu model) # pull in the resources.qrc file qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts.qrc") diff --git a/libraries/render-utils/src/AbstractViewStateInterface.h b/libraries/render-utils/src/AbstractViewStateInterface.h index 50a75c769a..0d73614e7c 100644 --- a/libraries/render-utils/src/AbstractViewStateInterface.h +++ b/libraries/render-utils/src/AbstractViewStateInterface.h @@ -32,6 +32,9 @@ public: /// gets the current view frustum for rendering the view state virtual ViewFrustum* getCurrentViewFrustum() = 0; + + /// gets the shadow view frustum for rendering the view state + virtual ViewFrustum* getShadowViewFrustum() = 0; virtual bool getShadowsEnabled() = 0; virtual bool getCascadeShadowsEnabled() = 0; diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 0fe2d18e74..3039c92d67 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -49,7 +49,7 @@ vec4 evalSphericalLight(SphericalHarmonics sh, vec3 direction ) { uniform SphericalHarmonics ambientSphere; // Everything about light -<@include Light.slh@> +<@include model/Light.slh@> // The view Matrix uniform mat4 invViewMat; @@ -95,13 +95,15 @@ vec3 evalAmbienSphereGlobalColor(float shadowAttenuation, vec3 position, vec3 no vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) { Light light = getLight(); + vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0)); float diffuseDot = dot(fragNormal, -getLightDirection(light)); - + // need to catch normals perpendicular to the projection plane hence the magic number for the threshold // it should be just 0, but we have innacurracy so we need to overshoot const float PERPENDICULAR_THRESHOLD = -0.005; float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); + //float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); // evaluate the shadow test but only relevant for light facing fragments float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index dffadc730f..317b3bd6b9 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -53,18 +53,33 @@ const int NUM_COORDS_PER_VERTEX = 3; const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat); const int NUM_BYTES_PER_INDEX = sizeof(GLushort); -void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) { +void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) { + bool registered = (id != UNKNOWN_ID); Vec2Pair radiusKey(glm::vec2(radius, slices), glm::vec2(stacks, 0)); IntPair slicesStacksKey(slices, stacks); - Vec3Pair colorKey(glm::vec3(color.x, color.y, slices), glm::vec3(color.z, color.y, stacks)); + Vec3Pair colorKey(glm::vec3(color.x, color.y, slices), glm::vec3(color.z, color.w, stacks)); int vertices = slices * (stacks - 1) + 2; int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD; - if (!_sphereVertices.contains(radiusKey)) { + if (registered && (!_registeredSphereVertices.contains(id) || _lastRegisteredSphereVertices[id] != radiusKey) + || !registered && !_sphereVertices.contains(radiusKey)) { + + if (registered && _registeredSphereVertices.contains(id)) { + _registeredSphereVertices[id].clear(); + #ifdef WANT_DEBUG + qDebug() << "renderSphere()... RELEASING REGISTERED VERTICES BUFFER"; + #endif + } + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); - _sphereVertices[radiusKey] = verticesBuffer; + if (registered) { + _registeredSphereVertices[id] = verticesBuffer; + _lastRegisteredSphereVertices[id] = radiusKey; + } else { + _sphereVertices[radiusKey] = verticesBuffer; + } GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX]; GLfloat* vertex = vertexData; @@ -106,10 +121,29 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); #endif } + #ifdef WANT_DEBUG + else if (registered) { + qDebug() << "renderSphere()... REUSING PREVIOUSLY REGISTERED VERTICES BUFFER"; + } + #endif - if (!_sphereIndices.contains(slicesStacksKey)) { + if (registered && (!_registeredSphereIndices.contains(id) || _lastRegisteredSphereIndices[id] != slicesStacksKey) + || !registered && !_sphereIndices.contains(slicesStacksKey)) { + + if (registered && _registeredSphereIndices.contains(id)) { + _registeredSphereIndices[id].clear(); + #ifdef WANT_DEBUG + qDebug() << "renderSphere()... RELEASING REGISTERED INDICES BUFFER"; + #endif + } + gpu::BufferPointer indicesBuffer(new gpu::Buffer()); - _sphereIndices[slicesStacksKey] = indicesBuffer; + if (registered) { + _registeredSphereIndices[id] = indicesBuffer; + _lastRegisteredSphereIndices[id] = slicesStacksKey; + } else { + _sphereIndices[slicesStacksKey] = indicesBuffer; + } GLushort* indexData = new GLushort[indices]; GLushort* index = indexData; @@ -164,7 +198,7 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm delete[] indexData; #ifdef WANT_DEBUG - qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER"; + qDebug() << "GeometryCache::renderSphere()... --- CREATING INDICES BUFFER"; qDebug() << " radius:" << radius; qDebug() << " slices:" << slices; qDebug() << " stacks:" << stacks; @@ -173,10 +207,29 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); #endif } + #ifdef WANT_DEBUG + else if (registered) { + qDebug() << "renderSphere()... REUSING PREVIOUSLY REGISTERED INDICES BUFFER"; + } + #endif + + if (registered && (!_registeredSphereColors.contains(id) || _lastRegisteredSphereColors[id] != colorKey) + || !registered && !_sphereColors.contains(colorKey)) { + + if (registered && _registeredSphereColors.contains(id)) { + _registeredSphereColors[id].clear(); + #ifdef WANT_DEBUG + qDebug() << "renderSphere()... RELEASING REGISTERED COLORS BUFFER"; + #endif + } - if (!_sphereColors.contains(colorKey)) { gpu::BufferPointer colorBuffer(new gpu::Buffer()); - _sphereColors[colorKey] = colorBuffer; + if (registered) { + _registeredSphereColors[id] = colorBuffer; + _lastRegisteredSphereColors[id] = colorKey; + } else { + _sphereColors[colorKey] = colorBuffer; + } int compactColor = ((int(color.x * 255.0f) & 0xFF)) | ((int(color.y * 255.0f) & 0xFF) << 8) | @@ -201,11 +254,16 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm qDebug() << " stacks:" << stacks; qDebug() << " _sphereColors.size():" << _sphereColors.size(); #endif - } - gpu::BufferPointer verticesBuffer = _sphereVertices[radiusKey]; - gpu::BufferPointer indicesBuffer = _sphereIndices[slicesStacksKey]; - gpu::BufferPointer colorBuffer = _sphereColors[colorKey]; + #ifdef WANT_DEBUG + else if (registered) { + qDebug() << "renderSphere()... REUSING PREVIOUSLY REGISTERED COLORS BUFFER"; + } + #endif + + gpu::BufferPointer verticesBuffer = registered ? _registeredSphereVertices[id] : _sphereVertices[radiusKey]; + gpu::BufferPointer indicesBuffer = registered ? _registeredSphereIndices[id] : _sphereIndices[slicesStacksKey]; + gpu::BufferPointer colorBuffer = registered ? _registeredSphereColors[id] : _sphereColors[colorKey]; const int VERTICES_SLOT = 0; const int NORMALS_SLOT = 1; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 864c5ff24c..92b6d44b6c 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -134,10 +134,10 @@ public: void renderCone(float base, float height, int slices, int stacks); - void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true) - { renderSphere(radius, slices, stacks, glm::vec4(color, 1.0f), solid); } + void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true, int id = UNKNOWN_ID) + { renderSphere(radius, slices, stacks, glm::vec4(color, 1.0f), solid, id); } - void renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid = true); + void renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid = true, int id = UNKNOWN_ID); void renderGrid(int xDivisions, int yDivisions, const glm::vec4& color); void renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id = UNKNOWN_ID); void renderSolidCube(float size, const glm::vec4& color); @@ -290,10 +290,15 @@ private: QHash _gridColors; QHash _sphereVertices; + QHash _registeredSphereVertices; + QHash _lastRegisteredSphereVertices; QHash _sphereIndices; + QHash _registeredSphereIndices; + QHash _lastRegisteredSphereIndices; QHash _sphereColors; - - + QHash _registeredSphereColors; + QHash _lastRegisteredSphereColors; + QHash > _networkGeometry; }; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index f166aecae9..bbb4dfe8cf 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -223,6 +223,23 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, boo } #endif +#if defined(Q_OS_WIN) + loc = glGetUniformBlockIndex(program.programId(), "transformObjectBuffer"); + if (loc >= 0) { + glUniformBlockBinding(program.programId(), loc, gpu::TRANSFORM_OBJECT_SLOT); + // locations.materialBufferUnit = 1; + } +#endif + +#if defined(Q_OS_WIN) + loc = glGetUniformBlockIndex(program.programId(), "transformCameraBuffer"); + if (loc >= 0) { + glUniformBlockBinding(program.programId(), loc, gpu::TRANSFORM_CAMERA_SLOT); + // locations.materialBufferUnit = 1; + } +#endif + + //program.link(); if (!program.isLinked()) { program.release(); } @@ -323,6 +340,9 @@ void Model::init() { _shadowProgram.addShaderFromSourceCode(QGLShader::Vertex, model_shadow_vert); _shadowProgram.addShaderFromSourceCode(QGLShader::Fragment, model_shadow_frag); + // Shadow program uses the same locations as standard rendering path but we still need to set the bindings + Model::Locations tempLoc; + initProgram(_shadowProgram, tempLoc); _skinProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_vert); _skinProgram.addShaderFromSourceCode(QGLShader::Fragment, model_frag); @@ -667,7 +687,7 @@ bool Model::render(float alpha, RenderMode mode, RenderArgs* args) { // render the attachments foreach (Model* attachment, _attachments) { - attachment->render(alpha, mode); + attachment->render(alpha, mode, args); } if (_meshStates.isEmpty()) { return false; @@ -687,6 +707,13 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) { _renderBatch.clear(); gpu::Batch& batch = _renderBatch; + // Setup the projection matrix + if (args && args->_viewFrustum) { + glm::mat4 proj; + args->_viewFrustum->evalProjectionMatrix(proj); + batch.setProjectionTransform(proj); + } + // Capture the view matrix once for the rendering of this model if (_transforms.empty()) { _transforms.push_back(Transform()); @@ -1659,11 +1686,26 @@ void Model::setupBatchTransform(gpu::Batch& batch) { void Model::endScene(RenderMode mode, RenderArgs* args) { PROFILE_RANGE(__FUNCTION__); + #if defined(ANDROID) + #else + glPushMatrix(); + #endif + RenderArgs::RenderSide renderSide = RenderArgs::MONO; if (args) { renderSide = args->_renderSide; } + gpu::GLBackend backend; + + if (args) { + glm::mat4 proj; + args->_viewFrustum->evalProjectionMatrix(proj); + gpu::Batch batch; + batch.setProjectionTransform(proj); + backend.render(batch); + } + // Do the rendering batch creation for mono or left eye, not for right eye if (renderSide != RenderArgs::STEREO_RIGHT) { // Let's introduce a gpu::Batch to capture all the calls to the graphics api @@ -1818,19 +1860,15 @@ void Model::endScene(RenderMode mode, RenderArgs* args) { // Render! { PROFILE_RANGE("render Batch"); - #if defined(ANDROID) - #else - glPushMatrix(); - #endif - - ::gpu::GLBackend::renderBatch(_sceneRenderBatch); - - #if defined(ANDROID) - #else - glPopMatrix(); - #endif + backend.render(_sceneRenderBatch); } + + #if defined(ANDROID) + #else + glPopMatrix(); + #endif + // restore all the default material settings _viewState->setupWorldLight(); diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index ef96f0e05f..303fa770ad 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -269,6 +269,9 @@ protected: /// first free ancestor. float getLimbLength(int jointIndex) const; + /// Allow sub classes to force invalidating the bboxes + void invalidCalculatedMeshBoxes() { _calculatedMeshBoxesValid = false; } + private: friend class AnimationHandle; diff --git a/libraries/render-utils/src/Shadow.slh b/libraries/render-utils/src/Shadow.slh index a8d0ce457a..d4c19915ff 100755 --- a/libraries/render-utils/src/Shadow.slh +++ b/libraries/render-utils/src/Shadow.slh @@ -31,6 +31,8 @@ uniform vec3 shadowDistances; // the inverse of the size of the shadow map uniform float shadowScale; +uniform mat4 shadowMatrices[4]; + vec2 samples[8] = vec2[8]( vec2(-2.0, -2.0), vec2(2.0, -2.0), diff --git a/libraries/render-utils/src/deferred_light.slv b/libraries/render-utils/src/deferred_light.slv index f26539fe69..1427dd0f52 100644 --- a/libraries/render-utils/src/deferred_light.slv +++ b/libraries/render-utils/src/deferred_light.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/deferred_light_limited.slv b/libraries/render-utils/src/deferred_light_limited.slv index fdfb88d806..e3051d43f7 100644 --- a/libraries/render-utils/src/deferred_light_limited.slv +++ b/libraries/render-utils/src/deferred_light_limited.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 308a8a73a7..114c5615b8 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf index db017cf5ac..d52363a26b 100755 --- a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf +++ b/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_shadow_map.slf index 43d3e91dbe..7f098eac2e 100755 --- a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/directional_light.slf b/libraries/render-utils/src/directional_light.slf index 3e708f849e..0299b2a229 100644 --- a/libraries/render-utils/src/directional_light.slf +++ b/libraries/render-utils/src/directional_light.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf index 90b3bf1d2b..71464fb916 100644 --- a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf +++ b/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/directional_light_shadow_map.slf b/libraries/render-utils/src/directional_light_shadow_map.slf index 5029b57020..2c53a02348 100644 --- a/libraries/render-utils/src/directional_light_shadow_map.slf +++ b/libraries/render-utils/src/directional_light_shadow_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/model.slf b/libraries/render-utils/src/model.slf index bc6f127a77..be465ed908 100755 --- a/libraries/render-utils/src/model.slf +++ b/libraries/render-utils/src/model.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // model.frag @@ -13,7 +13,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index 1c3b03a304..4f416e8f1f 100755 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // model.vert @@ -11,6 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> const int MAX_TEXCOORDS = 2; uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; @@ -19,16 +20,19 @@ uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; varying vec4 normal; void main(void) { - // transform and store the normal for interpolation - normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); // pass along the diffuse color gl_FrontColor = gl_Color; // and the texture coordinates gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - - // use standard pipeline transform - gl_Position = ftransform(); -} + // use standard pipeline transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, gl_Vertex); + + // transform and store the normal for interpolation + normal = vec4(normalize(transformModelToEyeDir(cam, obj, gl_Normal)), 0.0); + +} diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf index 59836e9737..9db31bf1ad 100755 --- a/libraries/render-utils/src/model_lightmap.slf +++ b/libraries/render-utils/src/model_lightmap.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model_lightmap.slv b/libraries/render-utils/src/model_lightmap.slv index 1ea5b7b68a..afe3c73549 100755 --- a/libraries/render-utils/src/model_lightmap.slv +++ b/libraries/render-utils/src/model_lightmap.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> + const int MAX_TEXCOORDS = 2; uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; @@ -25,9 +27,6 @@ varying vec4 normal; varying vec2 interpolatedTexcoord1; void main(void) { - // transform and store the normal for interpolation - normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); - // pass along the diffuse color gl_FrontColor = gl_Color; @@ -35,8 +34,13 @@ void main(void) { gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); // interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0)).xy; interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy; - + // use standard pipeline transform - gl_Position = ftransform(); + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, gl_Vertex); + + // transform and store the normal for interpolation + normal = vec4(normalize(transformModelToEyeDir(cam, obj, gl_Normal)), 0.0); } diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf index 6310ab0086..a7b6494ee5 100755 --- a/libraries/render-utils/src/model_lightmap_normal_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slv b/libraries/render-utils/src/model_lightmap_normal_map.slv index 14e1d52779..6e66b28e63 100755 --- a/libraries/render-utils/src/model_lightmap_normal_map.slv +++ b/libraries/render-utils/src/model_lightmap_normal_map.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> + const int MAX_TEXCOORDS = 2; uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; @@ -32,8 +34,8 @@ varying vec2 interpolatedTexcoord1; void main(void) { // transform and store the normal and tangent for interpolation - interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); - interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); + //interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); + //interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); // pass along the diffuse color gl_FrontColor = gl_Color; @@ -43,5 +45,11 @@ void main(void) { interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy; // use standard pipeline transform - gl_Position = ftransform(); + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, gl_Vertex); + + // transform and store the normal for interpolation + interpolatedNormal = vec4(normalize(transformModelToEyeDir(cam, obj, gl_Normal)), 0.0); + interpolatedTangent = vec4(normalize(transformModelToEyeDir(cam, obj, tangent)), 0.0); } diff --git a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf index ab555ea0c0..e5daae4160 100755 --- a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model_lightmap_specular_map.slf b/libraries/render-utils/src/model_lightmap_specular_map.slf index 2973882e8a..820ded5cad 100755 --- a/libraries/render-utils/src/model_lightmap_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_specular_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf index c6baa6f797..5ad0bfb50d 100755 --- a/libraries/render-utils/src/model_normal_map.slf +++ b/libraries/render-utils/src/model_normal_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv index a27cd49171..4111458464 100755 --- a/libraries/render-utils/src/model_normal_map.slv +++ b/libraries/render-utils/src/model_normal_map.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> + const int MAX_TEXCOORDS = 2; uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; @@ -27,8 +29,8 @@ varying vec4 interpolatedTangent; void main(void) { // transform and store the normal and tangent for interpolation - interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); - interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); + //interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); + //interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); // pass along the diffuse color gl_FrontColor = gl_Color; @@ -36,6 +38,12 @@ void main(void) { // and the texture coordinates gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - // use standard pipeline transform - gl_Position = ftransform(); + // use standard pipeline transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, gl_Vertex); + + // transform and store the normal for interpolation + interpolatedNormal = vec4(normalize(transformModelToEyeDir(cam, obj, gl_Normal)), 0.0); + interpolatedTangent = vec4(normalize(transformModelToEyeDir(cam, obj, tangent)), 0.0); } diff --git a/libraries/render-utils/src/model_normal_specular_map.slf b/libraries/render-utils/src/model_normal_specular_map.slf index 8e7c9d3293..5c272d0c6b 100755 --- a/libraries/render-utils/src/model_normal_specular_map.slf +++ b/libraries/render-utils/src/model_normal_specular_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model_shadow.slf b/libraries/render-utils/src/model_shadow.slf index 1fbb44140b..e8bdb01f30 100755 --- a/libraries/render-utils/src/model_shadow.slf +++ b/libraries/render-utils/src/model_shadow.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/model_shadow.slv b/libraries/render-utils/src/model_shadow.slv index 6ff8c23f5a..98f6bf5104 100755 --- a/libraries/render-utils/src/model_shadow.slv +++ b/libraries/render-utils/src/model_shadow.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -11,8 +11,11 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> void main(void) { - // just use standard pipeline transform - gl_Position = ftransform(); + // use standard pipeline transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, gl_Vertex); } diff --git a/libraries/render-utils/src/model_specular_map.slf b/libraries/render-utils/src/model_specular_map.slf index bfcc69287d..e50d2c452d 100755 --- a/libraries/render-utils/src/model_specular_map.slf +++ b/libraries/render-utils/src/model_specular_map.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf index 4d1bf7bdec..91592e07de 100755 --- a/libraries/render-utils/src/model_translucent.slf +++ b/libraries/render-utils/src/model_translucent.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -14,7 +14,7 @@ <@include DeferredBufferWrite.slh@> -<@include Material.slh@> +<@include model/Material.slh@> // the diffuse texture uniform sampler2D diffuseMap; diff --git a/libraries/render-utils/src/point_light.slf b/libraries/render-utils/src/point_light.slf index abe904ecce..78d3d1e458 100644 --- a/libraries/render-utils/src/point_light.slf +++ b/libraries/render-utils/src/point_light.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -19,7 +19,7 @@ <@include DeferredLighting.slh@> // Everything about light -<@include Light.slh@> +<@include model/Light.slh@> // The view Matrix uniform mat4 invViewMat; diff --git a/libraries/render-utils/src/sdf_text.slf b/libraries/render-utils/src/sdf_text.slf index 0e89ce4f47..1affbe4c57 100644 --- a/libraries/render-utils/src/sdf_text.slf +++ b/libraries/render-utils/src/sdf_text.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // sdf_text.frag diff --git a/libraries/render-utils/src/sdf_text.slv b/libraries/render-utils/src/sdf_text.slv index 7fb6dd42e8..27db1c4985 100644 --- a/libraries/render-utils/src/sdf_text.slv +++ b/libraries/render-utils/src/sdf_text.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // sdf_text.vert diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index faa4af4573..3e70674e33 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/simple.slv b/libraries/render-utils/src/simple.slv index e874a6d8a9..61338b440d 100644 --- a/libraries/render-utils/src/simple.slv +++ b/libraries/render-utils/src/simple.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // diff --git a/libraries/render-utils/src/skin_model.slv b/libraries/render-utils/src/skin_model.slv index 4cef8fddab..780b72323c 100755 --- a/libraries/render-utils/src/skin_model.slv +++ b/libraries/render-utils/src/skin_model.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> + const int MAX_TEXCOORDS = 2; const int MAX_CLUSTERS = 128; const int INDICES_PER_VERTEX = 4; @@ -34,14 +36,18 @@ void main(void) { position += clusterMatrix * gl_Vertex * clusterWeight; normal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; } - - normal = normalize(gl_ModelViewMatrix * normal); - + // pass along the diffuse color gl_FrontColor = gl_Color; // and the texture coordinates gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - gl_Position = gl_ModelViewProjectionMatrix * position; + // use standard pipeline transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, position); + + // transform and store the normal for interpolation + normal = vec4(normalize(transformModelToEyeDir(cam, obj, normal.xyz)), 0.0); } diff --git a/libraries/render-utils/src/skin_model_normal_map.slv b/libraries/render-utils/src/skin_model_normal_map.slv index c39f9cc0dd..43ec9c6a9d 100755 --- a/libraries/render-utils/src/skin_model_normal_map.slv +++ b/libraries/render-utils/src/skin_model_normal_map.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> + const int MAX_TEXCOORDS = 2; const int MAX_CLUSTERS = 128; const int INDICES_PER_VERTEX = 4; @@ -42,8 +44,8 @@ void main(void) { interpolatedNormal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; interpolatedTangent += clusterMatrix * vec4(tangent, 0.0) * clusterWeight; } - interpolatedNormal = gl_ModelViewMatrix * interpolatedNormal; - interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent; + // interpolatedNormal = gl_ModelViewMatrix * interpolatedNormal; + // interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent; // pass along the diffuse color gl_FrontColor = gl_Color; @@ -52,4 +54,12 @@ void main(void) { gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); gl_Position = gl_ModelViewProjectionMatrix * interpolatedPosition; + + // use standard pipeline transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, interpolatedPosition); + + interpolatedNormal = vec4(normalize(transformModelToEyeDir(cam, obj, interpolatedNormal.xyz)), 0.0); + interpolatedTangent = vec4(normalize(transformModelToEyeDir(cam, obj, interpolatedTangent.xyz)), 0.0); } diff --git a/libraries/render-utils/src/skin_model_shadow.slv b/libraries/render-utils/src/skin_model_shadow.slv index 9a594ac26c..de7f8f4e9f 100755 --- a/libraries/render-utils/src/skin_model_shadow.slv +++ b/libraries/render-utils/src/skin_model_shadow.slv @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -12,6 +12,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Transform.slh@> + const int MAX_CLUSTERS = 128; const int INDICES_PER_VERTEX = 4; @@ -27,5 +29,9 @@ void main(void) { float clusterWeight = clusterWeights[i]; position += clusterMatrix * gl_Vertex * clusterWeight; } - gl_Position = gl_ModelViewProjectionMatrix * position; + + // use standard pipeline transform + TransformCamera cam = getTransformCamera(); + TransformObject obj = getTransformObject(); + gl_Position = transformModelToClipPos(cam, obj, position); } diff --git a/libraries/render-utils/src/spot_light.slf b/libraries/render-utils/src/spot_light.slf index 95fabae3ed..e6c3938b71 100644 --- a/libraries/render-utils/src/spot_light.slf +++ b/libraries/render-utils/src/spot_light.slf @@ -1,4 +1,4 @@ -<@include Config.slh@> +<@include gpu/Config.slh@> <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // @@ -19,7 +19,7 @@ <@include DeferredLighting.slh@> // Everything about light -<@include Light.slh@> +<@include model/Light.slh@> // The view Matrix uniform mat4 invViewMat; diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 3bdf9a9fa9..df327b9c5c 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -44,8 +44,6 @@ #include "MIDIEvent.h" -EntityScriptingInterface ScriptEngine::_entityScriptingInterface; - static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ qDebug() << "script:print()<<" << context->argument(0).toString(); QString message = context->argument(0).toString() @@ -314,7 +312,8 @@ void ScriptEngine::init() { auto sceneScriptingInterface = DependencyManager::set(); - _entityScriptingInterface.init(); + auto entityScriptingInterface = DependencyManager::get(); + entityScriptingInterface->init(); // register various meta-types registerMetaTypes(this); @@ -352,7 +351,7 @@ void ScriptEngine::init() { registerGlobalObject("Script", this); registerGlobalObject("Audio", &AudioScriptingInterface::getInstance()); registerGlobalObject("Controller", _controllerScriptingInterface); - registerGlobalObject("Entities", &_entityScriptingInterface); + registerGlobalObject("Entities", entityScriptingInterface.data()); registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Vec3", &_vec3Library); registerGlobalObject("Uuid", &_uuidLibrary); @@ -470,6 +469,7 @@ void ScriptEngine::run() { int thisFrame = 0; auto nodeList = DependencyManager::get(); + auto entityScriptingInterface = DependencyManager::get(); qint64 lastUpdate = usecTimestampNow(); @@ -489,13 +489,13 @@ void ScriptEngine::run() { break; } - if (!_isFinished && _entityScriptingInterface.getEntityPacketSender()->serversExist()) { + if (!_isFinished && entityScriptingInterface->getEntityPacketSender()->serversExist()) { // release the queue of edit entity messages. - _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); + entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); // since we're in non-threaded mode, call process so that the packets are sent - if (!_entityScriptingInterface.getEntityPacketSender()->isThreaded()) { - _entityScriptingInterface.getEntityPacketSender()->process(); + if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) { + entityScriptingInterface->getEntityPacketSender()->process(); } } @@ -622,13 +622,13 @@ void ScriptEngine::run() { // kill the avatar identity timer delete _avatarIdentityTimer; - if (_entityScriptingInterface.getEntityPacketSender()->serversExist()) { + if (entityScriptingInterface->getEntityPacketSender()->serversExist()) { // release the queue of edit entity messages. - _entityScriptingInterface.getEntityPacketSender()->releaseQueuedMessages(); + entityScriptingInterface->getEntityPacketSender()->releaseQueuedMessages(); // since we're in non-threaded mode, call process so that the packets are sent - if (!_entityScriptingInterface.getEntityPacketSender()->isThreaded()) { - _entityScriptingInterface.getEntityPacketSender()->process(); + if (!entityScriptingInterface->getEntityPacketSender()->isThreaded()) { + entityScriptingInterface->getEntityPacketSender()->process(); } } diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 154fdb88e3..84d2527bd0 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -31,8 +31,6 @@ #include "ScriptUUID.h" #include "Vec3.h" -class EntityScriptingInterface; - const QString NO_SCRIPT(""); const unsigned int SCRIPT_DATA_CALLBACK_USECS = floor(((1.0 / 60.0f) * 1000 * 1000) + 0.5); @@ -46,9 +44,6 @@ public: ~ScriptEngine(); - /// Access the EntityScriptingInterface in order to initialize it with a custom packet sender and jurisdiction listener - static EntityScriptingInterface* getEntityScriptingInterface() { return &_entityScriptingInterface; } - ArrayBufferClass* getArrayBufferClass() { return _arrayBufferClass; } /// sets the script contents, will return false if failed, will fail if script is already running @@ -153,8 +148,6 @@ private: QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot); void stopTimer(QTimer* timer); - static EntityScriptingInterface _entityScriptingInterface; - AbstractControllerScriptingInterface* _controllerScriptingInterface; AvatarData* _avatarData; QString _scriptName; diff --git a/libraries/shared/src/Transform.h b/libraries/shared/src/Transform.h index 346a82a3b0..ec4513e51c 100644 --- a/libraries/shared/src/Transform.h +++ b/libraries/shared/src/Transform.h @@ -90,6 +90,10 @@ public: Mat4& getMatrix(Mat4& result) const; Mat4& getInverseMatrix(Mat4& result) const; + Mat4& getInverseTransposeMatrix(Mat4& result) const; + + Mat4& getRotationScaleMatrix(Mat4& result) const; + Mat4& getRotationScaleMatrixInverse(Mat4& result) const; Transform& evalInverse(Transform& result) const; @@ -329,6 +333,24 @@ inline Transform::Mat4& Transform::getInverseMatrix(Transform::Mat4& result) con return inverse.getMatrix(result); } +inline Transform::Mat4& Transform::getInverseTransposeMatrix(Transform::Mat4& result) const { + getInverseMatrix(result); + result = glm::transpose(result); + return result; +} + +inline Transform::Mat4& Transform::getRotationScaleMatrix(Mat4& result) const { + getMatrix(result); + result[3] = Vec4(0.0f, 0.0f, 0.0f, 1.0f); + return result; +} + +inline Transform::Mat4& Transform::getRotationScaleMatrixInverse(Mat4& result) const { + getInverseMatrix(result); + result[3] = Vec4(0.0f, 0.0f, 0.0f, 1.0f); + return result; +} + inline void Transform::evalFromRawMatrix(const Mat4& matrix) { // for now works only in the case of TRS transformation if ((matrix[0][3] == 0) && (matrix[1][3] == 0) && (matrix[2][3] == 0) && (matrix[3][3] == 1.0f)) {