Fixed Create App

This commit is contained in:
ksuprynowicz 2023-02-12 15:29:47 +01:00
parent c3417b807c
commit 5809576577
13 changed files with 3124 additions and 3067 deletions

View file

@ -45,6 +45,7 @@
* {@link InteractiveWindow}: none, top left, top right, bottom right, or bottom left of the Interface window. * {@link InteractiveWindow}: none, top left, top right, bottom right, or bottom left of the Interface window.
* <em>Read-only.</em> * <em>Read-only.</em>
*/ */
class DesktopScriptingInterface : public QObject, public Dependency { class DesktopScriptingInterface : public QObject, public Dependency {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int width READ getWidth) // Physical width of screen(s) including task bars and system menus Q_PROPERTY(int width READ getWidth) // Physical width of screen(s) including task bars and system menus

View file

@ -129,6 +129,7 @@ public:
virtual void compileTest() = 0; virtual void compileTest() = 0;
virtual QString scriptValueDebugDetails(const ScriptValue &value) = 0; virtual QString scriptValueDebugDetails(const ScriptValue &value) = 0;
virtual QString scriptValueDebugListMembers(const ScriptValue &value) = 0; virtual QString scriptValueDebugListMembers(const ScriptValue &value) = 0;
virtual void logBacktrace(const QString &title) = 0;
public: public:
// helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways // helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways
bool IS_THREADSAFE_INVOCATION(const QString& method); bool IS_THREADSAFE_INVOCATION(const QString& method);

View file

@ -2508,3 +2508,7 @@ ScriptValue ScriptManager::evaluate(const QString& program, const QString& fileN
void ScriptManager::requestGarbageCollection() { void ScriptManager::requestGarbageCollection() {
_engine->requestCollectGarbage(); _engine->requestCollectGarbage();
} }
void ScriptManager::logBacktrace(const QString &title) {
_engine->logBacktrace(title);
}

View file

@ -564,6 +564,13 @@ public:
*/ */
Q_INVOKABLE void requestGarbageCollection(); Q_INVOKABLE void requestGarbageCollection();
/**jsdoc
* Prints out current backtrace to the log.
* @function Script.logBacktrace
* @param {string} title - Title added to the printed out backtrace.
*/
Q_INVOKABLE void logBacktrace(const QString &title);
/*@jsdoc /*@jsdoc
* @function Script.loadEntityScript * @function Script.loadEntityScript
* @param {Uuid} entityID - Entity ID. * @param {Uuid} entityID - Entity ID.

View file

@ -1714,6 +1714,14 @@ QString ScriptEngineV8::scriptValueDebugDetailsV8(const V8ScriptValue &v8Value)
} }
}*/ }*/
void ScriptEngineV8::logBacktrace(const QString &title) {
QStringList backtrace = currentContext()->backtrace();
qDebug(scriptengine) << title;
for (int n = 0; n < backtrace.length(); n++) {
qDebug(scriptengine) << backtrace[n];
}
}
QStringList ScriptEngineV8::getCurrentScriptURLs() const { QStringList ScriptEngineV8::getCurrentScriptURLs() const {
auto isolate = _v8Isolate; auto isolate = _v8Isolate;
v8::Locker locker(isolate); v8::Locker locker(isolate);

View file

@ -136,6 +136,7 @@ public: // ScriptEngine implementation
QString scriptValueDebugDetailsV8(const V8ScriptValue &value); QString scriptValueDebugDetailsV8(const V8ScriptValue &value);
virtual QString scriptValueDebugListMembers(const ScriptValue &value) override; virtual QString scriptValueDebugListMembers(const ScriptValue &value) override;
QString scriptValueDebugListMembersV8(const V8ScriptValue &v8Value); QString scriptValueDebugListMembersV8(const V8ScriptValue &v8Value);
virtual void logBacktrace(const QString &title) override;
// helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways // helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways
inline bool IS_THREADSAFE_INVOCATION(const QString& method) { return ScriptEngine::IS_THREADSAFE_INVOCATION(method); } inline bool IS_THREADSAFE_INVOCATION(const QString& method) { return ScriptEngine::IS_THREADSAFE_INVOCATION(method); }

View file

@ -49,6 +49,7 @@ void ScriptEngineV8::registerCustomType(int type,
} }
Q_DECLARE_METATYPE(ScriptValue); Q_DECLARE_METATYPE(ScriptValue);
Q_DECLARE_METATYPE(QVariantMap);
/*static V8ScriptValue ScriptValueToV8ScriptValue(ScriptEngineV8* engine, const ScriptValue& src) { /*static V8ScriptValue ScriptValueToV8ScriptValue(ScriptEngineV8* engine, const ScriptValue& src) {
return ScriptValueV8Wrapper::fullUnwrap(static_cast<ScriptEngineV8*>(engine), src); return ScriptValueV8Wrapper::fullUnwrap(static_cast<ScriptEngineV8*>(engine), src);

View file

@ -1144,10 +1144,20 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
for (ConnectionList::iterator iter = _connections.begin(); iter != _connections.end(); ++iter) { for (ConnectionList::iterator iter = _connections.begin(); iter != _connections.end(); ++iter) {
Connection& conn = *iter; Connection& conn = *iter;
{ {
//auto functionContext = callback->CreationContext(); /*if (!conn.callback.get()->IsFunction()) {
auto functionContext = _v8Context.Get(_engine->getIsolate()); auto stringV8 = conn.callback.get()->ToDetailString(context).ToLocalChecked();
_engine->pushContext(functionContext); QString error = *v8::String::Utf8Value(_engine->getIsolate(), stringV8);
qDebug() << error;
Q_ASSERT(false);
}
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(conn.callback.get());
auto functionContext = callback->CreationContext();
v8::Context::Scope functionContextScope(functionContext); v8::Context::Scope functionContextScope(functionContext);
_engine->pushContext(functionContext);*/
/*auto functionContext = _v8Context.Get(_engine->getIsolate());
_engine->pushContext(functionContext);
v8::Context::Scope functionContextScope(functionContext);*/
auto functionContext = context;
Q_ASSERT(!conn.callback.get().IsEmpty()); Q_ASSERT(!conn.callback.get().IsEmpty());
Q_ASSERT(!conn.callback.get()->IsUndefined()); Q_ASSERT(!conn.callback.get()->IsUndefined());
@ -1178,7 +1188,7 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
<< _engine->formatErrorMessageFromTryCatch(tryCatch) << _engine->formatErrorMessageFromTryCatch(tryCatch)
<< "\nThis provided: " << conn.thisValue.get()->IsObject(); << "\nThis provided: " << conn.thisValue.get()->IsObject();
} }
_engine->popContext(); //_engine->popContext();
} }
} }
}); });

