Merge branch 'master' of https://github.com/worklist/hifi into 20245

Conflicts:
	examples/notifications.js
This commit is contained in:
Thijs Wenker 2015-02-17 23:30:58 +01:00
commit 4d12a6d81c
461 changed files with 18339 additions and 9524 deletions

11
.gitignore vendored
View file

@ -3,7 +3,7 @@ CMakeCache.txt
CMakeFiles/
CMakeScripts/
cmake_install.cmake
build/
build*/
Makefile
*.user
@ -38,3 +38,12 @@ interface/resources/visage/*
# Ignore interfaceCache for Linux users
interface/interfaceCache/
# ignore audio-client externals
libraries/audio-client/external/*/*
!libraries/audio-client/external/*/readme.txt
gvr-interface/assets/oculussig*
gvr-interface/libs/*
TAGS

View file

@ -1,17 +1,26 @@
###Dependencies
* [cmake](http://www.cmake.org/cmake/resources/software.html) ~> 2.8.12.2
* [Qt](http://qt-project.org/downloads) ~> 5.3.0
* [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.4
* [Qt](http://qt-project.org/downloads) ~> 5.3.2
* [OpenSSL](https://www.openssl.org/related/binaries.html) ~> 1.0.1g
* IMPORTANT: OpenSSL 1.0.1g is critical to avoid a security vulnerability.
* [Intel Threading Building Blocks](https://www.threadingbuildingblocks.org/) ~> 4.3
* [Bullet Physics Engine](http://bulletphysics.org) ~> 2.82
* [Soxr](http://sourceforge.net/projects/soxr/) ~> 0.1.1
* [Bullet Physics Engine](https://code.google.com/p/bullet/downloads/list) ~> 2.82
* [Gverb](https://github.com/highfidelity/gverb/archive/master.zip) (direct download to latest version)
#### CMake External Project Dependencies
The following dependencies will be downloaded, built, linked and included automatically by CMake where we require them. The CMakeLists files that handle grabbing each of the following external dependencies can be found in the [cmake/externals folder](cmake/externals). The resulting downloads, source files and binaries will be placed in the `build` directory in each of the subfolders for each external project. These are not placed in your normal build tree when doing an out of source build so that they do not need to be re-downloaded and re-compiled every time the CMake build folder is cleared.
* [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.4
* [gverb](https://github.com/highfidelity/gverb)
### OS Specific Build Guides
* [BUILD_OSX.md](BUILD_OSX.md) - additional instructions for OS X.
* [BUILD_LINUX.md](BUILD_LINUX.md) - additional instructions for Linux.
* [BUILD_WIN.md](BUILD_WIN.md) - additional instructions for Windows.
* [BUILD_ANDROID.md](BUILD_ANDROID.md) - additional instructions for Android
###CMake
Hifi uses CMake to generate build files and project files for your platform.
@ -54,11 +63,11 @@ In the examples below the variable $NAME would be replaced by the name of the de
####QXmpp
You can find QXmpp [here](https://github.com/qxmpp-project/qxmpp). The inclusion of the QXmpp enables text chat in the Interface client.
You can [find QXmpp here](https://github.com/qxmpp-project/qxmpp), 0.7.6 is the version you want. The inclusion of the QXmpp enables text chat in the Interface client.
OS X users who tap our [homebrew formulas repository](https://github.com/highfidelity/homebrew-formulas) can install QXmpp via homebrew - `brew install highfidelity/formulas/qxmpp`.
####Devices
You can support external input/output devices such as 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, 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.

143
BUILD_ANDROID.md Normal file
View file

@ -0,0 +1,143 @@
Please read the [general build guide](BUILD.md) for information on dependencies required for all platforms. Only Android specific instructions are found in this file.
###Android Dependencies
You will need the following tools to build our Android targets.
* [cmake](http://www.cmake.org/download/) ~> 3.1.0
* Note that this is a newer version required than the minimum for hifi desktop targets.
* [Qt](http://www.qt.io/download-open-source/#) ~> 5.4.0
* Note that this is a newer version required than the minimum for hifi desktop targets.
* [ant](http://ant.apache.org/bindownload.cgi) ~> 1.9.4
* [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html) = r10c
* [Android SDK](http://developer.android.com/sdk/installing/index.html) ~> 24.0.2
* Install the latest Platform-tools
* Install the latest Build-tools
* Install the SDK Platform for API Level 19
* Install Sources for Android SDK for API Level 19
* Install the ARM EABI v7a System Image if you want to run an emulator.
You will also need to cross-compile the dependencies required for all platforms for Android, and help CMake find these compiled libraries on your machine.
####Optional Components
* [Oculus Mobile SDK](https://developer.oculus.com/downloads/#sdk=mobile) ~> 0.4.2
####ANDROID_LIB_DIR
Since you won't be installing Android dependencies to system paths on your development machine, CMake will need a little help tracking down your Android dependencies.
This is most easily accomplished by installing all Android dependencies in the same folder. You can place this folder wherever you like on your machine. In this build guide and across our CMakeLists files this folder is referred to as `ANDROID_LIB_DIR`. You can set `ANDROID_LIB_DIR` in your environment or by passing when you run CMake.
####Qt
Install Qt 5.4 for Android for your host environment from the [Qt downloads page](http://www.qt.io/download/). Install Qt to ``$ANDROID_LIB_DIR/Qt``. This is required so that our root CMakeLists file can help CMake find your Android Qt installation.
The component required for the Android build is the `Android armv7` component.
If you would like to install Qt to a different location, or attempt to build with a different Qt version, you can pass `ANDROID_QT_CMAKE_PREFIX_PATH` to CMake. Point to the `cmake` folder inside `$VERSION_NUMBER/android_armv7/lib`. Otherwise, our root CMakeLists will set it to `$ANDROID_LIB_DIR/Qt/5.3/android_armv7/lib/cmake`.
####OpenSSL
Cross-compilation of OpenSSL has been tested from an OS X machine running 10.10 compiling OpenSSL 1.0.2. It is likely that the steps below will work for other OpenSSL versions than 1.0.2.
The original instructions to compile OpenSSL for Android from your host environment can be found [here](http://wiki.openssl.org/index.php/Android). We required some tweaks to get OpenSSL to successfully compile, those tweaks are explained below.
Download the [OpenSSL source](https://www.openssl.org/source/) and extract the tarball inside your `ANDROID_LIB_DIR`. Rename the extracted folder to `openssl`.
You will need the [setenv-android.sh script](http://wiki.openssl.org/index.php/File:Setenv-android.sh) from the OpenSSL wiki.
You must change three values at the top of the `setenv-android.sh` script - `_ANDROID_NDK`, `_ANDROID_EABI` and `_ANDROID_API`.
`_ANDROID_NDK` should be `android-ndk-r10`, `_ANDROID_EABI` should be `arm-linux-androidebi-4.9` and `_ANDROID_API` should be `19`.
First, make sure `ANDROID_NDK_ROOT` is set in your env. This should be the path to the root of your Android NDK install. `setenv-android.sh` needs `ANDROID_NDK_ROOT` to set the environment variables required for building OpenSSL.
Source the `setenv-android.sh` script so it can set environment variables that OpenSSL will use while compiling. If you use zsh as your shell you may need to modify the `setenv-android.sh` for it to set the correct variables in your env.
```
export ANDROID_NDK_ROOT=YOUR_NDK_ROOT
source setenv-android.sh
```
Then, from the OpenSSL directory, run the following commands.
```
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API
make depend
make all
```
This should generate libcrypto and libssl in the root of the OpenSSL directory. YOU MUST remove the `libssl.so` and `libcrypto.so` files that are generated. They are symlinks to `libssl.so.VER` and `libcrypto.so.VER` which Android does not know how to handle. By removing `libssl.so` and `libcrypto.so` the FindOpenSSL module will find the static libs and use those instead.
If you have been building other components it is possible that the OpenSSL compile will fail based on the values other cross-compilations (tbb, bullet) have set. Ensure that you are in a new terminal window to avoid compilation errors from previously set environment variables.
####Intel Threading Building Blocks
Download the [Intel Threading Building Blocks source](https://www.threadingbuildingblocks.org/download) and extract the tarball inside your `ANDROID_LIB_DIR`. Rename the extracted folder to `tbb`.
NOTE: BEFORE YOU ATTEMPT TO CROSS-COMPILE TBB, DISCONNECT ANY DEVICES ADB WOULD DETECT. The tbb build process asks adb for a couple of strings, and if a device is plugged in extra characters get added that will cause ndk-build to fail with an error.
From the tbb directory, execute the following commands. First, we build TBB using `ndk-build`. Then, the compiled libs are copied to a lib folder in the root of tbb directory.
```
cd jni
ndk-build target=android tbb tbbmalloc arch=arm
cd ../
mkdir lib
cp `find . -name "*.so"` lib/
```
####Soxr
Download the [Soxr source](http://sourceforge.net/projects/soxr/) and extract the tarball inside your `ANDROID_LIB_DIR`. Rename the extracted folder to `soxr`.
From the soxr directory, use cmake, along with the `android.toolchain.cmake` file (included in this repository under cmake/android) to cross-compile soxr for Android. Note that you will need ANDROID_NDK set in your environment before using the toolchain file.
The full set of commands to build soxr for Android is shown below. It is a long command, make sure you copy the entire command (up to `-DBUILD_TESTS=0`).
```
cmake -DCMAKE_TOOLCHAIN_FILE=$FULL_PATH_TO_TOOLCHAIN -DCMAKE_INSTALL_PREFIX=. -DHAVE_WORDS_BIGENDIAN_EXITCODE=1 -DBUILD_TESTS=0
make
make install
```
This will create the `lib` and `include` folders inside `ANDROID_LIB_DIR/soxr` that FindSoxr will look for.
####Oculus Mobile SDK
The Oculus Mobile SDK is optional, for Gear VR support. It is not required to compile gvr-interface.
Download the [Oculus Mobile SDK](https://developer.oculus.com/downloads/#sdk=mobile) and extract the archive inside your `ANDROID_LIB_DIR` folder. Rename the extracted folder to `libovr`.
From the VRLib directory, use ndk-build to build VrLib.
```
cd VRLib
ndk-build
```
This will create the liboculus.a archive that our FindLibOVR module will look for when cmake is run.
#####Hybrid testing
Currently the 'vr_dual' mode that would allow us to run a hybrid app has limited support in the Oculus Mobile SDK. The best way to have an application we can launch without having to connect to the GearVR is to put the Gear VR Service into developer mode. This stops Oculus Home from taking over the device when it is plugged into the Gear VR headset, and allows the application to be launched from the Applications page.
To put the Gear VR Service into developer mode you need an application with an Oculus Signature File on your device. Generate an Oculus Signature File for your device on the [Oculus osig tool page](https://developer.oculus.com/tools/osig/). Place this file in the gvr-interface/assets directory. Cmake will automatically copy it into your apk in the right place when you execute `make gvr-interface-apk`.
Once the application is on your device, go to `Settings->Application Manager->Gear VR Service->Manage Storage`. Tap on `VR Service Version` six times. It will scan your device to verify that you have an osig file in an application on your device, and then it will let you enable Developer mode.
###CMake
We use CMake to generate the makefiles that compile and deploy the Android APKs to your device. In order to create Makefiles for the Android targets, CMake requires that some environment variables are set, and that other variables are passed to it when it is run.
The following must be set in your environment:
* ANDROID_NDK - the root of your Android NDK install
* ANDROID_HOME - the root of your Android SDK install
* ANDROID_LIB_DIR - the directory containing cross-compiled versions of dependencies
The following must be passed to CMake when it is run:
* USE_ANDROID_TOOLCHAIN - set to true to build for Android

View file

@ -4,7 +4,7 @@ Please read the [general build guide](BUILD.md) for information on dependencies
[Homebrew](http://brew.sh/) is an excellent package manager for OS X. It makes install of all hifi dependencies very simple.
brew tap highfidelity/homebrew-formulas
brew install cmake glm openssl tbb
brew install cmake openssl tbb libsoxr
brew install highfidelity/formulas/qt5
brew link qt5 --force

View file

@ -1,15 +1,10 @@
Please read the [general build guide](BUILD.md) for information on dependencies required for all platforms. Only Windows specific instructions are found in this file.
###Windows Dependencies
###Windows Specific Dependencies
* [GLEW](http://glew.sourceforge.net/) ~> 1.10.0
* [freeglut MSVC](http://www.transmissionzero.co.uk/software/freeglut-devel/) ~> 2.8.1
* [zLib](http://www.zlib.net/) ~> 1.2.8
###Visual Studio
Currently building on Windows has been tested using the following compilers:
* Visual Studio 2013
* Visual Studio 2013 Express
* (remember that you need all other dependencies listed in [BUILD.md](BUILD.md))
####Visual Studio 2013
@ -30,23 +25,29 @@ You can use the online installer or the offline installer. If you use the offlin
NOTE: Qt does not support 64-bit builds on Windows 7, so you must use the 32-bit version of libraries for interface.exe to run. The 32-bit version of the static library is the one linked by our CMake find modules.
* Download the online installer [here](http://qt-project.org/downloads)
* [Download the online installer](http://qt-project.org/downloads)
* When it asks you to select components, ONLY select the following:
* Qt > Qt 5.3.2 > **msvc2013 32-bit OpenGL**
* Download the offline installer [here](http://download.qt-project.org/official_releases/qt/5.3/5.3.2/qt-opensource-windows-x86-msvc2013_opengl-5.3.2.exe)
* [Download the offline installer](http://download.qt-project.org/official_releases/qt/5.3/5.3.2/qt-opensource-windows-x86-msvc2013_opengl-5.3.2.exe)
Once Qt is installed, you need to manually configure the following:
* Make sure the Qt runtime DLLs are loadable. You must do this before you attempt to build because some tools for the build depend on Qt. E.g., add to the PATH: `Qt\5.3.2\msvc2013_opengl\bin\`.
* Go to Control Panel > System > Advanced System Settings > Environment Variables > New ...
* Set the QT_CMAKE_PREFIX_PATH environment variable to your `Qt\5.3.2\msvc2013_opengl` directory.
###External Libraries
As it stands, Hifi/Interface is a 32-bit application, so all libraries should also be 32-bit.
CMake will need to know where the headers and libraries for required external dependencies are.
The recommended route for CMake to find the external dependencies is to place all of the dependencies in one folder and set one ENV variable - HIFI_LIB_DIR. That ENV variable should point to a directory with the following structure:
root_lib_dir
-> bullet
-> include
-> lib
-> freeglut
-> bin
-> include
@ -55,9 +56,6 @@ The recommended route for CMake to find the external dependencies is to place al
-> bin
-> include
-> lib
-> glm
-> glm
-> glm.hpp
-> openssl
-> bin
-> include
@ -76,7 +74,7 @@ As with the Qt libraries, you will need to make sure that directories containing
###OpenSSL
QT will use OpenSSL if it's available, but it doesn't install it, so you must install it separately.
Qt will use OpenSSL if it's available, but it doesn't install it, so you must install it separately.
Your system may already have several versions of the OpenSSL DLL's (ssleay32.dll, libeay32.dll) lying around, but they may be the wrong version. If these DLL's are in the PATH then QT will try to use them, and if they're the wrong version then you will see the following errors in the console:
@ -90,9 +88,9 @@ Your system may already have several versions of the OpenSSL DLL's (ssleay32.dll
To prevent these problems, install OpenSSL yourself. Download the following binary packages [from this website](http://slproweb.com/products/Win32OpenSSL.html):
* Visual C++ 2008 Redistributables
* Win32 OpenSSL v1.0.1h
* Win32 OpenSSL v1.0.1L
Install OpenSSL into the Windows system directory, to make sure that QT uses the version that you've just installed, and not some other version.
Install OpenSSL into the Windows system directory, to make sure that Qt uses the version that you've just installed, and not some other version.
###Intel Threading Building Blocks (TBB)
@ -111,8 +109,10 @@ Add the following environment variables (remember to substitute your own directo
Add to the PATH: `%HIFI_LIB_DIR%\zlib`
Important! This should be added at the beginning of the path, not the end. That's because your
system likely has many copies of zlib1.dll, and you want High Fidelity to use the correct version. If High Fidelity picks up the wrong zlib1.dll then it might be unable to use it, and that would cause it to fail to start, showing only the cryptic error "The application was unable to start correctly: 0xc0000022".
(The PATH environment variable is where Windows looks for its DLL's and executables. There's a great tool for editing these variables with ease, [Rapid Environment Editor](http://www.rapidee.com/en/download))
Important! This should be added at the beginning of the path, not the end (your
system likely has many copies of zlib1.dll, and you want High Fidelity to use the correct version). If High Fidelity picks up the wrong zlib1.dll then it might be unable to use it, and that would cause it to fail to start, showing only the cryptic error "The application was unable to start correctly: 0xc0000022".
###freeglut
@ -126,14 +126,51 @@ Download the binary package: `glew-1.10.0-win32.zip`. Extract to %HIFI_LIB_DIR%\
Add to the PATH: `%HIFI_LIB_DIR%\glew\bin\Release\Win32`
###GLM
###Bullet
This package contains only headers, so there's nothing to add to the PATH.
Bullet 2.82 source can be [downloaded here](https://code.google.com/p/bullet/downloads/detail?name=bullet-2.82-r2704.zip). Bullet does not come with prebuilt libraries, you need to make those yourself.
Be careful with glm. For the folder other libraries would normally call 'include', the folder containing the headers, glm opts to use 'glm'. You will have a glm folder nested inside the top-level glm folder.
* Download the zip file and extract into a temporary folder
* Create a directory named cmakebuild. Bullet comes with a build\ directory by default, however, that directory is intended for use with premake, and considering premake doesn't support VS2013, we prefer to run the cmake build on its own directory.
* Make the following modifications to Bullet's source:
1. In file: Extras\HACD\hacdICHull.cpp --- in line: 17 --- insert: #include <algorithm>
2. In file: src\MiniCL\cl_MiniCL_Defs.h --- comment lines 364 to 372
3. In file: CMakeLists.txt set to ON the option USE_MSVC_RUNTIME_LIBRARY_DLL in line 27
Then create the Visual Studio solution and build the libraries - run the following commands from a Visual Studio 2013 command prompt, from within the cmakebuild directory created before:
```shell
cmake .. -G "Visual Studio 12"
msbuild BULLET_PHYSICS.sln /p:Configuration=Debug
```
This will create Debug libraries in cmakebuild\lib\Debug. You can replace Debug with Release in the msbuild command and that will generate Release libraries in cmakebuild\lib\Release.
You now have Bullet libraries compiled, now you need to put them in the right place for hifi to find them:
* Create a directory named bullet\ inside your %HIFI_LIB_DIR%
* Create two directores named lib\ and include\ inside bullet\
* Copy all the contents inside src\ from the bullet unzip path into %HIFI_LIB_DIR%\bullet\include\
* Copy all the contents inside cmakebuild\lib\ into %HIFI_LIB_DIR\bullet\lib
_Note that the INSTALL target should handle the copying of files into an install directory automatically, however, without modifications to Cmake, the install target didn't work right for me, please update this instructions if you get that working right - Leo <leo@highfidelity.io>_
###Soxr
Download the zip from the [soxr sourceforge page](http://sourceforge.net/projects/soxr/).
We recommend you install it to %HIFI_LIB_DIR%\soxr. This will help our FindSoxr cmake module find what it needs. You can place it wherever you like on your machine if you specify SOXR_ROOT_DIR as an environment variable or a variable passed when cmake is run.
Extract the soxr archive wherever you like. Then, inside the extracted folder, create a directory called `build`. From that build directory, the following commands will build and then install soxr to `%HIFI_LIB_DIR%`.
```
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%HIFI_LIB_DIR%/soxr
nmake
nmake install
```
###Build High Fidelity using Visual Studio
Follow the same build steps from the CMake section, but pass a different generator to CMake.
Follow the same build steps from the CMake section of [BUILD.md](BUILD.md), but pass a different generator to CMake.
cmake .. -DZLIB_LIBRARY=%ZLIB_LIBRARY% -DZLIB_INCLUDE_DIR=%ZLIB_INCLUDE_DIR% -G "Visual Studio 12"

View file

@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 2.8.12.2)
if (USE_ANDROID_TOOLCHAIN)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/android/android.toolchain.cmake")
set(ANDROID_NATIVE_API_LEVEL 19)
endif ()
if (WIN32)
cmake_policy(SET CMP0020 NEW)
endif (WIN32)
@ -58,8 +63,27 @@ if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --stdlib=libc++")
endif ()
if (NOT QT_CMAKE_PREFIX_PATH)
set(QT_CMAKE_PREFIX_PATH $ENV{QT_CMAKE_PREFIX_PATH})
if (NOT ANDROID_LIB_DIR)
set(ANDROID_LIB_DIR $ENV{ANDROID_LIB_DIR})
endif ()
if (ANDROID)
if (NOT ANDROID_QT_CMAKE_PREFIX_PATH)
set(QT_CMAKE_PREFIX_PATH ${ANDROID_LIB_DIR}/Qt/5.4/android_armv7/lib/cmake)
else ()
set(QT_CMAKE_PREFIX_PATH ${ANDROID_QT_CMAKE_PREFIX_PATH})
endif ()
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
if (ANDROID_LIB_DIR)
list(APPEND CMAKE_FIND_ROOT_PATH ${ANDROID_LIB_DIR})
endif ()
else ()
if (NOT QT_CMAKE_PREFIX_PATH)
set(QT_CMAKE_PREFIX_PATH $ENV{QT_CMAKE_PREFIX_PATH})
endif ()
endif ()
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT_CMAKE_PREFIX_PATH})
@ -71,6 +95,8 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.8)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Instruct CMake to run rcc automatically when needed
set(CMAKE_AUTORCC ON)
set(HIFI_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries")
@ -78,16 +104,30 @@ set(HIFI_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
set(MACRO_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros")
set(EXTERNAL_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/externals")
file(GLOB HIFI_CUSTOM_MACROS "cmake/macros/*.cmake")
foreach(CUSTOM_MACRO ${HIFI_CUSTOM_MACROS})
include(${CUSTOM_MACRO})
endforeach()
# targets on all platforms
add_subdirectory(assignment-client)
add_subdirectory(domain-server)
add_subdirectory(ice-server)
add_subdirectory(interface)
add_subdirectory(tests)
add_subdirectory(tools)
if (ANDROID)
file(GLOB ANDROID_CUSTOM_MACROS "cmake/android/*.cmake")
foreach(CUSTOM_MACRO ${ANDROID_CUSTOM_MACROS})
include(${CUSTOM_MACRO})
endforeach()
endif ()
# add subdirectories for all targets
if (NOT ANDROID)
add_subdirectory(assignment-client)
add_subdirectory(domain-server)
add_subdirectory(ice-server)
add_subdirectory(interface)
add_subdirectory(tests)
add_subdirectory(tools)
endif ()
if (ANDROID OR DESKTOP_GVR)
add_subdirectory(gvr-interface)
endif ()

View file

@ -61,7 +61,7 @@ Any target can be terminated with Ctrl-C (SIGINT) in the associated Terminal win
This assignment-client will grab one assignment from the domain-server. You can tell the assignment-client what type you want it to be with the `-t` option. You can also run an assignment-client that forks off *n* assignment-clients with the `-n` option.
./assignment-client -n 6
./assignment-client -n 4
To test things out you'll want to run the Interface client.

View file

@ -2,7 +2,9 @@ set(TARGET_NAME assignment-client)
setup_hifi_project(Core Gui Network Script Widgets)
include_glm()
add_dependency_external_project(glm)
find_package(GLM REQUIRED)
target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS})
# link in the shared libraries
link_hifi_libraries(

View file

@ -17,7 +17,7 @@
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <AvatarData.h>
#include <AvatarHashMap.h>
#include <NetworkAccessManager.h>
#include <NodeList.h>
#include <PacketHeaders.h>
@ -39,13 +39,14 @@ Agent::Agent(const QByteArray& packet) :
_receivedAudioStream(AudioConstants::NETWORK_FRAME_SAMPLES_STEREO, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES,
InboundAudioStream::Settings(0, false, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES, false,
DEFAULT_WINDOW_STARVE_THRESHOLD, DEFAULT_WINDOW_SECONDS_FOR_DESIRED_CALC_ON_TOO_MANY_STARVES,
DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false)),
_avatarHashMap()
DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false))
{
// be the parent of the script engine so it gets moved when we do
_scriptEngine.setParent(this);
_scriptEngine.getEntityScriptingInterface()->setPacketSender(&_entityEditSender);
DependencyManager::set<ResouceCacheSharedItems>();
}
void Agent::readPendingDatagrams() {
@ -133,7 +134,7 @@ void Agent::readPendingDatagrams() {
|| datagramPacketType == PacketTypeAvatarBillboard
|| datagramPacketType == PacketTypeKillAvatar) {
// let the avatar hash map process it
_avatarHashMap.processAvatarMixerDatagram(receivedPacket, nodeList->sendingNodeForPacket(receivedPacket));
DependencyManager::get<AvatarHashMap>()->processAvatarMixerDatagram(receivedPacket, nodeList->sendingNodeForPacket(receivedPacket));
// let this continue through to the NodeList so it updates last heard timestamp
// for the sending avatar-mixer
@ -169,7 +170,9 @@ void Agent::run() {
}
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
QNetworkReply *reply = networkAccessManager.get(QNetworkRequest(scriptURL));
QNetworkRequest networkRequest = QNetworkRequest(scriptURL);
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
QNetworkReply* reply = networkAccessManager.get(networkRequest);
QNetworkDiskCache* cache = new QNetworkDiskCache();
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
@ -198,14 +201,14 @@ void Agent::run() {
// give this AvatarData object to the script engine
_scriptEngine.setAvatarData(&scriptedAvatar, "Avatar");
_scriptEngine.setAvatarHashMap(&_avatarHashMap, "AvatarList");
_scriptEngine.setAvatarHashMap(DependencyManager::get<AvatarHashMap>().data(), "AvatarList");
// register ourselves to the script engine
_scriptEngine.registerGlobalObject("Agent", this);
_scriptEngine.init(); // must be done before we set up the viewers
_scriptEngine.registerGlobalObject("SoundCache", &SoundCache::getInstance());
_scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
_scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer);
_entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener());

View file

@ -18,7 +18,6 @@
#include <QtCore/QObject>
#include <QtCore/QUrl>
#include <AvatarHashMap.h>
#include <EntityEditPacketSender.h>
#include <EntityTree.h>
#include <EntityTreeHeadlessViewer.h>
@ -63,8 +62,6 @@ private:
MixedAudioStream _receivedAudioStream;
float _lastReceivedAudioLoudness;
AvatarHashMap _avatarHashMap;
};
#endif // hifi_Agent_h

View file

@ -9,14 +9,16 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtCore/QProcess>
#include <QtCore/qsharedmemory.h>
#include <QtCore/QThread>
#include <QtCore/QTimer>
#include <QProcess>
#include <QSettings>
#include <QSharedMemory>
#include <QThread>
#include <QTimer>
#include <AccountManager.h>
#include <AddressManager.h>
#include <Assignment.h>
#include <AvatarHashMap.h>
#include <HifiConfigVariantMap.h>
#include <LogHandler.h>
#include <LogUtils.h>
@ -54,6 +56,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
auto addressManager = DependencyManager::set<AddressManager>();
auto nodeList = DependencyManager::set<NodeList>(NodeType::Unassigned);
auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
// setup a shutdown event listener to handle SIGTERM or WM_CLOSE for us
#ifdef _WIN32
@ -133,7 +136,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
// Create Singleton objects on main thread
NetworkAccessManager::getInstance();
SoundCache::getInstance();
auto soundCache = DependencyManager::get<SoundCache>();
}
void AssignmentClient::sendAssignmentRequest() {

View file

@ -648,6 +648,7 @@ void AudioMixer::run() {
// setup a QThread with us as parent that will house the AudioMixerDatagramProcessor
_datagramProcessingThread = new QThread(this);
_datagramProcessingThread->setObjectName("Datagram Processor Thread");
// create an AudioMixerDatagramProcessor and move it to that thread
AudioMixerDatagramProcessor* datagramProcessor = new AudioMixerDatagramProcessor(nodeList->getNodeSocket(), thread());

View file

@ -147,3 +147,14 @@ void EntityServer::pruneDeletedEntities() {
}
}
void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectionObject) {
bool wantEditLogging = false;
readOptionBool(QString("wantEditLogging"), settingsSectionObject, wantEditLogging);
qDebug("wantEditLogging=%s", debug::valueOf(wantEditLogging));
EntityTree* tree = static_cast<EntityTree*>(_tree);
tree->setWantEditLogging(wantEditLogging);
}

View file

@ -41,6 +41,7 @@ public:
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode);
virtual void readAdditionalConfiguration(const QJsonObject& settingsSectionObject);
public slots:
void pruneDeletedEntities();

View file

@ -271,9 +271,10 @@ void MetavoxelSession::handleMessage(const QVariant& message) {
_lodPacketNumber = _sequencer.getIncomingPacketNumber();
} else if (userType == MetavoxelEditMessage::Type) {
QMetaObject::invokeMethod(_sender->getServer(), "applyEdit", Q_ARG(const MetavoxelEditMessage&,
message.value<MetavoxelEditMessage>()));
if (_node->getCanAdjustLocks()) {
QMetaObject::invokeMethod(_sender->getServer(), "applyEdit",
Q_ARG(const MetavoxelEditMessage&, message.value<MetavoxelEditMessage>()));
}
} else if (userType == QMetaType::QVariantList) {
foreach (const QVariant& element, message.toList()) {
handleMessage(element);

View file

@ -879,6 +879,7 @@ void OctreeServer::setupDatagramProcessingThread() {
// setup a QThread with us as parent that will house the OctreeServerDatagramProcessor
_datagramProcessingThread = new QThread(this);
_datagramProcessingThread->setObjectName("Octree Datagram Processor");
// create an OctreeServerDatagramProcessor and move it to that thread
OctreeServerDatagramProcessor* datagramProcessor = new OctreeServerDatagramProcessor(nodeList->getNodeSocket(), thread());

View file

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- IMPORTANT: Do not manually manipulate this automatically generated file, changes will be gone after the next build! -->
<manifest package="${ANDROID_APK_PACKAGE}" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="${ANDROID_APK_VERSION_NAME}" android:versionCode="${ANDROID_APK_VERSION_CODE}" android:installLocation="auto">
<application
android:hardwareAccelerated="true"
android:name="org.qtproject.qt5.android.bindings.QtApplication"
android:label="@string/AppDisplayName"
android:icon="@drawable/icon"
android:debuggable="${ANDROID_APK_DEBUGGABLE}">
<!-- VR MODE -->
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
<activity
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
android:name="${ANDROID_ACTIVITY_NAME}"
android:label="@string/AppDisplayName"
android:screenOrientation="landscape"
android:launchMode="singleTop"
${ANDROID_APK_THEME}>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<!-- Messages maps -->
<!-- Splash screen -->
<!-- <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/> -->
${ANDROID_EXTRA_ACTIVITY_XML}
</activity>
<activity
android:name="com.oculusvr.vrlib.PlatformActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="screenSize|orientation|keyboardHidden|keyboard">
</activity>
${ANDROID_EXTRA_APPLICATION_XML}
</application>
<uses-sdk android:minSdkVersion="${ANDROID_API_LEVEL}" android:targetSdkVersion="${ANDROID_API_LEVEL}"/>
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- camera permission required for GEAR VR passthrough camera -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->
<!-- Tell the system this app requires OpenGL ES 3.0. -->
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
</manifest>

View file

@ -0,0 +1,162 @@
#
# QtCreateAPK.cmake
#
# Created by Stephen Birarda on 11/18/14.
# Copyright 2013 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
#
#
# OPTIONS
# These options will modify how QtCreateAPK behaves. May be useful if somebody wants to fork.
# For High Fidelity purposes these should not need to be changed.
#
set(ANDROID_THIS_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) # Directory this CMake file is in
if (POLICY CMP0026)
cmake_policy(SET CMP0026 OLD)
endif ()
macro(qt_create_apk)
if(ANDROID_APK_FULLSCREEN)
set(ANDROID_APK_THEME "android:theme=\"@android:style/Theme.NoTitleBar.Fullscreen\"")
else()
set(ANDROID_APK_THEME "")
endif()
if (CMAKE_BUILD_TYPE MATCHES RELEASE)
set(ANDROID_APK_DEBUGGABLE "false")
set(ANDROID_APK_RELEASE_LOCAL ${ANDROID_APK_RELEASE})
else ()
set(ANDROID_APK_DEBUGGABLE "true")
set(ANDROID_APK_RELEASE_LOCAL "0")
endif ()
# Create "AndroidManifest.xml"
configure_file("${ANDROID_THIS_DIRECTORY}/AndroidManifest.xml.in" "${ANDROID_APK_BUILD_DIR}/AndroidManifest.xml")
# create "strings.xml"
configure_file("${ANDROID_THIS_DIRECTORY}/strings.xml.in" "${ANDROID_APK_BUILD_DIR}/res/values/strings.xml")
# figure out where the qt dir is
get_filename_component(QT_DIR "${QT_CMAKE_PREFIX_PATH}/../../" ABSOLUTE)
# find androiddeployqt
find_program(ANDROID_DEPLOY_QT androiddeployqt HINTS "${QT_DIR}/bin")
# set the path to our app shared library
set(EXECUTABLE_DESTINATION_PATH "${ANDROID_APK_OUTPUT_DIR}/libs/${ANDROID_ABI}/lib${TARGET_NAME}.so")
# add our dependencies to the deployment file
get_property(_DEPENDENCIES TARGET ${TARGET_NAME} PROPERTY INTERFACE_LINK_LIBRARIES)
foreach(_IGNORE_COPY IN LISTS IGNORE_COPY_LIBS)
list(REMOVE_ITEM _DEPENDENCIES ${_IGNORE_COPY})
endforeach()
foreach(_DEP IN LISTS _DEPENDENCIES)
if (NOT TARGET ${_DEP})
list(APPEND _DEPS_LIST ${_DEP})
else ()
if(NOT _DEP MATCHES "Qt5::.*")
get_property(_DEP_LOCATION TARGET ${_DEP} PROPERTY "LOCATION_${CMAKE_BUILD_TYPE}")
# recurisvely add libraries which are dependencies of this target
get_property(_DEP_DEPENDENCIES TARGET ${_DEP} PROPERTY INTERFACE_LINK_LIBRARIES)
foreach(_SUB_DEP IN LISTS _DEP_DEPENDENCIES)
if (NOT TARGET ${_SUB_DEP} AND NOT _SUB_DEP MATCHES "Qt5::.*")
list(APPEND _DEPS_LIST ${_SUB_DEP})
endif()
endforeach()
list(APPEND _DEPS_LIST ${_DEP_LOCATION})
endif()
endif ()
endforeach()
list(REMOVE_DUPLICATES _DEPS_LIST)
# just copy static libs to apk libs folder - don't add to deps list
foreach(_LOCATED_DEP IN LISTS _DEPS_LIST)
if (_LOCATED_DEP MATCHES "\\.a$")
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${_LOCATED_DEP} "${ANDROID_APK_OUTPUT_DIR}/libs/${ANDROID_ABI}"
)
list(REMOVE_ITEM _DEPS_LIST ${_LOCATED_DEP})
endif ()
endforeach()
string(REPLACE ";" "," _DEPS "${_DEPS_LIST}")
configure_file("${ANDROID_THIS_DIRECTORY}/deployment-file.json.in" "${TARGET_NAME}-deployment.json")
# copy the res folder from the target to the apk build dir
add_custom_target(
${TARGET_NAME}-copy-res
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/res" "${ANDROID_APK_BUILD_DIR}/res"
)
# copy the assets folder from the target to the apk build dir
add_custom_target(
${TARGET_NAME}-copy-assets
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/assets" "${ANDROID_APK_BUILD_DIR}/assets"
)
# copy the java folder from src to the apk build dir
add_custom_target(
${TARGET_NAME}-copy-java
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/java" "${ANDROID_APK_BUILD_DIR}/src"
)
# copy the libs folder from src to the apk build dir
add_custom_target(
${TARGET_NAME}-copy-libs
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/libs" "${ANDROID_APK_BUILD_DIR}/libs"
)
# handle setup for ndk-gdb
add_custom_target(${TARGET_NAME}-gdb DEPENDS ${TARGET_NAME})
if (ANDROID_APK_DEBUGGABLE)
get_property(TARGET_LOCATION TARGET ${TARGET_NAME} PROPERTY LOCATION)
set(GDB_SOLIB_PATH ${ANDROID_APK_BUILD_DIR}/obj/local/${ANDROID_NDK_ABI_NAME}/)
# generate essential Android Makefiles
file(WRITE ${ANDROID_APK_BUILD_DIR}/jni/Android.mk "APP_ABI := ${ANDROID_NDK_ABI_NAME}\n")
file(WRITE ${ANDROID_APK_BUILD_DIR}/jni/Application.mk "APP_ABI := ${ANDROID_NDK_ABI_NAME}\n")
# create gdb.setup
get_directory_property(PROJECT_INCLUDES DIRECTORY ${PROJECT_SOURCE_DIR} INCLUDE_DIRECTORIES)
string(REGEX REPLACE ";" " " PROJECT_INCLUDES "${PROJECT_INCLUDES}")
file(WRITE ${ANDROID_APK_BUILD_DIR}/libs/${ANDROID_NDK_ABI_NAME}/gdb.setup "set solib-search-path ${GDB_SOLIB_PATH}\n")
file(APPEND ${ANDROID_APK_BUILD_DIR}/libs/${ANDROID_NDK_ABI_NAME}/gdb.setup "directory ${PROJECT_INCLUDES}\n")
# copy lib to obj
add_custom_command(TARGET ${TARGET_NAME}-gdb PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${GDB_SOLIB_PATH})
add_custom_command(TARGET ${TARGET_NAME}-gdb PRE_BUILD COMMAND cp ${TARGET_LOCATION} ${GDB_SOLIB_PATH})
# strip symbols
add_custom_command(TARGET ${TARGET_NAME}-gdb PRE_BUILD COMMAND ${CMAKE_STRIP} ${TARGET_LOCATION})
endif ()
# use androiddeployqt to create the apk
add_custom_target(${TARGET_NAME}-apk
COMMAND ${ANDROID_DEPLOY_QT} --input "${TARGET_NAME}-deployment.json" --output "${ANDROID_APK_OUTPUT_DIR}" --android-platform android-${ANDROID_API_LEVEL} ${ANDROID_DEPLOY_QT_INSTALL} --verbose --deployment bundled "\\$(ARGS)"
DEPENDS ${TARGET_NAME} ${TARGET_NAME}-copy-res ${TARGET_NAME}-copy-assets ${TARGET_NAME}-copy-java ${TARGET_NAME}-copy-libs ${TARGET_NAME}-gdb
)
# rename the APK if the caller asked us to
if (ANDROID_APK_CUSTOM_NAME)
add_custom_command(
TARGET ${TARGET_NAME}-apk
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename "${ANDROID_APK_OUTPUT_DIR}/bin/QtApp-debug.apk" "${ANDROID_APK_OUTPUT_DIR}/bin/${ANDROID_APK_CUSTOM_NAME}"
)
endif ()
endmacro()

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
{
"qt": "@QT_DIR@",
"sdk": "@ANDROID_SDK_ROOT@",
"ndk": "@ANDROID_NDK@",
"toolchain-prefix": "@ANDROID_TOOLCHAIN_MACHINE_NAME@",
"tool-prefix": "@ANDROID_TOOLCHAIN_MACHINE_NAME@",
"toolchain-version": "@ANDROID_COMPILER_VERSION@",
"ndk-host": "@ANDROID_NDK_HOST_SYSTEM_NAME@",
"target-architecture": "@ANDROID_ABI@",
"application-binary": "@EXECUTABLE_DESTINATION_PATH@",
"android-extra-libs": "@_DEPS@",
"android-package-source-directory": "@ANDROID_APK_BUILD_DIR@"
}

View file

@ -0,0 +1,11 @@
<?xml version='1.0' encoding='utf-8'?>
<!-- IMPORTANT: Do not manually manipulate this automatically generated file, changes will be gone after the next build! -->
<resources>
<string name="AppDisplayName">${ANDROID_APP_DISPLAY_NAME}</string>
<string name="ministro_not_found_msg">Can\'t find Ministro service.\nThe application can\'t start.</string>
<string name="ministro_needed_msg">This application requires Ministro service. Would you like to install it?</string>
<string name="fatal_error_msg">Your application encountered a fatal error and cannot continue.</string>
</resources>

15
cmake/externals/glm/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,15 @@
set(EXTERNAL_NAME glm)
include(ExternalProject)
ExternalProject_Add(
${EXTERNAL_NAME}
PREFIX ${EXTERNAL_NAME}
URL http://pkgs.fedoraproject.org/repo/pkgs/glm/glm-0.9.5.4.zip/fab76fc982b256b46208e5c750ed456a/glm-0.9.5.4.zip
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
LOG_DOWNLOAD ON
)
ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR)
string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE TYPE STRING)

25
cmake/externals/gverb/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,25 @@
set(EXTERNAL_NAME gverb)
if (ANDROID)
set(ANDROID_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}" "-DANDROID_NATIVE_API_LEVEL=19")
endif ()
include(ExternalProject)
ExternalProject_Add(
${EXTERNAL_NAME}
PREFIX ${EXTERNAL_NAME}
GIT_REPOSITORY https://github.com/birarda/gverb.git
CMAKE_ARGS ${ANDROID_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
LOG_DOWNLOAD ON
)
ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR)
string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${INSTALL_DIR}/include CACHE TYPE STRING)
if (WIN32)
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/gverb.lib CACHE TYPE STRING)
else ()
set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${INSTALL_DIR}/lib/libgverb.a CACHE TYPE STRING)
endif ()

View file

@ -0,0 +1,25 @@
#
# SetupExternalProject.cmake
# cmake/macros
#
# Copyright 2015 High Fidelity, Inc.
# Created by Stephen Birarda on February 13, 2014
#
# Distributed under the Apache License, Version 2.0.
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
#
macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME)
string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER)
if (NOT DEFINED GET_${_PROJ_NAME_UPPER} OR GET_${_PROJ_NAME_UPPER})
if (NOT TARGET ${_PROJ_NAME})
add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${CMAKE_BINARY_DIR}/externals/${_PROJ_NAME})
endif ()
add_dependencies(${TARGET_NAME} ${_PROJ_NAME})
endif ()
endmacro()

View file

@ -13,5 +13,11 @@ macro(AUTO_MTC)
file(GLOB INCLUDE_FILES src/*.h)
add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND mtc -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS mtc ${INCLUDE_FILES})
if (NOT ANDROID)
set(MTC_EXECUTABLE mtc)
else ()
set(MTC_EXECUTABLE $ENV{MTC_PATH}/mtc)
endif ()
add_custom_command(OUTPUT ${AUTOMTC_SRC} COMMAND ${MTC_EXECUTABLE} -o ${AUTOMTC_SRC} ${INCLUDE_FILES} DEPENDS ${MTC_EXECUTABLE} ${INCLUDE_FILES})
endmacro()

View file

@ -10,18 +10,21 @@
macro(HIFI_LIBRARY_SEARCH_HINTS LIBRARY_FOLDER)
string(TOUPPER ${LIBRARY_FOLDER} LIBRARY_PREFIX)
set(${LIBRARY_PREFIX}_SEARCH_DIRS "")
if (${LIBRARY_PREFIX}_ROOT_DIR)
set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}")
list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_ROOT_DIR}")
endif ()
if (ANDROID)
list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "/${LIBRARY_FOLDER}")
endif ()
if (DEFINED ENV{${LIBRARY_PREFIX}_ROOT_DIR})
set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "$ENV{${LIBRARY_PREFIX}_ROOT_DIR}")
list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "$ENV{${LIBRARY_PREFIX}_ROOT_DIR}")
endif ()
if (DEFINED ENV{HIFI_LIB_DIR})
set(${LIBRARY_PREFIX}_SEARCH_DIRS "${${LIBRARY_PREFIX}_SEARCH_DIRS}" "$ENV{HIFI_LIB_DIR}/${LIBRARY_FOLDER}")
list(APPEND ${LIBRARY_PREFIX}_SEARCH_DIRS "$ENV{HIFI_LIB_DIR}/${LIBRARY_FOLDER}")
endif ()
endmacro(HIFI_LIBRARY_SEARCH_HINTS _library_folder)

View file

@ -1,19 +0,0 @@
#
# IncludeGLM.cmake
#
# Copyright 2013 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
#
macro(INCLUDE_GLM)
find_package(GLM REQUIRED)
include_directories("${GLM_INCLUDE_DIRS}")
if (APPLE OR UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${GLM_INCLUDE_DIRS}")
endif ()
endmacro(INCLUDE_GLM)

View file

@ -32,5 +32,4 @@ macro(LINK_HIFI_LIBRARIES)
list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES})
endif()
endforeach()
endmacro(LINK_HIFI_LIBRARIES)

View file

@ -9,14 +9,18 @@
macro(SETUP_HIFI_LIBRARY)
project(${TARGET_NAME})
project(${TARGET_NAME})
# grab the implemenation and header files
file(GLOB_RECURSE LIB_SRCS "src/*.h" "src/*.cpp")
set(LIB_SRCS ${LIB_SRCS})
list(APPEND ${TARGET_NAME}_SRCS ${LIB_SRCS})
# create a library and set the property so it can be referenced later
add_library(${TARGET_NAME} ${LIB_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC})
if (${${TARGET_NAME}_SHARED})
add_library(${TARGET_NAME} SHARED ${LIB_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC} ${QT_RESOURCES_FILE})
else ()
add_library(${TARGET_NAME} ${LIB_SRCS} ${AUTOMTC_SRC} ${AUTOSCRIBE_SHADER_LIB_SRC} ${QT_RESOURCES_FILE})
endif ()
set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN})
list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core)

View file

@ -35,27 +35,34 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("bullet")
macro(_FIND_BULLET_LIBRARY _var)
find_library(${_var}
NAMES
${ARGN}
set(_${_var}_NAMES ${ARGN})
find_library(${_var}_LIBRARY_RELEASE
NAMES ${_${_var}_NAMES}
HINTS
${BULLET_SEARCH_DIRS}
$ENV{BULLET_ROOT_DIR}
${BULLET_ROOT}
${BULLET_ROOT}/out/release8/libs
${BULLET_ROOT}/out/debug8/libs
PATH_SUFFIXES lib lib/Release lib/Debug
PATH_SUFFIXES lib lib/Release out/release8/libs
)
mark_as_advanced(${_var})
endmacro()
macro(_BULLET_APPEND_LIBRARIES _list _release)
set(_debug ${_release}_DEBUG)
if(${_debug})
set(${_list} ${${_list}} optimized ${${_release}} debug ${${_debug}})
else()
set(${_list} ${${_list}} ${${_release}})
endif()
foreach(_NAME IN LISTS _${_var}_NAMES)
list(APPEND _${_var}_DEBUG_NAMES "${_NAME}_Debug")
list(APPEND _${_var}_DEBUG_NAMES "${_NAME}_d")
endforeach()
find_library(${_var}_LIBRARY_DEBUG
NAMES ${_${_var}_DEBUG_NAMES}
HINTS
${BULLET_SEARCH_DIRS}
$ENV{BULLET_ROOT_DIR}
${BULLET_ROOT}
PATH_SUFFIXES lib lib/Debug out/debug8/libs
)
select_library_configurations(${_var})
mark_as_advanced(${_var}_LIBRARY)
mark_as_advanced(${_var}_LIBRARY)
endmacro()
find_path(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h
@ -69,25 +76,18 @@ find_path(BULLET_INCLUDE_DIR NAMES btBulletCollisionCommon.h
# Find the libraries
_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY BulletDynamics)
_FIND_BULLET_LIBRARY(BULLET_DYNAMICS_LIBRARY_DEBUG BulletDynamics_Debug BulletDynamics_d)
_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY BulletCollision)
_FIND_BULLET_LIBRARY(BULLET_COLLISION_LIBRARY_DEBUG BulletCollision_Debug BulletCollision_d)
_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY BulletMath LinearMath)
_FIND_BULLET_LIBRARY(BULLET_MATH_LIBRARY_DEBUG BulletMath_Debug BulletMath_d LinearMath_Debug LinearMath_d)
_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY BulletSoftBody)
_FIND_BULLET_LIBRARY(BULLET_SOFTBODY_LIBRARY_DEBUG BulletSoftBody_Debug BulletSoftBody_d)
_FIND_BULLET_LIBRARY(BULLET_DYNAMICS BulletDynamics)
_FIND_BULLET_LIBRARY(BULLET_COLLISION BulletCollision)
_FIND_BULLET_LIBRARY(BULLET_MATH BulletMath LinearMath)
_FIND_BULLET_LIBRARY(BULLET_SOFTBODY BulletSoftBody)
set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR})
set(BULLET_LIBRARIES ${BULLET_DYNAMICS_LIBRARY} ${BULLET_COLLISION_LIBRARY} ${BULLET_MATH_LIBRARY} ${BULLET_SOFTBODY_LIBRARY})
find_package_handle_standard_args(Bullet "Could NOT find Bullet, try to set the path to Bullet root folder in the system variable BULLET_ROOT_DIR"
BULLET_DYNAMICS_LIBRARY BULLET_COLLISION_LIBRARY BULLET_MATH_LIBRARY
BULLET_INCLUDE_DIR
BULLET_INCLUDE_DIRS
BULLET_LIBRARIES
)
set(BULLET_INCLUDE_DIRS ${BULLET_INCLUDE_DIR})
if(BULLET_FOUND)
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_DYNAMICS_LIBRARY)
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_COLLISION_LIBRARY)
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_MATH_LIBRARY)
_BULLET_APPEND_LIBRARIES(BULLET_LIBRARIES BULLET_SOFTBODY_LIBRARY)
endif()

View file

@ -18,8 +18,7 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("glm")
# locate header
find_path(GLM_INCLUDE_DIR "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS})
set(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}")
find_path(GLM_INCLUDE_DIRS "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIRS)

View file

@ -15,25 +15,11 @@
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
#
if (GVERB_INCLUDE_DIRS)
# in cache already
set(GVERB_FOUND TRUE)
else (GVERB_INCLUDE_DIRS)
include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("gverb")
include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("gverb")
find_path(GVERB_INCLUDE_DIRS gverb.h PATH_SUFFIXES include HINTS ${GVERB_SEARCH_DIRS})
find_library(GVERB_LIBRARIES gverb PATH_SUFFIXES lib HINTS ${GVERB_SEARCH_DIRS})
find_path(GVERB_INCLUDE_DIRS gverb.h PATH_SUFFIXES include HINTS ${GVERB_SEARCH_DIRS})
find_path(GVERB_SRC_DIRS gverb.c PATH_SUFFIXES src HINTS ${GVERB_SEARCH_DIRS})
if (GVERB_INCLUDE_DIRS)
set(GVERB_FOUND TRUE)
endif (GVERB_INCLUDE_DIRS)
if (GVERB_FOUND)
message(STATUS "Found Gverb: ${GVERB_INCLUDE_DIRS}")
else (GVERB_FOUND)
message(FATAL_ERROR "Could NOT find Gverb. Read ./interface/externals/gverb/readme.txt")
endif (GVERB_FOUND)
endif(GVERB_INCLUDE_DIRS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GVERB DEFAULT_MSG GVERB_INCLUDE_DIRS GVERB_LIBRARIES)

View file

@ -21,42 +21,60 @@
include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("libovr")
find_path(LIBOVR_INCLUDE_DIRS OVR.h PATH_SUFFIXES Include HINTS ${LIBOVR_SEARCH_DIRS})
find_path(LIBOVR_SRC_DIR Util_Render_Stereo.h PATH_SUFFIXES Src/Util HINTS ${LIBOVR_SEARCH_DIRS})
include(SelectLibraryConfigurations)
if (APPLE)
find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Mac/Debug HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Mac/Release HINTS ${LIBOVR_SEARCH_DIRS})
find_library(ApplicationServices ApplicationServices)
find_library(IOKit IOKit)
elseif (UNIX)
find_library(UDEV_LIBRARY_RELEASE udev /usr/lib/x86_64-linux-gnu/)
find_library(XINERAMA_LIBRARY_RELEASE Xinerama /usr/lib/x86_64-linux-gnu/)
if (NOT ANDROID)
find_path(LIBOVR_INCLUDE_DIRS OVR.h PATH_SUFFIXES Include HINTS ${LIBOVR_SEARCH_DIRS})
find_path(LIBOVR_SRC_DIR Util_Render_Stereo.h PATH_SUFFIXES Src/Util HINTS ${LIBOVR_SEARCH_DIRS})
if (CMAKE_CL_64)
set(LINUX_ARCH_DIR "i386")
else()
set(LINUX_ARCH_DIR "x86_64")
endif()
if (APPLE)
find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Mac/Debug HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Mac/Release HINTS ${LIBOVR_SEARCH_DIRS})
find_library(ApplicationServices ApplicationServices)
find_library(IOKit IOKit)
elseif (UNIX)
find_library(UDEV_LIBRARY_RELEASE udev /usr/lib/x86_64-linux-gnu/)
find_library(XINERAMA_LIBRARY_RELEASE Xinerama /usr/lib/x86_64-linux-gnu/)
find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Linux/Debug/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Linux/Release/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
if (CMAKE_CL_64)
set(LINUX_ARCH_DIR "i386")
else()
set(LINUX_ARCH_DIR "x86_64")
endif()
select_library_configurations(UDEV)
select_library_configurations(XINERAMA)
find_library(LIBOVR_LIBRARY_DEBUG NAMES ovr PATH_SUFFIXES Lib/Linux/Debug/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES ovr PATH_SUFFIXES Lib/Linux/Release/${LINUX_ARCH_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
elseif (WIN32)
if (MSVC10)
find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS})
elseif (MSVC12)
find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS})
select_library_configurations(UDEV)
select_library_configurations(XINERAMA)
elseif (WIN32)
if (MSVC10)
find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2010 HINTS ${LIBOVR_SEARCH_DIRS})
elseif (MSVC12)
find_library(LIBOVR_LIBRARY_DEBUG NAMES libovrd PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES libovr PATH_SUFFIXES Lib/Win32/VS2013 HINTS ${LIBOVR_SEARCH_DIRS})
endif ()
find_package(ATL)
endif ()
find_package(ATL)
endif ()
else (NOT ANDROID)
set(_VRLIB_JNI_DIR "VRLib/jni")
set(_VRLIB_LIBS_DIR "VRLib/obj/local/armeabi-v7a")
find_path(LIBOVR_VRLIB_DIR VRLib.vcxproj PATH_SUFFIXES VRLib HINTS ${LIBOVR_SEARCH_DIRS})
find_path(LIBOVR_INCLUDE_DIRS OVR.h PATH_SUFFIXES ${_VRLIB_JNI_DIR}/LibOVR/Include HINTS ${LIBOVR_SEARCH_DIRS})
find_path(LIBOVR_SRC_DIR OVR_CAPI.h PATH_SUFFIXES ${_VRLIB_JNI_DIR}/LibOVR/Src HINTS ${LIBOVR_SEARCH_DIRS})
find_path(MINIZIP_DIR minizip.c PATH_SUFFIXES ${_VRLIB_JNI_DIR}/3rdParty/minizip HINTS ${LIBOVR_SEARCH_DIRS})
find_path(JNI_DIR VrCommon.h PATH_SUFFIXES ${_VRLIB_JNI_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
find_library(LIBOVR_LIBRARY_RELEASE NAMES oculus PATH_SUFFIXES ${_VRLIB_LIBS_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
find_library(TURBOJPEG_LIBRARY NAMES jpeg PATH_SUFFIXES 3rdParty/turbojpeg HINTS ${LIBOVR_SEARCH_DIRS})
endif (NOT ANDROID)
select_library_configurations(LIBOVR)
set(LIBOVR_LIBRARIES ${LIBOVR_LIBRARY})
@ -66,6 +84,10 @@ list(APPEND LIBOVR_ARGS_LIST LIBOVR_INCLUDE_DIRS LIBOVR_SRC_DIR LIBOVR_LIBRARY)
if (APPLE)
list(APPEND LIBOVR_LIBRARIES ${IOKit} ${ApplicationServices})
list(APPEND LIBOVR_ARGS_LIST IOKit ApplicationServices)
elseif (ANDROID)
list(APPEND LIBOVR_ANDROID_LIBRARIES "-lGLESv3" "-lEGL" "-landroid" "-lOpenMAXAL" "-llog" "-lz" "-lOpenSLES")
list(APPEND LIBOVR_ARGS_LIST LIBOVR_ANDROID_LIBRARIES LIBOVR_VRLIB_DIR MINIZIP_DIR JNI_DIR TURBOJPEG_LIBRARY)
elseif (UNIX)
list(APPEND LIBOVR_LIBRARIES "${UDEV_LIBRARY}" "${XINERAMA_LIBRARY}")
list(APPEND LIBOVR_ARGS_LIST UDEV_LIBRARY XINERAMA_LIBRARY)
@ -75,7 +97,10 @@ elseif (WIN32)
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibOVR DEFAULT_MSG ${LIBOVR_ARGS_LIST})
if (ANDROID)
list(APPEND LIBOVR_INCLUDE_DIRS ${LIBOVR_SRC_DIR} ${MINIZIP_DIR} ${JNI_DIR})
endif ()
mark_as_advanced(LIBOVR_INCLUDE_DIRS LIBOVR_LIBRARIES LIBOVR_SEARCH_DIRS)

View file

@ -52,7 +52,9 @@ else ()
set(_OPENSSL_ROOT_HINTS_AND_PATHS ${OPENSSL_SEARCH_DIRS})
endif ()
find_path(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_INCLUDEDIR} PATH_SUFFIXES include)
find_path(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_INCLUDEDIR}
PATH_SUFFIXES include
)
if (WIN32 AND NOT CYGWIN)
if (MSVC)
@ -133,7 +135,9 @@ else()
PATH_SUFFIXES lib
)
find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_LIBDIR} PATH_SUFFIXES lib)
find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto HINTS ${_OPENSSL_ROOT_HINTS_AND_PATHS} ${_OPENSSL_LIBDIR}
PATH_SUFFIXES lib
)
mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)
@ -179,8 +183,8 @@ endfunction()
if (OPENSSL_INCLUDE_DIR)
if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str
REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
REGEX "^#[ ]?define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
# The version number is encoded as 0xMNNFFPPS: major minor fix patch status
# The status gives if this is a developer or prerelease and is ignored here.
# Major, minor, and fix directly translate into the version numbers shown in

View file

@ -1,5 +1,5 @@
#
# FindRtMidd.cmake
# FindRtMidi.cmake
#
# Try to find the RtMidi library
#

View file

@ -0,0 +1,30 @@
#
# FindSoxr.cmake
#
# Try to find the libsoxr resampling library
#
# You can provide a LIBSOXR_ROOT_DIR which contains lib and include directories
#
# Once done this will define
#
# SOXR_FOUND - system found libsoxr
# SOXR_INCLUDE_DIRS - the libsoxr include directory
# SOXR_LIBRARIES - link to this to use libsoxr
#
# Created on 1/22/2015 by Stephen Birarda
# Copyright 2015 High Fidelity, Inc.
#
# Distributed under the Apache License, Version 2.0.
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
#
include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("soxr")
find_path(SOXR_INCLUDE_DIRS soxr.h PATH_SUFFIXES include HINTS ${SOXR_SEARCH_DIRS})
find_library(SOXR_LIBRARIES NAMES soxr PATH_SUFFIXES lib HINTS ${SOXR_SEARCH_DIRS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SOXR DEFAULT_MSG SOXR_INCLUDE_DIRS SOXR_LIBRARIES)
mark_as_advanced(SOXR_INCLUDE_DIRS SOXR_LIBRARIES SOXR_SEARCH_DIRS)

View file

@ -28,7 +28,7 @@ set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
if (APPLE)
set(_TBB_LIB_DIR "lib/libc++")
elseif (UNIX)
elseif (UNIX AND NOT ANDROID)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_TBB_ARCH_DIR "intel64")
else()
@ -56,6 +56,13 @@ elseif (WIN32)
endif()
set(_TBB_LIB_DIR "lib/${_TBB_ARCH_DIR}/vc12")
elseif (ANDROID)
set(_TBB_DEFAULT_INSTALL_DIR "/tbb")
set(_TBB_LIB_NAME "tbb")
set(_TBB_LIB_DIR "lib")
set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc")
set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug")
set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug")
endif ()
find_library(TBB_LIBRARY_DEBUG NAMES ${_TBB_LIB_NAME}_debug PATH_SUFFIXES ${_TBB_LIB_DIR} HINTS ${TBB_SEARCH_DIRS})

View file

@ -6,7 +6,7 @@
{
"name": "access_token",
"label": "Access Token",
"help": "This is an access token generated on the <a href='https://data.highfidelity.io/user/security' target='_blank'>My Security</a> page of your High Fidelity account.<br/>Generate a token with the 'domains' scope and paste it here.<br/>This is required to associate this domain-server with a domain in your account."
"help": "This is an access token generated on the <a href='https://metaverse.highfidelity.io/user/security' target='_blank'>My Security</a> page of your High Fidelity account.<br/>Generate a token with the 'domains' scope and paste it here.<br/>This is required to associate this domain-server with a domain in your account."
},
{
"name": "id",
@ -30,7 +30,7 @@
},
{
"value": "disabled",
"label": "None: use the network information I have entered for this domain at data.highfidelity.io"
"label": "None: use the network information I have entered for this domain at metaverse.highfidelity.io"
}
]
},
@ -73,6 +73,20 @@
"can_set": true
}
]
},
{
"name": "allowed_editors",
"type": "table",
"label": "Allowed Editors",
"help": "List the High Fidelity names for people you want to be able lock or unlock entities in this domain.<br/>An empty list means everyone.",
"numbered": false,
"columns": [
{
"name": "username",
"label": "Username",
"can_set": true
}
]
}
]
},
@ -395,6 +409,13 @@
"default": "",
"advanced": true
},
{
"name": "wantEditLogging",
"type": "checkbox",
"help": "Logging of all edits to entities",
"default": true,
"advanced": true
},
{
"name": "verboseDebug",
"type": "checkbox",
@ -433,4 +454,4 @@
}
]
}
]
]

View file

@ -652,7 +652,7 @@ function chooseFromHighFidelityDomains(clickedButton) {
clickedButton.attr('disabled', 'disabled')
// get a list of user domains from data-web
data_web_domains_url = "https://data.highfidelity.io/api/v1/domains?access_token="
data_web_domains_url = "https://metaverse.highfidelity.io/api/v1/domains?access_token="
$.getJSON(data_web_domains_url + Settings.initialValues.metaverse.access_token, function(data){
modal_buttons = {
@ -682,7 +682,7 @@ function chooseFromHighFidelityDomains(clickedButton) {
modal_buttons["success"] = {
label: 'Create new domain',
callback: function() {
window.open("https://data.highfidelity.io/user/domains", '_blank');
window.open("https://metaverse.highfidelity.io/user/domains", '_blank');
}
}
modal_body = "<p>You do not have any domains in your High Fidelity account." +

View file

@ -13,21 +13,22 @@
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include <QtCore/QDir>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtCore/QProcess>
#include <QtCore/qsharedmemory.h>
#include <QtCore/QStandardPaths>
#include <QtCore/QTimer>
#include <QtCore/QUrlQuery>
#include <QDir>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QProcess>
#include <QSharedMemory>
#include <QStandardPaths>
#include <QTimer>
#include <QUrlQuery>
#include <AccountManager.h>
#include <HifiConfigVariantMap.h>
#include <HTTPConnection.h>
#include <LogUtils.h>
#include <PacketHeaders.h>
#include <SettingHandle.h>
#include <SharedUtil.h>
#include <ShutdownEventListener.h>
#include <UUID.h>
@ -40,6 +41,11 @@ int const DomainServer::EXIT_CODE_REBOOT = 234923;
const QString ICE_SERVER_DEFAULT_HOSTNAME = "ice.highfidelity.io";
const QString ALLOWED_USERS_SETTINGS_KEYPATH = "security.allowed_users";
const QString ALLOWED_EDITORS_SETTINGS_KEYPATH = "security.allowed_editors";
DomainServer::DomainServer(int argc, char* argv[]) :
QCoreApplication(argc, argv),
_httpManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this),
@ -637,10 +643,16 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
// we got a packetUUID we didn't recognize, just add the node
nodeUUID = QUuid::createUuid();
}
SharedNodePointer newNode = DependencyManager::get<LimitedNodeList>()->addOrUpdateNode(nodeUUID, nodeType,
publicSockAddr, localSockAddr);
// if this user is in the editors list (or if the editors list is empty) set the user's node's canAdjustLocks to true
const QVariant* allowedEditorsVariant =
valueForKeyPath(_settingsManager.getSettingsMap(), ALLOWED_EDITORS_SETTINGS_KEYPATH);
QStringList allowedEditors = allowedEditorsVariant ? allowedEditorsVariant->toStringList() : QStringList();
bool canAdjustLocks = allowedEditors.isEmpty() || allowedEditors.contains(username);
SharedNodePointer newNode =
DependencyManager::get<LimitedNodeList>()->addOrUpdateNode(nodeUUID, nodeType,
publicSockAddr, localSockAddr, canAdjustLocks);
// when the newNode is created the linked data is also created
// if this was a static assignment set the UUID, set the sendingSockAddr
DomainServerNodeData* nodeData = reinterpret_cast<DomainServerNodeData*>(newNode->getLinkedData());
@ -662,7 +674,6 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
}
}
const QString ALLOWED_USERS_SETTINGS_KEYPATH = "security.allowed_users";
bool DomainServer::shouldAllowConnectionFromNode(const QString& username,
const QByteArray& usernameSignature,
@ -841,6 +852,7 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif
// always send the node their own UUID back
QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append);
broadcastDataStream << node->getUUID();
broadcastDataStream << node->getCanAdjustLocks();
int numBroadcastPacketLeadBytes = broadcastDataStream.device()->pos();
@ -905,10 +917,10 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif
}
});
}
// always write the last broadcastPacket
nodeList->writeDatagram(broadcastPacket, node, senderSockAddr);
}
// always write the last broadcastPacket
nodeList->writeDatagram(broadcastPacket, node, senderSockAddr);
}
void DomainServer::readAvailableDatagrams() {
@ -1712,6 +1724,7 @@ bool DomainServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl &u
.arg(authorizationCode, oauthRedirectURL().toString(), _oauthClientID, _oauthClientSecret);
QNetworkRequest tokenRequest(tokenRequestUrl);
tokenRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
tokenRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QNetworkReply* tokenReply = NetworkAccessManager::getInstance().post(tokenRequest, tokenPostBody.toLocal8Bit());
@ -1901,7 +1914,9 @@ QNetworkReply* DomainServer::profileRequestGivenTokenReply(QNetworkReply* tokenR
profileURL.setPath("/api/v1/user/profile");
profileURL.setQuery(QString("%1=%2").arg(OAUTH_JSON_ACCESS_TOKEN_KEY, accessToken));
return NetworkAccessManager::getInstance().get(QNetworkRequest(profileURL));
QNetworkRequest profileRequest(profileURL);
profileRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
return NetworkAccessManager::getInstance().get(profileRequest);
}
const QString DS_SETTINGS_SESSIONS_GROUP = "web-sessions";
@ -1920,10 +1935,8 @@ Headers DomainServer::setupCookieHeadersFromProfileReply(QNetworkReply* profileR
_cookieSessionHash.insert(cookieUUID, sessionData);
// persist the cookie to settings file so we can get it back on DS relaunch
QSettings localSettings;
localSettings.beginGroup(DS_SETTINGS_SESSIONS_GROUP);
QVariant sessionVariant = QVariant::fromValue(sessionData);
localSettings.setValue(cookieUUID.toString(), QVariant::fromValue(sessionData));
QStringList path = QStringList() << DS_SETTINGS_SESSIONS_GROUP << cookieUUID.toString();
Setting::Handle<QVariant>(path).set(QVariant::fromValue(sessionData));
// setup expiry for cookie to 1 month from today
QDateTime cookieExpiry = QDateTime::currentDateTimeUtc().addMonths(1);
@ -1943,11 +1956,12 @@ Headers DomainServer::setupCookieHeadersFromProfileReply(QNetworkReply* profileR
void DomainServer::loadExistingSessionsFromSettings() {
// read data for existing web sessions into memory so existing sessions can be leveraged
QSettings domainServerSettings;
Settings domainServerSettings;
domainServerSettings.beginGroup(DS_SETTINGS_SESSIONS_GROUP);
foreach(const QString& uuidKey, domainServerSettings.childKeys()) {
_cookieSessionHash.insert(QUuid(uuidKey), domainServerSettings.value(uuidKey).value<DomainServerWebSessionData>());
_cookieSessionHash.insert(QUuid(uuidKey),
domainServerSettings.value(uuidKey).value<DomainServerWebSessionData>());
qDebug() << "Pulled web session from settings - cookie UUID is" << uuidKey;
}
}

View file

@ -32,10 +32,4 @@ Script.update.connect(function() {
injector = Audio.playSound(sound, audioOptions);
print("Playing: " + injector);
}
});
Script.scriptEnding.connect(function() {
if (injector !== null) {
injector.stop();
}
});

118
examples/blocks.js Normal file
View file

@ -0,0 +1,118 @@
//
// Blocks.js
//
// Created by Philip Rosedale on January 26, 2015
// Copyright 2015 High Fidelity, Inc.
//
// Create a bunch of building blocks and drop them onto a playing surface in front of you.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var FLOOR_SIZE = 7.5;
var FLOOR_THICKNESS = 0.10;
var EDGE_THICKESS = 0.25;
var SCALE = 0.25;
var NUM_BLOCKS = 25;
var DROP_HEIGHT = SCALE * 8.0;
var GRAVITY = -1.0;
var LIFETIME = 6000;
var DAMPING = 0.50;
var blockTypes = [];
blockTypes.push({ x: 1, y: 1, z: 1, red: 255, green: 0, blue: 0 });
blockTypes.push({ x: 1, y: 1, z: 2, red: 0, green: 255, blue: 0 });
blockTypes.push({ x: 1, y: 2, z: 5, red: 0, green: 0, blue: 255 });
blockTypes.push({ x: 1, y: 2, z: 2, red: 255, green: 255, blue: 0 });
blockTypes.push({ x: 1, y: 1, z: 5, red: 0, green: 255, blue: 255 });
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(FLOOR_SIZE * 2.0, Quat.getFront(Camera.getOrientation())));
var floor = Entities.addEntity(
{ type: "Box",
position: Vec3.subtract(center, { x: 0, y: SCALE / 2.0, z: 0 }),
dimensions: { x: FLOOR_SIZE, y: FLOOR_THICKNESS, z: FLOOR_SIZE },
color: { red: 128, green: 128, blue: 128 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
locked: true,
lifetime: LIFETIME });
var edge1 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: FLOOR_SIZE / 2.0, y: FLOOR_THICKNESS / 2.0, z: 0 }),
dimensions: { x: EDGE_THICKESS, y: EDGE_THICKESS, z: FLOOR_SIZE },
color: { red: 128, green: 128, blue: 128 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: true,
locked: true,
lifetime: LIFETIME });
var edge2 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: -FLOOR_SIZE / 2.0, y: FLOOR_THICKNESS / 2.0, z: 0 }),
dimensions: { x: EDGE_THICKESS, y: EDGE_THICKESS, z: FLOOR_SIZE },
color: { red: 128, green: 128, blue: 128 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: true,
locked: true,
lifetime: LIFETIME });
var edge3 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: 0, y: FLOOR_THICKNESS / 2.0, z: -FLOOR_SIZE / 2.0 }),
dimensions: { x: FLOOR_SIZE, y: EDGE_THICKESS, z: EDGE_THICKESS },
color: { red: 128, green: 128, blue: 128 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: true,
locked: true,
lifetime: LIFETIME });
var edge4 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: 0, y: FLOOR_THICKNESS / 2.0, z: FLOOR_SIZE / 2.0 }),
dimensions: { x: FLOOR_SIZE, y: EDGE_THICKESS, z: EDGE_THICKESS },
color: { red: 128, green: 128, blue: 128 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: true,
locked: true,
lifetime: LIFETIME });
blocks = [];
for (var i = 0; i < NUM_BLOCKS; i++) {
var which = Math.floor(Math.random() * blockTypes.length);
var type = blockTypes[which];
blocks.push(Entities.addEntity(
{ type: "Box",
position: { x: center.x + (Math.random() - 0.5) * (FLOOR_SIZE * 0.75),
y: center.y + DROP_HEIGHT,
z: center.z + (Math.random() - 0.5) * (FLOOR_SIZE * 0.75) },
dimensions: { x: type.x * SCALE, y: type.y * SCALE, z: type.z * SCALE },
color: { red: type.red, green: type.green, blue: type.blue },
gravity: { x: 0, y: GRAVITY, z: 0 },
ignoreCollisions: false,
damping: DAMPING,
lifetime: LIFETIME,
collisionsWillMove: true }));
}
function scriptEnding() {
Entities.deleteEntity(edge1);
Entities.deleteEntity(edge2);
Entities.deleteEntity(edge3);
Entities.deleteEntity(edge4);
Entities.deleteEntity(floor);
for (var i = 0; i < NUM_BLOCKS; i++) {
Entities.deleteEntity(blocks[i]);
}
}
Script.scriptEnding.connect(scriptEnding);

View file

@ -85,10 +85,10 @@ function checkHands(deltaTime) {
var chord = Controller.getTriggerValue(chordHand);
if (volume > 1.0) volume = 1.0;
if ((chord > 0.1) && Audio.isInjectorPlaying(soundPlaying)) {
if ((chord > 0.1) && soundPlaying.isPlaying) {
// If chord finger trigger pulled, stop current chord
print("stopped sound");
Audio.stopInjector(soundPlaying);
soundPlaying.stop();
}
var BUTTON_COUNT = 6;
@ -132,16 +132,21 @@ function checkHands(deltaTime) {
}
function playChord(position, volume) {
if (Audio.isInjectorPlaying(soundPlaying)) {
if (soundPlaying.isPlaying) {
print("stopped sound");
Audio.stopInjector(soundPlaying);
soundPlaying.stop();
}
print("Played sound: " + whichChord + " at volume " + options.volume);
soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], {
position: position,
volume: volume
});
if (!soundPlaying) {
soundPlaying = Audio.playSound(chords[guitarSelector + whichChord], {
position: position,
volume: volume
});
} else {
soundPlaying.restart();
}
}
function keyPressEvent(event) {

View file

@ -47,7 +47,6 @@ var yawFromMouse = 0;
var pitchFromMouse = 0;
var isMouseDown = false;
var BULLET_VELOCITY = 5.0;
var MIN_THROWER_DELAY = 1000;
var MAX_THROWER_DELAY = 1000;
var LEFT_BUTTON_3 = 3;
@ -98,7 +97,7 @@ var reticle = Overlays.addOverlay("image", {
y: screenSize.y / 2 - 16,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/reticle.png",
imageURL: HIFI_PUBLIC_BUCKET + "images/billiardsReticle.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
@ -113,6 +112,25 @@ var offButton = Overlays.addOverlay("image", {
alpha: 1
});
var platformButton = Overlays.addOverlay("image", {
x: screenSize.x - 48,
y: 130,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/city.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
var gridButton = Overlays.addOverlay("image", {
x: screenSize.x - 48,
y: 164,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/blocks.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
if (showScore) {
var text = Overlays.addOverlay("text", {
x: screenSize.x / 2 - 100,
@ -127,24 +145,30 @@ if (showScore) {
});
}
function printVector(string, vector) {
print(string + " " + vector.x + ", " + vector.y + ", " + vector.z);
}
var BULLET_VELOCITY = 10.0;
function shootBullet(position, velocity) {
var BULLET_SIZE = 0.07;
function shootBullet(position, velocity, grenade) {
var BULLET_SIZE = 0.10;
var BULLET_LIFETIME = 10.0;
var BULLET_GRAVITY = 0.0;
var BULLET_GRAVITY = -0.25;
var GRENADE_VELOCITY = 15.0;
var GRENADE_SIZE = 0.35;
var GRENADE_GRAVITY = -9.8;
var bVelocity = grenade ? Vec3.multiply(GRENADE_VELOCITY, Vec3.normalize(velocity)) : velocity;
var bSize = grenade ? GRENADE_SIZE : BULLET_SIZE;
var bGravity = grenade ? GRENADE_GRAVITY : BULLET_GRAVITY;
bulletID = Entities.addEntity(
{ type: "Sphere",
position: position,
dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE },
dimensions: { x: bSize, y: bSize, z: bSize },
color: { red: 255, green: 0, blue: 0 },
velocity: velocity,
velocity: bVelocity,
lifetime: BULLET_LIFETIME,
gravity: { x: 0, y: BULLET_GRAVITY, z: 0 },
gravity: { x: 0, y: bGravity, z: 0 },
damping: 0.01,
density: 5000,
density: 8000,
ignoreCollisions: false,
collisionsWillMove: true
});
@ -158,13 +182,15 @@ function shootBullet(position, velocity) {
}
// Kickback the arm
if (elbowKickAngle > 0.0) {
MyAvatar.setJointData("LeftForeArm", rotationBeforeKickback);
}
rotationBeforeKickback = MyAvatar.getJointRotation("LeftForeArm");
var armRotation = MyAvatar.getJointRotation("LeftForeArm");
armRotation = Quat.multiply(armRotation, Quat.fromPitchYawRollDegrees(0.0, 0.0, KICKBACK_ANGLE));
MyAvatar.setJointData("LeftForeArm", armRotation);
elbowKickAngle = KICKBACK_ANGLE;
}
function shootTarget() {
var TARGET_SIZE = 0.50;
var TARGET_GRAVITY = 0.0;
@ -174,7 +200,7 @@ function shootTarget() {
var DISTANCE_TO_LAUNCH_FROM = 5.0;
var ANGLE_RANGE_FOR_LAUNCH = 20.0;
var camera = Camera.getPosition();
//printVector("camera", camera);
var targetDirection = Quat.angleAxis(getRandomFloat(-ANGLE_RANGE_FOR_LAUNCH, ANGLE_RANGE_FOR_LAUNCH), { x:0, y:1, z:0 });
targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection);
var forwardVector = Quat.getFront(targetDirection);
@ -205,8 +231,79 @@ function shootTarget() {
Audio.playSound(targetLaunchSound, audioOptions);
}
function entityCollisionWithEntity(entity1, entity2, collision) {
function makeGrid(type, scale, size) {
var separation = scale * 2;
var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation())));
var x, y, z;
var GRID_LIFE = 60.0;
var dimensions;
for (x = 0; x < size; x++) {
for (y = 0; y < size; y++) {
for (z = 0; z < size; z++) {
dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/2.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) / 4.0 };
Entities.addEntity(
{ type: type,
position: { x: pos.x + x * separation, y: pos.y + y * separation, z: pos.z + z * separation },
dimensions: dimensions,
color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 },
velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: 0, z: 0 },
lifetime: GRID_LIFE,
rotation: Camera.getOrientation(),
damping: 0.1,
density: 100.0,
collisionsWillMove: true });
}
}
}
}
function makePlatform(gravity, scale, size) {
var separation = scale * 2;
var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation())));
pos.y -= separation * size;
var x, y, z;
var TARGET_LIFE = 60.0;
var INITIAL_GAP = 0.5;
var dimensions;
for (x = 0; x < size; x++) {
for (y = 0; y < size; y++) {
for (z = 0; z < size; z++) {
dimensions = { x: separation/2.0, y: separation, z: separation/2.0 };
Entities.addEntity(
{ type: "Box",
position: { x: pos.x - (separation * size / 2.0) + x * separation,
y: pos.y + y * (separation + INITIAL_GAP),
z: pos.z - (separation * size / 2.0) + z * separation },
dimensions: dimensions,
color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 },
velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: gravity, z: 0 },
lifetime: TARGET_LIFE,
damping: 0.1,
density: 100.0,
collisionsWillMove: true });
}
}
}
// Make a floor for this stuff to fall onto
Entities.addEntity({
type: "Box",
position: { x: pos.x, y: pos.y - separation / 2.0, z: pos.z },
dimensions: { x: 2.0 * separation * size, y: separation / 2.0, z: 2.0 * separation * size },
color: { red: 128, green: 128, blue: 128 },
lifetime: TARGET_LIFE
});
}
function entityCollisionWithEntity(entity1, entity2, collision) {
if (((entity1.id == bulletID.id) || (entity1.id == targetID.id)) &&
((entity2.id == bulletID.id) || (entity2.id == targetID.id))) {
score++;
@ -233,7 +330,9 @@ function keyPressEvent(event) {
var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY;
Script.setTimeout(shootTarget, time);
} else if ((event.text == ".") || (event.text == "SPACE")) {
shootFromMouse();
shootFromMouse(false);
} else if (event.text == ",") {
shootFromMouse(true);
} else if (event.text == "r") {
playLoadSound();
} else if (event.text == "s") {
@ -241,7 +340,6 @@ function keyPressEvent(event) {
Quat.print("arm = ", MyAvatar.getJointRotation("LeftArm"));
Quat.print("forearm = ", MyAvatar.getJointRotation("LeftForeArm"));
Quat.print("hand = ", MyAvatar.getJointRotation("LeftHand"));
}
}
@ -287,18 +385,7 @@ function update(deltaTime) {
if (targetID && !targetID.isKnownID) {
targetID = Entities.identifyEntity(targetID);
}
// Check for mouseLook movement, update rotation
// rotate body yaw for yaw received from mouse
var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } ));
//MyAvatar.orientation = newOrientation;
yawFromMouse = 0;
// apply pitch from mouse
var newPitch = MyAvatar.headPitch + pitchFromMouse;
//MyAvatar.headPitch = newPitch;
pitchFromMouse = 0;
if (activeControllers == 0) {
if (Controller.getNumberOfSpatialControls() > 0) {
activeControllers = Controller.getNumberOfSpatialControls();
@ -372,19 +459,19 @@ function update(deltaTime) {
var velocity = Vec3.multiply(BULLET_VELOCITY, Vec3.normalize(palmToFingerTipVector));
shootBullet(position, velocity);
shootBullet(position, velocity, false);
}
}
}
}
function shootFromMouse() {
function shootFromMouse(grenade) {
var DISTANCE_FROM_CAMERA = 1.0;
var camera = Camera.getPosition();
var forwardVector = Quat.getFront(Camera.getOrientation());
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_FROM_CAMERA));
var velocity = Vec3.multiply(forwardVector, BULLET_VELOCITY);
shootBullet(newPosition, velocity);
shootBullet(newPosition, velocity, grenade);
}
function mouseReleaseEvent(event) {
@ -392,25 +479,29 @@ function mouseReleaseEvent(event) {
isMouseDown = false;
}
function mouseMoveEvent(event) {
if (isMouseDown) {
var MOUSE_YAW_SCALE = -0.25;
var MOUSE_PITCH_SCALE = -12.5;
var FIXED_MOUSE_TIMESTEP = 0.016;
yawFromMouse += ((event.x - lastX) * MOUSE_YAW_SCALE * FIXED_MOUSE_TIMESTEP);
pitchFromMouse += ((event.y - lastY) * MOUSE_PITCH_SCALE * FIXED_MOUSE_TIMESTEP);
lastX = event.x;
lastY = event.y;
}
function mousePressEvent(event) {
var clickedText = false;
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
if (clickedOverlay == offButton) {
Script.stop();
} else if (clickedOverlay == platformButton) {
var platformSize = 3;
makePlatform(-9.8, 1.0, platformSize);
} else if (clickedOverlay == gridButton) {
makeGrid("Box", 1.0, 3);
}
}
function scriptEnding() {
Overlays.deleteOverlay(reticle);
Overlays.deleteOverlay(offButton);
Overlays.deleteOverlay(platformButton);
Overlays.deleteOverlay(gridButton);
Overlays.deleteOverlay(pointer[0]);
Overlays.deleteOverlay(pointer[1]);
Overlays.deleteOverlay(text);
MyAvatar.detachOne(gunModel);
MyAvatar.detachOne(gunModel);
clearPose();
}
@ -418,7 +509,7 @@ Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
Script.scriptEnding.connect(scriptEnding);
Script.update.connect(update);
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
Controller.mouseMoveEvent.connect(mouseMoveEvent);
Controller.mousePressEvent.connect(mousePressEvent);
Controller.keyPressEvent.connect(keyPressEvent);

View file

@ -14,17 +14,13 @@
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("libraries/entityPropertyDialogBox.js");
Script.include("../../libraries/entityPropertyDialogBox.js");
var entityPropertyDialogBox = EntityPropertyDialogBox;
var LASER_WIDTH = 4;
var LASER_COLOR = { red: 255, green: 0, blue: 0 };
var LASER_LENGTH_FACTOR = 500;
var MIN_ANGULAR_SIZE = 2;
var MAX_ANGULAR_SIZE = 45;
var allowLargeModels = false;
var allowSmallModels = false;
var allowLargeModels = true;
var allowSmallModels = true;
var wantEntityGlow = false;
var LEFT = 0;
@ -32,7 +28,45 @@ var RIGHT = 1;
var jointList = MyAvatar.getJointNames();
var mode = 0;
var LASER_WIDTH = 3;
var LASER_COLOR = { red: 50, green: 150, blue: 200 };
var DROP_COLOR = { red: 200, green: 200, blue: 200 };
var DROP_WIDTH = 4;
var DROP_DISTANCE = 5.0;
var LASER_LENGTH_FACTOR = 500;
var velocity = { x: 0, y: 0, z: 0 };
var lastAccurateIntersection = null;
var accurateIntersections = 0;
var totalIntersections = 0;
var inaccurateInARow = 0;
var maxInaccurateInARow = 0;
function getRayIntersection(pickRay) { // pickRay : { origin : {xyz}, direction : {xyz} }
if (lastAccurateIntersection === null) {
lastAccurateIntersection = Entities.findRayIntersectionBlocking(pickRay);
} else {
var intersection = Entities.findRayIntersection(pickRay);
if (intersection.accurate) {
lastAccurateIntersection = intersection;
accurateIntersections++;
maxInaccurateInARow = (maxInaccurateInARow > inaccurateInARow) ? maxInaccurateInARow : inaccurateInARow;
inaccurateInARow = 0;
} else {
inaccurateInARow++;
}
totalIntersections++;
}
return lastAccurateIntersection;
}
function printIntersectionsStats() {
var ratio = accurateIntersections / totalIntersections;
print("Out of " + totalIntersections + " intersections, " + accurateIntersections + " where accurate. (" + ratio * 100 +"%)");
print("Worst case was " + maxInaccurateInARow + " inaccurate intersections in a row.");
}
function controller(wichSide) {
this.side = wichSide;
@ -42,10 +76,10 @@ function controller(wichSide) {
this.bumper = 6 * wichSide + 5;
this.oldPalmPosition = Controller.getSpatialControlPosition(this.palm);
this.palmPosition = Controller.getSpatialControlPosition(this.palm);
this.palmPosition = this.oldPalmPosition;
this.oldTipPosition = Controller.getSpatialControlPosition(this.tip);
this.tipPosition = Controller.getSpatialControlPosition(this.tip);
this.tipPosition = this.oldTipPosition;
this.oldUp = Controller.getSpatialControlNormal(this.palm);
this.up = this.oldUp;
@ -74,8 +108,9 @@ function controller(wichSide) {
this.positionAtGrab;
this.rotationAtGrab;
this.gravityAtGrab;
this.modelPositionAtGrab;
this.rotationAtGrab;
this.modelRotationAtGrab;
this.jointsIntersectingFromStart = [];
this.laser = Overlays.addOverlay("line3d", {
@ -88,6 +123,14 @@ function controller(wichSide) {
anchor: "MyAvatar"
});
this.dropLine = Overlays.addOverlay("line3d", {
start: { x: 0, y: 0, z: 0 },
end: { x: 0, y: 0, z: 0 },
color: DROP_COLOR,
alpha: 1,
visible: false,
lineWidth: DROP_WIDTH });
this.guideScale = 0.02;
this.ball = Overlays.addOverlay("sphere", {
position: { x: 0, y: 0, z: 0 },
@ -125,6 +168,7 @@ function controller(wichSide) {
this.entityID = entityID;
this.modelURL = properties.modelURL;
this.oldModelPosition = properties.position;
this.oldModelRotation = properties.rotation;
this.oldModelHalfDiagonal = Vec3.length(properties.dimensions) / 2.0;
@ -132,7 +176,11 @@ function controller(wichSide) {
this.positionAtGrab = this.palmPosition;
this.rotationAtGrab = this.rotation;
this.modelPositionAtGrab = properties.position;
this.rotationAtGrab = properties.rotation;
this.modelRotationAtGrab = properties.rotation;
this.gravityAtGrab = properties.gravity;
Entities.editEntity(entityID, { gravity: { x: 0, y: 0, z: 0 }, velocity: { x: 0, y: 0, z: 0 } });
this.jointsIntersectingFromStart = [];
for (var i = 0; i < jointList.length; i++) {
var distance = Vec3.distance(MyAvatar.getJointPosition(jointList[i]), this.oldModelPosition);
@ -141,10 +189,14 @@ function controller(wichSide) {
}
}
this.showLaser(false);
Overlays.editOverlay(this.dropLine, { visible: true });
}
this.release = function () {
if (this.grabbing) {
Entities.editEntity(this.entityID, { gravity: this.gravityAtGrab });
jointList = MyAvatar.getJointNames();
var closestJointIndex = -1;
@ -183,6 +235,8 @@ function controller(wichSide) {
Entities.deleteEntity(this.entityID);
}
}
Overlays.editOverlay(this.dropLine, { visible: false });
}
this.grabbing = false;
@ -245,9 +299,9 @@ function controller(wichSide) {
var inverseRotation = Quat.inverse(MyAvatar.orientation);
var startPosition = Vec3.multiplyQbyV(inverseRotation, Vec3.subtract(this.palmPosition, MyAvatar.position));
startPosition = Vec3.multiply(startPosition, 1 / MyAvatar.scale);
var direction = Vec3.multiplyQbyV(inverseRotation, Vec3.subtract(this.tipPosition, this.palmPosition));
var distance = Vec3.length(direction);
direction = Vec3.multiply(direction, LASER_LENGTH_FACTOR / distance);
direction = Vec3.multiply(direction, LASER_LENGTH_FACTOR / (Vec3.length(direction) * MyAvatar.scale));
var endPosition = Vec3.sum(startPosition, direction);
Overlays.editOverlay(this.laser, {
@ -255,7 +309,6 @@ function controller(wichSide) {
end: endPosition
});
Overlays.editOverlay(this.ball, {
position: endPosition
});
@ -267,17 +320,16 @@ function controller(wichSide) {
start: Vec3.sum(endPosition, Vec3.multiply(this.up, 2 * this.guideScale)),
end: Vec3.sum(endPosition, Vec3.multiply(this.up, -2 * this.guideScale))
});
this.showLaser(!this.grabbing || mode == 0);
this.showLaser(!this.grabbing);
if (this.glowedIntersectingModel.isKnownID) {
Entities.editEntity(this.glowedIntersectingModel, { glowLevel: 0.0 });
this.glowedIntersectingModel.isKnownID = false;
}
if (!this.grabbing) {
var intersection = Entities.findRayIntersection({
origin: this.palmPosition,
direction: this.front
});
var intersection = getRayIntersection({ origin: this.palmPosition,
direction: this.front
});
var halfDiagonal = Vec3.length(intersection.properties.dimensions) / 2.0;
@ -300,67 +352,46 @@ function controller(wichSide) {
Overlays.editOverlay(this.leftRight, { visible: show });
Overlays.editOverlay(this.topDown, { visible: show });
}
this.moveEntity = function () {
this.moveEntity = function (deltaTime) {
if (this.grabbing) {
if (!this.entityID.isKnownID) {
print("Unknown grabbed ID " + this.entityID.id + ", isKnown: " + this.entityID.isKnownID);
this.entityID = Entities.findRayIntersection({
origin: this.palmPosition,
direction: this.front
}).entityID;
this.entityID = getRayIntersection({ origin: this.palmPosition,
direction: this.front
}).entityID;
print("Identified ID " + this.entityID.id + ", isKnown: " + this.entityID.isKnownID);
}
var newPosition;
var newRotation;
switch (mode) {
case 0:
newPosition = Vec3.sum(this.palmPosition,
Vec3.multiply(this.front, this.x));
newPosition = Vec3.sum(newPosition,
Vec3.multiply(this.up, this.y));
newPosition = Vec3.sum(newPosition,
Vec3.multiply(this.right, this.z));
newRotation = Quat.multiply(this.rotation,
Quat.inverse(this.oldRotation));
newRotation = Quat.multiply(newRotation,
this.oldModelRotation);
break;
case 1:
var forward = Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -1 });
var d = Vec3.dot(forward, MyAvatar.position);
var factor1 = Vec3.dot(forward, this.positionAtGrab) - d;
var factor2 = Vec3.dot(forward, this.modelPositionAtGrab) - d;
var vector = Vec3.subtract(this.palmPosition, this.positionAtGrab);
if (factor2 < 0) {
factor2 = 0;
}
if (factor1 <= 0) {
factor1 = 1;
factor2 = 1;
}
newPosition = Vec3.sum(this.modelPositionAtGrab,
Vec3.multiply(vector,
factor2 / factor1));
newRotation = Quat.multiply(this.rotation,
Quat.inverse(this.rotationAtGrab));
newRotation = Quat.multiply(newRotation,
this.rotationAtGrab);
break;
var CONSTANT_SCALING_FACTOR = 5.0;
var MINIMUM_SCALING_DISTANCE = 2.0;
var distanceToModel = Vec3.length(Vec3.subtract(this.oldModelPosition, this.palmPosition));
if (distanceToModel < MINIMUM_SCALING_DISTANCE) {
distanceToModel = MINIMUM_SCALING_DISTANCE;
}
var deltaPalm = Vec3.multiply(distanceToModel * CONSTANT_SCALING_FACTOR, Vec3.subtract(this.palmPosition, this.oldPalmPosition));
newPosition = Vec3.sum(this.oldModelPosition, deltaPalm);
newRotation = Quat.multiply(this.rotation,
Quat.inverse(this.rotationAtGrab));
newRotation = Quat.multiply(newRotation, newRotation);
newRotation = Quat.multiply(newRotation,
this.modelRotationAtGrab);
velocity = Vec3.multiply(1.0 / deltaTime, Vec3.subtract(newPosition, this.oldModelPosition));
Entities.editEntity(this.entityID, {
position: newPosition,
rotation: newRotation
rotation: newRotation,
velocity: velocity
});
this.oldModelRotation = newRotation;
this.oldModelPosition = newPosition;
Overlays.editOverlay(this.dropLine, { start: newPosition, end: Vec3.sum(newPosition, { x: 0, y: -DROP_DISTANCE, z: 0 }) });
var indicesToRemove = [];
for (var i = 0; i < this.jointsIntersectingFromStart.length; ++i) {
var distance = Vec3.distance(MyAvatar.getJointPosition(this.jointsIntersectingFromStart[i]), this.oldModelPosition);
@ -396,17 +427,6 @@ function controller(wichSide) {
this.triggerValue = Controller.getTriggerValue(this.trigger);
var bumperValue = Controller.isButtonPressed(this.bumper);
if (bumperValue && !this.bumperValue) {
if (mode == 0) {
mode = 1;
Overlays.editOverlay(leftController.laser, { color: { red: 0, green: 0, blue: 255 } });
Overlays.editOverlay(rightController.laser, { color: { red: 0, green: 0, blue: 255 } });
} else {
mode = 0;
Overlays.editOverlay(leftController.laser, { color: { red: 255, green: 0, blue: 0 } });
Overlays.editOverlay(rightController.laser, { color: { red: 255, green: 0, blue: 0 } });
}
}
this.bumperValue = bumperValue;
@ -475,10 +495,10 @@ function controller(wichSide) {
Vec3.print("Looking at: ", this.palmPosition);
var pickRay = { origin: this.palmPosition,
direction: Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)) };
var foundIntersection = Entities.findRayIntersection(pickRay);
var foundIntersection = getRayIntersection(pickRay);
if(!foundIntersection.accurate) {
print("No accurate intersection");
if(!foundIntersection.intersects) {
print("No intersection");
return;
}
newModel = foundIntersection.entityID;
@ -518,61 +538,37 @@ function controller(wichSide) {
var leftController = new controller(LEFT);
var rightController = new controller(RIGHT);
function moveEntities() {
function moveEntities(deltaTime) {
if (leftController.grabbing && rightController.grabbing && rightController.entityID.id == leftController.entityID.id) {
var newPosition = leftController.oldModelPosition;
var rotation = leftController.oldModelRotation;
var ratio = 1;
var u = Vec3.normalize(Vec3.subtract(rightController.oldPalmPosition, leftController.oldPalmPosition));
var v = Vec3.normalize(Vec3.subtract(rightController.palmPosition, leftController.palmPosition));
switch (mode) {
case 0:
var oldLeftPoint = Vec3.sum(leftController.oldPalmPosition, Vec3.multiply(leftController.oldFront, leftController.x));
var oldRightPoint = Vec3.sum(rightController.oldPalmPosition, Vec3.multiply(rightController.oldFront, rightController.x));
var oldMiddle = Vec3.multiply(Vec3.sum(oldLeftPoint, oldRightPoint), 0.5);
var oldLength = Vec3.length(Vec3.subtract(oldLeftPoint, oldRightPoint));
var leftPoint = Vec3.sum(leftController.palmPosition, Vec3.multiply(leftController.front, leftController.x));
var rightPoint = Vec3.sum(rightController.palmPosition, Vec3.multiply(rightController.front, rightController.x));
var middle = Vec3.multiply(Vec3.sum(leftPoint, rightPoint), 0.5);
var length = Vec3.length(Vec3.subtract(leftPoint, rightPoint));
ratio = length / oldLength;
newPosition = Vec3.sum(middle,
Vec3.multiply(Vec3.subtract(leftController.oldModelPosition, oldMiddle), ratio));
break;
case 1:
var u = Vec3.normalize(Vec3.subtract(rightController.oldPalmPosition, leftController.oldPalmPosition));
var v = Vec3.normalize(Vec3.subtract(rightController.palmPosition, leftController.palmPosition));
var cos_theta = Vec3.dot(u, v);
if (cos_theta > 1) {
cos_theta = 1;
}
var angle = Math.acos(cos_theta) / Math.PI * 180;
if (angle < 0.1) {
return;
}
var w = Vec3.normalize(Vec3.cross(u, v));
rotation = Quat.multiply(Quat.angleAxis(angle, w), leftController.oldModelRotation);
leftController.positionAtGrab = leftController.palmPosition;
leftController.rotationAtGrab = leftController.rotation;
leftController.modelPositionAtGrab = leftController.oldModelPosition;
leftController.rotationAtGrab = rotation;
rightController.positionAtGrab = rightController.palmPosition;
rightController.rotationAtGrab = rightController.rotation;
rightController.modelPositionAtGrab = rightController.oldModelPosition;
rightController.rotationAtGrab = rotation;
break;
var cos_theta = Vec3.dot(u, v);
if (cos_theta > 1) {
cos_theta = 1;
}
var angle = Math.acos(cos_theta) / Math.PI * 180;
if (angle < 0.1) {
return;
}
var w = Vec3.normalize(Vec3.cross(u, v));
rotation = Quat.multiply(Quat.angleAxis(angle, w), leftController.oldModelRotation);
leftController.positionAtGrab = leftController.palmPosition;
leftController.rotationAtGrab = leftController.rotation;
leftController.modelPositionAtGrab = leftController.oldModelPosition;
leftController.modelRotationAtGrab = rotation;
rightController.positionAtGrab = rightController.palmPosition;
rightController.rotationAtGrab = rightController.rotation;
rightController.modelPositionAtGrab = rightController.oldModelPosition;
rightController.modelRotationAtGrab = rotation;
Entities.editEntity(leftController.entityID, {
position: newPosition,
rotation: rotation,
@ -582,7 +578,6 @@ function moveEntities() {
y: leftController.oldModelHalfDiagonal * ratio,
z: leftController.oldModelHalfDiagonal * ratio }
});
leftController.oldModelPosition = newPosition;
leftController.oldModelRotation = rotation;
@ -593,8 +588,8 @@ function moveEntities() {
rightController.oldModelHalfDiagonal *= ratio;
return;
}
leftController.moveEntity();
rightController.moveEntity();
leftController.moveEntity(deltaTime);
rightController.moveEntity(deltaTime);
}
var hydraConnected = false;
@ -612,7 +607,7 @@ function checkController(deltaTime) {
leftController.update();
rightController.update();
moveEntities();
moveEntities(deltaTime);
} else {
if (hydraConnected) {
hydraConnected = false;
@ -628,43 +623,56 @@ var glowedEntityID = { id: -1, isKnownID: false };
// In order for editVoxels and editModels to play nice together, they each check to see if a "delete" menu item already
// exists. If it doesn't they add it. If it does they don't. They also only delete the menu item if they were the one that
// added it.
var ROOT_MENU = "Edit";
var ITEM_BEFORE = "Physics";
var MENU_SEPARATOR = "Models";
var EDIT_PROPERTIES = "Edit Properties...";
var INTERSECTION_STATS = "Print Intersection Stats";
var DELETE = "Delete";
var LARGE_MODELS = "Allow Selecting of Large Models";
var SMALL_MODELS = "Allow Selecting of Small Models";
var LIGHTS = "Allow Selecting of Lights";
var modelMenuAddedDelete = false;
var originalLightsArePickable = Entities.getLightsArePickable();
function setupModelMenus() {
print("setupModelMenus()");
// adj our menuitems
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Models", isSeparator: true, beforeItem: "Physics" });
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Edit Properties...",
shortcutKeyEvent: { text: "`" }, afterItem: "Models" });
if (!Menu.menuItemExists("Edit", "Delete")) {
Menu.addMenuItem({ menuName: ROOT_MENU, menuItemName: MENU_SEPARATOR, isSeparator: true, beforeItem: ITEM_BEFORE });
Menu.addMenuItem({ menuName: ROOT_MENU, menuItemName: EDIT_PROPERTIES,
shortcutKeyEvent: { text: "`" }, afterItem: MENU_SEPARATOR });
Menu.addMenuItem({ menuName: ROOT_MENU, menuItemName: INTERSECTION_STATS, afterItem: MENU_SEPARATOR });
if (!Menu.menuItemExists(ROOT_MENU, DELETE)) {
print("no delete... adding ours");
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Delete",
shortcutKeyEvent: { text: "backspace" }, afterItem: "Models" });
Menu.addMenuItem({ menuName: ROOT_MENU, menuItemName: DELETE,
shortcutKeyEvent: { text: "backspace" }, afterItem: MENU_SEPARATOR });
modelMenuAddedDelete = true;
} else {
print("delete exists... don't add ours");
}
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Allow Selecting of Large Models", shortcutKey: "CTRL+META+L",
afterItem: "Paste Models", isCheckable: true });
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Allow Selecting of Small Models", shortcutKey: "CTRL+META+S",
afterItem: "Allow Selecting of Large Models", isCheckable: true });
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Allow Selecting of Lights", shortcutKey: "CTRL+SHIFT+META+L",
afterItem: "Allow Selecting of Small Models", isCheckable: true });
Menu.addMenuItem({ menuName: ROOT_MENU, menuItemName: LARGE_MODELS, shortcutKey: "CTRL+META+L",
afterItem: DELETE, isCheckable: true });
Menu.addMenuItem({ menuName: ROOT_MENU, menuItemName: SMALL_MODELS, shortcutKey: "CTRL+META+S",
afterItem: LARGE_MODELS, isCheckable: true });
Menu.addMenuItem({ menuName: ROOT_MENU, menuItemName: LIGHTS, shortcutKey: "CTRL+SHIFT+META+L",
afterItem: SMALL_MODELS, isCheckable: true });
Entities.setLightsArePickable(false);
}
function cleanupModelMenus() {
Menu.removeMenuItem("Edit", "Edit Properties...");
Menu.removeSeparator(ROOT_MENU, MENU_SEPARATOR);
Menu.removeMenuItem(ROOT_MENU, EDIT_PROPERTIES);
Menu.removeMenuItem(ROOT_MENU, INTERSECTION_STATS);
if (modelMenuAddedDelete) {
// delete our menuitems
Menu.removeMenuItem("Edit", "Delete");
Menu.removeMenuItem(ROOT_MENU, DELETE);
}
Menu.removeMenuItem("Edit", "Allow Selecting of Large Models");
Menu.removeMenuItem("Edit", "Allow Selecting of Small Models");
Menu.removeMenuItem("Edit", "Allow Selecting of Lights");
Menu.removeMenuItem(ROOT_MENU, LARGE_MODELS);
Menu.removeMenuItem(ROOT_MENU, SMALL_MODELS);
Menu.removeMenuItem(ROOT_MENU, LIGHTS);
}
@ -688,13 +696,13 @@ function showPropertiesForm(editModelID) {
Menu.menuItemEvent.connect(function (menuItem) {
print("menuItemEvent() in JS... menuItem=" + menuItem);
if (menuItem == "Allow Selecting of Small Models") {
allowSmallModels = Menu.isOptionChecked("Allow Selecting of Small Models");
} else if (menuItem == "Allow Selecting of Large Models") {
allowLargeModels = Menu.isOptionChecked("Allow Selecting of Large Models");
} else if (menuItem == "Allow Selecting of Lights") {
Entities.setLightsArePickable(Menu.isOptionChecked("Allow Selecting of Lights"));
} else if (menuItem == "Delete") {
if (menuItem == SMALL_MODELS) {
allowSmallModels = Menu.isOptionChecked(SMALL_MODELS);
} else if (menuItem == LARGE_MODELS) {
allowLargeModels = Menu.isOptionChecked(LARGE_MODELS);
} else if (menuItem == LIGHTS) {
Entities.setLightsArePickable(Menu.isOptionChecked(LIGHTS));
} else if (menuItem == DELETE) {
if (leftController.grabbing) {
print(" Delete Entity.... leftController.entityID="+ leftController.entityID);
Entities.deleteEntity(leftController.entityID);
@ -712,7 +720,7 @@ Menu.menuItemEvent.connect(function (menuItem) {
} else {
print(" Delete Entity.... not holding...");
}
} else if (menuItem == "Edit Properties...") {
} else if (menuItem == EDIT_PROPERTIES) {
editModelID = -1;
if (leftController.grabbing) {
print(" Edit Properties.... leftController.entityID="+ leftController.entityID);
@ -727,16 +735,18 @@ Menu.menuItemEvent.connect(function (menuItem) {
print(" Edit Properties.... about to edit properties...");
showPropertiesForm(editModelID);
}
} else if (menuItem == INTERSECTION_STATS) {
printIntersectionsStats();
}
});
Controller.keyReleaseEvent.connect(function (event) {
// since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items
if (event.text == "`") {
handeMenuEvent("Edit Properties...");
handeMenuEvent(EDIT_PROPERTIES);
}
if (event.text == "BACKSPACE") {
handeMenuEvent("Delete");
handeMenuEvent(DELETE);
}
});

View file

@ -0,0 +1,211 @@
// PaddleBall.js
//
// Created by Philip Rosedale on January 21, 2015
// Copyright 2014 High Fidelity, Inc.
//
// Move your hand with the hydra controller, and hit the ball with the paddle.
// Click 'X' button to turn off this script.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
hitSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Collisions-ballhitsandcatches/billiards/collision1.wav");
var rightHandAnimation = HIFI_PUBLIC_BUCKET + "animations/RightHandAnimPhilip.fbx";
var leftHandAnimation = HIFI_PUBLIC_BUCKET + "animations/LeftHandAnimPhilip.fbx";
var BALL_SIZE = 0.08;
var PADDLE_SIZE = 0.20;
var PADDLE_THICKNESS = 0.06;
var PADDLE_COLOR = { red: 184, green: 134, blue: 11 };
var BALL_COLOR = { red: 255, green: 0, blue: 0 };
var LINE_COLOR = { red: 255, green: 255, blue: 0 };
var PADDLE_BOX_OFFSET = { x: 0.05, y: 0.0, z: 0.0 };
var HOLD_POSITION_LEFT_OFFSET = { x: -0.15, y: 0.05, z: -0.05 };
var HOLD_POSITION_RIGHT_OFFSET = { x: -0.15, y: 0.05, z: 0.05 };
var PADDLE_ORIENTATION = Quat.fromPitchYawRollDegrees(0,0,0);
var GRAVITY = 0.0;
var SPRING_FORCE = 15.0;
var lastSoundTime = 0;
var gameOn = false;
var leftHanded = true;
var controllerID;
function setControllerID() {
if (leftHanded) {
controllerID = 1;
} else {
controllerID = 3;
}
}
setControllerID();
Menu.addMenu("PaddleBall");
Menu.addMenuItem({ menuName: "PaddleBall", menuItemName: "Left-Handed", isCheckable: true, isChecked: true });
var screenSize = Controller.getViewportDimensions();
var offButton = Overlays.addOverlay("image", {
x: screenSize.x - 48,
y: 96,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/close.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
var ball, paddle, paddleModel, line;
function createEntities() {
ball = Entities.addEntity(
{ type: "Sphere",
position: Controller.getSpatialControlPosition(controllerID),
dimensions: { x: BALL_SIZE, y: BALL_SIZE, z: BALL_SIZE },
color: BALL_COLOR,
gravity: { x: 0, y: GRAVITY, z: 0 },
ignoreCollisions: false,
damping: 0.50,
collisionsWillMove: true });
paddle = Entities.addEntity(
{ type: "Box",
position: Controller.getSpatialControlPosition(controllerID),
dimensions: { x: PADDLE_SIZE, y: PADDLE_THICKNESS, z: PADDLE_SIZE * 0.80 },
color: PADDLE_COLOR,
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
damping: 0.10,
visible: false,
rotation: Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(controllerID)),
collisionsWillMove: false });
modelURL = "http://public.highfidelity.io/models/attachments/pong_paddle.fbx";
paddleModel = Entities.addEntity(
{ type: "Model",
position: Vec3.sum(Controller.getSpatialControlPosition(controllerID), PADDLE_BOX_OFFSET),
dimensions: { x: PADDLE_SIZE * 1.5, y: PADDLE_THICKNESS, z: PADDLE_SIZE * 1.25 },
color: PADDLE_COLOR,
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: true,
modelURL: modelURL,
damping: 0.10,
rotation: Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(controllerID)),
collisionsWillMove: false });
line = Overlays.addOverlay("line3d", {
start: { x: 0, y: 0, z: 0 },
end: { x: 0, y: 0, z: 0 },
color: LINE_COLOR,
alpha: 1,
visible: true,
lineWidth: 2 });
MyAvatar.stopAnimation(leftHandAnimation);
MyAvatar.stopAnimation(rightHandAnimation);
MyAvatar.startAnimation(leftHanded ? leftHandAnimation: rightHandAnimation, 15.0, 1.0, false, true, 0.0, 6);
}
function deleteEntities() {
Entities.deleteEntity(ball);
Entities.deleteEntity(paddle);
Entities.deleteEntity(paddleModel);
Overlays.deleteOverlay(line);
MyAvatar.stopAnimation(leftHanded ? leftHandAnimation: rightHandAnimation);
}
function update(deltaTime) {
var palmPosition = Controller.getSpatialControlPosition(controllerID);
var controllerActive = (Vec3.length(palmPosition) > 0);
if (!gameOn && controllerActive) {
createEntities();
gameOn = true;
} else if (gameOn && !controllerActive) {
deleteEntities();
gameOn = false;
}
if (!gameOn || !controllerActive) {
return;
}
if (!paddle.isKnownID) {
paddle = Entities.identifyEntity(paddle);
}
if (!ball.isKnownID) {
ball = Entities.identifyEntity(ball);
} else {
var paddleOrientation = leftHanded ? PADDLE_ORIENTATION : Quat.multiply(PADDLE_ORIENTATION, Quat.fromPitchYawRollDegrees(0, 180, 0));
var paddleWorldOrientation = Quat.multiply(Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(controllerID)), paddleOrientation);
var holdPosition = Vec3.sum(leftHanded ? MyAvatar.getLeftPalmPosition() : MyAvatar.getRightPalmPosition(),
Vec3.multiplyQbyV(paddleWorldOrientation, leftHanded ? HOLD_POSITION_LEFT_OFFSET : HOLD_POSITION_RIGHT_OFFSET ));
var props = Entities.getEntityProperties(ball);
var spring = Vec3.subtract(holdPosition, props.position);
var springLength = Vec3.length(spring);
spring = Vec3.normalize(spring);
var ballVelocity = Vec3.sum(props.velocity, Vec3.multiply(springLength * SPRING_FORCE * deltaTime, spring));
Entities.editEntity(ball, { velocity: ballVelocity });
Overlays.editOverlay(line, { start: props.position, end: holdPosition });
Entities.editEntity(paddle, { position: holdPosition,
velocity: Controller.getSpatialControlVelocity(controllerID),
rotation: paddleWorldOrientation });
Entities.editEntity(paddleModel, { position: Vec3.sum(holdPosition, Vec3.multiplyQbyV(paddleWorldOrientation, PADDLE_BOX_OFFSET)),
velocity: Controller.getSpatialControlVelocity(controllerID),
rotation: paddleWorldOrientation });
}
}
function entityCollisionWithEntity(entity1, entity2, collision) {
if ((entity1.id == ball.id) || (entity2.id ==ball.id)) {
var props1 = Entities.getEntityProperties(entity1);
var props2 = Entities.getEntityProperties(entity2);
var dVel = Vec3.length(Vec3.subtract(props1.velocity, props2.velocity));
var currentTime = new Date().getTime();
var MIN_MSECS_BETWEEN_BOUNCE_SOUNDS = 100;
var MIN_VELOCITY_FOR_SOUND_IMPACT = 0.25;
if ((dVel > MIN_VELOCITY_FOR_SOUND_IMPACT) && (currentTime - lastSoundTime) > MIN_MSECS_BETWEEN_BOUNCE_SOUNDS) {
Audio.playSound(hitSound, { position: props1.position, volume: Math.min(dVel, 1.0) });
lastSoundTime = new Date().getTime();
}
}
}
function mousePressEvent(event) {
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
if (clickedOverlay == offButton) {
Script.stop();
}
}
function menuItemEvent(menuItem) {
oldHanded = leftHanded;
if (menuItem == "Left-Handed") {
leftHanded = Menu.isOptionChecked("Left-Handed");
}
if ((leftHanded != oldHanded) && gameOn) {
setControllerID();
deleteEntities();
createEntities();
}
}
function scriptEnding() {
if (gameOn) {
deleteEntities();
}
Overlays.deleteOverlay(offButton);
MyAvatar.stopAnimation(leftHandAnimation);
MyAvatar.stopAnimation(rightHandAnimation);
Menu.removeMenu("PaddleBall");
}
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
Menu.menuItemEvent.connect(menuItemEvent);
Controller.mousePressEvent.connect(mousePressEvent);
Script.scriptEnding.connect(scriptEnding);
Script.update.connect(update);

View file

@ -60,11 +60,9 @@ Script.update.connect(function(deltaTime) {
}
if ((leftFrame != lastLeftFrame) && leftHandAnimation.length){
MyAvatar.stopAnimation(leftHandAnimation);
MyAvatar.startAnimation(leftHandAnimation, 30.0, 1.0, false, true, leftFrame, leftFrame);
}
if ((rightFrame != lastRightFrame) && rightHandAnimation.length) {
MyAvatar.stopAnimation(rightHandAnimation);
MyAvatar.startAnimation(rightHandAnimation, 30.0, 1.0, false, true, rightFrame, rightFrame);
}

View file

@ -20,8 +20,64 @@ Script.include("../../libraries/globals.js");
Script.include("../../libraries/virtualKeyboard.js");
Script.include("../../libraries/soundArray.js");
const MAX_SHOW_INSTRUCTION_TIMES = 2;
const INSTRUCTIONS_SETTING = "GoToInstructionsShowCounter"
var windowDimensions = Controller.getViewportDimensions();
var cursor = new Cursor({visible: false});;
function Instructions(imageURL, originalWidth, originalHeight) {
var tthis = this;
this.originalSize = {w: originalWidth, h: originalHeight};
this.visible = false;
this.overlay = Overlays.addOverlay("image", {
imageURL: imageURL,
x: 0,
y: 0,
width: originalWidth,
height: originalHeight,
alpha: 1,
visible: this.visible
});
this.show = function() {
var timesShown = Settings.getValue(INSTRUCTIONS_SETTING);
timesShown = timesShown === "" ? 0 : parseInt(timesShown);
print(timesShown);
if (timesShown < MAX_SHOW_INSTRUCTION_TIMES) {
Settings.setValue(INSTRUCTIONS_SETTING, timesShown + 1);
tthis.visible = true;
tthis.rescale();
Overlays.editOverlay(tthis.overlay, {visible: tthis.visible});
return;
}
tthis.remove();
}
this.remove = function() {
Overlays.deleteOverlay(tthis.overlay);
tthis.visible = false;
};
this.rescale = function() {
var scale = Math.min(windowDimensions.x / tthis.originalSize.w, windowDimensions.y / tthis.originalSize.h);
var newWidth = tthis.originalSize.w * scale;
var newHeight = tthis.originalSize.h * scale;
Overlays.editOverlay(tthis.overlay, {
x: (windowDimensions.x / 2) - (newWidth / 2),
y: (windowDimensions.y / 2) - (newHeight / 2),
width: newWidth,
height: newHeight
});
};
this.rescale();
};
var theInstruction = new Instructions(HIFI_PUBLIC_BUCKET + "images/tutorial-goTo.svg", 457, 284.1);
var firstControllerPlugged = false;
var cursor = new Cursor({visible: false});
var keyboard = new Keyboard({visible: false});
var textFontSize = 9;
var text = null;
@ -65,17 +121,17 @@ keyboard.onKeyPress = function(event) {
};
keyboard.onKeyRelease = function(event) {
print("Key release event test");
// you can cancel a key by releasing its focusing before releasing it
if (event.focus) {
if (event.event == 'delete') {
deleteChar();
deleteChar();
} else if (event.event == 'submit' || event.event == 'enter') {
print("going to hifi://" + locationURL);
location = "hifi://" + locationURL;
locationURL = "";
keyboard.hide();
updateTextOverlay();
print("going to hifi://" + locationURL);
location = "hifi://" + locationURL;
locationURL = "";
keyboard.hide();
cursor.hide();
updateTextOverlay();
}
}
};
@ -84,18 +140,18 @@ keyboard.onFullyLoaded = function() {
print("Virtual-keyboard fully loaded.");
var dimensions = Controller.getViewportDimensions();
text = Overlays.addOverlay("text", {
x: 0,
y: dimensions.y - keyboard.height() - 260,
width: dimensions.x,
height: 250,
backgroundColor: { red: 255, green: 255, blue: 255},
color: { red: 0, green: 0, blue: 0},
topMargin: 5,
leftMargin: 0,
font: {size: textFontSize},
text: "",
alpha: 0.8,
visible: keyboard.visible
x: 0,
y: dimensions.y - keyboard.height() - 260,
width: dimensions.x,
height: 250,
backgroundColor: { red: 255, green: 255, blue: 255},
color: { red: 0, green: 0, blue: 0},
topMargin: 5,
leftMargin: 0,
font: {size: textFontSize},
text: "",
alpha: 0.8,
visible: keyboard.visible
});
updateTextOverlay();
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
@ -107,6 +163,9 @@ keyboard.onFullyLoaded = function() {
};
function keyPressEvent(event) {
if (theInstruction.visible) {
return;
}
if (event.key === SPACEBAR_CHARCODE) {
keyboard.pressFocussedKey();
} else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) {
@ -119,6 +178,9 @@ function keyPressEvent(event) {
}
function keyReleaseEvent(event) {
if (theInstruction.visible) {
return;
}
if (event.key === SPACEBAR_CHARCODE) {
keyboard.releaseKeys();
}
@ -132,10 +194,15 @@ function scriptEnding() {
Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE});
Controller.releaseKeyEvents({key: RETURN_CHARCODE});
Controller.releaseKeyEvents({key: ENTER_CHARCODE});
theInstruction.remove();
}
function reportButtonValue(button, newValue, oldValue) {
if (button == Joysticks.BUTTON_FACE_BOTTOM) {
if (theInstruction.visible) {
if (button == Joysticks.BUTTON_FACE_BOTTOM && newValue) {
theInstruction.remove();
}
} else if (button == Joysticks.BUTTON_FACE_BOTTOM) {
if (newValue) {
keyboard.pressFocussedKey();
} else {
@ -143,11 +210,36 @@ function reportButtonValue(button, newValue, oldValue) {
}
} else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) {
deleteChar();
} else if (button == Joysticks.BUTTON_FACE_LEFT && newValue) {
keyboard.hide();
if (cursor !== undefined) {
cursor.hide();
}
Overlays.editOverlay(text, {visible: false});
} else if (button == Joysticks.BUTTON_RIGHT_SHOULDER && newValue) {
if (keyboard.visible) {
print("going to hifi://" + locationURL);
location = "hifi://" + locationURL;
locationURL = "";
keyboard.hide();
cursor.hide();
updateTextOverlay();
return;
}
keyboard.show();
if (cursor !== undefined) {
cursor.show();
}
Overlays.editOverlay(text, {visible: true});
}
}
function addJoystick(gamepad) {
gamepad.buttonStateChanged.connect(reportButtonValue);
if (!firstControllerPlugged) {
firstControllerPlugged = true;
theInstruction.show();
}
}
var allJoysticks = Joysticks.getAllJoysticks();

View file

@ -28,7 +28,7 @@ const TEXT_MARGIN_RIGHT = 0.17;
const TEXT_MARGIN_BOTTOM = 0.17;
var windowDimensions = Controller.getViewportDimensions();
var cursor = null;
var cursor = new Cursor();
var keyboard = new Keyboard();
var textFontSize = 9;
var text = null;
@ -78,7 +78,7 @@ keyboard.onKeyRelease = function(event) {
// you can cancel a key by releasing its focusing before releasing it
if (event.focus) {
if (event.event == 'delete') {
deleteChar();
deleteChar();
} else if (event.event == 'submit') {
print(textText);
@ -91,12 +91,14 @@ keyboard.onKeyRelease = function(event) {
if (maxLineWidth < usernameWidth) {
maxLineWidth = usernameWidth;
} else {
var spaceableWidth = maxLineWidth - usernameWidth;
var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width;
var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth);
for (var i = 0; i < numberOfSpaces; i++) {
usernameLine = " " + usernameLine;
}
var spaceableWidth = maxLineWidth - usernameWidth;
//TODO: WORKAROUND WARNING BELOW Fix this when spaces are not trimmed out of the textsize calculation anymore
var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, "| |").width
- Overlays.textSize(textSizeMeasureOverlay, "||").width;
var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth);
for (var i = 0; i < numberOfSpaces; i++) {
usernameLine = " " + usernameLine;
}
}
var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT;
if (position.x > 0 && position.y > 0 && position.z > 0) {
@ -135,7 +137,7 @@ keyboard.onFullyLoaded = function() {
});
updateTextOverlay();
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
cursor = new Cursor();
cursor.initialize();
cursor.onUpdate = function(position) {
keyboard.setFocusPosition(position.x, position.y);
};

View file

@ -8,6 +8,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.load("progress.js");
Script.load("lookWithTouch.js");
Script.load("editEntities.js");
Script.load("selectAudioDevice.js");
@ -16,3 +17,4 @@ Script.load("headMove.js");
Script.load("inspect.js");
Script.load("lobby.js");
Script.load("notifications.js");
Script.load("lookWithMouse.js")

109
examples/dice.js Normal file
View file

@ -0,0 +1,109 @@
//
// dice.js
// examples
//
// Created by Philip Rosedale on February 2, 2015
// Copyright 2015 High Fidelity, Inc.
//
// Press the dice button to throw some dice from the center of the screen.
// Change NUMBER_OF_DICE to change the number thrown (Yahtzee, anyone?)
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var isDice = false;
var NUMBER_OF_DICE = 2;
var dice = [];
var DIE_SIZE = 0.20;
var madeSound = true; // Set false at start of throw to look for collision
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
var rollSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/dice/diceRoll.wav");
var screenSize = Controller.getViewportDimensions();
var offButton = Overlays.addOverlay("image", {
x: screenSize.x - 48,
y: 96,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/close.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
var diceButton = Overlays.addOverlay("image", {
x: screenSize.x - 48,
y: 130,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/die.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
var GRAVITY = -3.5;
var LIFETIME = 300;
function shootDice(position, velocity) {
for (var i = 0; i < NUMBER_OF_DICE; i++) {
dice.push(Entities.addEntity(
{ type: "Model",
modelURL: HIFI_PUBLIC_BUCKET + "models/props/Dice/goldDie.fbx",
position: position,
velocity: velocity,
rotation: Quat.fromPitchYawRollDegrees(Math.random() * 360, Math.random() * 360, Math.random() * 360),
lifetime: LIFETIME,
gravity: { x: 0, y: GRAVITY, z: 0 },
collisionsWillMove: true
}));
position = Vec3.sum(position, Vec3.multiply(DIE_SIZE, Vec3.normalize(Quat.getRight(Camera.getOrientation()))));
}
}
function deleteDice() {
while(dice.length > 0) {
Entities.deleteEntity(dice.pop());
}
}
function entityCollisionWithEntity(entity1, entity2, collision) {
if (!madeSound) {
// Is it one of our dice?
for (var i = 0; i < dice.length; i++) {
if (!dice[i].isKnownID) {
dice[i] = Entities.identifyEntity(dice[i]);
}
if ((entity1.id == dice[i].id) || (entity2.id == dice[i].id)) {
madeSound = true;
Audio.playSound(rollSound, { position: collision.contactPoint });
}
}
}
}
function mousePressEvent(event) {
var clickedText = false;
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
if (clickedOverlay == offButton) {
deleteDice();
} else if (clickedOverlay == diceButton) {
var HOW_HARD = 2.0;
var position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
var velocity = Vec3.multiply(HOW_HARD, Quat.getFront(Camera.getOrientation()));
shootDice(position, velocity);
madeSound = false;
}
}
function scriptEnding() {
deleteDice();
Overlays.deleteOverlay(offButton);
Overlays.deleteOverlay(diceButton);
}
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
Controller.mousePressEvent.connect(mousePressEvent);
Script.scriptEnding.connect(scriptEnding);

View file

@ -12,50 +12,42 @@
//
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
Script.include("libraries/stringHelpers.js");
Script.include("libraries/dataviewHelpers.js");
Script.include("libraries/httpMultiPart.js");
Script.include("libraries/modelUploader.js");
Script.include("libraries/toolBars.js");
Script.include("libraries/progressDialog.js");
Script.include("libraries/entitySelectionTool.js");
Script.include([
"libraries/stringHelpers.js",
"libraries/dataviewHelpers.js",
"libraries/httpMultiPart.js",
"libraries/modelUploader.js",
"libraries/toolBars.js",
"libraries/progressDialog.js",
"libraries/entitySelectionTool.js",
"libraries/ModelImporter.js",
"libraries/ExportMenu.js",
"libraries/ToolTip.js",
"libraries/entityPropertyDialogBox.js",
"libraries/entityCameraTool.js",
"libraries/gridTool.js",
"libraries/entityList.js",
]);
var selectionDisplay = SelectionDisplay;
var selectionManager = SelectionManager;
Script.include("libraries/ModelImporter.js");
var modelImporter = new ModelImporter();
Script.include("libraries/ExportMenu.js");
Script.include("libraries/ToolTip.js");
Script.include("libraries/entityPropertyDialogBox.js");
var entityPropertyDialogBox = EntityPropertyDialogBox;
Script.include("libraries/entityCameraTool.js");
var cameraManager = new CameraManager();
Script.include("libraries/gridTool.js");
var grid = Grid();
gridTool = GridTool({ horizontalGrid: grid });
gridTool.setVisible(false);
Script.include("libraries/entityList.js");
var entityListTool = EntityListTool();
var hasShownPropertiesTool = false;
var entityListVisible = false;
selectionManager.addEventListener(function() {
selectionDisplay.updateHandles();
if (selectionManager.hasSelection() && !hasShownPropertiesTool) {
// Open properties and model list, but force selection of model list tab
propertiesTool.setVisible(false);
entityListTool.setVisible(false);
propertiesTool.setVisible(true);
entityListTool.setVisible(true);
hasShownPropertiesTool = true;
}
});
var windowDimensions = Controller.getViewportDimensions();
@ -82,9 +74,11 @@ var DEFAULT_DIMENSIONS = {
};
var MENU_INSPECT_TOOL_ENABLED = "Inspect Tool";
var MENU_AUTO_FOCUS_ON_SELECT = "Auto Focus on Select";
var MENU_EASE_ON_FOCUS = "Ease Orientation on Focus";
var SETTING_INSPECT_TOOL_ENABLED = "inspectToolEnabled";
var SETTING_AUTO_FOCUS_ON_SELECT = "autoFocusOnSelect";
var SETTING_EASE_ON_FOCUS = "cameraEaseOnFocus";
var modelURLs = [
@ -100,6 +94,7 @@ var modelURLs = [
var mode = 0;
var isActive = false;
var placingEntityID = null;
var toolBar = (function () {
var that = {},
@ -110,19 +105,12 @@ var toolBar = (function () {
newSphereButton,
newLightButton,
newTextButton,
browseModelsButton,
loadURLMenuItem,
loadFileMenuItem,
menuItemWidth,
menuItemOffset,
menuItemHeight,
menuItemMargin = 5,
menuTextColor = { red: 255, green: 255, blue: 255 },
menuBackgroundColor = { red: 18, green: 66, blue: 66 };
browseModelsButton;
function initialize() {
toolBar = new ToolBar(0, 0, ToolBar.VERTICAL);
// Hide active button for now - this may come back, so not deleting yet.
activeButton = toolBar.addTool({
imageURL: toolIconUrl + "models-tool.svg",
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
@ -139,7 +127,7 @@ var toolBar = (function () {
height: toolHeight,
alpha: 0.9,
visible: true
}, true, false);
});
browseModelsButton = toolBar.addTool({
imageURL: toolIconUrl + "list-icon.svg",
@ -149,34 +137,6 @@ var toolBar = (function () {
visible: true
});
menuItemOffset = toolBar.height / 3 + 2;
menuItemHeight = Tool.IMAGE_HEIGHT / 2 - 2;
loadURLMenuItem = Overlays.addOverlay("text", {
height: menuItemHeight,
backgroundColor: menuBackgroundColor,
topMargin: menuItemMargin,
text: "Model URL",
alpha: 0.9,
backgroundAlpha: 0.9,
visible: false
});
loadFileMenuItem = Overlays.addOverlay("text", {
height: menuItemHeight,
backgroundColor: menuBackgroundColor,
topMargin: menuItemMargin,
text: "Model File",
alpha: 0.9,
backgroundAlpha: 0.9,
visible: false
});
menuItemWidth = Math.max(Overlays.textSize(loadURLMenuItem, "Model URL").width,
Overlays.textSize(loadFileMenuItem, "Model File").width) + 20;
Overlays.editOverlay(loadURLMenuItem, { width: menuItemWidth });
Overlays.editOverlay(loadFileMenuItem, { width: menuItemWidth });
newCubeButton = toolBar.addTool({
imageURL: toolIconUrl + "add-cube.svg",
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
@ -215,17 +175,6 @@ var toolBar = (function () {
}
function toggleNewModelButton(active) {
if (active === undefined) {
active = !toolBar.toolSelected(newModelButton);
}
toolBar.selectTool(newModelButton, active);
Overlays.editOverlay(loadURLMenuItem, { visible: active });
Overlays.editOverlay(loadFileMenuItem, { visible: active });
}
that.setActive = function(active) {
if (active != isActive) {
isActive = active;
@ -239,15 +188,18 @@ var toolBar = (function () {
} else {
hasShownPropertiesTool = false;
cameraManager.enable();
entityListTool.setVisible(true);
gridTool.setVisible(true);
grid.setEnabled(true);
propertiesTool.setVisible(true);
Window.setFocus();
}
}
toolBar.selectTool(activeButton, active);
};
var RESIZE_INTERVAL = 50;
var RESIZE_TIMEOUT = 20000;
var RESIZE_TIMEOUT = 120000; // 2 minutes
var RESIZE_MAX_CHECKS = RESIZE_TIMEOUT / RESIZE_INTERVAL;
function addModel(url) {
var position;
@ -308,11 +260,10 @@ var toolBar = (function () {
toolsY = (windowDimensions.y - toolBar.height) / 2;
toolBar.move(toolsX, toolsY);
Overlays.editOverlay(loadURLMenuItem, { x: toolsX - menuItemWidth, y: toolsY + menuItemOffset });
Overlays.editOverlay(loadFileMenuItem, { x: toolsX - menuItemWidth, y: toolsY + menuItemOffset + menuItemHeight });
};
var newModelButtonDown = false;
var browseModelsButtonDown = false;
that.mousePressEvent = function (event) {
var clickedOverlay,
url,
@ -325,40 +276,14 @@ var toolBar = (function () {
return true;
}
// Handle these two buttons in the mouseRelease event handler so that we don't suppress a mouseRelease event from
// occurring when showing a modal dialog.
if (newModelButton === toolBar.clicked(clickedOverlay)) {
toggleNewModelButton();
newModelButtonDown = true;
return true;
}
if (clickedOverlay === loadURLMenuItem) {
toggleNewModelButton(false);
url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]);
if (url !== null && url !== "") {
addModel(url);
}
return true;
}
if (clickedOverlay === loadFileMenuItem) {
toggleNewModelButton(false);
file = Window.browse("Select your model file ...",
Settings.getValue("LastModelUploadLocation").path(),
"Model files (*.fst *.fbx)");
//"Model files (*.fst *.fbx *.svo)");
if (file !== null) {
Settings.setValue("LastModelUploadLocation", file);
modelUploader.upload(file, addModel);
}
return true;
}
if (browseModelsButton === toolBar.clicked(clickedOverlay)) {
toggleNewModelButton(false);
url = Window.s3Browse(".*(fbx|FBX)");
if (url !== null && url !== "") {
addModel(url);
}
browseModelsButtonDown = true;
return true;
}
@ -366,7 +291,7 @@ var toolBar = (function () {
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
if (position.x > 0 && position.y > 0 && position.z > 0) {
Entities.addEntity({
placingEntityID = Entities.addEntity({
type: "Box",
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
dimensions: DEFAULT_DIMENSIONS,
@ -383,7 +308,7 @@ var toolBar = (function () {
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
if (position.x > 0 && position.y > 0 && position.z > 0) {
Entities.addEntity({
placingEntityID = Entities.addEntity({
type: "Sphere",
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
dimensions: DEFAULT_DIMENSIONS,
@ -399,7 +324,7 @@ var toolBar = (function () {
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
if (position.x > 0 && position.y > 0 && position.z > 0) {
Entities.addEntity({
placingEntityID = Entities.addEntity({
type: "Light",
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
dimensions: DEFAULT_DIMENSIONS,
@ -420,18 +345,19 @@ var toolBar = (function () {
return true;
}
if (newTextButton === toolBar.clicked(clickedOverlay)) {
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
if (position.x > 0 && position.y > 0 && position.z > 0) {
Entities.addEntity({
placingEntityID = Entities.addEntity({
type: "Text",
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
dimensions: DEFAULT_DIMENSIONS,
backgroundColor: { red: 0, green: 0, blue: 0 },
dimensions: { x: 0.65, y: 0.3, z: 0.01 },
backgroundColor: { red: 64, green: 64, blue: 64 },
textColor: { red: 255, green: 255, blue: 255 },
text: "some text",
lineHight: "0.1"
lineHeight: 0.06
});
} else {
print("Can't create box: Text would be out of bounds.");
@ -439,14 +365,39 @@ var toolBar = (function () {
return true;
}
return false;
};
that.mouseReleaseEvent = function(event) {
var handled = false;
if (newModelButtonDown) {
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
if (newModelButton === toolBar.clicked(clickedOverlay)) {
url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]);
if (url !== null && url !== "") {
addModel(url);
}
handled = true;
}
} else if (browseModelsButtonDown) {
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
if (browseModelsButton === toolBar.clicked(clickedOverlay)) {
url = Window.s3Browse(".*(fbx|FBX)");
if (url !== null && url !== "") {
addModel(url);
}
handled = true;
}
}
newModelButtonDown = false;
browseModelsButtonDown = false;
return handled;
}
that.cleanup = function () {
toolBar.cleanup();
Overlays.deleteOverlay(loadURLMenuItem);
Overlays.deleteOverlay(loadFileMenuItem);
};
return that;
@ -507,7 +458,7 @@ function mousePressEvent(event) {
mouseHasMovedSincePress = false;
mouseCapturedByTool = false;
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event) || gridTool.mousePressEvent(event)) {
if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) {
mouseCapturedByTool = true;
return;
}
@ -536,26 +487,40 @@ var mouseCapturedByTool = false;
var lastMousePosition = null;
var idleMouseTimerId = null;
var IDLE_MOUSE_TIMEOUT = 200;
var DEFAULT_ENTITY_DRAG_DROP_DISTANCE = 2.0;
function mouseMoveEvent(event) {
if (placingEntityID) {
if (!placingEntityID.isKnownID) {
placingEntityID = Entities.identifyEntity(placingEntityID);
}
var pickRay = Camera.computePickRay(event.x, event.y);
var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE;
var offset = Vec3.multiply(distance, pickRay.direction);
var position = Vec3.sum(Camera.position, offset);
Entities.editEntity(placingEntityID, {
position: position,
});
return;
}
if (!isActive) {
return;
}
if (idleMouseTimerId) {
Script.clearTimeout(idleMouseTimerId);
}
mouseHasMovedSincePress = true;
if (isActive) {
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) {
return;
}
lastMousePosition = { x: event.x, y: event.y };
highlightEntityUnderCursor(lastMousePosition, false);
idleMouseTimerId = Script.setTimeout(handleIdleMouse, IDLE_MOUSE_TIMEOUT);
} else {
cameraManager.mouseMoveEvent(event);
// allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing
if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) {
return;
}
lastMousePosition = { x: event.x, y: event.y };
highlightEntityUnderCursor(lastMousePosition, false);
idleMouseTimerId = Script.setTimeout(handleIdleMouse, IDLE_MOUSE_TIMEOUT);
}
function handleIdleMouse() {
@ -593,6 +558,15 @@ function highlightEntityUnderCursor(position, accurateRay) {
function mouseReleaseEvent(event) {
if (toolBar.mouseReleaseEvent(event)) {
return true;
}
if (placingEntityID) {
if (isActive) {
selectionManager.setSelections([placingEntityID]);
}
placingEntityID = null;
}
if (isActive && selectionManager.hasSelection()) {
tooltip.show(false);
}
@ -608,7 +582,7 @@ function mouseReleaseEvent(event) {
}
function mouseClickEvent(event) {
if (!isActive) {
if (!event.isLeftButton || !isActive) {
return;
}
@ -619,6 +593,7 @@ function mouseClickEvent(event) {
}
return;
}
toolBar.setActive(true);
var pickRay = result.pickRay;
var foundEntity = result.entityID;
@ -660,15 +635,21 @@ function mouseClickEvent(event) {
orientation = MyAvatar.orientation;
intersection = rayPlaneIntersection(pickRay, P, Quat.getFront(orientation));
if (!event.isShifted) {
selectionManager.clearSelections();
}
var toggle = event.isShifted;
selectionManager.addEntity(foundEntity, toggle);
if (!event.isShifted) {
selectionManager.setSelections([foundEntity]);
} else {
selectionManager.addEntity(foundEntity, true);
}
print("Model selected: " + foundEntity.id);
selectionDisplay.select(selectedEntityID, event);
if (Menu.isOptionChecked(MENU_AUTO_FOCUS_ON_SELECT)) {
cameraManager.focus(selectionManager.worldPosition,
selectionManager.worldDimensions,
Menu.isOptionChecked(MENU_EASE_ON_FOCUS));
}
}
}
}
@ -710,7 +691,9 @@ function setupModelMenus() {
Menu.addMenuItem({ menuName: "File", menuItemName: "Import Models", shortcutKey: "CTRL+META+I", afterItem: "Export Models" });
Menu.addMenuItem({ menuName: "View", menuItemName: MENU_EASE_ON_FOCUS, afterItem: MENU_INSPECT_TOOL_ENABLED,
Menu.addMenuItem({ menuName: "View", menuItemName: MENU_AUTO_FOCUS_ON_SELECT, afterItem: MENU_INSPECT_TOOL_ENABLED,
isCheckable: true, isChecked: Settings.getValue(SETTING_AUTO_FOCUS_ON_SELECT) == "true" });
Menu.addMenuItem({ menuName: "View", menuItemName: MENU_EASE_ON_FOCUS, afterItem: MENU_AUTO_FOCUS_ON_SELECT,
isCheckable: true, isChecked: Settings.getValue(SETTING_EASE_ON_FOCUS) == "true" });
Entities.setLightsArePickable(false);
@ -736,11 +719,12 @@ function cleanupModelMenus() {
Menu.removeMenuItem("File", "Import Models");
Menu.removeMenuItem("View", MENU_INSPECT_TOOL_ENABLED);
Menu.removeMenuItem("View", MENU_AUTO_FOCUS_ON_SELECT);
Menu.removeMenuItem("View", MENU_EASE_ON_FOCUS);
}
Script.scriptEnding.connect(function() {
Settings.setValue(SETTING_INSPECT_TOOL_ENABLED, Menu.isOptionChecked(MENU_INSPECT_TOOL_ENABLED));
Settings.setValue(SETTING_AUTO_FOCUS_ON_SELECT, Menu.isOptionChecked(MENU_AUTO_FOCUS_ON_SELECT));
Settings.setValue(SETTING_EASE_ON_FOCUS, Menu.isOptionChecked(MENU_EASE_ON_FOCUS));
progressDialog.cleanup();
@ -806,9 +790,7 @@ function handeMenuEvent(menuItem) {
} else if (menuItem == "Import Models") {
modelImporter.doImport();
} else if (menuItem == "Entity List...") {
if (isActive) {
entityListTool.toggleVisible();
}
entityListTool.toggleVisible();
}
tooltip.show(false);
}
@ -816,16 +798,20 @@ function handeMenuEvent(menuItem) {
Menu.menuItemEvent.connect(handeMenuEvent);
Controller.keyPressEvent.connect(function(event) {
if (event.text == 'w' || event.text == 'a' || event.text == 's' || event.text == 'd'
|| event.text == 'UP' || event.text == 'DOWN' || event.text == 'LEFT' || event.text == 'RIGHT') {
toolBar.setActive(false);
if (isActive) {
cameraManager.keyPressEvent(event);
}
});
Controller.keyReleaseEvent.connect(function (event) {
if (isActive) {
cameraManager.keyReleaseEvent(event);
}
// since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items
if (event.text == "BACKSPACE" || event.text == "DELETE") {
deleteSelectedEntities();
} else if (event.text == "ESC") {
selectionManager.clearSelections();
} else if (event.text == "TAB") {
selectionDisplay.toggleSpaceMode();
} else if (event.text == "f") {
@ -846,55 +832,6 @@ Controller.keyReleaseEvent.connect(function (event) {
newPosition = Vec3.subtract(newPosition, { x: 0, y: selectionManager.worldDimensions.y * 0.5, z: 0 });
grid.setPosition(newPosition);
}
} else if (isActive) {
var delta = null;
var increment = event.isShifted ? grid.getMajorIncrement() : grid.getMinorIncrement();
if (event.text == 'UP') {
if (event.isControl || event.isAlt) {
delta = { x: 0, y: increment, z: 0 };
} else {
delta = { x: 0, y: 0, z: -increment };
}
} else if (event.text == 'DOWN') {
if (event.isControl || event.isAlt) {
delta = { x: 0, y: -increment, z: 0 };
} else {
delta = { x: 0, y: 0, z: increment };
}
} else if (event.text == 'LEFT') {
delta = { x: -increment, y: 0, z: 0 };
} else if (event.text == 'RIGHT') {
delta = { x: increment, y: 0, z: 0 };
}
if (delta != null) {
// Adjust delta so that movements are relative to the current camera orientation
var lookDirection = Quat.getFront(Camera.getOrientation());
lookDirection.z *= -1;
var angle = Math.atan2(lookDirection.z, lookDirection.x);
angle -= (Math.PI / 4);
var rotation = Math.floor(angle / (Math.PI / 2)) * (Math.PI / 2);
var rotator = Quat.fromPitchYawRollRadians(0, rotation, 0);
delta = Vec3.multiplyQbyV(rotator, delta);
SelectionManager.saveProperties();
for (var i = 0; i < selectionManager.selections.length; i++) {
var entityID = selectionManager.selections[i];
var properties = Entities.getEntityProperties(entityID);
Entities.editEntity(entityID, {
position: Vec3.sum(properties.position, delta)
});
}
pushCommandForSelections();
selectionManager._update();
}
}
});
@ -1050,9 +987,18 @@ PropertiesTool = function(opts) {
selectionManager.saveProperties();
for (var i = 0; i < selectionManager.selections.length; i++) {
var properties = selectionManager.savedProperties[selectionManager.selections[i].id];
Entities.editEntity(selectionManager.selections[i], {
dimensions: properties.naturalDimensions,
});
var naturalDimensions = properties.naturalDimensions;
// If any of the natural dimensions are not 0, resize
if (properties.type == "Model" && naturalDimensions.x == 0
&& naturalDimensions.y == 0 && naturalDimensions.z == 0) {
Window.alert("Cannot reset entity to its natural dimensions: Model URL"
+ " is invalid or the model has not yet been loaded.");
} else {
Entities.editEntity(selectionManager.selections[i], {
dimensions: properties.naturalDimensions,
});
}
}
pushCommandForSelections();
selectionManager._update();
@ -1078,4 +1024,3 @@ PropertiesTool = function(opts) {
};
propertiesTool = PropertiesTool();

View file

@ -48,7 +48,8 @@
this.turnSounds = new Array();
this.moveSound = null;
this.turnSound = null;
this.injector = null;
this.moveInjector = null;
this.turnInjector = null;
var debug = false;
var displayRotateTargets = true; // change to false if you don't want the rotate targets
@ -92,9 +93,14 @@
}
if (this.moveSound && this.moveSound.downloaded) {
if (debug) {
print("playMoveSound() --- calling this.injector = Audio.playSound(this.moveSound...)");
print("playMoveSound() --- calling this.moveInjector = Audio.playSound(this.moveSound...)");
}
if (!this.moveInjector) {
this.moveInjector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 });
} else {
this.moveInjector.restart();
}
this.injector = Audio.playSound(this.moveSound, { position: this.properties.position, loop: true, volume: 0.1 });
}
}
@ -105,9 +111,13 @@
}
if (this.turnSound && this.turnSound.downloaded) {
if (debug) {
print("playTurnSound() --- calling this.injector = Audio.playSound(this.turnSound...)");
print("playTurnSound() --- calling this.turnInjector = Audio.playSound(this.turnSound...)");
}
if (!this.turnInjector) {
this.turnInjector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 });
} else {
this.turnInjector.restart();
}
this.injector = Audio.playSound(this.turnSound, { position: this.properties.position, loop: true, volume: 0.1 });
}
}
@ -116,9 +126,11 @@
if (debug) {
print("stopSound()");
}
if (this.injector) {
Audio.stopInjector(this.injector);
this.injector = null;
if (this.turnInjector) {
this.turnInjector.stop();
}
if (this.moveInjector) {
this.moveInjector.stop();
}
}
@ -174,7 +186,7 @@
this.move = function(mouseEvent) {
this.updatePosition(mouseEvent);
if (this.injector === null) {
if (this.moveInjector === null || !this.moveInjector.isPlaying) {
this.playMoveSound();
}
};
@ -233,7 +245,7 @@
}
}
if (this.injector === null) {
if (this.turnInjector === null || !this.turnInjector.isPlaying) {
this.playTurnSound();
}
};

View file

@ -0,0 +1,41 @@
(function(){
var teleport;
var portalDestination;
function playSound() {
Audio.playSound(teleport, { volume: 0.40, localOnly: true });
};
this.preload = function(entityID) {
teleport = SoundCache.getSound("http://s3.amazonaws.com/hifi-public/birarda/teleport.raw");
var properties = Entities.getEntityProperties(entityID);
portalDestination = properties.userData;
print("The portal destination is " + portalDestination);
}
this.enterEntity = function(entityID) {
if (portalDestination.length > 0) {
print("Teleporting to hifi://" + portalDestination);
Window.location = "hifi://" + portalDestination;
}
};
this.leaveEntity = function(entityID) {
Entities.editEntity(entityID, {
animationURL: "http://hifi-public.s3.amazonaws.com/models/content/phonebooth.fbx",
animationSettings: '{ "frameIndex": 1, "running": false }'
});
playSound();
};
this.hoverEnterEntity = function(entityID) {
Entities.editEntity(entityID, {
animationURL: "http://hifi-public.s3.amazonaws.com/models/content/phonebooth.fbx",
animationSettings: '{ "fps": 24, "firstFrame": 1, "lastFrame": 25, "frameIndex": 1, "running": true, "hold": true }'
});
};
})

View file

@ -75,14 +75,14 @@ function maybePlaySound(deltaTime) {
//print("number playing = " + numPlaying);
}
for (var i = 0; i < playing.length; i++) {
if (!Audio.isInjectorPlaying(playing[i].audioId)) {
if (!playing[i].audioId.isPlaying) {
Entities.deleteEntity(playing[i].entityId);
if (useLights) {
Entities.deleteEntity(playing[i].lightId);
}
playing.splice(i, 1);
} else {
var loudness = Audio.getLoudness(playing[i].audioId);
var loudness = playing[i].audioId.loudness;
var newColor = { red: playing[i].color.red, green: playing[i].color.green, blue: playing[i].color.blue };
if (loudness > 0.05) {
newColor.red *= (1.0 - loudness);

View file

@ -76,9 +76,6 @@ function scriptEnding() {
if (entity != null) {
Entities.deleteEntity(entity);
}
if (injector != null) {
injector.stop();
}
}
Script.update.connect(update);

View file

@ -13,6 +13,9 @@
//
print("BUTTERFLIES START");
var numButterflies = 25;
@ -109,7 +112,7 @@ function updateButterflies(deltaTime) {
var properties = Entities.getEntityProperties(butterflies[i]);
if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
Entities.editEntity(butterflies[i], { position: flockPosition } );
} else if (properties.velocity.y < 0.0) {
} else if (properties.velocity.y <= 0.0) {
// If falling, Create a new direction and impulse
var HORIZ_SCALE = 0.50;
var VERT_SCALE = 0.50;
@ -139,3 +142,5 @@ Script.scriptEnding.connect(function() {
Entities.deleteEntity(butterflies[i]);
}
});
print("BUTTERFLIES END");

View file

@ -1,6 +1,20 @@
// Pool Table
// Billiards.js
//
// Created by Philip Rosedale on January 21, 2015
// Copyright 2014 High Fidelity, Inc.
//
// Creates a pool table in front of you. Hold and release space ball to shoot a ball.
// Cue ball will return if falls off table. Delete and reset to restart.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
var tableParts = [];
var balls = [];
var cueBall;
var LENGTH = 2.84;
var WIDTH = 1.42;
@ -13,9 +27,15 @@ var HOLE_SIZE = BALL_SIZE;
var DROP_HEIGHT = BALL_SIZE * 3.0;
var GRAVITY = -9.8;
var BALL_GAP = 0.001;
var tableCenter;
var cuePosition;
var startStroke = 0;
// Sounds to use
hitSounds = [];
hitSounds.push(SoundCache.getSound(HIFI_PUBLIC_BUCKET + "Collisions-ballhitsandcatches/billiards/collision1.wav"));
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
var screenSize = Controller.getViewportDimensions();
var reticle = Overlays.addOverlay("image", {
@ -23,7 +43,7 @@ var reticle = Overlays.addOverlay("image", {
y: screenSize.y / 2 - 16,
width: 32,
height: 32,
imageURL: HIFI_PUBLIC_BUCKET + "images/reticle.png",
imageURL: HIFI_PUBLIC_BUCKET + "images/billiardsReticle.png",
color: { red: 255, green: 255, blue: 255},
alpha: 1
});
@ -102,7 +122,7 @@ function makeBalls(pos) {
{ red: 128, green: 128, blue: 128}]; // Gray
// Object balls
var ballPosition = { x: pos.x + (LENGTH / 4.0) * SCALE, y: pos.y + DROP_HEIGHT, z: pos.z };
var ballPosition = { x: pos.x + (LENGTH / 4.0) * SCALE, y: pos.y + HEIGHT / 2.0 + DROP_HEIGHT, z: pos.z };
for (var row = 1; row <= 5; row++) {
ballPosition.z = pos.z - ((row - 1.0) / 2.0 * (BALL_SIZE + BALL_GAP) * SCALE);
for (var spot = 0; spot < row; spot++) {
@ -113,23 +133,36 @@ function makeBalls(pos) {
color: colors[balls.length],
gravity: { x: 0, y: GRAVITY, z: 0 },
ignoreCollisions: false,
damping: 0.40,
damping: 0.50,
collisionsWillMove: true }));
ballPosition.z += (BALL_SIZE + BALL_GAP) * SCALE;
}
ballPosition.x += (BALL_GAP + Math.sqrt(3.0) / 2.0 * BALL_SIZE) * SCALE;
}
// Cue Ball
ballPosition = { x: pos.x - (LENGTH / 4.0) * SCALE, y: pos.y + DROP_HEIGHT, z: pos.z };
balls.push(Entities.addEntity(
cuePosition = { x: pos.x - (LENGTH / 4.0) * SCALE, y: pos.y + HEIGHT / 2.0 + DROP_HEIGHT, z: pos.z };
cueBall = Entities.addEntity(
{ type: "Sphere",
position: ballPosition,
position: cuePosition,
dimensions: { x: BALL_SIZE * SCALE, y: BALL_SIZE * SCALE, z: BALL_SIZE * SCALE },
color: { red: 255, green: 255, blue: 255 },
gravity: { x: 0, y: GRAVITY, z: 0 },
angularVelocity: { x: 0, y: 0, z: 0 },
velocity: {x: 0, y: 0, z: 0 },
ignoreCollisions: false,
damping: 0.40,
collisionsWillMove: true }));
damping: 0.50,
collisionsWillMove: true });
}
function isObjectBall(id) {
for (var i; i < balls.length; i++) {
if (balls[i].id == id) {
return true;
}
}
return false;
}
function shootCue(velocity) {
@ -140,19 +173,23 @@ function shootCue(velocity) {
var velocity = Vec3.multiply(forwardVector, velocity);
var BULLET_LIFETIME = 3.0;
var BULLET_GRAVITY = 0.0;
var SHOOTER_COLOR = { red: 255, green: 0, blue: 0 };
var SHOOTER_SIZE = BALL_SIZE / 1.5 * SCALE;
bulletID = Entities.addEntity(
{ type: "Sphere",
position: cuePosition,
dimensions: { x: BALL_SIZE * SCALE, y: BALL_SIZE * SCALE, z: BALL_SIZE * SCALE },
color: { red: 255, green: 255, blue: 255 },
dimensions: { x: SHOOTER_SIZE, y: SHOOTER_SIZE, z: SHOOTER_SIZE },
color: SHOOTER_COLOR,
velocity: velocity,
lifetime: BULLET_LIFETIME,
gravity: { x: 0, y: BULLET_GRAVITY, z: 0 },
damping: 0.10,
density: 1000,
density: 8000,
ignoreCollisions: false,
collisionsWillMove: true
});
print("Shot, velocity = " + velocity);
}
function keyReleaseEvent(event) {
@ -185,13 +222,46 @@ function cleanup() {
Entities.deleteEntity(balls[i]);
}
Overlays.deleteOverlay(reticle);
Entities.deleteEntity(cueBall);
}
var tableCenter = Vec3.sum(MyAvatar.position, Vec3.multiply(4.0, Quat.getFront(Camera.getOrientation())));
function update(deltaTime) {
if (!cueBall.isKnownID) {
cueBall = Entities.identifyEntity(cueBall);
} else {
// Check if cue ball has fallen off table, re-drop if so
var cueProperties = Entities.getEntityProperties(cueBall);
if (cueProperties.position.y < tableCenter.y) {
// Replace the cueball
Entities.editEntity(cueBall, { position: cuePosition } );
}
}
}
function entityCollisionWithEntity(entity1, entity2, collision) {
/*
NOT WORKING YET
if ((entity1.id == cueBall.id) || (entity2.id == cueBall.id)) {
print("Cue ball collision!");
//audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
//Audio.playSound(hitSounds[0], { position: Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())) });
}
else if (isObjectBall(entity1.id) || isObjectBall(entity2.id)) {
print("Object ball collision");
} */
}
tableCenter = Vec3.sum(MyAvatar.position, Vec3.multiply(4.0, Quat.getFront(Camera.getOrientation())));
makeTable(tableCenter);
makeBalls(tableCenter);
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
Script.scriptEnding.connect(cleanup);
Controller.keyPressEvent.connect(keyPressEvent);
Controller.keyReleaseEvent.connect(keyReleaseEvent);
Script.update.connect(update);

