Fix branch wrapping #32

In this commit, the wrapping algorithm consider the position of neighbor's neighbor, so the cut normal of branch nodes would looks more natural. This commit also fix the radius calculation of the branch face.
Thanks @KeepFenDou for pointing out this issue.
master
Jeremy Hu 2019-05-28 23:49:50 +09:30
parent 7c068466e8
commit 63d32781c1
3 changed files with 22 additions and 4 deletions

View File

@ -1,3 +1,12 @@
Changes between 1.0.0-beta.16 and 1.0.0-beta.17:
--------------------------------------------------
- Remote IO Protocol
- Uncombined Mode
- User Defined Cut Face
- Base Plane Constrain
- Color Solubility
- Crash Fix
Changes between 1.0.0-beta.15 and 1.0.0-beta.16:
--------------------------------------------------
- Support onion skinning in pose editor

View File

@ -26,4 +26,5 @@ boynet <https://dust3d.discourse.group/u/boynet>
fornclake <https://www.reddit.com/user/fornclake>
bvanevery <https://www.reddit.com/user/bvanevery>
Toshio Araki <https://github.com/Toshiwoz>
Evan Gruda <evangruda@ufl.edu>
Evan Gruda <evangruda@ufl.edu>
KeepFenDou <https://github.com/huxingyi/dust3d/issues/32>

View File

@ -456,15 +456,23 @@ bool Builder::tryWrapMultipleBranchesForNode(size_t nodeIndex, std::vector<float
std::vector<std::pair<std::vector<size_t>, QVector3D>> cutsForEdges;
bool directSwallowed = false;
for (size_t i = 0; i < node.edges.size(); ++i) {
const QVector3D &cutNormal = node.raysToNeibors[i];
QVector3D cutNormal = node.raysToNeibors[i];
size_t edgeIndex = node.edges[i];
size_t neighborIndex = m_edges[edgeIndex].neiborOf(nodeIndex);
const auto &neighbor = m_nodes[neighborIndex];
if (neighbor.edges.size() == 2) {
size_t anotherEdgeIndex = neighbor.anotherEdge(edgeIndex);
size_t neighborsNeighborIndex = m_edges[anotherEdgeIndex].neiborOf(neighborIndex);
const auto &neighborsNeighbor = m_nodes[neighborsNeighborIndex];
cutNormal = ((cutNormal + (neighborsNeighbor.position - neighbor.position).normalized()) * 0.5).normalized();
}
float distance = (neighbor.position - node.position).length();
if (qFuzzyIsNull(distance))
distance = 0.0001f;
float radiusFactor = 1.0 - (node.radius / distance);
float radius = node.radius * radiusFactor + neighbor.radius * (1.0 - radiusFactor);
float radiusRate = neighbor.radius / node.radius;
float tangentTriangleLongEdgeLength = distance + (radiusRate * distance / (1.0 - radiusRate));
float segmentLength = node.radius * (tangentTriangleLongEdgeLength - node.radius) / tangentTriangleLongEdgeLength;
float radius = segmentLength / std::sin(std::acos(node.radius / tangentTriangleLongEdgeLength));
std::vector<QVector3D> cut;
float offsetDistance = 0;
offsetDistance = offsets[i] * (distance - node.radius - neighbor.radius);