crystalscad 0.2.7 → 0.3.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.
- data/README.md +70 -11
- data/crystalscad.gemspec +3 -1
- data/lib/crystalscad/BillOfMaterial.rb +6 -0
- data/lib/crystalscad/CrystalScad.rb +41 -1
- data/lib/crystalscad/Hardware.rb +2 -2
- data/lib/crystalscad/version.rb +1 -1
- data/skeleton_project/assemblies/example.rb +25 -0
- data/skeleton_project/observe.sh +2 -0
- data/skeleton_project/skeleton.rb +41 -0
- metadata +25 -41
data/README.md
CHANGED
@@ -1,28 +1,87 @@
|
|
1
1
|
CrystalScad
|
2
2
|
===========
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
Requires Ruby 1.9.3
|
7
|
-
Required gems: rubyscad
|
8
|
-
|
9
|
-
Currently not OpenSCAD feature complete
|
4
|
+
CrystalScad is a framework for programming 2d and 3d OpenScad models in Ruby.
|
10
5
|
|
11
6
|
Installation:
|
12
7
|
===========
|
13
|
-
|
8
|
+
Dependencies:
|
9
|
+
- Ruby 1.9.3
|
10
|
+
- inotifywait
|
11
|
+
- gem rubyscad
|
12
|
+
- gem requireall
|
13
|
+
|
14
|
+
Install via gem:
|
15
|
+
|
16
|
+
# gem install crystalscad
|
14
17
|
|
15
18
|
if you have multiple ruby versions, you likely need to use gem1.9.3 instead of gem
|
16
19
|
|
17
|
-
|
20
|
+
Install via git:
|
21
|
+
rake build
|
22
|
+
gem install pkg/crystalscad-<version>.gem
|
23
|
+
|
24
|
+
|
25
|
+
Coding
|
18
26
|
===========
|
19
|
-
|
20
|
-
|
27
|
+
Chain transformations:
|
28
|
+
res = cube([1,2,3]).rotate(x:90).translate(x:20,y:2,z:1).mirror(z:1)
|
29
|
+
|
30
|
+
CSG Modeling:
|
31
|
+
res = cylinder(d:10,h:10)
|
32
|
+
# union
|
33
|
+
res += cube(x:5,y:20,z:20)
|
34
|
+
# difference
|
35
|
+
res -= cylinder(d:5,h:10)
|
36
|
+
# intersection
|
37
|
+
res *= cylinder(d:10,h:10)
|
38
|
+
|
39
|
+
Hull:
|
40
|
+
res = hull(cylinder(d:10,h:10).cube([20,10,10].translate(x:10)))
|
41
|
+
|
42
|
+
Center cubes in X/Y direction only:
|
43
|
+
cube([10,10,10]).center_xy # note: does only work on cubes and must be put before any transformations
|
44
|
+
|
45
|
+
Also implemented: center_x, center_y, center_z
|
46
|
+
|
47
|
+
|
48
|
+
Long slots:
|
49
|
+
# produces a hull of two cylinders, 14mm apart
|
50
|
+
long_slot(d:4.4,h:10,l:14)
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
Framework Usage
|
57
|
+
===========
|
58
|
+
An example project skeleton is located in the skeleton_project directory. Try it out:
|
59
|
+
|
60
|
+
cd skeleton_project
|
61
|
+
./observe.sh
|
62
|
+
open skeleton.rb in an editor and skeleton.scad in OpenScad to play with it.
|
63
|
+
|
64
|
+
use ./skeleton.rb build to build all parts (specify all printed part in the Array parts in skeleton.rb)
|
65
|
+
|
66
|
+
To get started with your own project, rename skeleton_project/ and skeleton.rb to the name of your choice.
|
67
|
+
A few tips:
|
68
|
+
- Be visual. Put your desired situation on the screen, then model your object around it
|
69
|
+
- Make assemblies. An Assembly can be either a part that you need to print out or a set of parts that go together.
|
70
|
+
- When porting OpenScad code, beware of dividing integers. Example:
|
71
|
+
cylinder(r=11/2,h=10);
|
72
|
+
needs to be ported to
|
73
|
+
cylinder(r:11.0/2,h:10)
|
74
|
+
or
|
75
|
+
cylinder(d:11,h:10)
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
21
80
|
|
22
81
|
|
23
82
|
Real World Example:
|
24
83
|
===========
|
25
|
-
https://github.com/Joaz/bulldozer/blob/master/
|
84
|
+
https://github.com/Joaz/bulldozer/blob/master/
|
26
85
|
|
27
86
|
|
28
87
|
|
data/crystalscad.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.authors = ["Joachim Glauche"]
|
11
11
|
gem.email = ["webmaster@joaz.de"]
|
12
12
|
gem.homepage = "http://github.com/Joaz/CrystalScad"
|
13
|
-
gem.summary = %q{
|
13
|
+
gem.summary = %q{CrystalScad is a framework for programming OpenScad models in Ruby}
|
14
14
|
gem.description = %q{Inspired by SolidPython, based on RubyScad}
|
15
15
|
|
16
16
|
gem.license = 'GPL-3'
|
@@ -21,5 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.required_ruby_version = ">= 1.9.3"
|
23
23
|
gem.requirements << "rubyscad"
|
24
|
+
gem.requirements << "require_all"
|
25
|
+
|
24
26
|
end
|
25
27
|
|
@@ -29,6 +29,12 @@ module CrystalScad::BillOfMaterial
|
|
29
29
|
def output
|
30
30
|
@parts.map{|key, qty| "#{qty} x #{key}"}.join("\n")
|
31
31
|
end
|
32
|
+
|
33
|
+
def save(filename="bom.txt")
|
34
|
+
file = File.open(filename,"w")
|
35
|
+
file.puts output
|
36
|
+
file.close
|
37
|
+
end
|
32
38
|
end
|
33
39
|
|
34
40
|
@@bom = BillOfMaterial.new
|
@@ -48,6 +48,13 @@ module CrystalScad
|
|
48
48
|
def to_rubyscad
|
49
49
|
""
|
50
50
|
end
|
51
|
+
|
52
|
+
def save(filename,start_text=nil)
|
53
|
+
file = File.open(filename,"w")
|
54
|
+
file.puts start_text unless start_text == nil
|
55
|
+
file.puts scad_output
|
56
|
+
file.close
|
57
|
+
end
|
51
58
|
|
52
59
|
end
|
53
60
|
|
@@ -120,15 +127,41 @@ module CrystalScad
|
|
120
127
|
super(args)
|
121
128
|
@x,@y,@z = args[0][:size].map{|l| l.to_f}
|
122
129
|
end
|
130
|
+
|
131
|
+
def center_xy
|
132
|
+
@transformations << Translate.new({x:-@x/2,y:-@y/2})
|
133
|
+
self
|
134
|
+
end
|
135
|
+
|
136
|
+
def center_x
|
137
|
+
@transformations << Translate.new({x:-@x/2})
|
138
|
+
self
|
139
|
+
end
|
140
|
+
|
141
|
+
def center_y
|
142
|
+
@transformations << Translate.new({y:-@y/2})
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
def center_z
|
147
|
+
@transformations << Translate.new({z:-@z/2})
|
148
|
+
self
|
149
|
+
end
|
150
|
+
|
123
151
|
|
124
152
|
def to_rubyscad
|
125
153
|
return RubyScadBridge.new.cube(@args)
|
126
154
|
end
|
127
155
|
end
|
128
156
|
|
129
|
-
def cube(args)
|
157
|
+
def cube(args={})
|
130
158
|
if args.kind_of? Array
|
131
159
|
args = {size:args}
|
160
|
+
elsif args.kind_of? Hash
|
161
|
+
args[:x] ||= 0
|
162
|
+
args[:y] ||= 0
|
163
|
+
args[:z] ||= 0
|
164
|
+
args = {size:[args[:x],args[:y],args[:z]]}
|
132
165
|
end
|
133
166
|
Cube.new(args)
|
134
167
|
end
|
@@ -368,6 +401,13 @@ module CrystalScad
|
|
368
401
|
get_position_rec(obj.children)
|
369
402
|
end
|
370
403
|
|
404
|
+
# produces a hull() of 2 cylidners
|
405
|
+
# accepts d,r,h for cylinder options
|
406
|
+
# l long slot length
|
407
|
+
def long_slot(args)
|
408
|
+
hull(cylinder(d:args[:d],r:args[:r],h:args[:h]),cylinder(d:args[:d],r:args[:r],h:args[:h]).translate(x:args[:l]))
|
409
|
+
end
|
410
|
+
|
371
411
|
end
|
372
412
|
|
373
413
|
|
data/lib/crystalscad/Hardware.rb
CHANGED
@@ -23,7 +23,7 @@ module CrystalScad::Hardware
|
|
23
23
|
@args[:surface] ||= "zinc plated"
|
24
24
|
# options for output only:
|
25
25
|
@args[:additional_length] ||= 0
|
26
|
-
@args[:additional_diameter] ||= 0.
|
26
|
+
@args[:additional_diameter] ||= 0.3
|
27
27
|
|
28
28
|
@size = size
|
29
29
|
@length = length
|
@@ -171,7 +171,7 @@ module CrystalScad::Hardware
|
|
171
171
|
@height = chart_934[@size][:height]
|
172
172
|
end
|
173
173
|
|
174
|
-
def output(margin=0.
|
174
|
+
def output(margin=0.3)
|
175
175
|
return nut_934(margin)
|
176
176
|
end
|
177
177
|
|
data/lib/crystalscad/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Example < CrystalScad::Assembly
|
2
|
+
|
3
|
+
def initialize(args={})
|
4
|
+
super
|
5
|
+
end
|
6
|
+
|
7
|
+
def show
|
8
|
+
part(show=true)
|
9
|
+
end
|
10
|
+
|
11
|
+
def output
|
12
|
+
part(show=false)
|
13
|
+
end
|
14
|
+
|
15
|
+
def part(show)
|
16
|
+
bolt = Bolt.new(3,20)
|
17
|
+
|
18
|
+
res = cube([20,20,20]).center_xy
|
19
|
+
res -= bolt.output.translate(x:2,y:2)
|
20
|
+
res += bolt.show.translate(x:2,y:2) if show
|
21
|
+
|
22
|
+
res
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/ruby1.9.3
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "crystalscad"
|
5
|
+
require "require_all"
|
6
|
+
require_all "assemblies"
|
7
|
+
include CrystalScad
|
8
|
+
|
9
|
+
assembly = Example.new.show
|
10
|
+
subassembly = nil
|
11
|
+
|
12
|
+
def save(file,output,start_text=nil)
|
13
|
+
file = File.open(file,"w")
|
14
|
+
file.puts start_text unless start_text == nil
|
15
|
+
file.puts output
|
16
|
+
file.close
|
17
|
+
end
|
18
|
+
|
19
|
+
@@bom.save
|
20
|
+
|
21
|
+
assembly.save(File.expand_path(__FILE__).gsub(".rb","")+".scad","$fn=64;") if assembly
|
22
|
+
subassembly.save("part.scad","$fn=64;") if subassembly
|
23
|
+
|
24
|
+
Dir.mkdir("output") unless Dir.exists?("output")
|
25
|
+
parts = [Example]
|
26
|
+
|
27
|
+
parts.each do |part|
|
28
|
+
name = part.to_s.downcase
|
29
|
+
part.new.output.save("output/#{name}.scad","$fn=64;")
|
30
|
+
if ARGV[0] == "build"
|
31
|
+
puts "Building #{name}..."
|
32
|
+
system("openscad -o output/#{name}.stl output/#{name}.scad")
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
metadata
CHANGED
@@ -1,33 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystalscad
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 7
|
10
|
-
version: 0.2.7
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Joachim Glauche
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2013-09-19 00:00:00 Z
|
12
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Inspired by SolidPython, based on RubyScad
|
22
|
-
email:
|
15
|
+
email:
|
23
16
|
- webmaster@joaz.de
|
24
17
|
executables: []
|
25
|
-
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- COPYING
|
32
22
|
- Gemfile
|
33
23
|
- README.md
|
@@ -41,40 +31,34 @@ files:
|
|
41
31
|
- lib/crystalscad/Hardware.rb
|
42
32
|
- lib/crystalscad/LinearBearing.rb
|
43
33
|
- lib/crystalscad/version.rb
|
34
|
+
- skeleton_project/assemblies/example.rb
|
35
|
+
- skeleton_project/observe.sh
|
36
|
+
- skeleton_project/skeleton.rb
|
44
37
|
homepage: http://github.com/Joaz/CrystalScad
|
45
|
-
licenses:
|
38
|
+
licenses:
|
46
39
|
- GPL-3
|
47
40
|
post_install_message:
|
48
41
|
rdoc_options: []
|
49
|
-
|
50
|
-
require_paths:
|
42
|
+
require_paths:
|
51
43
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
45
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
hash: 53
|
58
|
-
segments:
|
59
|
-
- 1
|
60
|
-
- 9
|
61
|
-
- 3
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
62
49
|
version: 1.9.3
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
51
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
|
70
|
-
- 0
|
71
|
-
version: "0"
|
72
|
-
requirements:
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements:
|
73
57
|
- rubyscad
|
58
|
+
- require_all
|
74
59
|
rubyforge_project:
|
75
|
-
rubygems_version: 1.8.
|
60
|
+
rubygems_version: 1.8.23
|
76
61
|
signing_key:
|
77
62
|
specification_version: 3
|
78
|
-
summary:
|
63
|
+
summary: CrystalScad is a framework for programming OpenScad models in Ruby
|
79
64
|
test_files: []
|
80
|
-
|