mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:27:48 +02:00
Merge pull request #8441 from imgntn/marketplace_spawn_location
Better create locations for Entities
This commit is contained in:
commit
f66b36ff07
1 changed files with 29 additions and 26 deletions
|
@ -1128,37 +1128,40 @@ function handeMenuEvent(menuItem) {
|
||||||
}
|
}
|
||||||
tooltip.show(false);
|
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() {
|
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 HALF_TREE_SCALE = 16384;
|
||||||
|
var direction = Quat.getFront(MyAvatar.orientation);
|
||||||
|
var distance = 1;
|
||||||
|
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance));
|
||||||
|
|
||||||
var cameraOutOfBounds = Math.abs(cameraPosition.x) > HALF_TREE_SCALE || Math.abs(cameraPosition.y) > HALF_TREE_SCALE ||
|
if (Camera.mode === "entity" || Camera.mode === "independent") {
|
||||||
Math.abs(cameraPosition.z) > HALF_TREE_SCALE;
|
position = Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), distance))
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
position.y += 0.5;
|
||||||
placementPosition.x = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.x));
|
if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) {
|
||||||
placementPosition.y = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.y));
|
return null
|
||||||
placementPosition.z = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.z));
|
}
|
||||||
|
return position;
|
||||||
return placementPosition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPositionToImportEntity() {
|
||||||
|
var dimensions = Clipboard.getContentsDimensions();
|
||||||
|
var HALF_TREE_SCALE = 16384;
|
||||||
|
var direction = Quat.getFront(MyAvatar.orientation);
|
||||||
|
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), longest))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (position.x > HALF_TREE_SCALE || position.y > HALF_TREE_SCALE || position.z > HALF_TREE_SCALE) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
function importSVO(importURL) {
|
function importSVO(importURL) {
|
||||||
print("Import URL requested: " + importURL);
|
print("Import URL requested: " + importURL);
|
||||||
if (!Entities.canAdjustLocks()) {
|
if (!Entities.canAdjustLocks()) {
|
||||||
|
@ -1183,7 +1186,7 @@ function importSVO(importURL) {
|
||||||
z: 0
|
z: 0
|
||||||
};
|
};
|
||||||
if (Clipboard.getClipboardContentsLargestDimension() < VERY_LARGE) {
|
if (Clipboard.getClipboardContentsLargestDimension() < VERY_LARGE) {
|
||||||
position = getPositionToCreateEntity();
|
position = getPositionToImportEntity();
|
||||||
}
|
}
|
||||||
if (position !== null && position !== undefined) {
|
if (position !== null && position !== undefined) {
|
||||||
var pastedEntityIDs = Clipboard.pasteEntities(position);
|
var pastedEntityIDs = Clipboard.pasteEntities(position);
|
||||||
|
|
Loading…
Reference in a new issue