Skip to content

Commit

Permalink
GLTF parsing (#139)
Browse files Browse the repository at this point in the history
* inital gltf parse (really broken)

* use memcpy directly

* fix off-by-one error, working

* fix out of range error, change file name

* potential bugfix for lerp

* fix lerp

* Overhauled Bones.cpp to add GLTF caching (#140)

* Overhauled Bones.cpp to add GLTF caching

* Just call three methods as per @danwillm

* Removed pointless cast

* left hand transforms

* Update include/DeviceConfiguration.h

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update include/DeviceProvider.h

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update include/DriverLog.h

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update include/Util/Windows.h

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update src/Communication/BTSerialCommunicationManager.cpp

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update src/Communication/SerialCommunicationManager.cpp

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update src/DeviceProvider.cpp

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update src/Util/Windows.cpp

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update src/Util/Windows.cpp

Co-authored-by: noob247365 <noob247365@gmail.com>

* Update src/Util/Windows.cpp

Co-authored-by: noob247365 <noob247365@gmail.com>

* Gltf node index (#143)

* bone index->node index?

* remove num_bones from class members

* redo configuration

* bugfix node

* comments

Co-authored-by: noob247365 <noob247365@gmail.com>
  • Loading branch information
danwillm and noob247365 authored Aug 23, 2021
1 parent 10d933b commit 8b858f0
Show file tree
Hide file tree
Showing 22 changed files with 541 additions and 425 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libraries/openvr"]
path = libraries/openvr
url = https://github.com/ValveSoftware/openvr.git
url = https://github.com/ValveSoftware/openvr.git
[submodule "libraries/tinygltf"]
path = libraries/tinygltf
url = https://github.com/syoyo/tinygltf.git
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Deps
set(OPENVR_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/openvr/headers")
set(TINYGLTF_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/tinygltf")

set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})

Expand Down Expand Up @@ -35,7 +36,7 @@ file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")

add_library("${OPENGLOVE_PROJECT}" SHARED "${HEADERS}" "${SOURCES}")

target_include_directories("${OPENGLOVE_PROJECT}" PUBLIC "${OPENVR_INCLUDE_DIR}")
target_include_directories("${OPENGLOVE_PROJECT}" PUBLIC "${OPENVR_INCLUDE_DIR}" "${TINYGLTF_INCLUDE_DIR}")

target_include_directories("${OPENGLOVE_PROJECT}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/")
target_link_libraries("${OPENGLOVE_PROJECT}" PUBLIC "${OPENVR_LIB}" setupapi wsock32 ws2_32 bthprops)
Expand Down
123 changes: 75 additions & 48 deletions include/Bones.h
Original file line number Diff line number Diff line change
@@ -1,56 +1,83 @@
#pragma once
#include <openvr_driver.h>

#include <array>
#include <memory>

const int NUM_BONES = 31;
extern vr::VRBoneTransform_t rightOpenPose[NUM_BONES];
extern vr::VRBoneTransform_t rightFistPose[NUM_BONES];
#include "openvr_driver.h"

enum class HandSkeletonBone : vr::BoneIndex_t {
eBone_Root = 0,
eBone_Wrist,
eBone_Thumb0,
eBone_Thumb1,
eBone_Thumb2,
eBone_Thumb3,
eBone_IndexFinger0,
eBone_IndexFinger1,
eBone_IndexFinger2,
eBone_IndexFinger3,
eBone_IndexFinger4,
eBone_MiddleFinger0,
eBone_MiddleFinger1,
eBone_MiddleFinger2,
eBone_MiddleFinger3,
eBone_MiddleFinger4,
eBone_RingFinger0,
eBone_RingFinger1,
eBone_RingFinger2,
eBone_RingFinger3,
eBone_RingFinger4,
eBone_PinkyFinger0,
eBone_PinkyFinger1,
eBone_PinkyFinger2,
eBone_PinkyFinger3,
eBone_PinkyFinger4,
eBone_Aux_Thumb,
eBone_Aux_IndexFinger,
eBone_Aux_MiddleFinger,
eBone_Aux_RingFinger,
eBone_Aux_PinkyFinger,
eBone_Count
};

const short NUM_BONES = (short)HandSkeletonBone::eBone_Count;

extern vr::VRBoneTransform_t rightOpenPose[NUM_BONES];
extern vr::VRBoneTransform_t leftOpenPose[NUM_BONES];
extern vr::VRBoneTransform_t leftFistPose[NUM_BONES];

enum HandSkeletonBone : vr::BoneIndex_t {
eBone_Root = 0,
eBone_Wrist,
eBone_Thumb0,
eBone_Thumb1,
eBone_Thumb2,
eBone_Thumb3,
eBone_IndexFinger0,
eBone_IndexFinger1,
eBone_IndexFinger2,
eBone_IndexFinger3,
eBone_IndexFinger4,
eBone_MiddleFinger0,
eBone_MiddleFinger1,
eBone_MiddleFinger2,
eBone_MiddleFinger3,
eBone_MiddleFinger4,
eBone_RingFinger0,
eBone_RingFinger1,
eBone_RingFinger2,
eBone_RingFinger3,
eBone_RingFinger4,
eBone_PinkyFinger0,
eBone_PinkyFinger1,
eBone_PinkyFinger2,
eBone_PinkyFinger3,
eBone_PinkyFinger4,
eBone_Aux_Thumb,
eBone_Aux_IndexFinger,
eBone_Aux_MiddleFinger,
eBone_Aux_RingFinger,
eBone_Aux_PinkyFinger,
eBone_Count

struct Transform_t {
Transform_t();
std::array<float, 4> rotation;
std::array<float, 3> translation;
};

void ComputeHand(vr::VRBoneTransform_t* skeleton, const std::array<float, 5>& flexion, bool isRightHand);
void ComputeBoneFlexion(vr::VRBoneTransform_t* bone_transform, float transform, int index, const bool isRightHand);
struct AnimationData_t {
AnimationData_t();
Transform_t startTransform;
float startTime;
Transform_t endTransform;
float endTime;
};

class IModelManager {
public:
virtual bool Load() = 0;

virtual AnimationData_t GetAnimationDataByBoneIndex(const HandSkeletonBone& boneIndex, float f) const = 0;
virtual Transform_t GetTransformByBoneIndex(const HandSkeletonBone& boneIndex) const = 0;
};

class BoneAnimator {
public:
BoneAnimator(const std::string& fileName);
void ComputeSkeletonTransforms(vr::VRBoneTransform_t* skeleton, const std::array<float, 5>& flexion, const bool rightHand);
void TransformLeftBone(vr::VRBoneTransform_t& bone, const HandSkeletonBone& boneIndex);

private:
vr::VRBoneTransform_t GetTransformForBone(const HandSkeletonBone& boneIndex, const float f, const bool rightHand);

vr::HmdQuaternionf_t CalculateOrientation(const float transform, const int boneIndex, const vr::VRBoneTransform_t* openPose, const vr::VRBoneTransform_t* fistPose);
vr::HmdVector4_t CalculatePosition(const float transform, const int boneIndex, const vr::VRBoneTransform_t* openPose, const vr::VRBoneTransform_t* fistPose);
int FingerFromBone(vr::BoneIndex_t bone);
/**
*Linear interpolation between a and b.
**/
float Lerp(const float a, const float b, const float f);
std::string m_fileName;
std::unique_ptr<IModelManager> m_modelManager;
bool m_loaded;
std::vector<float> m_keyframes;
};
2 changes: 0 additions & 2 deletions include/Communication/BTSerialCommunicationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include "DeviceConfiguration.h"
#include "DriverLog.h"

static const char* c_btserialCommunicationSettingsSection = "communication_btserial";

class BTSerialCommunicationManager : public ICommunicationManager {
public:
BTSerialCommunicationManager(const VRBTSerialConfiguration_t& configuration, std::unique_ptr<IEncodingManager> encodingManager);
Expand Down
2 changes: 0 additions & 2 deletions include/Communication/SerialCommunicationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "CommunicationManager.h"
#include "DeviceConfiguration.h"

static const char* c_serialCommunicationSettingsSection = "communication_serial";

class SerialCommunicationManager : public ICommunicationManager {
public:
SerialCommunicationManager(const VRSerialConfiguration_t& configuration, std::unique_ptr<IEncodingManager> encodingManager)
Expand Down
11 changes: 8 additions & 3 deletions include/DeviceConfiguration.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#pragma once

#include "openvr_driver.h"

#include "Communication/CommunicationManager.h"
#include "DeviceDriver/DeviceDriver.h"
#include "Encode/EncodingManager.h"
#include "openvr_driver.h"

static const char* c_driverSettingsSection = "driver_openglove";
static const char* c_poseSettingsSection = "pose_settings";
extern const char* c_poseSettingsSection;
extern const char* c_driverSettingsSection;
extern const char* c_serialCommunicationSettingsSection;
extern const char* c_btserialCommunicationSettingsSection;
extern const char* c_knuckleDeviceSettingsSection;
extern const char* c_lucidGloveDeviceSettingsSection;

enum class VRCommunicationProtocol {
SERIAL = 0,
Expand Down
9 changes: 4 additions & 5 deletions include/DeviceDriver/KnuckleDriver.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#pragma once
#include <openvr_driver.h>

#include "openvr_driver.h"

#include <functional>
#include <memory>
Expand All @@ -13,11 +13,9 @@
#include "Encode/LegacyEncodingManager.h"
#include "ForceFeedback.h"

static const char* c_knuckleDeviceSettingsSection = "device_knuckles";

class KnuckleDeviceDriver : public IDeviceDriver {
public:
KnuckleDeviceDriver(VRDeviceConfiguration_t configuration, std::unique_ptr<ICommunicationManager> communicationManager, std::string serialNumber);
KnuckleDeviceDriver(VRDeviceConfiguration_t configuration, std::unique_ptr<ICommunicationManager> communicationManager, std::string serialNumber, std::shared_ptr<BoneAnimator> boneAnimator);

vr::EVRInitError Activate(uint32_t unObjectId);
void Deactivate();
Expand Down Expand Up @@ -51,4 +49,5 @@ class KnuckleDeviceDriver : public IDeviceDriver {

std::unique_ptr<ControllerPose> m_controllerPose;
std::unique_ptr<FFBListener> m_ffbProvider;
std::shared_ptr<BoneAnimator> m_boneAnimator;
};
72 changes: 31 additions & 41 deletions include/DeviceDriver/LucidGloveDriver.h
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
#pragma once
#include <openvr_driver.h>
#include "openvr_driver.h"

#include <functional>
#include <memory>

#include "Communication/CommunicationManager.h"
#include "Encode/LegacyEncodingManager.h"
#include "DeviceDriver/DeviceDriver.h"

#include "Bones.h"

#include "Communication/CommunicationManager.h"
#include "ControllerPose.h"
#include "DeviceConfiguration.h"
#include "DeviceDriver/DeviceDriver.h"
#include "Encode/LegacyEncodingManager.h"

static const char* c_lucidGloveDeviceSettingsSection = "device_lucidgloves";

/**
This class controls the behavior of the controller. This is where you
tell OpenVR what your controller has (buttons, joystick, trackpad, etc.).
This is also where you inform OpenVR when the state of your controller
changes (for example, a button is pressed).
For the methods, take a look at the comment blocks for the ITrackedDeviceServerDriver
class too. Those comment blocks have some good information.
**/
class LucidGloveDeviceDriver : public IDeviceDriver {
public:
LucidGloveDeviceDriver(VRDeviceConfiguration_t configuration, std::unique_ptr<ICommunicationManager> communicationManager, std::string serialNumber);
public:
LucidGloveDeviceDriver(VRDeviceConfiguration_t configuration, std::unique_ptr<ICommunicationManager> communicationManager, std::string serialNumber,
std::shared_ptr<BoneAnimator> boneAnimator);

vr::EVRInitError Activate(uint32_t unObjectId);
void Deactivate();

vr::EVRInitError Activate(uint32_t unObjectId);
void Deactivate();
void EnterStandby();
void* GetComponent(const char* pchComponentNameAndVersion);
void DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize);
vr::DriverPose_t GetPose();
void RunFrame();

void EnterStandby();
void* GetComponent(const char* pchComponentNameAndVersion);
void DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize);
vr::DriverPose_t GetPose();
void RunFrame();
std::string GetSerialNumber();

std::string GetSerialNumber();
bool IsActive();

bool IsActive();
private:
void StartDevice();
bool IsRightHand() const;
private:
void StartDevice();
bool IsRightHand() const;

bool m_hasActivated;
uint32_t m_driverId;
bool m_hasActivated;
uint32_t m_driverId;

vr::VRInputComponentHandle_t m_skeletalComponentHandle{};
vr::VRInputComponentHandle_t m_inputComponentHandles[15]{};
vr::VRInputComponentHandle_t m_skeletalComponentHandle{};
vr::VRInputComponentHandle_t m_inputComponentHandles[15]{};

vr::VRBoneTransform_t m_handTransforms[NUM_BONES];
vr::VRBoneTransform_t m_handTransforms[NUM_BONES];

VRDeviceConfiguration_t m_configuration;
std::unique_ptr<ICommunicationManager> m_communicationManager;
std::string m_serialNumber;
VRDeviceConfiguration_t m_configuration;
std::unique_ptr<ICommunicationManager> m_communicationManager;
std::string m_serialNumber;

std::unique_ptr<ControllerPose> m_controllerPose;
std::unique_ptr<ControllerPose> m_controllerPose;
std::shared_ptr<BoneAnimator> m_boneAnimator;
};
5 changes: 3 additions & 2 deletions include/DeviceProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#undef _WINSOCKAPI_
#define _WINSOCKAPI_

#include <openvr_driver.h>
#include "openvr_driver.h"

#include <memory>

#include "Bones.h"
#include "Communication/CommunicationManager.h"
#include "DeviceConfiguration.h"
#include "DeviceDriver/DeviceDriver.h"
Expand Down Expand Up @@ -66,5 +67,5 @@ class DeviceProvider : public vr::IServerTrackedDeviceProvider {
**/
VRDeviceConfiguration_t GetDeviceConfiguration(vr::ETrackedControllerRole role);

std::unique_ptr<IDeviceDriver> InstantiateDeviceDriver(VRDeviceConfiguration_t configuration);
std::unique_ptr<IDeviceDriver> InstantiateDeviceDriver(VRDeviceConfiguration_t configuration, std::shared_ptr<BoneAnimator> boneAnimator);
};
3 changes: 2 additions & 1 deletion include/DriverLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#pragma once

#include <string>
#include <openvr_driver.h>

#include "openvr_driver.h"

extern void DriverLog(const char* pchFormat, ...);

Expand Down
6 changes: 6 additions & 0 deletions include/Util/Windows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <string>

extern std::string GetDriverPath();
extern std::string GetLastErrorAsString();
1 change: 0 additions & 1 deletion libraries/asio
Submodule asio deleted from 57577c
1 change: 1 addition & 0 deletions libraries/tinygltf
Submodule tinygltf added at 514167
Binary file added openglove/resources/anims/glove_anim.glb
Binary file not shown.
Loading

0 comments on commit 8b858f0

Please sign in to comment.