mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:36:30 +02:00
Update tools to snap to grid on creation
This commit is contained in:
parent
2c6a76ec17
commit
6f0d5faa5b
2 changed files with 38 additions and 12 deletions
|
@ -53,11 +53,31 @@ Grid = function(opts) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
that.snapToGrid = function(position, majorOnly) {
|
that.snapToSurface = function(position, dimensions) {
|
||||||
if (!snapToGrid) {
|
if (!snapToGrid) {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dimensions === undefined) {
|
||||||
|
dimensions = { x: 0, y: 0, z: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: position.x,
|
||||||
|
y: origin.y + (dimensions.y / 2),
|
||||||
|
z: position.z
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
that.snapToGrid = function(position, majorOnly, dimensions) {
|
||||||
|
if (!snapToGrid) {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dimensions === undefined) {
|
||||||
|
dimensions = { x: 0, y: 0, z: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
var spacing = majorOnly ? (minorGridSpacing * majorGridEvery) : minorGridSpacing;
|
var spacing = majorOnly ? (minorGridSpacing * majorGridEvery) : minorGridSpacing;
|
||||||
|
|
||||||
position = Vec3.subtract(position, origin);
|
position = Vec3.subtract(position, origin);
|
||||||
|
@ -66,7 +86,7 @@ Grid = function(opts) {
|
||||||
position.y = Math.round(position.y / spacing) * spacing;
|
position.y = Math.round(position.y / spacing) * spacing;
|
||||||
position.z = Math.round(position.z / spacing) * spacing;
|
position.z = Math.round(position.z / spacing) * spacing;
|
||||||
|
|
||||||
return Vec3.sum(position, origin);
|
return Vec3.sum(Vec3.sum(position, Vec3.multiply(0.5, dimensions)), origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
that.snapToSpacing = function(delta, majorOnly) {
|
that.snapToSpacing = function(delta, majorOnly) {
|
||||||
|
|
|
@ -61,6 +61,12 @@ var DEFAULT_TEXT_DIMENSION_X = 1.0;
|
||||||
var DEFAULT_TEXT_DIMENSION_Y = 1.0;
|
var DEFAULT_TEXT_DIMENSION_Y = 1.0;
|
||||||
var DEFAULT_TEXT_DIMENSION_Z = 0.01;
|
var DEFAULT_TEXT_DIMENSION_Z = 0.01;
|
||||||
|
|
||||||
|
var DEFAULT_DIMENSIONS = {
|
||||||
|
x: DEFAULT_DIMENSION,
|
||||||
|
y: DEFAULT_DIMENSION,
|
||||||
|
z: DEFAULT_DIMENSION
|
||||||
|
};
|
||||||
|
|
||||||
var MENU_INSPECT_TOOL_ENABLED = "Inspect Tool";
|
var MENU_INSPECT_TOOL_ENABLED = "Inspect Tool";
|
||||||
var MENU_EASE_ON_FOCUS = "Ease Orientation on Focus";
|
var MENU_EASE_ON_FOCUS = "Ease Orientation on Focus";
|
||||||
|
|
||||||
|
@ -220,8 +226,8 @@ var toolBar = (function () {
|
||||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
var entityId = Entities.addEntity({
|
var entityId = Entities.addEntity({
|
||||||
type: "Model",
|
type: "Model",
|
||||||
position: position,
|
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
|
||||||
dimensions: { x: DEFAULT_DIMENSION, y: DEFAULT_DIMENSION, z: DEFAULT_DIMENSION },
|
dimensions: DEFAULT_DIMENSIONS,
|
||||||
modelURL: url
|
modelURL: url
|
||||||
});
|
});
|
||||||
print("Model added: " + url);
|
print("Model added: " + url);
|
||||||
|
@ -345,8 +351,8 @@ var toolBar = (function () {
|
||||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
Entities.addEntity({
|
Entities.addEntity({
|
||||||
type: "Box",
|
type: "Box",
|
||||||
position: position,
|
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
|
||||||
dimensions: { x: DEFAULT_DIMENSION, y: DEFAULT_DIMENSION, z: DEFAULT_DIMENSION },
|
dimensions: DEFAULT_DIMENSIONS,
|
||||||
color: { red: 255, green: 0, blue: 0 }
|
color: { red: 255, green: 0, blue: 0 }
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -362,8 +368,8 @@ var toolBar = (function () {
|
||||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
Entities.addEntity({
|
Entities.addEntity({
|
||||||
type: "Sphere",
|
type: "Sphere",
|
||||||
position: position,
|
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
|
||||||
dimensions: { x: DEFAULT_DIMENSION, y: DEFAULT_DIMENSION, z: DEFAULT_DIMENSION },
|
dimensions: DEFAULT_DIMENSIONS,
|
||||||
color: { red: 255, green: 0, blue: 0 }
|
color: { red: 255, green: 0, blue: 0 }
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -378,8 +384,8 @@ var toolBar = (function () {
|
||||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
Entities.addEntity({
|
Entities.addEntity({
|
||||||
type: "Light",
|
type: "Light",
|
||||||
position: position,
|
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
|
||||||
dimensions: { x: DEFAULT_DIMENSION, y: DEFAULT_DIMENSION, z: DEFAULT_DIMENSION },
|
dimensions: DEFAULT_DIMENSIONS,
|
||||||
isSpotlight: false,
|
isSpotlight: false,
|
||||||
diffuseColor: { red: 255, green: 255, blue: 255 },
|
diffuseColor: { red: 255, green: 255, blue: 255 },
|
||||||
ambientColor: { red: 255, green: 255, blue: 255 },
|
ambientColor: { red: 255, green: 255, blue: 255 },
|
||||||
|
@ -403,8 +409,8 @@ var toolBar = (function () {
|
||||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
Entities.addEntity({
|
Entities.addEntity({
|
||||||
type: "Text",
|
type: "Text",
|
||||||
position: position,
|
position: grid.snapToSurface(grid.snapToGrid(position, false, DEFAULT_DIMENSIONS), DEFAULT_DIMENSIONS),
|
||||||
dimensions: { x: DEFAULT_TEXT_DIMENSION_X, y: DEFAULT_TEXT_DIMENSION_Y, z: DEFAULT_TEXT_DIMENSION_Z },
|
dimensions: DEFAULT_DIMENSIONS,
|
||||||
backgroundColor: { red: 0, green: 0, blue: 0 },
|
backgroundColor: { red: 0, green: 0, blue: 0 },
|
||||||
textColor: { red: 255, green: 255, blue: 255 },
|
textColor: { red: 255, green: 255, blue: 255 },
|
||||||
text: "some text",
|
text: "some text",
|
||||||
|
|
Loading…
Reference in a new issue