Fix intermediate cut face

master
Jeremy Hu 2019-07-11 19:25:52 +09:30
parent d38737e2cb
commit f7b865f18b
1 changed files with 13 additions and 3 deletions

View File

@ -469,10 +469,20 @@ bool Builder::generateCutsForNode(size_t nodeIndex)
float farDistance = node.position.distanceToPoint(farOriginNode.position); float farDistance = node.position.distanceToPoint(farOriginNode.position);
float totalDistance = nearDistance + farDistance; float totalDistance = nearDistance + farDistance;
float distanceFactor = nearDistance / totalDistance; float distanceFactor = nearDistance / totalDistance;
if (QVector3D::dotProduct(nearOriginNode.cutNormal, farOriginNode.cutNormal) <= 0) const QVector3D *revisedNearCutNormal = nullptr;
cutNormal = (nearOriginNode.cutNormal * (1.0 - distanceFactor) - farOriginNode.cutNormal * distanceFactor).normalized(); const QVector3D *revisedFarCutNormal = nullptr;
if (distanceFactor <= 0.5) {
revisedNearCutNormal = &nearOriginNode.cutNormal;
revisedFarCutNormal = &node.cutNormal;
} else {
distanceFactor = (1.0 - distanceFactor);
revisedNearCutNormal = &farOriginNode.cutNormal;
revisedFarCutNormal = &node.cutNormal;
}
if (QVector3D::dotProduct(*revisedNearCutNormal, *revisedFarCutNormal) <= 0)
cutNormal = (*revisedNearCutNormal * (1.0 - distanceFactor) - *revisedFarCutNormal * distanceFactor).normalized();
else else
cutNormal = (nearOriginNode.cutNormal * (1.0 - distanceFactor) + farOriginNode.cutNormal * distanceFactor).normalized(); cutNormal = (*revisedNearCutNormal * (1.0 - distanceFactor) + *revisedFarCutNormal * distanceFactor).normalized();
if (QVector3D::dotProduct(cutNormal, node.cutNormal) <= 0) if (QVector3D::dotProduct(cutNormal, node.cutNormal) <= 0)
cutNormal = -cutNormal; cutNormal = -cutNormal;
} }