#ifndef _G3DVIEWER_PLUGIN_H #define _G3DVIEWER_PLUGIN_H #include #include #include #ifndef G3D_MAX_NAME_LEN #define G3D_MAX_NAME_LEN 1024 #endif /*****************************************************************************/ /* G3DImage: for height fields & textures */ /*****************************************************************************/ #define G3D_FLAG_IMG_GREYSCALE (1L << 1) /* greyscale image... */ typedef struct { gchar *name; /* always useful */ guint32 width; /* width of image */ guint32 height; /* height of image */ guint8 depth; /* color depth in bit */ guint32 flags; /* see defines above */ guint8 *pixeldata; /* width * height * depth bytes */ guint32 gl_texid; /* scale factor for texture coordinates if image is resized */ GLfloat scaleu; GLfloat scalev; } G3DImage; /*****************************************************************************/ /* G3DMaterial */ /*****************************************************************************/ #define G3D_FLAG_MAT_TWOSIDE (1L << 0) typedef struct { gchar *name; GLfloat r,g,b,a; GLfloat shininess; GLfloat specular[4]; guint32 flags; G3DImage *texture; /** texture map */ } G3DMaterial; /*****************************************************************************/ /* G3DFace */ /*****************************************************************************/ #define G3D_FLAG_FAC_NORMALS (1L << 0) #define G3D_FLAG_FAC_TEXMAP (1L << 1) typedef struct { G3DMaterial *material; /** has to be non-NULL */ guint32 num_vertices; /** number of vertices in face: 3 or more */ guint32 *index_vertex; /** num_vertices * sizeof(int) */ guint32 flags; /** see defines above */ /* if face has own normals: num_vertices * 3 * sizeof(GLfloat) */ GLfloat *normals; G3DImage *tex_image; guint32 tex_ncoords; GLfloat *tex_coords; } G3DFace; /*****************************************************************************/ /* G3DObject */ /*****************************************************************************/ typedef struct { gchar *name; GSList *materials; GSList *faces; /* vertices */ guint32 vertex_count; GLfloat *vertices; /* texture stuff: temporary storage, should be in G3DFace items */ guint32 tex_nverts; GLfloat *tex_vertices; G3DImage *tex_image; /* some fields to speed up rendering, should not be used by plugins */ GLfloat *_normals; G3DMaterial **_materials; guint32 _num_faces; guint32 *_indices; guint32 *_flags; guint32 *_tex_images; /* one per face: 0: no image, else texture id */ GLfloat *_tex_coords; /* two per vertex (6 per face) */ } G3DObject; /*****************************************************************************/ /* G3DModel: more than just for the model information */ /*****************************************************************************/ #define G3D_FLAG_GL_SPECULAR (1L << 0) #define G3D_FLAG_GL_SHININESS (1L << 1) #define G3D_FLAG_GL_ALLTWOSIDE (1L << 2) #define G3D_FLAG_GL_TEXTURES (1L << 3) typedef struct { GSList *lights; GSList *objects; GSList *materials; GHashTable *texture_files; GLfloat quat[4]; GLfloat zoom; struct { gint32 beginx, beginy; } mouse; GLfloat aspect; GLfloat bgcolor[4]; gchar *filename; guint32 glflags; /* Widgets */ struct { GtkWidget *window; GtkWidget *infowin; struct { GtkWidget *tree; } modeltab; struct { GtkWidget *label_desc; GtkWidget *label_exts; } plugintab; GtkWidget *glarea; GtkWidget *statushbox; GtkWidget *progressbar; gboolean show_statusbar; } interface; } G3DModel; /*****************************************************************************/ /* src/plugins.c: may be used in plugins to load images... */ /*****************************************************************************/ #define G3D_PLUGIN_ALL 0x00 #define G3D_PLUGIN_IMPORT 0x01 #define G3D_PLUGIN_EXPORT 0x02 /* unimplemented */ #define G3D_PLUGIN_IMAGE 0x10 #define G3D_PLUGIN_UNKNOWN 0xFF typedef struct { gchar *name; gchar *path; gchar *description; guint32 type; gchar **extensions; } G3DPlugin; int g3d_plugins_load_model(const gchar *filename, G3DModel *model); int g3d_plugins_load_image(const gchar *filename, G3DImage *image); gchar **g3d_plugins_get_image_extensions(void); GSList *g3d_plugins_getlist(guint32 type); /* texture.c */ G3DImage *g3d_texture_load_cached(G3DModel *model, const gchar *filename); int g3d_texture_load_all_textures(G3DModel *model); int g3d_texture_prepare(G3DImage *texture); void g3d_texture_free_cache(G3DModel *model); /* image.c */ int g3d_image_dump_ppm(G3DImage *image, const gchar *filename); /* object.c */ int g3d_object_smooth(G3DObject *object, GLfloat max_angle); /*****************************************************************************/ /* some interface function: may be changed in near future */ /*****************************************************************************/ void g3d_interface_update(void); void g3d_interface_progress_init(G3DModel *model); void g3d_interface_progress_update(G3DModel *model, gfloat percentage); void g3d_interface_progress_finish(G3DModel *model); /*****************************************************************************/ /* libmisc.a */ /*****************************************************************************/ /* readfile.c */ gint32 g3d_read_int8(FILE *f); gint32 g3d_read_int16_be(FILE *f); gint32 g3d_read_int16_le(FILE *f); gint32 g3d_read_int32_be(FILE *f); gint32 g3d_read_int32_le(FILE *f); GLfloat g3d_read_float_be(FILE *f); GLfloat g3d_read_float_le(FILE *f); void g3d_read_dumphex(FILE *f, int nbytes); /* iff.c */ #define G3D_IFF_MKID(a,b,c,d) ( \ (((guint32)(a))<<24) | \ (((guint32)(b))<<16) | \ (((guint32)(c))<< 8) | \ (((guint32)(d)) ) ) FILE *g3d_iff_open(const char *filename, guint32 *id, guint32 *len); int g3d_iff_readchunk(FILE *f, guint32 *id, guint32 *len); /* new.c */ G3DMaterial *g3d_new_G3DMaterial(void); /* vector.c */ int g3d_vector_normal(GLfloat ax, GLfloat ay, GLfloat az, GLfloat bx, GLfloat by, GLfloat bz, GLfloat *nx, GLfloat *ny, GLfloat *nz); double g3d_vector_angle(GLfloat ax, GLfloat ay, GLfloat az, GLfloat bx, GLfloat by, GLfloat bz); int g3d_vector_wrong(GLfloat ax, GLfloat ay, GLfloat az, GLfloat bx, GLfloat by, GLfloat bz); int g3d_vector_unify(GLfloat *nx, GLfloat *ny, GLfloat *nz); int g3d_vector_transform(GLfloat *x, GLfloat *y, GLfloat *z, GLfloat *matrix); #endif