34 #define EPSILON 1.0e-6f
35 #define ENABLE_ASSERTS 0
41 static const Vec2i edges[] =
48 static const Vec4i faceEdges[] =
56 m_vertices[0].pos =
Vec3f(lo.x, lo.y, lo.z);
57 m_vertices[1].pos =
Vec3f(hi.x, lo.y, lo.z);
58 m_vertices[2].pos =
Vec3f(lo.x, hi.y, lo.z);
59 m_vertices[3].pos =
Vec3f(hi.x, hi.y, lo.z);
60 m_vertices[4].pos =
Vec3f(lo.x, lo.y, hi.z);
61 m_vertices[5].pos =
Vec3f(hi.x, lo.y, hi.z);
62 m_vertices[6].pos =
Vec3f(lo.x, hi.y, hi.z);
63 m_vertices[7].pos =
Vec3f(hi.x, hi.y, hi.z);
66 for (
int i = 0; i < 12; i++)
67 m_edges[i].verts = edges[i];
70 m_faceEdges.resize(24);
71 FaceEdge* faceEdgePtr = m_faceEdges.getPtr();
72 for (
int i = 0; i < 6; i++)
76 f.
planeEq[i >> 1] = ((i & 1) == 0) ? -1.0f : 1.0f;
77 f.
planeEq.w = ((i & 1) == 0) ? -lo[i >> 1] : -hi[i >> 1];
82 for (
int j = 0; j < 4; j++)
83 (faceEdgePtr++)->edge = faceEdges[i][j];
93 for (
int i = m_faces.getSize() - 1; i >= 0; i--)
94 if (planeEq == m_faces[i].planeEq)
100 for (
int i = m_vertices.getSize() - 1; i >= 0; i--)
103 F32 t = planeEq.x * v.
pos.x + planeEq.y * v.
pos.y + planeEq.z * v.
pos.z;
107 culled = (culled || t - eps > 0.0f);
118 int firstNewVertex = m_vertices.getSize();
119 for (
int i = 0; i < m_edges.getSize(); i++)
123 Edge& oldEdge = m_edges[i];
134 oldEdge.
remap = edgeOfs;
135 Edge& newEdge = m_edges[edgeOfs++];
145 newEdge.
verts[(vx.
aux.
orient >= 0.0f) ? 0 : 1] = m_vertices.getSize();
153 int firstNewFaceEdge = m_faceEdges.getSize();
154 for (
int i = m_faces.getSize() - 1; i >= 0; i--)
156 Face& face = m_faces[i];
160 for (
int j = face.
numEdges - 1; j >= 0; j--)
164 int oldIdx = faceEdges[j].
edge;
165 int mask = oldIdx >> 31;
166 int newIdx = m_edges[oldIdx ^
mask].remap;
175 faceEdges[j].
old = newIdx ^
mask;
176 const Vec2i& verts = m_edges[newIdx].verts;
177 if (verts.x >= firstNewVertex)
180 newEdge[mask & 1] = verts.x;
182 else if (verts.y >= firstNewVertex)
185 newEdge[~mask & 1] = verts.y;
192 if (newEdge.x == -1 || newEdge.y == -1)
197 m_faces.removeSwap(i);
202 m_faceEdges.add().old = edgeOfs;
203 if (edgeOfs == m_edges.getSize())
205 m_edges[edgeOfs++].verts = newEdge;
208 m_edges.resize(edgeOfs);
212 Face& newFace = m_faces.add();
216 newFace.
numEdges = m_faceEdges.getSize() - firstNewFaceEdge;
223 for (
int i = m_faces.getSize() - 1; i >= 0; i--)
225 Face& face = m_faces[i];
228 for (
int j = face.
numEdges - 1; j >= 0; j--)
229 m_faceEdges[faceEdgeOfs++].edge = old[j].
old;
231 m_faceEdges[faceEdgeOfs++].edge = ~face.
newEdge;
234 m_faceEdges.resize(faceEdgeOfs);
239 for (
int i = 0; i < m_vertices.getSize(); i++)
242 if (i < firstNewVertex && v.aux.orient >= 0.0
f)
246 m_vertices[vertexOfs++].pos = v.
pos;
248 for (
int i = m_edges.getSize() - 1; i >= 0; i--)
250 Vec2i&
v = m_edges[i].verts;
251 v.x = m_vertices[v.x].aux.remap;
252 v.y = m_vertices[v.y].aux.remap;
254 m_vertices.resize(vertexOfs);
265 bool intersected =
false;
266 for (
int i = 0; i < other.m_faces.getSize(); i++)
267 if (
intersect(other.m_faces[i].planeEq, other.m_faces[i].planeID))
276 if (!m_faces.getSize())
280 const Vec3f& base = m_vertices[0].pos;
282 for (
int i = 0; i < m_faces.getSize(); i++)
284 const Face& face = m_faces[i];
288 for (
int j = 1; j < face.
numEdges; j++)
291 volume +=
cross(m_vertices[v.x].pos - base, m_vertices[v.y].pos - base).dot(first);
294 return volume * (1.0f / 6.0f);
301 const Face& face = m_faces[faceIdx];
306 for (
int i = 1; i < face.
numEdges; i++)
309 area +=
cross(m_vertices[v.x].pos - base, m_vertices[v.y].pos - base).length();
318 const Face& face = m_faces[faceIdx];
324 for (
int i = 1; i < face.
numEdges; i++)
327 const Vec3f& px = m_vertices[v.x].pos;
328 const Vec3f& py = m_vertices[v.y].pos;
329 F32 t =
cross(px - base, py - base).length();
330 pos += (px + py) * t;
333 return pos * (1.0f / 3.0f / area) + base * (1.0
f / 3.0
f);
340 if (!m_faces.getSize())
345 const Vec3f& base = m_vertices[0].pos;
347 for (
int i = 0; i < m_faces.getSize(); i++)
349 const Face& face = m_faces[i];
353 for (
int j = 1; j < face.
numEdges; j++)
356 const Vec3f& px = m_vertices[v.x].pos;
357 const Vec3f& py = m_vertices[v.y].pos;
358 F32 t =
cross(px - base, py - base).dot(first);
359 pos += (px + py + first) * t;
363 return pos * (1.0f / 4.0f / volume) + base * (1.0
f / 2.0
f);
374 for (
int i = m_faces.getSize() - 1; i >= 0; i--)
376 const Face& face = m_faces[i];
380 for (
int j = face.
numEdges - 1; j >= 0; j--)
385 v.
p = m_vertices[base].pos;
389 for (
int j = face.
numEdges - 1; j >= 0; j--)
392 if (e.x != base && e.y != base)
393 inds.
add(
Vec3i(vmap[base], vmap[e.x], vmap[e.y]));
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei const GLvoid pointer GLuint GLuint const GLchar name GLenum GLsizei GLenum GLsizei GLsizei height GLenum GLuint renderbuffer GLenum GLenum GLint params GLuint GLsizei range GLuint GLsizei const GLubyte GLsizei GLenum const GLvoid coords GLuint GLsizei GLsizei GLsizei const GLubyte GLsizei GLenum const GLvoid coords GLuint GLenum GLsizei const GLvoid pathString GLuint GLenum const GLvoid GLbitfield GLuint GLsizei GLenum GLuint GLfloat emScale GLuint GLuint srcPath GLuint GLuint GLenum const GLfloat transformValues GLuint GLenum GLint value GLuint GLenum GLfloat value GLenum GLint GLuint mask
Mesh< VertexPN > * createMesh(void) const
int getEdgeStartVertex(int idx) const
FW_CUDA_FUNC Vec3f getXYZ(void) const
bool intersect(const Vec4f &planeEq, int planeID=-1)
V & addVertex(const V &value)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v
Array< Vec3i > & mutableIndices(int submesh)
FW_CUDA_FUNC S32 abs(S32 a)
FW_CUDA_FUNC F32 fastClamp(F32 v, F32 lo, F32 hi)
void setCube(const Vec3f &lo, const Vec3f &hi)
int numVertices(void) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction f
FW_CUDA_FUNC F32 cross(const Vec2f &a, const Vec2f &b)
union FW::ConvexPolyhedron::Vertex::@0 aux
F32 computeArea(void) const
Vec3f computeCenterOfMass(void) const
Vec2i getEdge(int idx) const
F32 computeVolume(void) const
FW_CUDA_FUNC A lerp(const A &a, const A &b, const B &t)
const Vec3f & getEdgeStartPos(int idx) const