naev
0.12.6
src
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
25
typedef
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
38
typedef
struct
Material
{
39
char
*
name
;
40
int
blend
;
41
int
noshadows
;
42
int
double_sided
;
43
int
unlit
;
44
/* pbr_metallic_roughness */
45
Texture
baseColour_tex
;
46
Texture
metallic_tex
;
49
GLfloat
metallicFactor
;
51
GLfloat
roughnessFactor
;
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
77
typedef
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
;
84
int
material
;
85
}
MeshPrimitive
;
86
90
typedef
struct
Mesh
{
91
MeshPrimitive
*
primitives
;
92
int
nprimitives
;
93
}
Mesh
;
94
95
typedef
struct
NodeTransform
{
96
vec3
t
;
97
quat
r
;
98
vec3
s
;
99
}
NodeTransform
;
100
105
typedef
struct
Node
{
106
char
*
name
;
107
mat4
H
;
108
mat4
Horig
;
109
int
mesh
;
110
// int parent; /**< Parent node. */
111
size_t
*
children
;
112
size_t
nchildren
;
113
114
GLfloat
radius
;
115
vec3
aabb_min
;
116
vec3
aabb_max
;
117
118
/* Animation data. */
119
int
has_anim
;
120
NodeTransform
nt
;
121
NodeTransform
ntorig
;
122
}
Node
;
123
124
typedef
enum
AnimationInterpolation {
125
ANIM_INTER_LINEAR,
126
ANIM_INTER_STEP,
127
} AnimationInterpolation;
128
129
typedef
enum
AnimationType {
130
ANIM_TYPE_ROTATION,
131
ANIM_TYPE_TRANSLATION,
132
ANIM_TYPE_SCALE,
133
} AnimationType;
134
135
typedef
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
;
143
}
AnimationSampler
;
144
145
typedef
struct
AnimationChannel
{
146
AnimationType
type
;
147
Node
*
target
;
148
AnimationSampler
*
sampler
;
149
}
AnimationChannel
;
150
151
typedef
struct
Animation
{
152
char
*
name
;
153
AnimationSampler
*
samplers
;
154
size_t
nsamplers
;
155
AnimationChannel
*
channels
;
156
size_t
nchannels
;
157
}
Animation
;
158
162
typedef
struct
Scene
{
163
char
*
name
;
164
size_t
*
nodes
;
165
size_t
nnodes
;
166
}
Scene
;
167
168
typedef
struct
GltfTrail
{
169
char
*
generator
;
170
vec3
pos
;
171
}
GltfTrail
;
172
173
typedef
struct
GltfMount
{
174
int
id
;
176
vec3
pos
;
177
}
GltfMount
;
178
182
typedef
struct
GltfObject
{
183
char
*
path
;
184
Mesh
*
meshes
;
185
size_t
nmeshes
;
186
Node
*
nodes
;
187
size_t
nnodes
;
188
Scene
*
scenes
;
189
size_t
nscenes
;
190
Material
*
materials
;
191
size_t
nmaterials
;
192
Animation
*
animations
;
193
size_t
nanimations
;
194
GLfloat
radius
;
195
/* Some useful default scenes. */
196
int
scene_body
;
197
int
scene_engine
;
198
/* Useful things used for special cases. */
199
GltfTrail
*
trails
;
200
GltfMount
*
mounts
;
201
int
loaded
;
202
}
GltfObject
;
203
207
typedef
struct
Light
{
208
int
sun
;
209
/* left(-)/right(+), down(-)/up(+), forward(-)/back(+) */
210
vec3
211
pos
;
213
double
intensity
;
214
vec3
colour
;
215
}
Light
;
216
217
typedef
struct
Lighting
{
218
double
ambient_r, ambient_g,
ambient_b
;
219
Light
lights
[MAX_LIGHTS];
220
int
nlights
;
222
double
intensity
;
223
}
Lighting
;
224
extern
const
Lighting
225
L_default_const;
226
extern
const
Lighting
L_store_const;
227
extern
Lighting
L_default;
228
229
/* Framework itself. */
230
int
gltf_init(
void
);
231
void
gltf_exit(
void
);
232
233
/* Loading and freeing. */
234
GltfObject
*gltf_loadFromFile(
const
char
*filename );
235
void
gltf_free(
GltfObject
*obj );
236
237
/* Rendering and updating. */
238
void
gltf_render( GLuint fb,
GltfObject
*obj,
const
mat4
*H, GLfloat time,
239
double
size );
240
void
gltf_renderScene( GLuint fb,
GltfObject
*obj,
int
scene,
const
mat4
*H,
241
GLfloat time,
double
size,
const
Lighting
*L );
242
243
/* Lighting. */
244
void
gltf_lightReset(
void
);
245
int
gltf_lightSet(
int
idx,
const
Light
*L );
246
void
gltf_lightAmbient(
double
r,
double
g,
double
b );
247
void
gltf_lightAmbientGet(
double
*r,
double
*g,
double
*b );
248
void
gltf_lightIntensity(
double
strength );
249
double
gltf_lightIntensityGet(
void
);
250
void
gltf_lightTransform(
Lighting
*L,
const
mat4
*H );
251
252
/* Misc functions. */
253
GLuint gltf_shadowmap(
int
light );
AnimationChannel
Definition
gltf.h:145
AnimationChannel::target
Node * target
Definition
gltf.h:147
AnimationChannel::sampler
AnimationSampler * sampler
Definition
gltf.h:148
AnimationChannel::type
AnimationType type
Definition
gltf.h:146
AnimationSampler
Definition
gltf.h:135
AnimationSampler::max
GLfloat max
Definition
gltf.h:142
AnimationSampler::l
size_t l
Definition
gltf.h:140
AnimationSampler::cur
size_t cur
Definition
gltf.h:141
AnimationSampler::time
float * time
Definition
gltf.h:136
AnimationSampler::n
size_t n
Definition
gltf.h:139
AnimationSampler::interp
AnimationInterpolation interp
Definition
gltf.h:138
AnimationSampler::data
GLfloat * data
Definition
gltf.h:137
Animation
Definition
gltf.h:151
Animation::name
char * name
Definition
gltf.h:152
Animation::channels
AnimationChannel * channels
Definition
gltf.h:155
Animation::nsamplers
size_t nsamplers
Definition
gltf.h:154
Animation::samplers
AnimationSampler * samplers
Definition
gltf.h:153
Animation::nchannels
size_t nchannels
Definition
gltf.h:156
GltfMount
Definition
gltf.h:173
GltfMount::id
int id
Definition
gltf.h:174
GltfMount::pos
vec3 pos
Definition
gltf.h:176
GltfObject
Defines a complete object.
Definition
gltf.h:182
GltfObject::scene_body
int scene_body
Definition
gltf.h:196
GltfObject::mounts
GltfMount * mounts
Definition
gltf.h:200
GltfObject::nscenes
size_t nscenes
Definition
gltf.h:189
GltfObject::materials
Material * materials
Definition
gltf.h:190
GltfObject::nmaterials
size_t nmaterials
Definition
gltf.h:191
GltfObject::animations
Animation * animations
Definition
gltf.h:192
GltfObject::scene_engine
int scene_engine
Definition
gltf.h:197
GltfObject::nodes
Node * nodes
Definition
gltf.h:186
GltfObject::path
char * path
Definition
gltf.h:183
GltfObject::radius
GLfloat radius
Definition
gltf.h:194
GltfObject::scenes
Scene * scenes
Definition
gltf.h:188
GltfObject::nmeshes
size_t nmeshes
Definition
gltf.h:185
GltfObject::meshes
Mesh * meshes
Definition
gltf.h:184
GltfObject::trails
GltfTrail * trails
Definition
gltf.h:199
GltfObject::loaded
int loaded
Definition
gltf.h:201
GltfObject::nanimations
size_t nanimations
Definition
gltf.h:193
GltfObject::nnodes
size_t nnodes
Definition
gltf.h:187
GltfTrail
Definition
gltf.h:168
GltfTrail::generator
char * generator
Definition
gltf.h:169
GltfTrail::pos
vec3 pos
Definition
gltf.h:170
Light
Simple point/sun light model.
Definition
gltf.h:207
Light::pos
vec3 pos
Definition
gltf.h:211
Light::intensity
double intensity
Definition
gltf.h:213
Light::sun
int sun
Definition
gltf.h:208
Light::colour
vec3 colour
Definition
gltf.h:214
Lighting
Definition
gltf.h:217
Lighting::nlights
int nlights
Definition
gltf.h:220
Lighting::ambient_b
double ambient_b
Definition
gltf.h:218
Lighting::lights
Light lights[MAX_LIGHTS]
Definition
gltf.h:219
Lighting::intensity
double intensity
Definition
gltf.h:222
Material
PBR Material of an object.
Definition
gltf.h:38
Material::blend
int blend
Definition
gltf.h:40
Material::roughnessFactor
GLfloat roughnessFactor
Definition
gltf.h:51
Material::noshadows
int noshadows
Definition
gltf.h:41
Material::metallic_tex
Texture metallic_tex
Definition
gltf.h:46
Material::unlit
int unlit
Definition
gltf.h:43
Material::double_sided
int double_sided
Definition
gltf.h:42
Material::baseColour
GLfloat baseColour[4]
Definition
gltf.h:53
Material::baseColour_tex
Texture baseColour_tex
Definition
gltf.h:45
Material::metallicFactor
GLfloat metallicFactor
Definition
gltf.h:49
Material::name
char * name
Definition
gltf.h:39
MeshPrimitive
Represents the underlyig 3D data and associated material.
Definition
gltf.h:77
MeshPrimitive::vbo_tex1
GLuint vbo_tex1
Definition
gltf.h:83
MeshPrimitive::material
int material
Definition
gltf.h:84
MeshPrimitive::vbo_nor
GLuint vbo_nor
Definition
gltf.h:81
MeshPrimitive::vbo_tex0
GLuint vbo_tex0
Definition
gltf.h:82
MeshPrimitive::nidx
size_t nidx
Definition
gltf.h:78
MeshPrimitive::vbo_idx
GLuint vbo_idx
Definition
gltf.h:79
MeshPrimitive::vbo_pos
GLuint vbo_pos
Definition
gltf.h:80
Mesh
Represents a mesh that can be made of multiple primitives.
Definition
gltf.h:90
Mesh::primitives
MeshPrimitive * primitives
Definition
gltf.h:91
Mesh::nprimitives
int nprimitives
Definition
gltf.h:92
NodeTransform
Definition
gltf.h:95
NodeTransform::r
quat r
Definition
gltf.h:97
NodeTransform::t
vec3 t
Definition
gltf.h:96
NodeTransform::s
vec3 s
Definition
gltf.h:98
Node
Represents a node of an object. Each node can have multiple meshes and children nodes with an associa...
Definition
gltf.h:105
Node::name
char * name
Definition
gltf.h:106
Node::nt
NodeTransform nt
Definition
gltf.h:120
Node::has_anim
int has_anim
Definition
gltf.h:119
Node::radius
GLfloat radius
Definition
gltf.h:114
Node::ntorig
NodeTransform ntorig
Definition
gltf.h:121
Node::Horig
mat4 Horig
Definition
gltf.h:108
Node::children
size_t * children
Definition
gltf.h:111
Node::H
mat4 H
Definition
gltf.h:107
Node::mesh
int mesh
Definition
gltf.h:109
Node::aabb_min
vec3 aabb_min
Definition
gltf.h:115
Node::nchildren
size_t nchildren
Definition
gltf.h:112
Node::aabb_max
vec3 aabb_max
Definition
gltf.h:116
Scene
Represents a scene that can have multiple nodes.
Definition
gltf.h:162
Scene::name
char * name
Definition
gltf.h:163
Scene::nodes
size_t * nodes
Definition
gltf.h:164
Scene::nnodes
size_t nnodes
Definition
gltf.h:165
Texture
Definition
gltf.h:25
Texture::strength
GLfloat strength
Definition
gltf.h:28
Texture::tex
GLuint tex
Definition
gltf.h:26
Texture::texcoord
GLuint texcoord
Definition
gltf.h:27
glTexture
Abstraction for rendering sprite sheets.
Definition
opengl_tex.h:43
mat4
Definition
mat4.h:12
quat
Definition
mat4.h:20
vec3
Definition
vec3.h:6
Generated by
1.14.0