From 41720dbc4b0ca9f29fe1d8ef8702a1f5f00523cd Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 5 Feb 2015 10:07:31 -0800 Subject: [PATCH 1/3] Add drag-drop functionality for placing entities --- examples/editEntities.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index 220f10dffa..de8b0a29f5 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -94,6 +94,7 @@ var modelURLs = [ var mode = 0; var isActive = false; +var placingEntityID = null; var toolBar = (function () { var that = {}, @@ -363,7 +364,7 @@ var toolBar = (function () { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Box", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), dimensions: DEFAULT_DIMENSIONS, @@ -380,7 +381,7 @@ var toolBar = (function () { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Sphere", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), dimensions: DEFAULT_DIMENSIONS, @@ -396,7 +397,7 @@ var toolBar = (function () { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Light", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), dimensions: DEFAULT_DIMENSIONS, @@ -421,7 +422,7 @@ var toolBar = (function () { var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE)); if (position.x > 0 && position.y > 0 && position.z > 0) { - Entities.addEntity({ + placingEntityID = Entities.addEntity({ type: "Text", position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS), dimensions: { x: 0.5, y: 0.3, z: 0.01 }, @@ -535,6 +536,18 @@ var idleMouseTimerId = null; var IDLE_MOUSE_TIMEOUT = 200; function mouseMoveEvent(event) { + if (placingEntityID) { + if (!placingEntityID.isKnownID) { + placingEntityID = Entities.identifyEntity(placingEntityID); + } + var pickRay = Camera.computePickRay(event.x, event.y); + var offset = Vec3.multiply(cameraManager.zoomDistance, pickRay.direction); + var position = Vec3.sum(Camera.position, offset); + Entities.editEntity(placingEntityID, { + position: position, + }); + return; + } if (!isActive) { return; } @@ -590,6 +603,10 @@ function highlightEntityUnderCursor(position, accurateRay) { function mouseReleaseEvent(event) { + if (placingEntityID) { + selectionManager.setSelections([placingEntityID]); + placingEntityID = null; + } if (isActive && selectionManager.hasSelection()) { tooltip.show(false); } From 2343da0a8ac15e9d1f7a79147f461b4d525369f6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 5 Feb 2015 10:16:51 -0800 Subject: [PATCH 2/3] Update drag/drop distance while in non-independent mode --- examples/editEntities.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index de8b0a29f5..ac6fce205a 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -534,6 +534,7 @@ var mouseCapturedByTool = false; var lastMousePosition = null; var idleMouseTimerId = null; var IDLE_MOUSE_TIMEOUT = 200; +var DEFAULT_ENTITY_DRAG_DROP_DISTANCE = 2.0; function mouseMoveEvent(event) { if (placingEntityID) { @@ -541,7 +542,8 @@ function mouseMoveEvent(event) { placingEntityID = Entities.identifyEntity(placingEntityID); } var pickRay = Camera.computePickRay(event.x, event.y); - var offset = Vec3.multiply(cameraManager.zoomDistance, pickRay.direction); + var distance = Camera.mode == "independent" ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; + var offset = Vec3.multiply(distance, pickRay.direction); var position = Vec3.sum(Camera.position, offset); Entities.editEntity(placingEntityID, { position: position, From 1e11e658a809aa755ba2d5543ae2e70914ac0801 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 5 Feb 2015 10:18:34 -0800 Subject: [PATCH 3/3] Update drag/drop distance to be based on cameraManager.enabled rather than camera mode --- examples/editEntities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index ac6fce205a..d73c6fa6e7 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -542,7 +542,7 @@ function mouseMoveEvent(event) { placingEntityID = Entities.identifyEntity(placingEntityID); } var pickRay = Camera.computePickRay(event.x, event.y); - var distance = Camera.mode == "independent" ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; + var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; var offset = Vec3.multiply(distance, pickRay.direction); var position = Vec3.sum(Camera.position, offset); Entities.editEntity(placingEntityID, {