2021-11-30 21:29:18 -06:00
|
|
|
#ifndef MODEL_H
|
|
|
|
#define MODEL_H
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "HandmadeMath.h"
|
2023-11-30 10:47:59 -06:00
|
|
|
#include "transform.h"
|
2023-09-04 01:20:55 -05:00
|
|
|
#include "sokol/sokol_gfx.h"
|
2023-12-11 08:36:45 -06:00
|
|
|
#include "gameobject.h"
|
2024-04-26 16:04:31 -05:00
|
|
|
#include "anim.h"
|
|
|
|
#include "texture.h"
|
2023-09-04 01:20:55 -05:00
|
|
|
|
2024-05-02 13:52:28 -05:00
|
|
|
#define MAT_POS 0
|
|
|
|
#define MAT_UV 1
|
|
|
|
#define MAT_NORM 2
|
|
|
|
#define MAT_BONE 3
|
|
|
|
#define MAT_WEIGHT 4
|
|
|
|
#define MAT_COLOR 5
|
|
|
|
#define MAT_TAN 6
|
2024-05-06 21:59:22 -05:00
|
|
|
#define MAT_ANGLE 7
|
|
|
|
#define MAT_WH 8
|
|
|
|
#define MAT_ST 9
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-12-04 13:38:37 -06:00
|
|
|
typedef struct material {
|
2024-05-06 21:59:22 -05:00
|
|
|
struct texture *diffuse;
|
|
|
|
struct texture *metalrough;
|
2024-04-26 16:04:31 -05:00
|
|
|
float metal;
|
|
|
|
float rough;
|
2024-05-06 21:59:22 -05:00
|
|
|
struct texture *normal;
|
2024-04-26 16:04:31 -05:00
|
|
|
float nrm;
|
2024-05-06 21:59:22 -05:00
|
|
|
struct texture *occlusion;
|
2024-04-26 16:04:31 -05:00
|
|
|
float occl;
|
2024-05-06 21:59:22 -05:00
|
|
|
struct texture *emissive;
|
2024-04-26 16:04:31 -05:00
|
|
|
HMM_Vec3 emis;
|
2023-12-04 13:38:37 -06:00
|
|
|
} material;
|
|
|
|
|
|
|
|
struct model;
|
|
|
|
|
2024-04-26 16:04:31 -05:00
|
|
|
typedef struct primitive {
|
2024-04-30 10:32:27 -05:00
|
|
|
sg_buffer pos;
|
|
|
|
sg_buffer norm;
|
|
|
|
sg_buffer uv;
|
|
|
|
sg_buffer bone;
|
|
|
|
sg_buffer weight;
|
2024-05-02 13:52:28 -05:00
|
|
|
sg_buffer color;
|
2024-04-30 10:32:27 -05:00
|
|
|
sg_buffer idx;
|
|
|
|
material *mat;
|
2024-04-26 16:04:31 -05:00
|
|
|
uint32_t idx_count;
|
|
|
|
} primitive;
|
|
|
|
|
2023-11-03 08:31:06 -05:00
|
|
|
/* A single mesh */
|
2023-12-04 13:38:37 -06:00
|
|
|
typedef struct mesh {
|
2024-04-26 16:04:31 -05:00
|
|
|
primitive *primitives;
|
|
|
|
HMM_Mat4 *m;
|
2023-12-04 13:38:37 -06:00
|
|
|
} mesh;
|
2023-09-04 01:20:55 -05:00
|
|
|
|
2024-04-26 16:04:31 -05:00
|
|
|
typedef struct joint {
|
|
|
|
int me;
|
|
|
|
struct joint *children;
|
|
|
|
} joint_t;
|
|
|
|
|
|
|
|
typedef struct md5joint {
|
|
|
|
struct md5joint *parent;
|
|
|
|
HMM_Vec4 pos;
|
|
|
|
HMM_Quat rot;
|
|
|
|
HMM_Vec4 scale;
|
|
|
|
HMM_Mat4 t;
|
|
|
|
} md5joint;
|
|
|
|
|
|
|
|
typedef struct skin {
|
|
|
|
md5joint **joints;
|
|
|
|
HMM_Mat4 *invbind;
|
|
|
|
HMM_Mat4 binds[50]; /* binds = joint * invbind */
|
|
|
|
md5joint *root;
|
|
|
|
} skin;
|
|
|
|
|
2023-11-03 08:31:06 -05:00
|
|
|
/* A collection of meshes which create a full figure */
|
2023-12-04 13:38:37 -06:00
|
|
|
typedef struct model {
|
2023-05-12 13:22:05 -05:00
|
|
|
struct mesh *meshes;
|
2024-04-26 16:04:31 -05:00
|
|
|
md5joint *nodes;
|
2024-04-30 10:32:27 -05:00
|
|
|
material *mats;
|
2024-04-26 16:04:31 -05:00
|
|
|
skin skin;
|
|
|
|
struct animation anim;
|
2023-12-04 13:38:37 -06:00
|
|
|
} model;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
/* Make a Model struct */
|
2024-04-20 12:55:20 -05:00
|
|
|
struct model *model_make(const char *path);
|
|
|
|
void model_free(model *m);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2024-04-20 12:55:20 -05:00
|
|
|
void model_draw_go(model *m, gameobject *go, gameobject *cam);
|
2024-05-06 21:59:22 -05:00
|
|
|
sg_bindings primitive_bindings(primitive *p, JSValue pipe);
|
|
|
|
void primitive_gen_indices(primitive *prim);
|
|
|
|
int mat2type(int mat);
|
|
|
|
|
|
|
|
sg_buffer float_buffer(float *f, int v);
|
|
|
|
sg_buffer index_buffer(float *f, int verts);
|
|
|
|
sg_buffer texcoord_floats(float *f, int n);
|
|
|
|
sg_buffer par_idx_buffer(uint32_t *i, int v);
|
|
|
|
sg_buffer normal_floats(float *f, int n);
|
|
|
|
sg_buffer ubyten_buffer(float *f, int v);
|
|
|
|
sg_buffer ubyte_buffer(float *f, int v);
|
|
|
|
sg_buffer joint_buf(float *f, int v);
|
|
|
|
sg_buffer weight_buf(float *f, int v);
|
|
|
|
void primitive_free(primitive *prim);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2024-01-14 10:24:31 -06:00
|
|
|
material *material_make();
|
|
|
|
void material_free(material *mat);
|
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
#endif
|