mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 11:42:55 +02:00
Added shared DebugDraw singleton.
This commit is contained in:
parent
d53295655f
commit
d04f4d4b2b
5 changed files with 123 additions and 26 deletions
|
@ -47,6 +47,7 @@
|
||||||
#include "Recorder.h"
|
#include "Recorder.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "InterfaceLogging.h"
|
#include "InterfaceLogging.h"
|
||||||
|
#include "DebugDraw.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -1358,6 +1359,9 @@ void MyAvatar::preRender(RenderArgs* renderArgs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DebugDraw::getInstance().updateMyAvatarPos(getPosition());
|
||||||
|
DebugDraw::getInstance().updateMyAvatarRot(getOrientation());
|
||||||
|
|
||||||
if (shouldDrawHead != _prevShouldDrawHead) {
|
if (shouldDrawHead != _prevShouldDrawHead) {
|
||||||
_skeletonModel.setCauterizeBones(!shouldDrawHead);
|
_skeletonModel.setCauterizeBones(!shouldDrawHead);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "AbstractViewStateInterface.h"
|
#include "AbstractViewStateInterface.h"
|
||||||
#include "RenderUtilsLogging.h"
|
#include "RenderUtilsLogging.h"
|
||||||
#include "GLMHelpers.h"
|
#include "GLMHelpers.h"
|
||||||
|
#include "DebugDraw.h"
|
||||||
|
|
||||||
#include "AnimDebugDraw.h"
|
#include "AnimDebugDraw.h"
|
||||||
|
|
||||||
|
@ -67,13 +68,9 @@ namespace render {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static AnimDebugDraw* instance = nullptr;
|
|
||||||
|
|
||||||
AnimDebugDraw& AnimDebugDraw::getInstance() {
|
AnimDebugDraw& AnimDebugDraw::getInstance() {
|
||||||
if (!instance) {
|
static AnimDebugDraw instance;
|
||||||
instance = new AnimDebugDraw();
|
return instance;
|
||||||
}
|
|
||||||
return *instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t toRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
static uint32_t toRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||||
|
@ -176,14 +173,6 @@ void AnimDebugDraw::removePoses(const std::string& key) {
|
||||||
_poses.erase(key);
|
_poses.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimDebugDraw::addPose(const std::string& key, const AnimPose& pose, const AnimPose& rootPose) {
|
|
||||||
_singlePoses[key] = SinglePoseInfo(pose, rootPose);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnimDebugDraw::removePose(const std::string& key) {
|
|
||||||
_singlePoses.erase(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const uint32_t red = toRGBA(255, 0, 0, 255);
|
static const uint32_t red = toRGBA(255, 0, 0, 255);
|
||||||
static const uint32_t green = toRGBA(0, 255, 0, 255);
|
static const uint32_t green = toRGBA(0, 255, 0, 255);
|
||||||
static const uint32_t blue = toRGBA(0, 0, 255, 255);
|
static const uint32_t blue = toRGBA(0, 0, 255, 255);
|
||||||
|
@ -380,7 +369,11 @@ void AnimDebugDraw::update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
numVerts += _singlePoses.size() * VERTICES_PER_BONE;
|
// count marker verts from shared DebugDraw singleton
|
||||||
|
auto markerMap = DebugDraw::getInstance().getMarkerMap();
|
||||||
|
numVerts += markerMap.size() * VERTICES_PER_BONE;
|
||||||
|
auto myAvatarMarkerMap = DebugDraw::getInstance().getMyAvatarMarkerMap();
|
||||||
|
numVerts += myAvatarMarkerMap.size() * VERTICES_PER_BONE;
|
||||||
|
|
||||||
data._vertexBuffer->resize(sizeof(Vertex) * numVerts);
|
data._vertexBuffer->resize(sizeof(Vertex) * numVerts);
|
||||||
Vertex* verts = (Vertex*)data._vertexBuffer->editData();
|
Vertex* verts = (Vertex*)data._vertexBuffer->editData();
|
||||||
|
@ -486,11 +479,22 @@ void AnimDebugDraw::update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& iter : _singlePoses) {
|
// draw markers from shared DebugDraw singleton
|
||||||
AnimPose pose = std::get<0>(iter.second);
|
for (auto& iter : markerMap) {
|
||||||
AnimPose rootPose = std::get<1>(iter.second);
|
glm::quat rot = std::get<0>(iter.second);
|
||||||
const float radius = POSE_RADIUS / (pose.scale.x * rootPose.scale.x);
|
glm::vec3 pos = std::get<1>(iter.second);
|
||||||
addBone(rootPose, pose, radius, v);
|
glm::vec4 color = std::get<2>(iter.second); // TODO: currently ignored.
|
||||||
|
const float radius = POSE_RADIUS;
|
||||||
|
addBone(AnimPose::identity, AnimPose(glm::vec3(1), rot, pos), radius, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimPose myAvatarPose(glm::vec3(1), DebugDraw::getInstance().getMyAvatarRot(), DebugDraw::getInstance().getMyAvatarPos());
|
||||||
|
for (auto& iter : myAvatarMarkerMap) {
|
||||||
|
glm::quat rot = std::get<0>(iter.second);
|
||||||
|
glm::vec3 pos = std::get<1>(iter.second);
|
||||||
|
glm::vec4 color = std::get<2>(iter.second); // TODO: currently ignored.
|
||||||
|
const float radius = POSE_RADIUS;
|
||||||
|
addBone(myAvatarPose, AnimPose(glm::vec3(1), rot, pos), radius, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(numVerts == (v - verts));
|
assert(numVerts == (v - verts));
|
||||||
|
|
|
@ -39,10 +39,6 @@ public:
|
||||||
void addPoses(const std::string& key, AnimSkeleton::ConstPointer skeleton, const AnimPoseVec& poses, const AnimPose& rootPose, const glm::vec4& color);
|
void addPoses(const std::string& key, AnimSkeleton::ConstPointer skeleton, const AnimPoseVec& poses, const AnimPose& rootPose, const glm::vec4& color);
|
||||||
void removePoses(const std::string& key);
|
void removePoses(const std::string& key);
|
||||||
|
|
||||||
// draw a single pose
|
|
||||||
void addPose(const std::string& key, const AnimPose& rootPose, const AnimPose& pose);
|
|
||||||
void removePose(const std::string& key);
|
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -55,12 +51,10 @@ protected:
|
||||||
typedef std::tuple<AnimSkeleton::ConstPointer, AnimPose, glm::vec4> SkeletonInfo;
|
typedef std::tuple<AnimSkeleton::ConstPointer, AnimPose, glm::vec4> SkeletonInfo;
|
||||||
typedef std::tuple<AnimNode::ConstPointer, AnimPose, glm::vec4> AnimNodeInfo;
|
typedef std::tuple<AnimNode::ConstPointer, AnimPose, glm::vec4> AnimNodeInfo;
|
||||||
typedef std::tuple<AnimSkeleton::ConstPointer, AnimPoseVec, AnimPose, glm::vec4> PosesInfo;
|
typedef std::tuple<AnimSkeleton::ConstPointer, AnimPoseVec, AnimPose, glm::vec4> PosesInfo;
|
||||||
typedef std::tuple<AnimPose, AnimPose> SinglePoseInfo;
|
|
||||||
|
|
||||||
std::unordered_map<std::string, SkeletonInfo> _skeletons;
|
std::unordered_map<std::string, SkeletonInfo> _skeletons;
|
||||||
std::unordered_map<std::string, AnimNodeInfo> _animNodes;
|
std::unordered_map<std::string, AnimNodeInfo> _animNodes;
|
||||||
std::unordered_map<std::string, PosesInfo> _poses;
|
std::unordered_map<std::string, PosesInfo> _poses;
|
||||||
std::unordered_map<std::string, SinglePoseInfo> _singlePoses;
|
|
||||||
|
|
||||||
// no copies
|
// no copies
|
||||||
AnimDebugDraw(const AnimDebugDraw&) = delete;
|
AnimDebugDraw(const AnimDebugDraw&) = delete;
|
||||||
|
|
40
libraries/shared/src/DebugDraw.cpp
Normal file
40
libraries/shared/src/DebugDraw.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// DebugDraw.cpp
|
||||||
|
//
|
||||||
|
// 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 "DebugDraw.h"
|
||||||
|
|
||||||
|
DebugDraw& DebugDraw::getInstance() {
|
||||||
|
static DebugDraw instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugDraw::DebugDraw() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugDraw::~DebugDraw() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDraw::addMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color) {
|
||||||
|
_markers[key] = MarkerInfo(rotation, position, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDraw::removeMarker(const std::string& key) {
|
||||||
|
_markers.erase(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDraw::addMyAvatarMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color) {
|
||||||
|
_myAvatarMarkers[key] = MarkerInfo(rotation, position, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugDraw::removeMyAvatarMarker(const std::string& key) {
|
||||||
|
_myAvatarMarkers.erase(key);
|
||||||
|
}
|
||||||
|
|
55
libraries/shared/src/DebugDraw.h
Normal file
55
libraries/shared/src/DebugDraw.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
//
|
||||||
|
// DebugDraw.h
|
||||||
|
//
|
||||||
|
// 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_DebugDraw_h
|
||||||
|
#define hifi_DebugDraw_h
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <tuple>
|
||||||
|
#include <string>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
|
class DebugDraw {
|
||||||
|
public:
|
||||||
|
static DebugDraw& getInstance();
|
||||||
|
|
||||||
|
DebugDraw();
|
||||||
|
~DebugDraw();
|
||||||
|
|
||||||
|
// world space maker
|
||||||
|
void addMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color);
|
||||||
|
void removeMarker(const std::string& key);
|
||||||
|
|
||||||
|
// myAvatar relative marker
|
||||||
|
void addMyAvatarMarker(const std::string& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color);
|
||||||
|
void removeMyAvatarMarker(const std::string& key);
|
||||||
|
|
||||||
|
using MarkerInfo = std::tuple<glm::quat, glm::vec3, glm::vec4>;
|
||||||
|
using MarkerMap = std::unordered_map<std::string, MarkerInfo>;
|
||||||
|
|
||||||
|
//
|
||||||
|
// accessors used by renderer
|
||||||
|
//
|
||||||
|
|
||||||
|
const MarkerMap& getMarkerMap() const { return _markers; }
|
||||||
|
const MarkerMap& getMyAvatarMarkerMap() const { return _myAvatarMarkers; }
|
||||||
|
void updateMyAvatarPos(const glm::vec3& pos) { _myAvatarPos = pos; }
|
||||||
|
const glm::vec3& getMyAvatarPos() const { return _myAvatarPos; }
|
||||||
|
void updateMyAvatarRot(const glm::quat& rot) { _myAvatarRot = rot; }
|
||||||
|
const glm::quat& getMyAvatarRot() const { return _myAvatarRot; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MarkerMap _markers;
|
||||||
|
MarkerMap _myAvatarMarkers;
|
||||||
|
glm::quat _myAvatarRot;
|
||||||
|
glm::vec3 _myAvatarPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_DebugDraw_h
|
Loading…
Reference in a new issue