DI-Guy SDK Documentation  13.9
diguyGraphicsMesh.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2025 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
6 /*********************************************************************/
13 #pragma once
14 
15 #ifdef SWIG
17 #else
18 #define CPLUSPLUS_ONLY
19 #endif
20 
21 #ifdef CPLUSPLUS_ONLY
22 #include <diguy_constants.h>
24 #include <declspec_diguy.h>
25 #include <stdlib.h>
26 
27 class diguyGraphicsMesh;
30 class diguyGraphicsState;
31 class diguyGraphicsShape;
32 class bdiGeometryMesh;
33 
34 #endif
35 
36 
39 struct BDI_DECLSPEC_diguy diguyDrawCallData
40 {
42 
45  diguyGraphicsState* m_state_override;
46 
48  diguyGraphicsShape* m_shape;
49 
51  int m_num_instances;
52 
54  bool m_instancing_draw;
55 
58  bool m_allow_instancing;
59 
61  bool m_skip_vao_bind;
62 
64  int m_render_pass;
65 
67  int m_lod;
68 
70  float m_lod_fraction;
71 
73  bool m_fade_lod;
74 
75  float m_blend_shape_weights[4];
76 
77  int m_blend_shape_indexes[4];
78 
81  float m_transform_matrix[16];
82 
83 };
84 
85 
86 /****************************************************************************/
90 class BDI_DECLSPEC_diguy diguyGraphicsMesh
91 {
92 public:
93 
94 /*****************************************************************************/
103  /*l
104  *b Description:
105  **
106  ** Returns the name of the mesh. This pointer will
107  ** never be NULL.
108  **
109  *b Returns:
110  **
111  ** name of the mesh
112  */
113  const char* get_name();
114 
115  /*l
116  *b Description:
117  **
118  ** All meshes are assigned a unique identifier (uid)
119  ** This function returns the uid of the mesh.
120  **
121  ** *Note*: uids will change between DI-Guy runs.
122  **
123  *b Returns:
124  **
125  ** unique identifier of the object
126  */
127  long get_uid();
128 
129  /*l
130  *b Description:
131  **
132  ** This function returns the graphics state with which faces in this
133  ** mesh should be drawn. Specific information about material and
134  ** texture can then be accessed from this object.
135  **
136  ** Some meshes may have multiple possible graphics states associated
137  ** with them. In effect this means that depending on a character's
138  ** appearance, different textures or material settings may be used.
139  **
140  ** Call get_num_switched_graphics_states() to get the number of
141  ** graphics states that are associated with this mesh.
142  **
143  ** This function is typically called during the Build stage for
144  ** scene graph renderers, when geoset/mesh objects are being
145  ** created and their graphics states set.
146  **
147  *b Returns:
148  **
149  ** object of type diguyGraphicsState; NULL on failure
150  */
152  diguyGraphicsState* get_state( int graphics_state_switch_index = 0 );
153  const diguyGraphicsState* get_state( int graphics_state_switch_index = 0 ) const;
155 
156 
157  /*l
158  *b Description:
159  **
160  ** This function returns the number of switched graphics states
161  ** this mesh has. There should always be at least one.
162  **
163  ** See get_state() for more information on switched graphics states.
164  **
165  *b Returns:
166  **
167  ** number of switched graphics states this mesh has
168  */
169  int get_num_switched_graphics_states() const;
170 
171  /*l
172  *b Description:
173  **
174  ** This function returns whether or not the mesh is "skinned".
175  **
176  ** The position of vertices in a skinned mesh are determined
177  ** at run-time by transforming them with multiple link transforms.
178  **
179  ** It is likely that some type of shader is required to render
180  ** the mesh correctly. The shader recommended for this mesh can be
181  ** obtained by calling get_shader_program().
182  **
183  ** Though they sound similar, skinned meshes and deformable meshes
184  ** are different. The vertices in a deformable mesh have already
185  ** been transformed when the draw() function is called; nothing
186  ** more needs to be done. The vertices in a skinned are not ready
187  ** to be drawn, as they must first be transformed by a shader.
188  **
189  *b Returns:
190  **
191  ** 1 if mesh is skinned, 0 if not, -1 on failure
192  */
193  int get_is_skinned_mesh();
194 
195  /*l
196  *b Description:
197  **
198  ** This function returns whether or not the mesh is actually a morph object.
199  ** the pos,normals and tangents will then just be the deltas from the base mesh.
200  */
201  int get_is_blend_shape();
202 
203  /*l
204  *b Description:
205  **
206  ** This function frees most memory allocated by the DI-Guy geometry
207  ** loader for this object.
208  **
209  ** This function should only be called during or after the object's
210  ** build() function has been called. After it has been called, calls
211  ** to many accessor functions will fail.
212  */
213  void free_loader_memory();
214 
215 
216 /*****************************************************************************/
242 /*********************************************************************/
248  /*l
249  *b Description:
250  **
251  ** This function returns a pointer to the shader program designated
252  ** for this mesh, if any. Shader programs are shared objects usable
253  ** by many meshes.
254  **
255  *b Returns:
256  **
257  ** pointer to diguyGraphicsShaderProgram, or NULL if this mesh
258  ** does not have a shader specified
259  */
260  diguyGraphicsShaderProgram* get_shader_program();
261 
262  /*l
263  *b Description:
264  **
265  ** If this mesh has a shader program specified (see
266  ** get_shader_program()), this function returns a pointer to the
267  ** shader instance object specific to this mesh.
268  **
269  *b Returns:
270  **
271  ** pointer to diguyGraphicsShaderInstance, or NULL if this mesh
272  ** does not have a shader specified
273  */
274  diguyGraphicsShaderInstance* get_shader_instance();
275 
276 
277 /*********************************************************************/
283  /*l
284  *b Returns:
285  **
286  ** vertex format that describes the format of the data returned
287  ** by the get_vertex_buffer_data() function
288  */
289  diguyGraphicsVertexFormat get_vertex_format();
290 
291  /*l
292  *b Returns:
293  **
294  ** how many vertices this mesh has
295  */
296  int get_vertex_count();
297 
298  /*l
299  *b Returns:
300  **
301  ** size, in bytes, of the data buffer returned by
302  ** get_vertex_buffer_data()
303  */
304  int get_vertex_buffer_size();
305 
306 
307  /*l
308  *b Returns:
309  **
310  ** Pointer to a blend shape mesh that represents the offsets from this mesh, currently
311  ** we only have 1 of these which we use to adjust the weight of the character.
312  */
313  diguyGraphicsMesh* get_blend_shape( int index );
314 
316  int get_num_blend_shapes();
317 
318 #ifdef CPLUSPLUS_ONLY
319 
321  float* get_data_as_blend_shape_verts();
322 
323 #endif
324 
327  int get_blend_shape_vertex_buffer_size();
328 
329 #ifdef CPLUSPLUS_ONLY
330 
331  /*l
332  *b Description:
333  **
334  ** This function returns a pointer to the raw vertex buffer data
335  ** of this mesh. The format of the data can be obtained by calling
336  ** get_vertex_format().
337  **
338  ** Type-correct pointers into the data can be obtained by calling
339  ** get_first_vertex(), get_first_normal(), etc.
340  **
341  *b Returns:
342  **
343  ** pointer to raw vertex buffer data
344  */
345  void* get_vertex_buffer_data();
346 
347  /*l
348  *b Description:
349  **
350  ** This function returns a pointer to vertex position data of the
351  ** first vertex in the raw vertex buffer data returned by
352  ** get_vertex_buffer_data().
353  **
354  ** The XYZ position of the first vertex is stored in the first three
355  ** values of the returned pointer. The XYZ positions of subsequent
356  ** vertices need to be obtained by consecutively adding the
357  ** vertex stride to this returned pointer, as returned by
358  ** get_vertex_stride().
359  **
360  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
361  ** sizeof(float), so be careful about pointer arithmetic.
362  **
363  ** This approach is also used for the first normal, texture indices,
364  ** link index, and link weight of the vertex data.
365  **
366  ** An alternative approach to getting a pointer to the first vertex
367  ** position is to use get_vertex_offset(). See that function for
368  ** more information.
369  **
370  *b Returns:
371  **
372  ** pointer to vertex position of first vertex in vertex buffer data
373  */
374  float* get_first_vertex();
375 
376  /*l
377  *b Description:
378  **
379  ** This function returns how many bytes the first vertex position
380  ** is into the raw vertex buffer data returned by
381  ** get_vertex_buffer_data().
382  **
383  ** The XYZ positions of subsequent vertices need to be obtained by
384  ** consecutively adding the vertex stride to this offset, as
385  ** returned by get_vertex_stride().
386  **
387  ** *NOTE*: get_vertex_stride() returns a value in *bytes*, not
388  ** sizeof(float), so be careful about pointer arithmetic.
389  **
390  ** This approach is also used for the first normal, texture indices,
391  ** link index, and link weight offsets into the vertex data.
392  **
393  ** An alternative approach to getting a pointer to the first vertex
394  ** position is to use get_first_vertex() to get a type-correct
395  ** pointer.
396  **
397  *b Returns:
398  **
399  ** offset in bytes of the first vertex position in raw vertex buffer
400  ** data
401  */
402  int get_vertex_offset();
403 
404  /*l
405  *b Description:
406  **
407  ** This function returns how many bytes there are between each
408  ** vertex position in the raw data returned by
409  ** get_vertex_buffer_data().
410  **
411  ** See get_first_vertex() and get_vertex_offset() for more
412  ** information.
413  **
414  ** *NOTE*: this function returns a value in *bytes*, not
415  ** sizeof(float), so be careful about pointer arithmetic.
416  **
417  *b Returns:
418  **
419  ** stride in bytes between each vertex position in raw vertex buffer
420  ** data
421  */
422  int get_vertex_stride();
423 
424  /*l
425  *b Returns:
426  **
427  ** pointer to normal of first vertex in vertex buffer data; see
428  ** get_first_vertex() for more information
429  */
430  float* get_first_normal();
431 
432  /*l
433  *b Returns:
434  **
435  ** offset in bytes of the first normal in raw vertex buffer data;
436  ** see get_vertex_offset() for more information
437  */
438  int get_normal_offset();
439 
440 
441  /*l
442  *b Returns:
443  **
444  ** pointer to texture indices of first vertex in vertex buffer data
445  */
446  float* get_first_texture_indices();
447 
448  /*l
449  *b Returns:
450  **
451  ** offset in bytes of the first texture indices in raw vertex buffer
452  ** data; see get_vertex_offset() for more information
453  */
454  int get_texture_indices_offset();
455 
456 
457  /*l
458  *b Returns:
459  **
460  ** pointer to link index of first vertex in vertex buffer data, in
461  ** float form
462  */
463  float* get_first_link_index();
464 
465  /*l
466  *b Returns:
467  **
468  ** offset in bytes of the first link index in raw vertex buffer data;
469  ** see get_vertex_offset() for more information
470  */
471  int get_link_index_offset();
472 
473 
474 
475  /*l
476  *b Returns:
477  **
478  ** pointer to link weight of first vertex in vertex buffer data
479  */
480  float* get_first_link_weight();
481 
482  /*l
483  *b Returns:
484  **
485  ** offset in bytes of the first link weight offset in raw vertex buffer data;
486  ** see get_vertex_offset() for more information
487  */
488  int get_link_weight_offset();
489 
490  /*l
491  *b Description:
492  **
493  ** Returns a pointer to the UV tangent and flip bit of first vertex in
494  ** the vertex buffer data.
495  **
496  ** There are 3 floats representing the tangent, and one for UV
497  ** mirroring. See
498  ** http://www.dhpoware.com/demos/glslNormalMapping.html for an outline
499  ** of how tangents are calculated. Binormals are calculated in the
500  ** vertex shader making their storage unnecessary. Tangents should
501  ** exist for all skinned/dae models.
502  **
503  ** See get_first_vertex() for more information about how to interpret
504  ** tangent pointers and strides.
505  */
506  float* get_first_tangent();
507 
508  /*l
509  *b Returns:
510  **
511  ** offset in bytes of the first tangent in raw vertex buffer data;
512  ** see get_vertex_offset() for more information
513  */
514  int get_tangent_offset();
515 
516 
517 #endif
518 
519 
520  /*********************************************************************/
527  /*l
528  *b Returns:
529  **
530  ** index type used in data returned by the get_index_buffer_data()
531  ** function
532  */
533  diguyGraphicsIndexType get_index_type();
534 
535  /*l
536  *b Description:
537  **
538  ** This function returns how many indices there are in this mesh.
539  ** The number of triangles in this mesh can be derived by dividing
540  ** this value by 3.
541  **
542  ** Note that indices in index buffer data are different than the
543  ** indices contained in vertex buffer data. Index buffer indices
544  ** specify which *vertices* in vertex buffer data are used to create
545  ** polygons in a mesh (e.g., for the first triangle, use vertices 0,
546  ** 1, and 2), while indices stored in vertex buffer data specify
547  ** which *links* affect the final position of the vertex.
548  **
549  *b Returns:
550  **
551  ** number of indices in index buffer data returned by
552  ** get_index_buffer_data()
553  */
554  int get_index_count();
555 
556 #ifdef CPLUSPLUS_ONLY
557 
558  /*l
559  *b Returns:
560  **
561  ** size, in bytes, of the data buffer returned by
562  ** get_index_buffer_data()
563  */
564  int get_index_buffer_size();
565 
566  /*l
567  *b Description:
568  **
569  ** This function returns a pointer to the raw index buffer data of
570  ** this mesh. The format of the data can be obtained by calling
571  ** get_index_type().
572  **
573  *b Returns:
574  **
575  ** pointer to raw index buffer data
576  */
577  void* get_index_buffer_data();
578 
579 #endif
580 
581 
582 /*****************************************************************************/
594 #ifdef CPLUSPLUS_ONLY
595 
596  /*l
597  *b Description:
598  **
599  ** This function will be called by DI-Guy when it is time for a
600  ** renderer-specific mesh object to be created. All information
601  ** necessary to build the mesh should be available via the
602  ** Accessor Functions above when this function is called.
603  **
604  *i Immediate Mode:
605  **
606  ** Immediate mode renderers may override this function, to
607  ** create an object that may be invoked by draw().
608  **
609  *i Scene Graph:
610  **
611  ** Scene graph renderers usually do override this function, to
612  ** create a geometry object that gets associated with a
613  ** diguyGraphicsState object obtained by calling get_state().
614  **
615  *b Callable From:
616  **
617  *- - N/A (automatically called by DI-Guy Graphics API during
618  *- the Build Stage)
619  */
620  virtual void build();
621 
622  /*l
623  *b Description:
624  **
625  ** This function will be called by DI-Guy when it is time for a
626  ** renderer-specific mesh object to be destroyed.
627  **
628  *i Immediate Mode:
629  **
630  ** Immediate mode renderers may override this function, to
631  ** destroy any object that may have been created by build().
632  **
633  *i Scene Graph:
634  **
635  ** Scene graph renderers usually do override this function, to
636  ** destroy any object that may have been created by build().
637  **
638  *b Callable From:
639  **
640  *- - N/A (automatically called by DI-Guy Graphics API during
641  *- the Unbuild Stage)
642  */
643  virtual void unbuild();
644 
645  /*l
646  *b Description:
647  **
648  ** This function will be called by DI-Guy when the mesh should
649  ** be drawn. For scene graph renderers, most likely nothing
650  ** more needs to be done by this function.
651  **
652  *b Callable From:
653  **
654  *- - N/A (automatically called by DI-Guy Graphics API during
655  *- Draw Stage)
656  */
657  virtual void draw( diguyDrawCallData* draw_data );
658 
659 #endif
660 
661 /****************************************************************************/
662 /*****************************************************************************/
673 /****************************************************************************/
674 /****************************************************************************/
675 
676  // This seems like a mistake in retrospect. Please let MaK support know if you needed
677  // it's functionality
678  /*l
679  *b Description:
680  **
681  ** This function returns the last bound graphic state object this mesh
682  ** used. There should always be at least one. This can be used by
683  ** immediate mode renderers during draw calls to find out more about
684  ** the properties of the mesh.
685  **
686  ** See get_state() for more information on switched graphics states.
687  **
688  *b Returns:
689  **
690  ** object of type diguyGraphicsState; NULL on failure
691  */
692  //diguyGraphicsState* get_current_graphics_state();
693 
694 /****************************************************************************/
695 /*****************************************************************************/
703  int get_bounding_box( float* bbox_min_x, float* bbox_min_y, float* bbox_min_z,
704  float* bbox_max_x, float* bbox_max_y, float* bbox_max_z );
706 /****************************************************************************/
707 /****************************************************************************/
708 
710  //virtual void draw_instance_group( int num_instances );
711 
714  int get_normal_stride() { return get_vertex_stride(); }
715  int get_texture_indices_stride() { return get_vertex_stride(); }
716  int get_tangent_stride() { return get_vertex_stride(); }
717  int get_link_weight_stride() { return get_vertex_stride(); }
718  int get_link_index_stride() { return get_vertex_stride(); }
719 
720  /*l
721  *b Description:
722  **
723  ** This function returns whether or not the mesh is deformable.
724  **
725  ** The position of vertices in a deformable mesh may shift from
726  ** frame to frame and therefore should not be put into a
727  ** renderer-specific object that cannot be updated. (For example,
728  ** vertex buffer objects in OpenGL.)
729  **
730  ** The position of vertices in a non-deformable, non-skinned mesh
731  ** remain fixed from frame to frame.
732  **
733  ** Though they sound similar, skinned meshes and deformable meshes
734  ** are different. The vertices in a deformable mesh have already
735  ** been transformed when the draw() function is called; nothing
736  ** more needs to be done. The vertices in a skinned mesh are not
737  ** ready to be drawn, as they must first be transformed by a
738  ** shader.
739  **
740  ** We don't currently ever have deformable meshes... and you'd
741  ** still need to stream them to the videocard.
742  **
743  *b Returns:
744  **
745  ** 1 if mesh is deformable, 0 if not, -1 on failure
746  */
747  int get_is_deformable();
748 
753 #ifdef CPLUSPLUS_ONLY
754 
755  bdiGeometryMesh* get_scripted_object() { return m_scripted_object; }
756 
757 protected:
758 
759  /*l
760  ** A protected constructor. Constructors are called automatically
761  ** by DI-Guy.
762  */
763  diguyGraphicsMesh( void* internal_data );
764 
765  /*l
766  ** A protected destructor. Destructors are called automatically
767  ** by DI-Guy.
768  */
769  virtual ~diguyGraphicsMesh();
770 
771 private:
772 
773  /*l
774  ** A pointer to internal data.
775  */
776  bdiGeometryMesh* m_scripted_object;
777 
778  friend class bdiGeometryGeosetMesh;
779  friend class bdiGeometryMesh;
780  friend class bdiGeometryFactory;
781  friend class diguyGraphicsMeshArray;
782 
783 #endif
784 
785 };
A class that represents the unique per-character shader object.
Definition: diguyGraphicsShaderInstance.h:54
A class that represents a shared material/textures combination.
Definition: diguyGraphicsState.h:44
A class that represents a shared texture.
Definition: diguyGraphicsTexture.h:124
A class that represents a shared mesh object.
Definition: diguyGraphicsMesh.h:87
diguyGraphicsIndexType
This enumeration lists the type that indices stored in index buffer data might have.
Definition: diguyGraphicsVertexFormats.h:118
A struct that represents the information that diguy puts together for an immediate mode draw call...
Definition: diguyGraphicsMesh.h:37
A class that represents the unique per-character non-shared mesh object. DI-Guy encapsulates its text...
Definition: diguyGraphicsShape.h:49
This class implements shader programs for use with DI-Guy character graphics.
Definition: diguyGraphicsShaderProgram.h:94
diguyGraphicsVertexFormat
This enumeration lists types of vertex data formats DI-Guy may use.
Definition: diguyGraphicsVertexFormats.h:80