Commit c22ce48c authored by Christian Winter's avatar Christian Winter

instances. rotation and scale working basically

parent c3220788
...@@ -26,7 +26,7 @@ class LineManipulator { ...@@ -26,7 +26,7 @@ class LineManipulator {
if (Preferences.usePivot) if (Preferences.usePivot)
rotationCenter = pivot; rotationCenter = pivot;
else else
rotationCenter = Utilities.calculateCenterOfMass(selAsPoints); rotationCenter = Utilities.calculateCenterOfMass(Selection.getAllPositions());
} }
for (let p of selAsPoints) for (let p of selAsPoints)
...@@ -121,7 +121,7 @@ class LineManipulator { ...@@ -121,7 +121,7 @@ class LineManipulator {
if (Preferences.usePivot) if (Preferences.usePivot)
center = pivot; center = pivot;
else else
center = Utilities.calculateCenterOfMass(Selection.getAllSelectedPoints()); center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
let selectionAsPoints = Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points); let selectionAsPoints = Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points);
for (let p of selectionAsPoints) for (let p of selectionAsPoints)
...@@ -129,7 +129,7 @@ class LineManipulator { ...@@ -129,7 +129,7 @@ class LineManipulator {
for (let instance of Selection.data.prefabInstances) { for (let instance of Selection.data.prefabInstances) {
instance.transform.position = this.scalePoint(instance.transform.position, center, scaleVector); instance.transform.position = this.scalePoint(instance.transform.position, center, scaleVector);
instance.transform.scale = instance.transform.scale.addVector(scaleVector); instance.transform.scale = instance.transform.scale.multiplyVector(scaleVector);
} }
Renderer.redraw(); Renderer.redraw();
......
...@@ -605,7 +605,7 @@ ...@@ -605,7 +605,7 @@
this.drawRealCircle(line.end.position, line.thickness * this.handleSizeFactor, 0, line.color, false, false, true); this.drawRealCircle(line.end.position, line.thickness * this.handleSizeFactor, 0, line.color, false, false, true);
} }
this.drawPrefabInstances(Settings.prefabSelectionColor); this.drawPrefabInstances(Selection.data.prefabInstances, Settings.prefabSelectionColor);
if (File.currentLayer.hideInRenderPreview) if (File.currentLayer.hideInRenderPreview)
this.currentContext.setLineDash([]); this.currentContext.setLineDash([]);
...@@ -677,34 +677,10 @@ ...@@ -677,34 +677,10 @@
} }
} }
for (let i = 0; i < layer.prefabDict.keyValuePairs.length; ++i) { let instancesToDraw = [];
let prefab = layer.prefabDict.keyValuePairs[i][0]; for (let i = 0; i < layer.prefabDict.keyValuePairs.length; ++i)
let instances = layer.prefabDict.keyValuePairs[i][1]; instancesToDraw = instancesToDraw.concat(layer.prefabDict.keyValuePairs[i][1]);
this.drawPrefabInstances(instancesToDraw, Settings.prefabColor);
// TODO multibatching? or dont delete batch after rendering to reuse?
// green outline
if (!Logic.isPreviewing()) {
for (let instance of instances) {
for (let line of prefab.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.transform.position),
line.end.position.addVector(instance.transform.position),
line.thickness + Settings.prefabOutlineSize,
Settings.prefabColor
);
}
}
for (let instance of instances) {
for (let line of prefab.lines)
this.drawLineFromTo(
line.start.position.addVector(instance.transform.position),
line.end.position.addVector(instance.transform.position),
line.thickness,
line.color
);
}
}
} }
static drawRenderHiddenLayer(layer) { static drawRenderHiddenLayer(layer) {
...@@ -803,7 +779,7 @@ ...@@ -803,7 +779,7 @@
} }
// prefab instances // prefab instances
this.drawPrefabInstances(Settings.prefabSelectionColor, delta); this.drawPrefabInstances(Selection.data.prefabInstances, Settings.prefabSelectionColor, delta);
} }
...@@ -814,7 +790,7 @@ ...@@ -814,7 +790,7 @@
if (Preferences.usePivot) if (Preferences.usePivot)
center = pivot; center = pivot;
else else
center = Utilities.calculateCenterOfMass(Selection.getAllSelectedPoints()); center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
// selected lines // selected lines
for (let line of Selection.data.lines) for (let line of Selection.data.lines)
...@@ -834,7 +810,7 @@ ...@@ -834,7 +810,7 @@
ending.line.color ending.line.color
); );
this.drawPrefabInstances(Settings.prefabSelectionColor, null, angleDegree, null, center); this.drawPrefabInstances(Selection.data.prefabInstances, Settings.prefabSelectionColor, null, angleDegree, null, center);
} }
static drawScaleLinesPreview() { static drawScaleLinesPreview() {
...@@ -844,7 +820,7 @@ ...@@ -844,7 +820,7 @@
if (Preferences.usePivot) if (Preferences.usePivot)
center = pivot; center = pivot;
else else
center = Utilities.calculateCenterOfMass(Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points)); center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
// selected lines // selected lines
for (let line of Selection.data.lines) for (let line of Selection.data.lines)
...@@ -864,7 +840,7 @@ ...@@ -864,7 +840,7 @@
ending.line.color ending.line.color
); );
this.drawPrefabInstances(Settings.prefabSelectionColor, null, null, scaleVector, center); this.drawPrefabInstances(Selection.data.prefabInstances, Settings.prefabSelectionColor, null, null, scaleVector, center);
} }
static drawCrosshair(dontSnap) { static drawCrosshair(dontSnap) {
...@@ -992,14 +968,17 @@ ...@@ -992,14 +968,17 @@
} }
static drawPrefabInstances(outlinecolor, deltaPos, deltaRot, deltaScale, center) { static drawPrefabInstances(instances, outlinecolor, deltaPos, deltaRot, deltaScale, center) {
let positionOnly = false; let positionOnly = false;
// draw prefab instances // draw prefab instances
for (let instance of Selection.data.prefabInstances) { for (let instance of instances) {
if (!Logic.isPreviewing()) if (!Logic.isPreviewing())
{ {
// transform from prefab to instance
let pos = instance.transform.position; let pos = instance.transform.position;
// normal transform operation
if (deltaPos) if (deltaPos)
pos = pos.addVector(deltaPos); pos = pos.addVector(deltaPos);
if (deltaRot) if (deltaRot)
...@@ -1013,9 +992,18 @@ ...@@ -1013,9 +992,18 @@
// light green outline // light green outline
if (!Logic.isPreviewing()) { if (!Logic.isPreviewing()) {
for (let line of instance.reference.lines) { for (let line of instance.reference.lines) {
let start = line.start.position.addVector(instance.transform.position); // transform from prefab to instance
let end = line.end.position.addVector(instance.transform.position); let start = line.start.position;
start = start.addVector(instance.transform.position);
start = start.scaleFrom(instance.transform.position, instance.transform.scale);
start = start.rotateAround(instance.transform.position, instance.transform.rotation);
let end = line.end.position;
end = end.addVector(instance.transform.position);
end = end.scaleFrom(instance.transform.position, instance.transform.scale);
end = end.rotateAround(instance.transform.position, instance.transform.rotation);
// normal transformations
if (deltaPos) { if (deltaPos) {
start = start.addVector(deltaPos); start = start.addVector(deltaPos);
end = end.addVector(deltaPos); end = end.addVector(deltaPos);
...@@ -1035,8 +1023,16 @@ ...@@ -1035,8 +1023,16 @@
for (let line of instance.reference.lines) for (let line of instance.reference.lines)
{ {
let start = line.start.position.addVector(instance.transform.position); let start = line.start.position;
let end = line.end.position.addVector(instance.transform.position); start = start.addVector(instance.transform.position);
start = start.scaleFrom(instance.transform.position, instance.transform.scale);
start = start.rotateAround(instance.transform.position, instance.transform.rotation);
let end = line.end.position;
end = end.addVector(instance.transform.position);
end = end.scaleFrom(instance.transform.position, instance.transform.scale);
end = end.rotateAround(instance.transform.position, instance.transform.rotation);
if (deltaPos) { if (deltaPos) {
start = start.addVector(deltaPos); start = start.addVector(deltaPos);
......
...@@ -158,6 +158,13 @@ ...@@ -158,6 +158,13 @@
//ActionHistory.writeHistory(); //ActionHistory.writeHistory();
File.cleanUp(); File.cleanUp();
} }
static getAllPositions() {
let prefabInstancesPositions = [];
for (let instance of this.data.prefabInstances)
prefabInstancesPositions.push(instance.transform);
return Utilities.linesToLineEndings(this.data.lines).concat(this.data.points).concat(prefabInstancesPositions);
}
} }
class SelectionData { class SelectionData {
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
if (Preferences.usePivot) if (Preferences.usePivot)
rotationCenter = pivot; rotationCenter = pivot;
else else
rotationCenter = Utilities.calculateCenterOfMass(Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points)); rotationCenter = Utilities.calculateCenterOfMass(Selection.getAllPositions());
let p1 = Logic.currentState.startPos.subtractVector(rotationCenter); let p1 = Logic.currentState.startPos.subtractVector(rotationCenter);
let p2 = Logic.currentState.currentPos.subtractVector(rotationCenter); let p2 = Logic.currentState.currentPos.subtractVector(rotationCenter);
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
if (Preferences.usePivot) if (Preferences.usePivot)
center = pivot; center = pivot;
else else
center = Utilities.calculateCenterOfMass(Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points)); center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
let p1 = Logic.currentState.startPos.subtractVector(center); let p1 = Logic.currentState.startPos.subtractVector(center);
let p2 = Logic.currentState.currentPos.subtractVector(center); let p2 = Logic.currentState.currentPos.subtractVector(center);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment