oozby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f815ac48e5c34d5320cf8c68e405e50ae5628c1
4
+ data.tar.gz: bd65a310084b29367e72156a0115be35fcbec393
5
+ SHA512:
6
+ metadata.gz: 2e8e9c157aa4311fd3eed8e78696c6b3bd8c2a31925feadfc2c3614705610079aa7ca5a88086da4355a789673a2cc193807efa542d6ce4a95ddb34eae1fbda29
7
+ data.tar.gz: 9fe7a2662cb73940d13abd4c8ef311aa52a700eb2b148d4604ce453e769c06615a83d387adbaa355c26c7c13659335ea8201fb722b48445c9e668e37c6118950
data/bin/oozby ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.dirname(__FILE__) + "/../lib"
3
+ require 'fssm'
4
+ #require 'pp'
5
+ require 'oozby'
6
+
7
+ def recompile file
8
+ ooz = Oozby.new
9
+ ooz.parse_file file
10
+ #pp ooz.abstract_tree
11
+ File.open(file + '.scad', 'w') do |handle|
12
+ handle.write ooz.render
13
+ end
14
+
15
+ puts "Updated #{File.basename(file)}"
16
+ end
17
+
18
+ filename = File.absolute_path(ARGV.last)
19
+ recompile filename
20
+ FSSM.monitor(File.dirname(filename), File.basename(filename)) do
21
+ update { recompile filename }
22
+ create { recompile filename }
23
+ end
data/lib/oozby.rb ADDED
@@ -0,0 +1,6 @@
1
+ warn "Requires ruby 2.0 or newer" unless RUBY_VERSION.split('.').first.to_i >= 2
2
+ require_relative 'oozby/base'
3
+ require_relative 'oozby/environment'
4
+ require_relative 'oozby/method_preprocessor'
5
+ require_relative 'oozby/render'
6
+ require_relative 'oozby/element'
data/lib/oozby/base.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'pp'
2
+
3
+ # Oozby class loads up files and evaluates them to a syntax tree, and renders to openscad source code
4
+ class Oozby
5
+ def initialize
6
+ @code_tree = []
7
+ end
8
+
9
+ # parse oozby code in to a syntax tree
10
+ def parse code, filename: 'eval'
11
+ env = Oozby::Environment.new(ooz: self)
12
+
13
+ # rescue block to filter out junk oozby library stuff from backtraces
14
+ begin
15
+ compiled = eval("lambda {; #{code}; }", nil, filename)
16
+ env.instance_exec(&compiled)
17
+ rescue
18
+ warn "Recent Calls: " + env.instance_variable_get(:@method_history).last(10).reverse.inspect
19
+ backtrace = $!.backtrace
20
+ backtrace = backtrace.select { |item| !item.include? __dir__ }
21
+ raise $!, $!.message, backtrace
22
+ end
23
+ @code_tree = env._abstract_tree
24
+ end
25
+
26
+ # parse a file containing oozby code in to a syntax tree
27
+ def parse_file filename
28
+ parse File.read(filename), filename: filename
29
+ end
30
+
31
+ # render the last parsed oozby code in to openscad source code
32
+ def render
33
+ renderer = Oozby::Render.new(ooz: self)
34
+ renderer.render(@code_tree, clean: true).join("\n")
35
+ end
36
+
37
+ def abstract_tree
38
+ @code_tree
39
+ end
40
+ end
41
+
42
+
43
+
@@ -0,0 +1,57 @@
1
+ # Represent an oozby element
2
+ class Oozby::Element
3
+ attr_reader :data, :siblings
4
+
5
+ def initialize hash, parent_array
6
+ @data = hash
7
+ @siblings = parent_array
8
+ end
9
+
10
+ # include the next thing as a child of this thing
11
+ def > other
12
+ if other.respond_to? :to_oozby_element
13
+ other = [other]
14
+ elsif not other.is_a?(Array) or other.any? { |item| not item.respond_to? :to_oozby_element }
15
+ raise "Can only use > combiner to add Oozby::Element or array of Elements"
16
+ end
17
+
18
+ # convert all items to real Oozby Elements
19
+ other = other.map { |item| item.to_oozby_element }
20
+
21
+ # add others as children
22
+ children.push *(other.map { |item| item.data })
23
+
24
+ # remove children from their previous parents
25
+ other.each do |thing|
26
+ thing.siblings = children
27
+ end
28
+
29
+ other.first
30
+ end
31
+
32
+ def index
33
+ @siblings.index(@data)
34
+ end
35
+
36
+ def siblings= new_parent
37
+ @siblings.delete @data
38
+ @siblings = new_parent
39
+ end
40
+
41
+ [:children, :modifier, :method, :args, :named_args].each do |hash_accessor_name|
42
+ define_method(hash_accessor_name) { @data[hash_accessor_name] }
43
+ define_method("#{hash_accessor_name}=") { |val| @data[hash_accessor_name] = val }
44
+ end
45
+
46
+ def method_missing name, *args, &proc
47
+ if @data.respond_to? name
48
+ @data.send(name, *args, &proc)
49
+ else
50
+ super
51
+ end
52
+ end
53
+
54
+ def to_oozby_element
55
+ self
56
+ end
57
+ end
@@ -0,0 +1,187 @@
1
+ class Oozby::Environment
2
+ ResolutionDefaults = {
3
+ degrees_per_fragment: 12,
4
+ fragments_per_turn: 30,
5
+ minimum: 2,
6
+ fragments: 0
7
+ }
8
+
9
+ def initialize(ooz: nil)
10
+ @parent = ooz
11
+ @ast = []
12
+ @defaults = {center: false}
13
+ @resolution = ResolutionDefaults.dup
14
+ @modifier = nil
15
+ @one_time_modifier = nil
16
+ @preprocess = true
17
+ @method_history = []
18
+ @method_preprocessor = Oozby::MethodPreprocessor.new(env: self, ooz: @parent)
19
+ end
20
+
21
+ # create a new scope that inherits from this one, and capture syntax tree created
22
+ def _subscope &proc
23
+ # capture instance variables
24
+ capture = {}
25
+ instance_variables.each { |key| capture[key] = self.instance_variable_get(key) }
26
+
27
+ # reset for ast capture
28
+ @ast = []
29
+ @one_time_modifier = nil
30
+ @defaults = @defaults.dup
31
+ @resolution = @resolution.dup
32
+ self.instance_eval &proc
33
+ syntax_tree = @ast
34
+
35
+ # restore instance variables
36
+ capture.each { |key, value| self.instance_variable_set(key, value) }
37
+
38
+ return syntax_tree
39
+ end
40
+
41
+ def inject_abstract_tree code
42
+ code = [code] unless code.is_a? Array
43
+ @ast.push(*code)
44
+ end
45
+
46
+ def method_missing method_name, *args, **hash, &proc
47
+ if proc
48
+ children = _subscope(&proc)
49
+ else
50
+ children = []
51
+ end
52
+
53
+ call = {
54
+ method: method_name,
55
+ args: args, named_args: hash,
56
+ children: children,
57
+ modifier: @one_time_modifier || @modifier
58
+ }
59
+
60
+ @ast.push call
61
+ element = Oozby::Element.new(call, @ast)
62
+ @method_preprocessor.transform_call(element) if @preprocess
63
+ @one_time_modifier = nil
64
+ @method_history.push method_name # maintain list of recent methods to aid debugging
65
+ return element
66
+ end
67
+
68
+ #### Trigonometric Functions using degrees instead of radians
69
+ # add local definitions of trig functions
70
+ [:cos, :sin, :tan].each do |math_function|
71
+ define_method math_function do |deg|
72
+ Math.send(math_function, (deg.to_f / 180.0) * Math::PI)
73
+ end
74
+ end
75
+
76
+ # add inverse trig functions
77
+ [:acos, :asin, :atan, :atan2].each do |math_function|
78
+ define_method math_function do |*args|
79
+ (Math.send(math_function, *args) / Math::PI) * 180.0
80
+ end
81
+ end
82
+
83
+ def preprocessor state, &proc
84
+ previous = @transform
85
+ @preprocess = state
86
+ instance_eval &proc
87
+ @preprocess = previous
88
+ end
89
+
90
+ def defaults settings = nil, &proc
91
+ return @defaults if settings == nil
92
+ previous = @defaults
93
+ @defaults = @defaults.merge(settings)
94
+ if proc
95
+ ret = instance_eval &proc
96
+ @defaults = previous
97
+ end
98
+ ret
99
+ end
100
+
101
+ # implement the openscad lookup function
102
+ # Look up value in table, and linearly interpolate if there's no exact match.
103
+ # The first argument is the value to look up. The second is the lookup table
104
+ # -- a vector of key-value pairs.
105
+ # table can be an array of key/value subarray pairs, or a hash with numeric keys
106
+ def lookup key, table
107
+ table = table.to_a if table.is_a? Hash
108
+ table.sort! { |x,y| x[0] <=> y[0] }
109
+ b = table.bsearch { |x| x[0] >= key } || table.last
110
+ index_b = table.index(b)
111
+ a = if index_b > 0 then table[index_b - 1] else b end
112
+
113
+ return a[1] if key <= a[0]
114
+ return b[1] if key >= b[0]
115
+
116
+ key_difference = b[0] - a[0]
117
+ value_proportion = (key - a[0]).to_f / key_difference
118
+ (a[1].to_f * value_proportion) + (b[1].to_f * (1.0 - value_proportion))
119
+ end
120
+
121
+ # gets and sets resolution settings
122
+ def resolution **settings, &proc
123
+ warn "Setting fragments_per_turn and degrees_per_fragment together makes no sense!" if settings[:fragments_per_turn] && settings[:degrees_per_fragment]
124
+ previous_settings = @resolution
125
+ @resolution.merge! settings
126
+ @resolution[:degrees_per_fragment] = 360.0 / settings[:fragments_per_turn].to_f if settings[:fragments_per_turn]
127
+ @resolution[:fragments_per_turn] = 360.0 / settings[:degrees_per_fragment].to_f if settings[:degrees_per_fragment]
128
+
129
+ if proc
130
+ return_data = instance_eval(&proc)
131
+ @resolution = previous_settings
132
+ return_data
133
+ else
134
+ @resolution.dup
135
+ end
136
+ end
137
+
138
+ def _fragments_for diameter: nil, radius: nil
139
+ radius = diameter.to_f / 2.0 if diameter
140
+ if @resolution[:fragments] != 0
141
+ @resolution[:fragments]
142
+ else
143
+ max = (radius.to_f * Math::PI * 2.0) / @resolution[:minimum].to_f
144
+ if @resolution[:fragments_per_turn] > max
145
+ max
146
+ else
147
+ @resolution[:fragments_per_turn]
148
+ end
149
+ end
150
+ end
151
+
152
+ # the background modifier
153
+ def ghost &proc
154
+ _apply_modifier('%', &proc)
155
+ end
156
+
157
+ # the debug modifier
158
+ def highlight &proc
159
+ _apply_modifier('#', &proc)
160
+ end
161
+
162
+ # the root modifier
163
+ def root &proc
164
+ _apply_modifier('!', &proc)
165
+ end
166
+
167
+
168
+
169
+ def _apply_modifier new_modifier, &children
170
+ if children
171
+ previously = @modifier
172
+ @modifier = new_modifier
173
+ instance_eval &children
174
+ @modifier = previously
175
+ else
176
+ @one_time_modifier = new_modifier
177
+ end
178
+ end
179
+
180
+
181
+ # returns the abstract tree
182
+ def _abstract_tree; @ast; end
183
+ end
184
+
185
+
186
+
187
+
@@ -0,0 +1,210 @@
1
+ class Oozby::MethodPreprocessor
2
+ NoResolution = %i{translate rotate scale mirror resize difference union intersection hull minkowski}
3
+
4
+ def initialize env: nil, ooz: nil
5
+ @env = env
6
+ @parent = ooz
7
+ end
8
+
9
+ def transform_call(call_info)
10
+ send("_#{call_info.method}", call_info) if respond_to? "_#{call_info.method}"
11
+ resolution call_info unless NoResolution.include? call_info.method # apply resolution settings from scope
12
+ return call_info
13
+ end
14
+
15
+ # allow translate to take x, y, z named args instead of array, with defaults to 0
16
+ def xyz_to_array(info, default: 0, arg: false)
17
+ if [:x, :y, :z].any? { |name| info[:named_args].include? name }
18
+
19
+ # create coordinate 'vector' (array)
20
+ coords = [
21
+ info[:named_args][:x] || default,
22
+ info[:named_args][:y] || default,
23
+ info[:named_args][:z] || default
24
+ ]
25
+
26
+ # if argument name is specified, use that, otherwise make it the first argument in the call
27
+ if arg
28
+ info[:named_args][arg] = coords
29
+ else
30
+ info[:args].unshift coords
31
+ end
32
+
33
+ # delete unneeded bits from call
34
+ [:x, :y, :z].each { |item| info[:named_args].delete item }
35
+ end
36
+ end
37
+
38
+ # layout defaults like center = whatever
39
+ def layout_defaults(info)
40
+ info[:named_args] = @env.defaults.dup.merge(info[:named_args])
41
+ end
42
+
43
+ # apply resolution settings to call info
44
+ ResolutionLookupTable = {degrees_per_fragment: :"$fa", minimum: :"$fs", fragments: :"$fn"}
45
+ def resolution(info)
46
+ res = @env.resolution
47
+ res.delete_if { |k,v| Oozby::Environment::ResolutionDefaults[k] == v }
48
+ res.each do |key, value|
49
+ info[:named_args][ResolutionLookupTable[key] || "$#{key}".to_sym] ||= value
50
+ end
51
+ end
52
+
53
+ def _translate(info); xyz_to_array(info, arg: :v); end
54
+ def _rotate(info); xyz_to_array(info, arg: :a); end
55
+ def _scale(info); xyz_to_array(info, default: 1, arg: :v); end
56
+ def _mirror(info); xyz_to_array(info); end
57
+ def _resize(info); xyz_to_array(info, default: 1, arg: :newsize); end
58
+ def _cube(info)
59
+ xyz_to_array(info, default: 1, arg: :size)
60
+ expanded_names(info)
61
+ layout_defaults(info)
62
+
63
+ if info[:named_args][:r]
64
+ # render rounded rectangle
65
+ info.replace rounded_cube(**args_parse(info, :size, :center, :r))
66
+ end
67
+ end
68
+
69
+ def expanded_names(info)
70
+ # let users use 'radius' as longhand for 'r'
71
+ info.named_args[:r] = info.named_args.delete(:radius) if info.named_args[:radius]
72
+ info.named_args[:r1] = info.named_args.delete(:radius1) if info.named_args[:radius1]
73
+ info.named_args[:r1] = info.named_args.delete(:radius_1) if info.named_args[:radius_1]
74
+ info.named_args[:r2] = info.named_args.delete(:radius2) if info.named_args[:radius2]
75
+ info.named_args[:r2] = info.named_args.delete(:radius_2) if info.named_args[:radius_2]
76
+
77
+ info.named_args[:"$fn"] = info.named_args.delete(:facets) if info.named_args[:facets]
78
+
79
+ # allow range for radius
80
+ if info.named_args[:r].is_a? Range
81
+ range = info.named_args.delete(:r)
82
+ info.named_args[:r1] = range.first
83
+ info.named_args[:r2] = range.last
84
+ end
85
+
86
+ # let users specify diameter instead of radius - convert it
87
+ { diameter: :r, dia: :r, d: :r,
88
+ diameter1: :r1, diameter_1: :r1, dia1: :r1, dia_1: :r1, d1: :r1,
89
+ diameter2: :r2, diameter_2: :r2, dia2: :r2, dia_2: :r2, d2: :r2
90
+ }.each do |d, r|
91
+ if info.named_args.key? d
92
+ info.named_args[r] = info.named_args.delete(d) / 2.0
93
+ end
94
+ end
95
+
96
+ # long version 'height' becomes 'h'
97
+ info.named_args[:h] = info.named_args.delete(:height) if info.named_args[:height]
98
+ end
99
+
100
+ def _linear_extrude(info); layout_defaults(info); expanded_names(info); end
101
+ def _rotate_extrude(info); layout_defaults(info); expanded_names(info); end
102
+
103
+ def _circle(info); expanded_names(info); end
104
+ def _sphere(info); expanded_names(info); end
105
+ def _cylinder(info); expanded_names(info); layout_defaults(info); end
106
+ def _square(info)
107
+ expanded_names(info)
108
+ xyz_to_array(info, default: 1, arg: :size)
109
+ layout_defaults(info)
110
+
111
+ if info[:named_args][:r]
112
+ # render rounded rectangle
113
+ info.replace rounded_rect(**args_parse(info, :size, :center, :r))
114
+ end
115
+ end
116
+
117
+ def rounded_rect size: [1,1], center: false, r: 0.0
118
+ diameter = r * 2
119
+ circle_x = (size[0] / 2.0) - r
120
+ circle_y = (size[1] / 2.0) - r
121
+
122
+ capture do
123
+ translate(if center then [0,0] else [size[0].to_f / 2.0, size[1].to_f / 2.0] end) do
124
+ union do
125
+ square([size[0], size[1] - diameter], center = true)
126
+ square([size[0] - diameter, size[1]], center = true)
127
+ preprocessor true do
128
+ resolution(fragments: (_fragments_for(radius: r).to_f / 4.0).round * 4.0) do
129
+ translate([ circle_x, circle_y]) { circle(r: r) }
130
+ translate([ circle_x, -circle_y]) { circle(r: r) }
131
+ translate([-circle_x, -circle_y]) { circle(r: r) }
132
+ translate([-circle_x, circle_y]) { circle(r: r) }
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ def rounded_cube size: [1,1,1], center: false, r: 0.0
141
+ size = [size[0] || 1, size[1] || 1, size[2] || 1]
142
+ diameter = r.to_f * 2.0
143
+
144
+ preprocessor = self
145
+ # use rounded rect to create the body shape
146
+ capture do
147
+ offset = if center then [0,0,0] else [size[0].to_f / 2.0, size[1].to_f / 2.0, size[2].to_f / 2.0] end
148
+ translate(offset) do
149
+ # extrude the main body parts using rounded_rect as the basis
150
+ linear_extrude(height: size[2] - diameter, center: true) {
151
+ inject_abstract_tree(preprocessor.rounded_rect(size: [size[0], size[1]], center: center, r: r)) }
152
+ rotate([90,0,0]) { linear_extrude(height: size[1] - diameter, center: true) {
153
+ inject_abstract_tree(preprocessor.rounded_rect(size: [size[0], size[2]], center: center, r: r)) }}
154
+ rotate([0,90,0]) { linear_extrude(height: size[0] - diameter, center: true) {
155
+ inject_abstract_tree(preprocessor.rounded_rect(size: [size[2], size[1]], center: center, r: r)) }}
156
+
157
+ # fill in the corners with spheres
158
+ xr, yr, zr = size.map { |x| (x / 2) - r }
159
+ corner_coordinates = [
160
+ [ xr, yr, zr],
161
+ [ xr, yr,-zr],
162
+ [ xr,-yr, zr],
163
+ [ xr,-yr,-zr],
164
+ [-xr, yr, zr],
165
+ [-xr, yr,-zr],
166
+ [-xr,-yr, zr],
167
+ [-xr,-yr,-zr]
168
+ ]
169
+ preprocessor true do
170
+ resolution(fragments: (_fragments_for(radius: r).to_f / 4.0).round * 4.0) do
171
+ corner_coordinates.each do |coordinate|
172
+ translate(coordinate) do
173
+ # generate sphere shape
174
+ rotate_extrude do
175
+ intersection do
176
+ circle(r: r)
177
+ translate([r, 0, 0]) { square([r * 2, r * 4], center: true) }
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ # parse arguments like openscad does
189
+ def args_parse(info, *arg_names)
190
+ args = info[:named_args].dup
191
+ info[:args].length.times do |index|
192
+ warn "Overwriting argument #{arg_names[index]}"
193
+ args[arg_names[index]] = info[:args][index]
194
+ end
195
+
196
+ args
197
+ end
198
+
199
+ def capture &proc
200
+ (@env._subscope {
201
+ preprocessor(false) {
202
+ instance_eval(&proc)
203
+ }
204
+ }).first
205
+ end
206
+ end
207
+
208
+
209
+
210
+
@@ -0,0 +1,46 @@
1
+ require 'json'
2
+
3
+ # takes in an oozby abstract tree, and writes out openscad source code
4
+ class Oozby::Render
5
+ def initialize ooz: nil
6
+ @oozby = ooz
7
+ end
8
+
9
+ def escape thing
10
+ JSON.generate(thing, quirks_mode: true)
11
+ end
12
+
13
+ def render code_tree, clean: true
14
+ output = []
15
+ code_tree.each do |node|
16
+ if node.key? :method
17
+ # function call
18
+ method_name = (node[:modifier].to_s || '') + node[:method].to_s
19
+
20
+ args = node[:args].map { |a| escape(a) }
21
+ node[:named_args].each do |key, value|
22
+ args.push "#{key} = #{escape(value)}"
23
+ end
24
+
25
+ call = "#{method_name}(#{args.join(', ')})"
26
+ if node[:children].nil? or node[:children].empty?
27
+ output.push "#{call};"
28
+ elsif node[:children].length == 1
29
+ rendered_kids = render(node[:children])
30
+ output.push "#{call} " + rendered_kids.shift
31
+ output.push *rendered_kids
32
+ else
33
+ output.push "#{call} {"
34
+ output.push *render(node[:children]).map { |line| if clean then " #{line}" else line.to_s end }
35
+ output.push "}"
36
+ end
37
+
38
+ elsif node.key? :assign
39
+ output << "#{node[:assign]} = #{escape(node[:value])};"
40
+ end
41
+ end
42
+
43
+ output
44
+ end
45
+ end
46
+
data/license.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/readme.md ADDED
@@ -0,0 +1,28 @@
1
+ Oozby (Oozebane + Ruby) is inspired by the realisation that OpenSCAD does not truly support variables, and so it is more like a markup language than a programming language. Oozby aims to give users a similar interface to OpenSCAD, but with the more sensible and clear syntax of Ruby, and with a bunch of extra features patched in. Check out the examples folder to see some great demos of the features Oozby offers.
2
+
3
+ Here are some highlights:
4
+
5
+ * For built in functions which take an '`r`' parameter like `sphere`, `circle`, `cylinder`, you can specify any of these instead:
6
+ * + `r`, `radius`
7
+ * + `r1`, `radius\_1`, `radius1`
8
+ * + `r2`, `radius\_2`, `radius2`
9
+ * + `d`, `dia`, `diameter`: _anything specified as diameter will be automatically halved, taking a lot of `/ 2.0` statements out of your code__
10
+ * + and of course `d1`, `dia1`, `dia\_1`, `diameter1`, `diameter\_1`, `d2`, `dia2`, `dia\_2`, `diameter2`, `diameter\_2`
11
+ * Built in functions which take 'h' like `cylinder`, `linear\_extrude` can take `height` instead if you like
12
+ * Cubes and Squares have 'radius' option, which if > 0.0 causes the corners to be rounded very nicely.
13
+ * Full support for variables, can use all of ruby's core and standard libraries, use rubygems to pull in data - read images, access web services, read databases, automatically download things from thingiverse, whatever
14
+ * For cylinders you can specify a Range for the radius option instead of specifying r1 and r2 separately if you like
15
+ * All the round things have a 'facets' option which translates to $fn
16
+ * No semicolons (of course!) - specify one function as the parent of the next by using a block or use the > operator (see examples)
17
+ * Lambda, classes, methods, oh my!
18
+ * Built in functions like translate, rotate, scale, which take a 2d or 3d vector [x,y,z] can instead have options passed like this:
19
+ * + `translate(x: 5, y: 6)` - unspecified items default to 0
20
+ * + `scale(y: 2)` - unspecified items default to 1
21
+ * Specify defaults: You can create a context within a block where everything defaults to `center: true`! How many times have you had to write `center = true` again and again when constructing something with lots of symmetry in OpenSCAD?
22
+ * Establish a scope within a block with specific resolution
23
+
24
+ This tool is considered very experimental at the moment and could break in horrible ways. There is a good chance the API will change and break stuff until the gem hits 1.0, but hey, get on board and lets figure out how to make OpenSCAD less horrible. Maybe if we come up with really great ideas in Oozby that will give the OpenSCAD devs a clear direction forward for new syntaxes and features in the future - kind of the same idea as rubinius and pypy! A place to quickly prototype kooky ideas.
25
+
26
+ Oozby is not a language translator and doesn't try to be. It is a markup builder like Markaby or XML Builder, so you should expect it's output to sometimes be not very readable and unnecessarily verbose. Your variables and maths are all rendered by Oozby, and as a result Oozby cannot and probably never will be able to generate dynamic modules which can be used from OpenSCAD files. Of course, you can use Oozby libraries from inside other Oozby scripts! And it probably wouldn't be too difficult to implement the OpenSCAD language in Oozby itself, so it could automatically convert OpenSCAD in to Oozby and in that way allow OpenSCAD files to call on Oozby libraries.
27
+
28
+ Another note: Oozby uses regular ruby maths, and that means if you're not working entirely in whole millimetres you may encounter a little bit of floating point rounding. You should try to make surfaces intersect, not just come up against each other's edges exactly. Anything that wouldn't look right rendered by the quick opengl preview mode of OpenSCAD might not work properly with full CGAL renders. Also note that in ruby `5 / 2 = 2`. If you want `2.5`, make one of the operands a Float, so `5 / 2.0 = 2.5` or `5.0 / 2 = 2.5` or `5.0 / 2.0 = 2.5`. We could use refinements perhaps to patch the oozby environment so `5 / 2 = 2.5` but that would be weird for existing Ruby users. Not sure what to do here.
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oozby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bluebie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fssm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.10
27
+ description: OpenSCAD - a cad language for creating solid 3d objects, useful for CNC
28
+ and 3D Printing, is incredibly annoying. It doesn't even support variables! Oozby
29
+ is a markup builder like Markaby or XML Builder, so you can write OpenSCAD programs
30
+ in Ruby. It also patches in a bunch of really nice features which make programming
31
+ objects much more fun. Check out the Readme and examples folder for some demos of
32
+ what this tool can do!
33
+ email: a@creativepony.com
34
+ executables:
35
+ - oozby
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/oozby/base.rb
40
+ - lib/oozby/element.rb
41
+ - lib/oozby/environment.rb
42
+ - lib/oozby/method_preprocessor.rb
43
+ - lib/oozby/render.rb
44
+ - lib/oozby.rb
45
+ - readme.md
46
+ - license.txt
47
+ - bin/oozby
48
+ homepage: http://github.com/Bluebie/digiusb.rb
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --main
54
+ - lib/oozby/base.rb
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.0.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: A markup language for OpenSCAD
73
+ test_files: []