From ddce8d5a3a8a63a95774a9404ed8edbc014029da Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 19 Feb 2016 10:59:05 -0800 Subject: [PATCH] Marker basics working, now just need to tweak --- .../whiteboardV2/markerEntityScript.js | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/examples/homeContent/whiteboardV2/markerEntityScript.js b/examples/homeContent/whiteboardV2/markerEntityScript.js index d3a4f97fe9..e879b71144 100644 --- a/examples/homeContent/whiteboardV2/markerEntityScript.js +++ b/examples/homeContent/whiteboardV2/markerEntityScript.js @@ -16,6 +16,7 @@ MarkerTip = function() { _this = this; + _this.MARKER_TEXTURE_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/textures/paintStroke.png"; }; MarkerTip.prototype = { @@ -42,12 +43,48 @@ var intersection = Entities.findRayIntersection(pickRay, true); if (intersection.intersects) { - var name = Entities.getEntityProperties(intersection.entityID); - this.paint() + this.paint(intersection.intersection) } }, + newStroke: function(position) { + _this.strokeBasePosition = position; + _this.currentStroke = Entities.addEntity({ + type: "PolyLine", + name: "marker stroke", + dimensions: { + x: 10, + y: 10, + z: 10 + }, + position: position, + textures: _this.MARKER_TEXTURE_URL, + color: {red: 0, green: 10, blue: 200} + }); + + _this.linePoints = []; + _this.normals = []; + _this.strokeWidths = []; + }, + + paint: function(position) { + if (!_this.currentStroke) { + _this.newStroke(position); + } + + var localPoint = Vec3.subtract(position, this.strokeBasePosition); + _this.linePoints.push(localPoint); + _this.normals.push(_this._whiteboardNormal); + this.strokeWidths.push(0.02); + + Entities.editEntity(_this.currentStroke, { + linePoints: _this.linePoints, + normals: _this.normals, + strokeWidths: _this.strokeWidths + }); + }, + preload: function(entityID) { this.entityID = entityID; print("EBL PRELOAD"); @@ -56,7 +93,7 @@ setWhiteboard: function(myId, data) { _this.whiteboard = JSON.parse(data[0]); var props = Entities.getEntityProperties(_this.whiteboard, ["rotation"]); - Entities.editEntity(_this.whiteboard, {position: {x: 0, y: 1, z: 0}}); + this._whiteboardNormal = Vec3.multiply(Quat.getFront(props.rotation), -1); } };