From 1632f4cb3d448281bd6ca5134b286bbec67bf581 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 16 Aug 2016 10:52:05 -0700 Subject: [PATCH 1/4] better create locations --- scripts/system/edit.js | 53 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 19460b409b..e1360e2398 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1129,36 +1129,37 @@ function handeMenuEvent(menuItem) { tooltip.show(false); } -// This function tries to find a reasonable position to place a new entity based on the camera -// position. If a reasonable position within the world bounds can't be found, `null` will -// be returned. The returned position will also take into account grid snapping settings. function getPositionToCreateEntity() { - var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; - var direction = Quat.getFront(Camera.orientation); - var offset = Vec3.multiply(distance, direction); - var placementPosition = Vec3.sum(Camera.position, offset); - - var cameraPosition = Camera.position; - var HALF_TREE_SCALE = 16384; - - var cameraOutOfBounds = Math.abs(cameraPosition.x) > HALF_TREE_SCALE || Math.abs(cameraPosition.y) > HALF_TREE_SCALE || - Math.abs(cameraPosition.z) > HALF_TREE_SCALE; - var placementOutOfBounds = Math.abs(placementPosition.x) > HALF_TREE_SCALE || - Math.abs(placementPosition.y) > HALF_TREE_SCALE || - Math.abs(placementPosition.z) > HALF_TREE_SCALE; - - if (cameraOutOfBounds && placementOutOfBounds) { - return null; + var direction = Quat.getFront(MyAvatar.orientation); + var distance = 1; + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance)); + position.y +=0.5; + if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) { + return null } - - placementPosition.x = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.x)); - placementPosition.y = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.y)); - placementPosition.z = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.z)); - - return placementPosition; + return position; } +function getPositionToImportEntity() { + var dimensions = Clipboard.getContentsDimensions(); + var HALF_TREE_SCALE = 16384; + var direction = Quat.getFront(MyAvatar.orientation); + var distance = 1; + if (dimensions.x > distance) { + distance = dimensions.x + } + if (dimensions.z > distance) { + distance = dimensions.z + } + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance)); + + if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) { + return null + } + + return position; +} function importSVO(importURL) { print("Import URL requested: " + importURL); if (!Entities.canAdjustLocks()) { @@ -1183,7 +1184,7 @@ function importSVO(importURL) { z: 0 }; if (Clipboard.getClipboardContentsLargestDimension() < VERY_LARGE) { - position = getPositionToCreateEntity(); + position = getPositionToImportEntity(); } if (position !== null && position !== undefined) { var pastedEntityIDs = Clipboard.pasteEntities(position); From 06787029b75abf97e5677dd5908a34de8ea66168 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 16 Aug 2016 17:58:35 -0700 Subject: [PATCH 2/4] small --- scripts/system/edit.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index e1360e2398..5139425b85 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1128,13 +1128,16 @@ function handeMenuEvent(menuItem) { } tooltip.show(false); } - function getPositionToCreateEntity() { var HALF_TREE_SCALE = 16384; var direction = Quat.getFront(MyAvatar.orientation); var distance = 1; var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance)); - position.y +=0.5; + + if (Camera.mode === "entity" || Camera.mode === "independent") { + position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), distance)) + } + position.y += 0.5; if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) { return null } @@ -1145,15 +1148,21 @@ function getPositionToImportEntity() { var dimensions = Clipboard.getContentsDimensions(); var HALF_TREE_SCALE = 16384; var direction = Quat.getFront(MyAvatar.orientation); - var distance = 1; + var distance = 1.5; if (dimensions.x > distance) { - distance = dimensions.x + distance = dimensions.x / 2 } if (dimensions.z > distance) { - distance = dimensions.z + distance = dimensions.z / 2 } var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance)); + print('distance is:: ' + distance); + + if (Camera.mode === "entity" || Camera.mode === "independent") { + position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), distance)) + } + if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) { return null } From e9c2a1d509671769247949e83f3d72d23ed25614 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 16 Aug 2016 18:03:34 -0700 Subject: [PATCH 3/4] cleanup prints --- scripts/system/edit.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 5139425b85..3b623e6271 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1157,8 +1157,6 @@ function getPositionToImportEntity() { } var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance)); - print('distance is:: ' + distance); - if (Camera.mode === "entity" || Camera.mode === "independent") { position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), distance)) } From 0810ad0e7b0f66bb7cf53d9131cfb068fd5ff169 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 16 Aug 2016 18:13:42 -0700 Subject: [PATCH 4/4] use square of sides --- scripts/system/edit.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 3b623e6271..a3e5476bf9 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1148,17 +1148,12 @@ function getPositionToImportEntity() { var dimensions = Clipboard.getContentsDimensions(); var HALF_TREE_SCALE = 16384; var direction = Quat.getFront(MyAvatar.orientation); - var distance = 1.5; - if (dimensions.x > distance) { - distance = dimensions.x / 2 - } - if (dimensions.z > distance) { - distance = dimensions.z / 2 - } - var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance)); + var longest = 1; + longest = Math.sqrt(Math.pow(dimensions.x, 2) + Math.pow(dimensions.z, 2)); + var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, longest)); if (Camera.mode === "entity" || Camera.mode === "independent") { - position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), distance)) + position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), longest)) } if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) {