From 3b59bffb79ae88caa6e703e52cc6120132729379 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 15 Oct 2015 11:38:18 -0700 Subject: [PATCH] Deleting only strokes from the whiteboard where the erase button was clicked on --- .../whiteboard/whiteboardEntityScript.js | 23 ++++++++++++++----- .../painting/whiteboard/whiteboardSpawner.js | 2 +- libraries/octree/src/Octree.cpp | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/examples/painting/whiteboard/whiteboardEntityScript.js b/examples/painting/whiteboard/whiteboardEntityScript.js index 9ed5d21065..cff028c566 100644 --- a/examples/painting/whiteboard/whiteboardEntityScript.js +++ b/examples/painting/whiteboard/whiteboardEntityScript.js @@ -93,7 +93,7 @@ this.oldPosition = null; } } - } else if(this.intersection.properties.type !== "Unknown") { + } else if (this.intersection.properties.type !== "Unknown") { //Sometimes ray will pick against an invisible object with type unkown... so if type is unknown, ignore this.stopPainting(); } @@ -169,7 +169,10 @@ y: 50, z: 50 }, - lifetime: 200 + lifetime: 200, + userData: JSON.stringify({ + whiteboard: this.entityID + }) }); this.strokePoints = []; this.strokeNormals = []; @@ -194,10 +197,17 @@ }, eraseBoard: function() { - var entities = Entities.findEntities(this.position, 5); + var distance = Math.max(this.dimensions.x, this.dimensions.y); + var entities = Entities.findEntities(this.position, distance); entities.forEach(function(entity) { - var name = Entities.getEntityProperties(entity, "name").name; - if (name === "paintStroke") { + var props = Entities.getEntityProperties(entity, ["name, userData"]); + var name = props.name; + if(!props.userData) { + return; + } + var whiteboardID = JSON.parse(props.userData).whiteboard; + if (name === "paintStroke" && JSON.stringify(whiteboardID) === JSON.stringify(_this.entityID)) { + // This entity is a paintstroke and part of this whiteboard so delete it Entities.deleteEntity(entity); } }); @@ -205,9 +215,10 @@ preload: function(entityID) { this.entityID = entityID; - var props = Entities.getEntityProperties(this.entityID, ["position", "rotation", "userData"]); + var props = Entities.getEntityProperties(this.entityID, ["position", "rotation", "userData", "dimensions"]); this.position = props.position; this.rotation = props.rotation; + this.dimensions = props.dimensions; this.normal = Vec3.multiply(Quat.getFront(this.rotation), -1); this.painting = false; this.strokes = []; diff --git a/examples/painting/whiteboard/whiteboardSpawner.js b/examples/painting/whiteboard/whiteboardSpawner.js index 4219ee30bc..51e4dee87d 100644 --- a/examples/painting/whiteboard/whiteboardSpawner.js +++ b/examples/painting/whiteboard/whiteboardSpawner.js @@ -189,4 +189,4 @@ function cleanup() { // Uncomment this line to delete whiteboard and all associated entity on script close -Script.scriptEnding.connect(cleanup); \ No newline at end of file +// Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 6f6f5af303..3b6467401c 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -724,7 +724,7 @@ bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direc OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, void** intersectedObject, Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { - RayArgs args = { origin, direction, element, distance, face, surfaceNormal, intersectedObject, false, precisionPicking}; + RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, intersectedObject, false, precisionPicking}; distance = FLT_MAX; bool requireLock = lockType == Octree::Lock;