BBox3fa TriangleMeshTriangle8::update(char* prim, size_t num, void* geom) const { BBox3fa bounds = empty; TriangleMesh* mesh = (TriangleMesh*) geom; for (size_t j=0; j<num; j++) { Triangle8& dst = ((Triangle8*) prim)[j]; avxi vgeomID = -1, vprimID = -1, vmask = -1; avx3f v0 = zero, v1 = zero, v2 = zero; for (size_t i=0; i<8; i++) { if (dst.primID[i] == -1) break; const unsigned geomID = dst.geomID[i]; const unsigned primID = dst.primID[i]; const TriangleMesh::Triangle& tri = mesh->triangle(primID); const Vec3fa p0 = mesh->vertex(tri.v[0]); const Vec3fa p1 = mesh->vertex(tri.v[1]); const Vec3fa p2 = mesh->vertex(tri.v[2]); bounds.extend(merge(BBox3fa(p0),BBox3fa(p1),BBox3fa(p2))); vgeomID [i] = geomID; vprimID [i] = primID; vmask [i] = mesh->mask; v0.x[i] = p0.x; v0.y[i] = p0.y; v0.z[i] = p0.z; v1.x[i] = p1.x; v1.y[i] = p1.y; v1.z[i] = p1.z; v2.x[i] = p2.x; v2.y[i] = p2.y; v2.z[i] = p2.z; } new (&dst) Triangle8(v0,v1,v2,vgeomID,vprimID,vmask); } return bounds; }
void TriangleMeshTriangle8::pack(char* This, atomic_set<PrimRefBlock>::block_iterator_unsafe& prims, void* geom) const { TriangleMesh* mesh = (TriangleMesh*) geom; avxi geomID = -1, primID = -1, mask = -1; avx3f v0 = zero, v1 = zero, v2 = zero; for (size_t i=0; i<8 && prims; i++, prims++) { const PrimRef& prim = *prims; const TriangleMesh::Triangle& tri = mesh->triangle(prim.primID()); const Vec3fa& p0 = mesh->vertex(tri.v[0]); const Vec3fa& p1 = mesh->vertex(tri.v[1]); const Vec3fa& p2 = mesh->vertex(tri.v[2]); geomID [i] = mesh->id; primID [i] = prim.primID(); mask [i] = mesh->mask; v0.x[i] = p0.x; v0.y[i] = p0.y; v0.z[i] = p0.z; v1.x[i] = p1.x; v1.y[i] = p1.y; v1.z[i] = p1.z; v2.x[i] = p2.x; v2.y[i] = p2.y; v2.z[i] = p2.z; } new (This) Triangle8(v0,v1,v2,geomID,primID,mask); }
void SpatialSplit::Split::split<false>(size_t threadIndex, size_t threadCount, LockStepTaskScheduler* scheduler, PrimRefBlockAlloc<PrimRef>& alloc, Scene* scene, TriRefList& prims, TriRefList& lprims_o, PrimInfo& linfo_o, TriRefList& rprims_o, PrimInfo& rinfo_o) const { assert(valid()); TriRefList::item* lblock = lprims_o.insert(alloc.malloc(threadIndex)); TriRefList::item* rblock = rprims_o.insert(alloc.malloc(threadIndex)); linfo_o.reset(); rinfo_o.reset(); /* sort each primitive to left, right, or left and right */ while (atomic_set<PrimRefBlock>::item* block = prims.take()) { for (size_t i=0; i<block->size(); i++) { const PrimRef& prim = block->at(i); const BBox3fa bounds = prim.bounds(); const int bin0 = mapping.bin(bounds.lower)[dim]; const int bin1 = mapping.bin(bounds.upper)[dim]; /* sort to the left side */ if (bin1 < pos) { linfo_o.add(bounds,center2(bounds)); if (likely(lblock->insert(prim))) continue; lblock = lprims_o.insert(alloc.malloc(threadIndex)); lblock->insert(prim); continue; } /* sort to the right side */ if (bin0 >= pos) { rinfo_o.add(bounds,center2(bounds)); if (likely(rblock->insert(prim))) continue; rblock = rprims_o.insert(alloc.malloc(threadIndex)); rblock->insert(prim); continue; } /* split and sort to left and right */ TriangleMesh* mesh = (TriangleMesh*) scene->get(prim.geomID()); TriangleMesh::Triangle tri = mesh->triangle(prim.primID()); const Vec3fa v0 = mesh->vertex(tri.v[0]); const Vec3fa v1 = mesh->vertex(tri.v[1]); const Vec3fa v2 = mesh->vertex(tri.v[2]); PrimRef left,right; float fpos = mapping.pos(pos,dim); splitTriangle(prim,dim,fpos,v0,v1,v2,left,right); if (!left.bounds().empty()) { linfo_o.add(left.bounds(),center2(left.bounds())); if (!lblock->insert(left)) { lblock = lprims_o.insert(alloc.malloc(threadIndex)); lblock->insert(left); } } if (!right.bounds().empty()) { rinfo_o.add(right.bounds(),center2(right.bounds())); if (!rblock->insert(right)) { rblock = rprims_o.insert(alloc.malloc(threadIndex)); rblock->insert(right); } } } alloc.free(threadIndex,block); } }