30 int3(
int _x,
int _y,
int _z)
74 potentialVertex += n3n1;
75 potentialVertex += n1n2;
76 potentialVertex *= quotient;
78 btVector3 result(potentialVertex.getX(), potentialVertex.getY(), potentialVertex.getZ());
93 return p0 + (dif * t);
114 cp =
btCross(udir, vdir).normalized();
139#define SPLIT (OVER | UNDER)
140#define PAPERWIDTH (btScalar(0.001))
149 edges.resize(edges_size);
150 facets.resize(facets_size);
207 for (
int i = 0; i <
count; i++)
210 if (m == -1 ||
btDot(p[i], dir) >
btDot(p[m], dir))
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;
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;
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;
406 btHullTriangle *tr =
new (mem) btHullTriangle(a,
b, c);
407 tr->
id = m_tris.size();
408 m_tris.push_back(tr);
424 int n = m_tris.size();
425 btHullTriangle *ta = allocateTriangle(
v, t[1], t[2]);
426 ta->
n =
int3(t0->
n[0], n + 1, n + 2);
427 m_tris[t0->
n[0]]->neib(t[1], t[2]) = n + 0;
428 btHullTriangle *tb = allocateTriangle(
v, t[2], t[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;
431 btHullTriangle *tc = allocateTriangle(
v, t[0], t[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);
446 btHullTriangle *t =
NULL;
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;
504 btAlignedObjectArray<int> isextreme;
505 isextreme.
reserve(verts_count);
506 btAlignedObjectArray<int> allow;
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;
523 btHullTriangle *t0 = allocateTriangle(p[2], p[3], p[1]);
524 t0->
n =
int3(2, 3, 1);
525 btHullTriangle *t1 = allocateTriangle(p[3], p[2], p[0]);
526 t1->
n =
int3(3, 2, 0);
527 btHullTriangle *t2 = allocateTriangle(p[0], p[1], p[3]);
528 t2->
n =
int3(0, 1, 3);
529 btHullTriangle *t3 = allocateTriangle(p[1], p[0], p[2]);
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++)
539 btHullTriangle *t = m_tris[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];
575 btHullTriangle *nb = m_tris[m_tris[j]->n[0]];
586 btHullTriangle *t = m_tris[j];
588 if (t->
vmax >= 0)
break;
591 if (isextreme[t->
vmax])
607 int rc = calchullgen(
verts, verts_count, vlimit);
609 btAlignedObjectArray<int> ts;
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]);
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;
648 if (
result.m_Indices.size())
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);
717 result.mNumOutputVertices = ovcount;
718 result.m_OutputVertices.resize(
static_cast<int>(ovcount));
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++)
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())
819 return dx * dx + dy * dy + dz * dz;
822bool HullLibrary::CleanupVertices(
unsigned int svcount,
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++)
957 for (j = 0; j < vcount; j++)
970 if (dx < normalepsilon && dy < normalepsilon && dz < normalepsilon)
1008 for (
unsigned int i = 0; i < vcount; 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)
1074 btAlignedObjectArray<int> tmpIndices;
1084 usedIndices.
resize(
static_cast<int>(vcount));
1085 memset(&usedIndices[0], 0,
sizeof(
unsigned int) * vcount);
1089 for (i = 0; i <
int(indexcount); i++)
1095 if (usedIndices[
static_cast<int>(
v)])
1097 indices[i] = usedIndices[
static_cast<int>(
v)] - 1;
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;
VecBase< int32_t, 4 > int4
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
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)
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)
btAlignedObjectArray< unsigned int > TUIntArray
includes modifications/improvements by John Ratcliff, see BringOutYourDead below.
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.
VecBase< int32_t, 3 > int3
btAlignedObjectArray< HalfEdge > edges
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.
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)