597 static const int MAX_VERTS = 127;
598 static const int MAX_TRIS = 255;
599 static const int MAX_VERTS_PER_EDGE = 32;
600 float edge[(MAX_VERTS_PER_EDGE+1)*3];
606 for (
int i = 0; i < nin; ++i)
607 rcVcopy(&verts[i*3], &in[i*3]);
613 const float cs = chf.
cs;
614 const float ics = 1.0f/cs;
624 for (
int i = 0, j = nin-1; i < nin; j=i++)
626 const float* vj = &in[j*3];
627 const float* vi = &in[i*3];
628 bool swapped =
false;
631 if (fabsf(vj[0]-vi[0]) < 1e-6f)
648 float dx = vi[0] - vj[0];
649 float dy = vi[1] - vj[1];
650 float dz = vi[2] - vj[2];
651 float d = sqrtf(dx*dx + dz*dz);
652 int nn = 1 + (int)floorf(d/sampleDist);
653 if (nn >= MAX_VERTS_PER_EDGE) nn = MAX_VERTS_PER_EDGE-1;
654 if (nverts+nn >= MAX_VERTS)
655 nn = MAX_VERTS-1-nverts;
657 for (
int k = 0; k <= nn; ++k)
659 float u = (float)k/(
float)nn;
660 float* pos = &edge[k*3];
661 pos[0] = vj[0] + dx*u;
662 pos[1] = vj[1] + dy*u;
663 pos[2] = vj[2] + dz*u;
664 pos[1] =
getHeight(pos[0],pos[1],pos[2], cs, ics, chf.
ch, hp)*chf.
ch;
667 int idx[MAX_VERTS_PER_EDGE] = {0,nn};
669 for (
int k = 0; k < nidx-1; )
671 const int a = idx[k];
672 const int b = idx[k+1];
673 const float* va = &edge[a*3];
674 const float* vb = &edge[b*3];
678 for (
int m = a+1; m < b; ++m)
689 if (maxi != -1 && maxd >
rcSqr(sampleMaxError))
691 for (
int m = nidx; m > k; --m)
706 for (
int k = nidx-2; k > 0; --k)
708 rcVcopy(&verts[nverts*3], &edge[idx[k]*3]);
709 hull[nhull++] = nverts;
715 for (
int k = 1; k < nidx-1; ++k)
717 rcVcopy(&verts[nverts*3], &edge[idx[k]*3]);
718 hull[nhull++] = nverts;
726 if (minExtent < sampleDist*2)
738 if (tris.
size() == 0)
741 ctx->
log(
RC_LOG_WARNING,
"buildPolyDetail: Could not triangulate polygon (%d verts).", nverts);
748 float bmin[3], bmax[3];
751 for (
int i = 1; i < nin; ++i)
756 int x0 = (int)floorf(bmin[0]/sampleDist);
757 int x1 = (int)ceilf(bmax[0]/sampleDist);
758 int z0 = (int)floorf(bmin[2]/sampleDist);
759 int z1 = (int)ceilf(bmax[2]/sampleDist);
761 for (
int z = z0;
z < z1; ++
z)
763 for (
int x = x0;
x < x1; ++
x)
766 pt[0] =
x*sampleDist;
767 pt[1] = (bmax[1]+bmin[1])*0.5f;
768 pt[2] =
z*sampleDist;
770 if (
distToPoly(nin,in,pt) > -sampleDist/2)
continue;
781 const int nsamples = samples.
size()/4;
782 for (
int iter = 0; iter < nsamples; ++iter)
784 if (nverts >= MAX_VERTS)
788 float bestpt[3] = {0,0,0};
791 for (
int i = 0; i < nsamples; ++i)
793 const int* s = &samples[i*4];
798 pt[0] = s[0]*sampleDist +
getJitterX(i)*cs*0.1f;
800 pt[2] = s[2]*sampleDist +
getJitterY(i)*cs*0.1f;
811 if (bestd <= sampleMaxError || besti == -1)
814 samples[besti*4+3] = 1;
816 rcVcopy(&verts[nverts*3],bestpt);
823 delaunayHull(ctx, nverts, verts, nhull, hull, tris, edges);
827 const int ntris = tris.
size()/4;
828 if (ntris > MAX_TRIS)
831 ctx->
log(
RC_LOG_ERROR,
"rcBuildPolyMeshDetail: Shrinking triangle count from %d to max %d.", ntris, MAX_TRIS);
static float distToTriMesh(const float *p, const float *verts, const int, const int *tris, const int ntris)
Definition: RecastMeshDetail.cpp:169
static void triangulateHull(const int, const float *verts, const int nhull, const int *hull, rcIntArray &tris)
Definition: RecastMeshDetail.cpp:514
void rcSwap(T &a, T &b)
Definition: Recast.h:560
int size() const
The current size of the integer array.
Definition: RecastAlloc.h:100
void rcVmin(float *mn, const float *v)
Definition: Recast.h:657
An error log entry.
Definition: Recast.h:31
static float distToPoly(int nvert, const float *verts, const float *p)
Definition: RecastMeshDetail.cpp:185
static float distancePtSeg(const float *pt, const float *p, const float *q)
Definition: RecastMeshDetail.cpp:124
G3D::int16 z
Definition: Vector3int16.h:46
static void delaunayHull(rcContext *ctx, const int npts, const float *pts, const int nhull, const int *hull, rcIntArray &tris, rcIntArray &edges)
Definition: RecastMeshDetail.cpp:413
float getJitterY(const int i)
Definition: RecastMeshDetail.cpp:586
void rcVcopy(float *dest, const float *v)
Definition: Recast.h:677
float getJitterX(const int i)
Definition: RecastMeshDetail.cpp:581
T rcSqr(T a)
Definition: Recast.h:582
float cs
The size of each cell. (On the xz-plane.)
Definition: Recast.h:317
float ch
The height of each cell. (The minimum increment along the y-axis.)
Definition: Recast.h:318
void log(const rcLogCategory category, const char *format,...)
Definition: Recast.cpp:55
G3D::int16 x
Definition: Vector2int16.h:37
static unsigned short getHeight(const float fx, const float fy, const float fz, const float, const float ics, const float ch, const rcHeightPatch &hp)
Definition: RecastMeshDetail.cpp:203
A warning log entry.
Definition: Recast.h:30
static float polyMinExtent(const float *verts, const int nverts)
Definition: RecastMeshDetail.cpp:490
void resize(int n)
Definition: RecastAlloc.cpp:75
void push(int item)
Definition: RecastAlloc.h:83
void rcVmax(float *mx, const float *v)
Definition: Recast.h:667