mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 00:17:25 +02:00
Merge pull request #3840 from huffman/entity-snap-on-create
Entity snap on create (+ remove getEntityItemID)
This commit is contained in:
commit
168487e0a7
5 changed files with 43 additions and 35 deletions
|
@ -33,12 +33,11 @@ EntityListTool = function(opts) {
|
||||||
var ids = data.entityIds;
|
var ids = data.entityIds;
|
||||||
var entityIDs = [];
|
var entityIDs = [];
|
||||||
for (var i = 0; i < ids.length; i++) {
|
for (var i = 0; i < ids.length; i++) {
|
||||||
var entityID = Entities.getEntityItemID(ids[i]);
|
entityIDs.push({
|
||||||
if (entityID.isKnownID) {
|
id: ids[i],
|
||||||
entityIDs.push(entityID);
|
isKnownID: true,
|
||||||
} else {
|
creatorTokenID: 0,
|
||||||
print("Tried to select invalid entity: " + ids[i]);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
selectionManager.setSelections(entityIDs);
|
selectionManager.setSelections(entityIDs);
|
||||||
if (data.focus) {
|
if (data.focus) {
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -44,20 +44,6 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemID EntityScriptingInterface::getEntityItemID(const QString& uuid) {
|
|
||||||
EntityItemID entityID = EntityItemID(QUuid(uuid), UNKNOWN_ENTITY_TOKEN, false);
|
|
||||||
|
|
||||||
_entityTree->lockForRead();
|
|
||||||
EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(entityID));
|
|
||||||
_entityTree->unlock();
|
|
||||||
|
|
||||||
if (entity) {
|
|
||||||
return entity->getEntityItemID();
|
|
||||||
}
|
|
||||||
|
|
||||||
return entityID;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) {
|
EntityItemID EntityScriptingInterface::identifyEntity(EntityItemID entityID) {
|
||||||
EntityItemID actualID = entityID;
|
EntityItemID actualID = entityID;
|
||||||
|
|
||||||
|
|
|
@ -64,9 +64,6 @@ public slots:
|
||||||
/// adds a model with the specific properties
|
/// adds a model with the specific properties
|
||||||
Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties);
|
Q_INVOKABLE EntityItemID addEntity(const EntityItemProperties& properties);
|
||||||
|
|
||||||
// Get EntityItemID from uuid string
|
|
||||||
Q_INVOKABLE EntityItemID getEntityItemID(const QString& entityID);
|
|
||||||
|
|
||||||
/// identify a recently created model to determine its true ID
|
/// identify a recently created model to determine its true ID
|
||||||
Q_INVOKABLE EntityItemID identifyEntity(EntityItemID entityID);
|
Q_INVOKABLE EntityItemID identifyEntity(EntityItemID entityID);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue