diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..bc265f8 --- /dev/null +++ b/License.txt @@ -0,0 +1,5 @@ +2014.09.14 13:35 +https://github.com/jdarpinian/npvr + +License +BSD, except the np_* code. \ No newline at end of file diff --git a/bin/npvr.dll b/bin/npvr.dll deleted file mode 100644 index a71d1fc..0000000 Binary files a/bin/npvr.dll and /dev/null differ diff --git a/bin/install.bat b/bin/win32/install.bat similarity index 94% rename from bin/install.bat rename to bin/win32/install.bat index dcc596d..56a9c00 100644 --- a/bin/install.bat +++ b/bin/win32/install.bat @@ -1 +1 @@ -regsvr32 npvr.dll +regsvr32 npvr.dll diff --git a/bin/manifest.json b/bin/win32/manifest.json similarity index 94% rename from bin/manifest.json rename to bin/win32/manifest.json index 00e2fa8..1b3cca6 100644 --- a/bin/manifest.json +++ b/bin/win32/manifest.json @@ -1,14 +1,14 @@ -{ - "name": "npvr", - "version": "1.0.0.0", - "manifest_version": 2, - "description": "NPAPI plugin to expose fun VR devices.", - "offline_enabled": true, - - "plugins": [ - { - "path": "npvr.dll", - "public": true - } - ] -} +{ + "name": "npvr", + "version": "1.0.0.0", + "manifest_version": 2, + "description": "NPAPI plugin to expose fun VR devices.", + "offline_enabled": true, + + "plugins": [ + { + "path": "npvr.dll", + "public": true + } + ] +} diff --git a/bin/win32/npvr.dll b/bin/win32/npvr.dll new file mode 100644 index 0000000..326f005 Binary files /dev/null and b/bin/win32/npvr.dll differ diff --git a/bin/sixense.dll b/bin/win32/sixense.dll similarity index 100% rename from bin/sixense.dll rename to bin/win32/sixense.dll diff --git a/bin/uninstall.bat b/bin/win32/uninstall.bat similarity index 95% rename from bin/uninstall.bat rename to bin/win32/uninstall.bat index 8d39137..19647a4 100644 --- a/bin/uninstall.bat +++ b/bin/win32/uninstall.bat @@ -1 +1 @@ -regsvr32 /u npvr.dll +regsvr32 /u npvr.dll diff --git a/bin/x64/manifest.json b/bin/x64/manifest.json new file mode 100644 index 0000000..77e9fbc --- /dev/null +++ b/bin/x64/manifest.json @@ -0,0 +1,14 @@ +{ + "name": "npvr", + "version": "1.0.0.0", + "manifest_version": 2, + "description": "NPAPI plugin to expose fun VR devices.", + "offline_enabled": true, + + "plugins": [ + { + "path": "npvr_64.dll", + "public": true + } + ] +} diff --git a/bin/x64/npvr_64.dll b/bin/x64/npvr_64.dll new file mode 100644 index 0000000..fd196ba Binary files /dev/null and b/bin/x64/npvr_64.dll differ diff --git a/bin/x64/sixense_utils_x64.dll b/bin/x64/sixense_utils_x64.dll new file mode 100644 index 0000000..9cbeb92 Binary files /dev/null and b/bin/x64/sixense_utils_x64.dll differ diff --git a/bin/x64/sixense_x64.dll b/bin/x64/sixense_x64.dll new file mode 100644 index 0000000..6320f29 Binary files /dev/null and b/bin/x64/sixense_x64.dll differ diff --git a/examples/OculusRawData.html b/examples/OculusRawData.html new file mode 100644 index 0000000..58f0638 --- /dev/null +++ b/examples/OculusRawData.html @@ -0,0 +1,57 @@ + + + + NPVR Raw Data + + + + + + + + diff --git a/examples/rift_demo.html b/examples/rift_demo.html index c2b7498..b2403b1 100644 --- a/examples/rift_demo.html +++ b/examples/rift_demo.html @@ -1,4 +1,4 @@ - + @@ -151,8 +151,8 @@ controls = new THREE.OculusRiftControls( camera ); scene.add( controls.getObject() ); - // var cameraHelper = new THREE.CameraHelper(camera); - // scene.add(cameraHelper); + //var cameraHelper = new THREE.CameraHelper(camera); + //scene.add(cameraHelper); ray = new THREE.Raycaster(); ray.ray.direction.set( 0, -1, 0 ); @@ -276,12 +276,20 @@ } // Poll VR, if it's ready. - if (vr.isReady) { - vr.poll(vrstate); - } + if (vr.isReady) { + vr.poll(vrstate); + + camera.position.x = vrstate.oculus.position[0] * 100; + camera.position.y = vrstate.oculus.position[1] * 100 +50; + camera.position.z = vrstate.oculus.position[2] * 100; + + camera.rotation.w = vrstate.oculus.rotation[3] * Math.PI; + camera.rotation.y = vrstate.oculus.rotation[1] * Math.PI; + camera.rotation.z = vrstate.oculus.rotation[2] * Math.PI; + camera.rotation.x = vrstate.oculus.rotation[0] * Math.PI; + } controls.update( Date.now() - time, vr.isReady ? vrstate : null ); - //renderer.render( scene, camera ); effect.render( scene, camera ); time = Date.now(); diff --git a/lib/vr.js b/lib/vr.js index 563e6bb..50ce7e5 100644 --- a/lib/vr.js +++ b/lib/vr.js @@ -122,9 +122,12 @@ function execCommand(commandId, opt_commandData) { vr.hello = function() { - return execCommand(1); + return execCommand(1); }; +vr.configuration = function () { + return _vr_native_.oculState(); +} /** * Bitmask values for the sixense controller buttons field. @@ -195,7 +198,8 @@ var VRState = function() { }; this.oculus = { present: false, - rotation: new Float32Array(4) + rotation: new Float32Array(4), + position: new Float32Array(3) } }; @@ -239,7 +243,7 @@ vr.poll = function(state) { case 'r': // Oculus data. parseOculusChunk(state, deviceChunk); - break; + break; } } @@ -283,12 +287,16 @@ vr.poll = function(state) { }; function parseOculusChunk(state, data) { - if (data.length == 5) { + if (data.length == 8) { state.oculus.present = true; state.oculus.rotation[0] = parseFloat(data[1]); state.oculus.rotation[1] = parseFloat(data[2]); state.oculus.rotation[2] = parseFloat(data[3]); state.oculus.rotation[3] = parseFloat(data[4]); + + state.oculus.position[0] = parseFloat(data[5]); + state.oculus.position[1] = parseFloat(data[6]); + state.oculus.position[2] = parseFloat(data[7]); } else { state.oculus.present = false; } diff --git a/src/npvr/ovr_manager.cpp b/src/npvr/ovr_manager.cpp index d2f5b0a..d05fa31 100644 --- a/src/npvr/ovr_manager.cpp +++ b/src/npvr/ovr_manager.cpp @@ -11,43 +11,46 @@ OVRManager *OVRManager::Instance() { } OVRManager::OVRManager() { - OVR::System::Init(); - sensor_fusion_ = new OVR::SensorFusion(); - device_manager_ = OVR::DeviceManager::Create(); - hmd_device_ = device_manager_->EnumerateDevices().CreateDevice(); - if (hmd_device_) { - sensor_fusion_->AttachToSensor(hmd_device_->GetSensor()); - } - device_manager_->SetMessageHandler(this); -} + ovr_Initialize(); + ovrHmd hmd_devive = ovrHmd_Create(0); + hmd_device_ = hmd_devive; -void OVRManager::OnMessage(const OVR::Message &message) { - switch(message.Type) { - case OVR::MessageType::Message_DeviceRemoved: - // TODO: Verify that the removed device is the one we're using. - if (hmd_device_) { - hmd_device_->Release(); - hmd_device_ = NULL; - } - break; - case OVR::MessageType::Message_DeviceAdded: - if (!hmd_device_) { - // TODO: This doesn't work for some reason. - hmd_device_ = device_manager_->EnumerateDevices().CreateDevice(); - if (hmd_device_) { - sensor_fusion_->AttachToSensor(hmd_device_->GetSensor()); - } - } - break; - default: - break; - } + ovrHmd_ConfigureTracking(hmd_devive, ovrTrackingCap_Orientation | + ovrTrackingCap_MagYawCorrection | + ovrTrackingCap_Position, 0); } bool OVRManager::DevicePresent() const { return hmd_device_; } -OVR::Quatf &OVRManager::GetOrientation() const { - return sensor_fusion_->GetOrientation(); +OVR::Quatf* &OVRManager::GetOrientation() const { + + static ovrPosef eyeRenderPose[2]; + + ovrEyeType eye = hmd_device_->EyeRenderOrder[0]; + eyeRenderPose[0] = ovrHmd_GetEyePose(hmd_device_, eye); + + OVR::Quatf* orientation = new OVR::Quatf(eyeRenderPose[0].Orientation.x, eyeRenderPose[0].Orientation.y, eyeRenderPose[0].Orientation.z, eyeRenderPose[0].Orientation.w); + + return orientation; +} + +OVR::Vector3f* &OVRManager::GetPosition() const { + + static ovrPosef eyeRenderPose[2]; + + ovrEyeType eye = hmd_device_->EyeRenderOrder[0]; + eyeRenderPose[0] = ovrHmd_GetEyePose(hmd_device_, eye); + + OVR::Vector3f* position = new OVR::Vector3f(eyeRenderPose[0].Position.x, eyeRenderPose[0].Position.y, eyeRenderPose[0].Position.z); + + return position; +} + +ovrHmd &OVRManager::GetConfiguration() const { + + ovrHmd test = hmd_device_; + return test; } + diff --git a/src/npvr/ovr_manager.h b/src/npvr/ovr_manager.h index 6694375..475013e 100644 --- a/src/npvr/ovr_manager.h +++ b/src/npvr/ovr_manager.h @@ -8,17 +8,16 @@ namespace npvr { -class OVRManager: public OVR::MessageHandler { +class OVRManager { public: static OVRManager *Instance(); bool DevicePresent() const; - OVR::Quatf &GetOrientation() const; - virtual void OnMessage(const OVR::Message &message); + OVR::Quatf* &GetOrientation() const; + OVR::Vector3f* &GetPosition() const; + ovrHmd &OVRManager::GetConfiguration() const; private: OVRManager(); - OVR::DeviceManager *device_manager_; - OVR::HMDDevice *hmd_device_; - OVR::SensorFusion *sensor_fusion_; + ovrHmd hmd_device_; }; } // namespace npvr diff --git a/src/npvr/vr_object.cpp b/src/npvr/vr_object.cpp index 6ee1a51..690e582 100644 --- a/src/npvr/vr_object.cpp +++ b/src/npvr/vr_object.cpp @@ -32,6 +32,7 @@ VRObject::VRObject(NPP npp) : sixense_ready_(false) { exec_id_ = NPN_GetStringIdentifier("exec"); poll_id_ = NPN_GetStringIdentifier("poll"); + oState_id_ = NPN_GetStringIdentifier("oculState"); // Initialize sixense library, if needed. if (!sixense_init_count_) { @@ -94,6 +95,34 @@ void VRObject::ExecQuery(const char* command_str, std::ostringstream& s) { s << "hello!"; } +bool VRObject::InvokeOConfigurationRequest(const NPVariant* args, uint32_t arg_count, + NPVariant* result) { + std::ostringstream s; + + GetOculusConfiguration(s); + + // TODO(benvanik): avoid this extra allocation/copy somehow - perhaps + // by preallocating a large enough buffer (fixed size 8K or something) + std::string s_value = s.str(); + size_t s_len = s_value.length(); + NPUTF8* ret_str = (NPUTF8*)NPN_MemAlloc(s_len + 1); + strcpy(ret_str, s_value.c_str()); + STRINGZ_TO_NPVARIANT(ret_str, *result); + + return true; +} + +void VRObject::GetOculusConfiguration(std::ostringstream& s) { + OVRManager *manager = OVRManager::Instance(); + if (manager->DevicePresent()) { + ovrHmd configuration = manager->GetConfiguration(); + s << configuration->DisplayDeviceName << ","; + s << configuration->Resolution.h << ","; + s << configuration->Resolution.w << ","; + s << configuration->ProductName << ","; + } +} + bool VRObject::InvokePoll(const NPVariant* args, uint32_t arg_count, NPVariant* result) { std::ostringstream s; @@ -165,15 +194,19 @@ void VRObject::PollOculus(std::ostringstream& s) { OVRManager *manager = OVRManager::Instance(); if (manager->DevicePresent()) { s << "r,"; - OVR::Quatf o = manager->GetOrientation(); - s << o.x << "," << o.y << "," << o.z << "," << o.w; - s << "|"; + OVR::Quatf* o = manager->GetOrientation(); + // Extended with the three position parameters! ==> Attention: Needs update from VR.js + OVR::Vector3f* pos = manager->GetPosition(); + s << o->x << "," << o->y << "," << o->z << "," << o->w; + s << "," << pos->x << "," << pos->y << "," << pos->z; + s << "|"; } } bool VRObject::HasMethod(NPIdentifier name) { if (name == exec_id_ || - name == poll_id_) { + name == poll_id_ || + name == oState_id_) { return true; } return false; @@ -181,12 +214,18 @@ bool VRObject::HasMethod(NPIdentifier name) { bool VRObject::Invoke(NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result) { - if (name == exec_id_) { - return InvokeExec(args, argCount, result); - } else if (name == poll_id_) { - return InvokePoll(args, argCount, result); - } - return false; + if (name == exec_id_) { + return InvokeExec(args, argCount, result); + } + else if (name == poll_id_) { + return InvokePoll(args, argCount, result); + } + else if (name == oState_id_) + { + return InvokeOConfigurationRequest(args, argCount, result); + } + + return false; } bool VRObject::InvokeDefault(const NPVariant* args, uint32_t argCount, @@ -210,6 +249,7 @@ bool VRObject::Enumerate(NPIdentifier** identifiers, uint32_t* count) { static NPIdentifier all_ids[] = { exec_id_, poll_id_, + oState_id_, }; int id_count = (int)(sizeof(all_ids) / sizeof(NPIdentifier)); NPIdentifier* ids = (NPIdentifier*)NPN_MemAlloc(id_count); diff --git a/src/npvr/vr_object.h b/src/npvr/vr_object.h index a50f6b5..4ad47b0 100644 --- a/src/npvr/vr_object.h +++ b/src/npvr/vr_object.h @@ -31,12 +31,15 @@ class VRObject : public NPObjectBase { void ExecQuery(const char* command_str, std::ostringstream& s); bool InvokePoll(const NPVariant* args, uint32_t arg_count, NPVariant* result); + bool InvokeOConfigurationRequest(const NPVariant* args, uint32_t arg_count, NPVariant* result); void PollSixense(std::ostringstream& s); void PollOculus(std::ostringstream& s); + void GetOculusConfiguration(std::ostringstream& s); private: NPIdentifier exec_id_; NPIdentifier poll_id_; + NPIdentifier oState_id_; bool sixense_ready_; }; diff --git a/third_party/sixense/bin/x64/release_dll/sixense_utils_x64.dll b/third_party/sixense/bin/x64/release_dll/sixense_utils_x64.dll new file mode 100644 index 0000000..9cbeb92 Binary files /dev/null and b/third_party/sixense/bin/x64/release_dll/sixense_utils_x64.dll differ diff --git a/third_party/sixense/bin/x64/release_dll/sixense_utils_x64.pdb b/third_party/sixense/bin/x64/release_dll/sixense_utils_x64.pdb new file mode 100644 index 0000000..0581e0b Binary files /dev/null and b/third_party/sixense/bin/x64/release_dll/sixense_utils_x64.pdb differ diff --git a/third_party/sixense/bin/x64/release_dll/sixense_x64.dll b/third_party/sixense/bin/x64/release_dll/sixense_x64.dll new file mode 100644 index 0000000..6320f29 Binary files /dev/null and b/third_party/sixense/bin/x64/release_dll/sixense_x64.dll differ diff --git a/third_party/sixense/bin/x64/release_dll/sixense_x64.pdb b/third_party/sixense/bin/x64/release_dll/sixense_x64.pdb new file mode 100644 index 0000000..63c7468 Binary files /dev/null and b/third_party/sixense/bin/x64/release_dll/sixense_x64.pdb differ diff --git a/third_party/sixense/lib/x64/release_dll/sixense_utils_x64.lib b/third_party/sixense/lib/x64/release_dll/sixense_utils_x64.lib new file mode 100644 index 0000000..7211555 Binary files /dev/null and b/third_party/sixense/lib/x64/release_dll/sixense_utils_x64.lib differ diff --git a/third_party/sixense/lib/x64/release_dll/sixense_x64.lib b/third_party/sixense/lib/x64/release_dll/sixense_x64.lib new file mode 100644 index 0000000..bdf00ea Binary files /dev/null and b/third_party/sixense/lib/x64/release_dll/sixense_x64.lib differ