/// mean normal + from center void Sculptor::inflatePoints() { Vector3F nor = m_active->meanNormal; Array<int, VertexP> * vs = m_active->vertices; float wei, round; vs->begin(); while(!vs->end()) { VertexP * l = vs->value(); wei = *l->index->t4; const Vector3F p0(*(l->index->t1)); Vector3F pn = *l->index->t2; /// blow outwards if(pn.dot(nor) < 0.f) pn.reverse(); round = cos(p0.distanceTo(m_active->meanPosition) / selectRadius() * 1.5f ); pn *= round; pn += nor * round; *(l->index->t1) += pn * wei * m_strength * 0.1f; m_tree->displace(l, *(l->index->t1), p0); vs->next(); } smoothPoints(0.4f); }
void ActiveGroup::calculateWeight(Array<int, VertexP> * d) { float wei; d->begin(); while(!d->end()) { Vector3F * p = d->value()->index->t1; if(m_volumeType==VCylinder) { const Vector3F por = incidentRay.closetPointOnRay(*p); wei = m_drop->f(p->distanceTo(por), threshold); } else wei = m_drop->f(p->distanceTo(meanPosition), threshold); *d->value()->index->t4 = wei; d->next(); } }
char VertexPath::recursiveFindClosestNeighbor(unsigned vert, unsigned endVert, const Vector3F & endPoint) { VertexAdjacency adj = m_topology->getAdjacency(vert); Vector3F vertP = *(adj.m_v); unsigned closestNei; float minDist = 10e8; for(VertexAdjacency::VertexNeighbor * nei = adj.firstNeighbor(); !adj.isLastNeighbor(); nei = adj.nextNeighbor()) { if(nei->v->getIndex() == endVert) { m_vertices.push_back(endVert); return 1; } Vector3F p = *(nei->v->m_v); float dist = p.distanceTo(endPoint) + vertP.distanceTo(p); if(dist < minDist) { minDist = dist; closestNei = nei->v->getIndex(); } } m_vertices.push_back(closestNei); if(m_vertices.size() > 64) return 1; return recursiveFindClosestNeighbor(closestNei, endVert, endPoint); }
bool PlantSelection::touchCell(const Ray & incident, const sdb::Coord3 & c, Vector3F & pnt) { sdb::Array<int, Plant> * cell = m_grid->findCell(c); if(!cell) return false; if(cell->isEmpty() ) return false; float tt; cell->begin(); while(!cell->end()) { PlantData * d = cell->value()->index; pnt = incident.closetPointOnRay(d->t1->getTranslation(), &tt ); if(tt < -1.f && pnt.distanceTo(d->t1->getTranslation() ) < m_radius) return true; cell->next(); } return false; }
void ATetrahedronMesh::closestToPoint(unsigned icomponent, ClosestToPointTestResult * result) { if(result->_distance < 0.f) return; Vector3F * p = points(); unsigned * v = tetrahedronIndices(icomponent); Vector3F q[4]; q[0] = p[v[0]]; q[1] = p[v[1]]; q[2] = p[v[2]]; q[3] = p[v[3]]; Float4 coord; if(pointInsideTetrahedronTest(result->_toPoint, q)) { result->_distance = -1.f; result->_hasResult = true; result->_icomponent = icomponent; result->_isInside = true; coord = getBarycentricCoordinate4(result->_toPoint, q); result->_contributes[0] = coord.x; result->_contributes[1] = coord.y; result->_contributes[2] = coord.z; result->_contributes[3] = coord.w; return; } Vector3F clamped = closestPOnTetrahedron(q, result->_toPoint); float d = clamped.distanceTo(result->_toPoint); if(d>=result->_distance) return; result->_distance = d; result->_hasResult = true; result->_icomponent = icomponent; result->_isInside = false; coord = getBarycentricCoordinate4(clamped, q); result->_contributes[0] = coord.x; result->_contributes[1] = coord.y; result->_contributes[2] = coord.z; result->_contributes[3] = coord.w; }