Showing the changes to libraries/render-utils/src/Model.cpp (1 of 107 files). Show all
Unified · Split
| @@ -425,8 +425,8 @@ void Model::initJointStates() { · 424 unmodified lines | ||
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance, |
| 428 | − BoxFace& face, glm::vec3& surfaceNormal, | |
| 429 | − QString& extraInfo, bool pickAgainstTriangles, bool allowBackface) { | |
| 428 | + BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo, | |
| 429 | + bool pickAgainstTriangles, bool allowBackface) { | |
| 430 | 430 | |
| 431 | 431 | bool intersectedSomething = false; |
| 432 | 432 | |
| @@ -457,6 +457,10 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 24 unmodified lines | ||
| 457 | 457 | QMutexLocker locker(&_mutex); |
| 458 | 458 | |
| 459 | 459 | float bestDistance = std::numeric_limits<float>::max(); |
| 460 | + Triangle bestModelTriangle; | |
| 461 | + Triangle bestWorldTriangle; | |
| 462 | + int bestSubMeshIndex = 0; | |
| 463 | + | |
| 460 | 464 | int subMeshIndex = 0; |
| 461 | 465 | const FBXGeometry& geometry = getFBXGeometry(); |
| 462 | 466 | |
| @@ -474,8 +478,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 11 unmodified lines | ||
| 474 | 478 | for (auto& triangleSet : _modelSpaceMeshTriangleSets) { |
| 475 | 479 | float triangleSetDistance = 0.0f; |
| 476 | 480 | BoxFace triangleSetFace; |
| 477 | − glm::vec3 triangleSetNormal; | |
| 478 | − if (triangleSet.findRayIntersection(meshFrameOrigin, meshFrameDirection, triangleSetDistance, triangleSetFace, triangleSetNormal, pickAgainstTriangles, allowBackface)) { | |
| 481 | + Triangle triangleSetTriangle; | |
| 482 | + if (triangleSet.findRayIntersection(meshFrameOrigin, meshFrameDirection, triangleSetDistance, triangleSetFace, triangleSetTriangle, pickAgainstTriangles, allowBackface)) { | |
| 479 | 483 | |
| 480 | 484 | glm::vec3 meshIntersectionPoint = meshFrameOrigin + (meshFrameDirection * triangleSetDistance); |
| 481 | 485 | glm::vec3 worldIntersectionPoint = glm::vec3(meshToWorldMatrix * glm::vec4(meshIntersectionPoint, 1.0f)); |
| @@ -485,8 +489,11 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 3 unmodified lines | ||
| 485 | 489 | bestDistance = worldDistance; |
| 486 | 490 | intersectedSomething = true; |
| 487 | 491 | face = triangleSetFace; |
| 488 | − surfaceNormal = glm::vec3(meshToWorldMatrix * glm::vec4(triangleSetNormal, 0.0f)); | |
| 489 | − extraInfo = geometry.getModelNameOfMesh(subMeshIndex); | |
| 492 | + bestModelTriangle = triangleSetTriangle; | |
| 493 | + bestWorldTriangle = triangleSetTriangle * meshToWorldMatrix; | |
| 494 | + extraInfo["worldIntersectionPoint"] = vec3toVariant(worldIntersectionPoint); | |
| 495 | + extraInfo["meshIntersectionPoint"] = vec3toVariant(meshIntersectionPoint); | |
| 496 | + bestSubMeshIndex = subMeshIndex; | |
| 490 | 497 | } |
| 491 | 498 | } |
| 492 | 499 | subMeshIndex++; |
| @@ -494,9 +501,24 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 1 unmodified line | ||
| 494 | 501 | |
| 495 | 502 | if (intersectedSomething) { |
| 496 | 503 | distance = bestDistance; |
| 504 | + surfaceNormal = bestWorldTriangle.getNormal(); | |
| 505 | + if (pickAgainstTriangles) { | |
| 506 | + extraInfo["subMeshIndex"] = bestSubMeshIndex; | |
| 507 | + extraInfo["subMeshName"] = geometry.getModelNameOfMesh(bestSubMeshIndex); | |
| 508 | + extraInfo["subMeshTriangleWorld"] = QVariantMap{ | |
| 509 | + { "v0", vec3toVariant(bestWorldTriangle.v0) }, | |
| 510 | + { "v1", vec3toVariant(bestWorldTriangle.v1) }, | |
| 511 | + { "v2", vec3toVariant(bestWorldTriangle.v2) }, | |
| 512 | + }; | |
| 513 | + extraInfo["subMeshNormal"] = vec3toVariant(bestModelTriangle.getNormal()); | |
| 514 | + extraInfo["subMeshTriangle"] = QVariantMap{ | |
| 515 | + { "v0", vec3toVariant(bestModelTriangle.v0) }, | |
| 516 | + { "v1", vec3toVariant(bestModelTriangle.v1) }, | |
| 517 | + { "v2", vec3toVariant(bestModelTriangle.v2) }, | |
| 518 | + }; | |
| 519 | + } | |
| 520 | + | |
| 497 | 521 | } |
| 498 | − | |
| 499 | − return intersectedSomething; | |
| 500 | 522 | } |
| 501 | 523 | |
| 502 | 524 | return intersectedSomething; |