mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 20:58:38 +02:00
Merge pull request #3915 from ZappoMan/modelRayPick
Proper Model Ray Picking
This commit is contained in:
commit
60c2a89292
42 changed files with 371 additions and 116 deletions
|
@ -19,14 +19,17 @@ function setupMenus() {
|
||||||
if (!Menu.menuExists("Developer > Entities")) {
|
if (!Menu.menuExists("Developer > Entities")) {
|
||||||
Menu.addMenu("Developer > Entities");
|
Menu.addMenu("Developer > Entities");
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Bounds", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Bounds", isCheckable: true, isChecked: false });
|
||||||
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Triangles", isCheckable: true, isChecked: false });
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Bounds", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Bounds", isCheckable: true, isChecked: false });
|
||||||
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Children", isCheckable: true, isChecked: false });
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Display Model Element Children", 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 Do Precision Picking", 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: "Don't Do Precision Picking", 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 });
|
||||||
|
Menu.addMenuItem({ menuName: "Developer > Entities", menuItemName: "Disable Light Entities", isCheckable: true, isChecked: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2554,7 +2554,7 @@ function mousePressEvent(event) {
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
Vec3.print("[Mouse] Looking at: ", pickRay.origin);
|
Vec3.print("[Mouse] Looking at: ", pickRay.origin);
|
||||||
var foundIntersection = Entities.findRayIntersection(pickRay);
|
var foundIntersection = Entities.findRayIntersection(pickRay, true); // we want precision picking here
|
||||||
|
|
||||||
if(!foundIntersection.accurate) {
|
if(!foundIntersection.accurate) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -465,7 +465,7 @@ function rayPlaneIntersection(pickRay, point, normal) {
|
||||||
function findClickedEntity(event) {
|
function findClickedEntity(event) {
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
|
|
||||||
var foundIntersection = Entities.findRayIntersection(pickRay);
|
var foundIntersection = Entities.findRayIntersection(pickRay, true); // want precision picking
|
||||||
|
|
||||||
if (!foundIntersection.accurate) {
|
if (!foundIntersection.accurate) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -367,6 +367,7 @@ namespace MenuOption {
|
||||||
const QString DontCullTooSmallMeshParts = "Don't Cull Too Small Mesh Parts";
|
const QString DontCullTooSmallMeshParts = "Don't Cull Too Small Mesh Parts";
|
||||||
const QString DontReduceMaterialSwitches = "Don't Attempt to Reduce Material Switches";
|
const QString DontReduceMaterialSwitches = "Don't Attempt to Reduce Material Switches";
|
||||||
const QString DontRenderEntitiesAsScene = "Don't Render Entities as Scene";
|
const QString DontRenderEntitiesAsScene = "Don't Render Entities as Scene";
|
||||||
|
const QString DontDoPrecisionPicking = "Don't Do Precision Picking";
|
||||||
const QString DecreaseAvatarSize = "Decrease Avatar Size";
|
const QString DecreaseAvatarSize = "Decrease Avatar Size";
|
||||||
const QString DecreaseVoxelSize = "Decrease Voxel Size";
|
const QString DecreaseVoxelSize = "Decrease Voxel Size";
|
||||||
const QString DisableActivityLogger = "Disable Activity Logger";
|
const QString DisableActivityLogger = "Disable Activity Logger";
|
||||||
|
@ -378,6 +379,7 @@ namespace MenuOption {
|
||||||
const QString DisplayHandTargets = "Show Hand Targets";
|
const QString DisplayHandTargets = "Show Hand Targets";
|
||||||
const QString DisplayHermiteData = "Display Hermite Data";
|
const QString DisplayHermiteData = "Display Hermite Data";
|
||||||
const QString DisplayModelBounds = "Display Model Bounds";
|
const QString DisplayModelBounds = "Display Model Bounds";
|
||||||
|
const QString DisplayModelTriangles = "Display Model Triangles";
|
||||||
const QString DisplayModelElementChildProxies = "Display Model Element Children";
|
const QString DisplayModelElementChildProxies = "Display Model Element Children";
|
||||||
const QString DisplayModelElementProxy = "Display Model Element Bounds";
|
const QString DisplayModelElementProxy = "Display Model Element Bounds";
|
||||||
const QString DisplayTimingDetails = "Display Timing Details";
|
const QString DisplayTimingDetails = "Display Timing Details";
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <glm/gtx/transform.hpp>
|
#include <glm/gtx/transform.hpp>
|
||||||
|
|
||||||
|
#include <GeometryUtil.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include <MetavoxelMessages.h>
|
#include <MetavoxelMessages.h>
|
||||||
|
@ -1095,30 +1096,6 @@ VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>
|
||||||
_materials(materials) {
|
_materials(materials) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
|
||||||
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
|
|
||||||
glm::vec3 firstSide = v0 - v1;
|
|
||||||
glm::vec3 secondSide = v2 - v1;
|
|
||||||
glm::vec3 normal = glm::cross(secondSide, firstSide);
|
|
||||||
float dividend = glm::dot(normal, v1) - glm::dot(origin, normal);
|
|
||||||
if (dividend > 0.0f) {
|
|
||||||
return false; // origin below plane
|
|
||||||
}
|
|
||||||
float divisor = glm::dot(normal, direction);
|
|
||||||
if (divisor > -EPSILON) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
float t = dividend / divisor;
|
|
||||||
glm::vec3 point = origin + direction * t;
|
|
||||||
if (glm::dot(normal, glm::cross(point - v1, firstSide)) > 0.0f &&
|
|
||||||
glm::dot(normal, glm::cross(secondSide, point - v1)) > 0.0f &&
|
|
||||||
glm::dot(normal, glm::cross(point - v0, v2 - v0)) > 0.0f) {
|
|
||||||
distance = t;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
|
bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
|
||||||
const glm::vec3& direction, float& distance) const {
|
const glm::vec3& direction, float& distance) const {
|
||||||
float highest = _size - 1.0f;
|
float highest = _size - 1.0f;
|
||||||
|
|
|
@ -639,7 +639,8 @@ PickRay EntityTreeRenderer::computePickRay(float x, float y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType) {
|
RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||||
|
bool precisionPicking) {
|
||||||
RayToEntityIntersectionResult result;
|
RayToEntityIntersectionResult result;
|
||||||
if (_tree) {
|
if (_tree) {
|
||||||
EntityTree* entityTree = static_cast<EntityTree*>(_tree);
|
EntityTree* entityTree = static_cast<EntityTree*>(_tree);
|
||||||
|
@ -647,7 +648,8 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons
|
||||||
OctreeElement* element;
|
OctreeElement* element;
|
||||||
EntityItem* intersectedEntity = NULL;
|
EntityItem* intersectedEntity = NULL;
|
||||||
result.intersects = entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
result.intersects = entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
||||||
(void**)&intersectedEntity, lockType, &result.accurate);
|
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||||
|
precisionPicking);
|
||||||
if (result.intersects && intersectedEntity) {
|
if (result.intersects && intersectedEntity) {
|
||||||
result.entityID = intersectedEntity->getEntityItemID();
|
result.entityID = intersectedEntity->getEntityItemID();
|
||||||
result.properties = intersectedEntity->getProperties();
|
result.properties = intersectedEntity->getProperties();
|
||||||
|
@ -699,7 +701,9 @@ QScriptValueList EntityTreeRenderer::createEntityArgs(const EntityItemID& entity
|
||||||
void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||||
PerformanceTimer perfTimer("EntityTreeRenderer::mousePressEvent");
|
PerformanceTimer perfTimer("EntityTreeRenderer::mousePressEvent");
|
||||||
PickRay ray = computePickRay(event->x(), event->y());
|
PickRay ray = computePickRay(event->x(), event->y());
|
||||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock);
|
|
||||||
|
bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking);
|
||||||
|
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||||
if (rayPickResult.intersects) {
|
if (rayPickResult.intersects) {
|
||||||
//qDebug() << "mousePressEvent over entity:" << rayPickResult.entityID;
|
//qDebug() << "mousePressEvent over entity:" << rayPickResult.entityID;
|
||||||
emit mousePressOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
emit mousePressOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
||||||
|
@ -723,7 +727,8 @@ void EntityTreeRenderer::mousePressEvent(QMouseEvent* event, unsigned int device
|
||||||
void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
void EntityTreeRenderer::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||||
PerformanceTimer perfTimer("EntityTreeRenderer::mouseReleaseEvent");
|
PerformanceTimer perfTimer("EntityTreeRenderer::mouseReleaseEvent");
|
||||||
PickRay ray = computePickRay(event->x(), event->y());
|
PickRay ray = computePickRay(event->x(), event->y());
|
||||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock);
|
bool precisionPicking = !Menu::getInstance()->isOptionChecked(MenuOption::DontDoPrecisionPicking);
|
||||||
|
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||||
if (rayPickResult.intersects) {
|
if (rayPickResult.intersects) {
|
||||||
//qDebug() << "mouseReleaseEvent over entity:" << rayPickResult.entityID;
|
//qDebug() << "mouseReleaseEvent over entity:" << rayPickResult.entityID;
|
||||||
emit mouseReleaseOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
emit mouseReleaseOnEntity(rayPickResult.entityID, MouseEvent(*event, deviceID));
|
||||||
|
@ -757,7 +762,9 @@ void EntityTreeRenderer::mouseMoveEvent(QMouseEvent* event, unsigned int deviceI
|
||||||
PerformanceTimer perfTimer("EntityTreeRenderer::mouseMoveEvent");
|
PerformanceTimer perfTimer("EntityTreeRenderer::mouseMoveEvent");
|
||||||
|
|
||||||
PickRay ray = computePickRay(event->x(), event->y());
|
PickRay ray = computePickRay(event->x(), event->y());
|
||||||
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::TryLock);
|
|
||||||
|
bool precisionPicking = false; // for mouse moves we do not do precision picking
|
||||||
|
RayToEntityIntersectionResult rayPickResult = findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking);
|
||||||
if (rayPickResult.intersects) {
|
if (rayPickResult.intersects) {
|
||||||
QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID);
|
QScriptValueList entityScriptArgs = createMouseEventArgs(rayPickResult.entityID, event, deviceID);
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,8 @@ private:
|
||||||
QList<Model*> _releasedModels;
|
QList<Model*> _releasedModels;
|
||||||
void renderProxies(const EntityItem* entity, RenderArgs* args);
|
void renderProxies(const EntityItem* entity, RenderArgs* args);
|
||||||
PickRay computePickRay(float x, float y);
|
PickRay computePickRay(float x, float y);
|
||||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType);
|
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||||
|
bool precisionPicking);
|
||||||
|
|
||||||
EntityItemID _currentHoverOverEntityID;
|
EntityItemID _currentHoverOverEntityID;
|
||||||
EntityItemID _currentClickingOnEntityID;
|
EntityItemID _currentClickingOnEntityID;
|
||||||
|
|
|
@ -93,7 +93,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) {
|
||||||
|
|
||||||
bool RenderableLightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool RenderableLightEntityItem::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) const {
|
void** intersectedObject, bool precisionPicking) const {
|
||||||
|
|
||||||
// TODO: this isn't really correct because we don't know if we actually live in the main tree of the applications's
|
// TODO: this isn't really correct because we don't know if we actually live in the main tree of the applications's
|
||||||
// EntityTreeRenderer. But we probably do. Technically we could be on the clipboard and someone might be trying to
|
// EntityTreeRenderer. But we probably do. Technically we could be on the clipboard and someone might be trying to
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||||
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) const;
|
void** intersectedObject, bool precisionPicking) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -173,10 +173,18 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
|
||||||
// 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 = Menu::getInstance()->isOptionChecked(MenuOption::DontRenderEntitiesAsScene);
|
||||||
if (dontRenderAsScene) {
|
bool displayModelTriangles = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelTriangles);
|
||||||
_model->render(alpha, modelRenderMode, args);
|
bool rendered = false;
|
||||||
} else {
|
if (displayModelTriangles) {
|
||||||
_model->renderInScene(alpha, args);
|
rendered = _model->renderTriangleProxies();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rendered) {
|
||||||
|
if (dontRenderAsScene) {
|
||||||
|
_model->render(alpha, modelRenderMode, args);
|
||||||
|
} else {
|
||||||
|
_model->renderInScene(alpha, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if we couldn't get a model, then just draw a cube
|
// if we couldn't get a model, then just draw a cube
|
||||||
|
@ -257,7 +265,26 @@ EntityItemProperties RenderableModelEntityItem::getProperties() const {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
|
void** intersectedObject, bool precisionPicking) const {
|
||||||
|
|
||||||
|
glm::vec3 originInMeters = origin * (float)TREE_SCALE;
|
||||||
|
QString extraInfo;
|
||||||
|
float localDistance;
|
||||||
|
|
||||||
|
//qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection() precisionPicking:" << precisionPicking;
|
||||||
|
|
||||||
|
bool intersectsModel = _model->findRayIntersectionAgainstSubMeshes(originInMeters, direction,
|
||||||
|
localDistance, face, extraInfo, precisionPicking);
|
||||||
|
|
||||||
|
if (intersectsModel) {
|
||||||
|
// NOTE: findRayIntersectionAgainstSubMeshes() does work in meters, but we're expected to return
|
||||||
|
// results in tree scale.
|
||||||
|
distance = localDistance / (float)TREE_SCALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return intersectsModel; // we only got here if we intersected our non-aabox
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,11 @@ public:
|
||||||
virtual void somethingChangedNotification() { _needsInitialSimulation = true; }
|
virtual void somethingChangedNotification() { _needsInitialSimulation = true; }
|
||||||
|
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||||
|
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
|
void** intersectedObject, bool precisionPicking) const;
|
||||||
|
|
||||||
Model* getModel(EntityTreeRenderer* renderer);
|
Model* getModel(EntityTreeRenderer* renderer);
|
||||||
private:
|
private:
|
||||||
void remapTextures();
|
void remapTextures();
|
||||||
|
|
|
@ -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
|
||||||
|
@ -269,7 +270,7 @@ void Model::init() {
|
||||||
_program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model.vert");
|
_program.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/model.vert");
|
||||||
_program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model.frag");
|
_program.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + "shaders/model.frag");
|
||||||
_program.link();
|
_program.link();
|
||||||
|
|
||||||
initProgram(_program, _locations);
|
initProgram(_program, _locations);
|
||||||
|
|
||||||
_normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
_normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex,
|
||||||
|
@ -515,8 +516,61 @@ void Model::setJointStates(QVector<JointState> states) {
|
||||||
_boundingRadius = radius;
|
_boundingRadius = radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction,
|
bool Model::renderTriangleProxies() {
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const {
|
if (!isActive()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_calculatedMeshTrianglesValid) {
|
||||||
|
int color = 0;
|
||||||
|
foreach (const QVector<Triangle>& meshTriangles, _calculatedMeshTriangles) {
|
||||||
|
switch(color) {
|
||||||
|
case 0: glColor3ub( 0, 0, 255); break;
|
||||||
|
case 1: glColor3ub( 0, 255, 0); break;
|
||||||
|
case 2: glColor3ub( 0, 255, 255); break;
|
||||||
|
case 3: glColor3ub(255, 0, 0); break;
|
||||||
|
case 4: glColor3ub(255, 0, 255); break;
|
||||||
|
case 5: glColor3ub(255, 255, 0); break;
|
||||||
|
case 6: glColor3ub( 0, 0, 128); break;
|
||||||
|
case 7: glColor3ub( 0, 128, 0); break;
|
||||||
|
case 8: glColor3ub( 0, 128, 128); break;
|
||||||
|
case 9: glColor3ub(128, 0, 0); break;
|
||||||
|
case 10: glColor3ub(128, 0, 128); break;
|
||||||
|
case 11: glColor3ub(128, 128, 0); break;
|
||||||
|
case 12: glColor3ub(128, 128, 255); break;
|
||||||
|
case 13: glColor3ub(128, 255, 128); break;
|
||||||
|
case 14: glColor3ub(128, 255, 255); break;
|
||||||
|
case 15: glColor3ub(255, 128, 128); break;
|
||||||
|
case 16: glColor3ub(255, 128, 255); break;
|
||||||
|
case 17: glColor3ub(255, 255, 128); break;
|
||||||
|
default: glColor3ub(255,255, 255); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_calculatedMeshBoxes.size() > color) {
|
||||||
|
const AABox& box = _calculatedMeshBoxes[color];
|
||||||
|
glm::vec3 center = box.calcCenter();
|
||||||
|
glm::vec3 dimensions = box.getDimensions();
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(center.x, center.y, center.z);
|
||||||
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
|
Application::getInstance()->getDeferredLightingEffect()->renderWireCube(1.0f);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
foreach (const Triangle& triangle, meshTriangles) {
|
||||||
|
glVertex3f( triangle.v0.x, triangle.v0.y, triangle.v0.z);
|
||||||
|
glVertex3f( triangle.v1.x, triangle.v1.y, triangle.v1.z);
|
||||||
|
glVertex3f( triangle.v2.x, triangle.v2.y, triangle.v2.z);
|
||||||
|
}
|
||||||
|
glEnd();
|
||||||
|
color++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _calculatedMeshTrianglesValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
||||||
|
BoxFace& face, QString& extraInfo, bool pickAgainstTriangles) {
|
||||||
|
|
||||||
bool intersectedSomething = false;
|
bool intersectedSomething = false;
|
||||||
|
|
||||||
|
@ -524,7 +578,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
if (!isActive()) {
|
if (!isActive()) {
|
||||||
return intersectedSomething;
|
return intersectedSomething;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
glm::mat4 rotation = glm::mat4_cast(_rotation);
|
glm::mat4 rotation = glm::mat4_cast(_rotation);
|
||||||
|
@ -535,35 +589,70 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
Extents modelExtents = getMeshExtents(); // NOTE: unrotated
|
Extents modelExtents = getMeshExtents(); // NOTE: unrotated
|
||||||
|
|
||||||
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 modelFrameBox(corner, dimensions);
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
// 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 (modelFrameBox.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();
|
|
||||||
|
|
||||||
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
|
if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) {
|
||||||
if (distanceToSubMesh < bestDistance) {
|
if (distanceToSubMesh < bestDistance) {
|
||||||
bestDistance = distanceToSubMesh;
|
if (pickAgainstTriangles) {
|
||||||
intersectedSomething = true;
|
someTriangleHit = false;
|
||||||
face = subMeshFace;
|
if (!_calculatedMeshTrianglesValid) {
|
||||||
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
recalculateMeshBoxes(pickAgainstTriangles);
|
||||||
|
}
|
||||||
|
// check our triangles here....
|
||||||
|
const QVector<Triangle>& meshTriangles = _calculatedMeshTriangles[subMeshIndex];
|
||||||
|
int t = 0;
|
||||||
|
foreach (const Triangle& triangle, meshTriangles) {
|
||||||
|
t++;
|
||||||
|
|
||||||
|
float thisTriangleDistance;
|
||||||
|
if (findRayTriangleIntersection(origin, direction, triangle, thisTriangleDistance)) {
|
||||||
|
if (thisTriangleDistance < bestDistance) {
|
||||||
|
bestTriangleDistance = thisTriangleDistance;
|
||||||
|
someTriangleHit = true;
|
||||||
|
|
||||||
|
bestDistance = thisTriangleDistance;
|
||||||
|
intersectedSomething = true;
|
||||||
|
face = subMeshFace;
|
||||||
|
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// this is the non-triangle picking case...
|
||||||
|
bestDistance = distanceToSubMesh;
|
||||||
|
intersectedSomething = true;
|
||||||
|
face = subMeshFace;
|
||||||
|
extraInfo = geometry.getModelNameOfMesh(subMeshIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subMeshIndex++;
|
subMeshIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (intersectedSomething) {
|
||||||
|
distance = bestDistance;
|
||||||
|
}
|
||||||
|
|
||||||
return intersectedSomething;
|
return intersectedSomething;
|
||||||
}
|
}
|
||||||
|
@ -571,18 +660,81 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
return intersectedSomething;
|
return intersectedSomething;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::recalcuateMeshBoxes() {
|
// TODO: we seem to call this too often when things haven't actually changed... look into optimizing this
|
||||||
if (!_calculatedMeshBoxesValid) {
|
void Model::recalculateMeshBoxes(bool pickAgainstTriangles) {
|
||||||
|
bool calculatedMeshTrianglesNeeded = pickAgainstTriangles && !_calculatedMeshTrianglesValid;
|
||||||
|
|
||||||
|
if (!_calculatedMeshBoxesValid || calculatedMeshTrianglesNeeded) {
|
||||||
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();
|
||||||
|
_calculatedMeshTriangles.resize(numberOfMeshes);
|
||||||
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);
|
||||||
|
|
||||||
_calculatedMeshBoxes[i] = AABox(scaledMeshExtents);
|
_calculatedMeshBoxes[i] = AABox(scaledMeshExtents);
|
||||||
|
|
||||||
|
if (pickAgainstTriangles) {
|
||||||
|
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;
|
||||||
|
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)));
|
||||||
|
|
||||||
|
// Sam's recommended triangle slices
|
||||||
|
Triangle tri1 = { v0, v1, v3 };
|
||||||
|
Triangle tri2 = { v1, v2, v3 };
|
||||||
|
|
||||||
|
// NOTE: Random guy on the internet's recommended triangle slices
|
||||||
|
//Triangle tri1 = { v0, v1, v2 };
|
||||||
|
//Triangle tri2 = { v2, v3, v0 };
|
||||||
|
|
||||||
|
thisMeshTriangles.push_back(tri1);
|
||||||
|
thisMeshTriangles.push_back(tri2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (part.triangleIndices.size() > 0) {
|
||||||
|
int numberOfTris = part.triangleIndices.size() / INDICES_PER_TRIANGLE;
|
||||||
|
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 };
|
||||||
|
|
||||||
|
thisMeshTriangles.push_back(tri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_calculatedMeshTriangles[i] = thisMeshTriangles;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_calculatedMeshBoxesValid = true;
|
_calculatedMeshBoxesValid = true;
|
||||||
|
_calculatedMeshTrianglesValid = pickAgainstTriangles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,7 +744,7 @@ void Model::renderSetup(RenderArgs* args) {
|
||||||
// against. We cache the results of these calculations so long as the model hasn't been
|
// against. We cache the results of these calculations so long as the model hasn't been
|
||||||
// simulated and the mesh hasn't changed.
|
// simulated and the mesh hasn't changed.
|
||||||
if (args && !_calculatedMeshBoxesValid) {
|
if (args && !_calculatedMeshBoxesValid) {
|
||||||
recalcuateMeshBoxes();
|
recalculateMeshBoxes();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up dilated textures on first render after load/simulate
|
// set up dilated textures on first render after load/simulate
|
||||||
|
@ -844,6 +996,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()) {
|
||||||
|
@ -1142,6 +1303,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"
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ public:
|
||||||
enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE };
|
enum RenderMode { DEFAULT_RENDER_MODE, SHADOW_RENDER_MODE, DIFFUSE_RENDER_MODE, NORMAL_RENDER_MODE };
|
||||||
|
|
||||||
bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_RENDER_MODE, RenderArgs* args = NULL);
|
bool render(float alpha = 1.0f, RenderMode mode = DEFAULT_RENDER_MODE, RenderArgs* args = NULL);
|
||||||
|
bool renderTriangleProxies();
|
||||||
|
|
||||||
// Scene rendering support
|
// Scene rendering support
|
||||||
static void startScene(RenderArgs::RenderSide renderSide);
|
static void startScene(RenderArgs::RenderSide renderSide);
|
||||||
|
@ -119,6 +120,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; }
|
||||||
|
|
||||||
|
@ -193,8 +197,8 @@ public:
|
||||||
Q_INVOKABLE void setTextureWithNameToURL(const QString& name, const QUrl& url)
|
Q_INVOKABLE void setTextureWithNameToURL(const QString& name, const QUrl& url)
|
||||||
{ _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,
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
BoxFace& face, QString& extraInfo, bool pickAgainstTriangles = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSharedPointer<NetworkGeometry> _geometry;
|
QSharedPointer<NetworkGeometry> _geometry;
|
||||||
|
@ -318,7 +322,7 @@ private:
|
||||||
static ProgramObject _skinTranslucentProgram;
|
static ProgramObject _skinTranslucentProgram;
|
||||||
|
|
||||||
static ProgramObject _skinShadowProgram;
|
static ProgramObject _skinShadowProgram;
|
||||||
|
|
||||||
static int _normalMapTangentLocation;
|
static int _normalMapTangentLocation;
|
||||||
static int _normalSpecularMapTangentLocation;
|
static int _normalSpecularMapTangentLocation;
|
||||||
|
|
||||||
|
@ -361,10 +365,13 @@ 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 recalculateMeshBoxes(bool pickAgainstTriangles = false);
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -138,7 +138,7 @@ public:
|
||||||
virtual bool supportsDetailedRayIntersection() const { return false; }
|
virtual bool supportsDetailedRayIntersection() const { return false; }
|
||||||
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) const { return true; }
|
void** intersectedObject, bool precisionPicking) const { return true; }
|
||||||
|
|
||||||
// attributes applicable to all entity types
|
// attributes applicable to all entity types
|
||||||
EntityTypes::EntityType getType() const { return _type; }
|
EntityTypes::EntityType getType() const { return _type; }
|
||||||
|
|
|
@ -196,22 +196,26 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray) {
|
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking) {
|
||||||
return findRayIntersectionWorker(ray, Octree::TryLock);
|
return findRayIntersectionWorker(ray, Octree::TryLock, precisionPicking);
|
||||||
}
|
}
|
||||||
|
|
||||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray) {
|
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking) {
|
||||||
return findRayIntersectionWorker(ray, Octree::Lock);
|
return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking);
|
||||||
}
|
}
|
||||||
|
|
||||||
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
|
RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray,
|
||||||
Octree::lockType lockType) {
|
Octree::lockType lockType,
|
||||||
|
bool precisionPicking) {
|
||||||
|
|
||||||
|
|
||||||
RayToEntityIntersectionResult result;
|
RayToEntityIntersectionResult result;
|
||||||
if (_entityTree) {
|
if (_entityTree) {
|
||||||
OctreeElement* element;
|
OctreeElement* element;
|
||||||
EntityItem* intersectedEntity = NULL;
|
EntityItem* intersectedEntity = NULL;
|
||||||
result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
|
||||||
(void**)&intersectedEntity, lockType, &result.accurate);
|
(void**)&intersectedEntity, lockType, &result.accurate,
|
||||||
|
precisionPicking);
|
||||||
if (result.intersects && intersectedEntity) {
|
if (result.intersects && intersectedEntity) {
|
||||||
result.entityID = intersectedEntity->getEntityItemID();
|
result.entityID = intersectedEntity->getEntityItemID();
|
||||||
result.properties = intersectedEntity->getProperties();
|
result.properties = intersectedEntity->getProperties();
|
||||||
|
|
|
@ -90,11 +90,11 @@ public slots:
|
||||||
/// If the scripting context has visible voxels, this will determine a ray intersection, the results
|
/// If the scripting context has visible voxels, this will determine a ray intersection, the results
|
||||||
/// may be inaccurate if the engine is unable to access the visible voxels, in which case result.accurate
|
/// may be inaccurate if the engine is unable to access the visible voxels, in which case result.accurate
|
||||||
/// will be false.
|
/// will be false.
|
||||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray);
|
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false);
|
||||||
|
|
||||||
/// If the scripting context has visible voxels, this will determine a ray intersection, and will block in
|
/// If the scripting context has visible voxels, this will determine a ray intersection, and will block in
|
||||||
/// order to return an accurate result
|
/// order to return an accurate result
|
||||||
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray);
|
Q_INVOKABLE RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray, bool precisionPicking = false);
|
||||||
|
|
||||||
Q_INVOKABLE void setLightsArePickable(bool value);
|
Q_INVOKABLE void setLightsArePickable(bool value);
|
||||||
Q_INVOKABLE bool getLightsArePickable() const;
|
Q_INVOKABLE bool getLightsArePickable() const;
|
||||||
|
@ -124,7 +124,8 @@ private:
|
||||||
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
||||||
|
|
||||||
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
||||||
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType);
|
RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType,
|
||||||
|
bool precisionPicking);
|
||||||
|
|
||||||
uint32_t _nextCreatorTokenID;
|
uint32_t _nextCreatorTokenID;
|
||||||
EntityTree* _entityTree;
|
EntityTree* _entityTree;
|
||||||
|
|
|
@ -475,13 +475,17 @@ 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, bool precisionPicking, 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...
|
||||||
|
int entityNumber = 0;
|
||||||
|
|
||||||
QList<EntityItem*>::iterator entityItr = _entityItems->begin();
|
QList<EntityItem*>::iterator entityItr = _entityItems->begin();
|
||||||
QList<EntityItem*>::const_iterator entityEnd = _entityItems->end();
|
QList<EntityItem*>::const_iterator entityEnd = _entityItems->end();
|
||||||
bool somethingIntersected = false;
|
bool somethingIntersected = false;
|
||||||
|
|
||||||
|
//float bestEntityDistance = distance;
|
||||||
|
|
||||||
while(entityItr != entityEnd) {
|
while(entityItr != entityEnd) {
|
||||||
EntityItem* entity = (*entityItr);
|
EntityItem* entity = (*entityItr);
|
||||||
|
|
||||||
|
@ -513,10 +517,9 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
||||||
if (localDistance < distance) {
|
if (localDistance < distance) {
|
||||||
// now ask the entity if we actually intersect
|
// now ask the entity if we actually intersect
|
||||||
if (entity->supportsDetailedRayIntersection()) {
|
if (entity->supportsDetailedRayIntersection()) {
|
||||||
|
|
||||||
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
|
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
|
||||||
localFace, intersectedObject)) {
|
localFace, intersectedObject, precisionPicking)) {
|
||||||
|
|
||||||
if (localDistance < distance) {
|
if (localDistance < distance) {
|
||||||
distance = localDistance;
|
distance = localDistance;
|
||||||
face = localFace;
|
face = localFace;
|
||||||
|
@ -538,6 +541,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
||||||
}
|
}
|
||||||
|
|
||||||
++entityItr;
|
++entityItr;
|
||||||
|
entityNumber++;
|
||||||
}
|
}
|
||||||
return somethingIntersected;
|
return somethingIntersected;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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, bool precisionPicking, 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;
|
||||||
|
|
|
@ -96,7 +96,7 @@ void SphereEntityItem::recalculateCollisionShape() {
|
||||||
|
|
||||||
bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool SphereEntityItem::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) const {
|
void** intersectedObject, bool precisionPicking) const {
|
||||||
|
|
||||||
// NOTE: origin and direction are in tree units. But our _sphereShape is in meters, so we need to
|
// NOTE: origin and direction are in tree units. But our _sphereShape is in meters, so we need to
|
||||||
// do a little math to make these match each other.
|
// do a little math to make these match each other.
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||||
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) const;
|
void** intersectedObject, bool precisionPicking) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void recalculateCollisionShape();
|
virtual void recalculateCollisionShape();
|
||||||
|
|
|
@ -118,7 +118,7 @@ void TextEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
|
||||||
|
|
||||||
bool TextEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool TextEntityItem::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) const {
|
void** intersectedObject, bool precisionPicking) const {
|
||||||
|
|
||||||
RayIntersectionInfo rayInfo;
|
RayIntersectionInfo rayInfo;
|
||||||
rayInfo._rayStart = origin;
|
rayInfo._rayStart = origin;
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||||
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) const;
|
void** intersectedObject, bool precisionPicking) const;
|
||||||
|
|
||||||
static const QString DEFAULT_TEXT;
|
static const QString DEFAULT_TEXT;
|
||||||
void setText(const QString& value) { _text = value; }
|
void setText(const QString& value) { _text = value; }
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -693,13 +693,14 @@ public:
|
||||||
BoxFace& face;
|
BoxFace& face;
|
||||||
void** intersectedObject;
|
void** intersectedObject;
|
||||||
bool found;
|
bool found;
|
||||||
|
bool precisionPicking;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool findRayIntersectionOp(OctreeElement* element, void* extraData) {
|
bool findRayIntersectionOp(OctreeElement* element, void* extraData) {
|
||||||
RayArgs* args = static_cast<RayArgs*>(extraData);
|
RayArgs* args = static_cast<RayArgs*>(extraData);
|
||||||
bool keepSearching = true;
|
bool keepSearching = true;
|
||||||
if (element->findRayIntersection(args->origin, args->direction, keepSearching,
|
if (element->findRayIntersection(args->origin, args->direction, keepSearching,
|
||||||
args->element, args->distance, args->face, args->intersectedObject)) {
|
args->element, args->distance, args->face, args->intersectedObject, args->precisionPicking)) {
|
||||||
args->found = true;
|
args->found = true;
|
||||||
}
|
}
|
||||||
return keepSearching;
|
return keepSearching;
|
||||||
|
@ -707,8 +708,9 @@ bool findRayIntersectionOp(OctreeElement* element, void* extraData) {
|
||||||
|
|
||||||
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject,
|
OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject,
|
||||||
Octree::lockType lockType, bool* accurateResult) {
|
Octree::lockType lockType, bool* accurateResult, bool precisionPicking) {
|
||||||
RayArgs args = { origin / (float)(TREE_SCALE), direction, element, distance, face, intersectedObject, false};
|
RayArgs args = { origin / (float)(TREE_SCALE), direction, element, distance, face,
|
||||||
|
intersectedObject, false, precisionPicking};
|
||||||
distance = FLT_MAX;
|
distance = FLT_MAX;
|
||||||
|
|
||||||
bool gotLock = false;
|
bool gotLock = false;
|
||||||
|
|
|
@ -298,7 +298,9 @@ public:
|
||||||
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
OctreeElement*& node, float& distance, BoxFace& face,
|
OctreeElement*& node, float& distance, BoxFace& face,
|
||||||
void** intersectedObject = NULL,
|
void** intersectedObject = NULL,
|
||||||
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);
|
Octree::lockType lockType = Octree::TryLock,
|
||||||
|
bool* accurateResult = NULL,
|
||||||
|
bool precisionPicking = false);
|
||||||
|
|
||||||
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject = NULL,
|
bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject = NULL,
|
||||||
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);
|
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);
|
||||||
|
|
|
@ -1334,16 +1334,20 @@ void OctreeElement::notifyUpdateHooks() {
|
||||||
|
|
||||||
bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool OctreeElement::findRayIntersection(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, bool precisionPicking) {
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
AACube debugCube = cube;
|
||||||
|
debugCube.scale((float)TREE_SCALE);
|
||||||
|
|
||||||
// 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)) {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -1353,14 +1357,18 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
|
||||||
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
|
// if the distance to the element cube is not less than the current best distance, then it's not possible
|
||||||
localDistance *= TREE_SCALE;
|
// for any details inside the cube to be closer so we don't need to consider them.
|
||||||
if (localDistance < distance) {
|
if (cube.contains(origin) || distanceToElementCube < distance) {
|
||||||
if (findDetailedRayIntersection(origin, direction, keepSearching,
|
|
||||||
element, distance, face, intersectedObject)) {
|
if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails,
|
||||||
distance = localDistance;
|
face, intersectedObject, precisionPicking, distanceToElementCube)) {
|
||||||
face = localFace;
|
|
||||||
return true;
|
if (distanceToElementDetails < distance) {
|
||||||
|
distance = distanceToElementDetails;
|
||||||
|
face = localFace;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1368,11 +1376,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, bool precisionPicking, 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,11 +119,11 @@ public:
|
||||||
virtual bool canRayIntersect() const { return isLeaf(); }
|
virtual bool canRayIntersect() const { return isLeaf(); }
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
bool& keepSearching, OctreeElement*& node, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& node, float& distance, BoxFace& face,
|
||||||
void** intersectedObject = NULL);
|
void** intersectedObject = NULL, bool precisionPicking = false);
|
||||||
|
|
||||||
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, bool precisionPicking, 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,30 @@ bool findRayCapsuleIntersection(const glm::vec3& origin, const glm::vec3& direct
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
|
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
|
||||||
|
glm::vec3 firstSide = v0 - v1;
|
||||||
|
glm::vec3 secondSide = v2 - v1;
|
||||||
|
glm::vec3 normal = glm::cross(secondSide, firstSide);
|
||||||
|
float dividend = glm::dot(normal, v1) - glm::dot(origin, normal);
|
||||||
|
if (dividend > 0.0f) {
|
||||||
|
return false; // origin below plane
|
||||||
|
}
|
||||||
|
float divisor = glm::dot(normal, direction);
|
||||||
|
if (divisor > -EPSILON) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
float t = dividend / divisor;
|
||||||
|
glm::vec3 point = origin + direction * t;
|
||||||
|
if (glm::dot(normal, glm::cross(point - v1, firstSide)) > 0.0f &&
|
||||||
|
glm::dot(normal, glm::cross(secondSide, point - v1)) > 0.0f &&
|
||||||
|
glm::dot(normal, glm::cross(point - v0, v2 - v0)) > 0.0f) {
|
||||||
|
distance = t;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
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 findRayTriangleIntersection(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 findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
|
const Triangle& triangle, float& distance) {
|
||||||
|
return findRayTriangleIntersection(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