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 | bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance, | 427 | bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance, |
| 428 | BoxFace& face, glm::vec3& surfaceNormal, | 428 | BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo, |
| 429 | QString& extraInfo, bool pickAgainstTriangles, bool allowBackface) { | 429 | bool pickAgainstTriangles, bool allowBackface) { |
| 430 | 430 | ||
| 431 | bool intersectedSomething = false; | 431 | bool intersectedSomething = false; |
| 432 | 432 | ||
| @@ -457,6 +457,10 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 24 unmodified lines | |||
| 457 | QMutexLocker locker(&_mutex); | 457 | QMutexLocker locker(&_mutex); |
| 458 | 458 | ||
| 459 | float bestDistance = std::numeric_limits<float>::max(); | 459 | float bestDistance = std::numeric_limits<float>::max(); |
| 460 | Triangle bestModelTriangle; | ||
| 461 | Triangle bestWorldTriangle; | ||
| 462 | int bestSubMeshIndex = 0; | ||
| 463 | |||
| 460 | int subMeshIndex = 0; | 464 | int subMeshIndex = 0; |
| 461 | const FBXGeometry& geometry = getFBXGeometry(); | 465 | const FBXGeometry& geometry = getFBXGeometry(); |
| 462 | 466 | ||
| @@ -474,8 +478,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 11 unmodified lines | |||
| 474 | for (auto& triangleSet : _modelSpaceMeshTriangleSets) { | 478 | for (auto& triangleSet : _modelSpaceMeshTriangleSets) { |
| 475 | float triangleSetDistance = 0.0f; | 479 | float triangleSetDistance = 0.0f; |
| 476 | BoxFace triangleSetFace; | 480 | BoxFace triangleSetFace; |
| 477 | glm::vec3 triangleSetNormal; | 481 | Triangle triangleSetTriangle; |
| 478 | if (triangleSet.findRayIntersection(meshFrameOrigin, meshFrameDirection, triangleSetDistance, triangleSetFace, triangleSetNormal, pickAgainstTriangles, allowBackface)) { | 482 | if (triangleSet.findRayIntersection(meshFrameOrigin, meshFrameDirection, triangleSetDistance, triangleSetFace, triangleSetTriangle, pickAgainstTriangles, allowBackface)) { |
| 479 | 483 | ||
| 480 | glm::vec3 meshIntersectionPoint = meshFrameOrigin + (meshFrameDirection * triangleSetDistance); | 484 | glm::vec3 meshIntersectionPoint = meshFrameOrigin + (meshFrameDirection * triangleSetDistance); |
| 481 | glm::vec3 worldIntersectionPoint = glm::vec3(meshToWorldMatrix * glm::vec4(meshIntersectionPoint, 1.0f)); | 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 | bestDistance = worldDistance; | 489 | bestDistance = worldDistance; |
| 486 | intersectedSomething = true; | 490 | intersectedSomething = true; |
| 487 | face = triangleSetFace; | 491 | face = triangleSetFace; |
| 488 | surfaceNormal = glm::vec3(meshToWorldMatrix * glm::vec4(triangleSetNormal, 0.0f)); | 492 | bestModelTriangle = triangleSetTriangle; |
| 489 | extraInfo = geometry.getModelNameOfMesh(subMeshIndex); | 493 | bestWorldTriangle = triangleSetTriangle * meshToWorldMatrix; |
| 494 | extraInfo["worldIntersectionPoint"] = vec3toVariant(worldIntersectionPoint); | ||
| 495 | extraInfo["meshIntersectionPoint"] = vec3toVariant(meshIntersectionPoint); | ||
| 496 | bestSubMeshIndex = subMeshIndex; | ||
| 490 | } | 497 | } |
| 491 | } | 498 | } |
| 492 | subMeshIndex++; | 499 | subMeshIndex++; |
| @@ -494,9 +501,24 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 1 unmodified line | |||
| 494 | 501 | ||
| 495 | if (intersectedSomething) { | 502 | if (intersectedSomething) { |
| 496 | distance = bestDistance; | 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 | return intersectedSomething; | 524 | return intersectedSomething; |