mersh 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mersh.rb +14 -6
- data/test/binary_solid_header.stl +0 -0
- data/test/box.scad +1 -0
- data/test/box_ascii.stl +50 -50
- data/test/box_binary.stl +0 -0
- data/test/box_plain.json +1 -1
- data/test/box_threejs.json +1 -1
- data/test/test_mersh.rb +8 -2
- metadata +6 -4
data/lib/mersh.rb
CHANGED
@@ -21,7 +21,7 @@ require 'json'
|
|
21
21
|
require 'digest/md5'
|
22
22
|
|
23
23
|
class Mersh
|
24
|
-
VERSION = "0.0.
|
24
|
+
VERSION = "0.0.3"
|
25
25
|
attr_accessor :vertices, :faces, :normals
|
26
26
|
|
27
27
|
def initialize(file)
|
@@ -82,10 +82,17 @@ class Mersh
|
|
82
82
|
private
|
83
83
|
|
84
84
|
def parse
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
# some binary stls begin with the word solid, so can't rely on that
|
86
|
+
# instead, try to read the face count as if it was a binary stl and see if it matches the file size
|
87
|
+
@file.rewind
|
88
|
+
@file.seek 80, IO::SEEK_CUR
|
89
|
+
face_count = @file.read(4).unpack("I")[0]
|
90
|
+
predicted_size = 80 + 4 + 50 * face_count
|
91
|
+
|
92
|
+
if File.size(@file.path) == predicted_size
|
88
93
|
parse_binary_stl
|
94
|
+
else
|
95
|
+
parse_ascii_stl
|
89
96
|
end
|
90
97
|
end
|
91
98
|
|
@@ -95,11 +102,12 @@ class Mersh
|
|
95
102
|
@normals = []
|
96
103
|
|
97
104
|
face_count = 0
|
98
|
-
vertex_count
|
105
|
+
vertex_count = 0
|
99
106
|
vertex_index = {}
|
100
107
|
|
101
|
-
line_pos
|
108
|
+
line_pos = 1
|
102
109
|
|
110
|
+
@file.rewind
|
103
111
|
stl_data = @file.read
|
104
112
|
|
105
113
|
stl_data.gsub!(/^\s*solid.*$/i, '')
|
Binary file
|
data/test/box.scad
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
translate([0,0,5]) cube([20, 20, 10], center=true);
|
data/test/box_ascii.stl
CHANGED
@@ -1,86 +1,86 @@
|
|
1
|
-
solid
|
2
|
-
facet normal 0
|
1
|
+
solid OpenSCAD_Model
|
2
|
+
facet normal -1 0 0
|
3
3
|
outer loop
|
4
|
-
vertex
|
5
|
-
vertex -
|
6
|
-
vertex -
|
4
|
+
vertex -10 -10 10
|
5
|
+
vertex -10 10 10
|
6
|
+
vertex -10 -10 0
|
7
7
|
endloop
|
8
8
|
endfacet
|
9
|
-
facet normal 0
|
9
|
+
facet normal -1 0 0
|
10
10
|
outer loop
|
11
|
-
vertex -
|
12
|
-
vertex
|
13
|
-
vertex
|
11
|
+
vertex -10 -10 0
|
12
|
+
vertex -10 10 10
|
13
|
+
vertex -10 10 0
|
14
14
|
endloop
|
15
15
|
endfacet
|
16
|
-
facet normal 0
|
16
|
+
facet normal 0 0 1
|
17
17
|
outer loop
|
18
|
-
vertex
|
19
|
-
vertex -
|
20
|
-
vertex
|
18
|
+
vertex -10 -10 10
|
19
|
+
vertex 10 -10 10
|
20
|
+
vertex 10 10 10
|
21
21
|
endloop
|
22
22
|
endfacet
|
23
|
-
facet normal 0
|
23
|
+
facet normal 0 0 1
|
24
24
|
outer loop
|
25
|
-
vertex -
|
26
|
-
vertex
|
27
|
-
vertex
|
25
|
+
vertex -10 10 10
|
26
|
+
vertex -10 -10 10
|
27
|
+
vertex 10 10 10
|
28
28
|
endloop
|
29
29
|
endfacet
|
30
|
-
facet normal 1
|
30
|
+
facet normal 0 -1 0
|
31
31
|
outer loop
|
32
|
-
vertex
|
33
|
-
vertex
|
34
|
-
vertex
|
32
|
+
vertex -10 -10 0
|
33
|
+
vertex 10 -10 0
|
34
|
+
vertex 10 -10 10
|
35
35
|
endloop
|
36
36
|
endfacet
|
37
|
-
facet normal 1
|
37
|
+
facet normal 0 -1 0
|
38
38
|
outer loop
|
39
|
-
vertex
|
40
|
-
vertex
|
41
|
-
vertex
|
39
|
+
vertex -10 -10 10
|
40
|
+
vertex -10 -10 0
|
41
|
+
vertex 10 -10 10
|
42
42
|
endloop
|
43
43
|
endfacet
|
44
|
-
facet normal
|
44
|
+
facet normal 0 0 -1
|
45
45
|
outer loop
|
46
|
-
vertex
|
47
|
-
vertex
|
48
|
-
vertex
|
46
|
+
vertex -10 10 0
|
47
|
+
vertex 10 10 0
|
48
|
+
vertex -10 -10 0
|
49
49
|
endloop
|
50
50
|
endfacet
|
51
|
-
facet normal
|
51
|
+
facet normal 0 0 -1
|
52
52
|
outer loop
|
53
|
-
vertex -
|
54
|
-
vertex
|
55
|
-
vertex
|
53
|
+
vertex -10 -10 0
|
54
|
+
vertex 10 10 0
|
55
|
+
vertex 10 -10 0
|
56
56
|
endloop
|
57
57
|
endfacet
|
58
|
-
facet normal
|
58
|
+
facet normal 0 1 0
|
59
59
|
outer loop
|
60
|
-
vertex -
|
61
|
-
vertex
|
62
|
-
vertex -
|
60
|
+
vertex -10 10 10
|
61
|
+
vertex 10 10 10
|
62
|
+
vertex -10 10 0
|
63
63
|
endloop
|
64
64
|
endfacet
|
65
|
-
facet normal
|
65
|
+
facet normal 0 1 0
|
66
66
|
outer loop
|
67
|
-
vertex -
|
68
|
-
vertex
|
69
|
-
vertex
|
67
|
+
vertex -10 10 0
|
68
|
+
vertex 10 10 10
|
69
|
+
vertex 10 10 0
|
70
70
|
endloop
|
71
71
|
endfacet
|
72
|
-
facet normal
|
72
|
+
facet normal 1 0 0
|
73
73
|
outer loop
|
74
|
-
vertex -
|
75
|
-
vertex
|
76
|
-
vertex
|
74
|
+
vertex 10 -10 0
|
75
|
+
vertex 10 10 0
|
76
|
+
vertex 10 10 10
|
77
77
|
endloop
|
78
78
|
endfacet
|
79
|
-
facet normal
|
79
|
+
facet normal 1 0 0
|
80
80
|
outer loop
|
81
|
-
vertex
|
82
|
-
vertex -
|
83
|
-
vertex
|
81
|
+
vertex 10 -10 10
|
82
|
+
vertex 10 -10 0
|
83
|
+
vertex 10 10 10
|
84
84
|
endloop
|
85
85
|
endfacet
|
86
|
-
endsolid
|
86
|
+
endsolid OpenSCAD_Model
|
data/test/box_binary.stl
CHANGED
Binary file
|
data/test/box_plain.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"
|
1
|
+
{"faces":[[0,1,2],[2,1,3],[0,4,5],[1,0,5],[2,6,4],[0,2,4],[3,7,2],[2,7,6],[1,5,3],[3,5,7],[6,7,5],[4,6,5]],"vertices":[[-10.0,-10.0,10.0],[-10.0,10.0,10.0],[-10.0,-10.0,0.0],[-10.0,10.0,0.0],[10.0,-10.0,10.0],[10.0,10.0,10.0],[10.0,-10.0,0.0],[10.0,10.0,0.0]],"normals":[[-1.0,0.0,0.0],[-1.0,0.0,0.0],[0.0,0.0,1.0],[0.0,0.0,1.0],[0.0,-1.0,0.0],[0.0,-1.0,0.0],[0.0,0.0,-1.0],[0.0,0.0,-1.0],[0.0,1.0,0.0],[0.0,1.0,0.0],[1.0,0.0,0.0],[1.0,0.0,0.0]]}
|
data/test/box_threejs.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"morphTargets":[],"uvs":[[]],"
|
1
|
+
{"morphTargets":[],"morphColors":[],"faces":[0,0,1,2,0,2,1,3,0,0,4,5,0,1,0,5,0,2,6,4,0,0,2,4,0,3,7,2,0,2,7,6,0,1,5,3,0,3,5,7,0,6,7,5,0,4,6,5],"metadata":{"generatedBy":"Mersh","formatVersion":3},"uvs":[[]],"colors":[],"materials":[],"vertices":[-10.0,-10.0,10.0,-10.0,10.0,10.0,-10.0,-10.0,0.0,-10.0,10.0,0.0,10.0,-10.0,10.0,10.0,10.0,10.0,10.0,-10.0,0.0,10.0,10.0,0.0],"scale":1.0,"normals":[]}
|
data/test/test_mersh.rb
CHANGED
@@ -15,7 +15,7 @@ class MershTest < Test::Unit::TestCase
|
|
15
15
|
box = Mersh.new(@ascii_stl)
|
16
16
|
box_plain_json = box.to_json
|
17
17
|
box_threejs_json = box.to_json('threejs')
|
18
|
-
|
18
|
+
|
19
19
|
assert_equal String, box_threejs_json.class
|
20
20
|
assert_equal JSON.parse(File.open(@threejs_json).read), JSON.parse(box_threejs_json)
|
21
21
|
|
@@ -27,7 +27,7 @@ class MershTest < Test::Unit::TestCase
|
|
27
27
|
box = Mersh.new(@binary_stl)
|
28
28
|
box_plain_json = box.to_json
|
29
29
|
box_threejs_json = box.to_json('threejs')
|
30
|
-
|
30
|
+
|
31
31
|
assert_equal String, box_threejs_json.class
|
32
32
|
assert_equal JSON.parse(File.open(@threejs_json).read), JSON.parse(box_threejs_json)
|
33
33
|
|
@@ -55,4 +55,10 @@ class MershTest < Test::Unit::TestCase
|
|
55
55
|
|
56
56
|
assert stl.vertices.size > 0
|
57
57
|
end
|
58
|
+
|
59
|
+
def test_solid_header_binary
|
60
|
+
stl = Mersh.new(@current_dir + "/binary_solid_header.stl")
|
61
|
+
|
62
|
+
assert stl.vertices.size > 0
|
63
|
+
end
|
58
64
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mersh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Buser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2013-04-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: json
|
@@ -42,6 +42,8 @@ extra_rdoc_files: []
|
|
42
42
|
files:
|
43
43
|
- lib/mersh.rb
|
44
44
|
- bin/mersh
|
45
|
+
- test/binary_solid_header.stl
|
46
|
+
- test/box.scad
|
45
47
|
- test/box_ascii.stl
|
46
48
|
- test/box_binary.stl
|
47
49
|
- test/box_plain.json
|