mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 13:24:02 +02:00
basics of triangle picking working for models
This commit is contained in:
parent
0647211fb8
commit
a6b86da47a
25 changed files with 298 additions and 39 deletions
|
@ -24,6 +24,7 @@ function setupMenus() {
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt to Reduce Material Switches", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt to Reduce Material Switches", isCheckable: true, isChecked: false });
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt Render Entities as Scene", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Don't Attempt Render Entities as Scene", isCheckable: true, isChecked: false });
|
||||||
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Pick Against Model Triangles", isCheckable: true, isChecked: false });
|
||||||
Menu.addMenu("Developer > Entities > Culling");
|
Menu.addMenu("Developer > Entities > Culling");
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Out Of View Mesh Parts", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Out Of View Mesh Parts", isCheckable: true, isChecked: false });
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Too Small Mesh Parts", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities > Culling", menuItemName: "Don't Cull Too Small Mesh Parts", isCheckable: true, isChecked: false });
|
||||||
|
|
|
@ -432,6 +432,7 @@ namespace MenuOption {
|
||||||
const QString OldVoxelCullingMode = "Old Voxel Culling Mode";
|
const QString OldVoxelCullingMode = "Old Voxel Culling Mode";
|
||||||
const QString Pair = "Pair";
|
const QString Pair = "Pair";
|
||||||
const QString PasteToVoxel = "Paste to Voxel...";
|
const QString PasteToVoxel = "Paste to Voxel...";
|
||||||
|
const QString PickAgainstModelTriangles = "Pick Against Model Triangles";
|
||||||
const QString PipelineWarnings = "Log Render Pipeline Warnings";
|
const QString PipelineWarnings = "Log Render Pipeline Warnings";
|
||||||
const QString Preferences = "Preferences...";
|
const QString Preferences = "Preferences...";
|
||||||
const QString Quit = "Quit";
|
const QString Quit = "Quit";
|
||||||
|
|
|
@ -133,9 +133,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
getModel(renderer);
|
getModel(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (_model) {
|
if (_model) {
|
||||||
// handle animations..
|
// handle animations..
|
||||||
if (hasAnimation()) {
|
if (hasAnimation()) {
|
||||||
|
@ -175,7 +172,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
// TODO: this is the majority of model render time. And rendering of a cube model vs the basic Box render
|
// TODO: this is the majority of model render time. And rendering of a cube model vs the basic Box render
|
||||||
// is significantly more expensive. Is there a way to call this that doesn't cost us as much?
|
// is significantly more expensive. Is there a way to call this that doesn't cost us as much?
|
||||||
PerformanceTimer perfTimer("model->render");
|
PerformanceTimer perfTimer("model->render");
|
||||||
bool dontRenderAsScene = Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene);
|
bool dontRenderAsScene = true; // Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene);
|
||||||
if (dontRenderAsScene) {
|
if (dontRenderAsScene) {
|
||||||
_model->render(alpha, modelRenderMode, args);
|
_model->render(alpha, modelRenderMode, args);
|
||||||
} else {
|
} else {
|
||||||
|
@ -270,10 +267,14 @@ bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& ori
|
||||||
qDebug() << " originInMeters:" << originInMeters;
|
qDebug() << " originInMeters:" << originInMeters;
|
||||||
QString extraInfo;
|
QString extraInfo;
|
||||||
float localDistance;
|
float localDistance;
|
||||||
|
|
||||||
bool intersectsModel = _model->findRayIntersectionAgainstSubMeshes(originInMeters, direction, localDistance, face, extraInfo);
|
bool intersectsModel = _model->findRayIntersectionAgainstSubMeshes(originInMeters, direction, localDistance, face, extraInfo);
|
||||||
|
|
||||||
if (intersectsModel) {
|
if (intersectsModel) {
|
||||||
|
// NOTE: findRayIntersectionAgainstSubMeshes() does work in meters, but we're expected to return
|
||||||
|
// results in tree scale.
|
||||||
distance = localDistance / (float)TREE_SCALE;
|
distance = localDistance / (float)TREE_SCALE;
|
||||||
|
qDebug() << " --hit this mode -- returning distance:" << distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
return intersectsModel; // we only got here if we intersected our non-aabox
|
return intersectsModel; // we only got here if we intersected our non-aabox
|
||||||
|
|
|
@ -54,6 +54,7 @@ Model::Model(QObject* parent) :
|
||||||
_blendNumber(0),
|
_blendNumber(0),
|
||||||
_appliedBlendNumber(0),
|
_appliedBlendNumber(0),
|
||||||
_calculatedMeshBoxesValid(false),
|
_calculatedMeshBoxesValid(false),
|
||||||
|
_calculatedMeshTrianglesValid(false),
|
||||||
_meshGroupsKnown(false) {
|
_meshGroupsKnown(false) {
|
||||||
|
|
||||||
// we may have been created in the network thread, but we live in the main thread
|
// we may have been created in the network thread, but we live in the main thread
|
||||||
|
@ -516,7 +517,7 @@ void Model::setJointStates(QVector<JointState> states) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
float& distance, BoxFace& face, QString& extraInfo) {
|
||||||
|
|
||||||
bool intersectedSomething = false;
|
bool intersectedSomething = false;
|
||||||
|
|
||||||
|
@ -525,7 +526,11 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
return intersectedSomething;
|
return intersectedSomething;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pickAgainstTriangles = Menu::getInstance()->isOptionChecked(MenuOption::PickAgainstModelTriangles);
|
||||||
|
|
||||||
qDebug() << "Model::findRayIntersectionAgainstSubMeshes()...";
|
qDebug() << "Model::findRayIntersectionAgainstSubMeshes()...";
|
||||||
|
qDebug() << " origin:" << origin;
|
||||||
|
qDebug() << " direction:" << direction;
|
||||||
|
|
||||||
// extents is the entity relative, scaled, centered extents of the entity
|
// extents is the entity relative, scaled, centered extents of the entity
|
||||||
glm::vec3 position = _translation;
|
glm::vec3 position = _translation;
|
||||||
|
@ -538,31 +543,58 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
qDebug() << " modelExtents:" << modelExtents;
|
qDebug() << " modelExtents:" << modelExtents;
|
||||||
|
|
||||||
glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;
|
glm::vec3 dimensions = modelExtents.maximum - modelExtents.minimum;
|
||||||
glm::vec3 corner = dimensions * -0.5f; // since we're going to do the ray picking in the model frame of reference
|
glm::vec3 corner = dimensions * _registrationPoint; // since we're going to do the ray picking in the model frame of reference
|
||||||
AABox overlayFrameBox(corner, dimensions);
|
AABox overlayFrameBox(corner, dimensions);
|
||||||
|
|
||||||
qDebug() << " overlayFrameBox:" << overlayFrameBox;
|
qDebug() << " overlayFrameBox:" << overlayFrameBox;
|
||||||
|
|
||||||
glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
|
glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
|
||||||
glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
|
glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
|
||||||
|
qDebug() << " modelFrameOrigin:" << modelFrameOrigin;
|
||||||
|
qDebug() << " modelFrameDirection:" << modelFrameDirection;
|
||||||
|
|
||||||
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame
|
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame
|
||||||
// and testing intersection there.
|
// and testing intersection there.
|
||||||
if (overlayFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
|
if (overlayFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) {
|
||||||
|
|
||||||
float bestDistance = std::numeric_limits<float>::max();
|
float bestDistance = std::numeric_limits<float>::max();
|
||||||
|
float bestTriangleDistance = std::numeric_limits<float>::max();
|
||||||
|
bool someTriangleHit = false;
|
||||||
|
|
||||||
float distanceToSubMesh;
|
float distanceToSubMesh;
|
||||||
BoxFace subMeshFace;
|
BoxFace subMeshFace;
|
||||||
int subMeshIndex = 0;
|
int subMeshIndex = 0;
|
||||||
|
|
||||||
|
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||||
|
|
||||||
// If we hit the models box, then consider the submeshes...
|
// If we hit the models box, then consider the submeshes...
|
||||||
foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
|
foreach(const AABox& subMeshBox, _calculatedMeshBoxes) {
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
|
||||||
|
|
||||||
qDebug() << "subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;
|
qDebug() << "subMeshBox[" << subMeshIndex <<"]:" << subMeshBox;
|
||||||
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
|
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
|
||||||
if (distanceToSubMesh < bestDistance) {
|
if (distanceToSubMesh < bestDistance) {
|
||||||
|
|
||||||
|
if (pickAgainstTriangles) {
|
||||||
|
if (!_calculatedMeshTrianglesValid) {
|
||||||
|
recalcuateMeshBoxes();
|
||||||
|
}
|
||||||
|
// check our triangles here....
|
||||||
|
const QVector<Triangle>& meshTriangles = _calculatedMeshTriangles[subMeshIndex];
|
||||||
|
int t = 0;
|
||||||
|
foreach (const Triangle& triangle, meshTriangles) {
|
||||||
|
//qDebug() << "triangle["<< t <<"] :" << triangle.v0 << ", "<< triangle.v1 << ", " << triangle.v2;
|
||||||
|
t++;
|
||||||
|
|
||||||
|
float thisTriangleDistance;
|
||||||
|
if (findRayTrianlgeIntersection(origin, direction, triangle, thisTriangleDistance)) {
|
||||||
|
if (thisTriangleDistance < bestTriangleDistance) {
|
||||||
|
bestTriangleDistance = thisTriangleDistance;
|
||||||
|
someTriangleHit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bestDistance = distanceToSubMesh;
|
bestDistance = distanceToSubMesh;
|
||||||
intersectedSomething = true;
|
intersectedSomething = true;
|
||||||
face = subMeshFace;
|
face = subMeshFace;
|
||||||
|
@ -572,6 +604,27 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
subMeshIndex++;
|
subMeshIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we were asked to pick against triangles, and we didn't hit one, then we
|
||||||
|
// do not consider this model to be hit at all.
|
||||||
|
if (pickAgainstTriangles && !someTriangleHit) {
|
||||||
|
intersectedSomething = false;
|
||||||
|
}
|
||||||
|
qDebug() << "pickAgainstTriangles:" << pickAgainstTriangles;
|
||||||
|
qDebug() << "someTriangleHit:" << someTriangleHit;
|
||||||
|
qDebug() << "bestTriangleDistance:" << bestTriangleDistance;
|
||||||
|
qDebug() << "bestDistance:" << bestDistance;
|
||||||
|
|
||||||
|
if (intersectedSomething) {
|
||||||
|
qDebug() << " --- we hit this model --- ";
|
||||||
|
|
||||||
|
if (pickAgainstTriangles) {
|
||||||
|
distance = bestTriangleDistance;
|
||||||
|
} else {
|
||||||
|
distance = bestDistance;
|
||||||
|
}
|
||||||
|
qDebug() << "distance:" << distance;
|
||||||
|
}
|
||||||
|
|
||||||
return intersectedSomething;
|
return intersectedSomething;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,17 +632,92 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::recalcuateMeshBoxes() {
|
void Model::recalcuateMeshBoxes() {
|
||||||
if (!_calculatedMeshBoxesValid) {
|
bool pickAgainstTriangles = Menu::getInstance()->isOptionChecked(MenuOption::PickAgainstModelTriangles);
|
||||||
|
bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid;
|
||||||
|
|
||||||
|
if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded) {
|
||||||
|
qDebug() << "Model::recalcuateMeshBoxes()";
|
||||||
PerformanceTimer perfTimer("calculatedMeshBoxes");
|
PerformanceTimer perfTimer("calculatedMeshBoxes");
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||||
int numberOfMeshes = geometry.meshes.size();
|
int numberOfMeshes = geometry.meshes.size();
|
||||||
_calculatedMeshBoxes.resize(numberOfMeshes);
|
_calculatedMeshBoxes.resize(numberOfMeshes);
|
||||||
|
_calculatedMeshTriangles.clear();
|
||||||
for (int i = 0; i < numberOfMeshes; i++) {
|
for (int i = 0; i < numberOfMeshes; i++) {
|
||||||
const FBXMesh& mesh = geometry.meshes.at(i);
|
const FBXMesh& mesh = geometry.meshes.at(i);
|
||||||
Extents scaledMeshExtents = calculateScaledOffsetExtents(mesh.meshExtents);
|
Extents scaledMeshExtents = calculateScaledOffsetExtents(mesh.meshExtents);
|
||||||
|
|
||||||
|
qDebug() << "mesh.meshExtents["<<i<<"]:" << mesh.meshExtents;
|
||||||
|
qDebug() << "scaledMeshExtents["<<i<<"]:" << scaledMeshExtents;
|
||||||
|
|
||||||
_calculatedMeshBoxes[i] = AABox(scaledMeshExtents);
|
_calculatedMeshBoxes[i] = AABox(scaledMeshExtents);
|
||||||
|
|
||||||
|
qDebug() << "_calculatedMeshBoxes["<<i<<"]:" << _calculatedMeshBoxes[i];
|
||||||
|
|
||||||
|
if (pickAgainstTriangles) {
|
||||||
|
qDebug() << "mesh.parts.size():" << mesh.parts.size();
|
||||||
|
qDebug() << "---- calculating triangles for mesh parts for mesh:" << i << " ----------";
|
||||||
|
QVector<Triangle> thisMeshTriangles;
|
||||||
|
for (int j = 0; j < mesh.parts.size(); j++) {
|
||||||
|
const FBXMeshPart& part = mesh.parts.at(j);
|
||||||
|
|
||||||
|
const int INDICES_PER_TRIANGLE = 3;
|
||||||
|
const int INDICES_PER_QUAD = 4;
|
||||||
|
|
||||||
|
if (part.quadIndices.size() > 0) {
|
||||||
|
int numberOfQuads = part.quadIndices.size() / INDICES_PER_QUAD;
|
||||||
|
qDebug() << "numberOfQuads:" << numberOfQuads;
|
||||||
|
int vIndex = 0;
|
||||||
|
for (int q = 0; q < numberOfQuads; q++) {
|
||||||
|
int i0 = part.quadIndices[vIndex++];
|
||||||
|
int i1 = part.quadIndices[vIndex++];
|
||||||
|
int i2 = part.quadIndices[vIndex++];
|
||||||
|
int i3 = part.quadIndices[vIndex++];
|
||||||
|
|
||||||
|
glm::vec3 v0 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i0], 1.0f)));
|
||||||
|
glm::vec3 v1 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i1], 1.0f)));
|
||||||
|
glm::vec3 v2 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i2], 1.0f)));
|
||||||
|
glm::vec3 v3 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i3], 1.0f)));
|
||||||
|
|
||||||
|
Triangle tri1 = { v0, v1, v3 };
|
||||||
|
Triangle tri2 = { v1, v2, v3 };
|
||||||
|
|
||||||
|
//qDebug() << "quad["<< q <<"].t1 :" << v0 << ", "<< v1 << ", " << v3;
|
||||||
|
//qDebug() << "quad["<< q <<"].t2 :" << v1 << ", "<< v2 << ", " << v3;
|
||||||
|
|
||||||
|
thisMeshTriangles.push_back(tri1);
|
||||||
|
thisMeshTriangles.push_back(tri2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (part.triangleIndices.size() > 0) {
|
||||||
|
int numberOfTris = part.triangleIndices.size() / INDICES_PER_TRIANGLE;
|
||||||
|
qDebug() << "numberOfTris:" << numberOfTris;
|
||||||
|
int vIndex = 0;
|
||||||
|
for (int t = 0; t < numberOfTris; t++) {
|
||||||
|
int i0 = part.triangleIndices[vIndex++];
|
||||||
|
int i1 = part.triangleIndices[vIndex++];
|
||||||
|
int i2 = part.triangleIndices[vIndex++];
|
||||||
|
|
||||||
|
glm::vec3 v0 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i0], 1.0f)));
|
||||||
|
glm::vec3 v1 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i1], 1.0f)));
|
||||||
|
glm::vec3 v2 = calculateScaledOffsetPoint(glm::vec3(mesh.modelTransform * glm::vec4(mesh.vertices[i2], 1.0f)));
|
||||||
|
|
||||||
|
Triangle tri = { v0, v1, v2 };
|
||||||
|
|
||||||
|
//qDebug() << "triangle["<< t <<"] :" << v0 << ", " << v1 << ", " << v2;
|
||||||
|
|
||||||
|
thisMeshTriangles.push_back(tri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_calculatedMeshTriangles.push_back(thisMeshTriangles);
|
||||||
|
qDebug() << "------------------------------------------------------------------------------";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
_calculatedMeshBoxesValid = true;
|
_calculatedMeshBoxesValid = true;
|
||||||
|
_calculatedMeshTrianglesValid = pickAgainstTriangles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -851,6 +979,15 @@ Extents Model::calculateScaledOffsetExtents(const Extents& extents) const {
|
||||||
return translatedExtents;
|
return translatedExtents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 Model::calculateScaledOffsetPoint(const glm::vec3& point) const {
|
||||||
|
// we need to include any fst scaling, translation, and rotation, which is captured in the offset matrix
|
||||||
|
glm::vec3 offsetPoint = glm::vec3(_geometry->getFBXGeometry().offset * glm::vec4(point, 1.0f));
|
||||||
|
glm::vec3 scaledPoint = ((offsetPoint + _offset) * _scale);
|
||||||
|
glm::vec3 rotatedPoint = _rotation * scaledPoint;
|
||||||
|
glm::vec3 translatedPoint = rotatedPoint + _translation;
|
||||||
|
return translatedPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Model::getJointState(int index, glm::quat& rotation) const {
|
bool Model::getJointState(int index, glm::quat& rotation) const {
|
||||||
if (index == -1 || index >= _jointStates.size()) {
|
if (index == -1 || index >= _jointStates.size()) {
|
||||||
|
@ -1149,6 +1286,7 @@ void Model::simulate(float deltaTime, bool fullUpdate) {
|
||||||
|
|
||||||
if (isActive() && fullUpdate) {
|
if (isActive() && fullUpdate) {
|
||||||
_calculatedMeshBoxesValid = false; // if we have to simulate, we need to assume our mesh boxes are all invalid
|
_calculatedMeshBoxesValid = false; // if we have to simulate, we need to assume our mesh boxes are all invalid
|
||||||
|
_calculatedMeshTrianglesValid = false;
|
||||||
|
|
||||||
// check for scale to fit
|
// check for scale to fit
|
||||||
if (_scaleToFit && !_scaledToFit) {
|
if (_scaleToFit && !_scaledToFit) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "Transform.h"
|
#include "Transform.h"
|
||||||
#include <AABox.h>
|
#include <AABox.h>
|
||||||
#include <AnimationCache.h>
|
#include <AnimationCache.h>
|
||||||
|
#include <GeometryUtil.h>
|
||||||
#include <PhysicsEntity.h>
|
#include <PhysicsEntity.h>
|
||||||
|
|
||||||
#include "AnimationHandle.h"
|
#include "AnimationHandle.h"
|
||||||
|
@ -34,7 +35,6 @@ class Shape;
|
||||||
#include "RenderArgs.h"
|
#include "RenderArgs.h"
|
||||||
class ViewFrustum;
|
class ViewFrustum;
|
||||||
|
|
||||||
|
|
||||||
#include "gpu/Stream.h"
|
#include "gpu/Stream.h"
|
||||||
#include "gpu/Batch.h"
|
#include "gpu/Batch.h"
|
||||||
|
|
||||||
|
@ -119,6 +119,9 @@ public:
|
||||||
/// Returns the scaled equivalent of some extents in model space.
|
/// Returns the scaled equivalent of some extents in model space.
|
||||||
Extents calculateScaledOffsetExtents(const Extents& extents) const;
|
Extents calculateScaledOffsetExtents(const Extents& extents) const;
|
||||||
|
|
||||||
|
/// Returns the scaled equivalent of a point in model space.
|
||||||
|
glm::vec3 calculateScaledOffsetPoint(const glm::vec3& point) const;
|
||||||
|
|
||||||
/// Returns a reference to the shared geometry.
|
/// Returns a reference to the shared geometry.
|
||||||
const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; }
|
const QSharedPointer<NetworkGeometry>& getGeometry() const { return _geometry; }
|
||||||
|
|
||||||
|
@ -194,7 +197,7 @@ public:
|
||||||
{ _geometry->setTextureWithNameToURL(name, url); }
|
{ _geometry->setTextureWithNameToURL(name, url); }
|
||||||
|
|
||||||
bool findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
bool findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
float& distance, BoxFace& face, QString& extraInfo);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSharedPointer<NetworkGeometry> _geometry;
|
QSharedPointer<NetworkGeometry> _geometry;
|
||||||
|
@ -361,9 +364,12 @@ private:
|
||||||
|
|
||||||
static void initSkinProgram(ProgramObject& program, SkinLocations& locations, int specularTextureUnit = 1);
|
static void initSkinProgram(ProgramObject& program, SkinLocations& locations, int specularTextureUnit = 1);
|
||||||
|
|
||||||
QVector<AABox> _calculatedMeshBoxes;
|
QVector<AABox> _calculatedMeshBoxes; // world coordinate AABoxes for all sub mesh boxes
|
||||||
bool _calculatedMeshBoxesValid;
|
bool _calculatedMeshBoxesValid;
|
||||||
|
|
||||||
|
QVector< QVector<Triangle> > _calculatedMeshTriangles; // world coordinate triangles for all sub meshes
|
||||||
|
bool _calculatedMeshTrianglesValid;
|
||||||
|
|
||||||
void recalcuateMeshBoxes();
|
void recalcuateMeshBoxes();
|
||||||
|
|
||||||
void segregateMeshGroups(); // used to calculate our list of translucent vs opaque meshes
|
void segregateMeshGroups(); // used to calculate our list of translucent vs opaque meshes
|
||||||
|
|
|
@ -167,7 +167,7 @@ QScriptValue Base3DOverlay::getProperty(const QString& property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face) const {
|
float& distance, BoxFace& face) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,10 +50,10 @@ public:
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||||
|
|
||||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
float& distance, BoxFace& face, QString& extraInfo) {
|
||||||
return findRayIntersection(origin, direction, distance, face);
|
return findRayIntersection(origin, direction, distance, face);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ void BillboardOverlay::replyFinished() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face) const {
|
float& distance, BoxFace& face) {
|
||||||
|
|
||||||
if (_billboardTexture) {
|
if (_billboardTexture) {
|
||||||
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
|
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||||
|
|
||||||
virtual BillboardOverlay* createClone() const;
|
virtual BillboardOverlay* createClone() const;
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ QScriptValue Circle3DOverlay::getProperty(const QString& property) {
|
||||||
|
|
||||||
|
|
||||||
bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
||||||
const glm::vec3& direction, float& distance, BoxFace& face) const {
|
const glm::vec3& direction, float& distance, BoxFace& face) {
|
||||||
|
|
||||||
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
|
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
|
||||||
if (intersects) {
|
if (intersects) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
void setMajorTickMarksColor(const xColor& value) { _majorTickMarksColor = value; }
|
void setMajorTickMarksColor(const xColor& value) { _majorTickMarksColor = value; }
|
||||||
void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; }
|
void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; }
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||||
|
|
||||||
virtual Circle3DOverlay* createClone() const;
|
virtual Circle3DOverlay* createClone() const;
|
||||||
|
|
||||||
|
|
|
@ -170,14 +170,14 @@ QScriptValue ModelOverlay::getProperty(const QString& property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool ModelOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face) const {
|
float& distance, BoxFace& face) {
|
||||||
|
|
||||||
QString subMeshNameTemp;
|
QString subMeshNameTemp;
|
||||||
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, subMeshNameTemp);
|
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, subMeshNameTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
float& distance, BoxFace& face, QString& extraInfo) {
|
||||||
|
|
||||||
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo);
|
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,9 @@ public:
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
float& distance, BoxFace& face, QString& extraInfo);
|
||||||
|
|
||||||
virtual ModelOverlay* createClone() const;
|
virtual ModelOverlay* createClone() const;
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ QScriptValue Planar3DOverlay::getProperty(const QString& property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face) const {
|
float& distance, BoxFace& face) {
|
||||||
|
|
||||||
RayIntersectionInfo rayInfo;
|
RayIntersectionInfo rayInfo;
|
||||||
rayInfo._rayStart = origin;
|
rayInfo._rayStart = origin;
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::vec2 _dimensions;
|
glm::vec2 _dimensions;
|
||||||
|
|
|
@ -100,7 +100,7 @@ QScriptValue Volume3DOverlay::getProperty(const QString& property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face) const {
|
float& distance, BoxFace& face) {
|
||||||
|
|
||||||
// extents is the entity relative, scaled, centered extents of the entity
|
// extents is the entity relative, scaled, centered extents of the entity
|
||||||
glm::vec3 position = getPosition();
|
glm::vec3 position = getPosition();
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::vec3 _dimensions;
|
glm::vec3 _dimensions;
|
||||||
|
|
|
@ -475,7 +475,7 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3
|
||||||
|
|
||||||
bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
void** intersectedObject) {
|
void** intersectedObject, float distanceToElementCube) {
|
||||||
|
|
||||||
// only called if we do intersect our bounding cube, but find if we actually intersect with entities...
|
// only called if we do intersect our bounding cube, but find if we actually intersect with entities...
|
||||||
|
|
||||||
|
@ -509,15 +509,32 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
||||||
|
|
||||||
// we can use the AABox's ray intersection by mapping our origin and direction into the entity frame
|
// we can use the AABox's ray intersection by mapping our origin and direction into the entity frame
|
||||||
// and testing intersection there.
|
// and testing intersection there.
|
||||||
|
qDebug() << "EntityTreeElement::findDetailedRayIntersection()....";
|
||||||
|
qDebug() << " origin:" << origin;
|
||||||
|
qDebug() << " checking entity:" << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType()));
|
||||||
|
qDebug() << " distance:" << distance;
|
||||||
|
|
||||||
if (entityFrameBox.findRayIntersection(entityFrameOrigin, entityFrameDirection, localDistance, localFace)) {
|
if (entityFrameBox.findRayIntersection(entityFrameOrigin, entityFrameDirection, localDistance, localFace)) {
|
||||||
|
qDebug() << " localDistance:" << localDistance;
|
||||||
|
|
||||||
if (localDistance < distance) {
|
if (localDistance < distance) {
|
||||||
|
qDebug() << " localDistance < distance... continue...";
|
||||||
|
|
||||||
// now ask the entity if we actually intersect
|
// now ask the entity if we actually intersect
|
||||||
if (entity->supportsDetailedRayIntersection()) {
|
if (entity->supportsDetailedRayIntersection()) {
|
||||||
|
|
||||||
|
qDebug() << " entity->supportsDetailedRayIntersection()....";
|
||||||
|
|
||||||
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
|
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
|
||||||
localFace, intersectedObject)) {
|
localFace, intersectedObject)) {
|
||||||
|
|
||||||
|
qDebug() << " localDistance (detailed):" << localDistance;
|
||||||
|
|
||||||
if (localDistance < distance) {
|
if (localDistance < distance) {
|
||||||
|
|
||||||
|
qDebug() << " localDistance < distance...";
|
||||||
|
qDebug() << " CHOOSING THIS ONE ---> " << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType()));
|
||||||
|
|
||||||
distance = localDistance;
|
distance = localDistance;
|
||||||
face = localFace;
|
face = localFace;
|
||||||
*intersectedObject = (void*)entity;
|
*intersectedObject = (void*)entity;
|
||||||
|
@ -527,6 +544,10 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
||||||
} else {
|
} else {
|
||||||
// if the entity type doesn't support a detailed intersection, then just return the non-AABox results
|
// if the entity type doesn't support a detailed intersection, then just return the non-AABox results
|
||||||
if (localDistance < distance) {
|
if (localDistance < distance) {
|
||||||
|
|
||||||
|
qDebug() << " localDistance < distance...";
|
||||||
|
qDebug() << " CHOOSING THIS ONE ---> " << entity->getEntityItemID() << "-" << qPrintable(EntityTypes::getEntityTypeName(entity->getType()));
|
||||||
|
|
||||||
distance = localDistance;
|
distance = localDistance;
|
||||||
face = localFace;
|
face = localFace;
|
||||||
*intersectedObject = (void*)entity;
|
*intersectedObject = (void*)entity;
|
||||||
|
|
|
@ -137,7 +137,7 @@ public:
|
||||||
virtual bool canRayIntersect() const { return hasEntities(); }
|
virtual bool canRayIntersect() const { return hasEntities(); }
|
||||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
void** intersectedObject);
|
void** intersectedObject, float distanceToElementCube);
|
||||||
|
|
||||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
glm::vec3& penetration, void** penetratedObject) const;
|
glm::vec3& penetration, void** penetratedObject) const;
|
||||||
|
|
|
@ -2044,6 +2044,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
||||||
|
|
||||||
extracted.mesh.meshExtents.minimum = glm::min(extracted.mesh.meshExtents.minimum, transformedVertex);
|
extracted.mesh.meshExtents.minimum = glm::min(extracted.mesh.meshExtents.minimum, transformedVertex);
|
||||||
extracted.mesh.meshExtents.maximum = glm::max(extracted.mesh.meshExtents.maximum, transformedVertex);
|
extracted.mesh.meshExtents.maximum = glm::max(extracted.mesh.meshExtents.maximum, transformedVertex);
|
||||||
|
extracted.mesh.modelTransform = modelTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for textures, material properties
|
// look for textures, material properties
|
||||||
|
|
|
@ -149,6 +149,7 @@ public:
|
||||||
QVector<FBXCluster> clusters;
|
QVector<FBXCluster> clusters;
|
||||||
|
|
||||||
Extents meshExtents;
|
Extents meshExtents;
|
||||||
|
glm::mat4 modelTransform;
|
||||||
|
|
||||||
bool isEye;
|
bool isEye;
|
||||||
|
|
||||||
|
|
|
@ -1339,28 +1339,54 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
|
||||||
keepSearching = true; // assume that we will continue searching after this.
|
keepSearching = true; // assume that we will continue searching after this.
|
||||||
|
|
||||||
AACube cube = getAACube();
|
AACube cube = getAACube();
|
||||||
float localDistance;
|
float distanceToElementCube = std::numeric_limits<float>::max();
|
||||||
|
float distanceToElementDetails = distance;
|
||||||
BoxFace localFace;
|
BoxFace localFace;
|
||||||
|
|
||||||
|
qDebug() << "OctreeElement::findRayIntersection()....";
|
||||||
|
qDebug() << " origin:" << origin;
|
||||||
|
qDebug() << " checking element:" << cube;
|
||||||
|
qDebug() << " distance:" << distance;
|
||||||
|
|
||||||
// if the ray doesn't intersect with our cube, we can stop searching!
|
// if the ray doesn't intersect with our cube, we can stop searching!
|
||||||
if (!cube.findRayIntersection(origin, direction, localDistance, localFace)) {
|
if (!cube.findRayIntersection(origin, direction, distanceToElementCube, localFace)) {
|
||||||
|
qDebug() << " didn't intersect cube... done searching...";
|
||||||
keepSearching = false; // no point in continuing to search
|
keepSearching = false; // no point in continuing to search
|
||||||
return false; // we did not intersect
|
return false; // we did not intersect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << " distanceToElementCube:" << distanceToElementCube;
|
||||||
|
|
||||||
// by default, we only allow intersections with leaves with content
|
// by default, we only allow intersections with leaves with content
|
||||||
if (!canRayIntersect()) {
|
if (!canRayIntersect()) {
|
||||||
return false; // we don't intersect with non-leaves, and we keep searching
|
return false; // we don't intersect with non-leaves, and we keep searching
|
||||||
}
|
}
|
||||||
|
|
||||||
// we did hit this element, so calculate appropriate distances
|
// we did hit this element, so calculate appropriate distances
|
||||||
localDistance *= TREE_SCALE;
|
//localDistance *= TREE_SCALE;
|
||||||
if (localDistance < distance) {
|
|
||||||
|
// if the distance to the element cube is not less than the current best distance, then it's not possible
|
||||||
|
// for any details inside the cube to be closer so we don't need to consider them.
|
||||||
|
if (distanceToElementCube < distance) {
|
||||||
|
|
||||||
|
qDebug() << " distanceToElementCube < distance:" << (distanceToElementCube < distance);
|
||||||
|
qDebug() << " continue.... call... findDetailedRayIntersection()...";
|
||||||
|
//qDebug() << " distanceToElementCube < distance -- continue.... call... findDetailedRayIntersection()...";
|
||||||
|
|
||||||
if (findDetailedRayIntersection(origin, direction, keepSearching,
|
if (findDetailedRayIntersection(origin, direction, keepSearching,
|
||||||
element, distance, face, intersectedObject)) {
|
element, distanceToElementDetails, face, intersectedObject, distanceToElementCube)) {
|
||||||
distance = localDistance;
|
|
||||||
face = localFace;
|
qDebug() << " findDetailedRayIntersection() -- intersected something";
|
||||||
return true;
|
if (distanceToElementDetails < distance) {
|
||||||
|
qDebug() << " distanceToElementDetails < distance -- THIS ONE IS GOOD -------";
|
||||||
|
|
||||||
|
distance = distanceToElementDetails;
|
||||||
|
face = localFace;
|
||||||
|
|
||||||
|
qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------";
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1368,11 +1394,12 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
|
||||||
|
|
||||||
bool OctreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool OctreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
void** intersectedObject) {
|
void** intersectedObject, float distanceToElementCube) {
|
||||||
|
|
||||||
// we did hit this element, so calculate appropriate distances
|
// we did hit this element, so calculate appropriate distances
|
||||||
if (hasContent()) {
|
if (hasContent()) {
|
||||||
element = this;
|
element = this;
|
||||||
|
distance = distanceToElementCube;
|
||||||
if (intersectedObject) {
|
if (intersectedObject) {
|
||||||
*intersectedObject = this;
|
*intersectedObject = this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ public:
|
||||||
|
|
||||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
void** intersectedObject);
|
void** intersectedObject, float distanceToElementCube);
|
||||||
|
|
||||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
glm::vec3& penetration, void** penetratedObject) const;
|
glm::vec3& penetration, void** penetratedObject) const;
|
||||||
|
|
|
@ -252,6 +252,52 @@ bool findRayCapsuleIntersection(const glm::vec3& origin, const glm::vec3& direct
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool findRayTrianlgeIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
|
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
|
||||||
|
|
||||||
|
glm::vec3 e1, e2, h, s, q;
|
||||||
|
float a, f, u, v, t;
|
||||||
|
|
||||||
|
e1 = v1 - v0;
|
||||||
|
e2 = v2 - v0;
|
||||||
|
|
||||||
|
h = glm::cross(direction, e2);
|
||||||
|
a = glm::dot(e1, h);
|
||||||
|
|
||||||
|
if (a > -0.00001 && a < 0.00001) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = 1/a;
|
||||||
|
s = origin - v0;
|
||||||
|
u = f * glm::dot(s,h);
|
||||||
|
|
||||||
|
if (u < 0.0 || u > 1.0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
q = glm::cross(s, e1);
|
||||||
|
v = f * glm::dot(direction, q);
|
||||||
|
|
||||||
|
if (v < 0.0 || u + v > 1.0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// at this stage we can compute t to find out where the intersection point is on the line
|
||||||
|
t = f * glm::dot(e2,q);
|
||||||
|
|
||||||
|
// ray intersection
|
||||||
|
if (t > 0.00001) {
|
||||||
|
distance = t;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// this means that there is a line intersection but not a ray intersection
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Do line segments (r1p1.x, r1p1.y)--(r1p2.x, r1p2.y) and (r2p1.x, r2p1.y)--(r2p2.x, r2p2.y) intersect?
|
// Do line segments (r1p1.x, r1p1.y)--(r1p2.x, r1p2.y) and (r2p1.x, r2p1.y)--(r2p2.x, r2p2.y) intersect?
|
||||||
// from: http://ptspts.blogspot.com/2010/06/how-to-determine-if-two-line-segments.html
|
// from: http://ptspts.blogspot.com/2010/06/how-to-determine-if-two-line-segments.html
|
||||||
bool doLineSegmentsIntersect(glm::vec2 r1p1, glm::vec2 r1p2, glm::vec2 r2p1, glm::vec2 r2p2) {
|
bool doLineSegmentsIntersect(glm::vec2 r1p1, glm::vec2 r1p2, glm::vec2 r2p1, glm::vec2 r2p2) {
|
||||||
|
|
|
@ -76,6 +76,22 @@ bool findRaySphereIntersection(const glm::vec3& origin, const glm::vec3& directi
|
||||||
bool findRayCapsuleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool findRayCapsuleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
const glm::vec3& start, const glm::vec3& end, float radius, float& distance);
|
const glm::vec3& start, const glm::vec3& end, float radius, float& distance);
|
||||||
|
|
||||||
|
bool findRayTrianlgeIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
|
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance);
|
||||||
|
|
||||||
|
class Triangle {
|
||||||
|
public:
|
||||||
|
glm::vec3 v0;
|
||||||
|
glm::vec3 v1;
|
||||||
|
glm::vec3 v2;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline bool findRayTrianlgeIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
|
const Triangle& triangle, float& distance) {
|
||||||
|
return findRayTrianlgeIntersection(origin, direction, triangle.v0, triangle.v1, triangle.v2, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool doLineSegmentsIntersect(glm::vec2 r1p1, glm::vec2 r1p2, glm::vec2 r2p1, glm::vec2 r2p2);
|
bool doLineSegmentsIntersect(glm::vec2 r1p1, glm::vec2 r1p2, glm::vec2 r2p1, glm::vec2 r2p2);
|
||||||
bool isOnSegment(float xi, float yi, float xj, float yj, float xk, float yk);
|
bool isOnSegment(float xi, float yi, float xj, float yj, float xk, float yk);
|
||||||
int computeDirection(float xi, float yi, float xj, float yj, float xk, float yk);
|
int computeDirection(float xi, float yi, float xj, float yj, float xk, float yk);
|
||||||
|
|
Loading…
Reference in a new issue