DI-Guy SDK Documentation  13.8
diguyOsgGraphicsLink.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2024 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
6 #ifndef diguyOsgGraphicsLink_h__
7 #define diguyOsgGraphicsLink_h__
8 
9 #include <diguyGraphicsLink.h>
10 
11 #include <osg/Group>
12 #include <osg/MatrixTransform>
13 #include <osgViewer/Viewer>
14 
15 class diguyGraphicsState;
21 class diguyScenario;
22 
23 
32 class diguyOsgRootNode : public osg::MatrixTransform
33 {
34 public :
36  void traverse(osg::NodeVisitor& nv);
37 
39  void add_geode_for_fast_draw(diguyOsgGraphicsShape * shape, osg::Geode* geode, int lod)
40  {
41  if(lod >= m_lod_drawables.size()){
42  m_lod_drawables.resize(lod+1);
43  }
44  m_lod_drawables[lod].push_back(diguyOsgGraphicsShapeGeodeMap(shape, geode));
45  }
46  void add_switch_for_fast_draw(diguyOsgGraphicsShape * shape, osg::Switch* switch_node)
47  {
48  m_switch_nodes.push_back(diguyOsgGraphicsShapeSwitchMap(shape, switch_node));
49  }
50 
51 private:
52  // two pairs for tracking shape geode and shape switch connections
54  {
55  diguyOsgGraphicsShapeGeodeMap(diguyOsgGraphicsShape * shape, osg::Geode* geode) :
56  m_shape(shape), m_geode(geode) {}
57 
59  osg::Geode* m_geode;
60  };
62  {
63  diguyOsgGraphicsShapeSwitchMap(diguyOsgGraphicsShape * shape, osg::Switch* switch_node) :
64  m_shape(shape), m_switch(switch_node){}
65 
67  osg::Switch* m_switch;
68  };
69 
70  std::vector<diguyOsgGraphicsShapeSwitchMap> m_switch_nodes;
71  std::vector<std::vector<diguyOsgGraphicsShapeGeodeMap> > m_lod_drawables;
72 
74 };
75 
76 
77 
100 {
101 
102 public:
103 
104  diguyOsgGraphicsLink(void* internal_data);
105 
106  virtual void build() override;
107 
108 
109  virtual void unbuild() override;
110  virtual void update() override;
111  virtual void attach_to_scene();
112  virtual void detach_from_scene();
113  virtual void instancing_state_changed(int is_instanced) override;
114  virtual void set_shader_instance(diguyGraphicsShaderInstance* shader_instance) override;
115 
116  virtual void post_build();
118  osg::MatrixTransform* get_dof_node() {return m_dof_node.get();}
119  osg::StateSet* get_top_level_state_set();
120 
123  static void set_diguy_attach_ptr(diguyScenario * scenario, osg::Group* diguy_attach_pt);
124 
125  static osgViewer::Viewer* get_viewer() {return s_viewer; }
126  static void set_viewer(osgViewer::Viewer* viewer) {s_viewer = viewer;}
127 
130 
131 protected:
132  friend class diguyOsgGraphicsShape;
133  friend class diguyOsgRootNode;
134 
135  osg::Geode* make_bounding_sphere_visual(osg::Vec3& center, float radius);
137 // diguyGraphicsState* get_top_level_graphics_state();
138 // void recursive_post_build(diguyGraphicsState* first_state);
141  osg::ref_ptr<osg::Uniform> m_ufrm_link_matrix;
143  // vars that are probably only relevant to the base link
144  osg::ref_ptr<osg::MatrixTransform> m_dof_node;
145  osg::ref_ptr<osg::Uniform> m_ufrm_inverse_transform_matrix;
146  osg::ref_ptr<osg::Uniform> m_ufrm_eye_point_os;
147  osg::ref_ptr<osg::Uniform> m_ufrm_light_dir_os;
148  osg::ref_ptr<osg::Uniform> m_ufrm_emission_color;
149 
150  osg::ref_ptr<osg::Geode> m_bounding_sphere_visual;
154 
155  static osg::Group* s_diguy_attach_pt;
156  static osg::Group* s_diguy_instancing_attach_pt;
157  static osgViewer::Viewer* s_viewer;
158  int m_instanced;
159 };
160 
161 
168 #endif // diguyOsgGraphicsLink_h__
169 
170 
Definition: diguyOsgGraphicsShaderProgram.h:34
A class that represents the unique per-character shader object.
Definition: diguyGraphicsShaderInstance.h:54
void add_geode_for_fast_draw(diguyOsgGraphicsShape *shape, osg::Geode *geode, int lod)
Definition: diguyOsgGraphicsLink.h:38
Graphics state objects mostly serve as containers for other sub-objects, such as materials and textur...
Definition: diguyOsgGraphicsState.h:25
std::vector< diguyOsgGraphicsShapeSwitchMap > m_switch_nodes
Definition: diguyOsgGraphicsLink.h:69
diguyOsgRootNode(diguyOsgGraphicsLink *link)
Definition: diguyOsgGraphicsShaderInstance.h:21
osg::Geode * m_geode
Definition: diguyOsgGraphicsLink.h:58
Definition: diguyOsgGraphicsLink.h:31
osg::Switch * m_switch
Definition: diguyOsgGraphicsLink.h:66
A class that represents a shared material/textures combination.
Definition: diguyGraphicsState.h:44
Definition: diguyOsgGraphicsLink.h:60
void traverse(osg::NodeVisitor &nv)
diguyOsgGraphicsShape * m_shape
Definition: diguyOsgGraphicsLink.h:65
Definition: diguyOsgGraphicsLink.h:52
Shapes are the high-level containers of visible geometry.
Definition: diguyOsgGraphicsShape.h:38
Represents the scenario currently being portrayed.
Definition: diguyScenario.h:99
std::vector< std::vector< diguyOsgGraphicsShapeGeodeMap > > m_lod_drawables
Definition: diguyOsgGraphicsLink.h:70
diguyOsgGraphicsShapeSwitchMap(diguyOsgGraphicsShape *shape, osg::Switch *switch_node)
Definition: diguyOsgGraphicsLink.h:62
diguyOsgGraphicsShape * m_shape
Definition: diguyOsgGraphicsLink.h:57
void remove_shape(diguyOsgGraphicsShape *shape)
void add_switch_for_fast_draw(diguyOsgGraphicsShape *shape, osg::Switch *switch_node)
Definition: diguyOsgGraphicsLink.h:45
diguyOsgGraphicsLink * m_link
Definition: diguyOsgGraphicsLink.h:72
diguyOsgGraphicsShapeGeodeMap(diguyOsgGraphicsShape *shape, osg::Geode *geode)
Definition: diguyOsgGraphicsLink.h:54