solidruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +3 -0
  4. data/COPYING +674 -0
  5. data/Gemfile +2 -0
  6. data/Guardfile +24 -0
  7. data/LICENSE.md +675 -0
  8. data/README.md +180 -0
  9. data/Rakefile +10 -0
  10. data/bin/solidruby +61 -0
  11. data/examples/chamfered_cube.rb +39 -0
  12. data/examples/filleted_cube.rb +39 -0
  13. data/examples/gear.rb +11 -0
  14. data/examples/knurls.rb +12 -0
  15. data/examples/nut_support.rb +17 -0
  16. data/examples/openscad_examples/old/example001.rb +42 -0
  17. data/examples/openscad_examples/old/example002.rb +45 -0
  18. data/examples/openscad_examples/old/example003.rb +37 -0
  19. data/examples/openscad_examples/old/example004.rb +22 -0
  20. data/examples/openscad_examples/old/example005.rb +45 -0
  21. data/examples/openscad_examples/old/example006.rb +85 -0
  22. data/examples/openscad_examples/old/example007.dxf +2410 -0
  23. data/examples/openscad_examples/old/example007.rb +107 -0
  24. data/examples/openscad_examples/old/example008.rb +61 -0
  25. data/examples/openscad_examples/old/example009.dxf +3894 -0
  26. data/examples/openscad_examples/old/example009.rb.old +48 -0
  27. data/examples/openscad_examples/old/example010.dat +51 -0
  28. data/examples/openscad_examples/old/example010.rb +23 -0
  29. data/examples/openscad_examples/old/example011.rb +42 -0
  30. data/examples/openscad_examples/old/example012.rb +22 -0
  31. data/examples/openscad_examples/old/example012.stl +450 -0
  32. data/examples/openscad_examples/old/example013.dxf +2276 -0
  33. data/examples/openscad_examples/old/example013.rb +30 -0
  34. data/examples/openscad_examples/old/example014.rb +30 -0
  35. data/examples/openscad_examples/old/example015.rb +46 -0
  36. data/examples/openscad_examples/old/example016.rb +75 -0
  37. data/examples/openscad_examples/old/example016.stl +0 -0
  38. data/examples/pipe.rb +38 -0
  39. data/examples/pipe_bug.rb +16 -0
  40. data/examples/printed_gear.rb +12 -0
  41. data/examples/printed_gear2.rb +16 -0
  42. data/examples/printed_thread.rb +9 -0
  43. data/examples/printed_thread2.rb +13 -0
  44. data/examples/stack.rb +21 -0
  45. data/examples/threads.rb +183 -0
  46. data/examples/threads2.rb +93 -0
  47. data/examples/threads3.rb +46 -0
  48. data/lib/solidruby.rb +60 -0
  49. data/lib/solidruby/assemblies/assembly.rb +176 -0
  50. data/lib/solidruby/assemblies/bolt.rb +158 -0
  51. data/lib/solidruby/assemblies/gear.rb +131 -0
  52. data/lib/solidruby/assemblies/linear_bearing.rb +84 -0
  53. data/lib/solidruby/assemblies/nut.rb +153 -0
  54. data/lib/solidruby/assemblies/pipe.rb +153 -0
  55. data/lib/solidruby/assemblies/ruler.rb +44 -0
  56. data/lib/solidruby/assemblies/tslot.rb +141 -0
  57. data/lib/solidruby/assemblies/tslot_machining.rb +62 -0
  58. data/lib/solidruby/assemblies/washer.rb +57 -0
  59. data/lib/solidruby/bill_of_material.rb +43 -0
  60. data/lib/solidruby/csg_modelling/csg_modelling.rb +43 -0
  61. data/lib/solidruby/csg_modelling/difference.rb +41 -0
  62. data/lib/solidruby/csg_modelling/hull.rb +23 -0
  63. data/lib/solidruby/csg_modelling/intersection.rb +24 -0
  64. data/lib/solidruby/csg_modelling/minkowski.rb +23 -0
  65. data/lib/solidruby/csg_modelling/union.rb +41 -0
  66. data/lib/solidruby/csg_modifiers/color.rb +41 -0
  67. data/lib/solidruby/csg_modifiers/csg_modifier.rb +50 -0
  68. data/lib/solidruby/csg_modifiers/linear_extrude.rb +34 -0
  69. data/lib/solidruby/csg_modifiers/projection.rb +29 -0
  70. data/lib/solidruby/csg_modifiers/rotate_extrude.rb +30 -0
  71. data/lib/solidruby/extra.rb +58 -0
  72. data/lib/solidruby/helpers/chamfer.rb +27 -0
  73. data/lib/solidruby/helpers/fillet.rb +28 -0
  74. data/lib/solidruby/helpers/position.rb +267 -0
  75. data/lib/solidruby/helpers/rounded_cube.rb +37 -0
  76. data/lib/solidruby/helpers/triangle.rb +167 -0
  77. data/lib/solidruby/primitives/circle.rb +26 -0
  78. data/lib/solidruby/primitives/cube.rb +123 -0
  79. data/lib/solidruby/primitives/cylinder.rb +72 -0
  80. data/lib/solidruby/primitives/import.rb +42 -0
  81. data/lib/solidruby/primitives/polygon.rb +26 -0
  82. data/lib/solidruby/primitives/polyhedron.rb +30 -0
  83. data/lib/solidruby/primitives/primitive.rb +19 -0
  84. data/lib/solidruby/primitives/render.rb +48 -0
  85. data/lib/solidruby/primitives/sphere.rb +49 -0
  86. data/lib/solidruby/primitives/square.rb +88 -0
  87. data/lib/solidruby/primitives/surface.rb +44 -0
  88. data/lib/solidruby/primitives/text.rb +43 -0
  89. data/lib/solidruby/printed_thread.rb +163 -0
  90. data/lib/solidruby/rubyscad_bridge.rb +376 -0
  91. data/lib/solidruby/screw_thread.rb +170 -0
  92. data/lib/solidruby/solidruby.rb +150 -0
  93. data/lib/solidruby/solidruby_object.rb +176 -0
  94. data/lib/solidruby/transformations/mirror.rb +22 -0
  95. data/lib/solidruby/transformations/rotate.rb +22 -0
  96. data/lib/solidruby/transformations/scale.rb +22 -0
  97. data/lib/solidruby/transformations/transformation.rb +29 -0
  98. data/lib/solidruby/transformations/translate.rb +32 -0
  99. data/lib/solidruby/version.rb +18 -0
  100. data/lib/templates/assembly.tt +13 -0
  101. data/lib/templates/gitignore.tt +3 -0
  102. data/lib/templates/guardfile.tt +4 -0
  103. data/lib/templates/main.tt +20 -0
  104. data/lib/templates/params.tt +3 -0
  105. data/lib/templates/printed.tt +9 -0
  106. data/manual/manual.html +417 -0
  107. data/solidruby.gemspec +35 -0
  108. metadata +277 -0
