Skip to content

Commit

Permalink
Improved filament visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
repetier committed Feb 5, 2013
1 parent ed72690 commit 7b874a7
Show file tree
Hide file tree
Showing 18 changed files with 1,133 additions and 460 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 0.84
Added japanese translation by Hajime Ashida.
Fixed error marking elements outside even if inside.
Improved filament visualization.

Version 0.83 22-01-2013
Slic3r 0.9.8 included
New translation: Latvian from www.ajmotion.lv
Expand Down
3 changes: 2 additions & 1 deletion src/RepetierHost/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/RepetierHost/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public Main()
translate();
toolAction.Text = Trans.T("L_IDLE");
toolConnection.Text = Trans.T("L_DISCONNECTED");
updateTravelMoves();
}
public void translate()
{
Expand Down Expand Up @@ -1175,6 +1176,7 @@ public void updateShowFilament()
}
public void updateTravelMoves()
{
if (threeDSettings == null) return;
if (threeDSettings.checkDisableTravelMoves.Checked)
{
toolShowTravel.Image = imageList.Images[5];
Expand Down
542 changes: 271 additions & 271 deletions src/RepetierHost/Main.resx

Large diffs are not rendered by default.

Binary file modified src/RepetierHost/RepetierHost.suo
Binary file not shown.
4 changes: 4 additions & 0 deletions src/RepetierHost/model/GCodeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public void Analyze(GCode code)
{
case 0:
case 1:
case 2: // Simplification to get at least some of part of the move
case 3:
eChanged = false;
if (code.hasF) f = code.F;
if (relative)
Expand Down Expand Up @@ -351,6 +353,8 @@ public void analyzeShort(GCodeShort code)
switch (code.compressedCommand)
{
case 1:
case 2:
case 3:
isG1Move = true;
eChanged = false;
if (code.hasF) f = code.f;
Expand Down
156 changes: 124 additions & 32 deletions src/RepetierHost/model/GCodeVisual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class GCodeTravel
}
public class GCodePath
{
public static bool correctNorms = true; // Draw correct normals
public int pointsCount = 0;
public int drawMethod = -1;
public float[] positions = null;
Expand Down Expand Up @@ -203,8 +204,8 @@ public void UpdateVBO(bool buffer)
int n = nv * (method == 0 ? 1 : 2) * (pointsCount - pointsLists.Count);
//if (method != 0) positions = new float[n * 3]; else positions = new float[3 * pointsCount];
//if (method != 0) normals = new float[n * 3]; else normals = null;
if (method != 0) positions = new float[pointsCount * nv * 3]; else positions = new float[3 * pointsCount];
if (method != 0) normals = new float[pointsCount * nv * 3]; else normals = null;
if (method != 0) positions = new float[pointsCount * nv * 3 * (correctNorms ? 2 : 1)]; else positions = new float[3 * pointsCount];
if (method != 0) normals = new float[pointsCount * nv * 3 * (correctNorms ? 2 : 1)]; else normals = null;
if (method != 0) elements = new int[(pointsCount - pointsLists.Count) * nv * 4 + pointsLists.Count * (nv - 2) * 4]; else elements = new int[n * 2];
int pos = 0;
int npos = 0;
Expand All @@ -215,9 +216,15 @@ public void UpdateVBO(bool buffer)
float[] dir = new float[3];
float[] dirs = new float[3];
float[] diru = new float[3];
float[] actdirs = new float[3];
float[] actdiru = new float[3];
float[] norm = new float[3];
float[] lastdir = new float[3];
float[] actdir = new float[3];
diru[0] = diru[1] = 0;
diru[2] = 1;
actdiru[0] = actdiru[1] = 0;
actdiru[2] = 1;
float laste = 0;
float dh = 0.5f * h;
float dw = 0.5f * w;
Expand Down Expand Up @@ -289,62 +296,143 @@ public void UpdateVBO(bool buffer)
GCodeVisual.normalize(ref dir);
double vacos = dir[0] * lastdir[0] + dir[1] * lastdir[1] + dir[2] * lastdir[2];
if (vacos > 1) vacos = 1;
if (vacos < 0.1)
vacos = 0.1;
if (vacos < 0.7)
vacos = 0.7;
float zoomw = (float)vacos; // Math.Cos(Math.Acos(vacos));
lastdir[0] = actdir[0];
lastdir[1] = actdir[1];
lastdir[2] = actdir[2];
dirs[0] = -dir[1];
dirs[1] = dir[0];
dirs[2] = dir[2];
diru[0] = diru[1] = 0;
diru[2] = 1;
actdirs[0] = -actdir[1];
actdirs[1] = actdir[0];
actdirs[2] = actdir[2];
alpha = 0;
float c, s;
int b = vpos / 3 - nv;
int b = vpos / 3 - nv*(correctNorms ? 2 : 1);
for (i = 0; i < nv; i++)
{
c = (float)Math.Cos(alpha) * dh;
s = (float)Math.Sin(alpha) * dw / zoomw;
norm[0] = (float)(s * dirs[0] + c * diru[0]);
norm[1] = (float)(s * dirs[1] + c * diru[1]);
norm[2] = (float)(s * dirs[2] + c * diru[2]);
if (correctNorms)
{
float s2 = (float)Math.Sin(alpha) * dw;
norm[0] = (float)(s2 * actdirs[0] + c * actdiru[0]);
norm[1] = (float)(s2 * actdirs[1] + c * actdiru[1]);
norm[2] = (float)(s2 * actdirs[2] + c * actdiru[2]);
}
else
{
norm[0] = (float)(s * dirs[0] + c * diru[0]);
norm[1] = (float)(s * dirs[1] + c * diru[1]);
norm[2] = (float)(s * dirs[2] + c * diru[2]);
}
GCodeVisual.normalize(ref norm);
if (!first)
{
elements[pos++] = b + (i + 1) % nv;//2
elements[pos++] = b + i;//1
elements[pos++] = b + i + nv;//4
elements[pos++] = b + (i + 1) % nv + nv;//3
if (correctNorms)
{
elements[pos++] = b + 2*((i + 1) % nv)+1;
elements[pos++] = b + 2*i+1;
elements[pos++] = b + 2*(i + nv);
elements[pos++] = b + 2*((i + 1) % nv + nv);
}
else
{
elements[pos++] = b + (i + 1) % nv;
elements[pos++] = b + i;
elements[pos++] = b + i + nv;
elements[pos++] = b + (i + 1) % nv + nv;
}
}
if (correctNorms)
{
if (first || ptNode == null)
{
if (first)
{
normals[npos++] = -actdir[0];
normals[npos++] = -actdir[1];
normals[npos++] = -actdir[2];
}
else
{
normals[npos++] = norm[0];
normals[npos++] = norm[1];
normals[npos++] = norm[2];
}
positions[vpos++] = v.X + s * dirs[0] + c * diru[0];
positions[vpos++] = v.Y + s * dirs[1] + c * diru[1];
positions[vpos++] = v.Z - dh + s * dirs[2] + c * diru[2];
}
else
{
normals[npos] = normals[npos - 6 * nv+3];
normals[npos + 1] = normals[npos - 6 * nv +4];
normals[npos + 2] = normals[npos - 6 * nv +5];
npos += 3;
positions[vpos++] = v.X + s * dirs[0] + c * diru[0];
positions[vpos++] = v.Y + s * dirs[1] + c * diru[1];
positions[vpos++] = v.Z - dh + s * dirs[2] + c * diru[2];
}
}
if (correctNorms && ptNode == null)
{
normals[npos++] = actdir[0];
normals[npos++] = actdir[1];
normals[npos++] = actdir[2];
}
else
{
normals[npos++] = norm[0];
normals[npos++] = norm[1];
normals[npos++] = norm[2];
}
normals[npos++] = norm[0];
normals[npos++] = norm[1];
normals[npos++] = norm[2];
positions[vpos++] = v.X + s * dirs[0] + c * diru[0];
positions[vpos++] = v.Y + s * dirs[1] + c * diru[1];
positions[vpos++] = v.Z - dh + s * dirs[2] + c * diru[2];
alpha += dalpha;
}
if (first || ptNode == null) // Draw cap
{
b = vpos / 3 - nv;
b = vpos / 3 - nv * (correctNorms ? 2 : 1);
int nn = (nv - 2) / 2;
for (i = 0; i < nn; i++)
{
if (first)
if (correctNorms)
{
elements[pos++] = b + i;
elements[pos++] = b + i + 1;
elements[pos++] = b + nv - i - 2;
elements[pos++] = b + nv - i - 1;
if (first)
{
elements[pos++] = b + 2*i;
elements[pos++] = b + 2*i + 2;
elements[pos++] = b + 2*nv - 2*i - 4;
elements[pos++] = b + 2*nv - 2*i - 2;
}
else
{
elements[pos++] = b + 2*(nv -i -1)+1;
elements[pos++] = b + 2*(nv - i -2)+1;
elements[pos++] = b + 2*i + 3;
elements[pos++] = b + 2*i+1;
}
}
else
{
elements[pos++] = b + nv - i - 1;
elements[pos++] = b + nv - i - 2;
elements[pos++] = b + i + 1;
elements[pos++] = b + i;
if (first)
{
elements[pos++] = b + i;
elements[pos++] = b + i + 1;
elements[pos++] = b + nv - i - 2;
elements[pos++] = b + nv - i - 1;
}
else
{
elements[pos++] = b + nv - i - 1;
elements[pos++] = b + nv - i - 2;
elements[pos++] = b + i + 1;
elements[pos++] = b + i;
}
}
}
}
Expand Down Expand Up @@ -423,6 +511,7 @@ public class GCodeVisual : ThreeDModel
public float lastFilWidth = 999;
public float lastFilDiameter = 999;
public bool lastFilUseHeight = true;
public bool lastCorrectNormals = true;
public float laste = -999;
public float hotFilamentLength = 1000;
public float minHotDist = 0;
Expand Down Expand Up @@ -834,10 +923,11 @@ public void drawSegment(GCodePath path)
if (liveView && path.lastDist > minHotDist)
{
GL.EnableClientState(ArrayCap.ColorArray);
cp = new float[path.positions.Length];
cp = new float[path.positions.Length*(GCodePath.correctNorms ? 2 : 1)];
int nv = 8 * (method - 1);
if (method == 1) nv = 4;
if (method == 0) nv = 1;
if (GCodePath.correctNorms) nv *= 2;
int p = 0;
foreach (LinkedList<GCodePoint> points in path.pointsLists)
{
Expand Down Expand Up @@ -903,10 +993,11 @@ public void drawSegment(GCodePath path)
if (liveView && path.lastDist > minHotDist)
{
GL.EnableClientState(ArrayCap.ColorArray);
cp = new float[path.positions.Length];
cp = new float[path.positions.Length * (GCodePath.correctNorms ? 2 : 1)];
int nv = 8 * (method - 1);
if (method == 1) nv = 4;
if (method == 0) nv = 1;
if (GCodePath.correctNorms) nv *= 2;
int p = 0;
foreach (LinkedList<GCodePoint> points in path.pointsLists)
{
Expand Down Expand Up @@ -987,6 +1078,8 @@ public void drawSegment(GCodePath path)
float dh = 0.5f * h;
float dw = 0.5f * w;
if (path.pointsCount < 2) return;
diru[0] = diru[1] = 0;
diru[2] = 1;
GL.Begin(BeginMode.Quads);
bool first = true;
Vector3 last = new Vector3();
Expand Down Expand Up @@ -1022,8 +1115,6 @@ public void drawSegment(GCodePath path)
dirs[0] = -dir[1];
dirs[1] = dir[0];
dirs[2] = dir[2];
diru[0] = diru[1] = 0;
diru[2] = 1;
alpha = 0;
float c = (float)Math.Cos(alpha) * dh;
float s = (float)Math.Sin(alpha) * dw;
Expand Down Expand Up @@ -1368,11 +1459,12 @@ public override void Paint()
w = h * wfac;
fixedH = Main.threeDSettings.useLayerHeight;
dfac = (float)(Math.PI * Main.threeDSettings.filamentDiameter * Main.threeDSettings.filamentDiameter * 0.25 / wfac);
recompute = lastFilHeight != h || lastFilWidth != w || fixedH != lastFilUseHeight || dfac != lastFilDiameter;
recompute = lastFilHeight != h || lastFilWidth != w || fixedH != lastFilUseHeight || dfac != lastFilDiameter || lastCorrectNormals!=GCodePath.correctNorms;
lastFilHeight = h;
lastFilWidth = w;
lastFilDiameter = dfac;
lastFilUseHeight = fixedH;
lastCorrectNormals = GCodePath.correctNorms;
for (int i = 0; i < MaxExtruder; i++)
{
if (i == 1) col = Main.threeDSettings.filament2.BackColor;
Expand Down
2 changes: 1 addition & 1 deletion src/RepetierHost/model/PrinterConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ public void doDispose()
string zextra = "";
GetInjectLock();
injectManualCommand("G1 X" + dx.ToString(GCode.format) + " Y" + dy.ToString(GCode.format) + " F" + travelFeedRate.ToString(GCode.format));
if (analyzer.hasZHome && analyzer.z + analyzer.zOffset < disposeZ && disposeZ > 0 && disposeZ < Main.printerSettings.PrintAreaHeight)
if (analyzer.hasZHome && analyzer.z + analyzer.zOffset < disposeZ && disposeZ > 0 && disposeZ <= Main.printerSettings.PrintAreaHeight)
{
float dz = disposeZ - analyzer.zOffset - (analyzer.relative ? analyzer.z : 0);
zextra = "G1 Z" + dz.ToString(GCode.format) + " F" + maxZFeedRate.ToString(GCode.format);
Expand Down
2 changes: 1 addition & 1 deletion src/RepetierHost/view/FormPrinterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void UpdateDimensions()
}
public bool PointInside(float x, float y, float z)
{
if (z < 0 || z > PrintAreaHeight) return false;
if (z < -0.001 || z > PrintAreaHeight) return false;
if (printerType < 2)
{
if (x < BedLeft || x > BedLeft + PrintAreaWidth) return false;
Expand Down
6 changes: 3 additions & 3 deletions src/RepetierHost/view/PrintPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/RepetierHost/view/Skeinforge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public string findPypy()
}
}

return null;
return findPythonw();
}
public string findPythonw()
{
Expand Down
Loading

0 comments on commit 7b874a7

Please sign in to comment.