View file

@ -91,6 +91,7 @@ ScriptValue ScriptValueV8Wrapper::call(const ScriptValue& thisObject, const Scri
//qDebug() << "V8 This: " << _engine->scriptValueDebugDetailsV8(v8This); //qDebug() << "V8 This: " << _engine->scriptValueDebugDetailsV8(v8This);
}else{ }else{
recv = _engine->getContext()->Global(); recv = _engine->getContext()->Global();
//recv = v8::Null(isolate);
//qDebug() << "global"; //qDebug() << "global";
} }
//qDebug() << "V8 Call: " << *v8::String::Utf8Value(isolate, v8This.get()->TypeOf(isolate)); //qDebug() << "V8 Call: " << *v8::String::Utf8Value(isolate, v8This.get()->TypeOf(isolate));

View file

@ -18,7 +18,9 @@
progressDialog, tooltip, MyAvatar, Quat, Controller, Clipboard, HMD, UndoStack, OverlaySystemWindow, progressDialog, tooltip, MyAvatar, Quat, Controller, Clipboard, HMD, UndoStack, OverlaySystemWindow,
keyUpEventFromUIWindow:true */ keyUpEventFromUIWindow:true */
//(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
//var CreateApp = function() { // BEGIN LOCAL_SCOPE
var createApp = {};
var EDIT_TOGGLE_BUTTON = "com.highfidelity.interface.system.editButton"; var EDIT_TOGGLE_BUTTON = "com.highfidelity.interface.system.editButton";
@ -84,6 +86,7 @@ var shouldUseEditTabletApp = function() {
var selectionDisplay = SelectionDisplay; var selectionDisplay = SelectionDisplay;
selectionDisplay.createApp = createApp;
var selectionManager = SelectionManager; var selectionManager = SelectionManager;
var PARTICLE_SYSTEM_URL = Script.resolvePath("assets/images/icon-particles.svg"); var PARTICLE_SYSTEM_URL = Script.resolvePath("assets/images/icon-particles.svg");
@ -121,11 +124,13 @@ var copiedRotation;
var cameraManager = new CameraManager(); var cameraManager = new CameraManager();
var grid = new Grid(); var grid = new Grid();
selectionDisplay.grid = grid;
var gridTool = new GridTool({ var gridTool = new GridTool({
horizontalGrid: grid, horizontalGrid: grid,
createToolsWindow: createToolsWindow, createToolsWindow: createToolsWindow,
shouldUseEditTabletApp: shouldUseEditTabletApp shouldUseEditTabletApp: shouldUseEditTabletApp
}); });
gridTool.selectionDisplay = selectionDisplay;
gridTool.setVisible(false); gridTool.setVisible(false);
var editTools = new EditTools({ var editTools = new EditTools({
@ -144,6 +149,7 @@ var EntityShapeVisualizer = Script.require('./modules/entityShapeVisualizer.js')
var entityShapeVisualizer = new EntityShapeVisualizer(["Zone"], entityShapeVisualizerSessionName); var entityShapeVisualizer = new EntityShapeVisualizer(["Zone"], entityShapeVisualizerSessionName);
var entityListTool = new EntityListTool(shouldUseEditTabletApp); var entityListTool = new EntityListTool(shouldUseEditTabletApp);
entityListTool.createApp = createApp;
selectionManager.addEventListener(function () { selectionManager.addEventListener(function () {
selectionDisplay.updateHandles(); selectionDisplay.updateHandles();
@ -667,7 +673,7 @@ var toolBar = (function () {
SelectionManager.addEntity(entityID, false, this); SelectionManager.addEntity(entityID, false, this);
SelectionManager.saveProperties(); SelectionManager.saveProperties();
pushCommandForSelections([{ createApp.pushCommandForSelections([{
entityID: entityID, entityID: entityID,
properties: properties properties: properties
}], [], true); }], [], true);
@ -1124,6 +1130,7 @@ var toolBar = (function () {
Messages.sendLocalMessage("edit-events", JSON.stringify({ Messages.sendLocalMessage("edit-events", JSON.stringify({
enabled: active enabled: active
})); }));
print("Setting isActive: " + active);
isActive = active; isActive = active;
activeButton.editProperties({isActive: isActive}); activeButton.editProperties({isActive: isActive});
undoHistory.setEnabled(isActive); undoHistory.setEnabled(isActive);
@ -1175,7 +1182,7 @@ var orientation;
var intersection; var intersection;
function rayPlaneIntersection(pickRay, point, normal) { // createApp.rayPlaneIntersection = function(pickRay, point, normal) { //
// //
// This version of the test returns the intersection of a line with a plane // This version of the test returns the intersection of a line with a plane
// //
@ -1187,7 +1194,7 @@ function rayPlaneIntersection(pickRay, point, normal) { //
return Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, t)); return Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, t));
} }
function rayPlaneIntersection2(pickRay, point, normal) { createApp.rayPlaneIntersection2 = function(pickRay, point, normal) {
// //
// This version of the test returns false if the ray is directed away from the plane // This version of the test returns false if the ray is directed away from the plane
// //
@ -1244,7 +1251,7 @@ function findClickedEntity(event) {
} }
selectionDisplay.moveSelection(Vec3.sum(entityResult.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface}))); selectionDisplay.moveSelection(Vec3.sum(entityResult.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface})));
selectionManager._update(false, this); selectionManager._update(false, this);
pushCommandForSelections(); createApp.pushCommandForSelections();
expectingRotateAsClickedSurface = false; expectingRotateAsClickedSurface = false;
audioFeedback.action(); audioFeedback.action();
} }
@ -1389,6 +1396,7 @@ function mouseMove(event) {
} }
function mouseReleaseEvent(event) { function mouseReleaseEvent(event) {
print("mouseReleaseEvent");
mouseDown = false; mouseDown = false;
if (lastMouseMoveEvent) { if (lastMouseMoveEvent) {
@ -1396,20 +1404,24 @@ function mouseReleaseEvent(event) {
lastMouseMoveEvent = null; lastMouseMoveEvent = null;
} }
if (propertyMenu.mouseReleaseEvent(event)) { if (propertyMenu.mouseReleaseEvent(event)) {
print("propertyMenu.mouseReleaseEvent(event)");
return true; return true;
} }
if (isActive && selectionManager.hasSelection()) { if (isActive && selectionManager.hasSelection()) {
tooltip.show(false); tooltip.show(false);
} }
if (mouseCapturedByTool) { if (mouseCapturedByTool) {
print("mouseCapturedByTool");
return; return;
} }
cameraManager.mouseReleaseEvent(event); cameraManager.mouseReleaseEvent(event);
if (!mouseHasMovedSincePress) { if (!mouseHasMovedSincePress) {
print("!mouseHasMovedSincePress: " + JSON.stringify(event));
mouseClickEvent(event); mouseClickEvent(event);
} else {
print("mouseHasMovedSincePress");
} }
} }
@ -1429,9 +1441,11 @@ function wasTabletOrEditHandleClicked(event) {
} }
function mouseClickEvent(event) { function mouseClickEvent(event) {
print("mouseClickEvent isActive: " + isActive);
var wantDebug = false; var wantDebug = false;
var result, properties, tabletClicked; var result, properties, tabletClicked;
if (isActive && event.isLeftButton) { if (isActive && event.isLeftButton) {
print("mouseClickEvent isActive && event.isLeftButton");
result = findClickedEntity(event); result = findClickedEntity(event);
var tabletOrEditHandleClicked = wasTabletOrEditHandleClicked(event); var tabletOrEditHandleClicked = wasTabletOrEditHandleClicked(event);
if (tabletOrEditHandleClicked) { if (tabletOrEditHandleClicked) {
@ -1485,7 +1499,7 @@ function mouseClickEvent(event) {
if (0 < x && sizeOK && selectionManager.editEnabled) { if (0 < x && sizeOK && selectionManager.editEnabled) {
selectedEntityID = foundEntity; selectedEntityID = foundEntity;
orientation = MyAvatar.orientation; orientation = MyAvatar.orientation;
intersection = rayPlaneIntersection(pickRay, P, Quat.getForward(orientation)); intersection = createApp.rayPlaneIntersection(pickRay, P, Quat.getForward(orientation));
if (!event.isShifted) { if (!event.isShifted) {
selectionManager.setSelections([foundEntity], this); selectionManager.setSelections([foundEntity], this);
@ -1904,7 +1918,7 @@ function deleteSelectedEntities() {
if (savedProperties.length > 0) { if (savedProperties.length > 0) {
SelectionManager.clearSelections(this); SelectionManager.clearSelections(this);
pushCommandForSelections([], savedProperties); createApp.pushCommandForSelections([], savedProperties);
entityListTool.deleteEntities(deletedIDs); entityListTool.deleteEntities(deletedIDs);
} }
} else { } else {
@ -2369,7 +2383,7 @@ function applyEntityProperties(data) {
// For currently selected entities, push a command to the UndoStack that uses the current entity properties for the // For currently selected entities, push a command to the UndoStack that uses the current entity properties for the
// redo command, and the saved properties for the undo command. Also, include create and delete entity data. // redo command, and the saved properties for the undo command. Also, include create and delete entity data.
function pushCommandForSelections(createdEntityData, deletedEntityData, doNotSaveEditProperties) { createApp.pushCommandForSelections = function (createdEntityData, deletedEntityData, doNotSaveEditProperties) {
doNotSaveEditProperties = false; doNotSaveEditProperties = false;
var undoData = { var undoData = {
editEntities: [], editEntities: [],
@ -2620,7 +2634,7 @@ var PropertiesTool = function (opts) {
if (data.onlyUpdateEntities) { if (data.onlyUpdateEntities) {
blockPropertyUpdates = true; blockPropertyUpdates = true;
} else { } else {
pushCommandForSelections(); createApp.pushCommandForSelections();
SelectionManager.saveProperties(); SelectionManager.saveProperties();
} }
selectionManager._update(false, this); selectionManager._update(false, this);
@ -2652,7 +2666,7 @@ var PropertiesTool = function (opts) {
position: newPosition position: newPosition
}); });
} }
pushCommandForSelections(); createApp.pushCommandForSelections();
selectionManager._update(false, this); selectionManager._update(false, this);
} }
} else if (data.action === "moveAllToGrid") { } else if (data.action === "moveAllToGrid") {
@ -2672,7 +2686,7 @@ var PropertiesTool = function (opts) {
position: newPosition position: newPosition
}); });
} }
pushCommandForSelections(); createApp.pushCommandForSelections();
selectionManager._update(false, this); selectionManager._update(false, this);
} }
} else if (data.action === "resetToNaturalDimensions") { } else if (data.action === "resetToNaturalDimensions") {
@ -2693,7 +2707,7 @@ var PropertiesTool = function (opts) {
}); });
} }
} }
pushCommandForSelections(); createApp.pushCommandForSelections();
selectionManager._update(false, this); selectionManager._update(false, this);
} }
} else if (data.action === "previewCamera") { } else if (data.action === "previewCamera") {
@ -2711,7 +2725,7 @@ var PropertiesTool = function (opts) {
dimensions: Vec3.multiply(multiplier, properties.dimensions) dimensions: Vec3.multiply(multiplier, properties.dimensions)
}); });
} }
pushCommandForSelections(); createApp.pushCommandForSelections();
selectionManager._update(false, this); selectionManager._update(false, this);
} }
} else if (data.action === "reloadClientScripts") { } else if (data.action === "reloadClientScripts") {
@ -2751,7 +2765,7 @@ var PropertiesTool = function (opts) {
position: copiedPosition position: copiedPosition
}); });
} }
pushCommandForSelections(); createApp.pushCommandForSelections();
selectionManager._update(false, this); selectionManager._update(false, this);
} else { } else {
audioFeedback.rejection(); audioFeedback.rejection();
@ -2764,7 +2778,7 @@ var PropertiesTool = function (opts) {
rotation: copiedRotation rotation: copiedRotation
}); });
} }
pushCommandForSelections(); createApp.pushCommandForSelections();
selectionManager._update(false, this); selectionManager._update(false, this);
} else { } else {
audioFeedback.rejection(); audioFeedback.rejection();
@ -2782,7 +2796,7 @@ var PropertiesTool = function (opts) {
rotation: Quat.IDENTITY rotation: Quat.IDENTITY
}); });
} }
pushCommandForSelections(); createApp.pushCommandForSelections();
selectionManager._update(false, this); selectionManager._update(false, this);
} else { } else {
audioFeedback.rejection(); audioFeedback.rejection();
@ -3181,7 +3195,8 @@ function zoneSortOrder(a, b) {
} }
//print("getParentState added"); //print("getParentState added");
function getParentState(id) { //function getParentState(id) {
createApp.getParentState = function(id) {
var state = "NONE"; var state = "NONE";
var properties = Entities.getEntityProperties(id, ["parentID"]); var properties = Entities.getEntityProperties(id, ["parentID"]);
var children = getDomainOnlyChildrenIDs(id); var children = getDomainOnlyChildrenIDs(id);
@ -3266,4 +3281,5 @@ function rotateAsNextClickedSurface() {
} }
} }
//}()); // END LOCAL_SCOPE }()); // END LOCAL_SCOPE
//}(); // END LOCAL_SCOPE

