mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 13:40:02 +02:00
Merge pull request #12701 from misslivirose/fix-edit-grid-color
Fix for grid color changes not applying
This commit is contained in:
commit
2f4bc5bd04
1 changed files with 44 additions and 38 deletions
|
@ -2,15 +2,7 @@ var GRID_CONTROLS_HTML_URL = Script.resolvePath('../html/gridControls.html');
|
||||||
|
|
||||||
Grid = function(opts) {
|
Grid = function(opts) {
|
||||||
var that = {};
|
var that = {};
|
||||||
|
var gridColor = { red: 0, green: 0, blue: 0 };
|
||||||
var colors = [
|
|
||||||
{ red: 0, green: 0, blue: 0 },
|
|
||||||
{ red: 255, green: 255, blue: 255 },
|
|
||||||
{ red: 255, green: 0, blue: 0 },
|
|
||||||
{ red: 0, green: 255, blue: 0 },
|
|
||||||
{ red: 0, green: 0, blue: 255 },
|
|
||||||
];
|
|
||||||
var colorIndex = 0;
|
|
||||||
var gridAlpha = 0.6;
|
var gridAlpha = 0.6;
|
||||||
var origin = { x: 0, y: +MyAvatar.getJointPosition('LeftToeBase').y.toFixed(1) + 0.1, z: 0 };
|
var origin = { x: 0, y: +MyAvatar.getJointPosition('LeftToeBase').y.toFixed(1) + 0.1, z: 0 };
|
||||||
var scale = 500;
|
var scale = 500;
|
||||||
|
@ -28,10 +20,10 @@ Grid = function(opts) {
|
||||||
position: origin,
|
position: origin,
|
||||||
visible: false,
|
visible: false,
|
||||||
drawInFront: false,
|
drawInFront: false,
|
||||||
color: colors[0],
|
color: gridColor,
|
||||||
alpha: gridAlpha,
|
alpha: gridAlpha,
|
||||||
minorGridEvery: minorGridEvery,
|
minorGridEvery: minorGridEvery,
|
||||||
majorGridEvery: majorGridEvery,
|
majorGridEvery: majorGridEvery
|
||||||
});
|
});
|
||||||
|
|
||||||
that.visible = false;
|
that.visible = false;
|
||||||
|
@ -39,26 +31,38 @@ Grid = function(opts) {
|
||||||
|
|
||||||
that.getOrigin = function() {
|
that.getOrigin = function() {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
that.getMinorIncrement = function() {
|
||||||
|
return minorGridEvery;
|
||||||
|
};
|
||||||
|
|
||||||
that.getMinorIncrement = function() { return minorGridEvery; };
|
|
||||||
that.setMinorIncrement = function(value) {
|
that.setMinorIncrement = function(value) {
|
||||||
minorGridEvery = value;
|
minorGridEvery = value;
|
||||||
updateGrid();
|
updateGrid();
|
||||||
}
|
};
|
||||||
that.getMajorIncrement = function() { return majorGridEvery; };
|
|
||||||
|
that.getMajorIncrement = function() {
|
||||||
|
return majorGridEvery;
|
||||||
|
};
|
||||||
|
|
||||||
that.setMajorIncrement = function(value) {
|
that.setMajorIncrement = function(value) {
|
||||||
majorGridEvery = value;
|
majorGridEvery = value;
|
||||||
updateGrid();
|
updateGrid();
|
||||||
};
|
};
|
||||||
|
|
||||||
that.getColorIndex = function() { return colorIndex; };
|
that.getColor = function() {
|
||||||
that.setColorIndex = function(value) {
|
return gridColor;
|
||||||
colorIndex = value;
|
};
|
||||||
|
|
||||||
|
that.setColor = function(value) {
|
||||||
|
gridColor = value;
|
||||||
updateGrid();
|
updateGrid();
|
||||||
};
|
};
|
||||||
|
|
||||||
that.getSnapToGrid = function() { return snapToGrid; };
|
that.getSnapToGrid = function() {
|
||||||
|
return snapToGrid;
|
||||||
|
};
|
||||||
that.setSnapToGrid = function(value) {
|
that.setSnapToGrid = function(value) {
|
||||||
snapToGrid = value;
|
snapToGrid = value;
|
||||||
that.emitUpdate();
|
that.emitUpdate();
|
||||||
|
@ -67,9 +71,11 @@ Grid = function(opts) {
|
||||||
that.setEnabled = function(enabled) {
|
that.setEnabled = function(enabled) {
|
||||||
that.enabled = enabled;
|
that.enabled = enabled;
|
||||||
updateGrid();
|
updateGrid();
|
||||||
}
|
};
|
||||||
|
|
||||||
that.getVisible = function() { return that.visible; };
|
that.getVisible = function() {
|
||||||
|
return that.visible;
|
||||||
|
};
|
||||||
that.setVisible = function(visible, noUpdate) {
|
that.setVisible = function(visible, noUpdate) {
|
||||||
that.visible = visible;
|
that.visible = visible;
|
||||||
updateGrid();
|
updateGrid();
|
||||||
|
@ -77,7 +83,7 @@ Grid = function(opts) {
|
||||||
if (!noUpdate) {
|
if (!noUpdate) {
|
||||||
that.emitUpdate();
|
that.emitUpdate();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
that.snapToSurface = function(position, dimensions, registration) {
|
that.snapToSurface = function(position, dimensions, registration) {
|
||||||
if (!snapToGrid) {
|
if (!snapToGrid) {
|
||||||
|
@ -97,7 +103,7 @@ Grid = function(opts) {
|
||||||
y: origin.y + (registration.y * dimensions.y),
|
y: origin.y + (registration.y * dimensions.y),
|
||||||
z: position.z
|
z: position.z
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
that.snapToGrid = function(position, majorOnly, dimensions, registration) {
|
that.snapToGrid = function(position, majorOnly, dimensions, registration) {
|
||||||
if (!snapToGrid) {
|
if (!snapToGrid) {
|
||||||
|
@ -121,7 +127,7 @@ Grid = function(opts) {
|
||||||
position.z = Math.round(position.z / spacing) * spacing;
|
position.z = Math.round(position.z / spacing) * spacing;
|
||||||
|
|
||||||
return Vec3.sum(Vec3.sum(position, Vec3.multiplyVbyV(registration, dimensions)), origin);
|
return Vec3.sum(Vec3.sum(position, Vec3.multiplyVbyV(registration, dimensions)), origin);
|
||||||
}
|
};
|
||||||
|
|
||||||
that.snapToSpacing = function(delta, majorOnly) {
|
that.snapToSpacing = function(delta, majorOnly) {
|
||||||
if (!snapToGrid) {
|
if (!snapToGrid) {
|
||||||
|
@ -133,11 +139,11 @@ Grid = function(opts) {
|
||||||
var snappedDelta = {
|
var snappedDelta = {
|
||||||
x: Math.round(delta.x / spacing) * spacing,
|
x: Math.round(delta.x / spacing) * spacing,
|
||||||
y: Math.round(delta.y / spacing) * spacing,
|
y: Math.round(delta.y / spacing) * spacing,
|
||||||
z: Math.round(delta.z / spacing) * spacing,
|
z: Math.round(delta.z / spacing) * spacing
|
||||||
};
|
};
|
||||||
|
|
||||||
return snappedDelta;
|
return snappedDelta;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
that.setPosition = function(newPosition, noUpdate) {
|
that.setPosition = function(newPosition, noUpdate) {
|
||||||
|
@ -157,7 +163,7 @@ Grid = function(opts) {
|
||||||
majorGridEvery: majorGridEvery,
|
majorGridEvery: majorGridEvery,
|
||||||
gridSize: halfSize,
|
gridSize: halfSize,
|
||||||
visible: that.visible,
|
visible: that.visible,
|
||||||
snapToGrid: snapToGrid,
|
snapToGrid: snapToGrid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -183,8 +189,8 @@ Grid = function(opts) {
|
||||||
majorGridEvery = data.majorGridEvery;
|
majorGridEvery = data.majorGridEvery;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.colorIndex !== undefined) {
|
if (data.gridColor) {
|
||||||
colorIndex = data.colorIndex;
|
gridColor = data.gridColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.gridSize) {
|
if (data.gridSize) {
|
||||||
|
@ -196,7 +202,7 @@ Grid = function(opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGrid(true);
|
updateGrid(true);
|
||||||
}
|
};
|
||||||
|
|
||||||
function updateGrid(noUpdate) {
|
function updateGrid(noUpdate) {
|
||||||
Overlays.editOverlay(gridOverlay, {
|
Overlays.editOverlay(gridOverlay, {
|
||||||
|
@ -204,8 +210,8 @@ Grid = function(opts) {
|
||||||
visible: that.visible && that.enabled,
|
visible: that.visible && that.enabled,
|
||||||
minorGridEvery: minorGridEvery,
|
minorGridEvery: minorGridEvery,
|
||||||
majorGridEvery: majorGridEvery,
|
majorGridEvery: majorGridEvery,
|
||||||
color: colors[colorIndex],
|
color: gridColor,
|
||||||
alpha: gridAlpha,
|
alpha: gridAlpha
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!noUpdate) {
|
if (!noUpdate) {
|
||||||
|
@ -219,7 +225,7 @@ Grid = function(opts) {
|
||||||
|
|
||||||
that.addListener = function(callback) {
|
that.addListener = function(callback) {
|
||||||
that.onUpdate = callback;
|
that.onUpdate = callback;
|
||||||
}
|
};
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
updateGrid();
|
updateGrid();
|
||||||
|
@ -238,7 +244,7 @@ GridTool = function(opts) {
|
||||||
|
|
||||||
var webView = null;
|
var webView = null;
|
||||||
webView = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
webView = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
webView.setVisible = function(value) {};
|
webView.setVisible = function(value) { };
|
||||||
|
|
||||||
horizontalGrid.addListener(function(data) {
|
horizontalGrid.addListener(function(data) {
|
||||||
webView.emitScriptEvent(JSON.stringify(data));
|
webView.emitScriptEvent(JSON.stringify(data));
|
||||||
|
@ -250,8 +256,8 @@ GridTool = function(opts) {
|
||||||
webView.webEventReceived.connect(function(data) {
|
webView.webEventReceived.connect(function(data) {
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
print("gridTool.js: Error parsing JSON: " + e.name + " data " + data)
|
print("gridTool.js: Error parsing JSON: " + e.name + " data " + data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,11 +286,11 @@ GridTool = function(opts) {
|
||||||
|
|
||||||
that.addListener = function(callback) {
|
that.addListener = function(callback) {
|
||||||
listeners.push(callback);
|
listeners.push(callback);
|
||||||
}
|
};
|
||||||
|
|
||||||
that.setVisible = function(visible) {
|
that.setVisible = function(visible) {
|
||||||
webView.setVisible(visible);
|
webView.setVisible(visible);
|
||||||
}
|
};
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue