C++ SDK Reference  12.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diguyGraphicsMesh.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright (C) 1992-2013 Boston Dynamics
4  * ALL RIGHTS RESERVED.
5  *
6  * These coded instructions, statements, and computer programs
7  * contain unpublished proprietary information of Boston Dynamics
8  * and are protected by Copyright Laws of the United States.
9  * They may not be used, duplicated, or disclosed in any form, in
10  * whole or in part, without the prior written consent from Boston
11  * Dynamics.
12  *
13  * RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the government is subject
15  * to restrictions as set forth in FAR 52.227.19(c)(2) or
16  * subparagraph (c)(1)(ii) of the Rights in Technical Data and
17  * Computer Software clause at DFARS 252.227-7013 and/or in
18  * similar or successor clauses in the FAR, or the DOD or NASA
19  * FAR Supplement, or to subparagraphs (c)(1) and (c)(2) of the
20  * Commercial Computer Software--Restricted Rights at 48 CFR
21  * 52.227-19, as applicable. Unpublished-rights reserved under
22  * the Copyright Laws of the United States.
23  * Contractor/Manufacturer is:
24  * Boston Dynamics/78 Fourth Avenue/Waltham MA 02451.
25  */
26 
27 /*********************************************************************/
34 #ifndef __diguyGraphicsMesh_H
35 #define __diguyGraphicsMesh_H
36 
37 #ifdef SWIG
39 #else
40 #define CPLUSPLUS_ONLY
41 #endif
42 
43 #ifdef CPLUSPLUS_ONLY
44 #include <diguy_constants.h>
46 #include <declspec_diguy.h>
47 
48 class diguyGraphicsMeshInternalData;
49 class diguyGraphicsMesh;
52 class diguyGraphicsState;
53 
54 
55 #endif
56 
57 /****************************************************************************/
58 class BDI_DECLSPEC_diguy diguyGraphicsMesh
59 {
60 
61 public:
62 
63 /*****************************************************************************/
72  /*l
73  *b Description:
74  **
75  ** Returns the name of the mesh. This pointer will
76  ** never be NULL.
77  **
78  *b Returns:
79  **
80  ** name of the mesh
81  */
82  const char* get_name();
83 
84  /*l
85  *b Description:
86  **
87  ** All meshs are assigned a unique identifer (uid).
88  ** This function returns the uid of the mesh.
89  **
90  ** *Note*: uids will change between DI-Guy runs.
91  **
92  *b Returns:
93  **
94  ** unique identifier of the object
95  */
96  long get_uid();
97 
98  /*l
99  *b Description:
100  **
101  ** This function returns the graphics state with which faces in this
102  ** mesh should be drawn. Specific information about material and
103  ** texture can then be accessed from this object.
104  **
105  ** Some meshes may have multiple possible graphics states associated
106  ** with them. In effect this means that depending on a character's
107  ** appearance, different textures or material settings may be used.
108  **
109  ** Call get_num_switched_graphics_states() to get the number of
110  ** graphics states that are associated with this mesh.
111  **
112  ** This function is typically called during the Build stage for
113  ** scene graph renderers, when geoset/mesh objects are being
114  ** created and their graphics states set.
115  **
116  *b Returns:
117  **
118  ** object of type diguyGraphicsState; NULL on failure
119  */
120  diguyGraphicsState* get_state(int graphics_state_switch_index = 0);
121 
122  /*l
123  *b Description:
124  **
125  ** This function returns the last bound graphic state object this mesh
126  ** used. There should always be at least one. This can be used by
127  ** immediate mode renderers during draw calls to find out more about
128  ** the properties of the mesh.
129  **
130  ** See get_state() for more information on switched graphics states.
131  **
132  *b Returns:
133  **
134  ** object of type diguyGraphicsState; NULL on failure
135  */
136  diguyGraphicsState* get_current_graphics_state();
137 
138  /*l
139  *b Description:
140  **
141  ** This function returns the number of switched graphics states
142  ** this mesh has. There should always be at least one.
143  **
144  ** See get_state() for more information on switched graphics states.
145  **
146  *b Returns:
147  **
148  ** number of switched graphics states this mesh has
149  */
150  int get_num_switched_graphics_states();
151 
152  /*l
153  *b Description:
154  **
155  ** This function returns whether or not the mesh is "skinned".
156  **
157  ** The position of vertices in a skinned mesh are determined
158  ** at run-time by transforming them with multiple link transforms.
159  **
160  ** It is likely that some type of shader is required to render
161  ** the mesh correctly. The shader recommended for this mesh can be
162  ** obtained by calling get_shader_program().
163  **
164  ** Though they sound similar, skinned meshes and deformable meshes
165  ** are different. The vertices in a deformable mesh have already
166  ** been transformed when the draw() function is called; nothing
167  ** more needs to be done. The vertices in a skinned are not ready
168  ** to be drawn, as they must first be transformed by a shader.
169  **
170  *b Returns:
171  **
172  ** 1 if mesh is skinned, 0 if not, -1 on failure
173  */
174  int get_is_skinned_mesh();
175 
176  /*l
177  *b Description:
178  **
179  ** This function returns whether or not the mesh is deformable.
180  **
181  ** The position of vertices in a deformable mesh may shift from
182  ** frame to frame and therefore should not be put into a
183  ** renderer-specific object that cannot be updated. (For example,
184  ** vertex buffer objects in OpenGL.)
185  **
186  ** The position of vertices in a non-deformable, non-skinned mesh
187  ** remain fixed from frame to frame.
188  **
189  ** Though they sound similar, skinned meshes and deformable meshes
190  ** are different. The vertices in a deformable mesh have already
191  ** been transformed when the draw() function is called; nothing
192  ** more needs to be done. The vertices in a skinned mesh are not
193  ** ready to be drawn, as they must first be transformed by a
194  ** shader.
195  **
196  *b Returns:
197  **
198  ** 1 if mesh is deformable, 0 if not, -1 on failure
199  */
200  int get_is_deformable();
201 
202  /*l
203  *b Description:
204  **
205  ** This function frees most memory allocated by the DI-Guy geometry
206  ** loader for this object.
207  **
208  ** This function should only be called during or after the object's
209  ** build() function has been called. After it has been called, calls
210  ** to many accessor functions will fail.
211  */
212  void free_loader_memory();
213 
214 
215 /*****************************************************************************/
241 /*********************************************************************/
247  /*l
248  *b Description:
249  **
250  ** This function returns a pointer to the shader program designated
251  ** for this mesh, if any. Shader programs are shared objects usable
252  ** by many meshes.
253  **
254  *b Returns:
255  **
256  ** pointer to diguyGraphicsShaderProgram, or NULL if this mesh
257  ** does not have a shader specified
258  */
259  diguyGraphicsShaderProgram* get_shader_program();
260 
261  /*l
262  *b Description:
263  **
264  ** If this mesh has a shader program specified (see
265  ** get_shader_program()), this function returns a pointer to the
266  ** shader instance object specific to this mesh.
267  **
268  *b Returns:
269  **
270  ** pointer to diguyGraphicsShaderInstance, or NULL if this mesh
271  ** does not have a shader specified
272  */
273  diguyGraphicsShaderInstance* get_shader_instance();
274 
275 
276 /*********************************************************************/
282  /*l
283  *b Returns:
284  **
285  ** vertex format that describes the format of the data returned
286  ** by the get_vertex_buffer_data() function
287  */
288  diguyGraphicsVertexFormat get_vertex_format();
289 
290  /*l
291  *b Returns:
292  **
293  ** how many vertices this mesh has
294  */
295  int get_vertex_count();
296 
297  /*l
298  *b Returns:
299  **
300  ** size, in bytes, of the data buffer returned by
301  ** get_vertex_buffer_data()
302  */
303  int get_vertex_buffer_size();
304 
305 #ifdef CPLUSPLUS_ONLY
306 
307  /*l
308  *b Description:
309  **
310  ** This function returns a pointer to the raw vertex buffer data
311  ** of this mesh. The format of the data can be obtained by calling
312  ** get_vertex_format().
313  **
314  ** Type-correct pointers into the data can be obtained by calling
315  ** get_first_vertex(), get_first_normal(), etc.
316  **
317  *b Returns:
318  **
319  ** pointer to raw vertex buffer data
320  */
321  void* get_vertex_buffer_data();
322 
323  /*l
324  *b Description:
325  **
326  ** This function returns a pointer to vertex position data of the
327  ** first vertex in the raw vertex buffer data returned by
328  ** get_vertex_buffer_data().
329  **
330  ** The XYZ position of the first vertex is stored in the first three
331  ** values of the returned pointer. The XYZ positions of subsequent
332  ** vertices need to be obtained by consecutively adding the
333  ** vertex stride to this returned pointer, as returned by
334  ** get_vertex_stride().
335  **
336  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
337  ** sizeof(float), so be careful about pointer arithmetic.
338  **
339  ** This approach is also used for the first normal, texture indices,
340  ** link index, and link weight of the vertex data.
341  **
342  ** An alternative approach to getting a pointer to the first vertex
343  ** position is to use get_vertex_offset(). See that function for
344  ** more information.
345  **
346  *b Returns:
347  **
348  ** pointer to vertex position of first vertex in vertex buffer data
349  */
350  float* get_first_vertex();
351 
352  /*l
353  *b Description:
354  **
355  ** This function returns how many bytes the first vertex position
356  ** is into the raw vertex buffer data returned by
357  ** get_vertex_buffer_data().
358  **
359  ** The XYZ positions of subsequent vertices need to be obtained by
360  ** consecutively adding the vertex stride to this offset, as
361  ** returned by get_vertex_stride().
362  **
363  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
364  ** sizeof(float), so be careful about pointer arithmetic.
365  **
366  ** This approach is also used for the first normal, texture indices,
367  ** link index, and link weight offsets into the vertex data.
368  **
369  ** An alternative approach to getting a pointer to the first vertex
370  ** position is to use get_first_vertex() to get a type-correct
371  ** pointer.
372  **
373  *b Returns:
374  **
375  ** offset in bytes of the first vertex position in raw vertex buffer
376  ** data
377  */
378  int get_vertex_offset();
379 
380  /*l
381  *b Description:
382  **
383  ** This function returns how many bytes there are between each
384  ** vertex position in the raw data returned by
385  ** get_vertex_buffer_data().
386  **
387  ** See get_first_vertex() and get_vertex_offset() for more
388  ** information.
389  **
390  ** *NOTE*: this function returns a value in *bytes*, not
391  ** sizeof(float), so be careful about pointer arithmetic.
392  **
393  *b Returns:
394  **
395  ** stride in bytes between each vertex position in raw vertex buffer
396  ** data
397  */
398  int get_vertex_stride();
399 
400  /*l
401  *b Returns:
402  **
403  ** pointer to normal of first vertex in vertex buffer data; see
404  ** get_first_vertex() for more information
405  */
406  float* get_first_normal();
407 
408  /*l
409  *b Returns:
410  **
411  ** offset in bytes of the first normal in raw vertex buffer data;
412  ** see get_vertex_offset() for more information
413  */
414  int get_normal_offset();
415 
416  /*l
417  *b Returns:
418  **
419  ** stride in bytes between each normal in raw vertex buffer
420  ** data; see get_vertex_stride() for more information
421  */
422  int get_normal_stride();
423 
424  /*l
425  *b Returns:
426  **
427  ** pointer to texture indices of first vertex in vertex buffer data
428  */
429  float* get_first_texture_indices();
430 
431  /*l
432  *b Returns:
433  **
434  ** offset in bytes of the first texture indices in raw vertex buffer
435  ** data; see get_vertex_offset() for more information
436  */
437  int get_texture_indices_offset();
438 
439  /*l
440  *b Returns:
441  **
442  ** stride in bytes between each texture indices pair in raw vertex
443  ** buffer data; see get_vertex_stride() for more information
444  */
445  int get_texture_indices_stride();
446 
447  /*l
448  *b Returns:
449  **
450  ** pointer to link index of first vertex in vertex buffer data, in
451  ** float form
452  */
453  float* get_first_link_index();
454 
455  /*l
456  *b Returns:
457  **
458  ** offset in bytes of the first link index in raw vertex buffer data;
459  ** see get_vertex_offset() for more information
460  */
461  int get_link_index_offset();
462 
463  /*l
464  *b Returns:
465  **
466  ** stride in bytes between each link index in raw vertex buffer
467  ** data; see get_vertex_stride() for more information
468  */
469  int get_link_index_stride();
470 
471  /*l
472  *b Returns:
473  **
474  ** pointer to link weight of first vertex in vertex buffer data
475  */
476  float* get_first_link_weight();
477 
478  /*l
479  *b Returns:
480  **
481  ** offset in bytes of the first link offset in raw vertex buffer data;
482  ** see get_vertex_offset() for more information
483  */
484  int get_link_weight_offset();
485 
486  /*l
487  *b Returns:
488  **
489  ** stride in bytes between each link weight in raw vertex buffer data;
490  ** see get_vertex_stride() for more information
491  */
492  int get_link_weight_stride();
493 
494  /*l
495  *b Description:
496  **
497  ** Returns a pointer to the UV tangent and flip bit of first vertex in
498  ** the vertex buffer data.
499  **
500  ** There are 3 floats representing the tangent, and one for UV
501  ** mirroring. See
502  ** http://www.dhpoware.com/demos/glslNormalMapping.html for an outline
503  ** of how tangents are calculated. Binormals are calculated in the
504  ** vertex shader making their storage unnecessary. Tangents should
505  ** exist for all skinned/dae models.
506  **
507  ** See get_first_vertex() for more information about how to interpret
508  ** tangent pointers and strides.
509  */
510  float* get_first_tangent();
511 
512  /*l
513  *b Returns:
514  **
515  ** offset in bytes of the first tangent in raw vertex buffer data;
516  ** see get_vertex_offset() for more information
517  */
518  int get_tangent_offset();
519 
520  /*l
521  *b Returns:
522  **
523  ** stride in bytes between each tangent in raw vertex buffer data; see
524  ** get_vertex_stride() for more information
525  */
526  int get_tangent_stride();
527 
528 #endif
529 
530 
531  /*********************************************************************/
538  /*l
539  *b Returns:
540  **
541  ** index type used in data returned by the get_index_buffer_data()
542  ** function
543  */
544  diguyGraphicsIndexType get_index_type();
545 
546  /*l
547  *b Description:
548  **
549  ** This function returns how many indices there are in this mesh.
550  ** The number of triangles in this mesh can be derived by dividing
551  ** this value by 3.
552  **
553  ** Note that indices in index buffer data are different than the
554  ** indices contained in vertex buffer data. Index buffer indices
555  ** specify which *vertices* in vertex buffer data are used to create
556  ** polygons in a mesh (e.g., for the first triangle, use vertices 0,
557  ** 1, and 2), while indices stored in vertex buffer data specify
558  ** which *links* affect the final position of the vertex.
559  **
560  *b Returns:
561  **
562  ** number of indices in index buffer data returned by
563  ** get_index_buffer_data()
564  */
565  int get_index_count();
566 
567 #ifdef CPLUSPLUS_ONLY
568 
569  /*l
570  *b Returns:
571  **
572  ** size, in bytes, of the data buffer returned by
573  ** get_index_buffer_data()
574  */
575  int get_index_buffer_size();
576 
577  /*l
578  *b Description:
579  **
580  ** This function returns a pointer to the raw index buffer data of
581  ** this mesh. The format of the data can be obtained by calling
582  ** get_index_type().
583  **
584  *b Returns:
585  **
586  ** pointer to raw index buffer data
587  */
588  void* get_index_buffer_data();
589 
590 #endif
591 
592 
593 /*****************************************************************************/
605 #ifdef CPLUSPLUS_ONLY
606 
607  /*l
608  *b Description:
609  **
610  ** This function will be called by DI-Guy when it is time for a
611  ** renderer-specific mesh object to be created. All information
612  ** necessary to build the mesh should be available via the
613  ** Accessor Functions above when this function is called.
614  **
615  *i Immediate Mode:
616  **
617  ** Immediate mode renderers may override this function, to
618  ** create an object that may be invoked by draw().
619  **
620  *i Scene Graph:
621  **
622  ** Scene graph renderers usually do override this function, to
623  ** create a geometry object that gets associated with a
624  ** diguyGraphicsState object obtained by calling get_state().
625  **
626  *b Callable From:
627  **
628  *- - N/A (automatically called by DI-Guy Graphics API during
629  *- the Build Stage)
630  */
631  virtual void build();
632 
633  /*l
634  *b Description:
635  **
636  ** This function will be called by DI-Guy when it is time for a
637  ** renderer-specific mesh object to be destroyed.
638  **
639  *i Immediate Mode:
640  **
641  ** Immediate mode renderers may override this function, to
642  ** destroy any object that may have been created by build().
643  **
644  *i Scene Graph:
645  **
646  ** Scene graph renderers usually do override this function, to
647  ** destroy any object that may have been created by build().
648  **
649  *b Callable From:
650  **
651  *- - N/A (automatically called by DI-Guy Graphics API during
652  *- the Unbuild Stage)
653  */
654  virtual void unbuild();
655 
656  /*l
657  *b Description:
658  **
659  ** This function will be called by DI-Guy when the mesh should
660  ** be drawn. For scene graph renderers, most likely nothing
661  ** more needs to be done by this function.
662  **
663  *b Callable From:
664  **
665  *- - N/A (automatically called by DI-Guy Graphics API during
666  *- Draw Stage)
667  */
668  virtual void draw();
669 
670 #endif
671 
672 /****************************************************************************/
673 /*****************************************************************************/
684 /****************************************************************************/
685 /****************************************************************************/
686 
687 #ifdef CPLUSPLUS_ONLY
688 
689  /*l
690  *b Description:
691  **
692  ** Deprecated as of 10.0.0; use Geometry Data Accessor Functions
693  ** instead. This function can't provide data for all vertex formats
694  ** or index formats that DI-Guy now supports. This function assumes
695  ** that vertex buffer data is in array format, and that indices in
696  ** index buffer data are unsigned shorts. Data for skinned meshes
697  ** can't be represented with this function.
698  */
699  int get_vertex_info(int* num_vertices,
700  float** vertex_array,
701  float** normal_array,
702  float** texture_array,
703  int* index_array_size,
704  unsigned short** index_array);
705 
706 #endif
707 
708 
709 /****************************************************************************/
710 /****************************************************************************/
711 
716 #ifdef CPLUSPLUS_ONLY
717 
718  diguyGraphicsMeshInternalData* get_internal_data() {return m_internal_data;}
719 
720 protected:
722  /*l
723  ** A protected constructor. Constructors are called automatically
724  ** by DI-Guy.
725  */
726  diguyGraphicsMesh(void* internal_data);
728  /*l
729  ** A protected destructor. Destructors are called automatically
730  ** by DI-Guy.
731  */
732  virtual ~diguyGraphicsMesh();
733 
734 private:
735 
736  /*l
737  ** A pointer to internal data.
738  */
739  diguyGraphicsMeshInternalData* m_internal_data;
740 
741  friend class bdiGeometryGeosetMesh;
742  friend class bdiGeometryGeoset;
743  friend class bdiGeometryFactory;
744  friend class diguyGraphicsMeshArray;
745  friend class diguyGraphicsMeshInternalData;
746 
747 
748 #endif
749 };
750 
751 
752 #endif /* __diguyGraphicsMesh_H */
753