From 20d1a2440c9487defcf5c34180976aa457c638db Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 14 Oct 2015 11:15:49 -0700 Subject: [PATCH] Ignoring unknown types in collision --- examples/controllers/handControllerGrab.js | 3 +- .../whiteboard/whiteboardEntityScript.js | 38 ++++++++++++------- .../painting/whiteboard/whiteboardSpawner.js | 24 ++++++++++-- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 3445547fa1..0f59e80948 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -67,7 +67,7 @@ var MSEC_PER_SEC = 1000.0; var startTime = Date.now(); var LIFETIME = 10; var ACTION_LIFETIME = 10; // seconds -var PICKS_PER_SECOND_PER_HAND = 5; +var PICKS_PER_SECOND_PER_HAND = 60; var MSECS_PER_SEC = 1000.0; // states for the state machine @@ -177,6 +177,7 @@ function MyController(hand, triggerAction) { this.continueFarGrabbingNonColliding(); break; case STATE_RELEASE: + print("TRIGGER VALUE " + this.triggerValue); this.release(); break; } diff --git a/examples/painting/whiteboard/whiteboardEntityScript.js b/examples/painting/whiteboard/whiteboardEntityScript.js index fe47ec1810..59977fe52a 100644 --- a/examples/painting/whiteboard/whiteboardEntityScript.js +++ b/examples/painting/whiteboard/whiteboardEntityScript.js @@ -20,8 +20,6 @@ var _this; var RIGHT_HAND = 1; var LEFT_HAND = 0; - var SPATIAL_CONTROLLERS_PER_PALM = 2; - var TIP_CONTROLLER_OFFSET = 1; var MIN_POINT_DISTANCE = 0.02; var MAX_POINT_DISTANCE = 0.5; var MAX_POINTS_PER_LINE = 40; @@ -58,7 +56,9 @@ this.getHandRotation = MyAvatar.getLeftPalmRotation; this.triggerAction = Controller.findAction("LEFT_HAND_CLICK"); } - Overlays.editOverlay(this.laserPointer, {visible: true}); + Overlays.editOverlay(this.laserPointer, { + visible: true + }); }, continueFarGrabbingNonColliding: function() { @@ -69,13 +69,14 @@ }; this.intersection = Entities.findRayIntersection(pickRay, true, this.whitelist); + if (this.intersection.intersects) { var distance = Vec3.distance(handPosition, this.intersection.intersection); if (distance < MAX_DISTANCE) { this.triggerValue = Controller.getActionValue(this.triggerAction); this.currentStrokeWidth = map(this.triggerValue, 0, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH); var displayPoint = this.intersection.intersection; - displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, -.01)); + displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, -0.01)); Overlays.editOverlay(this.laserPointer, { position: displayPoint, size: { @@ -90,11 +91,22 @@ this.oldPosition = null; } } - } else { - this.releaseGrab(); + } else if(this.intersection.properties.type !== "Unknown") { + //If type is unknown, ignore + print("entity name " + this.intersection.properties.type); + this.stopPainting(); } }, + stopPainting: function() { + this.painting = false; + Overlays.editOverlay(this.laserPointer, { + visible: false + }); + this.oldPosition = null; + print("STOP PAINTING"); + }, + paint: function(position, normal) { if (this.painting === false) { if (this.oldPosition) { @@ -108,11 +120,12 @@ var localPoint = Vec3.subtract(position, this.strokeBasePosition); //Move stroke a bit forward along normal so it doesnt zfight with mesh its drawing on - localPoint = Vec3.sum(localPoint, Vec3.multiply(this.normal, 0.001 + Math.random() * .001)); //rand avoid z fighting - + localPoint = Vec3.sum(localPoint, Vec3.multiply(this.normal, 0.001 + Math.random() * 0.001)); //rand avoid z fighting + this.oldPosition = position; var distance = Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]); if (this.strokePoints.length > 0 && distance < MIN_POINT_DISTANCE) { //need a minimum distance to avoid binormal NANs + return; } if (this.strokePoints.length > 0 && distance > MAX_POINT_DISTANCE) { @@ -140,7 +153,6 @@ this.painting = false; return; } - this.oldPosition = position; }, @@ -168,9 +180,9 @@ }, releaseGrab: function() { - this.painting = false; - Overlays.editOverlay(this.laserPointer, {visible: false}); - this.oldPosition = null; + print("RELEASE"); + this.stopPainting(); + }, changeColor: function() { @@ -184,7 +196,7 @@ var entities = Entities.findEntities(this.position, 5); entities.forEach(function(entity) { var name = Entities.getEntityProperties(entity, "name").name; - if(name === "paintStroke") { + if (name === "paintStroke") { Entities.deleteEntity(entity); } }); diff --git a/examples/painting/whiteboard/whiteboardSpawner.js b/examples/painting/whiteboard/whiteboardSpawner.js index 32e049aef6..43a490a67e 100644 --- a/examples/painting/whiteboard/whiteboardSpawner.js +++ b/examples/painting/whiteboard/whiteboardSpawner.js @@ -11,8 +11,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html /*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ - - +// Script specific +/*global hexToRgb */ Script.include("../../libraries/utils.js"); var scriptURL = Script.resolvePath("whiteBoardEntityScript.js?v2"); @@ -38,6 +38,7 @@ var colors = [ ]; var whiteboard = Entities.addEntity({ type: "Box", + name: "whiteboard", position: center, rotation: rotation, script: scriptURL, @@ -61,7 +62,7 @@ var colorBoxes = []; var colorSquareDimensions = { x: (whiteboardDimensions.x / 2) / (colors.length - 1), - y: .1, + y: 0.1, z: 0.05 }; colorBoxPosition.y += whiteboardDimensions.y / 2 + colorSquareDimensions.y / 2 - 0.01; @@ -76,7 +77,6 @@ for (var i = 0; i < colors.length; i++) { color: colors[i], script: scriptURL, userData: JSON.stringify({ - colorPalette: true, whiteboard: whiteboard }) }); @@ -84,6 +84,21 @@ for (var i = 0; i < colors.length; i++) { colorBoxPosition = Vec3.sum(colorBoxPosition, spaceBetweenColorBoxes); } +var blackBoxDimensions = {x: .2, y: .2, z: 0.05}; +colorBoxPosition = Vec3.subtract(center, Vec3.multiply(direction, whiteboardDimensions.x / 2 + blackBoxDimensions.x/2 - 0.01)); +colorBoxPosition.y += 0.3; +var blackBox = Entities.addEntity({ + type: 'Box', + position: colorBoxPosition, + dimensions: blackBoxDimensions, + rotation: rotation, + color: {red: 0, green: 0, blue: 0}, + script: scriptURL, + userData: JSON.stringify({ + whiteboard: whiteboard + }) +}) + var eraseBoxDimensions = { x: 0.5, @@ -124,6 +139,7 @@ print(JSON.stringify(Entities.getEntityProperties(eraseAllText))) function cleanup() { Entities.deleteEntity(whiteboard); Entities.deleteEntity(eraseAllText); + Entities.deleteEntity(blackBox); colorBoxes.forEach(function(colorBox) { Entities.deleteEntity(colorBox); });