183 NSCParameterAssert(data != NULL);
187 data->pendingCapacity = capacity;
188 data->triangles = data->smallData;
197 NSCAssert(data->triangles != kScribbleValue,
@"Attempt to destroy a GeometryData twice.");
202 free(data->triangles);
206 data->triangles = kScribbleValue;
212 NSCParameterAssert(data != NULL);
214 if (data->count < data->capacity) {
215 data->triangles[data->count++] = tri;
223- (id)initWithCapacity:(NSUInteger)capacity
225 NSParameterAssert(capacity < UINT32_MAX);
229 if ((
self = [super init])) {
243+ (instancetype)converterWithCapacity:(NSUInteger)capacity
245 return [[[
self alloc] initWithCapacity:capacity] autorelease];
250 return [
NSString stringWithFormat:@"%u triangles", _data.count];
260- (
Octree*)findOctreeToDepth:(NSUInteger)depth
274 NSCParameterAssert(data != NULL);
278 for (i = 0; i < data->count; i++)
279 for (j = 0; j < 3; j++) {
280 Vector v = data->triangles[i].v[j];
282 result = fmax(result, fabs(v.
x));
283 result = fmax(result, fabs(v.
y));
284 result = fmax(result, fabs(v.
z));
291 NSCParameterAssert(data != NULL);
293 OOScalar subHalfWidth = 0.5f * halfWidth;
295 if (data->count == 0) {
342 uint32_t subCapacity = data->count * kFactor;
344#define DECL_GEOMETRY(NAME, CAP) \
346 InitGeometryData(&NAME, CAP);
361 if (g_xx0.count != 0) {
366 if (g_x00.count != 0) {
369 if (g_x10.count != 0) {
375 if (g_xx1.count != 0) {
380 if (g_x01.count != 0) {
383 if (g_x11.count != 0) {
416 NSCParameterAssert(data != NULL);
420 uint32_t i,
count = data->count;
421 for (i = 0; i <
count; i++) {
422 data->triangles[i].v[0].x +=
offset;
423 data->triangles[i].v[1].x +=
offset;
424 data->triangles[i].v[2].x +=
offset;
430 NSCParameterAssert(data != NULL);
434 uint32_t i,
count = data->count;
435 for (i = 0; i <
count; i++) {
436 data->triangles[i].v[0].y +=
offset;
437 data->triangles[i].v[1].y +=
offset;
438 data->triangles[i].v[2].y +=
offset;
444 NSCParameterAssert(data != NULL);
448 uint32_t i,
count = data->count;
449 for (i = 0; i <
count; i++) {
450 data->triangles[i].v[0].z +=
offset;
451 data->triangles[i].v[1].z +=
offset;
452 data->triangles[i].v[2].z +=
offset;
458 NSCParameterAssert(data != NULL && dPlus != NULL && dMinus != NULL);
461 uint32_t i,
count = data->count;
462 for (i = 0; i <
count; i++) {
463 bool done_tri =
false;
464 Vector v0 = data->triangles[i].v[0];
465 Vector v1 = data->triangles[i].v[1];
466 Vector v2 = data->triangles[i].v[2];
468 if (v0.
x >= 0.0f && v1.
x >= 0.0f && v2.
x >= 0.0f) {
471 }
else if (v0.
x <= 0.0f && v1.
x <= 0.0f && v2.
x <= 0.0f) {
481 i01 = v0.
x / (v0.
x - v1.
x);
485 i12 = v1.
x / (v1.
x - v2.
x);
489 i20 = v2.
x / (v2.
x - v0.
x);
524 if (v0.
x > 0.0f && v1.
x > 0.0f && v2.
x < 0.0f) {
530 if (v0.
x > 0.0f && v1.
x < 0.0f && v2.
x > 0.0f) {
536 if (v0.
x > 0.0f && v1.
x < 0.0f && v2.
x < 0.0f) {
542 if (v0.
x < 0.0f && v1.
x > 0.0f && v2.
x > 0.0f) {
548 if (v0.
x < 0.0f && v1.
x > 0.0f && v2.
x < 0.0f) {
554 if (v0.
x < 0.0f && v1.
x < 0.0f && v2.
x > 0.0f) {
567 NSCParameterAssert(data != NULL && dPlus != NULL && dMinus != NULL);
570 uint32_t i,
count = data->count;
571 for (i = 0; i <
count; i++) {
572 bool done_tri =
false;
573 Vector v0 = data->triangles[i].v[0];
574 Vector v1 = data->triangles[i].v[1];
575 Vector v2 = data->triangles[i].v[2];
577 if (v0.
y >= 0.0f && v1.
y >= 0.0f && v2.
y >= 0.0f) {
581 if (v0.
y <= 0.0f && v1.
y <= 0.0f && v2.
y <= 0.0f) {
592 i01 = v0.
y / (v0.
y - v1.
y);
596 i12 = v1.
y / (v1.
y - v2.
y);
600 i20 = v2.
y / (v2.
y - v0.
y);
635 if (v0.
y > 0.0f && v1.
y > 0.0f && v2.
y < 0.0f) {
641 if (v0.
y > 0.0f && v1.
y < 0.0f && v2.
y > 0.0f) {
647 if (v0.
y > 0.0f && v1.
y < 0.0f && v2.
y < 0.0f) {
653 if (v0.
y < 0.0f && v1.
y > 0.0f && v2.
y > 0.0f) {
659 if (v0.
y < 0.0f && v1.
y > 0.0f && v2.
y < 0.0f) {
665 if (v0.
y < 0.0f && v1.
y < 0.0f && v2.
y > 0.0f) {
678 NSCParameterAssert(data != NULL && dPlus != NULL && dMinus != NULL);
681 uint32_t i,
count = data->count;
682 for (i = 0; i <
count; i++) {
683 bool done_tri =
false;
684 Vector v0 = data->triangles[i].v[0];
685 Vector v1 = data->triangles[i].v[1];
686 Vector v2 = data->triangles[i].v[2];
688 if (v0.
z >= 0.0f && v1.
z >= 0.0f && v2.
z >= 0.0f) {
691 }
else if (v0.
z <= 0.0f && v1.
z <= 0.0f && v2.
z <= 0.0f) {
702 i01 = v0.
z / (v0.
z - v1.
z);
706 i12 = v1.
z / (v1.
z - v2.
z);
710 i20 = v2.
z / (v2.
z - v0.
z);
745 if (v0.
z > 0.0f && v1.
z > 0.0f && v2.
z < 0.0f) {
751 if (v0.
z > 0.0f && v1.
z < 0.0f && v2.
z > 0.0f) {
757 if (v0.
z > 0.0f && v1.
z < 0.0f && v2.
z < 0.0f) {
763 if (v0.
z < 0.0f && v1.
z > 0.0f && v2.
z > 0.0f) {
769 if (v0.
z < 0.0f && v1.
z > 0.0f && v2.
z < 0.0f) {
775 if (v0.
z < 0.0f && v1.
z < 0.0f && v2.
z > 0.0f) {
804 NSCParameterAssert(data != NULL);
805 NSCParameterAssert(data->count == data->capacity);
809 data->triangles = malloc(data->capacity *
sizeof(
Triangle));
810 memcpy(data->triangles, data->smallData,
sizeof data->smallData);
813 data->capacity = 1 + data->capacity * 2;
814 data->triangles = realloc(data->triangles, data->capacity *
sizeof(
Triangle));
824 data->triangles[data->count++] = tri;
#define OOLog(class, format,...)
NSString *const kOOLogAllocationFailure
@ kOOMeshToOctreeConverterSmallDataCapacity
static void SplitGeometryX(GeometryData *data, GeometryData *dPlus, GeometryData *dMinus, OOScalar x)
#define DECL_GEOMETRY(NAME, CAP)
OOINLINE void DestroyGeometryData(GeometryData *data)
static void TranslateGeometryZ(GeometryData *data, OOScalar offset)
static NO_INLINE_FUNC void AddTriangle_slow(GeometryData *data, Triangle tri)
static void TranslateGeometryX(GeometryData *data, OOScalar offset)
static void SplitGeometryY(GeometryData *data, GeometryData *dPlus, GeometryData *dMinus, OOScalar y)
OOINLINE void AddTriangle(GeometryData *data, Triangle tri)
void BuildSubOctree(GeometryData *data, OOOctreeBuilder *builder, OOScalar halfWidth, NSUInteger depth)
OOINLINE void InitGeometryData(GeometryData *data, uint32_t capacity)
static void TranslateGeometryY(GeometryData *data, OOScalar offset)
static OOScalar MaxDimensionFromOrigin(GeometryData *data)
struct OOMeshToOctreeConverterInternalData GeometryData
static void SplitGeometryZ(GeometryData *data, GeometryData *dPlus, GeometryData *dMinus, OOScalar z)
OOINLINE bool OOTriangleIsDegenerate(Triangle tri) CONST_FUNC
OOINLINE Triangle make_triangle(Vector v0, Vector v1, Vector v2) CONST_FUNC
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
#define OCTREE_MIN_HALF_WIDTH
NSString * descriptionComponents()
struct OOMeshToOctreeConverter::OOMeshToOctreeConverterInternalData _data
Octree * buildOctreeWithRadius:(GLfloat radius)