Source

dark-hammer / include / engine / h3d-types.h

The branch '0.4.7' does not exist.
/***********************************************************************************
 * Copyright (c) 2012, Sepehr Taghdisian
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 *
 ***********************************************************************************/

/**
 * Note: every structure here should be 1-byte packed and using compiler variable primitives
 */

#ifndef H3D_TYPES_H_
#define H3D_TYPES_H_

#include "core/types.h"
#include "core/vec-math.h"
#include "core/color.h"
#include "gfx-input-types.h"
#include "core/prims.h"
#include "core/color.h"

#define H3D_SIGN	0x683364	/*h3d*/
#define H3D_VERSION	0x312e30	/*1.0*/
#define H3D_VERSION_11 0x312e31 /*1.1*/
#pragma pack(push, 1)

enum h3d_type
{
	H3D_MESH = (1<<0),  /* h3dm files */
	H3D_ANIM = (1<<1),  /* h3da files */
    H3D_PHX = (1<<2)
};

enum h3d_texture_type
{
	H3D_TEXTURE_DIFFUSE = 0,
	H3D_TEXTURE_NORMAL = 1,
	H3D_TEXTURE_GLOSS = 2,
	H3D_TEXTURE_ALPHAMAP = 3,
	H3D_TEXTURE_EMISSIVE = 4,
	H3D_TEXTURE_REFLECTION = 5
};

struct _GCCPACKED_ h3d_header
{
	uint32 sign;
	uint32 version;
	uint32 type;	/* enum h3d_type */
	uint32 data_offset;
};

/*************************************************************************************************
 * model 
 */
struct _GCCPACKED_ h3d_geo_subset
{
	uint32 ib_idx;
	uint32 idx_cnt;
};

struct _GCCPACKED_ h3d_joint
{
	char name[32];
	fl32 inv_bind_mat[12];
	uint32 parent_idx;
};

struct _GCCPACKED_ h3d_geo
{
	uint32 vert_id_cnt;	/* number of vertex-ids (vertex-buffers) */
	uint32 vert_cnt;
	uint32 tri_cnt;
	uint32 subset_cnt;
	uint32 joint_cnt;
	uint32 bones_pervertex_max;
	bool_t ib_isui32;	/* index-buffer is 32bit integer ?*/
	uint32 vert_ids[GFX_MAX_VBUFFERS];	/* type=gfx_input_element_id, count = vert_id_cnt */

#if 0
    /* comes after in the h3d file (data) */
	struct h3d_geo_subset* subsets;
	void* indexes; /* can be uint16* or uint32* */
	struct vec4f* poss;
	struct vec4f* norms;
	struct vec4f* tangents;
	struct vec4f* binormals;
	struct vec4f* blend_weights;
	struct vec4i* blend_indexes;
	struct vec2f* coords0;
	struct vec2f* coords1;
	struct vec2f* coords2;
	struct vec2f* coords3;
	struct color* colors;
	struct h3d_joint* joints;
	struct mat3f* init_pose;
#endif
};

struct _GCCPACKED_ h3d_texture
{
	uint32 type;	/* h3d_texture_type */
	char filepath[DH_PATH_MAX];
};

struct _GCCPACKED_ h3d_mtl
{
	fl32 diffuse[3];
	fl32 specular[3];
	fl32 ambient[3];
    fl32 emissive[3];
	fl32 spec_exp;
	fl32 spec_intensity;
	fl32 opacity;
	uint32 texture_cnt;

#if 0
    /* comes after in the h3d file (data) */
	struct h3d_texture* textures;
#endif
};

struct _GCCPACKED_ h3d_submesh
{
	uint32 subset_idx;
	uint32 mtl_idx;
};

struct h3d_mesh
{
	uint32 geo_idx;
	uint32 submesh_cnt;

#if 0
    /* comes after in the h3d file (data) */
	struct h3d_submesh* submeshes;
#endif
};

struct _GCCPACKED_ h3d_node
{
	char name[32];
	uint32 mesh_idx;
	uint32 parent_idx;
	uint32 child_cnt;
    fl32 xform_pos[3];
    fl32 xform_rot[4];
    fl32 bb_min[3];
    fl32 bb_max[3];

#if 0
    /* comes after in the h3d file (data) */
	uint32* child_idxs;
#endif
};

