History

merge from upstream

Seth Alves committed 8 years ago

Commit 64a46bf2 parents 98e0e66 b97c938107 files · +1462 −601Browse files

Showing the changes to libraries/render-utils/src/Model.cpp (1 of 107 files). Show all

Unified · Split

libraries/render-utils/src/Model.cpp+30−8
@@ -425,8 +425,8 @@ void Model::initJointStates() { · 424 unmodified lines
425425 }
426426
427427 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) {
430430
431431 bool intersectedSomething = false;
432432
@@ -457,6 +457,10 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 24 unmodified lines
457457 QMutexLocker locker(&_mutex);
458458
459459 float bestDistance = std::numeric_limits<float>::max();
460+ Triangle bestModelTriangle;
461+ Triangle bestWorldTriangle;
462+ int bestSubMeshIndex = 0;
463+
460464 int subMeshIndex = 0;
461465 const FBXGeometry& geometry = getFBXGeometry();
462466
@@ -474,8 +478,8 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 11 unmodified lines
474478 for (auto& triangleSet : _modelSpaceMeshTriangleSets) {
475479 float triangleSetDistance = 0.0f;
476480 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)) {
479483
480484 glm::vec3 meshIntersectionPoint = meshFrameOrigin + (meshFrameDirection * triangleSetDistance);
481485 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
485489 bestDistance = worldDistance;
486490 intersectedSomething = true;
487491 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;
490497 }
491498 }
492499 subMeshIndex++;
@@ -494,9 +501,24 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g · 1 unmodified line
494501
495502 if (intersectedSomething) {
496503 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+
497521 }
498−
499− return intersectedSomething;
500522 }
501523
502524 return intersectedSomething;