View file

@ -218,7 +218,7 @@ var EntityListTool = function(shouldUseEditTabletApp) {
url = properties.imageURL; url = properties.imageURL;
} }
//print("Global object before getParentState call: " + JSON.stringify(globalThis)); //print("Global object before getParentState call: " + JSON.stringify(globalThis));
var parentStatus = getParentState(ids[i]); var parentStatus = that.createApp.getParentState(ids[i]);
var parentState = ""; var parentState = "";
if (parentStatus === "PARENT") { if (parentStatus === "PARENT") {
parentState = "A"; parentState = "A";

View file

@ -83,12 +83,15 @@ SelectionManager = (function() {
// FUNCTION: HANDLE ENTITY SELECTION TOOL UPDATES // FUNCTION: HANDLE ENTITY SELECTION TOOL UPDATES
function handleEntitySelectionToolUpdates(channel, message, sender) { function handleEntitySelectionToolUpdates(channel, message, sender) {
//print("Channel: " + channel + " Sender: " + sender + " Message: " + JSON.stringify(message));
if (channel !== 'entityToolUpdates') { if (channel !== 'entityToolUpdates') {
return; return;
} }
print("handleEntitySelectionToolUpdates entityToolUpdates");
if (sender !== MyAvatar.sessionUUID) { if (sender !== MyAvatar.sessionUUID) {
return; return;
} }
print("handleEntitySelectionToolUpdates MyAvatar.sessionUUID");
var wantDebug = false; var wantDebug = false;
var messageParsed; var messageParsed;
@ -99,6 +102,7 @@ SelectionManager = (function() {
return; return;
} }
print("handleEntitySelectionToolUpdates JSON.parse(message): " + messageParsed.method);
if (messageParsed.method === "selectEntity") { if (messageParsed.method === "selectEntity") {
if (!that.editEnabled) { if (!that.editEnabled) {
return; return;
@ -125,7 +129,7 @@ SelectionManager = (function() {
} }
selectionDisplay.moveSelection(Vec3.sum(messageParsed.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface}))); selectionDisplay.moveSelection(Vec3.sum(messageParsed.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface})));
that._update(false, this); that._update(false, this);
pushCommandForSelections(); that.createApp.pushCommandForSelections();
expectingRotateAsClickedSurface = false; expectingRotateAsClickedSurface = false;
audioFeedback.action(); audioFeedback.action();
} }
@ -147,6 +151,7 @@ SelectionManager = (function() {
that.clearSelections(); that.clearSelections();
} }
} else if (messageParsed.method === "pointingAt") { } else if (messageParsed.method === "pointingAt") {
print("handleEntitySelectionToolUpdates pointingAt");
if (messageParsed.hand === Controller.Standard.RightHand) { if (messageParsed.hand === Controller.Standard.RightHand) {
that.pointingAtDesktopWindowRight = messageParsed.desktopWindow; that.pointingAtDesktopWindowRight = messageParsed.desktopWindow;
that.pointingAtTabletRight = messageParsed.tablet; that.pointingAtTabletRight = messageParsed.tablet;
@ -232,6 +237,8 @@ SelectionManager = (function() {
}; };
that.setSelections = function(entityIDs, caller) { that.setSelections = function(entityIDs, caller) {
print("setSelections: " + JSON.stringify(entityIDs));
Script.logBacktrace("setSelections");
that.selections = []; that.selections = [];
for (var i = 0; i < entityIDs.length; i++) { for (var i = 0; i < entityIDs.length; i++) {
var entityID = entityIDs[i]; var entityID = entityIDs[i];
@ -723,7 +730,7 @@ SelectionManager = (function() {
var newPosition = Vec3.sum(relativePosition, targetPosition); var newPosition = Vec3.sum(relativePosition, targetPosition);
Entities.editEntity(id, { "position": newPosition }); Entities.editEntity(id, { "position": newPosition });
} }
pushCommandForSelections(); that.createApp.pushCommandForSelections();
that._update(false, this); that._update(false, this);
} else { } else {
audioFeedback.rejection(); audioFeedback.rejection();
@ -2002,7 +2009,7 @@ SelectionDisplay = (function() {
var handleBoundingBoxColor = COLOR_BOUNDING_EDGE; var handleBoundingBoxColor = COLOR_BOUNDING_EDGE;
if (SelectionManager.selections.length === 1) { if (SelectionManager.selections.length === 1) {
var parentState = getParentState(SelectionManager.selections[0]); var parentState = that.createApp.getParentState(SelectionManager.selections[0]);
if (parentState === "CHILDREN") { if (parentState === "CHILDREN") {
handleBoundingBoxColor = COLOR_BOUNDING_EDGE_CHILDREN; handleBoundingBoxColor = COLOR_BOUNDING_EDGE_CHILDREN;
} else if (parentState === "PARENT") { } else if (parentState === "PARENT") {
@ -2504,7 +2511,7 @@ SelectionDisplay = (function() {
} }
updateSelectionsRotation(axisRotation, SelectionManager.worldPosition); updateSelectionsRotation(axisRotation, SelectionManager.worldPosition);
SelectionManager._update(false, this); SelectionManager._update(false, this);
pushCommandForSelections(); that.createApp.pushCommandForSelections();
audioFeedback.action(); audioFeedback.action();
} }
}; };
@ -2585,7 +2592,7 @@ SelectionDisplay = (function() {
print(" starting elevation: " + startingElevation); print(" starting elevation: " + startingElevation);
} }
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal); initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) { if (debugPickPlaneEnabled) {
that.showDebugPickPlane(pickPlanePosition, pickPlaneNormal); that.showDebugPickPlane(pickPlanePosition, pickPlaneNormal);
@ -2598,7 +2605,7 @@ SelectionDisplay = (function() {
} }
}, },
onEnd: function(event, reason) { onEnd: function(event, reason) {
pushCommandForSelections(duplicatedEntityIDs); that.createApp.pushCommandForSelections(duplicatedEntityIDs);
if (isConstrained) { if (isConstrained) {
Entities.editEntity(xRailToolEntity, { Entities.editEntity(xRailToolEntity, {
visible: false, visible: false,
@ -2617,7 +2624,7 @@ SelectionDisplay = (function() {
var wantDebug = false; var wantDebug = false;
var pickRay = generalComputePickRay(event.x, event.y); var pickRay = generalComputePickRay(event.x, event.y);
var newPick = rayPlaneIntersection2(pickRay, pickPlanePosition, pickPlaneNormal); var newPick = that.createApp.rayPlaneIntersection2(pickRay, pickPlanePosition, pickPlaneNormal);
// If the pick ray doesn't hit the pick plane in this direction, do nothing. // If the pick ray doesn't hit the pick plane in this direction, do nothing.
// this will happen when someone drags across the horizon from the side they started on. // this will happen when someone drags across the horizon from the side they started on.
@ -2722,7 +2729,7 @@ SelectionDisplay = (function() {
var negateAndHalve = -0.5; var negateAndHalve = -0.5;
var cornerPosition = Vec3.sum(startPosition, Vec3.multiply(negateAndHalve, SelectionManager.worldDimensions)); var cornerPosition = Vec3.sum(startPosition, Vec3.multiply(negateAndHalve, SelectionManager.worldDimensions));
vector = Vec3.subtract( vector = Vec3.subtract(
grid.snapToGrid(Vec3.sum(cornerPosition, vector), constrainMajorOnly), that.grid.snapToGrid(Vec3.sum(cornerPosition, vector), constrainMajorOnly),
cornerPosition); cornerPosition);
// editing a parent will cause all the children to automatically follow along, so don't // editing a parent will cause all the children to automatically follow along, so don't
@ -2801,7 +2808,7 @@ SelectionDisplay = (function() {
axisVector = Vec3.multiplyQbyV(rotation, axisVector); axisVector = Vec3.multiplyQbyV(rotation, axisVector);
pickPlaneNormal = Vec3.cross(Vec3.cross(pickRay.direction, axisVector), axisVector); pickPlaneNormal = Vec3.cross(Vec3.cross(pickRay.direction, axisVector), axisVector);
pickPlanePosition = SelectionManager.worldPosition; pickPlanePosition = SelectionManager.worldPosition;
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal); initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
SelectionManager.saveProperties(); SelectionManager.saveProperties();
that.resetPreviousHandleColor(); that.resetPreviousHandleColor();
@ -2822,7 +2829,7 @@ SelectionDisplay = (function() {
} }
}, },
onEnd: function(event, reason) { onEnd: function(event, reason) {
pushCommandForSelections(duplicatedEntityIDs); that.createApp.pushCommandForSelections(duplicatedEntityIDs);
}, },
onMove: function(event) { onMove: function(event) {
var pickRay = generalComputePickRay(event.x, event.y); var pickRay = generalComputePickRay(event.x, event.y);
@ -2832,7 +2839,7 @@ SelectionDisplay = (function() {
pickRay = previousPickRay; pickRay = previousPickRay;
} }
var newPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal); var newPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) { if (debugPickPlaneEnabled) {
that.showDebugPickPlaneHit(newPick); that.showDebugPickPlaneHit(newPick);
} }
@ -2850,8 +2857,8 @@ SelectionDisplay = (function() {
var dotVector = Vec3.dot(vector, projectionVector); var dotVector = Vec3.dot(vector, projectionVector);
vector = Vec3.multiply(dotVector, projectionVector); vector = Vec3.multiply(dotVector, projectionVector);
var gridOrigin = grid.getOrigin(); var gridOrigin = that.grid.getOrigin();
vector = Vec3.subtract(grid.snapToGrid(Vec3.sum(vector, gridOrigin)), gridOrigin); vector = Vec3.subtract(that.grid.snapToGrid(Vec3.sum(vector, gridOrigin)), gridOrigin);
var wantDebug = false; var wantDebug = false;
if (wantDebug) { if (wantDebug) {
@ -2962,7 +2969,7 @@ SelectionDisplay = (function() {
pickPlaneNormal = Vec3.cross(Vec3.cross(pickRay.direction, axisVector), axisVector); pickPlaneNormal = Vec3.cross(Vec3.cross(pickRay.direction, axisVector), axisVector);
pickPlanePosition = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffsetWorld)); pickPlanePosition = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffsetWorld));
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal); initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
that.setHandleTranslateVisible(false); that.setHandleTranslateVisible(false);
that.setHandleRotateVisible(false); that.setHandleRotateVisible(false);
@ -3009,7 +3016,7 @@ SelectionDisplay = (function() {
} }
activeStretchCubePanelOffset = null; activeStretchCubePanelOffset = null;
pushCommandForSelections(); that.createApp.pushCommandForSelections();
}, },
onMove: function(event) { onMove: function(event) {
var pickRay = generalComputePickRay(event.x, event.y); var pickRay = generalComputePickRay(event.x, event.y);
@ -3019,7 +3026,7 @@ SelectionDisplay = (function() {
pickRay = previousPickRay; pickRay = previousPickRay;
} }
var newPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal); var newPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) { if (debugPickPlaneEnabled) {
that.showDebugPickPlaneHit(newPick); that.showDebugPickPlaneHit(newPick);
} }
@ -3029,7 +3036,7 @@ SelectionDisplay = (function() {
changeInDimensions = Vec3.multiply(dotVector, axisVector); changeInDimensions = Vec3.multiply(dotVector, axisVector);
changeInDimensions = Vec3.multiplyQbyV(Quat.inverse(rotation), changeInDimensions); changeInDimensions = Vec3.multiplyQbyV(Quat.inverse(rotation), changeInDimensions);
changeInDimensions = Vec3.multiplyVbyV(mask, changeInDimensions); changeInDimensions = Vec3.multiplyVbyV(mask, changeInDimensions);
changeInDimensions = grid.snapToSpacing(changeInDimensions); changeInDimensions = that.grid.snapToSpacing(changeInDimensions);
changeInDimensions = Vec3.multiply(NEGATE_VECTOR, Vec3.multiplyVbyV(signs, changeInDimensions)); changeInDimensions = Vec3.multiply(NEGATE_VECTOR, Vec3.multiplyVbyV(signs, changeInDimensions));
var newDimensions = Vec3.sum(initialDimensions, changeInDimensions); var newDimensions = Vec3.sum(initialDimensions, changeInDimensions);
@ -3088,7 +3095,7 @@ SelectionDisplay = (function() {
pickPlanePosition = initialPosition; pickPlanePosition = initialPosition;
pickPlaneNormal = Vec3.subtract(pickRay.origin, pickPlanePosition); pickPlaneNormal = Vec3.subtract(pickRay.origin, pickPlanePosition);
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal); initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
that.setHandleTranslateVisible(false); that.setHandleTranslateVisible(false);
that.setHandleRotateVisible(false); that.setHandleRotateVisible(false);
@ -3121,7 +3128,7 @@ SelectionDisplay = (function() {
that.replaceCollisionsAfterStretch = false; that.replaceCollisionsAfterStretch = false;
} }
pushCommandForSelections(); that.createApp.pushCommandForSelections();
}, },
onMove: function(event) { onMove: function(event) {
var pickRay = generalComputePickRay(event.x, event.y); var pickRay = generalComputePickRay(event.x, event.y);
@ -3131,7 +3138,7 @@ SelectionDisplay = (function() {
pickRay = previousPickRay; pickRay = previousPickRay;
} }
var newPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal); var newPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) { if (debugPickPlaneEnabled) {
that.showDebugPickPlaneHit(newPick); that.showDebugPickPlaneHit(newPick);
} }
@ -3140,7 +3147,7 @@ SelectionDisplay = (function() {
var dimensionsMultiple = toCameraDistance * SCALE_DIMENSIONS_CAMERA_DISTANCE_MULTIPLE; var dimensionsMultiple = toCameraDistance * SCALE_DIMENSIONS_CAMERA_DISTANCE_MULTIPLE;
var changeInDimensions = Vec3.subtract(newPick, initialPick); var changeInDimensions = Vec3.subtract(newPick, initialPick);
changeInDimensions = Vec3.multiplyQbyV(Quat.inverse(Camera.orientation), changeInDimensions); changeInDimensions = Vec3.multiplyQbyV(Quat.inverse(Camera.orientation), changeInDimensions);
changeInDimensions = grid.snapToSpacing(changeInDimensions); changeInDimensions = that.grid.snapToSpacing(changeInDimensions);
changeInDimensions = Vec3.multiply(changeInDimensions, dimensionsMultiple); changeInDimensions = Vec3.multiply(changeInDimensions, dimensionsMultiple);
var averageDimensionChange = (changeInDimensions.x + changeInDimensions.y + changeInDimensions.z) / 3; var averageDimensionChange = (changeInDimensions.x + changeInDimensions.y + changeInDimensions.z) / 3;
@ -3309,7 +3316,7 @@ SelectionDisplay = (function() {
// editOverlays may not have committed rotation changes. // editOverlays may not have committed rotation changes.
// Compute zero position based on where the toolEntity will be eventually. // Compute zero position based on where the toolEntity will be eventually.
var initialPick = rayPlaneIntersection(pickRay, rotationCenter, rotationNormal); var initialPick = that.createApp.rayPlaneIntersection(pickRay, rotationCenter, rotationNormal);
// In case of a parallel ray, this will be null, which will cause early-out // In case of a parallel ray, this will be null, which will cause early-out
// in the onMove helper. // in the onMove helper.
rotationZero = initialPick; rotationZero = initialPick;
@ -3343,7 +3350,7 @@ SelectionDisplay = (function() {
} }
}); });
Entities.editEntity(handleRotateCurrentRing, { visible: false, ignorePickIntersection: true }); Entities.editEntity(handleRotateCurrentRing, { visible: false, ignorePickIntersection: true });
pushCommandForSelections(); that.createApp.pushCommandForSelections();
if (wantDebug) { if (wantDebug) {
print("================== " + getMode() + "(addHandleRotateTool onEnd) <- ======================="); print("================== " + getMode() + "(addHandleRotateTool onEnd) <- =======================");
} }
@ -3364,7 +3371,7 @@ SelectionDisplay = (function() {
} }
var pickRay = generalComputePickRay(event.x, event.y); var pickRay = generalComputePickRay(event.x, event.y);
var result = rayPlaneIntersection(pickRay, rotationCenter, rotationNormal); var result = that.createApp.rayPlaneIntersection(pickRay, rotationCenter, rotationNormal);
if (result) { if (result) {
var centerToZero = Vec3.subtract(rotationZero, rotationCenter); var centerToZero = Vec3.subtract(rotationZero, rotationCenter);
var centerToIntersect = Vec3.subtract(result, rotationCenter); var centerToIntersect = Vec3.subtract(result, rotationCenter);

View file

@ -292,8 +292,8 @@ GridTool = function(opts) {
var dataString = JSON.stringify(data); var dataString = JSON.stringify(data);
webView.emitScriptEvent(dataString); webView.emitScriptEvent(dataString);
createToolsWindow.emitScriptEvent(dataString); createToolsWindow.emitScriptEvent(dataString);
if (selectionDisplay) { if (that.selectionDisplay) {
selectionDisplay.updateHandles(); that.selectionDisplay.updateHandles();
} }
}); });