struct _GCCPACKED_ h3d_occ
{
    char name[32];
    uint32 vert_cnt;
    uint32 tri_cnt;

#if 0
    /* data which comes after in the file */
    void* indexes;
    struct vec4f* poss;
#endif
};

/*************************************************************************************************
 * anim
 */
struct _GCCPACKED_ h3d_anim_channel
{
    char bindto[32];
#if 0
    /* data comes after in the file */
    struct vec3f* poss;
    struct quat4f* rots;
#endif
};

struct _GCCPACKED_ h3d_anim_clip
{
    char name[32];
    uint32 start;
    uint32 end;
    bool_t looped;
};

struct _GCCPACKED_ h3d_anim
{
    uint32 fps;
    uint32 frame_cnt;
    uint32 channel_cnt;
    bool_t has_scale;
    uint32 clip_cnt;
    uint32 clips_offset;    /* points to end of anim data for clips table */

#if 0
    /* data comes after in the file */
    struct h3d_anim_channels* channels;
    struct h3d_anim_clip* clips;
#endif
};

/*************************************************************************************************
 * physics
 */
enum h3d_phx_rigidtype
{
    H3D_PHX_RIGID_ST = 1,
    H3D_PHX_RIGID_DYN = 2
};

enum h3d_phx_shapetype
{
    H3D_PHX_SHAPE_BOX = 1,
    H3D_PHX_SHAPE_SPHERE = 2,
    H3D_PHX_SHAPE_CAPSULE = 3,
    H3D_PHX_SHAPE_CONVEX = 4,
    H3D_PHX_SHAPE_TRI = 5
};

enum h3d_phx_geotype
{
    H3D_PHX_GEO_CONVEX = 1,
    H3D_PHX_GEO_TRI = 2
};

struct h3d_phx_mtl
{
    fl32 friction_st;
    fl32 friction_dyn;
    fl32 restitution;
};

struct h3d_phx_geo
{
    uint32 type; /* h3d_phx_geotype */
    uint32 size;
    uint32 vert_cnt;
    uint32 tri_cnt;

#if 0
    /* comes after in file */
    void* data;
#endif
};

struct _GCCPACKED_ h3d_phx_shape
{
    uint32 type; /* h3d_phx_shapetype */
    fl32 local_pos[3];
    fl32 local_rot[4];
    uint32 mtl_cnt;
    bool_t ccd;

    /* shape descriptions */
    union   {
        struct {
            fl32 hx;
            fl32 hy;
            fl32 hz;
        } box;

        struct {
            fl32 radius;
        } sphere;

        struct {
            fl32 radius;
            fl32 half_height;
        } capsule;

        struct {
            uint32 id;  /* index to h3d_phx.geos */
        } mesh;

        fl32 f[3];
    };

#if 0
    /* data comes after in the file */
    uint32* mtl_ids;    /* index to h3d_phx.mtls */
#endif
};

struct _GCCPACKED_ h3d_phx_rigid
{
    char name[32];
    uint32 type; /* h3d_phx_rigidtype */
    fl32 mass;
    fl32 cmass_pos[3];  /* position of center-of-mass */ 
    fl32 cmass_rot[4]; /* rotation of center-of-mass (quaternion) */
    uint32 shape_cnt;
    fl32 lin_damping;
    fl32 ang_damping;
    int32 positer_cnt_min;
    int32 veliter_cnt_min;
    bool_t gravity_disable;

#if 0
    /* data comes after in the file */
    struct h3d_phx_shape* shapes;
#endif
};

struct _GCCPACKED_ h3d_phx
{
    uint32 mtl_cnt;
    uint32 geo_cnt;
    uint32 rigid_cnt;
    
#if 0
    /* dynamic data */
    struct h3d_phx_mtl* mtls;
    struct h3d_phx_geo* geos;
    struct h3d_phx_rigid* rigid;
#endif
};

#pragma pack(pop)

#endif /* H3D_TYPES_H_ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.