30 int3(
int _x,
int _y,
int _z)
73 btVector3 potentialVertex = n2n3;
74 potentialVertex += n3n1;
75 potentialVertex += n1n2;
76 potentialVertex *= quotient;
78 btVector3
result(potentialVertex.getX(), potentialVertex.getY(), potentialVertex.getZ());
82btScalar DistanceBetweenLines(
const btVector3 &ustart,
const btVector3 &udir,
const btVector3 &vstart,
const btVector3 &vdir, btVector3 *upoint =
NULL, btVector3 *vpoint =
NULL);
83btVector3
TriNormal(
const btVector3 &v0,
const btVector3 &v1,
const btVector3 &
v2);
84btVector3
NormalOf(
const btVector3 *vert,
const int n);
93 return p0 + (dif * t);
98 return point - plane.normal * (
btDot(point, plane.normal) + plane.dist);
101btVector3
TriNormal(
const btVector3 &v0,
const btVector3 &v1,
const btVector3 &
v2)
105 btVector3 cp =
btCross(v1 - v0,
v2 - v1);
111btScalar DistanceBetweenLines(
const btVector3 &ustart,
const btVector3 &udir,
const btVector3 &vstart,
const btVector3 &vdir, btVector3 *upoint, btVector3 *vpoint)
114 cp =
btCross(udir, vdir).normalized();
123 plane.dist = -
btDot(plane.normal, vstart);
130 plane.dist = -
btDot(plane.normal, ustart);
139#define SPLIT (OVER | UNDER)
140#define PAPERWIDTH (btScalar(0.001))
148 vertices.resize(vertices_size);
149 edges.resize(edges_size);
207 for (
int i = 0; i <
count; i++)
210 if (m == -1 ||
btDot(p[i], dir) >
btDot(p[m], dir))
217btVector3
orth(
const btVector3 &
v);
222 if (a.length() >
b.length())
224 return a.normalized();
228 return b.normalized();
239 if (allow[m] == 3)
return m;
248 if (ma == m && mb == m)
253 if (ma != -1 && ma != mb)
261 if (mc == m && md == m)
281 for (
int i = 0; i < 3; i++)
283 if (a[i] !=
b[i])
return 0;
288int above(btVector3 *vertices,
const int3 &t,
const btVector3 &p,
btScalar epsilon);
291 btVector3 n =
TriNormal(vertices[t[0]], vertices[t[1]], vertices[t[2]]);
292 return (
btDot(n, p - vertices[t[0]]) > epsilon);
297 for (
int i = 0; i < 3; i++)
299 int i1 = (i + 1) % 3;
300 if (t[i] == a && t[i1] ==
b)
return 1;
307 return (t[0] ==
v || t[1] ==
v || t[2] ==
v);
313 for (i = 0; i < 3; i++)
315 int i1 = (i + 1) % 3;
338 int &
neib(
int a,
int b);
345 for (i = 0; i < 3; i++)
347 int i1 = (i + 1) % 3;
348 int i2 = (i + 2) % 3;
349 if ((*
this)[i] == a && (*this)[i1] ==
b)
return n[i2];
350 if ((*
this)[i] ==
b && (*this)[i1] == a)
return n[i2];
358 for (i = 0; i < 3; i++)
360 int i1 = (i + 1) % 3;
361 int i2 = (i + 2) % 3;
364 btAssert(m_tris[s->neib(a,
b)]->neib(
b, a) == s->id);
366 m_tris[s->neib(a,
b)]->neib(
b, a) = t->
neib(
b, a);
367 m_tris[t->
neib(
b, a)]->neib(a,
b) = s->neib(a,
b);
374 deAllocateTriangle(s);
376 deAllocateTriangle(t);
385 for (i = 0; i < 3; i++)
387 int i1 = (i + 1) % 3;
388 int i2 = (i + 2) % 3;
424 int n = m_tris.
size();
426 ta->
n =
int3(t0->
n[0], n + 1, n + 2);
427 m_tris[t0->
n[0]]->neib(t[1], t[2]) = n + 0;
429 tb->
n =
int3(t0->
n[1], n + 2, n + 0);
430 m_tris[t0->
n[1]]->neib(t[2], t[0]) = n + 1;
432 tc->
n =
int3(t0->
n[2], n + 0, n + 1);
433 m_tris[t0->
n[2]]->neib(t[0], t[1]) = n + 2;
437 if (
hasvert(*m_tris[ta->
n[0]],
v)) removeb2b(ta, m_tris[ta->
n[0]]);
438 if (
hasvert(*m_tris[tb->
n[0]],
v)) removeb2b(tb, m_tris[tb->
n[0]]);
439 if (
hasvert(*m_tris[tc->
n[0]],
v)) removeb2b(tc, m_tris[tc->
n[0]]);
440 deAllocateTriangle(t0);
447 for (i = 0; i < m_tris.
size(); i++)
449 if (!t || (m_tris[i] && t->
rise < m_tris[i]->rise))
454 return (t->
rise > epsilon) ? t :
NULL;
464 if (p0 == p1 || basis[0] ==
btVector3(0, 0, 0))
465 return int4(-1, -1, -1, -1);
470 basis[1].normalize();
475 basis[1].normalize();
478 if (p2 == p0 || p2 == p1)
482 if (p2 == p0 || p2 == p1)
483 return int4(-1, -1, -1, -1);
485 basis[2] =
btCross(basis[1], basis[0]).normalized();
487 if (p3 == p0 || p3 == p1 || p3 == p2) p3 =
maxdirsterid(
verts, verts_count, -basis[2], allow);
488 if (p3 == p0 || p3 == p1 || p3 == p2)
489 return int4(-1, -1, -1, -1);
490 btAssert(!(p0 == p1 || p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3 || p2 == p3));
495 return int4(p0, p1, p2, p3);
498int HullLibrary::calchullgen(btVector3 *
verts,
int verts_count,
int vlimit)
500 if (verts_count < 4)
return 0;
501 if (vlimit == 0) vlimit = 1000000000;
505 isextreme.
reserve(verts_count);
509 for (j = 0; j < verts_count; j++)
513 bmin.setMin(
verts[j]);
514 bmax.setMax(
verts[j]);
519 int4 p = FindSimplex(
verts, verts_count, allow);
520 if (p.
x == -1)
return 0;
524 t0->
n =
int3(2, 3, 1);
526 t1->
n =
int3(3, 2, 0);
528 t2->
n =
int3(0, 1, 3);
530 t3->
n =
int3(1, 0, 2);
531 isextreme[p[0]] = isextreme[p[1]] = isextreme[p[2]] = isextreme[p[3]] = 1;
537 for (j = 0; j < m_tris.
size(); j++)
548 while (vlimit > 0 && ((te = extrudable(epsilon)) != 0))
559 if (!m_tris[j])
continue;
563 extrude(m_tris[j],
v);
570 if (!m_tris[j])
continue;
572 int3 nt = *m_tris[j];
588 if (t->
vmax >= 0)
break;
591 if (isextreme[t->
vmax])
605int HullLibrary::calchull(btVector3 *
verts,
int verts_count,
TUIntArray &tris_out,
int &tris_count,
int vlimit)
607 int rc = calchullgen(
verts, verts_count, vlimit);
612 for (i = 0; i < m_tris.
size(); i++)
616 for (
int j = 0; j < 3; j++)
618 deAllocateTriangle(m_tris[i]);
621 tris_count = ts.
size() / 3;
624 for (i = 0; i < ts.
size(); i++)
626 tris_out[i] =
static_cast<unsigned int>(ts[i]);
633bool HullLibrary::ComputeHull(
unsigned int vcount,
const btVector3 *vertices,
PHullResult &result,
unsigned int vlimit)
636 int ret = calchull((btVector3 *)vertices, (
int)vcount, result.m_Indices, tris_count,
static_cast<int>(vlimit));
637 if (!
ret)
return false;
638 result.mIndexCount = (
unsigned int)(tris_count * 3);
639 result.mFaceCount = (
unsigned int)tris_count;
640 result.mVertices = (btVector3 *)vertices;
641 result.mVcount = (
unsigned int)vcount;
648 if (result.m_Indices.size())
650 result.m_Indices.clear();
654 result.mIndexCount = 0;
655 result.mVertices = 0;
677 unsigned int vcount = desc.
mVcount;
678 if (vcount < 8) vcount = 8;
681 vertexSource.
resize(
static_cast<int>(vcount));
685 unsigned int ovcount;
693 for (
unsigned int i = 0; i < ovcount; i++)
695 btVector3 &
v = vertexSource[
static_cast<int>(i)];
702 ok = ComputeHull(ovcount, &vertexSource[0], hr, desc.
mMaxVertices);
716 result.mPolygons =
false;
717 result.mNumOutputVertices = ovcount;
718 result.m_OutputVertices.resize(
static_cast<int>(ovcount));
722 result.m_Indices.resize(
static_cast<int>(hr.
mIndexCount));
724 memcpy(&result.m_OutputVertices[0], &vertexScratch[0],
sizeof(btVector3) * ovcount);
728 const unsigned int *source = &hr.
m_Indices[0];
729 unsigned int *dest = &result.m_Indices[0];
731 for (
unsigned int i = 0; i < hr.
mFaceCount; i++)
747 result.mPolygons =
true;
748 result.mNumOutputVertices = ovcount;
749 result.m_OutputVertices.resize(
static_cast<int>(ovcount));
752 result.m_Indices.resize(
static_cast<int>(result.mNumIndices));
753 memcpy(&result.m_OutputVertices[0], &vertexScratch[0],
sizeof(btVector3) * ovcount);
757 const unsigned int *source = &hr.
m_Indices[0];
758 unsigned int *dest = &result.m_Indices[0];
759 for (
unsigned int i = 0; i < hr.
mFaceCount; i++)
789 if (result.m_OutputVertices.size())
791 result.mNumOutputVertices = 0;
792 result.m_OutputVertices.clear();
794 if (result.m_Indices.size())
796 result.mNumIndices = 0;
797 result.m_Indices.clear();
805 btVector3 &dest = p[vcount];
819 return dx * dx + dy * dy + dz * dz;
822bool HullLibrary::CleanupVertices(
unsigned int svcount,
823 const btVector3 *svertices,
825 unsigned int &vcount,
830 if (svcount == 0)
return false;
834#define EPSILON btScalar(0.000001)
838 btScalar recip[3] = {0.f, 0.f, 0.f};
850 const char *vtx = (
const char *)svertices;
854 for (
unsigned int i = 0; i < svcount; i++)
860 for (
int j = 0; j < 3; j++)
862 if (p[j] < bmin[j]) bmin[j] = p[j];
863 if (p[j] > bmax[j]) bmax[j] = p[j];
874 center[0] = dx *
btScalar(0.5) + bmin[0];
875 center[1] = dy *
btScalar(0.5) + bmin[1];
876 center[2] = dz *
btScalar(0.5) + bmin[2];
906 addPoint(vcount, vertices, x1, y1, z1);
907 addPoint(vcount, vertices, x2, y1, z1);
908 addPoint(vcount, vertices, x2, y2, z1);
909 addPoint(vcount, vertices, x1, y2, z1);
910 addPoint(vcount, vertices, x1, y1, z2);
911 addPoint(vcount, vertices, x2, y1, z2);
912 addPoint(vcount, vertices, x2, y2, z2);
913 addPoint(vcount, vertices, x1, y2, z2);
929 center[0] *= recip[0];
930 center[1] *= recip[1];
931 center[2] *= recip[2];
935 vtx = (
const char *)svertices;
937 for (
unsigned int i = 0; i < svcount; i++)
939 const btVector3 *p = (
const btVector3 *)vtx;
957 for (j = 0; j < vcount; j++)
960 btVector3 &
v = vertices[j];
970 if (dx < normalepsilon && dy < normalepsilon && dz < normalepsilon)
992 btVector3 &dest = vertices[vcount];
1008 for (
unsigned int i = 0; i < vcount; i++)
1010 const btVector3 &p = vertices[i];
1011 for (
int j = 0; j < 3; j++)
1013 if (p[j] < bmin[j]) bmin[j] = p[j];
1014 if (p[j] > bmax[j]) bmax[j] = p[j];
1056 addPoint(vcount, vertices, x1, y1, z1);
1057 addPoint(vcount, vertices, x2, y1, z1);
1058 addPoint(vcount, vertices, x2, y2, z1);
1059 addPoint(vcount, vertices, x1, y2, z1);
1060 addPoint(vcount, vertices, x1, y1, z2);
1061 addPoint(vcount, vertices, x2, y1, z2);
1062 addPoint(vcount, vertices, x2, y2, z2);
1063 addPoint(vcount, vertices, x1, y2, z2);
1072void HullLibrary::BringOutYourDead(
const btVector3 *
verts,
unsigned int vcount, btVector3 *overts,
unsigned int &ocount,
unsigned int *indices,
unsigned indexcount)
1084 usedIndices.
resize(
static_cast<int>(vcount));
1085 memset(&usedIndices[0], 0,
sizeof(
unsigned int) * vcount);
1089 for (i = 0; i <
int(indexcount); i++)
1091 unsigned int v = indices[i];
1095 if (usedIndices[
static_cast<int>(
v)])
1097 indices[i] = usedIndices[
static_cast<int>(
v)] - 1;
1101 indices[i] = ocount;
1103 overts[ocount][0] =
verts[
v][0];
1104 overts[ocount][1] =
verts[
v][1];
1105 overts[ocount][2] =
verts[
v][2];
1109 if (tmpIndices[k] ==
int(
v))
1115 btAssert(ocount >= 0 && ocount <= vcount);
1117 usedIndices[
static_cast<int>(
v)] = ocount;
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
void addPoint(const btVector3 &point, bool recalculateLocalAabb=true)
ConvexH::HalfEdge HalfEdge
btVector3 ThreePlaneIntersection(const btPlane &p0, const btPlane &p1, const btPlane &p2)
btScalar DistanceBetweenLines(const btVector3 &ustart, const btVector3 &udir, const btVector3 &vstart, const btVector3 &vdir, btVector3 *upoint=NULL, btVector3 *vpoint=NULL)
int maxdirsterid(const T *p, int count, const T &dir, btAlignedObjectArray< int > &allow)
btVector3 PlaneLineIntersection(const btPlane &plane, const btVector3 &p0, const btVector3 &p1)
static void addPoint(unsigned int &vcount, btVector3 *p, btScalar x, btScalar y, btScalar z)
int operator==(const btPlane &a, const btPlane &b)
void ReleaseHull(PHullResult &result)
int hasvert(const int3 &t, int v)
btPlane PlaneFlip(const btPlane &plane)
btVector3 NormalOf(const btVector3 *vert, const int n)
int coplanar(const btPlane &a, const btPlane &b)
btVector3 PlaneProject(const btPlane &plane, const btVector3 &point)
int maxdirfiltered(const T *p, int count, const T &dir, btAlignedObjectArray< int > &allow)
btVector3 TriNormal(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2)
int SplitTest(ConvexH &convex, const btPlane &plane)
int hasedge(const int3 &t, int a, int b)
int above(btVector3 *vertices, const int3 &t, const btVector3 &p, btScalar epsilon)
btScalar planetestepsilon
int PlaneTest(const btPlane &p, const btVector3 &v)
btScalar GetDist(btScalar px, btScalar py, btScalar pz, const btScalar *p2)
int shareedge(const int3 &a, const int3 &b)
btVector3 orth(const btVector3 &v)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE btScalar btCos(btScalar x)
#define SIMD_RADS_PER_DEG
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
SIMD_FORCE_INLINE btScalar btSin(btScalar x)
SIMD_FORCE_INLINE btScalar btFabs(btScalar x)
SIMD_FORCE_INLINE void btSwap(T &a, T &b)
SIMD_FORCE_INLINE btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
SIMD_FORCE_INLINE btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors.
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
btAlignedObjectArray< btPlane > facets
btAlignedObjectArray< btVector3 > vertices
bool HasHullFlag(HullFlag flag) const
unsigned int mMaxVertices
const btVector3 * mVertices
unsigned int mVertexStride
HullError ReleaseResult(HullResult &result)
HullError CreateConvexHull(const HullDesc &desc, HullResult &result)
btAlignedObjectArray< int > m_vertexIndexMapping
SIMD_FORCE_INLINE void reserve(int _Count)
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
SIMD_FORCE_INLINE void resize(int newsize, const T &fillData=T())
SIMD_FORCE_INLINE void push_back(const T &_Val)
btHullTriangle(int a, int b, int c)
const int & operator[](int i) const
int3(int _x, int _y, int _z)
local_group_size(16, 16) .push_constant(Type b
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float2 fabs(const float2 a)
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.