2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / Scene Compositor sub-project
\r
9 * GPAC is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation; either version 2, or (at your option)
\r
12 * any later version.
\r
14 * GPAC is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public
\r
20 * License along with this library; see the file COPYING. If not, write to
\r
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
\r
29 #include <gpac/scenegraph_vrml.h>
\r
30 #include <gpac/path2d.h>
\r
32 /*by default we store each color on 32 bit rather than 4 floats (128 bits)*/
\r
34 //#define MESH_USE_SFCOLOR
\r
36 #ifdef MESH_USE_SFCOLOR
\r
37 #define MESH_MAKE_COL(_argb) _argb
\r
38 #define MESH_GET_COLOR(_argb, _vertex) _argb = (_vertex).color;
\r
40 #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
41 #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
44 /*by default we store normals as signed bytes rather than floats*/
\r
46 //#define MESH_USE_FIXED_NORMAL
\r
48 #ifdef MESH_USE_FIXED_NORMAL
\r
49 #define MESH_SET_NORMAL(_vertex, _nor) _vertex.normal = _nor;
\r
50 #define MESH_GET_NORMAL(_nor, _vertex) _nor = _vertex.normal;
\r
51 #define MESH_NORMAL_UNIT FIX_ONE
\r
60 #define MESH_NORMAL_UNIT 1
\r
62 #ifdef GPAC_FIXED_POINT
\r
63 #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
64 #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
66 #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
67 #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
76 /*texture coordinates*/
\r
79 #ifdef MESH_USE_FIXED_NORMAL
\r
82 SFVec3f_bytes normal;
\r
84 /*color if used by mesh object*/
\r
85 #ifdef MESH_USE_SFCOLOR
\r
95 /*default: triangles described by indices (nb triangles = nb indices / 3) */
\r
97 /*point set: indices is meaningless*/
\r
99 /*line set: lines described by indices (nb lines = nb indices / 2) */
\r
106 /*vertex.color is used*/
\r
107 MESH_HAS_COLOR = 1,
\r
108 /*mesh is 2D: normal should be ignored and a global normal set to 0 0 1*/
\r
109 MESH_IS_2D = 1<<1,
\r
110 /*mesh has no texture coords - disable texturing*/
\r
111 MESH_NO_TEXTURE = 1<<2,
\r
112 /*mesh faces are clockwise*/
\r
113 MESH_IS_CW = 1<<3,
\r
114 /*mesh is solid (back face culling + 2 side lighting)*/
\r
115 MESH_IS_SOLID = 1<<4,
\r
116 /*mesh has smoothed normals*/
\r
117 MESH_IS_SMOOTHED = 1<<5,
\r
118 /*vertex.color is used with alpha channel*/
\r
119 MESH_HAS_ALPHA = 1<<6,
\r
122 /*indexes as used in glDrawElements - note that integer type is not allowed with oglES*/
\r
123 #ifdef GPAC_USE_OGL_ES
\r
124 #define IDX_TYPE u16
\r
126 #define IDX_TYPE u32
\r
129 /*mesh object used by all 2D/3D primitives. */
\r
130 typedef struct __gf_mesh
\r
133 u32 v_count, v_alloc;
\r
134 GF_Vertex *vertices;
\r
135 /*triangle indexes*/
\r
136 u32 i_count, i_alloc;
\r
139 /*one of the above type*/
\r
142 /*one of the above flags*/
\r
145 /*bounds info: bounding box and bounding sphere radius*/
\r
148 /*aabb tree of the mesh if any*/
\r
149 struct __AABBNode *aabb_root;
\r
150 /*triangle indexes used in AABB tree - order may be different than the one in mesh->indices*/
\r
151 IDX_TYPE *aabb_indices;
\r
152 // u32 aabb_nb_index;
\r
155 GF_Mesh *new_mesh();
\r
156 void mesh_free(GF_Mesh *mesh);
\r
158 void mesh_reset(GF_Mesh *mesh);
\r
159 /*recompute mesh bounds*/
\r
160 void mesh_update_bounds(GF_Mesh *mesh);
\r
161 /*adds new vertex*/
\r
162 void mesh_set_vertex_vx(GF_Mesh *mesh, GF_Vertex *vx);
\r
163 /*adds new vertex (exported for tesselator only)*/
\r
164 void mesh_set_vertex(GF_Mesh *mesh, Fixed x, Fixed y, Fixed z, Fixed nx, Fixed ny, Fixed nz, Fixed u, Fixed v);
\r
165 /*adds an index (exported for tesselator only)*/
\r
166 void mesh_set_index(GF_Mesh *mesh, u32 idx);
\r
167 /*adds an point & associated color, normal set to NULL*/
\r
168 void mesh_set_point(GF_Mesh *mesh, Fixed x, Fixed y, Fixed z, SFColorRGBA col);
\r
169 /*adds an index (exported for tesselator only)*/
\r
170 void mesh_set_triangle(GF_Mesh *mesh, u32 id1, u32 id2, u32 id3);
\r
171 /*make dest mesh the clone of orig*/
\r
172 void mesh_clone(GF_Mesh *dest, GF_Mesh *orig);
\r
173 /*recompute all normals*/
\r
174 void mesh_recompute_normals(GF_Mesh *mesh);
\r
175 /*generate texture coordinate - ONLY LOCAL MODES SUPPORTED FOR NOW*/
\r
176 void mesh_generate_tex_coords(GF_Mesh *mesh, GF_Node *__texCoords);
\r
178 /*inserts a box (lines only) of size 1.0 1.0 1.0*/
\r
179 void mesh_new_unit_bbox(GF_Mesh *mesh);
\r
181 /*insert base primitives - low res indicates less subdivision steps for circles (cone, cylinder, ellipse, sphere)*/
\r
182 void mesh_new_rectangle(GF_Mesh *mesh, SFVec2f size);
\r
183 void mesh_new_ellipse(GF_Mesh *mesh, Fixed a_dia, Fixed b_dia, Bool low_res);
\r
184 void mesh_new_box(GF_Mesh *mesh, SFVec3f size);
\r
185 void mesh_new_cylinder(GF_Mesh *mesh, Fixed height, Fixed radius, Bool bottom, Bool side, Bool top, Bool low_res);
\r
186 void mesh_new_cone(GF_Mesh *mesh, Fixed height, Fixed radius, Bool bottom, Bool side, Bool low_res);
\r
187 void mesh_new_sphere(GF_Mesh *mesh, Fixed radius, Bool low_res);
\r
188 /*inserts ILS/ILS2D and IFS2D outline when not filled*/
\r
189 void mesh_new_ils(GF_Mesh *mesh, GF_Node *__coord, MFInt32 *coordIndex, GF_Node *__color, MFInt32 *colorIndex, Bool colorPerVertex, Bool do_close);
\r
191 void mesh_new_ifs2d(GF_Mesh *mesh, GF_Node *ifs2d);
\r
193 void mesh_new_ifs(GF_Mesh *mesh, GF_Node *ifs);
\r
194 /*inserts PS/PS2D*/
\r
195 void mesh_new_ps(GF_Mesh *mesh, GF_Node *__coord, GF_Node *__color);
\r
196 /*inserts ElevationGrid*/
\r
197 void mesh_new_elevation_grid(GF_Mesh *mesh, GF_Node *eg);
\r
198 /*inserts Extrusion*/
\r
199 void mesh_new_extrusion(GF_Mesh *mesh, GF_Node *ext);
\r
200 /*builds mesh from path, performing tesselation if desired*/
\r
201 void mesh_from_path(GF_Mesh *mesh, GF_Path *path);
\r
202 /*builds mesh for outline of the given path*/
\r
203 void mesh_get_outline(GF_Mesh *mesh, GF_Path *path);
\r
204 /*constructs an extrusion from given path - mesh is reseted, txcoords computed from path bounds
\r
205 @thespine: spine line
\r
206 @creaseAngle: creaseAngle for normal smoothing, 0 for no smoothing
\r
207 begin_cap, end_cap: indicates whether start/end faces shall be added
\r
208 @spine_ori: orientation at spine points
\r
209 @spine_scale: scale at spine points
\r
210 @tx_along_spine: if set, texture coords are generated so that the texture is mapped on the side,
\r
211 otherwise the same txcoords are used all along the extrusion spine
\r
213 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
214 /*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
215 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
217 /*returns 1 if intersection and set outPoint to closest intersection, 0 otherwise*/
\r
218 Bool gf_mesh_intersect_ray(GF_Mesh *mesh, GF_Ray *r, SFVec3f *outPoint, SFVec3f *outNormal, SFVec2f *outTexCoords);
\r
219 /*returns 1 if any face is less than min_dist from pos, with collision point on closest face (towards pos)*/
\r
220 Bool gf_mesh_closest_face(GF_Mesh *mesh, SFVec3f pos, Fixed min_dist, SFVec3f *outPoint);
\r
225 /*AABB tree node (exported for bounds drawing)*/
\r
226 typedef struct __AABBNode
\r
230 /*sorted indices in mesh indices list*/
\r
234 /*children nodes, NULL if leaf*/
\r
235 struct __AABBNode *pos, *neg;
\r
238 /*tree construction modes*/
\r
241 /*AABB tree is not used*/
\r
243 /*longest box axis is used to divide an AABB node*/
\r
245 /*keep tree well-balanced*/
\r
247 /*best axis is use: test largest, then middle, then smallest axis*/
\r
249 /*use variance to pick axis*/
\r
251 /*fifty/fifty point split*/
\r
255 void gf_mesh_build_aabbtree(GF_Mesh *mesh);
\r
259 * tesselation functions
\r
262 /*appends given face (and tesselate if needed) to the mesh. Only vertices are used in the face
\r
263 indices are ignored.
\r
264 partially implemented on ogl-ES*/
\r
265 void TesselateFaceMesh(GF_Mesh *mesh, GF_Mesh *face);
\r
267 #ifndef GPAC_USE_OGL_ES
\r
268 /*converts 2D path into a polygon - these are only partially implemented when using oglES
\r
270 0, regular odd/even windining rule with texCoords
\r
271 1, zero-non-zero windining rule without texCoords
\r
272 2, zero-non-zero windining rule with texCoords
\r
274 void TesselatePath(GF_Mesh *mesh, GF_Path *path, u32 outline_style);
\r
276 /*appends given face (and tesselate if needed) to the mesh. Only vertices are used in the face
\r
277 indices are ignored.
\r
278 Same as TesselateFaceMesh + faces info to determine where are the polygons in the face - used by extruder only
\r
280 void TesselateFaceMeshComplex(GF_Mesh *dest, GF_Mesh *orig, u32 nbFaces, u32 *ptsPerFaces);
\r
284 #endif /*_GF_MESH_H_*/
\r