Wood Plugin for Slic3r? January 22, 2013 10:53PM |
Registered: 14 years ago Posts: 51 |
Re: Wood Plugin for Slic3r? January 23, 2013 02:51AM |
Registered: 14 years ago Posts: 3,742 |
Quote
Jeremie Francois
So I developed a Cura & Skeinforge plugin that inserts the appropriate M104 at each layer...
Re: Wood Plugin for Slic3r? January 23, 2013 07:31AM |
Registered: 14 years ago Posts: 51 |
Re: Wood Plugin for Slic3r? January 23, 2013 08:09AM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 23, 2013 08:26AM |
Registered: 14 years ago Posts: 3,742 |
Re: Wood Plugin for Slic3r? January 23, 2013 04:22PM |
Registered: 14 years ago Posts: 51 |
Re: Wood Plugin for Slic3r? January 23, 2013 09:54PM |
Registered: 12 years ago Posts: 81 |
Re: Wood Plugin for Slic3r? January 24, 2013 02:06AM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 24, 2013 02:26AM |
Registered: 14 years ago Posts: 3,742 |
#Name: Wood #Info: Vary the print temperature troughout the print to create wood rings with the LayWood printing material #Depend: GCode #Type: postprocess #Param: minTemp(float:180) Min print temperature (c) #Param: maxTemp(float:230) Max print temperature (c) #Param: grainSize(float:3.0) Average Grain Size (mm) import re import random import math __author__ = 'Jeremie Francois ([email protected])' __date__ = '$Date: 2012/10/26 $' __license__ = 'GNU Affero General Public License [www.gnu.org]' def getValue(line, key, default = None): if not key in line or (';' in line and line.find(key) > line.find(';')): return default subPart = line[line.find(key) + 1:] m = re.search('^[0-9]+\.?[0-9]*', subPart) if m == None: return default try: return float(m.group(0)) except: return default class Perlin: # Perlin noise: [mrl.nyu.edu] def __init__(self, tiledim=256): self.tiledim= tiledim self.perm = [None]*2*tiledim permutation = [] for value in xrange(tiledim): permutation.append(value) random.shuffle(permutation) for i in xrange(tiledim): self.perm = permutation self.perm[tiledim+i] = self.perm def fade(self, t): return t * t * t * (t * (t * 6 - 15) + 10) def lerp(self, t, a, b): return a + t * (b - a) def grad(self, hash, x, y, z): #CONVERT LO 4 BITS OF HASH CODE INTO 12 GRADIENT DIRECTIONS. h = hash & 15 if h < 8: u = x else: u = y if h < 4: v = y else: if h == 12 or h == 14: v = x else: v = z if h&1 == 0: first = u else: first = -u if h&2 == 0: second = v else: second = -v return first + second def noise(self, x,y,z): #FIND UNIT CUBE THAT CONTAINS POINT. X = int(x)&(self.tiledim-1) Y = int(y)&(self.tiledim-1) Z = int(z)&(self.tiledim-1) #FIND RELATIVE X,Y,Z OF POINT IN CUBE. x -= int(x) y -= int(y) z -= int(z) #COMPUTE FADE CURVES FOR EACH OF X,Y,Z. u = self.fade(x) v = self.fade(y) w = self.fade(z) #HASH COORDINATES OF THE 8 CUBE CORNERS A = self.perm[X ]+Y; AA = self.perm[A]+Z; AB = self.perm[A+1]+Z B = self.perm[X+1]+Y; BA = self.perm+Z; BB = self.perm[B+1]+Z #AND ADD BLENDED RESULTS FROM 8 CORNERS OF CUBE return self.lerp(w,self.lerp(v, self.lerp(u,self.grad(self.perm[AA ],x ,y ,z ), self.grad(self.perm[BA ],x-1,y ,z )), self.lerp(u,self.grad(self.perm[AB ],x ,y-1,z ), self.grad(self.perm[BB ],x-1,y-1,z ))), self.lerp(v, self.lerp(u,self.grad(self.perm[AA+1],x ,y ,z-1), self.grad(self.perm[BA+1],x-1,y ,z-1)), self.lerp(u,self.grad(self.perm[AB+1],x ,y-1,z-1), self.grad(self.perm[BB+1],x-1,y-1,z-1)))) def fractal(self, octaves, persistence, x,y,z, frequency=1): value = 0.0 amplitude = 1.0 totalAmplitude= 0.0 for octave in xrange(octaves): n= self.noise(x*frequency,y*frequency,z*frequency) value += amplitude * n totalAmplitude += amplitude amplitude *= persistence frequency *= 2 return value / totalAmplitude with open(filename, "r") as f: lines = f.readlines() #Find the total height of the object maxZ = 0 z = 0 for line in lines: if getValue(line, 'G', None) == 1: z = getValue(line, 'Z', z) if maxZ < z: maxZ = z "First pass generates the noise curve, we'll normalize it afterwards because the user expects to reach the min & max temperatures" perlin = Perlin() noises = [] banding = 5 octaves = 3 persistence = 0.5 z = 0 for line in lines: if getValue(line, 'G', None) == 1: newZ = getValue(line, 'Z', z) if newZ != z: z = newZ noise= banding * perlin.fractal(octaves, persistence, 0,0,z/(grainSize*2)); noise = (noise - math.floor(noise)) noises.append(noise) temps = [] maxNoises = max(noises) minNoises = min(noises) for n in noises: nn = ( n - minNoises ) / ( maxNoises - minNoises ) temps.append(minTemp + (maxTemp - minTemp) * nn) #Save the file with M104 temperature settings per layer z = 0 idx = 0 with open(filename, "w") as f: f.write(";Wood temperature graph:\n") for n in xrange(15, 0, -1): str = ";%3i | " % (minTemp + (maxTemp - minTemp) * n / 15) for t in temps: if (t - minTemp) / (maxTemp - minTemp) * 15 >= (n - 0.5): str += "#" else: str += " " f.write(str + "\n") for line in lines: if getValue(line, 'G', None) == 1: newZ = getValue(line, 'Z', z) if newZ != z: z = newZ f.write("M104 S%i\n" % (temps[idx])) idx += 1 f.write(line)
Re: Wood Plugin for Slic3r? January 24, 2013 02:42AM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 24, 2013 02:48AM |
Registered: 14 years ago Posts: 3,742 |
python -v filename=myfile.gcode wood.py
Re: Wood Plugin for Slic3r? January 24, 2013 02:49AM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 24, 2013 03:19AM |
Registered: 14 years ago Posts: 3,742 |
Re: Wood Plugin for Slic3r? January 24, 2013 04:34AM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 24, 2013 04:38AM |
Registered: 14 years ago Posts: 3,742 |
Re: Wood Plugin for Slic3r? January 24, 2013 11:23AM |
Registered: 14 years ago Posts: 3,742 |
Wood.py -h -g <grainSize> -i <input> -o <output> -n <minTemp> -x <maxTemp> where; -h Show the usage info -g Sets the grainSize (default 3mm) -i Sets the input gcode filename -o Sets the output gcode filename -n Sets the minimum temperature (default 190°C) -x Sets the maximum temperature (default 240°C)
Wood.py -i owl.gcode -o owlWood.gcode
Re: Wood Plugin for Slic3r? January 24, 2013 11:46AM |
Registered: 14 years ago Posts: 3,742 |
Quote
jf pion
may be only need to REPLACE: if newZ != z: z = newZ WITH: if newZ > z: z = newZ
Re: Wood Plugin for Slic3r? January 24, 2013 03:12PM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 24, 2013 03:41PM |
Registered: 14 years ago Posts: 3,742 |
Re: Wood Plugin for Slic3r? January 24, 2013 03:54PM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 24, 2013 04:08PM |
Registered: 14 years ago Posts: 3,742 |
Wood.py -i coupler_slic3rl.gcode -o coupler_slic3rWood.gcode -n 190 -x 240
Re: Wood Plugin for Slic3r? January 24, 2013 04:41PM |
Registered: 12 years ago Posts: 141 |
Re: Wood Plugin for Slic3r? January 24, 2013 08:34PM |
Registered: 14 years ago Posts: 51 |
Re: Wood Plugin for Slic3r? January 24, 2013 11:35PM |
Registered: 14 years ago Posts: 51 |
Matthews-MacBook-Pro-3:~ matthewlaberge$ /Volumes/BigDisk/Downloads/Wood.py -i Owl.gcode -o OwlWood.gcode /Volumes/BigDisk/Downloads/Wood.py: line 9: import: command not found /Volumes/BigDisk/Downloads/Wood.py: line 10: import: command not found /Volumes/BigDisk/Downloads/Wood.py: line 11: import: command not found /Volumes/BigDisk/Downloads/Wood.py: line 12: import: command not found /Volumes/BigDisk/Downloads/Wood.py: line 13: import: command not found /Volumes/BigDisk/Downloads/Wood.py: line 15: __author__: command not found /Volumes/BigDisk/Downloads/Wood.py: line 16: __date__: command not found /Volumes/BigDisk/Downloads/Wood.py: line 17: __license__: command not found /Volumes/BigDisk/Downloads/Wood.py: line 19: syntax error near unexpected token `(' /Volumes/BigDisk/Downloads/Wood.py: line 19: `def getValue(line, key, default = None):'
Re: Wood Plugin for Slic3r? January 25, 2013 12:25AM |
Registered: 14 years ago Posts: 51 |
#!/usr/bin/python
Matthews-MacBook-Pro-3:~ matthewlaberge$ /Volumes/BigDisk/Downloads/Wood.py -i /Volumes/BigDisk/Downloads/Owl.gcode -o /Volumes/BigDisk/Downloads/OwlWood.gcode -n 180 -x 220
;Wood temperature graph: ;240 | ;236 | ;233 | ;230 | ;226 | # ;223 | # ;220 | # ;216 | # ;213 | # ;210 | # ;206 | # ;203 | # ;200 | # ;196 | # ;193 | #
Re: Wood Plugin for Slic3r? January 25, 2013 03:19AM |
Registered: 14 years ago Posts: 3,742 |
Re: Wood Plugin for Slic3r? January 25, 2013 03:21AM |
Registered: 14 years ago Posts: 3,742 |
;Wood temperature graph: ;240 | # # ;236 | # # # # # # ## # # ;233 | # # ### # # # # # # # # ### # # # ;230 | # # ### # # # # # # # # # ### ## # # ## ;226 | # # ##### ## # # # ## # # # ### # ## # # ## ;223 | # # ##### ### # # # # ## # # # ### # # ## ### # ### ;220 | # # # ##### ### # # # # ## # # # ### # # ## ### ##### ;216 | # # # ###### ### # # # # ## # # ## ### # # ## ### ##### ;213 | # # # ###### ### ## # # # ## # # # ## ### ## ## ## ### ##### ;210 | # ### ###### ### ## # # # ## # # # # ## ### ## ## ### ### ###### ;206 | # ### ###### ### ## # # # ## ## # # # ## ### ## ## ### ### ###### ;203 | # ########## ### ## # # # ### ### # # ## ## ### ### ## ### ### ###### ;200 | # ########## ### ## # # # ####### # # ## ## ### ### ## ####### ###### ;196 | # ############## ## ### ## ########### ## ## ### # ### ## ############## ;193 | # ################# #### ## ########### ## ## ### ######### ##############
Re: Wood Plugin for Slic3r? January 25, 2013 03:54AM |
Registered: 14 years ago Posts: 3,742 |
Quote
labmat
Once I did this it took me a little more time to figure out that I had to specifiy the exact file path for the input and output gcode file, I had just assumed that that the script would know to find the input and output it in the same directory as the script. My terminal command looked like the following.
Matthews-MacBook-Pro-3:~ matthewlaberge$ Wood.py -i Owl.gcode -o OwlWood.gcode -n 180 -x 220
Re: Wood Plugin for Slic3r? January 27, 2013 10:17AM |
Registered: 14 years ago Posts: 51 |
Re: Wood Plugin for Slic3r? January 29, 2013 11:49AM |