DI-Guy C++ SDK Reference  13.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguyGraphicsShape.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2014 VT MAK
4  ** All rights reserved.
5  *********************************************************************/
6 
7 /*********************************************************************/
14 #ifndef __diguyGraphicsShape_H
15 #define __diguyGraphicsShape_H
16 
17 #ifdef SWIG
18 %module diguyGraphicsShape
19 #else
20 #define CPLUSPLUS_ONLY
21 #endif
22 
23 #ifdef CPLUSPLUS_ONLY
24 #include <diguy_constants.h>
25 
26 class bdiShape;
27 class diguyCharacter;
28 class diguyGraphicsFile;
29 class diguyGraphicsLink;
30 class diguyGraphicsMesh;
31 class diguyGraphicsShape;
32 class diguyGraphicsState;
33 
34 
35 /****************************************************************************/
36 
37 #endif
38 
39 #include <declspec_diguy.h>
40 
41 /****************************************************************************/
42 class BDI_DECLSPEC_diguy diguyGraphicsShape
43 {
44 
45 public:
46 
47 
48 /*****************************************************************************/
61  /*l
62  *b Description:
63  **
64  ** This function returns the name of the shape. The returned pointer
65  ** will never be NULL.
66  **
67  *b Returns:
68  **
69  ** name of the shape as C string
70  */
71  const char* get_name();
72 
73  /*l
74  *b Description:
75  **
76  ** All shapes are assigned a unique identifier, or uid. This function
77  ** returns this shape's uid.
78  **
79  ** *Note*: unique identifiers can change between DI-Guy runs.
80  **
81  *b Returns:
82  **
83  ** unique identifier of object
84  */
85  long get_uid();
86 
87  /*l
88  *b Description:
89  **
90  ** This function returns a pointer to the diguyCharacter to which this
91  ** shape belongs.
92  **
93  *b Returns:
94  **
95  ** pointer of type diguyCharacter
96  */
97  diguyCharacter* get_character();
98 
99 
100  /*l
101  *b Description:
102  **
103  ** This function returns the name of the shape set of which this shape
104  ** is a part.
105  **
106  ** A shape set is a collection of shapes that are related, coming from
107  ** a set of related geometry files, sometimes one file per LOD.
108  **
109  ** A shape is a collection of parts each representing the same thing
110  ** at varying levels of detail.
111  **
112  ** For example, in its config files DI-Guy has a shape set named
113  ** "firefighter", which references five OpenFlight files named
114  ** firefighter_LOD1.flt through firefighter_LOD5.flt. The firefighter
115  ** shape set contains separate shapes for the head, arms, legs, etc.,
116  ** at five different levels of detail.
117  **
118  ** Use the function get_shape_set_filename_for_lod() to get the actual
119  ** geometry filenames that should be used for each LOD.
120  **
121  *b Returns:
122  **
123  ** shape set of shape as C string
124  */
125  const char* get_shape_set_name();
126 
127  /*l
128  *b Description:
129  **
130  ** This function returns the name of the shape. This name identifies
131  ** which pieces of geometry out of the shape set should comprise the
132  ** shape.
133  **
134  *b Returns:
135  **
136  ** shape name of shape as C string
137  */
138  const char* get_shape_set_shape_name();
139 
140  /*l
141  *b Description:
142  **
143  ** This function returns the name of the link to which this shape is
144  ** typically attached.
145  **
146  ** Use the function get_link() to get a pointer to the actual link to
147  ** which this shape is attached.
148  **
149  *b Returns:
150  **
151  ** name of recommended attachment link as C string
152  */
153  const char* get_recommended_attachment_link_name();
154 
155  /*l
156  *b Description:
157  **
158  ** This function returns how many LODs this shape has. This will be a
159  ** number between 1 and 7.
160  **
161  *b Returns:
162  **
163  ** number of LODs
164  */
165  int get_num_lods();
166 
167 #ifdef CPLUSPLUS_ONLY
168 
169  /*l
170  *b Description:
171  **
172  ** This function returns the LOD ranges of this shape. The returned
173  ** pointer points to an array of eight floats, which represent ranges
174  ** in meters at which LODs should be shown.
175  **
176  *b Returns:
177  **
178  ** LOD ranges
179  **
180  *b Only Callable From C++
181  */
182  float* get_lod_ranges();
183 
184 #endif
185 
186  /*l
187  *b Description:
188  **
189  ** This function returns the most recent lod setting as set by
190  ** set_graphics_lod(), or as set by
191  ** diguyCharacter::set_graphics_lod().
192  **
193  *b Returns:
194  **
195  ** LOD index; integer from 1 to get_num_lods()
196  */
197  int get_graphics_lod();
198 
199  /*l
200  *b Description:
201  **
202  ** This function returns the filename of the geometry file from which
203  ** the shape is read for a specific LOD.
204  **
205  *b Arguments:
206  **
207  *a lod - level of detail; a number between 1 and get_num_lods()
208  **
209  *b Returns:
210  **
211  ** geometry filename as C string
212  */
213  const char* get_shape_set_filename_for_lod(int lod);
214 
215  /*l
216  *b Description:
217  **
218  ** This function returns the number of low-level geometry meshes that
219  ** comprise this shape.
220  **
221  *b Arguments:
222  **
223  *a lod - level of detail; a number between 1 and get_num_lods()
224  **
225  *b Returns:
226  **
227  ** number of meshes in this shape
228  */
229  int get_num_meshes(int lod);
230 
231  /*l
232  *b Description:
233  **
234  ** This function returns a pointer to one of the low-level geometry
235  ** mesh objects that comprise this shape.
236  **
237  *b Arguments:
238  **
239  *a index - index of mesh; a number between 0 and get_num_meshes() - 1
240  *a lod - level of detail; a number between 1 and get_num_lods()
241  **
242  *b Returns:
243  **
244  ** pointer to object of type diguyGraphicsMesh; NULL on error
245  */
246  diguyGraphicsMesh* get_mesh_at_index_for_lod(int index, int lod);
247 
248  /*l
249  *b Description:
250  **
251  ** This function returns a pointer to the link to which this shape is
252  ** actually attached.
253  **
254  *b Arguments:
255  **
256  *a index - index of mesh; a number between 0 and get_num_meshes() - 1
257  *a lod - level of detail; a number between 1 and get_num_lods()
258  **
259  *b Returns:
260  **
261  ** pointer to object of type diguyGraphicsMesh; NULL on error
262  */
263  diguyGraphicsLink* get_link();
264 
265  /*l
266  *b Description:
267  **
268  ** This function returns the name of the DI-Guy motion data variable
269  ** that controls whether this shape should be visible.
270  **
271  ** The returned pointer will be NULL if there is no associated
272  ** variable.
273  **
274  *b Returns:
275  **
276  ** name of the variable; NULL if there is no variable
277  */
278  const char* get_switch_var_name();
279 
280  /*l
281  *b Description:
282  **
283  ** This function returns the value of the DI-Guy motion data variable
284  ** for which the shape should be visible.
285  **
286  ** Note that the variable in the motion data is a float, but gets cast
287  ** to an integer and compared against this number during shape
288  ** updates.
289  **
290  *b Returns:
291  **
292  ** number representing value for which shape should be visible
293  */
294  int get_switch_value();
295 
296  /*l
297  *b Description:
298  **
299  ** This function returns whether this shape should currently be hidden
300  ** or shown, based on the value of the shape's switch variable (if
301  ** any).
302  **
303  *b Returns:
304  **
305  ** 1 if shape should be hidden, 0 if not
306  */
307  int get_is_hidden();
308 
309  /*l
310  *b Description:
311  **
312  ** This function returns the geometry file from which geometry for the
313  ** shape was read. Each LOD of the shape may potentially come from a
314  ** different file.
315  **
316  ** Note that if a diguyGraphicsFile create function has not been
317  ** registered with a call to diguy_graphics_set_file_create_func(),
318  ** this function will return NULL.
319  **
320  *b Arguments:
321  **
322  *a lod - level of detail; a number between 1 and get_num_lods()
323  **
324  *b Returns:
325  **
326  ** object of type diguyGraphicsFile
327  */
328  diguyGraphicsFile* get_diguy_graphics_file(int lod);
329 
330 #ifdef CPLUSPLUS_ONLY
331 
332  /*l
333  *b Description:
334  **
335  ** This function returns a pointer to an object that represents the
336  ** geometry for the shape. The returned object is an object that has
337  ** been returned by a previous call to diguyGraphicsFile::find_part(),
338  ** and can be safely cast to the type of object that has been so
339  ** returned.
340  **
341  ** Note that if a diguyGraphicsFile create function has not been
342  ** registered with a call to diguy_graphics_set_file_create_func(),
343  ** this function will return NULL.
344  **
345  *b Arguments:
346  **
347  *a lod - level of detail; a number between 1 and get_num_lods()
348  **
349  *b Returns:
350  **
351  ** generic object which must be cast appropriately
352  **
353  *b Only Callable From C++
354  */
355  void* get_diguy_graphics_file_part(int lod);
356 
357 #endif
358 
359  /*l
360  *b Description:
361  **
362  ** Some shapes have meshes that have multiple selectable graphics
363  ** states, including materials and textures. This function returns
364  ** the value that specifies which graphics state to use for meshes of
365  ** this shape.
366  **
367  ** This is different than get_switch_value(), which returns the value
368  ** of the switch that controls whether or not meshes of this state are
369  ** shown.
370  **
371  *b Returns:
372  **
373  ** value of state switch; -1 if there is no state switch
374  */
375  int get_graphics_state_switch_index();
376 
377  /*l
378  *b Description:
379  **
380  ** Returns the number of switched graphics states available to this
381  ** shape. See get_graphics_state_switch_index().
382  **
383  *b Returns:
384  **
385  ** number of switched graphics states
386  */
387  int get_num_switched_graphics_states();
388 
389  /*l
390  *b Description:
391  **
392  ** Returns the graphics state associated with the passed switch value.
393  **
394  *b Returns:
395  **
396  ** pointer to type diguyGraphicsState
397  */
398  diguyGraphicsState* get_switched_graphics_state(int switch_value = -1);
399 
400  /*l
401  *b Description:
402  **
403  ** Returns in the passed pointers the unique color of this shape. All
404  ** shapes in a DI-Guy appearance are assigned a unique RGB color that
405  ** can be used in pick/selection operations.
406  **
407  ** Also see diguyScenario::map_color_to_impact().
408  **
409  ** See programming_examples/diguy_graphics_api/ogl_examples/intersection_test
410  ** for an example of its usage.
411  **
412  *b Returns:
413  **
414  ** 0 on success, -1 on failure
415  */
416  int get_unique_color(unsigned char* r,
417  unsigned char* g,
418  unsigned char* b);
419 
420  /*l
421  *b Description:
422  **
423  ** This function identifies if this shape has skinned data. Scene
424  ** graph renderers will need to know this in the build phase to help
425  ** set up the matrix data shader functionality.
426  **
427  *b Returns:
428  **
429  ** 1 if contains at lease one file with skinned data, 0 if not
430  */
431  int get_contains_skinned_file();
432 
434  /*l
435  *b Description:
436  **
437  ** By default DI-Guy provides three 4 float uniforms at the shape
438  ** level that can be used by end users to customize the appearance of
439  ** characters via shaders and misc textures. You can see a
440  ** demonstration of this in the Exface_sales_demo.dss file where an
441  ** additional texture is used. The uniforms are named:
442  **
443  *- -"ufrm_blood_color"
444  *- -"ufrm_grime_color"
445  *- -"ufrm_glow_color"
446  **
447  *b Example:
448  **
449  *e local character = this_scenario:get_character_at_index(0);
450  *e local link = character:get_link_at_index(0);
451  *e local shape = link:find_shape_by_class_type("head");
452  *e shape:set_material_parameter_4f("ufrm_blood_color",1,.1,.1,.5, 1);
453  */
454  int set_material_parameter_4f(const char* parameter_name,
455  float x, float y, float z, float w,
456  float blend_time = 0.0);
457 
458  /*l
459  *b Description:
460  **
461  ** Allow access to the current values of a material parameter, accounting
462  ** for value blending. Returns -1 if the parameter can't be found.
463  */
464  int get_material_parameter_4f(const char* parameter_name,
465  float* x, float* y, float* z, float* w);
466 
467  /*l
468  *b Description:
469  **
470  ** Returns a char * of length get_variation_texture_size() that represents
471  ** the pixels in a unique per shape texture. Typically a Retained mode
472  ** renderer would need to use this to load a state node with the texture
473  ** see diguyOsgGraphicsShape.cpp for an example. For an immediate mode
474  ** renderer we push the texture to the object via update_variation_texture()
475  */
476  unsigned char * get_variation_texture();
477 
479  int get_variation_texture_size();
480 
482  int get_num_variations();
483 
485  const char * get_variation_name(int variation_index);
486 
488  int set_variation_index(int variation_index);
489 
491  int get_has_custom_variation();
492 
494  int get_num_variation_components();
495 
497  const char * get_variation_component_name(int index);
498 
500  int get_variation_component_index(const char * name);
501 
504  int set_variation_component_value(int index, float color_shift_r, float color_shift_g, float color_shift_b);
505 
507  int set_state_switch_index(int index);
508 
509 #ifdef CPLUSPLUS_ONLY
510 
511  /*l
512  *b Description:
513  **
514  ** This function is typically called by scene graph renderers as part
515  ** of diguyGraphicsShape::update(). Scene graph renderers should
516  ** queue up this data to be sent to the graphics card at the
517  ** appropriate time.
518  **
519  ** Note that the format of the data in mat_data will be affected by
520  ** the bdiGraphicsInitGraphicsAPI variable transpose_shader_matrices
521  ** value.
522  **
523  *b Callable From:
524  **
525  *- C++
526  */
527  int get_shader_matrix_data(int* num_matrixes, const float** matrix_data);
528 
529 #endif
530 
531 
532 /*****************************************************************************/
544 #ifdef CPLUSPLUS_ONLY
545 
546  /*l
547  *b Description:
548  **
549  ** This function will be called by DI-Guy when it is time for
550  ** renderer-specific shape objects to be created. All information
551  ** necessary to build the shape should be available via the Accessor
552  ** Functions above when this function is called.
553  **
554  ** The build() function for the link to which a shape is attached
555  ** will be called before the shape's build() function.
556  **
557  *i Immediate Mode:
558  **
559  ** Immediate mode renderers can override this function, to create a
560  ** pre-compiled object that expedites the draw(). Display lists in
561  ** OpenGL are an example of this.
562  **
563  *i Scene Graph:
564  **
565  ** Scene graph renderers usually do override this function, to create
566  ** scene graph nodes that will hold geometry nodes of meshes attached
567  ** to the shape.
568  **
569  ** The following nodes are typically created:
570  **
571  *- - a switch node to control showing and hiding of the shape
572  *- - an LOD node to control which meshes are shown due to
573  *- LOD calculations
574  *- - a geometry parent or group-type object to which mesh
575  *- nodes can be attached
576  **
577  ** The scene graph nodes created by this function should be attached
578  ** to the nodes of the link to which the shape is attached. Use the
579  ** get_link() function to get a pointer to the link.
580  **
581  ** In addition, the scene graph objects of meshes attached to the
582  ** shape should be retrieved and attached to the shape's nodes. Use
583  ** the get_mesh_at_index_for_lod() function to get pointers to the
584  ** meshes.
585  **
586  *b Callable From:
587  **
588  *- - N/A (automatically called by DI-Guy Graphics API during
589  *- the Build Stage)
590  */
591  virtual void build();
592 
593  /*l
594  *b Description:
595  **
596  ** This function will be called by DI-Guy when it is time for the
597  ** renderer-specific shape objects created during the build() call to
598  ** be destroyed.
599  **
600  ** The unbuild() function for the shape will be called before the
601  ** unbuild() function of the link to which the shape is attached.
602  **
603  *i Immediate Mode:
604  **
605  ** Scene graph renderers can override this function, to destroy the
606  ** scene graph nodes created by build().
607  **
608  *i Scene Graph:
609  **
610  ** Scene graph renderers usually do override this function, to
611  ** destroy the scene graph nodes created by build().
612  **
613  *b Callable From:
614  **
615  *- - N/A (automatically called by DI-Guy Graphics API during
616  *- the Unbuild Stage)
617  */
618  virtual void unbuild();
619 
620  /*l
621  *b Description:
622  **
623  ** This function will be called by DI-Guy when it is time for
624  ** renderer-specific shape objects created during the build() call to
625  ** be updated with new data.
626  **
627  ** Shape updates control whether the shape is visible based on motion
628  ** data. The DI-Guy Graphics software looks at the switch value and
629  ** calls show() or hide() as appropriate, so it is likely that this
630  ** function does not need to be overridden in immediate mode.
631  **
632  ** The update() function for the link to which a shape is attached
633  ** will be called before the shape's update() function.
634  **
635  *i Immediate Mode:
636  **
637  ** Immediate mode renderers usually do not override this function.
638  **
639  *i Scene Graph:
640  **
641  ** Scene graph renderers should override this function if they are
642  ** supporting skinned characters. Each skinned shape can potentially
643  ** have different uniforms that need to be sent to the video card; see
644  ** get_shader_matrix_data().
645  **
646  *b Callable From:
647  **
648  *- - N/A (automatically called by DI-Guy Graphics API during
649  *- Update Stage)
650  */
651  virtual void update();
652 
653  /*l
654  *b Description:
655  **
656  ** This function will be called by DI-Guy when the shape should be
657  ** shown, typically due to a change in the motion data that controls
658  ** the switch. See get_switch_var_name() and get_switch_value().
659  **
660  *i Immediate Mode:
661  **
662  ** Immediate mode renderers usually do not override this function.
663  ** DI-Guy does not call the draw() function of hidden shapes.
664  **
665  *i Scene Graph:
666  **
667  ** Scene graph renderers usually do override this function, to update
668  ** the state of the switch node created during the build() call.
669  **
670  *b Callable From:
671  **
672  *- - N/A (automatically called by DI-Guy Graphics API during
673  *- Update Stage)
674  */
675  virtual void show();
676 
677  /*l
678  *b Description:
679  **
680  ** This function will be called by DI-Guy when the shape should be
681  ** hidden, typically due to a change in the motion data that controls
682  ** the switch. See get_switch_var_name() and get_switch_value().
683  **
684  *i Immediate Mode:
685  **
686  ** Immediate mode renderers usually do not override this function.
687  ** DI-Guy does not call the draw() function of hidden shapes.
688  **
689  *i Scene Graph:
690  **
691  ** Scene graph renderers usually do override this function, to update
692  ** the state of the switch node created during the build() call.
693  **
694  *b Callable From:
695  **
696  *- - N/A (automatically called by DI-Guy Graphics API during
697  *- Update Stage)
698  */
699  virtual void hide();
700 
701  // TODO MarcM Documentation
702  virtual void instancing_state_changed(int val);
703 
704  /*l
705  *b Description:
706  **
707  ** This function will be called by DI-Guy when it is time for the
708  ** geometry of this shape to be drawn.
709  **
710  *i Immediate Mode:
711  **
712  ** Immediate mode renderers usually do not override this function.
713  ** The actual draw calls happen in diguyGraphicsMesh::draw() calls.
714  **
715  *i Scene Graph:
716  **
717  ** Scene graph renderers usually do not override this function;
718  ** drawing is handled automatically by scene graphs.
719  **
720  *b Callable From:
721  **
722  *- - N/A (automatically called by DI-Guy Graphics API during
723  *- Draw Stage)
724  */
725  virtual void draw(int lod);
726 
727  /*l
728  *b Description:
729  **
730  ** This function will be called by DI-Guy when the LOD ranges of this
731  ** shape need to be updated after the shape has initially been built
732  ** in the Build Stage.
733  **
734  *b Arguments:
735  **
736  *a lod_ranges - new lod ranges for this shape
737  **
738  ** See diguyScenario::set_default_lod_ranges() for a description of
739  ** what will be in the lod_ranges argument.
740  **
741  *i Immediate Mode:
742  **
743  ** Immediate mode renderers usually do not override this function.
744  ** Instead, they use the lod passed into the draw() function.
745  **
746  *i Scene Graph:
747  **
748  ** Scene graph renderers can override this function, to update the
749  ** ranges of LOD nodes created in the Build Stage, if any.
750  **
751  ** If there were LOD-type nodes created in the Build Stage, their
752  ** ranges should be updated based on the passed values.
753  **
754  ** If no LOD-type nodes were created in the Build Stage, this
755  ** function should have no effect.
756  **
757  ** Typically only one of set_graphics_lod_ranges() or
758  ** set_graphics_lod() is implemented.
759  **
760  *b Callable From:
761  **
762  *- - N/A (automatically called by DI-Guy Graphics API when the
763  *- DI-Guy API function diguyCharacter::set_lod_ranges() is
764  *- called)
765  */
766  virtual void set_graphics_lod_ranges(float* ranges);
767 
768  /*l
769  *b Description:
770  **
771  ** This function will be called by DI-Guy when the LOD of this link
772  ** is "manually" set by a diguyCharacter::set_graphics_lod() function
773  ** call.
774  **
775  *i Immediate Mode:
776  **
777  ** Immediate mode renderers usually do not override this function.
778  ** Instead, they use the lod passed into the draw() function.
779  **
780  *i Scene Graph:
781  **
782  ** Scene graph renderers sometimes override this function, to update
783  ** the state of switch nodes created in the Build Stage.
784  **
785  ** Typically only one of set_graphics_lod_ranges() or
786  ** set_graphics_lod() is implemented.
787  **
788  *b Callable From:
789  **
790  *- - N/A (automatically called by DI-Guy Graphics API when the
791  *- DI-Guy API function diguyCharacter::set_graphics_lod() is
792  *- called)
793  */
794  virtual void set_graphics_lod(int lod);
795 
796 
797  /*l
798  *b Description:
799  **
800  ** Pushes a char * pixel buffer of length num_pixels that represents
801  ** the unique per shape texture. Typically a Immediate mode renderer
802  ** would need to use this to create or update a texture
803  ** see diguyOglGraphicsShape.cpp for an example. For an retained mode
804  ** renderer we have get_variation_texture() as an accessor.
805  **
806  *b Callable From:
807  **
808  *- - N/A (automatically called by DI-Guy Graphics API during
809  *- Build Stage)
810  */
811  virtual void update_variation_texture(int num_pixels, unsigned char * pixel_data);
812 
813  /*l
814  *b Description:
815  **
816  ** Returns the unique color of the character links. All links in a
817  ** DI-Guy appearance are assigned a unique RGB color that can be used
818  ** in pick/selection operations. The data returned in color_data is
819  ** an array of length num_colors with 4 floats per entry (r, g, b, a).
820  **
821  ** See programming_examples/diguy_graphics_api/osg_2_examples/intersection_test
822  ** for an example of its usage.
823  **
824  *b Returns:
825  **
826  ** 0 on success, -1 on failure
827  */
828  int get_bind_color_array(int* num_colors, const float** color_data);
829 
830 #endif
831 
832 #ifdef CPLUSPLUS_ONLY
833 
834  // EXPERIMENTAL
835  // FIXME: Added to access quats directly instead of shader matricies
836  // for Unity optimization. [Marc 11/22/2013]
837  int get_link_to_matrix_table(int* num_matrices, const float** lookup_data);
838 
839  int get_bone_index_from_link_index(int link_index);
840 
841 #endif
842 
844 /****************************************************************************/
845 /****************************************************************************/
857  int get_has_offset_translation();
858 
859  int get_offset_translation(float* tx, float* ty, float* tz);
860 
861  int get_has_offset_rotation();
862 
863  int get_offset_rotation(float* rz, float* rx, float* ry);
865  int get_has_offset_scale();
867  int get_offset_scale(float* sx, float* sy, float* sz);
868 
869 /****************************************************************************/
870 /****************************************************************************/
871 
876 #ifdef CPLUSPLUS_ONLY
877 
878  bdiShape* get_scripted_object() {return m_scripted_object;}
879 
880 protected:
881 
882  /*l
883  ** A protected constructor. Constructors are called automatically
884  ** by DI-Guy.
885  */
886  diguyGraphicsShape(void* internal_data);
887 
888  /*l
889  ** A protected destructor. Destructors are called automatically
890  ** by DI-Guy.
891  */
892  virtual ~diguyGraphicsShape();
893 
894 private:
895 
896  /*l
897  ** A pointer to internal data.
898  */
899  bdiShape* m_scripted_object;
900 
901  friend class bdiShape;
902  friend class bdiGraphicsFactory;
903 
904 #endif
905 
906 };
907 
908 
909 #endif /* __diguyGraphicsShape_H */
910