data/README.md ADDED
@@ -0,0 +1,180 @@
1
+ SolidRuby
2
+ ===========
3
+
4
+ SolidRuby is a framework for programming 2d and 3d OpenSCAD models in Ruby.
5
+ It is a fork of [CrystalScad](https://github.com/Joaz/CrystalScad) with the aim to update and improve the codebase.
6
+
7
+ SolidRuby, like CrystalScad and RubyScad on which it is based, is released under the GPLv3 license.
8
+
9
+ [![Build Status](https://travis-ci.org/MC-Squared/SolidRuby.svg?branch=master)](https://travis-ci.org/MC-Squared/SolidRuby)
10
+
11
+ Installation:
12
+ ===========
13
+
14
+ Dependencies:
15
+
16
+ - Ruby 1.9.3+
17
+
18
+ Install via gem:
19
+ ```
20
+ # gem install solidruby
21
+ ```
22
+
23
+ if you have multiple ruby versions, you likely need to use gem1.9.3 instead of gem.
24
+
25
+ Install via git:
26
+
27
+ - clone repository
28
+ - \# rake install
29
+
30
+ Getting started
31
+ ===========
32
+ SolidRuby comes with a generator that generates project stubs automatically for you. Run this command from a terminal in the directory that you want to create a project:
33
+
34
+ ```
35
+ # solidruby new [my_project_name]
36
+ ```
37
+ Change [my_project_name] to the name of your project
38
+
39
+ A project named "my_project" will create those files and directories:
40
+
41
+ - my_project/my_project.rb - the controller
42
+ - my_project/lib/assemblies - for putting together assemblies of individual parts
43
+ - my_project/lib/electronics - put electronics here
44
+ - my_project/lib/hardware - put hardware parts in here
45
+ - my_project/lib/printed - put parts that you want to print in here
46
+ - my_project/lib/lasercut - put sheets that need to be cut (by laser or other) in here
47
+ - my_project/lib/params.rb - place for global parameters
48
+ - my_project/lib/assemblies/my_project_assembly.rb - dummy assembly
49
+ - my_project/Guardfile - guard
50
+
51
+ A Guardfile is created to automatically update the output scad files.
52
+
53
+ Coding
54
+ ===========
55
+ Nearly all OpenSCAD functions are implemented. You can use the same parameters as in OpenSCAD, although SolidRuby provides some convenient variable names like diameter (d) for cylinders.
56
+
57
+ Some examples:
58
+
59
+ CSG Modeling:
60
+ ```
61
+ res = cylinder(d:10, h:10)
62
+ # union
63
+ res += cube(x:5, y:20, z:20)
64
+ # difference
65
+ res -= cylinder(d:5, h:10)
66
+ # intersection
67
+ res *= cylinder(d:10, h:10)
68
+ ```
69
+
70
+ Chain transformations:
71
+ ```
72
+ res = cube(1, 2, 3).rotate(x: 90).translate(x: 20, y: 2, z: 1).mirror(z: 1)
73
+ ```
74
+
75
+
76
+ Hull:
77
+ ```
78
+ res = hull(cylinder(d:10, h:10).cube(20, 10, 10].translate(x: 10)))
79
+ ```
80
+
81
+ Center cubes in X/Y direction only:
82
+ ```
83
+ cube(10, 10, 10).center_xy # note: only works on cubes and must be put before any transformations
84
+ ```
85
+
86
+ Also implemented: center_x, center_y, center_z, center
87
+
88
+ Helpers:
89
+
90
+ Some helpers have been implemented to ease modelling.
91
+ Where helpers take face/edge/corner the options are:
92
+ ```
93
+ faces: :top, :bottom, :left, :right, :front, :back, :center
94
+ edges: :top, :bottom, :left, :right, :front, :back, :center
95
+ corners: :left, :right, :center
96
+ ```
97
+ For example:
98
+
99
+ Triangles - can be either linear_extruded or simply used for calulations
100
+ triangle(alpha: 90, c: 5, b: 3) #a right triangle on the origin, with Y leg 5 units, X leg 3 units
101
+ ```
102
+ triangle(alpha: 45, c: 6, b: 9).beta #get calulated angle from triangle
103
+ ```
104
+
105
+ Filleted cubes
106
+ Filled cubes can be created by using the .fillet helper:
107
+ ```
108
+ cube(10).fillet(edges: :vertical, r: 2)
109
+ cube(10).fillet(top: [:left, :right], front: :bottom, r: 2)
110
+ ```
111
+
112
+ Chamfered cubes
113
+ Similar to filleted cubes above
114
+ ```
115
+ cube(10).chamfer(edges: :vertical, h: 2)
116
+ ```
117
+
118
+ Both the fillet() and chamfer() helper can be used in isolation as well:
119
+ ```
120
+ fillet(h: 10, r: 2)
121
+ chamfer(l: 10, h: 2)
122
+ ```
123
+
124
+ Rounded cubes:
125
+ Due to how fillet is applied, the corners of a cube are not perfect when doing all sides.
126
+ In this case you can use rounded_cube:
127
+ ```
128
+ rounded_cube(x: 10, y: 10, z: 10, r: 2) #Actually a hull of 8 spheres
129
+ ```
130
+
131
+ Hollow cylinders:
132
+ Hollow cylinders can be created by indicating an :id argument (inner diameter)
133
+ ```
134
+ cylinder(d: 10, id: 8, h: 10) #creates a fully hollow cylinder
135
+ cylinder(d: 10, id: 8, h: 10, ih: 8) #inner cutout only partial height
136
+ ```
137
+
138
+ Placing onto:
139
+ For simple primitives you can use .place to place objects onto their faces:
140
+ ```
141
+ c = cube(10)
142
+ res = c + cube(5).place(onto: c, face: :top, edge: :top, corner: :center)
143
+
144
+ cy = cylinder(d: 10, h: 50)
145
+ res = cy + sphere(10).place(onto: cy, face: :top) #edge and corner default to center
146
+ ```
147
+
148
+ Long slots:
149
+ ```
150
+ # produces a hull of two cylinders, 14mm apart
151
+ long_slot(d:4.4, h:10, l:14)
152
+ ```
153
+
154
+ Printed threads:
155
+ There is a printed thread class for printing threads, i.e. for nuts and bolts:
156
+ ```
157
+ t1 = PrintedThread.new(diameter: 20, pitch: 2.5, length: 22.5, internal: true)
158
+ ```
159
+
160
+
161
+ A few tips:
162
+ - Be visual. By running `guard` you can watch your updates in OpenSCAD
163
+
164
+ - When porting OpenSCAD code, beware of dividing integers. Example:
165
+ ```
166
+ cylinder(r=11/2, h=10);
167
+ ```
168
+ needs to be ported to
169
+ ```
170
+ cylinder(r:11/2.0, h:10)
171
+ ```
172
+ or
173
+ ```
174
+ cylinder(d:11, h:10)
175
+ ```
176
+
177
+
178
+ License:
179
+ ===========
180
+ GPLv3
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/solidruby ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'thor/group'
5
+ require 'thor/actions'
6
+ require 'solidruby'
7
+
8
+ class SolidRubyGenerator < Thor
9
+ include Thor::Actions
10
+
11
+ def self.source_root
12
+ File.dirname(__FILE__) + '/../lib/templates'
13
+ end
14
+
15
+ desc 'printed NAME', 'generate printed part'
16
+ def printed(name)
17
+ @clean_name = name.split(/[-|_]/).map { |s| s.capitalize }.join
18
+ template('printed.tt', "lib/printed/#{name}.rb")
19
+ end
20
+ end
21
+
22
+ class SolidRubyCli < Thor
23
+ include Thor::Actions
24
+
25
+ def self.source_root
26
+ File.dirname(__FILE__) + '/../lib/templates'
27
+ end
28
+
29
+ desc 'version', 'shows the current version of SolidRuby'
30
+ def version
31
+ puts SolidRuby::VERSION
32
+ end
33
+
34
+ desc 'new APP_NAME', 'creates a new project stub'
35
+ def new(name)
36
+
37
+ @clean_name = name.split(/[-|_]/).map { |s| s.capitalize }.join
38
+ @name = name
39
+
40
+ empty_directory("#{name}/lib/assemblies/")
41
+ empty_directory("#{name}/lib/electronics/")
42
+ empty_directory("#{name}/lib/hardware/")
43
+ empty_directory("#{name}/lib/printed/")
44
+ empty_directory("#{name}/lib/lasercut/")
45
+ empty_directory("#{name}/output")
46
+ create_file("#{name}/output/.keep")
47
+
48
+ template('main.tt', "#{name}/#{name}.rb")
49
+ chmod("#{name}/#{name}.rb", 0755)
50
+
51
+ template('guardfile.tt', "#{name}/Guardfile")
52
+ template('gitignore.tt', "#{name}/.gitignore")
53
+ template('assembly.tt', "#{name}/lib/assemblies/#{name}_assembly.rb")
54
+ template('params.tt', "#{name}/lib/params.rb")
55
+ end
56
+
57
+ desc 'g COMMANDS', 'generator module'
58
+ subcommand 'g', SolidRubyGenerator
59
+ end
60
+
61
+ SolidRubyCli.start(ARGV)
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'solidruby'
4
+ include SolidRuby
5
+
6
+ def chamfered_cube
7
+ edges = [:top, :bottom, :left, :right]
8
+ faces = [:top, :bottom, :left, :right, :front, :back]
9
+
10
+ res = nil
11
+ x = 0
12
+ y = 0
13
+
14
+ faces.each do |f|
15
+ edges.each do |e|
16
+ res += cube(x: 5, y: 5, z: 10).chamfer({f => e, h: 1})
17
+ .translate(x: x, y: y)
18
+
19
+ y += 10
20
+ end
21
+
22
+ x += 10
23
+ y = 0
24
+ end
25
+
26
+ res += cube(x: 5, y: 5, z: 10)
27
+ .chamfer(edges: :vertical, h: 1)
28
+ .translate(x: -10)
29
+
30
+ res += cube(x: 5, y: 5, z: 10)
31
+ .chamfer(edges: :horizontal, h: 1)
32
+ .translate(x: -10, y: 10)
33
+
34
+ res += cube(x: 5, y: 5, z: 10)
35
+ .chamfer(edges: :all, h: 1)
36
+ .translate(x: -10, y: 20)
37
+ end
38
+
39
+ chamfered_cube.save('chamfered_cube.scad')
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'solidruby'
4
+ include SolidRuby
5
+
6
+ def filleted_cube
7
+ edges = [:top, :bottom, :left, :right]
8
+ faces = [:top, :bottom, :left, :right, :front, :back]
9
+
10
+ res = nil
11
+ x = 0
12
+ y = 0
13
+
14
+ faces.each do |f|
15
+ edges.each do |e|
16
+ res += cube(x: 5, y: 5, z: 10).fillet({f => e, :r => 1})
17
+ .translate(x: x, y: y)
18
+
19
+ y += 10
20
+ end
21
+
22
+ x += 10
23
+ y = 0
24
+ end
25
+
26
+ res += cube(x: 5, y: 5, z: 10)
27
+ .fillet(edges: :vertical, r: 1)
28
+ .translate(x: -10)
29
+
30
+ res += cube(x: 5, y: 5, z: 10)
31
+ .fillet(edges: :horizontal, r: 1)
32
+ .translate(x: -10, y: 10)
33
+
34
+ res += cube(x: 5, y: 5, z: 10)
35
+ .fillet(edges: :all, r: 1)
36
+ .translate(x: -10, y: 20)
37
+ end
38
+
39
+ filleted_cube.save('filleted_cube.scad')
data/examples/gear.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'solidruby'
4
+ include SolidRuby
5
+
6
+ g1 = Gear.new(module: 0.5, teeth: 80, bore: 5, height: 4)
7
+ #g2 = Gear.new(module: 0.5, teeth: 14, bore: 5, height: 8)
8
+
9
+ g1.save('gear.scad')
10
+ # puts g1.distance_to(g2)
11
+ # puts g1.show.scad_output
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require 'solidruby'
3
+ include SolidRuby
4
+
5
+ res = knurled_cube([41, 10, 4])
6
+ # Total rendering time: 0 hours, 5 minutes, 53 seconds
7
+
8
+ # Total rendering time: 0 hours, 1 minutes, 41 seconds
9
+
10
+ # res = knurled_cylinder(d:16,h:10)
11
+
12
+ res.save('knurls.scad', '$fn=64;')
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'solidruby'
4
+ include SolidRuby
5
+
6
+ res = cube([160, 20, 20]).center_y.translate(x: -5)
7
+ [2.5, 3, 4, 5, 6, 8, 10, 12].each do |size|
8
+ b = Bolt.new(size, 40)
9
+ n = Nut.new(size)
10
+ res -= b.output
11
+ res -= n.output
12
+ res += n.add_support(0.2)
13
+
14
+ res.translate(x: -20)
15
+ end
16
+
17
+ res.save('nut_support.scad', '$fn=64;')
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'solidruby'
4
+ include SolidRuby
5
+
6
+ size = 50
7
+ hole = 25
8
+ h = size * 2.5
9
+
10
+ res = sphere(d: size)
11
+ res -= cylinder(d: hole, h: h, center: true)
12
+ res -= cylinder(d: hole, h: h, center: true).rotate(x: 90)
13
+ res -= cylinder(d: hole, h: h, center: true).rotate(y: 90)
14
+
15
+ res.save('example001.scad')
16
+
17
+ # module example001()
18
+ # {
19
+ # function r_from_dia(d) = d / 2;
20
+ #
21
+ # module rotcy(rot, r, h) {
22
+ # rotate(90, rot)
23
+ # cylinder(r = r, h = h, center = true);
24
+ # }
25
+ #
26
+ # difference() {
27
+ # sphere(r = r_from_dia(size));
28
+ # rotcy([0, 0, 0], cy_r, cy_h);
29
+ # rotcy([1, 0, 0], cy_r, cy_h);
30
+ # rotcy([0, 1, 0], cy_r, cy_h);
31
+ # }
32
+ #
33
+ # size = 50;
34
+ # hole = 25;
35
+ #
36
+ # cy_r = r_from_dia(hole);
37
+ # cy_h = r_from_dia(size * 2.5);
38
+ # }
39
+ #
40
+ # echo(version=version());
41
+ #
42
+ # example001();
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'solidruby'
4
+ include SolidRuby
5
+
6
+ # note that center:true doesn't work with cube
7
+ # however, there are convenience methods like
8
+ # center, center_x, center_y, center_xy, center_z available.
9
+ # As rule of thumb, avoid center if possible.
10
+
11
+ res1 = cube([30, 30, 30]).center
12
+ res1 += cube([15, 15, 50]).center.translate(z: -25)
13
+
14
+ res2 = cube([50, 10, 10]).center
15
+ res2 += cube([10, 50, 10]).center
16
+ res2 += cube([10, 10, 50]).center
17
+
18
+ res = res1 - res2
19
+ res *= cylinder(r1: 20, r2: 5, h: 50, center: true).translate(z: 5)
20
+
21
+ res.save('example002.scad')
22
+
23
+ # module example002()
24
+ # {
25
+ # intersection() {
26
+ # difference() {
27
+ # union() {
28
+ # cube([30, 30, 30], center = true);
29
+ # translate([0, 0, -25])
30
+ # cube([15, 15, 50], center = true);
31
+ # }
32
+ # union() {
33
+ # cube([50, 10, 10], center = true);
34
+ # cube([10, 50, 10], center = true);
35
+ # cube([10, 10, 50], center = true);
36
+ # }
37
+ # }
38
+ # translate([0, 0, 5])
39
+ # cylinder(h = 50, r1 = 20, r2 = 5, center = true);
40
+ # }
41
+ # }
42
+ #
43
+ # echo(version=version());
44
+ #
45
+ # example002();