MCPcopy Create free account
hub / github.com/RenderKit/embree / createGridGeometry

Function createGridGeometry

tutorials/grid_geometry/grid_geometry_device.cpp:201–508  ·  view source on GitHub ↗

adds a displaced sphere to the scene */

Source from the content-addressed store, hash-verified

199
200/* adds a displaced sphere to the scene */
201void createGridGeometry (GridMesh& gmesh)
202{
203#if 1
204 /* calculates top vertex ring */
205 for (int i=0; i<5; i++) {
206 const float theta = 45.0f*float(pi)/180.0f;
207 const float phi = 72.0f*i*float(pi)/180.0f;
208 sphere_vertices[i] = Vec3fa(sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi));
209 }
210
211 /* calculates center vertex ring */
212 for (int i=0; i<10; i++) {
213 const float theta = 90.0f*float(pi)/180.0f;
214 const float phi = (18.0f+36.0f*i)*float(pi)/180.0f;
215 sphere_vertices[5+i] = Vec3fa(sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi));
216 }
217
218 /* calculates bottom vertex ring */
219 for (int i=0; i<5; i++) {
220 const float theta = 135.0f*float(pi)/180.0f;
221 const float phi = 72.0f*i*float(pi)/180.0f;
222 sphere_vertices[5+10+i] = Vec3fa(sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi));
223 }
224#endif
225
226 /* temporary subdivision geometry to evaluate base surface */
227 RTCGeometry geomSubdiv = rtcNewGeometry(g_device, RTC_GEOMETRY_TYPE_SUBDIVISION);
228 rtcSetSharedGeometryBuffer(geomSubdiv, RTC_BUFFER_TYPE_VERTEX, 0, RTC_FORMAT_FLOAT3, sphere_vertices, 0, sizeof(Vec3fa), NUM_VERTICES);
229 rtcSetSharedGeometryBuffer(geomSubdiv, RTC_BUFFER_TYPE_INDEX, 0, RTC_FORMAT_UINT, sphere_indices, 0, sizeof(unsigned int), NUM_INDICES);
230 rtcSetSharedGeometryBuffer(geomSubdiv, RTC_BUFFER_TYPE_FACE, 0, RTC_FORMAT_UINT, sphere_faces, 0, sizeof(unsigned int), NUM_FACES);
231 rtcCommitGeometry(geomSubdiv);
232
233 /* grid resolution has to be uneven as non-quads are split into multiple quads */
234 assert((GRID_RESOLUTION_X%2) == 1);
235 assert((GRID_RESOLUTION_Y%2) == 1);
236
237 /* subgrid resolution for non-quads */
238 unsigned int SUB_GRID_RESOLUTION_X = GRID_RESOLUTION_X/2+1;
239 unsigned int SUB_GRID_RESOLUTION_Y = GRID_RESOLUTION_Y/2+1;
240
241 /* grid resolution for quads */
242 unsigned int QUAD_GRID_RESOLUTION_X = GRID_RESOLUTION_X;
243 unsigned int QUAD_GRID_RESOLUTION_Y = GRID_RESOLUTION_Y;
244
245 /* each quad becomes one grid, other faces become multiple grids */
246 int numGrids = 0;
247 int numVertices = 0;
248 for (int f=0; f<NUM_FACES; f++)
249 {
250 if (sphere_faces[f] == 4)
251 {
252 numGrids++;
253 numVertices += QUAD_GRID_RESOLUTION_X*QUAD_GRID_RESOLUTION_Y;
254 }
255 else
256 {
257 numGrids += sphere_faces[f];
258 numVertices += sphere_faces[f]*SUB_GRID_RESOLUTION_X*SUB_GRID_RESOLUTION_Y;

Callers 1

device_initFunction · 0.85

Calls 15

rtcCommitGeometryFunction · 0.85
rtcSetNewGeometryBufferFunction · 0.85
alignedUSMMallocFunction · 0.85
rtcInterpolate1Function · 0.85
getVertexFunction · 0.85
rtcReleaseGeometryFunction · 0.85
alignedUSMFreeFunction · 0.85
displacementFunction · 0.70

Tested by

no test coverage detected