Files
vr-poser/include/BoneSelector.h
2026-03-16 00:22:49 -04:00

55 lines
1.6 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <osg/ref_ptr>
#include <osg/Vec3>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Geometry>
#include <osgViewer/Viewer>
#include <osgAnimation/Bone>
class PoseManager;
class BoneSelector {
public:
explicit BoneSelector(PoseManager* poseMgr);
void init(osgViewer::Viewer* viewer, osg::Group* sceneRoot);
/// Update bone positions each frame. Only rebuilds geometry when
/// selection changes — sphere positions update via vertex array dirty().
void updateVisualization();
std::string pick(float mouseX, float mouseY, osgViewer::Viewer* viewer);
void setSelected(const std::string& boneName);
const std::string& selected() const { return m_selected; }
void setVisible(bool v);
bool isVisible() const { return m_visible; }
private:
void buildInitialGeometry(); // called once on init
void updatePositions(); // cheap per-frame position update
PoseManager* m_poseMgr = nullptr;
osg::ref_ptr<osg::Group> m_root;
osg::ref_ptr<osg::Geode> m_lines;
osg::ref_ptr<osg::Geode> m_spheres;
// Line geometry arrays — updated in place each frame
osg::ref_ptr<osg::Vec3Array> m_lineVerts;
osg::ref_ptr<osg::Vec4Array> m_lineColors;
// Sphere positions — one MatrixTransform per bone
std::vector<osg::ref_ptr<osg::MatrixTransform>> m_sphereXforms;
std::vector<std::string> m_sphereBoneNames;
std::string m_selected;
std::string m_prevSelected; // detect selection changes
bool m_visible = true;
bool m_geometryBuilt = false;
};