View file

@ -168,14 +168,16 @@
</script>
</head>
<body onload='loaded();'>
<div>
<div id="entity-list-header">
<input type="button" id="refresh" value="Refresh"></button>
<input type="button" id="teleport" value="Teleport"></button>
<input type="button" id="delete" style="background-color: rgb(244, 64, 64); float: right" value="Delete"></button>
</div>
<div id="entity-list">
<input type="text" class="search" id="filter" placeholder="Filter" />
<div id="search-area">
<input type="text" class="search" id="filter" placeholder="Filter" />
</div>
<table id="entity-table">
<thead>
<tr>

View file

@ -119,6 +119,7 @@
var elCollisionsWillMove = document.getElementById("property-collisions-will-move");
var elLifetime = document.getElementById("property-lifetime");
var elScriptURL = document.getElementById("property-script-url");
var elUserData = document.getElementById("property-user-data");
var elBoxSections = document.querySelectorAll(".box-section");
var elBoxColorRed = document.getElementById("property-box-red");
@ -154,6 +155,7 @@
var elModelAnimationSettings = document.getElementById("property-model-animation-settings");
var elModelTextures = document.getElementById("property-model-textures");
var elModelOriginalTextures = document.getElementById("property-model-original-textures");
var elModelShapeType = document.getElementById("property-model-shape");
var elTextSections = document.querySelectorAll(".text-section");
var elTextText = document.getElementById("property-text-text");
@ -224,6 +226,7 @@
elCollisionsWillMove.checked = properties.collisionsWillMove;
elLifetime.value = properties.lifetime;
elScriptURL.value = properties.script;
elUserData.value = properties.userData;
if (properties.type != "Box") {
for (var i = 0; i < elBoxSections.length; i++) {
@ -256,6 +259,7 @@
elModelAnimationSettings.value = properties.animationSettings;
elModelTextures.value = properties.textures;
elModelOriginalTextures.value = properties.originalTextures;
elModelShapeType.value = properties.shapeType;
}
if (properties.type != "Text") {
@ -361,6 +365,7 @@
elCollisionsWillMove.addEventListener('change', createEmitCheckedPropertyUpdateFunction('collisionsWillMove'));
elLifetime.addEventListener('change', createEmitNumberPropertyUpdateFunction('lifetime'));
elScriptURL.addEventListener('change', createEmitTextPropertyUpdateFunction('script'));
elUserData.addEventListener('change', createEmitTextPropertyUpdateFunction('userData'));
var boxColorChangeFunction = createEmitColorPropertyUpdateFunction(
'color', elBoxColorRed, elBoxColorGreen, elBoxColorBlue);
@ -401,6 +406,7 @@
elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex'));
elModelAnimationSettings.addEventListener('change', createEmitTextPropertyUpdateFunction('animationSettings'));
elModelTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures'));
elModelShapeType.addEventListener('change', createEmitNumberPropertyUpdateFunction('shapeType'));
elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text'));
elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight'));
@ -559,13 +565,6 @@
</div>
<div class="property">
<div class="label">Mass</div>
<div class="value">
<input type='number' id="property-mass"></input>
</div>
</div>
<div>
<div class="label">Density</div>
<div>
<input type='number' id="property-density"></input>
@ -600,6 +599,13 @@
</div>
</div>
<div class="property">
<div class="label">User Data</div>
<div class="value">
<textarea id="property-user-data"></textarea>
</div>
</div>
<div class="box-section property">
<div class="label">Color</div>
@ -645,7 +651,7 @@
<div class="model-section property">
<div class="label">Animation Settings</div>
<div class="value">
<textarea id="property-model-animation-settings" value='asdfasdf'></textarea>
<textarea id="property-model-animation-settings"></textarea>
</div>
</div>
<div class="model-section property">
@ -661,6 +667,17 @@
</div>
</div>
<div class="model-section property">
<div class="label">Shape Type</div>
<div class="value">
<select name="SelectShapeType" id="property-model-shape" name="SelectShapeType">
<option value=0>None</option>
<option value=1>Box</option>
<option value=2>Sphere</option>
</select>
</div>
</div>
<div class="text-section property">
<div class="label">Text</div>

View file

@ -0,0 +1,166 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
function loaded() {
var gridColor = { red: 0, green: 0, blue: 0 };
var gridColors = [
{ red: 0, green: 0, blue: 0 },
{ red: 255, green: 255, blue: 255 },
{ red: 255, green: 0, blue: 0 },
{ red: 0, green: 255, blue: 0},
{ red: 0, green: 0, blue: 255 },
];
var gridColorIndex = 0;
elPosY = document.getElementById("horiz-y");
elMinorSpacing = document.getElementById("minor-spacing");
elMajorSpacing = document.getElementById("major-spacing");
elSnapToGrid = document.getElementById("snap-to-grid");
elHorizontalGridVisible = document.getElementById("horiz-grid-visible");
elMoveToSelection = document.getElementById("move-to-selection");
elMoveToAvatar = document.getElementById("move-to-avatar");
if (window.EventBridge !== undefined) {
EventBridge.scriptEventReceived.connect(function(data) {
data = JSON.parse(data);
if (data.origin) {
var origin = data.origin;
elPosY.value = origin.y.toFixed(2);
}
if (data.minorGridWidth !== undefined) {
elMinorSpacing.value = data.minorGridWidth;
}
if (data.majorGridEvery !== undefined) {
elMajorSpacing.value = data.majorGridEvery;
}
if (data.gridColor) {
gridColor = data.gridColor;
}
if (data.snapToGrid !== undefined) {
elSnapToGrid.checked = data.snapToGrid == true;
}
if (data.visible !== undefined) {
elHorizontalGridVisible.checked = data.visible == true;
}
});
function emitUpdate() {
EventBridge.emitWebEvent(JSON.stringify({
type: "update",
origin: {
y: elPosY.value,
},
minorGridWidth: elMinorSpacing.value,
majorGridEvery: elMajorSpacing.value,
gridColor: gridColor,
colorIndex: gridColorIndex,
snapToGrid: elSnapToGrid.checked,
visible: elHorizontalGridVisible.checked,
}));
}
}
elPosY.addEventListener("change", emitUpdate);
elMinorSpacing.addEventListener("change", emitUpdate);
elMajorSpacing.addEventListener("change", emitUpdate);
elSnapToGrid.addEventListener("change", emitUpdate);
elHorizontalGridVisible.addEventListener("change", emitUpdate);
elMoveToAvatar.addEventListener("click", function() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "moveToAvatar",
}));
});
elMoveToSelection.addEventListener("click", function() {
EventBridge.emitWebEvent(JSON.stringify({
type: "action",
action: "moveToSelection",
}));
});
var gridColorBox = document.getElementById('grid-color');
for (var i = 0; i < gridColors.length; i++) {
var colors = gridColors[i];
var box = document.createElement('div');
box.setAttribute('class', 'color-box');
box.style.background = 'rgb(' + colors.red + ', ' + colors.green + ', ' + colors.blue + ')';
document.getElementById("grid-colors").appendChild(box);
box.addEventListener("click", function(color, index) {
return function() {
gridColor = color;
gridColorIndex = index;
emitUpdate();
}
}({ red: colors.red, green: colors.green, blue: colors.blue }, i));
}
EventBridge.emitWebEvent(JSON.stringify({ type: 'init' }));
}
</script>
</head>
<body onload='loaded();'>
<div class="grid-section">
<div class="property-section">
<label>Visible</label>
<span>
<input type='checkbox' id="horiz-grid-visible">
</span>
</div>
<div class="property-section">
<label>Snap to grid</label>
<span>
<input type='checkbox' id="snap-to-grid">
</span>
</div>
<div id="horizontal-position" class="property-section">
<label>Position (Y Axis)</label>
<span>
<input type='number' id="horiz-y" class="number" value="0.0" step="0.1"></input>
</span>
</div>
<div class="property-section">
<label>Minor Grid Size</label>
<span>
<input type='number' id="minor-spacing" min="0" step="0.01", ></input>
</span>
</div>
<div class="property-section">
<label>Major Grid Every</label>
<span>
<input type='number' id="major-spacing" min="2" step="1", ></input>
</span>
</div>
<div class="property-section">
<label>Grid Color</label>
<span id="grid-colors"></span>
</div>
<div class="property-section">
<span>
<input type="button" id="move-to-selection" value="Move to Selection">
</span>
</div>
<div class="property-section">
<span>
<input type="button" id="move-to-avatar" value="Move to Avatar">
</span>
</div>
</div>
</body>
</html>

