--- /dev/null
+/*\r
+ * GPAC - Multimedia Framework C SDK\r
+ *\r
+ * Copyright (c) Jean Le Feuvre 2000-2005\r
+ * All rights reserved\r
+ *\r
+ * This file is part of GPAC / Scene Compositor sub-project\r
+ *\r
+ * GPAC is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation; either version 2, or (at your option)\r
+ * any later version.\r
+ * \r
+ * GPAC is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public\r
+ * License along with this library; see the file COPYING. If not, write to\r
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
+ *\r
+ */\r
+\r
+\r
+#ifndef _GF_MESH_H_\r
+#define _GF_MESH_H_\r
+\r
+#include <gpac/scenegraph_vrml.h>\r
+#include <gpac/path2d.h>\r
+\r
+/*by default we store each color on 32 bit rather than 4 floats (128 bits)*/\r
+\r
+//#define MESH_USE_SFCOLOR\r
+\r
+#ifdef MESH_USE_SFCOLOR\r
+#define MESH_MAKE_COL(_argb) _argb\r
+#define MESH_GET_COLOR(_argb, _vertex) _argb = (_vertex).color;\r
+#else\r
+#define MESH_MAKE_COL(_argb) GF_COL_ARGB(FIX2INT(255*(_argb.alpha)), FIX2INT(255*(_argb.blue)), FIX2INT(255*(_argb.green)), FIX2INT(255*(_argb.red)))\r
+#define MESH_GET_COLOR(_argb, _vertex) { _argb.alpha = INT2FIX(GF_COL_A((_vertex).color))/255; _argb.red = INT2FIX(GF_COL_R((_vertex).color))/255; _argb.green = INT2FIX(GF_COL_G((_vertex).color))/255; _argb.blue = INT2FIX(GF_COL_B((_vertex).color))/255; }\r
+#endif\r
+\r
+/*by default we store normals as signed bytes rather than floats*/\r
+\r
+//#define MESH_USE_FIXED_NORMAL\r
+\r
+#ifdef MESH_USE_FIXED_NORMAL\r
+#define MESH_SET_NORMAL(_vertex, _nor) _vertex.normal = _nor;\r
+#define MESH_GET_NORMAL(_nor, _vertex) _nor = _vertex.normal;\r
+#define MESH_NORMAL_UNIT FIX_ONE\r
+#else\r
+\r
+typedef struct\r
+{\r
+ s8 x, y, z;\r
+ s8 __dummy;\r
+} SFVec3f_bytes;\r
+\r
+#define MESH_NORMAL_UNIT 1\r
+\r
+#ifdef GPAC_FIXED_POINT\r
+#define MESH_SET_NORMAL(_vertex, _nor) { SFVec3f_bytes __nor; __nor.x = (s8) FIX2INT(_nor.x*100); __nor.y = (s8) FIX2INT(_nor.y*100); __nor.z = (s8) FIX2INT(_nor.z*100); __nor.__dummy=0; _vertex.normal = __nor; }\r
+#define MESH_GET_NORMAL(_nor, _vertex) { (_nor).x = INT2FIX(_vertex.normal.x); (_nor).y = INT2FIX(_vertex.normal.y); (_nor).z = INT2FIX(_vertex.normal.z); gf_vec_norm(&(_nor)); }\r
+#else\r
+#define MESH_SET_NORMAL(_vertex, _nor) { SFVec3f_bytes __nor; __nor.x = (s8) (_nor.x*100); __nor.y = (s8) (_nor.y*100); __nor.z = (s8) (_nor.z*100); __nor.__dummy=0; _vertex.normal = __nor; }\r
+#define MESH_GET_NORMAL(_nor, _vertex) { (_nor).x = _vertex.normal.x; (_nor).y = _vertex.normal.y; (_nor).z = _vertex.normal.z; gf_vec_norm(&(_nor)); }\r
+#endif\r
+\r
+#endif\r
+\r
+typedef struct\r
+{\r
+ /*position*/\r
+ SFVec3f pos; \r
+ /*texture coordinates*/\r
+ SFVec2f texcoords;\r
+ /*normal*/\r
+#ifdef MESH_USE_FIXED_NORMAL\r
+ SFVec3f normal;\r
+#else\r
+ SFVec3f_bytes normal;\r
+#endif\r
+ /*color if used by mesh object*/\r
+#ifdef MESH_USE_SFCOLOR\r
+ SFColorRGBA color;\r
+#else\r
+ u32 color;\r
+#endif\r
+} GF_Vertex;\r
+\r
+/*mesh type used*/\r
+enum\r
+{\r
+ /*default: triangles described by indices (nb triangles = nb indices / 3) */\r
+ MESH_TRIANGLES = 0,\r
+ /*point set: indices is meaningless*/\r
+ MESH_POINTSET,\r
+ /*line set: lines described by indices (nb lines = nb indices / 2) */\r
+ MESH_LINESET,\r
+};\r
+\r
+/*mesh flags*/\r
+enum\r
+{\r
+ /*vertex.color is used*/\r
+ MESH_HAS_COLOR = 1, \r
+ /*mesh is 2D: normal should be ignored and a global normal set to 0 0 1*/\r
+ MESH_IS_2D = 1<<1, \r
+ /*mesh has no texture coords - disable texturing*/\r
+ MESH_NO_TEXTURE = 1<<2, \r
+ /*mesh faces are clockwise*/\r
+ MESH_IS_CW = 1<<3, \r
+ /*mesh is solid (back face culling + 2 side lighting)*/\r
+ MESH_IS_SOLID = 1<<4, \r
+ /*mesh has smoothed normals*/\r
+ MESH_IS_SMOOTHED = 1<<5, \r
+ /*vertex.color is used with alpha channel*/\r
+ MESH_HAS_ALPHA = 1<<6, \r
+};\r
+\r
+/*indexes as used in glDrawElements - note that integer type is not allowed with oglES*/\r
+#ifdef GPAC_USE_OGL_ES\r
+#define IDX_TYPE u16\r
+#else\r
+#define IDX_TYPE u32\r
+#endif\r
+\r
+/*mesh object used by all 2D/3D primitives. */\r
+typedef struct __gf_mesh\r
+{\r
+ /*vertex list*/\r
+ u32 v_count, v_alloc;\r
+ GF_Vertex *vertices;\r
+ /*triangle indexes*/\r
+ u32 i_count, i_alloc;\r
+ IDX_TYPE *indices;\r
+\r
+ /*one of the above type*/\r
+ u32 mesh_type;\r
+\r
+ /*one of the above flags*/\r
+ u32 flags;\r
+\r
+ /*bounds info: bounding box and bounding sphere radius*/\r
+ GF_BBox bounds;\r
+\r
+ /*aabb tree of the mesh if any*/\r
+ struct __AABBNode *aabb_root;\r
+ /*triangle indexes used in AABB tree - order may be different than the one in mesh->indices*/\r
+ IDX_TYPE *aabb_indices;\r
+// u32 aabb_nb_index;\r
+} GF_Mesh;\r
+\r
+GF_Mesh *new_mesh();\r
+void mesh_free(GF_Mesh *mesh);\r
+/*reset mesh*/\r
+void mesh_reset(GF_Mesh *mesh);\r
+/*recompute mesh bounds*/\r
+void mesh_update_bounds(GF_Mesh *mesh);\r
+/*adds new vertex*/\r
+void mesh_set_vertex_vx(GF_Mesh *mesh, GF_Vertex *vx);\r
+/*adds new vertex (exported for tesselator only)*/\r
+void mesh_set_vertex(GF_Mesh *mesh, Fixed x, Fixed y, Fixed z, Fixed nx, Fixed ny, Fixed nz, Fixed u, Fixed v);\r
+/*adds an index (exported for tesselator only)*/\r
+void mesh_set_index(GF_Mesh *mesh, u32 idx);\r
+/*adds an point & associated color, normal set to NULL*/\r
+void mesh_set_point(GF_Mesh *mesh, Fixed x, Fixed y, Fixed z, SFColorRGBA col);\r
+/*adds an index (exported for tesselator only)*/\r
+void mesh_set_triangle(GF_Mesh *mesh, u32 id1, u32 id2, u32 id3);\r
+/*make dest mesh the clone of orig*/\r
+void mesh_clone(GF_Mesh *dest, GF_Mesh *orig);\r
+/*recompute all normals*/\r
+void mesh_recompute_normals(GF_Mesh *mesh);\r
+/*generate texture coordinate - ONLY LOCAL MODES SUPPORTED FOR NOW*/\r
+void mesh_generate_tex_coords(GF_Mesh *mesh, GF_Node *__texCoords);\r
+\r
+/*inserts a box (lines only) of size 1.0 1.0 1.0*/\r
+void mesh_new_unit_bbox(GF_Mesh *mesh);\r
+\r
+/*insert base primitives - low res indicates less subdivision steps for circles (cone, cylinder, ellipse, sphere)*/\r
+void mesh_new_rectangle(GF_Mesh *mesh, SFVec2f size);\r
+void mesh_new_ellipse(GF_Mesh *mesh, Fixed a_dia, Fixed b_dia, Bool low_res);\r
+void mesh_new_box(GF_Mesh *mesh, SFVec3f size);\r
+void mesh_new_cylinder(GF_Mesh *mesh, Fixed height, Fixed radius, Bool bottom, Bool side, Bool top, Bool low_res);\r
+void mesh_new_cone(GF_Mesh *mesh, Fixed height, Fixed radius, Bool bottom, Bool side, Bool low_res);\r
+void mesh_new_sphere(GF_Mesh *mesh, Fixed radius, Bool low_res);\r
+/*inserts ILS/ILS2D and IFS2D outline when not filled*/\r
+void mesh_new_ils(GF_Mesh *mesh, GF_Node *__coord, MFInt32 *coordIndex, GF_Node *__color, MFInt32 *colorIndex, Bool colorPerVertex, Bool do_close);\r
+/*inserts IFS2D*/\r
+void mesh_new_ifs2d(GF_Mesh *mesh, GF_Node *ifs2d);\r
+/*inserts IFS*/\r
+void mesh_new_ifs(GF_Mesh *mesh, GF_Node *ifs);\r
+/*inserts PS/PS2D*/\r
+void mesh_new_ps(GF_Mesh *mesh, GF_Node *__coord, GF_Node *__color);\r
+/*inserts ElevationGrid*/\r
+void mesh_new_elevation_grid(GF_Mesh *mesh, GF_Node *eg);\r
+/*inserts Extrusion*/\r
+void mesh_new_extrusion(GF_Mesh *mesh, GF_Node *ext);\r
+/*builds mesh from path, performing tesselation if desired*/\r
+void mesh_from_path(GF_Mesh *mesh, GF_Path *path);\r
+/*builds mesh for outline of the given path*/\r
+void mesh_get_outline(GF_Mesh *mesh, GF_Path *path);\r
+/*constructs an extrusion from given path - mesh is reseted, txcoords computed from path bounds\r
+@thespine: spine line\r
+@creaseAngle: creaseAngle for normal smoothing, 0 for no smoothing\r
+begin_cap, end_cap: indicates whether start/end faces shall be added\r
+@spine_ori: orientation at spine points\r
+@spine_scale: scale at spine points\r
+@tx_along_spine: if set, texture coords are generated so that the texture is mapped on the side, \r
+otherwise the same txcoords are used all along the extrusion spine\r
+*/\r
+void mesh_extrude_path(GF_Mesh *mesh, GF_Path *path, MFVec3f *thespine, Fixed creaseAngle, Bool begin_cap, Bool end_cap, MFRotation *spine_ori, MFVec2f *spine_scale, Bool tx_along_spine);\r
+/*special extension of the above: APPENDS an extrusion from given path - mesh is NOT reseted, txcoords are computed based on min_cx, min_cy, width_cx, width_cy*/\r
+void mesh_extrude_path_ext(GF_Mesh *mesh, GF_Path *path, MFVec3f *thespine, Fixed creaseAngle, Fixed min_cx, Fixed min_cy, Fixed width_cx, Fixed width_cy, Bool begin_cap, Bool end_cap, MFRotation *spine_ori, MFVec2f *spine_scale, Bool tx_along_spine);\r
+\r
+/*returns 1 if intersection and set outPoint to closest intersection, 0 otherwise*/\r
+Bool gf_mesh_intersect_ray(GF_Mesh *mesh, GF_Ray *r, SFVec3f *outPoint, SFVec3f *outNormal, SFVec2f *outTexCoords);\r
+/*returns 1 if any face is less than min_dist from pos, with collision point on closest face (towards pos)*/\r
+Bool gf_mesh_closest_face(GF_Mesh *mesh, SFVec3f pos, Fixed min_dist, SFVec3f *outPoint);\r
+\r
+\r
+\r
+\r
+/*AABB tree node (exported for bounds drawing)*/\r
+typedef struct __AABBNode\r
+{\r
+ /*bbox*/\r
+ SFVec3f min, max;\r
+ /*sorted indices in mesh indices list*/\r
+ IDX_TYPE *indices;\r
+ /*nb triangles*/\r
+ u32 nb_idx;\r
+ /*children nodes, NULL if leaf*/\r
+ struct __AABBNode *pos, *neg;\r
+} AABBNode;\r
+\r
+/*tree construction modes*/\r
+enum\r
+{\r
+ /*AABB tree is not used*/\r
+ AABB_NONE, \r
+ /*longest box axis is used to divide an AABB node*/\r
+ AABB_LONGEST, \r
+ /*keep tree well-balanced*/\r
+ AABB_BALANCED,\r
+ /*best axis is use: test largest, then middle, then smallest axis*/\r
+ AABB_BEST_AXIS, \r
+ /*use variance to pick axis*/\r
+ AABB_SPLATTER,\r
+ /*fifty/fifty point split*/\r
+ AABB_FIFTY,\r
+};\r
+\r
+void gf_mesh_build_aabbtree(GF_Mesh *mesh);\r
+\r
+\r
+/*\r
+ * tesselation functions\r
+ */\r
+\r
+/*appends given face (and tesselate if needed) to the mesh. Only vertices are used in the face\r
+indices are ignored. \r
+partially implemented on ogl-ES*/\r
+void TesselateFaceMesh(GF_Mesh *mesh, GF_Mesh *face);\r
+\r
+#ifndef GPAC_USE_OGL_ES\r
+/*converts 2D path into a polygon - these are only partially implemented when using oglES\r
+for_outline:\r
+ 0, regular odd/even windining rule with texCoords\r
+ 1, zero-non-zero windining rule without texCoords\r
+ 2, zero-non-zero windining rule with texCoords\r
+*/\r
+void TesselatePath(GF_Mesh *mesh, GF_Path *path, u32 outline_style);\r
+\r
+/*appends given face (and tesselate if needed) to the mesh. Only vertices are used in the face\r
+indices are ignored. \r
+Same as TesselateFaceMesh + faces info to determine where are the polygons in the face - used by extruder only\r
+*/\r
+void TesselateFaceMeshComplex(GF_Mesh *dest, GF_Mesh *orig, u32 nbFaces, u32 *ptsPerFaces);\r
+\r
+#endif\r
+\r
+#endif /*_GF_MESH_H_*/\r
+\r