crystalscad 0.5.3 → 0.5.5
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/bin/crystalgen +1 -0
- data/lib/crystalscad/CrystalScad.rb +22 -78
- data/lib/crystalscad/CrystalScadObject.rb +39 -0
- data/lib/crystalscad/Hardware.rb +1 -1
- data/lib/crystalscad/Pipe.rb +10 -5
- data/lib/crystalscad/Primitive.rb +45 -0
- data/lib/crystalscad/version.rb +1 -1
- data/lib/crystalscad.rb +3 -0
- metadata +6 -4
data/bin/crystalgen
CHANGED
@@ -45,6 +45,7 @@ res.save(\"#{name}.scad\",\"$fn=64;\")
|
|
45
45
|
empty_directory("#{name}/lib/hardware/")
|
46
46
|
empty_directory("#{name}/lib/printed/")
|
47
47
|
empty_directory("#{name}/lib/lasercut/")
|
48
|
+
empty_directory("#{name}/output")
|
48
49
|
|
49
50
|
|
50
51
|
create_file("#{name}/lib/assemblies/#{name}_assembly.rb") do
|
@@ -25,87 +25,9 @@ module CrystalScad
|
|
25
25
|
include CrystalScad::PrintedThreads
|
26
26
|
|
27
27
|
|
28
|
-
class CrystalScadObject
|
29
|
-
attr_accessor :args
|
30
|
-
attr_accessor :transformations
|
31
|
-
def initialize(*args)
|
32
|
-
@transformations = []
|
33
|
-
@args = args.flatten
|
34
|
-
if @args[0].kind_of? Hash
|
35
|
-
@args = @args[0]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def walk_tree
|
40
|
-
res = ""
|
41
|
-
|
42
|
-
@transformations.reverse.each{|trans|
|
43
|
-
res += trans.walk_tree
|
44
|
-
}
|
45
|
-
res += self.to_rubyscad.to_s+ "\n"
|
46
|
-
res
|
47
|
-
end
|
48
|
-
alias :scad_output :walk_tree
|
49
|
-
|
50
|
-
def to_rubyscad
|
51
|
-
""
|
52
|
-
end
|
53
|
-
|
54
|
-
def save(filename,start_text=nil)
|
55
|
-
file = File.open(filename,"w")
|
56
|
-
file.puts start_text unless start_text == nil
|
57
|
-
file.puts scad_output
|
58
|
-
file.close
|
59
|
-
end
|
60
|
-
|
61
|
-
def method_missing(meth, *args, &block)
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
28
|
|
66
|
-
class Primitive < CrystalScadObject
|
67
|
-
attr_accessor :children
|
68
29
|
|
69
|
-
def rotate(args)
|
70
|
-
# always make sure we have a z parameter; otherwise RubyScad will produce a 2-dimensional output
|
71
|
-
# which can result in openscad weirdness
|
72
|
-
if args[:z] == nil
|
73
|
-
args[:z] = 0
|
74
|
-
end
|
75
|
-
@transformations << Rotate.new(args)
|
76
|
-
self
|
77
|
-
end
|
78
30
|
|
79
|
-
def rotate_around(point,args)
|
80
|
-
x,y,z= point.x, point.y, point.z
|
81
|
-
self.translate(x:-x,y:-y,z:-z).rotate(args).translate(x:x,y:y,z:z)
|
82
|
-
end
|
83
|
-
|
84
|
-
def translate(args)
|
85
|
-
@transformations << Translate.new(args)
|
86
|
-
self
|
87
|
-
end
|
88
|
-
|
89
|
-
def union(args)
|
90
|
-
@transformations << Union.new(args)
|
91
|
-
self
|
92
|
-
end
|
93
|
-
|
94
|
-
def mirror(args)
|
95
|
-
@transformations << Mirror.new(args)
|
96
|
-
self
|
97
|
-
end
|
98
|
-
|
99
|
-
def scale(args)
|
100
|
-
if args.kind_of? Numeric or args.kind_of? Array
|
101
|
-
args = {v:args}
|
102
|
-
end
|
103
|
-
@transformations << Scale.new(args)
|
104
|
-
self
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
31
|
|
110
32
|
class Transformation < CrystalScadObject
|
111
33
|
end
|
@@ -597,6 +519,28 @@ module CrystalScad
|
|
597
519
|
a*180 / Math::PI
|
598
520
|
end
|
599
521
|
|
522
|
+
|
523
|
+
# Saves all files generated of a CrystalScad file
|
524
|
+
# Saves outputs of
|
525
|
+
# - show
|
526
|
+
# - output
|
527
|
+
# - view*
|
528
|
+
def save_all(class_name)
|
529
|
+
res = class_name.send :new
|
530
|
+
(res.methods.grep(/view/)+[:show,:output]).each do |i|
|
531
|
+
res.send :initialize # ensure default values are loaded at each interation
|
532
|
+
res.send i unless i == :show or i == :output # call the view method
|
533
|
+
unless i == :output
|
534
|
+
output = res.show
|
535
|
+
else
|
536
|
+
output = res.output
|
537
|
+
end
|
538
|
+
|
539
|
+
output.save("output/#{res.class}_#{i}.scad","fn=64;")
|
540
|
+
end
|
541
|
+
|
542
|
+
end
|
543
|
+
|
600
544
|
end
|
601
545
|
|
602
546
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CrystalScad
|
2
|
+
class CrystalScadObject
|
3
|
+
attr_accessor :args
|
4
|
+
attr_accessor :transformations
|
5
|
+
def initialize(*args)
|
6
|
+
@transformations = []
|
7
|
+
@args = args.flatten
|
8
|
+
if @args[0].kind_of? Hash
|
9
|
+
@args = @args[0]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def walk_tree
|
14
|
+
res = ""
|
15
|
+
|
16
|
+
@transformations.reverse.each{|trans|
|
17
|
+
res += trans.walk_tree
|
18
|
+
}
|
19
|
+
res += self.to_rubyscad.to_s+ "\n"
|
20
|
+
res
|
21
|
+
end
|
22
|
+
alias :scad_output :walk_tree
|
23
|
+
|
24
|
+
def to_rubyscad
|
25
|
+
""
|
26
|
+
end
|
27
|
+
|
28
|
+
def save(filename,start_text=nil)
|
29
|
+
file = File.open(filename,"w")
|
30
|
+
file.puts start_text unless start_text == nil
|
31
|
+
file.puts scad_output
|
32
|
+
file.close
|
33
|
+
end
|
34
|
+
|
35
|
+
def method_missing(meth, *args, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/crystalscad/Hardware.rb
CHANGED
data/lib/crystalscad/Pipe.rb
CHANGED
@@ -49,7 +49,12 @@ module CrystalScad
|
|
49
49
|
def inner_shape
|
50
50
|
nil
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
|
+
# This will be called on bent, so this library can work with rectangle pipes, if you overwrite this and let it rotate z by 90
|
54
|
+
def apply_rotation(obj)
|
55
|
+
return obj
|
56
|
+
end
|
57
|
+
|
53
58
|
# go clockwise
|
54
59
|
def cw(radius,angle,color=nil)
|
55
60
|
if angle > 360
|
@@ -115,8 +120,8 @@ module CrystalScad
|
|
115
120
|
end
|
116
121
|
|
117
122
|
def bent_cw(radius,angle)
|
118
|
-
res = shape.translate(x:radius).rotate_extrude(fn:@bent_segments)
|
119
|
-
res -= inner_shape.translate(x:radius).rotate_extrude(fn:@bent_segments) unless inner_shape == nil
|
123
|
+
res = apply_rotation(shape).translate(x:radius).rotate_extrude(fn:@bent_segments)
|
124
|
+
res -= apply_rotation(inner_shape).translate(x:radius).rotate_extrude(fn:@bent_segments) unless inner_shape == nil
|
120
125
|
|
121
126
|
len = radius+@diameter/2.0
|
122
127
|
@x = Math::sin(radians(angle))*len
|
@@ -139,8 +144,8 @@ module CrystalScad
|
|
139
144
|
end
|
140
145
|
|
141
146
|
def bent_ccw(radius,angle)
|
142
|
-
res = shape.translate(x:radius).rotate_extrude(fn:@bent_segments)
|
143
|
-
res -= inner_shape.translate(x:radius).rotate_extrude(fn:@bent_segments) unless inner_shape == nil
|
147
|
+
res = apply_rotation(shape).translate(x:radius).rotate_extrude(fn:@bent_segments)
|
148
|
+
res -= apply_rotation(inner_shape).translate(x:radius).rotate_extrude(fn:@bent_segments) unless inner_shape == nil
|
144
149
|
|
145
150
|
len = radius+@diameter/2.0
|
146
151
|
@x = Math::sin(radians(angle))*len
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module CrystalScad
|
2
|
+
class Primitive < CrystalScadObject
|
3
|
+
attr_accessor :children
|
4
|
+
|
5
|
+
def rotate(args)
|
6
|
+
# always make sure we have a z parameter; otherwise RubyScad will produce a 2-dimensional output
|
7
|
+
# which can result in openscad weirdness
|
8
|
+
if args[:z] == nil
|
9
|
+
args[:z] = 0
|
10
|
+
end
|
11
|
+
@transformations << Rotate.new(args)
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def rotate_around(point,args)
|
16
|
+
x,y,z= point.x, point.y, point.z
|
17
|
+
self.translate(x:-x,y:-y,z:-z).rotate(args).translate(x:x,y:y,z:z)
|
18
|
+
end
|
19
|
+
|
20
|
+
def translate(args)
|
21
|
+
@transformations << Translate.new(args)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def union(args)
|
26
|
+
@transformations << Union.new(args)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def mirror(args)
|
31
|
+
@transformations << Mirror.new(args)
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def scale(args)
|
36
|
+
if args.kind_of? Numeric or args.kind_of? Array
|
37
|
+
args = {v:args}
|
38
|
+
end
|
39
|
+
@transformations << Scale.new(args)
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/lib/crystalscad/version.rb
CHANGED
data/lib/crystalscad.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'crystalscad/version'
|
2
2
|
require 'crystalscad/BillOfMaterial'
|
3
|
+
require 'crystalscad/CrystalScadObject'
|
3
4
|
require 'crystalscad/Assembly'
|
5
|
+
require 'crystalscad/Primitive'
|
4
6
|
require 'crystalscad/Hardware'
|
7
|
+
|
5
8
|
require 'crystalscad/LinearBearing'
|
6
9
|
require 'crystalscad/Gears'
|
7
10
|
require 'crystalscad/ScrewThreads'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystalscad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 5
|
10
|
+
version: 0.5.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joachim Glauche
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2015-04-
|
18
|
+
date: 2015-04-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rubyscad
|
@@ -113,10 +113,12 @@ files:
|
|
113
113
|
- lib/crystalscad/Assembly.rb
|
114
114
|
- lib/crystalscad/BillOfMaterial.rb
|
115
115
|
- lib/crystalscad/CrystalScad.rb
|
116
|
+
- lib/crystalscad/CrystalScadObject.rb
|
116
117
|
- lib/crystalscad/Gears.rb
|
117
118
|
- lib/crystalscad/Hardware.rb
|
118
119
|
- lib/crystalscad/LinearBearing.rb
|
119
120
|
- lib/crystalscad/Pipe.rb
|
121
|
+
- lib/crystalscad/Primitive.rb
|
120
122
|
- lib/crystalscad/PrintedThreads.rb
|
121
123
|
- lib/crystalscad/Ruler.rb
|
122
124
|
- lib/crystalscad/ScrewThreads.rb
|