lovr/src/modules/data/modelData.h

228 lines
4.3 KiB
C
Raw Normal View History

2019-09-07 22:07:07 +00:00
#include "core/map.h"
2019-12-10 21:01:28 +00:00
#include "core/util.h"
2019-04-05 11:27:48 +00:00
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
2017-02-19 09:54:58 +00:00
#pragma once
2017-11-25 20:29:40 +00:00
#define MAX_BONES 48
2017-11-02 06:10:21 +00:00
2019-04-05 11:27:48 +00:00
struct Blob;
struct Image;
2019-04-05 11:27:48 +00:00
2018-09-26 00:10:09 +00:00
typedef enum {
ATTR_POSITION,
ATTR_NORMAL,
ATTR_TEXCOORD,
ATTR_COLOR,
ATTR_TANGENT,
ATTR_BONES,
ATTR_WEIGHTS,
MAX_DEFAULT_ATTRIBUTES
} DefaultAttribute;
typedef enum {
DRAW_POINTS,
DRAW_LINES,
DRAW_LINE_LOOP,
DRAW_LINE_STRIP,
DRAW_TRIANGLES,
DRAW_TRIANGLE_STRIP,
DRAW_TRIANGLE_FAN
} DrawMode;
2018-12-18 22:27:46 +00:00
typedef enum {
FILTER_NEAREST,
FILTER_BILINEAR,
FILTER_TRILINEAR
2018-12-18 22:27:46 +00:00
} FilterMode;
typedef struct {
FilterMode mode;
float anisotropy;
} TextureFilter;
typedef enum {
WRAP_CLAMP,
WRAP_REPEAT,
WRAP_MIRRORED_REPEAT
} WrapMode;
typedef struct {
WrapMode s;
WrapMode t;
WrapMode r;
} TextureWrap;
2018-12-17 22:40:07 +00:00
typedef enum {
SCALAR_METALNESS,
SCALAR_ROUGHNESS,
SCALAR_ALPHA_CUTOFF,
2018-12-17 22:40:07 +00:00
MAX_MATERIAL_SCALARS
} MaterialScalar;
typedef enum {
COLOR_DIFFUSE,
COLOR_EMISSIVE,
MAX_MATERIAL_COLORS
} MaterialColor;
typedef enum {
TEXTURE_DIFFUSE,
TEXTURE_EMISSIVE,
TEXTURE_METALNESS,
TEXTURE_ROUGHNESS,
TEXTURE_OCCLUSION,
TEXTURE_NORMAL,
MAX_MATERIAL_TEXTURES
} MaterialTexture;
2018-12-16 01:27:23 +00:00
typedef enum {
SMOOTH_STEP,
SMOOTH_LINEAR,
2019-01-23 06:40:34 +00:00
SMOOTH_CUBIC
2018-12-16 01:27:23 +00:00
} SmoothMode;
typedef enum {
PROP_TRANSLATION,
PROP_ROTATION,
PROP_SCALE,
} AnimationProperty;
2018-09-26 00:10:09 +00:00
typedef enum { I8, U8, I16, U16, I32, U32, F32 } AttributeType;
2019-01-27 22:29:06 +00:00
typedef union {
void* raw;
int8_t* i8;
uint8_t* u8;
int16_t* i16;
uint16_t* u16;
int32_t* i32;
uint32_t* u32;
float* f32;
} AttributeData;
2018-09-26 00:10:09 +00:00
typedef struct {
2019-01-16 03:25:51 +00:00
char* data;
size_t size;
size_t stride;
} ModelBuffer;
typedef struct {
2019-03-17 07:58:01 +00:00
uint32_t offset;
uint32_t buffer;
2019-01-16 03:25:51 +00:00
uint32_t count;
2018-09-26 00:10:09 +00:00
AttributeType type;
2019-05-21 03:35:07 +00:00
unsigned components : 3;
unsigned normalized : 1;
unsigned matrix : 1;
unsigned hasMin : 1;
unsigned hasMax : 1;
2019-01-16 03:25:51 +00:00
float min[4];
float max[4];
} ModelAttribute;
2018-09-26 00:10:09 +00:00
2018-12-16 01:27:23 +00:00
typedef struct {
2019-05-21 03:35:07 +00:00
uint32_t nodeIndex;
2018-12-16 01:27:23 +00:00
AnimationProperty property;
SmoothMode smoothing;
2019-05-21 03:35:07 +00:00
uint32_t keyframeCount;
2019-01-18 18:11:24 +00:00
float* times;
float* data;
2019-01-16 03:25:51 +00:00
} ModelAnimationChannel;
2018-12-16 01:27:23 +00:00
typedef struct {
2019-09-07 22:07:07 +00:00
const char* name;
2018-12-16 01:27:23 +00:00
ModelAnimationChannel* channels;
2019-05-21 03:35:07 +00:00
uint32_t channelCount;
2019-01-16 03:25:51 +00:00
float duration;
2018-12-16 01:27:23 +00:00
} ModelAnimation;
2018-12-17 22:40:07 +00:00
typedef struct {
2019-09-07 22:07:07 +00:00
const char* name;
2018-12-17 22:40:07 +00:00
float scalars[MAX_MATERIAL_SCALARS];
Color colors[MAX_MATERIAL_COLORS];
uint32_t images[MAX_MATERIAL_TEXTURES];
2019-01-31 02:56:17 +00:00
TextureFilter filters[MAX_MATERIAL_TEXTURES];
TextureWrap wraps[MAX_MATERIAL_TEXTURES];
2018-12-17 22:40:07 +00:00
} ModelMaterial;
2017-02-19 09:54:58 +00:00
typedef struct {
2019-01-16 03:25:51 +00:00
ModelAttribute* attributes[MAX_DEFAULT_ATTRIBUTES];
ModelAttribute* indices;
DrawMode mode;
2019-05-21 03:35:07 +00:00
uint32_t material;
} ModelPrimitive;
2017-02-19 09:54:58 +00:00
2018-09-26 00:10:09 +00:00
typedef struct {
2019-09-07 22:07:07 +00:00
const char* name;
union {
float matrix[16];
struct {
float translation[4];
float rotation[4];
float scale[4];
} properties;
} transform;
2018-09-26 00:10:09 +00:00
uint32_t* children;
uint32_t childCount;
2019-01-16 03:25:51 +00:00
uint32_t primitiveIndex;
uint32_t primitiveCount;
2019-05-21 03:35:07 +00:00
uint32_t skin;
2019-05-24 22:14:09 +00:00
bool matrix;
2017-02-19 09:54:58 +00:00
} ModelNode;
2018-12-16 01:27:23 +00:00
typedef struct {
uint32_t* joints;
uint32_t jointCount;
2019-01-16 03:25:51 +00:00
float* inverseBindMatrices;
2018-12-16 01:27:23 +00:00
} ModelSkin;
2019-04-05 11:58:29 +00:00
typedef struct ModelData {
2021-02-11 23:37:55 +00:00
uint32_t ref;
void* data;
2019-04-05 11:27:48 +00:00
struct Blob** blobs;
2019-01-16 03:25:51 +00:00
ModelBuffer* buffers;
struct Image** images;
2018-12-17 22:40:07 +00:00
ModelMaterial* materials;
2019-01-31 02:56:17 +00:00
ModelAttribute* attributes;
2018-12-16 01:27:23 +00:00
ModelPrimitive* primitives;
2019-01-31 02:56:17 +00:00
ModelAnimation* animations;
2018-12-16 01:27:23 +00:00
ModelSkin* skins;
2019-01-31 02:56:17 +00:00
ModelNode* nodes;
2019-05-21 03:35:07 +00:00
uint32_t rootNode;
uint32_t blobCount;
uint32_t bufferCount;
uint32_t imageCount;
2019-05-21 03:35:07 +00:00
uint32_t materialCount;
uint32_t attributeCount;
uint32_t primitiveCount;
uint32_t animationCount;
uint32_t skinCount;
uint32_t nodeCount;
ModelAnimationChannel* channels;
uint32_t* children;
uint32_t* joints;
2019-09-07 22:07:07 +00:00
char* chars;
2019-05-21 03:35:07 +00:00
uint32_t channelCount;
uint32_t childCount;
uint32_t jointCount;
2019-09-07 22:07:07 +00:00
uint32_t charCount;
2019-05-24 22:14:09 +00:00
2019-09-07 22:07:07 +00:00
map_t animationMap;
map_t materialMap;
map_t nodeMap;
2017-02-19 09:54:58 +00:00
} ModelData;
2016-10-29 22:18:10 +00:00
2019-12-08 09:46:54 +00:00
typedef void* ModelDataIO(const char* filename, size_t* bytesRead);
ModelData* lovrModelDataCreate(struct Blob* blob, ModelDataIO* io);
2019-12-08 09:46:54 +00:00
ModelData* lovrModelDataInitGltf(ModelData* model, struct Blob* blob, ModelDataIO* io);
ModelData* lovrModelDataInitObj(ModelData* model, struct Blob* blob, ModelDataIO* io);
ModelData* lovrModelDataInitStl(ModelData* model, struct Blob* blob, ModelDataIO* io);
2018-02-26 08:59:03 +00:00
void lovrModelDataDestroy(void* ref);
void lovrModelDataAllocate(ModelData* model);