naev 0.12.6
gltf.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6/* We use this file in utils/model-view-c to debug things. */
7#ifdef PACKAGE
8#define HAVE_NAEV
9#endif
10
11#include <stddef.h>
12
13#include "glad.h"
14
15#include "mat4.h"
16#include "vec3.h"
17#ifdef HAVE_NAEV
18#include "opengl_tex.h"
19#endif /* HAVE_NAEV */
20
21#define MAX_LIGHTS \
22 7
24
25typedef struct Texture {
26 GLuint tex;
27 GLuint texcoord;
28 GLfloat strength;
30#ifdef HAVE_NAEV
31 glTexture *gtex;
32#endif /* HAVE_NAEV */
33} Texture;
34
38typedef struct Material {
39 char *name;
40 int blend;
43 int unlit;
44 /* pbr_metallic_roughness */
53 GLfloat baseColour[4];
55 /* pbr_specular_glossiness */
56 /* Sheen. */
57 GLfloat sheen[3];
58 GLfloat sheen_roughness;
59 /* Clearcoat */
60 /*GLuint clearcoat_tex;
61 GLuint clearcoat_roughness_tex;
62 GLuint clearcoat_normal_tex; */
63 GLfloat clearcoat;
64 GLfloat clearcoat_roughness;
65 /* misc. */
66 Texture normal_tex;
67 Texture occlusion_tex;
68 Texture emissive_tex;
69 GLfloat emissiveFactor[3];
70 /* Custom Naev. */
71 // GLfloat waxiness;
72} Material;
73
77typedef struct MeshPrimitive {
78 size_t nidx;
79 GLuint vbo_idx;
80 GLuint vbo_pos;
81 GLuint vbo_nor;
82 GLuint vbo_tex0;
83 GLuint vbo_tex1;
86
90typedef struct Mesh {
93} Mesh;
94
100
105typedef struct Node {
106 char *name;
109 int mesh;
110 // int parent; /**< Parent node. */
111 size_t *children;
112 size_t nchildren;
113
114 GLfloat radius;
117
118 /* Animation data. */
122} Node;
123
124typedef enum AnimationInterpolation {
125 ANIM_INTER_LINEAR,
126 ANIM_INTER_STEP,
127} AnimationInterpolation;
128
129typedef enum AnimationType {
130 ANIM_TYPE_ROTATION,
131 ANIM_TYPE_TRANSLATION,
132 ANIM_TYPE_SCALE,
133} AnimationType;
134
135typedef struct AnimationSampler {
136 float *time;
137 GLfloat *data;
138 AnimationInterpolation interp;
139 size_t n;
140 size_t l;
141 size_t cur;
142 GLfloat max;
144
150
158
162typedef struct Scene {
163 char *name;
164 size_t *nodes;
165 size_t nnodes;
166} Scene;
167
168typedef struct GltfTrail {
169 char *generator;
171} GltfTrail;
172
173typedef struct GltfMount {
174 int id;
177} GltfMount;
178
182typedef struct GltfObject {
183 char *path;
185 size_t nmeshes;
187 size_t nnodes;
189 size_t nscenes;
191 size_t nmaterials;
193 size_t nanimations;
194 GLfloat radius;
195 /* Some useful default scenes. */
198 /* Useful things used for special cases. */
201 int loaded;
202} GltfObject;
203
207typedef struct Light {
208 int sun;
209 /* left(-)/right(+), down(-)/up(+), forward(-)/back(+) */
210 vec3
213 double intensity;
215} Light;
216
217typedef struct Lighting {
218 double ambient_r, ambient_g, ambient_b;
219 Light lights[MAX_LIGHTS];
222 double intensity;
223} Lighting;
224extern const Lighting
225 L_default_const;
226extern const Lighting L_store_const;
227extern Lighting L_default;
228
229/* Framework itself. */
230int gltf_init( void );
231void gltf_exit( void );
232
233/* Loading and freeing. */
234GltfObject *gltf_loadFromFile( const char *filename );
235void gltf_free( GltfObject *obj );
236
237/* Rendering and updating. */
238void gltf_render( GLuint fb, GltfObject *obj, const mat4 *H, GLfloat time,
239 double size );
240void gltf_renderScene( GLuint fb, GltfObject *obj, int scene, const mat4 *H,
241 GLfloat time, double size, const Lighting *L );
242
243/* Lighting. */
244void gltf_lightReset( void );
245int gltf_lightSet( int idx, const Light *L );
246void gltf_lightAmbient( double r, double g, double b );
247void gltf_lightAmbientGet( double *r, double *g, double *b );
248void gltf_lightIntensity( double strength );
249double gltf_lightIntensityGet( void );
250void gltf_lightTransform( Lighting *L, const mat4 *H );
251
252/* Misc functions. */
253GLuint gltf_shadowmap( int light );
Node * target
Definition gltf.h:147
AnimationSampler * sampler
Definition gltf.h:148
AnimationType type
Definition gltf.h:146
GLfloat max
Definition gltf.h:142
size_t cur
Definition gltf.h:141
float * time
Definition gltf.h:136
AnimationInterpolation interp
Definition gltf.h:138
GLfloat * data
Definition gltf.h:137
char * name
Definition gltf.h:152
AnimationChannel * channels
Definition gltf.h:155
size_t nsamplers
Definition gltf.h:154
AnimationSampler * samplers
Definition gltf.h:153
size_t nchannels
Definition gltf.h:156
int id
Definition gltf.h:174
vec3 pos
Definition gltf.h:176
Defines a complete object.
Definition gltf.h:182
int scene_body
Definition gltf.h:196
GltfMount * mounts
Definition gltf.h:200
size_t nscenes
Definition gltf.h:189
Material * materials
Definition gltf.h:190
size_t nmaterials
Definition gltf.h:191
Animation * animations
Definition gltf.h:192
int scene_engine
Definition gltf.h:197
Node * nodes
Definition gltf.h:186
char * path
Definition gltf.h:183
GLfloat radius
Definition gltf.h:194
Scene * scenes
Definition gltf.h:188
size_t nmeshes
Definition gltf.h:185
Mesh * meshes
Definition gltf.h:184
GltfTrail * trails
Definition gltf.h:199
int loaded
Definition gltf.h:201
size_t nanimations
Definition gltf.h:193
size_t nnodes
Definition gltf.h:187
char * generator
Definition gltf.h:169
vec3 pos
Definition gltf.h:170
Simple point/sun light model.
Definition gltf.h:207
vec3 pos
Definition gltf.h:211
double intensity
Definition gltf.h:213
int sun
Definition gltf.h:208
vec3 colour
Definition gltf.h:214
int nlights
Definition gltf.h:220
double ambient_b
Definition gltf.h:218
Light lights[MAX_LIGHTS]
Definition gltf.h:219
double intensity
Definition gltf.h:222
PBR Material of an object.
Definition gltf.h:38
int blend
Definition gltf.h:40
GLfloat roughnessFactor
Definition gltf.h:51
int noshadows
Definition gltf.h:41
Texture metallic_tex
Definition gltf.h:46
int unlit
Definition gltf.h:43
int double_sided
Definition gltf.h:42
GLfloat baseColour[4]
Definition gltf.h:53
Texture baseColour_tex
Definition gltf.h:45
GLfloat metallicFactor
Definition gltf.h:49
char * name
Definition gltf.h:39
Represents the underlyig 3D data and associated material.
Definition gltf.h:77
GLuint vbo_tex1
Definition gltf.h:83
int material
Definition gltf.h:84
GLuint vbo_nor
Definition gltf.h:81
GLuint vbo_tex0
Definition gltf.h:82
size_t nidx
Definition gltf.h:78
GLuint vbo_idx
Definition gltf.h:79
GLuint vbo_pos
Definition gltf.h:80
Represents a mesh that can be made of multiple primitives.
Definition gltf.h:90
MeshPrimitive * primitives
Definition gltf.h:91
int nprimitives
Definition gltf.h:92
quat r
Definition gltf.h:97
vec3 t
Definition gltf.h:96
vec3 s
Definition gltf.h:98
Represents a node of an object. Each node can have multiple meshes and children nodes with an associa...
Definition gltf.h:105
char * name
Definition gltf.h:106
NodeTransform nt
Definition gltf.h:120
int has_anim
Definition gltf.h:119
GLfloat radius
Definition gltf.h:114
NodeTransform ntorig
Definition gltf.h:121
mat4 Horig
Definition gltf.h:108
size_t * children
Definition gltf.h:111
mat4 H
Definition gltf.h:107
int mesh
Definition gltf.h:109
vec3 aabb_min
Definition gltf.h:115
size_t nchildren
Definition gltf.h:112
vec3 aabb_max
Definition gltf.h:116
Represents a scene that can have multiple nodes.
Definition gltf.h:162
char * name
Definition gltf.h:163
size_t * nodes
Definition gltf.h:164
size_t nnodes
Definition gltf.h:165
Definition gltf.h:25
GLfloat strength
Definition gltf.h:28
GLuint tex
Definition gltf.h:26
GLuint texcoord
Definition gltf.h:27
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:43
Definition mat4.h:12
Definition mat4.h:20
Definition vec3.h:6