View file

@ -8,7 +8,7 @@ body {
background-color: rgb(76, 76, 76);
color: rgb(204, 204, 204);
font-family: Arial;
font-size: 11px;
font-size: 8.25pt;
-webkit-touch-callout: none;
-webkit-user-select: none;
@ -31,25 +31,25 @@ body {
.color-box {
display: inline-block;
width: 20px;
height: 20px;
border: 1px solid black;
margin: 2px;
width: 15pt;
height: 15pt;
border: 0.75pt solid black;
margin: 1.5pt;
cursor: pointer;
}
.color-box.highlight {
width: 18px;
height: 18px;
border: 2px solid black;
width: 13.5pt;
height: 13.5pt;
border: 1.5pt solid black;
}
.section-header {
background: #AAA;
border-bottom: 1px solid #CCC;
border-bottom: 0.75pt solid #CCC;
background-color: #333333;
color: #999;
padding: 4px;
padding: 3pt;
}
.section-header label {
@ -61,7 +61,7 @@ body {
.property-section {
display: block;
margin: 10 10;
height: 30px;
height: 22.5pt;
}
.property-section label {
@ -73,25 +73,37 @@ body {
}
.grid-section {
border-top: 1px solid #DDD;
background-color: #efefef;
}
input[type=button] {
cursor: pointer;
background-color: #608e96;
border-color: #608e96;
border-radius: 5px;
padding: 5px 10px;
border-radius: 3.75pt;
padding: 3.75pt 7.5pt;
border: 0;
color: #fff;
font-weight: bold;
}
#entity-list-header {
padding: 0.5em;
}
#search-area {
width: 100%;
padding: 0.5em;
box-sizing: border-box;
}
#search-area input {
width: 100%;
}
textarea, input {
margin: 0;
padding: 2px;
border: 1px solid #999;
padding: 1.5pt;
border: 0.75pt solid #999;
background-color: #eee;
}
@ -112,31 +124,32 @@ input.coord {
table#entity-table {
border-collapse: collapse;
font-family: Sans-Serif;
font-size: 10px;
font-size: 7.5pt;
width: 100%;
}
#entity-table tr {
cursor: pointer;
border-bottom: 1px solid rgb(63, 63, 63)
border-bottom: 0.75pt solid rgb(63, 63, 63)
}
#entity-table tr.selected {
color: rgb(43, 43, 43);
background-color: #AAA;
}
#entity-table th {
background-color: #333;
color: #fff;
border: 0px black solid;
border: 0pt black solid;
text-align: left;
word-wrap: nowrap;
white-space: nowrap;
}
#entity-table td {
font-size: 11px;
border: 0px black solid;
font-size: 8.25pt;
border: 0pt black solid;
word-wrap: nowrap;
white-space: nowrap;
text-overflow: ellipsis;
@ -148,47 +161,47 @@ table#entity-table {
}
th#entity-type {
width: 60px;
width: 33.75pt;
}
div.input-area {
display: inline-block;
font-size: 10px;
font-size: 7.5pt;
}
input {
}
#type {
font-size: 14px;
font-size: 10.5pt;
}
#type label {
color: rgb(150, 150, 150);
}
#properties-list input, #properties-list textarea {
input, textarea {
background-color: rgb(102, 102, 102);
color: rgb(204, 204, 204);
border: none;
font-size: 10px;
font-size: 7.5pt;
}
#properties-list input[type=button] {
cursor: pointer;
background-color: rgb(51, 102, 102);
border-color: #608e96;
border-radius: 5px;
padding: 5px 10px;
border-radius: 3.75pt;
padding: 3.75pt 7.5pt;
border: 0;
color: rgb(204, 204, 204);
}
#properties-list .property {
padding: 8px 8px;
border-top: 1px solid rgb(63, 63, 63);
padding: 6pt 6pt;
border-top: 0.75pt solid rgb(63, 63, 63);
min-height: 1em;
}
@ -203,11 +216,11 @@ table#properties-list {
}
#properties-list > div {
margin: 4px 0;
margin: 3pt 0;
}
#properties-list {
border-bottom: 1px solid #e5e5e5;
border-bottom: 0.75pt solid #e5e5e5;
}
#properties-list .label {
@ -221,11 +234,11 @@ table#properties-list {
}
#properties-list .value > div{
padding: 4px 0;
padding: 3pt 0;
}
col#col-label {
width: 130px;
width: 97.5pt;
}
div.outer {

View file

@ -158,6 +158,11 @@ function handleModes() {
avatarOrientation.w != MyAvatar.orientation.w)) {
newMode = noMode;
}
if (mode == noMode && newMode != noMode && Camera.mode == "independent") {
newMode = noMode;
}
// if leaving noMode
if (mode == noMode && newMode != noMode) {
saveCameraState();

View file

@ -15,8 +15,11 @@ var MOUSE_SENSITIVITY = 0.9;
var SCROLL_SENSITIVITY = 0.05;
var PAN_ZOOM_SCALE_RATIO = 0.4;
// Scaling applied based on the size of the object being focused
var FOCUS_ZOOM_SCALE = 1.3;
var KEY_ORBIT_SENSITIVITY = 90;
var KEY_ZOOM_SENSITIVITY = 3;
// Scaling applied based on the size of the object being focused (Larger values focus further away)
var FOCUS_ZOOM_SCALE = 2.3;
// Minimum zoom level when focusing on an object
var FOCUS_MIN_ZOOM = 0.5;
@ -43,6 +46,10 @@ var easeOutCubic = function(t) {
EASE_TIME = 0.5;
function clamp(value, minimum, maximum) {
return Math.min(Math.max(value, minimum), maximum);
}
function mergeObjects(obj1, obj2) {
var newObj = {};
for (key in obj1) {
@ -60,6 +67,49 @@ CameraManager = function() {
that.enabled = false;
that.mode = MODE_INACTIVE;
var actions = {
orbitLeft: 0,
orbitRight: 0,
orbitUp: 0,
orbitDown: 0,
orbitForward: 0,
orbitBackward: 0,
}
var keyToActionMapping = {
"a": "orbitLeft",
"d": "orbitRight",
"w": "orbitForward",
"s": "orbitBackward",
"e": "orbitUp",
"c": "orbitDown",
"LEFT": "orbitLeft",
"RIGHT": "orbitRight",
"UP": "orbitForward",
"DOWN": "orbitBackward",
}
var CAPTURED_KEYS = [];
for (key in keyToActionMapping) {
CAPTURED_KEYS.push(key);
}
function getActionForKeyEvent(event) {
var action = keyToActionMapping[event.text];
if (action !== undefined) {
if (event.isShifted) {
if (action == "orbitForward") {
action = "orbitUp";
} else if (action == "orbitBackward") {
action = "orbitDown";
}
}
return action;
}
return null;
}
that.zoomDistance = INITIAL_ZOOM_DISTANCE;
that.targetZoomDistance = INITIAL_ZOOM_DISTANCE;
@ -80,7 +130,12 @@ CameraManager = function() {
that.lastMousePosition = { x: 0, y: 0 };
that.enable = function() {
if (that.enabled) return;
if (Camera.mode == "independent" || that.enabled) return;
for (var i = 0; i < CAPTURED_KEYS.length; i++) {
Controller.captureKeyEvents({ text: CAPTURED_KEYS[i] });
}
that.enabled = true;
that.mode = MODE_INACTIVE;
@ -111,6 +166,11 @@ CameraManager = function() {
that.disable = function(ignoreCamera) {
if (!that.enabled) return;
for (var i = 0; i < CAPTURED_KEYS.length; i++) {
Controller.releaseKeyEvents({ text: CAPTURED_KEYS[i] });
}
that.enabled = false;
that.mode = MODE_INACTIVE;
@ -207,6 +267,11 @@ CameraManager = function() {
if (that.enabled && that.mode != MODE_INACTIVE) {
var x = Window.getCursorPositionX();
var y = Window.getCursorPositionY();
if (!hasDragged) {
that.lastMousePosition.x = x;
that.lastMousePosition.y = y;
hasDragged = true;
}
if (that.mode == MODE_ORBIT) {
var diffX = x - that.lastMousePosition.x;
var diffY = y - that.lastMousePosition.y;
@ -234,9 +299,31 @@ CameraManager = function() {
that.moveFocalPoint(dPosition);
}
var newX = Window.x + Window.innerWidth / 2;
var newY = Window.y + Window.innerHeight / 2;
Window.setCursorPosition(newX, newY);
var newX = x;
var newY = y;
var updatePosition = false;
if (x <= Window.x) {
newX = Window.x + Window.innerWidth;
updatePosition = true;
} else if (x >= (Window.x + Window.innerWidth)) {
newX = Window.x;
updatePosition = true;
}
if (y <= Window.y) {
newY = Window.y + Window.innerHeight;
updatePosition = true;
} else if (y >= (Window.y + Window.innerHeight)) {
newY = Window.y;
updatePosition = true;
}
if (updatePosition) {
Window.setCursorPosition(newX, newY);
}
that.lastMousePosition.x = newX;
that.lastMousePosition.y = newY;
@ -245,6 +332,7 @@ CameraManager = function() {
return false;
}
var hasDragged = false;
that.mousePressEvent = function(event) {
if (cameraTool.mousePressEvent(event)) {
return true;
@ -259,12 +347,7 @@ CameraManager = function() {
}
if (that.mode != MODE_INACTIVE) {
var newX = Window.x + Window.innerWidth / 2;
var newY = Window.y + Window.innerHeight / 2;
Window.setCursorPosition(newX, newY);
that.lastMousePosition.x = newX;
that.lastMousePosition.y = newY;
Window.setCursorVisible(false);
hasDragged = false;
return true;
}
@ -279,6 +362,20 @@ CameraManager = function() {
that.mode = MODE_INACTIVE;
}
that.keyPressEvent = function(event) {
var action = getActionForKeyEvent(event);
if (action) {
actions[action] = 1;
}
};
that.keyReleaseEvent = function(event) {
var action = getActionForKeyEvent(event);
if (action) {
actions[action] = 0;
}
};
that.wheelEvent = function(event) {
if (!that.enabled) return;
@ -332,6 +429,19 @@ CameraManager = function() {
return;
}
// Update based on current actions
that.targetYaw += (actions.orbitRight - actions.orbitLeft) * dt * KEY_ORBIT_SENSITIVITY;
that.targetPitch += (actions.orbitUp - actions.orbitDown) * dt * KEY_ORBIT_SENSITIVITY;
that.targetPitch = clamp(that.targetPitch, -90, 90);
var dZoom = actions.orbitBackward - actions.orbitForward;
if (dZoom) {
dZoom *= that.targetZoomDistance * dt * KEY_ZOOM_SENSITIVITY;
that.targetZoomDistance += dZoom;
that.targetZoomDistance = clamp(that.targetZoomDistance, MIN_ZOOM_DISTANCE, MAX_ZOOM_DISTANCE);
}
if (easing) {
easingTime = Math.min(EASE_TIME, easingTime + dt);
}
@ -383,6 +493,7 @@ CameraManager = function() {
});
Script.update.connect(that.update);
Script.scriptEnding.connect(that.disable);
Controller.wheelEvent.connect(that.wheelEvent);

View file

@ -1221,7 +1221,7 @@ SelectionDisplay = (function () {
x: selectionManager.worldDimensions.x,
y: selectionManager.worldDimensions.z
},
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
rotation: Quat.fromPitchYawRollDegrees(90, 0, 0),
});

View file

@ -2,11 +2,11 @@ Grid = function(opts) {
var that = {};
var colors = [
{ red: 0, green: 255, blue: 0 },
{ red: 255, green: 255, blue: 255 },
{ red: 0, green: 0, blue: 0 },
{ red: 0, green: 0, blue: 255 },
{ red: 255, green: 255, blue: 255 },
{ red: 255, green: 0, blue: 0 },
{ red: 0, green: 255, blue: 0 },
{ red: 0, green: 0, blue: 255 },
];
var colorIndex = 0;
var gridAlpha = 0.6;
@ -224,273 +224,50 @@ Grid = function(opts) {
GridTool = function(opts) {
var that = {};
var UI_URL = HIFI_PUBLIC_BUCKET + "images/tools/grid-toolbar.svg";
var UI_WIDTH = 854;
var UI_HEIGHT = 37;
var horizontalGrid = opts.horizontalGrid;
var verticalGrid = opts.verticalGrid;
var listeners = [];
var uiOverlays = {};
var allOverlays = [];
var url = Script.resolvePath('html/gridControls.html');
var webView = new WebWindow('Grid', url, 200, 280);
function addUIOverlay(key, overlay, x, y, width, height) {
uiOverlays[key] = {
overlay: overlay,
x: x,
y: y,
width: width,
height: height,
};
allOverlays.push(overlay);
}
horizontalGrid.addListener(function(data) {
webView.eventBridge.emitScriptEvent(JSON.stringify(data));
selectionDisplay.updateHandles();
});
var lastKnownWindowWidth = null;
function repositionUI() {
if (lastKnownWindowWidth == Window.innerWidth) {
return;
}
lastKnownWindowWidth = Window.innerWidth;
var x = Window.innerWidth / 2 - UI_WIDTH / 2;
var y = 10;
for (var key in uiOverlays) {
info = uiOverlays[key];
Overlays.editOverlay(info.overlay, {
x: x + info.x,
y: y + info.y,
});
}
}
// "Spritesheet" is laid out horizontally in this order
var UI_SPRITE_LIST = [
{ name: "gridText", width: 54 },
{ name: "visibleCheckbox", width: 60 },
{ name: "snapToGridCheckbox", width: 105 },
{ name: "color0", width: 27 },
{ name: "color1", width: 27 },
{ name: "color2", width: 27 },
{ name: "color3", width: 27 },
{ name: "color4", width: 27 },
{ name: "minorGridIcon", width: 34 },
{ name: "minorGridDecrease", width: 25 },
{ name: "minorGridInput", width: 26 },
{ name: "minorGridIncrease", width: 25 },
{ name: "majorGridIcon", width: 40 },
{ name: "majorGridDecrease", width: 25 },
{ name: "majorGridInput", width: 26 },
{ name: "majorGridIncrease", width: 25 },
{ name: "yPositionLabel", width: 160 },
{ name: "moveToLabel", width: 54 },
{ name: "moveToAvatar", width: 26 },
{ name: "moveToSelection", width: 34 },
];
// Add all overlays from spritesheet
var baseOverlay = null;
var x = 0;
for (var i = 0; i < UI_SPRITE_LIST.length; i++) {
var info = UI_SPRITE_LIST[i];
var props = {
imageURL: UI_URL,
subImage: { x: x, y: 0, width: info.width, height: UI_HEIGHT },
width: info.width,
height: UI_HEIGHT,
alpha: 1.0,
visible: false,
};
var overlay;
if (baseOverlay == null) {
overlay = Overlays.addOverlay("image", {
imageURL: UI_URL,
});
baseOverlay = overlay;
} else {
overlay = Overlays.cloneOverlay(baseOverlay);
}
Overlays.editOverlay(overlay, props);
addUIOverlay(info.name, overlay, x, 0, info.width, UI_HEIGHT);
x += info.width;
}
// Add Text overlays
var textProperties = {
color: { red: 255, green: 255, blue: 255 },
topMargin: 6,
leftMargin: 4,
alpha: 1,
backgroundAlpha: 0,
text: "",
font: { size: 12 },
visible: false,
};
var minorGridWidthText = Overlays.addOverlay("text", textProperties);
var majorGridEveryText = Overlays.addOverlay("text", textProperties);
var yPositionText = Overlays.addOverlay("text", textProperties);
addUIOverlay('minorGridWidthText', minorGridWidthText, 414, 8, 24, 24);
addUIOverlay('majorGridEveryText', majorGridEveryText, 530, 8, 24, 24);
addUIOverlay('yPositionText', yPositionText, 660, 8, 24, 24);
var NUM_COLORS = 5;
function updateColorIndex(index) {
if (index < 0 || index >= NUM_COLORS) {
return;
}
for (var i = 0 ; i < NUM_COLORS; i++) {
var info = uiOverlays['color' + i];
Overlays.editOverlay(info.overlay, {
subImage: {
x: info.x,
y: i == index ? UI_HEIGHT : 0,
width: info.width,
height: info.height,
}
});
}
}
function updateGridVisible(value) {
var info = uiOverlays.visibleCheckbox;
Overlays.editOverlay(info.overlay, {
subImage: {
x: info.x,
y: value ? UI_HEIGHT : 0,
width: info.width,
height: info.height,
webView.eventBridge.webEventReceived.connect(function(data) {
data = JSON.parse(data);
if (data.type == "init") {
horizontalGrid.emitUpdate();
} else if (data.type == "update") {
horizontalGrid.update(data);
for (var i = 0; i < listeners.length; i++) {
listeners[i](data);
}
});
}
function updateSnapToGrid(value) {
var info = uiOverlays.snapToGridCheckbox;
Overlays.editOverlay(info.overlay, {
subImage: {
x: info.x,
y: value ? UI_HEIGHT : 0,
width: info.width,
height: info.height,
}
});
}
function updateMinorGridWidth(value) {
Overlays.editOverlay(minorGridWidthText, {
text: value.toFixed(1),
});
}
function updateMajorGridEvery(value) {
Overlays.editOverlay(majorGridEveryText, {
text: value,
});
}
function updateYPosition(value) {
Overlays.editOverlay(yPositionText, {
text: value.toFixed(2),
});
}
function updateOverlays() {
updateGridVisible(horizontalGrid.getVisible());
updateSnapToGrid(horizontalGrid.getSnapToGrid());
updateColorIndex(horizontalGrid.getColorIndex());
updateMinorGridWidth(horizontalGrid.getMinorGridWidth());
updateMajorGridEvery(horizontalGrid.getMajorGridEvery());
updateYPosition(horizontalGrid.getOrigin().y);
}
that.setVisible = function(visible) {
for (var i = 0; i < allOverlays.length; i++) {
Overlays.editOverlay(allOverlays[i], { visible: visible });
}
}
that.mousePressEvent = function(event) {
var overlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
if (allOverlays.indexOf(overlay) >= 0) {
if (overlay == uiOverlays.color0.overlay) {
horizontalGrid.setColorIndex(0);
} else if (overlay == uiOverlays.color1.overlay) {
horizontalGrid.setColorIndex(1);
} else if (overlay == uiOverlays.color2.overlay) {
horizontalGrid.setColorIndex(2);
} else if (overlay == uiOverlays.color3.overlay) {
horizontalGrid.setColorIndex(3);
} else if (overlay == uiOverlays.color4.overlay) {
horizontalGrid.setColorIndex(4);
} else if (overlay == uiOverlays.visibleCheckbox.overlay) {
horizontalGrid.setVisible(!horizontalGrid.getVisible());
} else if (overlay == uiOverlays.snapToGridCheckbox.overlay) {
horizontalGrid.setSnapToGrid(!horizontalGrid.getSnapToGrid());
} else if (overlay == uiOverlays.moveToAvatar.overlay) {
} else if (data.type == "action") {
var action = data.action;
if (action == "moveToAvatar") {
var position = MyAvatar.getJointPosition("LeftFoot");
if (position.x == 0 && position.y == 0 && position.z == 0) {
position = MyAvatar.position;
}
horizontalGrid.setPosition(position);
} else if (overlay == uiOverlays.moveToSelection.overlay) {
} else if (action == "moveToSelection") {
var newPosition = selectionManager.worldPosition;
newPosition = Vec3.subtract(newPosition, { x: 0, y: selectionManager.worldDimensions.y * 0.5, z: 0 });
horizontalGrid.setPosition(newPosition);
} else if (overlay == uiOverlays.minorGridDecrease.overlay) {
var newValue = Math.max(0.1, horizontalGrid.getMinorGridWidth() - 0.1);
horizontalGrid.setMinorGridWidth(newValue);
} else if (overlay == uiOverlays.minorGridIncrease.overlay) {
horizontalGrid.setMinorGridWidth(horizontalGrid.getMinorGridWidth() + 0.1);
} else if (overlay == uiOverlays.majorGridDecrease.overlay) {
var newValue = Math.max(2, horizontalGrid.getMajorGridEvery() - 1);
horizontalGrid.setMajorGridEvery(newValue);
} else if (overlay == uiOverlays.majorGridIncrease.overlay) {
horizontalGrid.setMajorGridEvery(horizontalGrid.getMajorGridEvery() + 1);
} else if (overlay == uiOverlays.yPositionLabel.overlay) {
var newValue = Window.prompt("Y Position:", horizontalGrid.getOrigin().y.toFixed(4));
if (newValue !== null) {
var y = parseFloat(newValue)
if (isNaN(y)) {
Window.alert("Invalid position");
} else {
horizontalGrid.setPosition({ x: 0, y: y, z: 0 });
}
}
grid.setPosition(newPosition);
}
// Clicking anywhere within the toolbar will "consume" this press event
return true;
}
return false;
};
Script.scriptEnding.connect(function() {
for (var i = 0; i < allOverlays.length; i++) {
Overlays.deleteOverlay(allOverlays[i]);
}
});
Script.update.connect(repositionUI);
horizontalGrid.addListener(function() {
selectionDisplay.updateHandles();
updateOverlays();
});
that.addListener = function(callback) {
listeners.push(callback);
}
updateOverlays();
repositionUI();
that.setVisible = function(visible) {
webView.setVisible(visible);
}
return that;
};

View file

@ -21,7 +21,7 @@ modelUploader = (function () {
//svoBuffer,
mapping,
geometry,
API_URL = "https://data.highfidelity.io/api/v1/models",
API_URL = "https://metaverse.highfidelity.io/api/v1/models",
MODEL_URL = "http://public.highfidelity.io/models/content",
NAME_FIELD = "name",
SCALE_FIELD = "scale",

View file

@ -147,9 +147,13 @@ KeyboardKey = (function(keyboard, keyProperties) {
return true;
};
for (var i = 0; i < this.bounds.length; i++) {
var newOverlay = Overlays.cloneOverlay(this.keyboard.background);
if (THREE_D_MODE) {
Overlays.editOverlay(newOverlay, {
this.overlays.push(Overlays.addOverlay("billboard", {
scale: 1,
rotation: MyAvatar.rotation,
isFacingAvatar: false,
url: KEYBOARD_URL,
alpha: 1,
position: {
x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale,
y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale,
@ -160,9 +164,10 @@ KeyboardKey = (function(keyboard, keyProperties) {
subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]},
alpha: 1,
visible: tthis.keyboard.visible
});
}));
} else {
Overlays.editOverlay(newOverlay, {
this.overlays.push(Overlays.addOverlay("image", {
imageURL: KEYBOARD_URL,
x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale,
y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale,
width: this.bounds[i][BOUND_W] * keyboard.scale,
@ -170,9 +175,8 @@ KeyboardKey = (function(keyboard, keyProperties) {
subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]},
alpha: 1,
visible: tthis.keyboard.visible
});
}));
}
this.overlays.push(newOverlay);
}
});
@ -317,6 +321,8 @@ Keyboard = (function(params) {
for (var i = 0; i < this.keys.length; i++) {
this.keys[i].remove();
}
// resets the cursor and magnifier
this.updateVisibility(false);
};
this.show = function() {
@ -336,6 +342,7 @@ Keyboard = (function(params) {
if (HMD.magnifier == visible) {
HMD.toggleMagnifier();
}
Window.cursorVisible = !visible;
Overlays.editOverlay(tthis.background, { visible: tthis.visible });
for (var i = 0; i < this.keys.length; i++) {
this.keys[i].updateVisibility();
@ -440,13 +447,12 @@ Keyboard = (function(params) {
{bounds: [[899, 355, 263, 67]], event: 'submit'}
];
for (var i = 0; i < keyProperties.length; i++) {
this.keys.push(new KeyboardKey(this, keyProperties[i]));
}
this.keyboardTextureLoaded = function() {
if (Overlays.isLoaded(tthis.background)) {
Script.clearInterval(tthis.keyboardTextureLoaded_timer);
for (var i = 0; i < keyProperties.length; i++) {
tthis.keys.push(new KeyboardKey(tthis, keyProperties[i]));
}
if (keyboard.onFullyLoaded != null) {
tthis.onFullyLoaded();
}
@ -510,12 +516,16 @@ Cursor = (function(params) {
});
}
var editobject = {};
if (tthis.x !== HMD.HUDLookAtPosition2D.x) {
tthis.x = HMD.HUDLookAtPosition2D.x;
var hudLookatPosition = HMD.getHUDLookAtPosition2D();
if (hudLookatPosition === null) {
return;
}
if (tthis.x !== hudLookatPosition.x) {
tthis.x = hudLookatPosition.x;
editobject.x = tthis.x - (CURSOR_WIDTH / 2);
}
if (tthis.y !== HMD.HUDLookAtPosition2D.y) {
tthis.y = HMD.HUDLookAtPosition2D.y;
if (tthis.y !== hudLookatPosition.y) {
tthis.y = hudLookatPosition.y;
editobject.y = tthis.y - (CURSOR_HEIGHT / 2);
}
if (Object.keys(editobject).length > 0) {

View file

@ -55,7 +55,9 @@ var droneSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/drone.st
var currentDrone = null;
var latinSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/latin.stereo.raw")
var latinInjector = null;
var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/elevator.stereo.raw")
var elevatorInjector = null;
var currentMuzakInjector = null;
var currentSound = null;
@ -140,7 +142,11 @@ function drawLobby() {
if (droneSound.downloaded) {
// start the drone sound
currentDrone = Audio.playSound(droneSound, { stereo: true, loop: true, localOnly: true, volume: DRONE_VOLUME });
if (!currentDrone) {
currentDrone = Audio.playSound(droneSound, { stereo: true, loop: true, localOnly: true, volume: DRONE_VOLUME });
} else {
currentDrone.restart();
}
}
// start one of our muzak sounds
@ -152,7 +158,7 @@ var places = {};
function changeLobbyTextures() {
var req = new XMLHttpRequest();
req.open("GET", "https://data.highfidelity.io/api/v1/places?limit=21", false);
req.open("GET", "https://metaverse.highfidelity.io/api/v1/places?limit=21", false);
req.send();
places = JSON.parse(req.responseText).data.places;
@ -173,6 +179,26 @@ function changeLobbyTextures() {
var MUZAK_VOLUME = 0.1;
function playCurrentSound(secondOffset) {
if (currentSound == latinSound) {
if (!latinInjector) {
latinInjector = Audio.playSound(latinSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME });
} else {
latinInjector.restart();
}
currentMuzakInjector = latinInjector;
} else if (currentSound == elevatorSound) {
if (!elevatorInjector) {
elevatorInjector = Audio.playSound(elevatorSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME });
} else {
elevatorInjector.restart();
}
currentMuzakInjector = elevatorInjector;
}
}
function playNextMuzak() {
if (panelWall) {
if (currentSound == latinSound) {
@ -184,8 +210,8 @@ function playNextMuzak() {
currentSound = latinSound;
}
}
currentMuzakInjector = Audio.playSound(currentSound, { localOnly: true, volume: MUZAK_VOLUME });
playCurrentSound(0);
}
}
@ -200,10 +226,11 @@ function playRandomMuzak() {
currentSound = elevatorSound;
}
if (currentSound) {
if (currentSound) {
// pick a random number of seconds from 0-10 to offset the muzak
var secondOffset = Math.random() * 10;
currentMuzakInjector = Audio.playSound(currentSound, { localOnly: true, secondOffset: secondOffset, volume: MUZAK_VOLUME });
playCurrentSound(secondOffset);
} else {
currentMuzakInjector = null;
}
@ -227,10 +254,9 @@ function cleanupLobby() {
panelWall = false;
orbShell = false;
Audio.stopInjector(currentDrone);
currentDrone = null;
currentDrone.stop();
currentMuzakInjector.stop();
Audio.stopInjector(currentMuzakInjector);
currentMuzakInjector = null;
places = {};
@ -354,7 +380,7 @@ function update(deltaTime) {
Overlays.editOverlay(descriptionText, { position: textOverlayPosition() });
// if the reticle is up then we may need to play the next muzak
if (currentMuzakInjector && !Audio.isInjectorPlaying(currentMuzakInjector)) {
if (currentMuzakInjector && !currentMuzakInjector.isPlaying) {
playNextMuzak();
}
}

View file

@ -80,14 +80,6 @@ Controller.mousePressEvent.connect(mousePressEvent);
Controller.mouseMoveEvent.connect(mouseMoveEvent);
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
// disable the standard application for mouse events
Controller.captureMouseEvents();
function scriptEnding() {
// re-enabled the standard application for mouse events
Controller.releaseMouseEvents();
}
MyAvatar.bodyYaw = 0;
MyAvatar.bodyPitch = 0;
MyAvatar.bodyRoll = 0;

View file

@ -52,18 +52,17 @@
// 2. Declare a text string.
// 3. Call createNotifications(text) parsing the text.
// example:
// var welcome;
// if (key.text == "q") { //queries number of users online
// var numUsers = GlobalServices.onlineUsers.length;
// var welcome = "There are " + numUsers + " users online now.";
// var welcome = "There are " + GlobalServices.onlineUsers.length + " users online now.";
// createNotification(welcome);
// }
Script.include("./libraries/globals.js");
Script.include("./libraries/soundArray.js");
var width = 340.0; //width of notification overlay
var height = 40.0; // height of a single line notification overlay
var windowDimensions = Controller.getViewportDimensions(); // get the size of the interface window
var overlayLocationX = (windowDimensions.x - (width + 20.0));// positions window 20px from the right of the interface window
var overlayLocationX = (windowDimensions.x - (width + 20.0)); // positions window 20px from the right of the interface window
var buttonLocationX = overlayLocationX + (width - 28.0);
var locationY = 20.0; // position down from top of interface window
var topMargin = 13.0;
@ -72,7 +71,9 @@ var textColor = { red: 228, green: 228, blue: 228}; // text color
var backColor = { red: 2, green: 2, blue: 2}; // background color was 38,38,38
var backgroundAlpha = 0;
var fontSize = 12.0;
var persistTime = 10.0; // time in seconds before notification fades
var PERSIST_TIME_2D = 10.0; // Time in seconds before notification fades
var PERSIST_TIME_3D = 15.0;
var persistTime = PERSIST_TIME_2D;
var clickedText = false;
var frame = 0;
var ourWidth = Window.innerWidth;
@ -104,25 +105,182 @@ var times = [];
var heights = [];
var myAlpha = [];
var arrays = [];
var isOnHMD = false,
ENABLE_VR_MODE = "Enable VR Mode",
NOTIFICATIONS_3D_DIRECTION = 0.0, // Degrees from avatar orientation.
NOTIFICATIONS_3D_DISTANCE = 0.6, // Horizontal distance from avatar position.
NOTIFICATIONS_3D_ELEVATION = -0.8, // Height of top middle of top notification relative to avatar eyes.
NOTIFICATIONS_3D_YAW = 0.0, // Degrees relative to notifications direction.
NOTIFICATIONS_3D_PITCH = -60.0, // Degrees from vertical.
NOTIFICATION_3D_SCALE = 0.002, // Multiplier that converts 2D overlay dimensions to 3D overlay dimensions.
NOTIFICATION_3D_BUTTON_WIDTH = 40 * NOTIFICATION_3D_SCALE, // Need a little more room for button in 3D.
overlay3DDetails = [];
// push data from above to the 2 dimensional array
function createArrays(notice, button, createTime, height, myAlpha) {
arrays.push([notice, button, createTime, height, myAlpha]);
}
// This handles the final dismissal of a notification after fading
function dismiss(firstNoteOut, firstButOut, firstOut) {
Overlays.deleteOverlay(firstNoteOut);
Overlays.deleteOverlay(firstButOut);
notifications.splice(firstOut, 1);
buttons.splice(firstOut, 1);
times.splice(firstOut, 1);
heights.splice(firstOut, 1);
myAlpha.splice(firstOut, 1);
overlay3DDetails.splice(firstOut, 1);
}
function fadeIn(noticeIn, buttonIn) {
var q = 0,
qFade,
pauseTimer = null;
pauseTimer = Script.setInterval(function () {
q += 1;
qFade = q / 10.0;
Overlays.editOverlay(noticeIn, { alpha: qFade });
Overlays.editOverlay(buttonIn, { alpha: qFade });
if (q >= 9.0) {
Script.clearInterval(pauseTimer);
}
}, 10);
}
// this fades the notification ready for dismissal, and removes it from the arrays
function fadeOut(noticeOut, buttonOut, arraysOut) {
var r = 9.0,
rFade,
pauseTimer = null;
pauseTimer = Script.setInterval(function () {
r -= 1;
rFade = r / 10.0;
Overlays.editOverlay(noticeOut, { alpha: rFade });
Overlays.editOverlay(buttonOut, { alpha: rFade });
if (r < 0) {
dismiss(noticeOut, buttonOut, arraysOut);
arrays.splice(arraysOut, 1);
ready = true;
Script.clearInterval(pauseTimer);
}
}, 20);
}
function calculate3DOverlayPositions(noticeWidth, noticeHeight, y) {
// Calculates overlay positions and orientations in avatar coordinates.
var noticeY,
originOffset,
notificationOrientation,
notificationPosition,
buttonPosition;
// Notification plane positions
noticeY = -y * NOTIFICATION_3D_SCALE - noticeHeight / 2;
notificationPosition = { x: 0, y: noticeY, z: 0 };
buttonPosition = { x: (noticeWidth - NOTIFICATION_3D_BUTTON_WIDTH) / 2, y: noticeY, z: 0.001 };
// Rotate plane
notificationOrientation = Quat.fromPitchYawRollDegrees(NOTIFICATIONS_3D_PITCH,
NOTIFICATIONS_3D_DIRECTION + NOTIFICATIONS_3D_YAW, 0);
notificationPosition = Vec3.multiplyQbyV(notificationOrientation, notificationPosition);
buttonPosition = Vec3.multiplyQbyV(notificationOrientation, buttonPosition);
// Translate plane
originOffset = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, NOTIFICATIONS_3D_DIRECTION, 0),
{ x: 0, y: 0, z: -NOTIFICATIONS_3D_DISTANCE });
originOffset.y += NOTIFICATIONS_3D_ELEVATION;
notificationPosition = Vec3.sum(originOffset, notificationPosition);
buttonPosition = Vec3.sum(originOffset, buttonPosition);
return {
notificationOrientation: notificationOrientation,
notificationPosition: notificationPosition,
buttonPosition: buttonPosition
};
}
// Pushes data to each array and sets up data for 2nd dimension array
// to handle auxiliary data not carried by the overlay class
// specifically notification "heights", "times" of creation, and .
function notify(notice, button, height) {
var noticeWidth,
noticeHeight,
positions,
last;
randomSounds.playRandom();
if (isOnHMD) {
// Calculate 3D values from 2D overlay properties.
noticeWidth = notice.width * NOTIFICATION_3D_SCALE + NOTIFICATION_3D_BUTTON_WIDTH;
noticeHeight = notice.height * NOTIFICATION_3D_SCALE;
notice.size = { x: noticeWidth, y: noticeHeight };
notice.topMargin = 0.75 * notice.topMargin * NOTIFICATION_3D_SCALE;
notice.leftMargin = 2 * notice.leftMargin * NOTIFICATION_3D_SCALE;
notice.bottomMargin = 0;
notice.rightMargin = 0;
notice.lineHeight = 10.0 * (fontSize / 12.0) * NOTIFICATION_3D_SCALE;
notice.isFacingAvatar = false;
button.url = button.imageURL;
button.scale = button.width * NOTIFICATION_3D_SCALE;
button.isFacingAvatar = false;
positions = calculate3DOverlayPositions(noticeWidth, noticeHeight, notice.y);
notifications.push((Overlays.addOverlay("text3d", notice)));
buttons.push((Overlays.addOverlay("billboard", button)));
overlay3DDetails.push({
notificationOrientation: positions.notificationOrientation,
notificationPosition: positions.notificationPosition,
buttonPosition: positions.buttonPosition,
width: noticeWidth,
height: noticeHeight
});
} else {
notifications.push((Overlays.addOverlay("text", notice)));
buttons.push((Overlays.addOverlay("image", button)));
}
height = height + 1.0;
heights.push(height);
times.push(new Date().getTime() / 1000);
myAlpha.push(0);
last = notifications.length - 1;
createArrays(notifications[last], buttons[last], times[last], heights[last], myAlpha[last]);
fadeIn(notifications[last], buttons[last]);
}
// This function creates and sizes the overlays
function createNotification(text) {
var count = (text.match(/\n/g) || []).length;
var breakPoint = 43.0; // length when new line is added
var extraLine = 0;
var breaks = 0;
var height = 40.0;
var stack = 0;
var count = (text.match(/\n/g) || []).length,
breakPoint = 43.0, // length when new line is added
extraLine = 0,
breaks = 0,
height = 40.0,
stack = 0,
level,
noticeProperties,
bLevel,
buttonProperties,
i;
if (text.length >= breakPoint) {
breaks = count;
}
var extraLine = breaks * 16.0;
for (i = 0; i < heights.length; i++) {
extraLine = breaks * 16.0;
for (i = 0; i < heights.length; i += 1) {
stack = stack + heights[i];
}
var level = (stack + 20.0);
level = (stack + 20.0);
height = height + extraLine;
var overlayProperties = {
noticeProperties = {
x: overlayLocationX,
y: level,
width: width,
@ -133,10 +291,11 @@ function createNotification(text) {
topMargin: topMargin,
leftMargin: leftMargin,
font: {size: fontSize},
text: text,
};
var bLevel = level + 12.0;
var buttonProperties = {
text: text
};
bLevel = level + 12.0;
buttonProperties = {
x: buttonLocationX,
y: bLevel,
width: 10.0,
@ -145,88 +304,43 @@ function createNotification(text) {
imageURL: "http://hifi-public.s3.amazonaws.com/images/close-small-light.svg",
color: { red: 255, green: 255, blue: 255},
visible: true,
alpha: backgroundAlpha,
};
Notify(overlayProperties, buttonProperties, height);
alpha: backgroundAlpha
};
notify(noticeProperties, buttonProperties, height);
}
// Pushes data to each array and sets up data for 2nd dimension array
// to handle auxiliary data not carried by the overlay class
// specifically notification "heights", "times" of creation, and .
function Notify(notice, button, height){
randomSounds.playRandom();
notifications.push((Overlays.addOverlay("text", notice)));
buttons.push((Overlays.addOverlay("image",button)));
times.push(new Date().getTime() / 1000);
height = height + 1.0;
heights.push(height);
myAlpha.push(0);
var last = notifications.length - 1;
createArrays(notifications[last], buttons[last], times[last], heights[last], myAlpha[last]);
fadeIn(notifications[last], buttons[last])
function deleteNotification(index) {
Overlays.deleteOverlay(notifications[index]);
Overlays.deleteOverlay(buttons[index]);
notifications.splice(index, 1);
buttons.splice(index, 1);
times.splice(index, 1);
heights.splice(index, 1);
myAlpha.splice(index, 1);
overlay3DDetails.splice(index, 1);
arrays.splice(index, 1);
}
function fadeIn(noticeIn, buttonIn) {
var myLength = arrays.length;
var q = 0;
var pauseTimer = null;
pauseTimer = Script.setInterval(function() {
q++;
qFade = q / 10.0;
Overlays.editOverlay(noticeIn, {alpha: qFade});
Overlays.editOverlay(buttonIn, {alpha: qFade});
if (q >= 9.0) {
Script.clearInterval(pauseTimer);
// wraps whole word to newline
function stringDivider(str, slotWidth, spaceReplacer) {
var p,
left,
right;
if (str.length > slotWidth) {
p = slotWidth;
while (p > 0 && str[p] !== ' ') {
p -= 1;
}
}, 10);
}
// push data from above to the 2 dimensional array
function createArrays(notice, button, createTime, height, myAlpha) {
arrays.push([notice, button, createTime, height, myAlpha]);
}
// handles mouse clicks on buttons
function mousePressEvent(event) {
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); //identify which overlay was clicked
for (i = 0; i < buttons.length; i++) { //if user clicked a button
if(clickedOverlay == buttons[i]) {
Overlays.deleteOverlay(notifications[i]);
Overlays.deleteOverlay(buttons[i]);
notifications.splice(i, 1);
buttons.splice(i, 1);
times.splice(i, 1);
heights.splice(i, 1);
myAlpha.splice(i, 1);
arrays.splice(i, 1);
}
}
}
// Control key remains active only while key is held down
function keyReleaseEvent(key) {
if (key.key == 16777249) {
ctrlIsPressed = false;
}
}
// Triggers notification on specific key driven events
function keyPressEvent(key) {
if (key.key == 16777249) {
ctrlIsPressed = true;
}
if (key.text == "q") { //queries number of users online
var numUsers = GlobalServices.onlineUsers.length;
var welcome = "There are " + numUsers + " users online now.";
createNotification(welcome);
}
if (key.text == "s") {
if (ctrlIsPressed == true){
var noteString = "Snapshot taken.";
createNotification(noteString);
if (p > 0) {
left = str.substring(0, p);
right = str.substring(p + 1);
return left + spaceReplacer + stringDivider(right, slotWidth, spaceReplacer);
}
}
return str;
}
// formats string to add newline every 43 chars
@ -234,138 +348,106 @@ function wordWrap(str) {
var result = stringDivider(str, 43.0, "\n");
createNotification(result);
}
// wraps whole word to newline
function stringDivider(str, slotWidth, spaceReplacer) {
if (str.length > slotWidth) {
var p = slotWidth;
for (; p > 0 && str[p] != ' '; p--) {
}
if (p > 0) {
var left = str.substring(0, p);
var right = str.substring(p + 1);
return left + spaceReplacer + stringDivider(right, slotWidth, spaceReplacer);
}
}
return str;
}
// This fires a notification on window resize
function checkSize(){
if((Window.innerWidth != ourWidth)||(Window.innerHeight != ourHeight)) {
function checkSize() {
if ((Window.innerWidth !== ourWidth) || (Window.innerHeight !== ourHeight)) {
var windowResize = "Window has been resized";
ourWidth = Window.innerWidth;
ourHeight = Window.innerHeight;
windowDimensions = Controller.getViewportDimensions();
overlayLocationX = (windowDimensions.x - (width + 60.0));
buttonLocationX = overlayLocationX + (width - 35.0);
createNotification(windowResize)
createNotification(windowResize);
}
}
// Triggers notification if a user logs on or off
function onOnlineUsersChanged(users) {
if (!isStartingUp()) { // Skip user notifications at startup.
for (user in users) {
if (last_users.indexOf(users[user]) == -1.0) {
createNotification(users[user] + " has joined");
}
}
for (user in last_users) {
if (users.indexOf(last_users[user]) == -1.0) {
createNotification(last_users[user] + " has left");
}
function update() {
var nextOverlay,
noticeOut,
buttonOut,
arraysOut,
defaultEyePosition,
avatarOrientation,
notificationPosition,
notificationOrientation,
buttonPosition,
positions,
i,
j,
k;
if (isOnHMD !== Menu.isOptionChecked(ENABLE_VR_MODE)) {
while (arrays.length > 0) {
deleteNotification(0);
}
isOnHMD = !isOnHMD;
persistTime = isOnHMD ? PERSIST_TIME_3D : PERSIST_TIME_2D;
return;
}
last_users = users;
}
// Triggers notification if @MyUserName is mentioned in chat and returns the message to the notification.
function onIncomingMessage(user, message) {
var myMessage = message;
var alertMe = "@" + GlobalServices.myUsername;
var thisAlert = user + ": " + myMessage;
if (myMessage.indexOf(alertMe) > -1.0) {
wordWrap(thisAlert);
}
}
// Triggers mic mute notification
function onMuteStateChanged() {
var muteState = AudioDevice.getMuted() ? "muted" : "unmuted";
var muteString = "Microphone is now " + muteState;
createNotification(muteString);
}
function update(){
frame++;
if ((frame % 60.0) == 0) { // only update once a second
frame += 1;
if ((frame % 60.0) === 0) { // only update once a second
checkSize(); // checks for size change to trigger windowResize notification
locationY = 20.0;
for (var i = 0; i < arrays.length; i++) { //repositions overlays as others fade
var nextOverlay = Overlays.getOverlayAtPoint({x: overlayLocationX, y: locationY});
Overlays.editOverlay(notifications[i], { x:overlayLocationX, y:locationY});
Overlays.editOverlay(buttons[i], { x:buttonLocationX, y:locationY + 12.0});
for (i = 0; i < arrays.length; i += 1) { //repositions overlays as others fade
nextOverlay = Overlays.getOverlayAtPoint({ x: overlayLocationX, y: locationY });
Overlays.editOverlay(notifications[i], { x: overlayLocationX, y: locationY });
Overlays.editOverlay(buttons[i], { x: buttonLocationX, y: locationY + 12.0 });
if (isOnHMD) {
positions = calculate3DOverlayPositions(overlay3DDetails[i].width, overlay3DDetails[i].height, locationY);
overlay3DDetails[i].notificationOrientation = positions.notificationOrientation;
overlay3DDetails[i].notificationPosition = positions.notificationPosition;
overlay3DDetails[i].buttonPosition = positions.buttonPosition;
}
locationY = locationY + arrays[i][3];
}
}
// This checks the age of the notification and prepares to fade it after 9.0 seconds (var persistTime - 1)
for (var i = 0; i < arrays.length; i++) {
// This checks the age of the notification and prepares to fade it after 9.0 seconds (var persistTime - 1)
for (i = 0; i < arrays.length; i += 1) {
if (ready) {
var j = arrays[i][2];
var k = j + persistTime;
if (k < (new Date().getTime() / 1000)) {
j = arrays[i][2];
k = j + persistTime;
if (k < (new Date().getTime() / 1000)) {
ready = false;
noticeOut = arrays[i][0];
buttonOut = arrays[i][1];
var arraysOut = i;
arraysOut = i;
fadeOut(noticeOut, buttonOut, arraysOut);
}
}
}
}
// this fades the notification ready for dismissal, and removes it from the arrays
function fadeOut(noticeOut, buttonOut, arraysOut) {
var myLength = arrays.length;
var r = 9.0;
var pauseTimer = null;
pauseTimer = Script.setInterval(function() {
r--;
rFade = r / 10.0;
Overlays.editOverlay(noticeOut, {alpha: rFade});
Overlays.editOverlay(buttonOut, {alpha: rFade});
if (r < 0) {
dismiss(noticeOut, buttonOut, arraysOut);
arrays.splice(arraysOut, 1);
ready = true;
Script.clearInterval(pauseTimer);
if (isOnHMD && notifications.length > 0) {
// Update 3D overlays to maintain positions relative to avatar
defaultEyePosition = MyAvatar.getDefaultEyePosition();
avatarOrientation = MyAvatar.orientation;
for (i = 0; i < notifications.length; i += 1) {
notificationPosition = Vec3.sum(defaultEyePosition,
Vec3.multiplyQbyV(avatarOrientation, overlay3DDetails[i].notificationPosition));
notificationOrientation = Quat.multiply(avatarOrientation, overlay3DDetails[i].notificationOrientation);
buttonPosition = Vec3.sum(defaultEyePosition,
Vec3.multiplyQbyV(avatarOrientation, overlay3DDetails[i].buttonPosition));
Overlays.editOverlay(notifications[i], { position: notificationPosition, rotation: notificationOrientation });
Overlays.editOverlay(buttons[i], { position: buttonPosition, rotation: notificationOrientation });
}
}, 20);
}
// This handles the final dismissal of a notification after fading
function dismiss(firstNoteOut, firstButOut, firstOut) {
var working = firstOut;
Overlays.deleteOverlay(firstNoteOut);
Overlays.deleteOverlay(firstButOut);
notifications.splice(firstOut, 1);
buttons.splice(firstOut, 1);
times.splice(firstOut, 1);
heights.splice(firstOut, 1);
myAlpha.splice(firstOut,1);
}
// This reports the number of users online at startup
function reportUsers() {
var numUsers = GlobalServices.onlineUsers.length;
var welcome = "Welcome! There are " + numUsers + " users online now.";
createNotification(welcome);
}
}
var STARTUP_TIMEOUT = 500, // ms
startingUp = true,
startupTimer = null;
// This reports the number of users online at startup
function reportUsers() {
var welcome;
welcome = "Welcome! There are " + GlobalServices.onlineUsers.length + " users online now.";
createNotification(welcome);
}
function finishStartup() {
startingUp = false;
Script.clearTimeout(startupTimer);
@ -383,6 +465,113 @@ function isStartingUp() {
return startingUp;
}
// Triggers notification if a user logs on or off
function onOnlineUsersChanged(users) {
var i;
if (!isStartingUp()) { // Skip user notifications at startup.
for (i = 0; i < users.length; i += 1) {
if (last_users.indexOf(users[i]) === -1.0) {
createNotification(users[i] + " has joined");
}
}
for (i = 0; i < last_users.length; i += 1) {
if (users.indexOf(last_users[i]) === -1.0) {
createNotification(last_users[i] + " has left");
}
}
}
last_users = users;
}
// Triggers notification if @MyUserName is mentioned in chat and returns the message to the notification.
function onIncomingMessage(user, message) {
var myMessage,
alertMe,
thisAlert;
myMessage = message;
alertMe = "@" + GlobalServices.myUsername;
thisAlert = user + ": " + myMessage;
if (myMessage.indexOf(alertMe) > -1.0) {
wordWrap(thisAlert);
}
}
// Triggers mic mute notification
function onMuteStateChanged() {
var muteState,
muteString;
muteState = AudioDevice.getMuted() ? "muted" : "unmuted";
muteString = "Microphone is now " + muteState;
createNotification(muteString);
}
// handles mouse clicks on buttons
function mousePressEvent(event) {
var pickRay,
clickedOverlay,
i;
if (isOnHMD) {
pickRay = Camera.computePickRay(event.x, event.y);
clickedOverlay = Overlays.findRayIntersection(pickRay).overlayID;
} else {
clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
}
for (i = 0; i < buttons.length; i += 1) {
if (clickedOverlay === buttons[i]) {
deleteNotification(i);
}
}
}
// Control key remains active only while key is held down
function keyReleaseEvent(key) {
if (key.key === 16777249) {
ctrlIsPressed = false;
}
}
// Triggers notification on specific key driven events
function keyPressEvent(key) {
var numUsers,
welcome,
noteString;
if (key.key === 16777249) {
ctrlIsPressed = true;
}
if (key.text === "q") { //queries number of users online
numUsers = GlobalServices.onlineUsers.length;
welcome = "There are " + numUsers + " users online now.";
createNotification(welcome);
}
if (key.text === "s") {
if (ctrlIsPressed === true) {
noteString = "Snapshot taken.";
createNotification(noteString);
}
}
}
// When our script shuts down, we should clean up all of our overlays
function scriptEnding() {
var i;
for (i = 0; i < notifications.length; i += 1) {
Overlays.deleteOverlay(notifications[i]);
Overlays.deleteOverlay(buttons[i]);
}
}
AudioDevice.muteToggled.connect(onMuteStateChanged);
Controller.keyPressEvent.connect(keyPressEvent);
@ -391,3 +580,4 @@ GlobalServices.onlineUsersChanged.connect(onOnlineUsersChanged);
GlobalServices.incomingMessage.connect(onIncomingMessage);
Controller.keyReleaseEvent.connect(keyReleaseEvent);
Script.update.connect(update);
Script.scriptEnding.connect(scriptEnding);

121
examples/planets.js Normal file
View file

@ -0,0 +1,121 @@
//
// planets.js
//
// Created by Philip Rosedale on January 26, 2015
// Copyright 2015 High Fidelity, Inc.
//
// Some planets are created in front of you. A physical object shot or thrown between them will move
// correctly.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var MAX_RANGE = 75.0;
var MAX_TRANSLATION = MAX_RANGE / 20.0;
var LIFETIME = 600;
var DAMPING = 0.0;
var G = 3.0;
// In this section, setup where you want your 'Planets' that will exert gravity on the
// smaller test particles. Use the first one for the simplest 'planets around sun' simulation.
// Add additional planets to make things a lot more complicated!
var planetTypes = [];
planetTypes.push({ radius: 15, red: 0, green: 0, blue: 255, x: 0.0, y:0, z: 0.0 });
//planetTypes.push({ radius: 10, red: 0, green: 255, blue: 0, x: 0.60, y:0, z: 0.60 });
//planetTypes.push({ radius: 10, red: 0, green: 0, blue: 255, x: 0.75, y:0, z: 0.75 });
//planetTypes.push({ radius: 5, red: 255, green: 0, blue: 0, x: 0.25, y:0, z: 0.25 });
//planetTypes.push({ radius: 5, red: 0, green: 255, blue: 255, x: 0, y:0, z: 0 });
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(MAX_RANGE, Quat.getFront(Camera.getOrientation())));
var NUM_INITIAL_PARTICLES = 200;
var PARTICLE_MIN_SIZE = 0.50;
var PARTICLE_MAX_SIZE = 1.50;
var INITIAL_VELOCITY = 5.0;
var planets = [];
var particles = [];
// Create planets that will extert gravity on test particles
for (var i = 0; i < planetTypes.length; i++) {
var rotationalVelocity = 10 + Math.random() * 60;
var position = { x: planetTypes[i].x, y: planetTypes[i].y, z: planetTypes[i].z };
position = Vec3.multiply(MAX_RANGE / 2, position);
position = Vec3.sum(center, position);
planets.push(Entities.addEntity(
{ type: "Sphere",
position: position,
dimensions: { x: planetTypes[i].radius, y: planetTypes[i].radius, z: planetTypes[i].radius },
color: { red: planetTypes[i].red, green: planetTypes[i].green, blue: planetTypes[i].blue },
gravity: { x: 0, y: 0, z: 0 },
angularVelocity: { x: 0, y: rotationalVelocity, z: 0 },
angularDamping: 0.0,
ignoreCollisions: false,
lifetime: LIFETIME,
collisionsWillMove: false }));
}
Script.setTimeout(createParticles, 1000);
function createParticles() {
// Create initial test particles that will move according to gravity from the planets
for (var i = 0; i < NUM_INITIAL_PARTICLES; i++) {
var radius = PARTICLE_MIN_SIZE + Math.random() * PARTICLE_MAX_SIZE;
var gray = Math.random() * 155;
var whichPlanet = Math.floor(Math.random() * planets.length);
var position = { x: (Math.random() - 0.5) * MAX_RANGE, y: (Math.random() - 0.5) * MAX_TRANSLATION, z: (Math.random() - 0.5) * MAX_RANGE };
var separation = Vec3.length(position);
particles.push(Entities.addEntity(
{ type: "Sphere",
position: Vec3.sum(center, position),
dimensions: { x: radius, y: radius, z: radius },
color: { red: 100 + gray, green: 100 + gray, blue: 100 + gray },
gravity: { x: 0, y: 0, z: 0 },
angularVelocity: { x: 0, y: 0, z: 0 },
velocity: Vec3.multiply(INITIAL_VELOCITY * Math.sqrt(separation), Vec3.normalize(Vec3.cross(position, { x: 0, y: 1, z: 0 }))),
ignoreCollisions: false,
damping: DAMPING,
lifetime: LIFETIME,
collisionsWillMove: true }));
}
Script.update.connect(update);
}
function scriptEnding() {
for (var i = 0; i < planetTypes.length; i++) {
Entities.deleteEntity(planets[i]);
}
for (var i = 0; i < particles.length; i++) {
Entities.deleteEntity(particles[i]);
}
}
function update(deltaTime) {
// Apply gravitational force from planets
for (var t = 0; t < particles.length; t++) {
var properties1 = Entities.getEntityProperties(particles[t]);
var velocity = properties1.velocity;
var vColor = Vec3.length(velocity) / 50 * 255;
var dV = { x:0, y:0, z:0 };
var mass1 = Math.pow(properties1.dimensions.x / 2.0, 3.0);
for (var p = 0; p < planets.length; p++) {
var properties2 = Entities.getEntityProperties(planets[p]);
var mass2 = Math.pow(properties2.dimensions.x / 2.0, 3.0);
var between = Vec3.subtract(properties1.position, properties2.position);
var separation = Vec3.length(between);
dV = Vec3.sum(dV, Vec3.multiply(-G * mass1 * mass2 / separation, Vec3.normalize(between)));
}
if (Math.random() < 0.1) {
Entities.editEntity(particles[t], { color: { red: vColor, green: 100, blue: (255 - vColor) }, velocity: Vec3.sum(velocity, Vec3.multiply(deltaTime, dV))});
} else {
Entities.editEntity(particles[t], { velocity: Vec3.sum(velocity, Vec3.multiply(deltaTime, dV))});
}
}
}
Script.scriptEnding.connect(scriptEnding);

182
examples/popcorn.js Normal file
View file

@ -0,0 +1,182 @@
//
// popcorn.js
// examples
//
// Created by Philip Rosedale on January 25, 2014
// Copyright 2015 High Fidelity, Inc.
//
// Creates a bunch of physical balls trapped in a box with a rotating wall in the middle that smacks them around,
// and a periodic 'pop' force that shoots them into the air.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var BALL_SIZE = 0.07;
var WALL_THICKNESS = 0.10;
var SCALE = 1.0;
var GRAVITY = -1.0;
var LIFETIME = 600;
var DAMPING = 0.50;
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(SCALE * 3.0, Quat.getFront(Camera.getOrientation())));
var floor = Entities.addEntity(
{ type: "Box",
position: Vec3.subtract(center, { x: 0, y: SCALE / 2.0, z: 0 }),
dimensions: { x: SCALE, y: WALL_THICKNESS, z: SCALE },
color: { red: 0, green: 255, blue: 0 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
lifetime: LIFETIME });
var ceiling = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: 0, y: SCALE / 2.0, z: 0 }),
dimensions: { x: SCALE, y: WALL_THICKNESS, z: SCALE },
color: { red: 128, green: 128, blue: 128 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: true,
lifetime: LIFETIME });
var wall1 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: SCALE / 2.0, y: 0, z: 0 }),
dimensions: { x: WALL_THICKNESS, y: SCALE, z: SCALE },
color: { red: 0, green: 255, blue: 0 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: false,
lifetime: LIFETIME });
var wall2 = Entities.addEntity(
{ type: "Box",
position: Vec3.subtract(center, { x: SCALE / 2.0, y: 0, z: 0 }),
dimensions: { x: WALL_THICKNESS, y: SCALE, z: SCALE },
color: { red: 0, green: 255, blue: 0 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: false,
lifetime: LIFETIME });
var wall3 = Entities.addEntity(
{ type: "Box",
position: Vec3.subtract(center, { x: 0, y: 0, z: SCALE / 2.0 }),
dimensions: { x: SCALE, y: SCALE, z: WALL_THICKNESS },
color: { red: 0, green: 255, blue: 0 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: false,
lifetime: LIFETIME });
var wall4 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: 0, y: 0, z: SCALE / 2.0 }),
dimensions: { x: SCALE, y: SCALE, z: WALL_THICKNESS },
color: { red: 0, green: 255, blue: 0 },
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: false,
lifetime: LIFETIME });
var corner1 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: -SCALE / 2.0, y: 0, z: SCALE / 2.0 }),
dimensions: { x: WALL_THICKNESS, y: SCALE, z: WALL_THICKNESS },
color: { red: 128, green: 128, blue: 128 },
ignoreCollisions: false,
visible: true,
lifetime: LIFETIME });
var corner2 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: -SCALE / 2.0, y: 0, z: -SCALE / 2.0 }),
dimensions: { x: WALL_THICKNESS, y: SCALE, z: WALL_THICKNESS },
color: { red: 128, green: 128, blue: 128 },
ignoreCollisions: false,
visible: true,
lifetime: LIFETIME });
var corner3 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: SCALE / 2.0, y: 0, z: SCALE / 2.0 }),
dimensions: { x: WALL_THICKNESS, y: SCALE, z: WALL_THICKNESS },
color: { red: 128, green: 128, blue: 128 },
ignoreCollisions: false,
visible: true,
lifetime: LIFETIME });
var corner4 = Entities.addEntity(
{ type: "Box",
position: Vec3.sum(center, { x: SCALE / 2.0, y: 0, z: -SCALE / 2.0 }),
dimensions: { x: WALL_THICKNESS, y: SCALE, z: WALL_THICKNESS },
color: { red: 128, green: 128, blue: 128 },
ignoreCollisions: false,
visible: true,
lifetime: LIFETIME });
var spinner = Entities.addEntity(
{ type: "Box",
position: center,
dimensions: { x: SCALE / 1.5, y: SCALE / 3.0, z: SCALE / 8.0 },
color: { red: 255, green: 0, blue: 0 },
angularVelocity: { x: 0, y: 360, z: 0 },
angularDamping: 0.0,
gravity: { x: 0, y: 0, z: 0 },
ignoreCollisions: false,
visible: true,
lifetime: LIFETIME });
var NUM_BALLS = 70;
balls = [];
for (var i = 0; i < NUM_BALLS; i++) {
balls.push(Entities.addEntity(
{ type: "Sphere",
position: { x: center.x + (Math.random() - 0.5) * (SCALE - BALL_SIZE - WALL_THICKNESS),
y: center.y + (Math.random() - 0.5) * (SCALE - BALL_SIZE - WALL_THICKNESS) ,
z: center.z + (Math.random() - 0.5) * (SCALE - BALL_SIZE - WALL_THICKNESS) },
dimensions: { x: BALL_SIZE, y: BALL_SIZE, z: BALL_SIZE },
color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 },
gravity: { x: 0, y: GRAVITY, z: 0 },
ignoreCollisions: false,
damping: DAMPING,
lifetime: LIFETIME,
collisionsWillMove: true }));
}
var VEL_MAG = 2.0;
var CHANCE_OF_POP = 0.007; // 0.01;
function update(deltaTime) {
for (var i = 0; i < NUM_BALLS; i++) {
if (Math.random() < CHANCE_OF_POP) {
Entities.editEntity(balls[i], { velocity: { x: (Math.random() - 0.5) * VEL_MAG, y: Math.random() * VEL_MAG, z: (Math.random() - 0.5) * VEL_MAG }});
}
}
}
function scriptEnding() {
Entities.deleteEntity(wall1);
Entities.deleteEntity(wall2);
Entities.deleteEntity(wall3);
Entities.deleteEntity(wall4);
Entities.deleteEntity(corner1);
Entities.deleteEntity(corner2);
Entities.deleteEntity(corner3);
Entities.deleteEntity(corner4);
Entities.deleteEntity(floor);
Entities.deleteEntity(ceiling);
Entities.deleteEntity(spinner);
for (var i = 0; i < NUM_BALLS; i++) {
Entities.deleteEntity(balls[i]);
}
}
Script.scriptEnding.connect(scriptEnding);
Script.update.connect(update);

265
examples/progress.js Normal file
View file

@ -0,0 +1,265 @@
//
// progress.js
// examples
//
// Created by David Rowe on 29 Jan 2015.
// Copyright 2015 High Fidelity, Inc.
//
// This script displays a progress download indicator when downloads are in progress.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function () {
var progress = 100, // %
alpha = 0.0,
alphaDelta = 0.0, // > 0 if fading in; < 0 if fading out/
ALPHA_DELTA_IN = 0.15,
ALPHA_DELTA_OUT = -0.02,
fadeTimer = null,
FADE_INTERVAL = 30, // ms between changes in alpha.
fadeWaitTimer = null,
FADE_OUT_WAIT = 1000, // Wait before starting to fade out after progress 100%.
visible = false,
BAR_WIDTH = 320, // Nominal dimension of SVG in pixels of visible portion (half) of the bar.
BAR_HEIGHT = 20,
BAR_URL = "http://hifi-public.s3.amazonaws.com/images/progress-bar.svg",
BACKGROUND_WIDTH = 360,
BACKGROUND_HEIGHT = 60,
BACKGROUND_URL = "http://hifi-public.s3.amazonaws.com/images/progress-bar-background.svg",
isOnHMD = false,
windowWidth = 0,
windowHeight = 0,
background2D = {},
bar2D = {},
SCALE_2D = 0.55, // Scale the SVGs for 2D display.
background3D = {},
bar3D = {},
ENABLE_VR_MODE_MENU_ITEM = "Enable VR Mode",
PROGRESS_3D_DIRECTION = 0.0, // Degrees from avatar orientation.
PROGRESS_3D_DISTANCE = 0.602, // Horizontal distance from avatar position.
PROGRESS_3D_ELEVATION = -0.8, // Height of top middle of top notification relative to avatar eyes.
PROGRESS_3D_YAW = 0.0, // Degrees relative to notifications direction.
PROGRESS_3D_PITCH = -60.0, // Degrees from vertical.
SCALE_3D = 0.0017, // Scale the bar SVG for 3D display.
BACKGROUND_3D_SIZE = { x: 0.76, y: 0.08 }, // Match up with the 3D background with those of notifications.js notices.
BACKGROUND_3D_COLOR = { red: 2, green: 2, blue: 2 },
BACKGROUND_3D_ALPHA = 0.7;
function fade() {
alpha = alpha + alphaDelta;
if (alpha < 0) {
alpha = 0;
}
if (alpha > 1) {
alpha = 1;
}
if (alpha === 0 || alpha === 1) { // Finished fading in or out
alphaDelta = 0;
Script.clearInterval(fadeTimer);
}
if (alpha === 0) { // Finished fading out
visible = false;
}
if (isOnHMD) {
Overlays.editOverlay(background3D.overlay, {
backgroundAlpha: alpha * BACKGROUND_3D_ALPHA,
visible: visible
});
} else {
Overlays.editOverlay(background2D.overlay, {
alpha: alpha,
visible: visible
});
}
Overlays.editOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay, {
alpha: alpha,
visible: visible
});
}
function onDownloadInfoChanged(info) {
var i;
// Calculate progress
if (info.downloading.length + info.pending === 0) {
progress = 100;
} else {
progress = 0;
for (i = 0; i < info.downloading.length; i += 1) {
progress += info.downloading[i];
}
progress = progress / (info.downloading.length + info.pending);
}
// Update state
if (!visible) { // Not visible because no recent downloads
if (progress < 100) { // Have started downloading so fade in
visible = true;
alphaDelta = ALPHA_DELTA_IN;
fadeTimer = Script.setInterval(fade, FADE_INTERVAL);
}
} else if (alphaDelta !== 0.0) { // Fading in or out
if (alphaDelta > 0) {
if (progress === 100) { // Was donloading but now have finished so fade out
alphaDelta = ALPHA_DELTA_OUT;
}
} else {
if (progress < 100) { // Was finished downloading but have resumed so fade in
alphaDelta = ALPHA_DELTA_IN;
}
}
} else { // Fully visible because downloading or recently so
if (fadeWaitTimer === null) {
if (progress === 100) { // Was downloading but have finished so fade out soon
fadeWaitTimer = Script.setTimeout(function () {
alphaDelta = ALPHA_DELTA_OUT;
fadeTimer = Script.setInterval(fade, FADE_INTERVAL);
fadeWaitTimer = null;
}, FADE_OUT_WAIT);
}
} else {
if (progress < 100) { // Was finished and waiting to fade out but have resumed downloading so don't fade out
Script.clearInterval(fadeWaitTimer);
fadeWaitTimer = null;
}
}
}
// Update progress bar
if (visible) {
Overlays.editOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay, {
subImage: { x: BAR_WIDTH * (1 - progress / 100), y: 0, width: BAR_WIDTH, height: BAR_HEIGHT }
});
}
}
function createOverlays() {
if (isOnHMD) {
background3D.overlay = Overlays.addOverlay("rectangle3d", {
size: BACKGROUND_3D_SIZE,
color: BACKGROUND_3D_COLOR,
alpha: BACKGROUND_3D_ALPHA,
solid: true,
isFacingAvatar: false,
visible: false,
ignoreRayIntersection: true
});
bar3D.overlay = Overlays.addOverlay("billboard", {
url: BAR_URL,
subImage: { x: BAR_WIDTH, y: 0, width: BAR_WIDTH, height: BAR_HEIGHT },
scale: SCALE_3D * BAR_WIDTH,
isFacingAvatar: false,
visible: false,
alpha: 0.0,
ignoreRayIntersection: true
});
} else {
background2D.overlay = Overlays.addOverlay("image", {
imageURL: BACKGROUND_URL,
width: background2D.width,
height: background2D.height,
visible: false,
alpha: 0.0
});
bar2D.overlay = Overlays.addOverlay("image", {
imageURL: BAR_URL,
subImage: { x: BAR_WIDTH, y: 0, width: BAR_WIDTH, height: BAR_HEIGHT },
width: bar2D.width,
height: bar2D.height,
visible: false,
alpha: 0.0
});
}
}
function deleteOverlays() {
Overlays.deleteOverlay(isOnHMD ? background3D.overlay : background2D.overlay);
Overlays.deleteOverlay(isOnHMD ? bar3D.overlay : bar2D.overlay);
}
function update() {
var viewport,
eyePosition,
avatarOrientation;
if (isOnHMD !== Menu.isOptionChecked(ENABLE_VR_MODE_MENU_ITEM)) {
deleteOverlays();
isOnHMD = !isOnHMD;
createOverlays();
}
if (visible) {
if (isOnHMD) {
// Update 3D overlays to maintain positions relative to avatar
eyePosition = MyAvatar.getDefaultEyePosition();
avatarOrientation = MyAvatar.orientation;
Overlays.editOverlay(background3D.overlay, {
position: Vec3.sum(eyePosition, Vec3.multiplyQbyV(avatarOrientation, background3D.offset)),
rotation: Quat.multiply(avatarOrientation, background3D.orientation)
});
Overlays.editOverlay(bar3D.overlay, {
position: Vec3.sum(eyePosition, Vec3.multiplyQbyV(avatarOrientation, bar3D.offset)),
rotation: Quat.multiply(avatarOrientation, bar3D.orientation)
});
} else {
// Update 2D overlays to maintain positions at bottom middle of window
viewport = Controller.getViewportDimensions();
if (viewport.x !== windowWidth || viewport.y !== windowHeight) {
windowWidth = viewport.x;
windowHeight = viewport.y;
Overlays.editOverlay(background2D.overlay, {
x: windowWidth / 2 - background2D.width / 2,
y: windowHeight - background2D.height - bar2D.height
});
Overlays.editOverlay(bar2D.overlay, {
x: windowWidth / 2 - bar2D.width / 2,
y: windowHeight - background2D.height - bar2D.height + (background2D.height - bar2D.height) / 2
});
}
}
}
}
function setUp() {
background2D.width = SCALE_2D * BACKGROUND_WIDTH;
background2D.height = SCALE_2D * BACKGROUND_HEIGHT;
bar2D.width = SCALE_2D * BAR_WIDTH;
bar2D.height = SCALE_2D * BAR_HEIGHT;
background3D.offset = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, PROGRESS_3D_DIRECTION, 0),
{ x: 0, y: 0, z: -PROGRESS_3D_DISTANCE });
background3D.offset.y += PROGRESS_3D_ELEVATION;
background3D.orientation = Quat.fromPitchYawRollDegrees(PROGRESS_3D_PITCH, PROGRESS_3D_DIRECTION + PROGRESS_3D_YAW, 0);
bar3D.offset = Vec3.sum(background3D.offset, { x: 0, y: 0, z: 0.001 }); // Just in front of background
bar3D.orientation = background3D.orientation;
createOverlays();
}
function tearDown() {
deleteOverlays();
}
setUp();
GlobalServices.downloadInfoChanged.connect(onDownloadInfoChanged);
GlobalServices.updateDownloadInfo();
Script.update.connect(update);
Script.scriptEnding.connect(tearDown);
}());

View file

@ -98,8 +98,16 @@ function setupAudioMenus() {
}
}
function onDevicechanged() {
Menu.removeMenu("Tools > Audio");
setupAudioMenus();
}
// Have a small delay before the menu's get setup and the audio devices can switch to the last selected ones
Script.setTimeout(function() { setupAudioMenus(); }, 5000);
Script.setTimeout(function () {
AudioDevice.deviceChanged.connect(onDevicechanged);
setupAudioMenus();
}, 5000);
function scriptEnding() {
Menu.removeMenu("Tools > Audio");

View file

@ -21,20 +21,13 @@ var offset = Vec3.normalize(Quat.getFront(MyAvatar.orientation));
var position = Vec3.sum(MyAvatar.position, offset);
function update(deltaTime) {
if (!Audio.isInjectorPlaying(soundPlaying)) {
soundPlaying = Audio.playSound(sound, {
position: position,
loop: true
});
print("Started sound loop");
}
}
function scriptEnding() {
if (Audio.isInjectorPlaying(soundPlaying)) {
Audio.stopInjector(soundPlaying);
print("Stopped sound loop");
}
if (sound.downloaded && !soundPlaying) {
print("Started sound loop");
soundPlaying = Audio.playSound(sound, {
position: position,
loop: true
});
}
}
Script.update.connect(update);

View file

@ -32,14 +32,13 @@ var sound = Audio.playSound(soundClip, { position: orbitCenter, loop: true, volu
function update(deltaTime) {
time += deltaTime;
currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS };
trailingLoudness = 0.9 * trailingLoudness + 0.1 * Audio.getLoudness(sound);
trailingLoudness = 0.9 * trailingLoudness + 0.1 * sound.loudness;
Entities.editEntity( objectId, { position: currentPosition, color: { red: Math.min(trailingLoudness * 2000, 255), green: 0, blue: 0 } } );
Audio.setInjectorOptions(sound, { position: currentPosition });
sound.setOptions({ position: currentPosition });
}
Script.scriptEnding.connect(function() {
Entities.deleteEntity(objectId);
Audio.stopInjector(sound);
});
Script.update.connect(update);

View file

@ -30,7 +30,7 @@ var playing = false;
var ball = false;
function maybePlaySound(deltaTime) {
if (sound.downloaded) {
if (sound.downloaded && !soundPlaying) {
var properties = {
type: "Sphere",
position: options.position,
@ -45,11 +45,9 @@ function maybePlaySound(deltaTime) {
}
function scriptEnding() {
if (Audio.isInjectorPlaying(soundPlaying)) {
Audio.stopInjector(soundPlaying);
Entities.deleteEntity(ball);
print("Stopped sound.");
}
if (ball) {
Entities.deleteEntity(ball);
}
}
// Connect a call back that happens every frame

View file

@ -10,7 +10,7 @@
//
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
Script.include("libraries/toolBars.js");
Script.include("../../libraries/toolBars.js");
var recordingFile = "recording.rec";

View file

@ -18,6 +18,10 @@ function setupMenus() {
}
if (!Menu.menuExists("Developer > Entities")) {
Menu.addMenu("Developer > Entities");
// NOTE: these menu items aren't currently working. I've temporarily removed them. Will add them back once we
// rewire these to work
/*
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Bounds", isCheckable: true, isChecked: false });
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Triangles", isCheckable: true, isChecked: false });
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Bounds", isCheckable: true, isChecked: false });
@ -26,9 +30,26 @@ function setupMenus() {
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt Render Entities as Scene", isCheckable: true, isChecked: false });
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Do Precision Picking", isCheckable: true, isChecked: false });
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
*/
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't send collision updates to server", isCheckable: true, isChecked: false });
}
}
Menu.menuItemEvent.connect(function (menuItem) {
print("menuItemEvent() in JS... menuItem=" + menuItem);
if (menuItem == "Don't send collision updates to server") {
var dontSendUpdates = Menu.isOptionChecked("Don't send collision updates to server");
print(" dontSendUpdates... checked=" + dontSendUpdates);
Entities.setSendPhysicsUpdates(!dontSendUpdates);
}
});
setupMenus();
// register our scriptEnding callback
Script.scriptEnding.connect(scriptEnding);
function scriptEnding() {
Menu.removeMenu("Developer > Entities");
}

View file

@ -0,0 +1,90 @@
set(TARGET_NAME gvr-interface)
if (ANDROID)
set(ANDROID_APK_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/apk-build")
set(ANDROID_APK_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apk")
set(ANDROID_SDK_ROOT $ENV{ANDROID_HOME})
set(ANDROID_APP_DISPLAY_NAME Interface)
set(ANDROID_API_LEVEL 19)
set(ANDROID_APK_PACKAGE io.highfidelity.gvrinterface)
set(ANDROID_ACTIVITY_NAME io.highfidelity.gvrinterface.InterfaceActivity)
set(ANDROID_APK_VERSION_NAME "0.1")
set(ANDROID_APK_VERSION_CODE 1)
set(ANDROID_APK_FULLSCREEN TRUE)
set(ANDROID_DEPLOY_QT_INSTALL "--install")
set(BUILD_SHARED_LIBS ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ANDROID_APK_OUTPUT_DIR}/libs/${ANDROID_ABI}")
setup_hifi_library(Gui Widgets AndroidExtras)
else ()
setup_hifi_project(Gui Widgets)
endif ()
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
add_dependency_external_project(glm)
find_package(GLM REQUIRED)
target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS})
link_hifi_libraries(shared networking audio-client avatars)
include_dependency_includes()
if (ANDROID)
find_package(LibOVR)
if (LIBOVR_FOUND)
add_definitions(-DHAVE_LIBOVR)
target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES} ${LIBOVR_ANDROID_LIBRARIES} ${TURBOJPEG_LIBRARY})
include_directories(SYSTEM ${LIBOVR_INCLUDE_DIRS})
# we need VRLib, so add a project.properties to our apk build folder that says that
file(RELATIVE_PATH RELATIVE_VRLIB_PATH ${ANDROID_APK_OUTPUT_DIR} "${LIBOVR_VRLIB_DIR}")
file(WRITE "${ANDROID_APK_BUILD_DIR}/project.properties" "android.library.reference.1=${RELATIVE_VRLIB_PATH}")
list(APPEND IGNORE_COPY_LIBS ${LIBOVR_ANDROID_LIBRARIES})
endif ()
endif ()
# the presence of a HOCKEY_APP_ID means we are making a beta build
if (ANDROID AND HOCKEY_APP_ID)
set(HOCKEY_APP_ENABLED true)
set(HOCKEY_APP_ACTIVITY "<activity android:name='net.hockeyapp.android.UpdateActivity' />\n")
set(ANDROID_ACTIVITY_NAME io.highfidelity.gvrinterface.InterfaceBetaActivity)
set(ANDROID_DEPLOY_QT_INSTALL "")
set(ANDROID_APK_CUSTOM_NAME "Interface-beta.apk")
# set the ANDROID_APK_VERSION_CODE to the number of git commits
execute_process(
COMMAND git rev-list --first-parent --count HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(ANDROID_APK_VERSION_CODE ${GIT_COMMIT_COUNT})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/templates/InterfaceBetaActivity.java.in" "${ANDROID_APK_BUILD_DIR}/src/io/highfidelity/gvrinterface/InterfaceBetaActivity.java")
elseif (ANDROID)
set(HOCKEY_APP_ENABLED false)
endif ()
if (ANDROID)
set(HIFI_URL_INTENT "<intent-filter>\
\n <action android:name='android.intent.action.VIEW' />\
\n <category android:name='android.intent.category.DEFAULT' />\
\n <category android:name='android.intent.category.BROWSABLE' />\
\n <data android:scheme='hifi' />\
\n </intent-filter>"
)
set(ANDROID_EXTRA_APPLICATION_XML "${HOCKEY_APP_ACTIVITY}")
set(ANDROID_EXTRA_ACTIVITY_XML "${HIFI_URL_INTENT}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/templates/hockeyapp.xml.in" "${ANDROID_APK_BUILD_DIR}/res/values/hockeyapp.xml")
qt_create_apk()
endif (ANDROID)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View file

@ -0,0 +1,73 @@
//
// Client.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 1/20/15.
// Copyright 2013 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 <AccountManager.h>
#include <AddressManager.h>
#include <HifiSockAddr.h>
#include <NodeList.h>
#include <PacketHeaders.h>
#include "Client.h"
Client::Client(QObject* parent) :
QObject(parent)
{
// we need to make sure that required dependencies are created
DependencyManager::set<AddressManager>();
setupNetworking();
}
void Client::setupNetworking() {
// once Application order of instantiation is fixed this should be done from AccountManager
AccountManager::getInstance().setAuthURL(DEFAULT_NODE_AUTH_URL);
// setup the NodeList for this client
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
auto nodeList = DependencyManager::set<NodeList>(NodeType::Agent, 0);
// while datagram processing remains simple for targets using Client, we'll handle datagrams
connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, this, &Client::processDatagrams);
// every second, ask the NodeList to check in with the domain server
QTimer* domainCheckInTimer = new QTimer(this);
domainCheckInTimer->setInterval(DOMAIN_SERVER_CHECK_IN_MSECS);
connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
// TODO: once the Client knows its Address on start-up we should be able to immediately send a check in here
domainCheckInTimer->start();
// handle the case where the domain stops talking to us
// TODO: can we just have the nodelist do this when it sets up? Is there a user of the NodeList that wouldn't want this?
connect(nodeList.data(), &NodeList::limitOfSilentDomainCheckInsReached, nodeList.data(), &NodeList::reset);
}
void Client::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) {
DependencyManager::get<NodeList>()->processNodeData(senderSockAddr, incomingPacket);
}
void Client::processDatagrams() {
HifiSockAddr senderSockAddr;
static QByteArray incomingPacket;
auto nodeList = DependencyManager::get<NodeList>();
while (DependencyManager::get<NodeList>()->getNodeSocket().hasPendingDatagrams()) {
incomingPacket.resize(nodeList->getNodeSocket().pendingDatagramSize());
nodeList->getNodeSocket().readDatagram(incomingPacket.data(), incomingPacket.size(),
senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer());
if (nodeList->packetVersionAndHashMatch(incomingPacket)) {
processVerifiedPacket(senderSockAddr, incomingPacket);
}
}
}

View file

@ -0,0 +1,33 @@
//
// Client.h
// gvr-interface/src
//
// Created by Stephen Birarda on 1/20/15.
// Copyright 2013 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_Client_h
#define hifi_Client_h
#include <QtCore/QObject>
#include <HifiSockAddr.h>
class Client : public QObject {
Q_OBJECT
public:
Client(QObject* parent = 0);
virtual void cleanupBeforeQuit() = 0;
protected:
void setupNetworking();
virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket);
private slots:
void processDatagrams();
};
#endif // hifi_Client_h

View file

@ -0,0 +1,191 @@
//
// GVRInterface.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 11/18/14.
// Copyright 2013 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
//
#ifdef ANDROID
#include <jni.h>
#include <qpa/qplatformnativeinterface.h>
#include <QtAndroidExtras/QAndroidJniEnvironment>
#include <QtAndroidExtras/QAndroidJniObject>
#ifdef HAVE_LIBOVR
#include <KeyState.h>
#include <VrApi/VrApi.h>
#endif
#endif
#include <QtCore/QTimer>
#include <QtGui/QKeyEvent>
#include <QtWidgets/QMenuBar>
#include "GVRMainWindow.h"
#include "RenderingClient.h"
#include "GVRInterface.h"
static QString launchURLString = QString();
#ifdef ANDROID
extern "C" {
JNIEXPORT void Java_io_highfidelity_gvrinterface_InterfaceActivity_handleHifiURL(JNIEnv *jni, jclass clazz, jstring hifiURLString) {
launchURLString = QAndroidJniObject(hifiURLString).toString();
}
}
#endif
GVRInterface::GVRInterface(int argc, char* argv[]) :
QApplication(argc, argv),
_mainWindow(NULL),
_inVRMode(false)
{
setApplicationName("gvr-interface");
setOrganizationName("highfidelity");
setOrganizationDomain("io");
if (!launchURLString.isEmpty()) {
// did we get launched with a lookup URL? If so it is time to give that to the AddressManager
qDebug() << "We were opened via a hifi URL -" << launchURLString;
}
_client = new RenderingClient(this, launchURLString);
launchURLString = QString();
connect(this, &QGuiApplication::applicationStateChanged, this, &GVRInterface::handleApplicationStateChange);
#if defined(ANDROID) && defined(HAVE_LIBOVR)
QAndroidJniEnvironment jniEnv;
QPlatformNativeInterface* interface = QApplication::platformNativeInterface();
jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity");
ovr_RegisterHmtReceivers(&*jniEnv, activity);
// PLATFORMACTIVITY_REMOVAL: Temp workaround for PlatformActivity being
// stripped from UnityPlugin. Alternate is to use LOCAL_WHOLE_STATIC_LIBRARIES
// but that increases the size of the plugin by ~1MiB
OVR::linkerPlatformActivity++;
#endif
// call our idle function whenever we can
QTimer* idleTimer = new QTimer(this);
connect(idleTimer, &QTimer::timeout, this, &GVRInterface::idle);
idleTimer->start(0);
// call our quit handler before we go down
connect(this, &QCoreApplication::aboutToQuit, this, &GVRInterface::handleApplicationQuit);
}
void GVRInterface::handleApplicationQuit() {
_client->cleanupBeforeQuit();
}
void GVRInterface::idle() {
#if defined(ANDROID) && defined(HAVE_LIBOVR)
if (!_inVRMode && ovr_IsHeadsetDocked()) {
qDebug() << "The headset just got docked - enter VR mode.";
enterVRMode();
} else if (_inVRMode) {
if (ovr_IsHeadsetDocked()) {
static int counter = 0;
// Get the latest head tracking state, predicted ahead to the midpoint of the time
// it will be displayed. It will always be corrected to the real values by
// time warp, but the closer we get, the less black will be pulled in at the edges.
const double now = ovr_GetTimeInSeconds();
static double prev;
const double rawDelta = now - prev;
prev = now;
const double clampedPrediction = std::min( 0.1, rawDelta * 2);
ovrSensorState sensor = ovrHmd_GetSensorState(OvrHmd, now + clampedPrediction, true );
auto ovrOrientation = sensor.Predicted.Pose.Orientation;
glm::quat newOrientation(ovrOrientation.w, ovrOrientation.x, ovrOrientation.y, ovrOrientation.z);
_client->setOrientation(newOrientation);
if (counter++ % 100000 == 0) {
qDebug() << "GetSensorState in frame" << counter << "-"
<< ovrOrientation.x << ovrOrientation.y << ovrOrientation.z << ovrOrientation.w;
}
} else {
qDebug() << "The headset was undocked - leaving VR mode.";
leaveVRMode();
}
}
OVR::KeyState& backKeyState = _mainWindow->getBackKeyState();
auto backEvent = backKeyState.Update(ovr_GetTimeInSeconds());
if (backEvent == OVR::KeyState::KEY_EVENT_LONG_PRESS) {
qDebug() << "Attemping to start the Platform UI Activity.";
ovr_StartPackageActivity(_ovr, PUI_CLASS_NAME, PUI_GLOBAL_MENU);
} else if (backEvent == OVR::KeyState::KEY_EVENT_DOUBLE_TAP || backEvent == OVR::KeyState::KEY_EVENT_SHORT_PRESS) {
qDebug() << "Got an event we should cancel for!";
} else if (backEvent == OVR::KeyState::KEY_EVENT_DOUBLE_TAP) {
qDebug() << "The button is down!";
}
#endif
}
void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) {
switch(state) {
case Qt::ApplicationActive:
qDebug() << "The application is active.";
break;
case Qt::ApplicationSuspended:
qDebug() << "The application is being suspended.";
break;
default:
break;
}
}
void GVRInterface::enterVRMode() {
#if defined(ANDROID) && defined(HAVE_LIBOVR)
// Default vrModeParms
ovrModeParms vrModeParms;
vrModeParms.AsynchronousTimeWarp = true;
vrModeParms.AllowPowerSave = true;
vrModeParms.DistortionFileName = NULL;
vrModeParms.EnableImageServer = false;
vrModeParms.CpuLevel = 2;
vrModeParms.GpuLevel = 2;
vrModeParms.GameThreadTid = 0;
QAndroidJniEnvironment jniEnv;
QPlatformNativeInterface* interface = QApplication::platformNativeInterface();
jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity");
vrModeParms.ActivityObject = activity;
ovrHmdInfo hmdInfo;
_ovr = ovr_EnterVrMode(vrModeParms, &hmdInfo);
_inVRMode = true;
#endif
}
void GVRInterface::leaveVRMode() {
#if defined(ANDROID) && defined(HAVE_LIBOVR)
ovr_LeaveVrMode(_ovr);
_inVRMode = false;
#endif
}

View file

@ -0,0 +1,72 @@
//
// GVRInterface.h
// gvr-interface/src
//
// Created by Stephen Birarda on 11/18/14.
// Copyright 2013 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_GVRInterface_h
#define hifi_GVRInterface_h
#include <QtWidgets/QApplication>
#if defined(ANDROID) && defined(HAVE_LIBOVR)
class ovrMobile;
class ovrHmdInfo;
// This is set by JNI_OnLoad() when the .so is initially loaded.
// Must use to attach each thread that will use JNI:
namespace OVR {
// PLATFORMACTIVITY_REMOVAL: Temp workaround for PlatformActivity being
// stripped from UnityPlugin. Alternate is to use LOCAL_WHOLE_STATIC_LIBRARIES
// but that increases the size of the plugin by ~1MiB
extern int linkerPlatformActivity;
}
#endif
class GVRMainWindow;
class RenderingClient;
class QKeyEvent;
#if defined(qApp)
#undef qApp
#endif
#define qApp (static_cast<GVRInterface*>(QApplication::instance()))
class GVRInterface : public QApplication {
Q_OBJECT
public:
GVRInterface(int argc, char* argv[]);
RenderingClient* getClient() { return _client; }
void setMainWindow(GVRMainWindow* mainWindow) { _mainWindow = mainWindow; }
protected:
void keyPressEvent(QKeyEvent* event);
private slots:
void handleApplicationStateChange(Qt::ApplicationState state);
void idle();
private:
void handleApplicationQuit();
void enterVRMode();
void leaveVRMode();
#if defined(ANDROID) && defined(HAVE_LIBOVR)
ovrMobile* _ovr;
ovrHmdInfo* _hmdInfo;
#endif
GVRMainWindow* _mainWindow;
RenderingClient* _client;
bool _inVRMode;
};
#endif // hifi_GVRInterface_h

View file

@ -0,0 +1,176 @@
//
// GVRMainWindow.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 1/20/14.
// Copyright 2013 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 <QtGui/QKeyEvent>
#include <QtWidgets/QApplication>
#include <QtWidgets/QInputDialog>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QVBoxLayout>
#ifndef ANDROID
#include <QtWidgets/QDesktopWidget>
#elif defined(HAVE_LIBOVR)
#include <OVR_CAPI.h>
const float LIBOVR_DOUBLE_TAP_DURATION = 0.25f;
const float LIBOVR_LONG_PRESS_DURATION = 0.75f;
#endif
#include <AddressManager.h>
#include "InterfaceView.h"
#include "LoginDialog.h"
#include "RenderingClient.h"
#include "GVRMainWindow.h"
GVRMainWindow::GVRMainWindow(QWidget* parent) :
QMainWindow(parent),
#if defined(ANDROID) && defined(HAVE_LIBOVR)
_backKeyState(LIBOVR_DOUBLE_TAP_DURATION, LIBOVR_LONG_PRESS_DURATION),
_wasBackKeyDown(false),
#endif
_mainLayout(NULL),
_menuBar(NULL),
_loginAction(NULL)
{
#ifndef ANDROID
const int NOTE_4_WIDTH = 2560;
const int NOTE_4_HEIGHT = 1440;
setFixedSize(NOTE_4_WIDTH / 2, NOTE_4_HEIGHT / 2);
#endif
setupMenuBar();
QWidget* baseWidget = new QWidget(this);
// setup a layout so we can vertically align to top
_mainLayout = new QVBoxLayout(baseWidget);
_mainLayout->setAlignment(Qt::AlignTop);
// set the layout on the base widget
baseWidget->setLayout(_mainLayout);
setCentralWidget(baseWidget);
// add the interface view
new InterfaceView(baseWidget);
}
GVRMainWindow::~GVRMainWindow() {
delete _menuBar;
}
void GVRMainWindow::keyPressEvent(QKeyEvent* event) {
#ifdef ANDROID
if (event->key() == Qt::Key_Back) {
// got the Android back key, hand off to OVR KeyState
_backKeyState.HandleEvent(ovr_GetTimeInSeconds(), true, (_wasBackKeyDown ? 1 : 0));
_wasBackKeyDown = true;
return;
}
#endif
QWidget::keyPressEvent(event);
}
void GVRMainWindow::keyReleaseEvent(QKeyEvent* event) {
#ifdef ANDROID
if (event->key() == Qt::Key_Back) {
// release on the Android back key, hand off to OVR KeyState
_backKeyState.HandleEvent(ovr_GetTimeInSeconds(), false, 0);
_wasBackKeyDown = false;
}
#endif
QWidget::keyReleaseEvent(event);
}
void GVRMainWindow::setupMenuBar() {
QMenu* fileMenu = new QMenu("File");
QMenu* helpMenu = new QMenu("Help");
_menuBar = new QMenuBar(0);
_menuBar->addMenu(fileMenu);
_menuBar->addMenu(helpMenu);
QAction* goToAddress = new QAction("Go to Address", fileMenu);
connect(goToAddress, &QAction::triggered, this, &GVRMainWindow::showAddressBar);
fileMenu->addAction(goToAddress);
_loginAction = new QAction("Login", fileMenu);
fileMenu->addAction(_loginAction);
// change the login action depending on our logged in/out state
AccountManager& accountManager = AccountManager::getInstance();
connect(&accountManager, &AccountManager::loginComplete, this, &GVRMainWindow::refreshLoginAction);
connect(&accountManager, &AccountManager::logoutComplete, this, &GVRMainWindow::refreshLoginAction);
// refresh the state now
refreshLoginAction();
QAction* aboutQt = new QAction("About Qt", helpMenu);
connect(aboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
helpMenu->addAction(aboutQt);
setMenuBar(_menuBar);
}
void GVRMainWindow::showAddressBar() {
// setup the address QInputDialog
QInputDialog* addressDialog = new QInputDialog(this);
addressDialog->setLabelText("Address");
// add the address dialog to the main layout
_mainLayout->addWidget(addressDialog);
connect(addressDialog, &QInputDialog::textValueSelected,
DependencyManager::get<AddressManager>().data(), &AddressManager::handleLookupString);
}
void GVRMainWindow::showLoginDialog() {
LoginDialog* loginDialog = new LoginDialog(this);
// have the acccount manager handle credentials from LoginDialog
AccountManager& accountManager = AccountManager::getInstance();
connect(loginDialog, &LoginDialog::credentialsEntered, &accountManager, &AccountManager::requestAccessToken);
connect(&accountManager, &AccountManager::loginFailed, this, &GVRMainWindow::showLoginFailure);
_mainLayout->addWidget(loginDialog);
}
void GVRMainWindow::showLoginFailure() {
QMessageBox::warning(this, "Login Failed",
"Could not log in with that username and password. Please try again!");
}
void GVRMainWindow::refreshLoginAction() {
AccountManager& accountManager = AccountManager::getInstance();
disconnect(_loginAction, &QAction::triggered, &accountManager, 0);
if (accountManager.isLoggedIn()) {
_loginAction->setText("Logout");
connect(_loginAction, &QAction::triggered, &accountManager, &AccountManager::logout);
} else {
_loginAction->setText("Login");
connect(_loginAction, &QAction::triggered, this, &GVRMainWindow::showLoginDialog);
}
}

View file

@ -0,0 +1,58 @@
//
// GVRMainWindow.h
// gvr-interface/src
//
// Created by Stephen Birarda on 1/20/14.
// Copyright 2013 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_GVRMainWindow_h
#define hifi_GVRMainWindow_h
#include <QtWidgets/QMainWindow>
#if defined(ANDROID) && defined(HAVE_LIBOVR)
#include <KeyState.h>
#endif
class QKeyEvent;
class QMenuBar;
class QVBoxLayout;
class GVRMainWindow : public QMainWindow {
Q_OBJECT
public:
GVRMainWindow(QWidget* parent = 0);
~GVRMainWindow();
public slots:
void showAddressBar();
void showLoginDialog();
void showLoginFailure();
#if defined(ANDROID) && defined(HAVE_LIBOVR)
OVR::KeyState& getBackKeyState() { return _backKeyState; }
#endif
protected:
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
private slots:
void refreshLoginAction();
private:
void setupMenuBar();
#if defined(ANDROID) && defined(HAVE_LIBOVR)
OVR::KeyState _backKeyState;
bool _wasBackKeyDown;
#endif
QVBoxLayout* _mainLayout;
QMenuBar* _menuBar;
QAction* _loginAction;
};
#endif // hifi_GVRMainWindow_h

View file

@ -0,0 +1,18 @@
//
// InterfaceView.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 1/28/14.
// Copyright 2013 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 "InterfaceView.h"
InterfaceView::InterfaceView(QWidget* parent, Qt::WindowFlags flags) :
QOpenGLWidget(parent, flags)
{
}

View file

@ -0,0 +1,23 @@
//
// InterfaceView.h
// gvr-interface/src
//
// Created by Stephen Birarda on 1/28/14.
// Copyright 2013 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_InterfaceView_h
#define hifi_InterfaceView_h
#include <QtWidgets/QOpenGLWidget>
class InterfaceView : public QOpenGLWidget {
Q_OBJECT
public:
InterfaceView(QWidget* parent = 0, Qt::WindowFlags flags = 0);
};
#endif // hifi_InterfaceView_h

View file

@ -0,0 +1,69 @@
//
// LoginDialog.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 2015-02-03.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include "LoginDialog.h"
LoginDialog::LoginDialog(QWidget* parent) :
QDialog(parent)
{
setupGUI();
setWindowTitle("Login");
setModal(true);
}
void LoginDialog::setupGUI() {
// setup a grid layout
QGridLayout* formGridLayout = new QGridLayout(this);
_usernameLineEdit = new QLineEdit(this);
QLabel* usernameLabel = new QLabel(this);
usernameLabel->setText("Username");
usernameLabel->setBuddy(_usernameLineEdit);
formGridLayout->addWidget(usernameLabel, 0, 0);
formGridLayout->addWidget(_usernameLineEdit, 1, 0);
_passwordLineEdit = new QLineEdit(this);
_passwordLineEdit->setEchoMode(QLineEdit::Password);
QLabel* passwordLabel = new QLabel(this);
passwordLabel->setText("Password");
passwordLabel->setBuddy(_passwordLineEdit);
formGridLayout->addWidget(passwordLabel, 2, 0);
formGridLayout->addWidget(_passwordLineEdit, 3, 0);
QDialogButtonBox* buttons = new QDialogButtonBox(this);
QPushButton* okButton = buttons->addButton(QDialogButtonBox::Ok);
QPushButton* cancelButton = buttons->addButton(QDialogButtonBox::Cancel);
okButton->setText("Login");
connect(cancelButton, &QPushButton::clicked, this, &QDialog::close);
connect(okButton, &QPushButton::clicked, this, &LoginDialog::loginButtonClicked);
formGridLayout->addWidget(buttons, 4, 0, 1, 2);
setLayout(formGridLayout);
}
void LoginDialog::loginButtonClicked() {
emit credentialsEntered(_usernameLineEdit->text(), _passwordLineEdit->text());
close();
}

View file

@ -0,0 +1,34 @@
//
// LoginDialog.h
// gvr-interface/src
//
// Created by Stephen Birarda on 2015-02-03.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_LoginDialog_h
#define hifi_LoginDialog_h
#include <QtWidgets/QDialog>
class QLineEdit;
class LoginDialog : public QDialog {
Q_OBJECT
public:
LoginDialog(QWidget* parent = 0);
signals:
void credentialsEntered(const QString& username, const QString& password);
private slots:
void loginButtonClicked();
private:
void setupGUI();
QLineEdit* _usernameLineEdit;
QLineEdit* _passwordLineEdit;
};
#endif // hifi_LoginDialog_h

View file

@ -0,0 +1,167 @@
//
// RenderingClient.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 1/20/15.
// Copyright 2013 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 <QtCore/QThread>
#include <QtWidgets/QInputDialog>
#include <AddressManager.h>
#include <AudioClient.h>
#include <AvatarHashMap.h>
#include <NodeList.h>
#include "RenderingClient.h"
RenderingClient* RenderingClient::_instance = NULL;
RenderingClient::RenderingClient(QObject *parent, const QString& launchURLString) :
Client(parent)
{
_instance = this;
// connect to AddressManager and pass it the launch URL, if we have one
auto addressManager = DependencyManager::get<AddressManager>();
connect(addressManager.data(), &AddressManager::locationChangeRequired, this, &RenderingClient::goToLocation);
addressManager->loadSettings(launchURLString);
// tell the NodeList which node types all rendering clients will want to know about
DependencyManager::get<NodeList>()->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer);
DependencyManager::set<AvatarHashMap>();
// get our audio client setup on its own thread
QThread* audioThread = new QThread();
auto audioClient = DependencyManager::set<AudioClient>();
audioClient->setPositionGetter(getPositionForAudio);
audioClient->setOrientationGetter(getOrientationForAudio);
audioClient->moveToThread(audioThread);
connect(audioThread, &QThread::started, audioClient.data(), &AudioClient::start);
connect(audioClient.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
audioThread->start();
connect(&_avatarTimer, &QTimer::timeout, this, &RenderingClient::sendAvatarPacket);
_avatarTimer.setInterval(16); // 60 FPS
_avatarTimer.start();
_fakeAvatar.setDisplayName("GearVR");
_fakeAvatar.setFaceModelURL(QUrl(DEFAULT_HEAD_MODEL_URL));
_fakeAvatar.setSkeletonModelURL(QUrl(DEFAULT_BODY_MODEL_URL));
_fakeAvatar.toByteArray(); // Creates HeadData
}
void RenderingClient::sendAvatarPacket() {
_fakeAvatar.setPosition(_position);
_fakeAvatar.setHeadOrientation(_orientation);
QByteArray packet = byteArrayWithPopulatedHeader(PacketTypeAvatarData);
packet.append(_fakeAvatar.toByteArray());
DependencyManager::get<NodeList>()->broadcastToNodes(packet, NodeSet() << NodeType::AvatarMixer);
_fakeAvatar.sendIdentityPacket();
}
void RenderingClient::cleanupBeforeQuit() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection);
// destroy the AudioClient so it and its thread will safely go down
DependencyManager::destroy<AudioClient>();
}
void RenderingClient::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) {
auto nodeList = DependencyManager::get<NodeList>();
PacketType incomingType = packetTypeForPacket(incomingPacket);
switch (incomingType) {
case PacketTypeAudioEnvironment:
case PacketTypeAudioStreamStats:
case PacketTypeMixedAudio:
case PacketTypeSilentAudioFrame: {
if (incomingType == PacketTypeAudioStreamStats) {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "parseAudioStreamStatsPacket",
Qt::QueuedConnection,
Q_ARG(QByteArray, incomingPacket));
} else if (incomingType == PacketTypeAudioEnvironment) {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "parseAudioEnvironmentData",
Qt::QueuedConnection,
Q_ARG(QByteArray, incomingPacket));
} else {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "addReceivedAudioToStream",
Qt::QueuedConnection,
Q_ARG(QByteArray, incomingPacket));
}
// update having heard from the audio-mixer and record the bytes received
SharedNodePointer audioMixer = nodeList->sendingNodeForPacket(incomingPacket);
if (audioMixer) {
audioMixer->setLastHeardMicrostamp(usecTimestampNow());
}
break;
}
case PacketTypeBulkAvatarData:
case PacketTypeKillAvatar:
case PacketTypeAvatarIdentity:
case PacketTypeAvatarBillboard: {
// update having heard from the avatar-mixer and record the bytes received
SharedNodePointer avatarMixer = nodeList->sendingNodeForPacket(incomingPacket);
if (avatarMixer) {
avatarMixer->setLastHeardMicrostamp(usecTimestampNow());
QMetaObject::invokeMethod(DependencyManager::get<AvatarHashMap>().data(),
"processAvatarMixerDatagram",
Q_ARG(const QByteArray&, incomingPacket),
Q_ARG(const QWeakPointer<Node>&, avatarMixer));
}
break;
}
default:
Client::processVerifiedPacket(senderSockAddr, incomingPacket);
break;
}
}
void RenderingClient::goToLocation(const glm::vec3& newPosition,
bool hasOrientationChange, const glm::quat& newOrientation,
bool shouldFaceLocation) {
qDebug().nospace() << "RenderingClient goToLocation - moving to " << newPosition.x << ", "
<< newPosition.y << ", " << newPosition.z;
glm::vec3 shiftedPosition = newPosition;
if (hasOrientationChange) {
qDebug().nospace() << "RenderingClient goToLocation - new orientation is "
<< newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w;
// orient the user to face the target
glm::quat quatOrientation = newOrientation;
if (shouldFaceLocation) {
quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
// move the user a couple units away
const float DISTANCE_TO_USER = 2.0f;
shiftedPosition = newPosition - quatOrientation * glm::vec3( 0.0f, 0.0f,-1.0f) * DISTANCE_TO_USER;
}
_orientation = quatOrientation;
}
_position = shiftedPosition;
}

View file

@ -0,0 +1,57 @@
//
// RenderingClient.h
// gvr-interface/src
//
// Created by Stephen Birarda on 1/20/15.
// Copyright 2013 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_RenderingClient_h
#define hifi_RenderingClient_h
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <QTimer>
#include <AvatarData.h>
#include "Client.h"
class RenderingClient : public Client {
Q_OBJECT
public:
RenderingClient(QObject* parent = 0, const QString& launchURLString = QString());
const glm::vec3& getPosition() const { return _position; }
const glm::quat& getOrientation() const { return _orientation; }
void setOrientation(const glm::quat& orientation) { _orientation = orientation; }
static glm::vec3 getPositionForAudio() { return _instance->getPosition(); }
static glm::quat getOrientationForAudio() { return _instance->getOrientation(); }
virtual void cleanupBeforeQuit();
private slots:
void goToLocation(const glm::vec3& newPosition,
bool hasOrientationChange, const glm::quat& newOrientation,
bool shouldFaceLocation);
void sendAvatarPacket();
private:
virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket);
static RenderingClient* _instance;
glm::vec3 _position;
glm::quat _orientation;
QTimer _avatarTimer;
AvatarData _fakeAvatar;
};
#endif // hifi_RenderingClient_h

View file

@ -0,0 +1,41 @@
//
// InterfaceActivity.java
// gvr-interface/java
//
// Created by Stephen Birarda on 1/26/15.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
package io.highfidelity.gvrinterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
import android.util.Log;
import org.qtproject.qt5.android.bindings.QtActivity;
public class InterfaceActivity extends QtActivity {
public static native void handleHifiURL(String hifiURLString);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Get the intent that started this activity in case we have a hifi:// URL to parse
Intent intent = getIntent();
if (intent.getAction() == Intent.ACTION_VIEW) {
Uri data = intent.getData();
if (data.getScheme().equals("hifi")) {
handleHifiURL(data.toString());
}
}
}
}

View file

@ -0,0 +1,28 @@
//
// main.cpp
// gvr-interface/src
//
// Created by Stephen Birarda on 11/17/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 "GVRMainWindow.h"
#include "GVRInterface.h"
int main(int argc, char* argv[]) {
GVRInterface app(argc, argv);
GVRMainWindow mainWindow;
#ifdef ANDROID
mainWindow.showFullScreen();
#else
mainWindow.showMaximized();
#endif
app.setMainWindow(&mainWindow);
return app.exec();
}

View file

@ -0,0 +1,51 @@
//
// InterfaceBetaActivity.java
// gvr-interface/java
//
// Created by Stephen Birarda on 1/27/15.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
package io.highfidelity.gvrinterface;
import android.os.Bundle;
import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.UpdateManager;
public class InterfaceBetaActivity extends InterfaceActivity {
public String _hockeyAppID;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_hockeyAppID = getString(R.string.HockeyAppID);
checkForUpdates();
}
@Override
protected void onPause() {
super.onPause();
UpdateManager.unregister();
}
@Override
protected void onResume() {
super.onResume();
checkForCrashes();
}
private void checkForCrashes() {
CrashManager.register(this, _hockeyAppID);
}
private void checkForUpdates() {
// Remove this for store / production builds!
UpdateManager.register(this, _hockeyAppID);
}
}

View file

@ -0,0 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="HockeyAppID">${HOCKEY_APP_ID}</string>
<bool name="HockeyAppEnabled">${HOCKEY_APP_ENABLED}</bool>
</resources>

View file

@ -4,6 +4,6 @@ set(TARGET_NAME ice-server)
setup_hifi_project(Network)
# link the shared hifi libraries
link_hifi_libraries(networking shared)
link_hifi_libraries(embedded-webserver networking shared)
include_dependency_includes()

Some files were not shown because too many files have changed in this diff Show more