Commit c22ce48c authored by Christian Winter's avatar Christian Winter

instances. rotation and scale working basically

parent c3220788
......@@ -26,7 +26,7 @@ class LineManipulator {
if (Preferences.usePivot)
rotationCenter = pivot;
else
rotationCenter = Utilities.calculateCenterOfMass(selAsPoints);
rotationCenter = Utilities.calculateCenterOfMass(Selection.getAllPositions());
}
for (let p of selAsPoints)
......@@ -121,7 +121,7 @@ class LineManipulator {
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(Selection.getAllSelectedPoints());
center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
let selectionAsPoints = Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points);
for (let p of selectionAsPoints)
......@@ -129,7 +129,7 @@ class LineManipulator {
for (let instance of Selection.data.prefabInstances) {
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();
......
......@@ -605,7 +605,7 @@
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)
this.currentContext.setLineDash([]);
......@@ -677,34 +677,10 @@
}
}
for (let i = 0; i < layer.prefabDict.keyValuePairs.length; ++i) {
let prefab = layer.prefabDict.keyValuePairs[i][0];
let instances = layer.prefabDict.keyValuePairs[i][1];
// 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
);
}
}
let instancesToDraw = [];
for (let i = 0; i < layer.prefabDict.keyValuePairs.length; ++i)
instancesToDraw = instancesToDraw.concat(layer.prefabDict.keyValuePairs[i][1]);
this.drawPrefabInstances(instancesToDraw, Settings.prefabColor);
}
static drawRenderHiddenLayer(layer) {
......@@ -803,7 +779,7 @@
}
// prefab instances
this.drawPrefabInstances(Settings.prefabSelectionColor, delta);
this.drawPrefabInstances(Selection.data.prefabInstances, Settings.prefabSelectionColor, delta);
}
......@@ -814,7 +790,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(Selection.getAllSelectedPoints());
center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
// selected lines
for (let line of Selection.data.lines)
......@@ -834,7 +810,7 @@
ending.line.color
);
this.drawPrefabInstances(Settings.prefabSelectionColor, null, angleDegree, null, center);
this.drawPrefabInstances(Selection.data.prefabInstances, Settings.prefabSelectionColor, null, angleDegree, null, center);
}
static drawScaleLinesPreview() {
......@@ -844,7 +820,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points));
center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
// selected lines
for (let line of Selection.data.lines)
......@@ -864,7 +840,7 @@
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) {
......@@ -992,14 +968,17 @@
}
static drawPrefabInstances(outlinecolor, deltaPos, deltaRot, deltaScale, center) {
static drawPrefabInstances(instances, outlinecolor, deltaPos, deltaRot, deltaScale, center) {
let positionOnly = false;
// draw prefab instances
for (let instance of Selection.data.prefabInstances) {
for (let instance of instances) {
if (!Logic.isPreviewing())
{
// transform from prefab to instance
let pos = instance.transform.position;
// normal transform operation
if (deltaPos)
pos = pos.addVector(deltaPos);
if (deltaRot)
......@@ -1013,9 +992,18 @@
// light green outline
if (!Logic.isPreviewing()) {
for (let line of instance.reference.lines) {
let start = line.start.position.addVector(instance.transform.position);
let end = line.end.position.addVector(instance.transform.position);
// transform from prefab to instance
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) {
start = start.addVector(deltaPos);
end = end.addVector(deltaPos);
......@@ -1035,8 +1023,16 @@
for (let line of instance.reference.lines)
{
let start = line.start.position.addVector(instance.transform.position);
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);
if (deltaPos) {
start = start.addVector(deltaPos);
......
......@@ -158,6 +158,13 @@
//ActionHistory.writeHistory();
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 {
......
......@@ -35,7 +35,7 @@
if (Preferences.usePivot)
rotationCenter = pivot;
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 p2 = Logic.currentState.currentPos.subtractVector(rotationCenter);
......
......@@ -39,7 +39,7 @@
if (Preferences.usePivot)
center = pivot;
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 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