mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 06:57:37 +02:00
introduce precision picking in API form
This commit is contained in:
parent
303274a554
commit
7ea85073f4
23 changed files with 74 additions and 78 deletions
|
@ -19,15 +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: "Pick Against Model Triangles", 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;
|
||||||
|
|
|
@ -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";
|
||||||
|
|
|
@ -650,7 +650,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);
|
||||||
|
@ -658,7 +659,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();
|
||||||
|
@ -710,7 +712,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));
|
||||||
|
@ -734,7 +738,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));
|
||||||
|
@ -768,7 +773,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
|
||||||
|
@ -259,24 +267,21 @@ EntityItemProperties RenderableModelEntityItem::getProperties() const {
|
||||||
|
|
||||||
bool RenderableModelEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool RenderableModelEntityItem::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 {
|
||||||
|
|
||||||
//qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection()....";
|
|
||||||
//qDebug() << " this.id:" << getEntityItemID();
|
|
||||||
//qDebug() << " this.modelURL:" << getModelURL();
|
|
||||||
//qDebug() << " origin:" << origin;
|
|
||||||
glm::vec3 originInMeters = origin * (float)TREE_SCALE;
|
glm::vec3 originInMeters = origin * (float)TREE_SCALE;
|
||||||
//qDebug() << " originInMeters:" << originInMeters;
|
|
||||||
QString extraInfo;
|
QString extraInfo;
|
||||||
float localDistance;
|
float localDistance;
|
||||||
|
|
||||||
bool intersectsModel = _model->findRayIntersectionAgainstSubMeshes(originInMeters, direction, localDistance, face, extraInfo);
|
qDebug() << "RenderableModelEntityItem::findDetailedRayIntersection() precisionPicking:" << precisionPicking;
|
||||||
|
|
||||||
|
bool intersectsModel = _model->findRayIntersectionAgainstSubMeshes(originInMeters, direction,
|
||||||
|
localDistance, face, extraInfo, precisionPicking);
|
||||||
|
|
||||||
if (intersectsModel) {
|
if (intersectsModel) {
|
||||||
// NOTE: findRayIntersectionAgainstSubMeshes() does work in meters, but we're expected to return
|
// NOTE: findRayIntersectionAgainstSubMeshes() does work in meters, but we're expected to return
|
||||||
// results in tree scale.
|
// 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,7 +54,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;
|
||||||
|
|
||||||
Model* getModel(EntityTreeRenderer* renderer);
|
Model* getModel(EntityTreeRenderer* renderer);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -640,7 +640,7 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g
|
||||||
someTriangleHit = false;
|
someTriangleHit = false;
|
||||||
//qDebug() << " subMeshBox[" << subMeshIndex <<"] --- check triangles!!";
|
//qDebug() << " subMeshBox[" << subMeshIndex <<"] --- check triangles!!";
|
||||||
if (!_calculatedMeshTrianglesValid) {
|
if (!_calculatedMeshTrianglesValid) {
|
||||||
recalcuateMeshBoxes();
|
recalcuateMeshBoxes(pickAgainstTriangles);
|
||||||
}
|
}
|
||||||
// check our triangles here....
|
// check our triangles here....
|
||||||
const QVector<Triangle>& meshTriangles = _calculatedMeshTriangles[subMeshIndex];
|
const QVector<Triangle>& meshTriangles = _calculatedMeshTriangles[subMeshIndex];
|
||||||
|
|
|
@ -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,16 +196,17 @@ 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;
|
||||||
|
|
|
@ -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,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, float distanceToElementCube) {
|
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...
|
||||||
|
|
||||||
|
@ -540,7 +540,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
||||||
//qDebug() << " 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, precisionPicking)) {
|
||||||
|
|
||||||
//qDebug() << " localDistance (detailed):" << localDistance;
|
//qDebug() << " localDistance (detailed):" << localDistance;
|
||||||
|
|
||||||
|
|
|
@ -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, float distanceToElementCube);
|
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; }
|
||||||
|
|
|
@ -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,7 +1334,7 @@ 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.
|
||||||
|
|
||||||
|
@ -1346,55 +1346,28 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
|
||||||
AACube debugCube = cube;
|
AACube debugCube = cube;
|
||||||
debugCube.scale((float)TREE_SCALE);
|
debugCube.scale((float)TREE_SCALE);
|
||||||
|
|
||||||
//qDebug() << "OctreeElement::findRayIntersection()....";
|
|
||||||
//qDebug() << " origin:" << origin;
|
|
||||||
//qDebug() << " checking element:" << debugCube << "in meters";
|
|
||||||
//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, distanceToElementCube, 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()) {
|
||||||
//qDebug() << " NOT canRayIntersect() -- no point in calling detailed...";
|
|
||||||
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
|
|
||||||
//localDistance *= TREE_SCALE;
|
|
||||||
|
|
||||||
// if the distance to the element cube is not less than the current best distance, then it's not possible
|
// 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.
|
// for any details inside the cube to be closer so we don't need to consider them.
|
||||||
if (cube.contains(origin) || distanceToElementCube < distance) {
|
if (cube.contains(origin) || distanceToElementCube < distance) {
|
||||||
|
|
||||||
//qDebug() << " distanceToElementCube < distance:" << (distanceToElementCube < distance);
|
if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails,
|
||||||
//qDebug() << " cube.contains(origin):" << (cube.contains(origin));
|
face, intersectedObject, precisionPicking, distanceToElementCube)) {
|
||||||
//qDebug() << " continue.... call... findDetailedRayIntersection()...";
|
|
||||||
//qDebug() << " distanceToElementCube < distance -- continue.... call... findDetailedRayIntersection()...";
|
|
||||||
|
|
||||||
if (findDetailedRayIntersection(origin, direction, keepSearching,
|
|
||||||
element, distanceToElementDetails, face, intersectedObject, distanceToElementCube)) {
|
|
||||||
|
|
||||||
//qDebug() << " findDetailedRayIntersection() -- intersected something";
|
|
||||||
if (distanceToElementDetails < distance) {
|
if (distanceToElementDetails < distance) {
|
||||||
//qDebug() << " distanceToElementDetails < distance -- THIS ONE IS GOOD -------";
|
|
||||||
|
|
||||||
distance = distanceToElementDetails;
|
distance = distanceToElementDetails;
|
||||||
face = localFace;
|
face = localFace;
|
||||||
|
|
||||||
//qDebug() << " distance:" << distance << " -- THIS ONE IS GOOD -------";
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
//qDebug() << " distanceToElementDetails:" << distanceToElementDetails;
|
|
||||||
//qDebug() << " distance:" << distance;
|
|
||||||
//qDebug() << " distanceToElementDetails >= distance -- THIS ONE IS NOT SELECTED even though it INTERSECTED -------";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1403,7 +1376,7 @@ 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, float distanceToElementCube) {
|
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()) {
|
||||||
|
|
|
@ -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, float distanceToElementCube);
|
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;
|
||||||
|
|
Loading…
Reference in a new issue