mittsu-3mf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +25 -0
- data/Rakefile +10 -0
- data/lib/mittsu/3mf/exporter.rb +113 -0
- data/lib/mittsu/3mf/version.rb +5 -0
- data/lib/mittsu/3mf.rb +3 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '090feca45fc7af2c1d8a2e340bdd891613936528ac15e1546f8d8b8448879572'
|
4
|
+
data.tar.gz: 792ef38dbb785b310ff53de0008cfe4a670077c83430c4b979c61bc051fdc0e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 582b8756f4ad104ee31bca34d3df7511540c9243770ae49f2687249aa5d4d65efad8388183125cd4134ea64bc79b56721c61aa783c3426618cd15185fc1b47a3
|
7
|
+
data.tar.gz: a226ad6b92db706855237594fef7b8c20e8a6aa3045315bd9cb2ed64680e9fbd7c2dad72ed72bc4a4d70e2e779d82f0aa46c3f69e212cb4b437f4051b3f09a9f
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Mittsu: 3MF
|
2
|
+
3MF support for [Mittsu](https://github.com/danini-the-panini/mittsu).
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Just install:
|
7
|
+
|
8
|
+
`bundle add mittsu-3mf`
|
9
|
+
|
10
|
+
Then require in your code:
|
11
|
+
|
12
|
+
`require 'mittsu/3mf'`
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Currently this gem just includes an exporter. Loading 3MF files is "coming soon".
|
17
|
+
|
18
|
+
```
|
19
|
+
exporter = Mittsu::ThreeMFExporter.new
|
20
|
+
exporter.export(object, "output.3mf")
|
21
|
+
```
|
22
|
+
|
23
|
+
## About
|
24
|
+
|
25
|
+
This code was originally written for [Manyfold](https://manyfold.app), supported by funding from [NLNet](https://nlnet.nl) and [NGI Zero](https://ngi.eu/ngi-projects/ngi-zero/).
|
data/Rakefile
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require "builder"
|
2
|
+
require "zip/filesystem"
|
3
|
+
|
4
|
+
module Mittsu
|
5
|
+
class ThreeMFExporter
|
6
|
+
def initialize(options = {})
|
7
|
+
end
|
8
|
+
|
9
|
+
def export(object, filename)
|
10
|
+
Zip::OutputStream.open(filename) do |zip|
|
11
|
+
# OPC content types file
|
12
|
+
store(zip, "[Content_Types].xml", content_types_file)
|
13
|
+
# Add models
|
14
|
+
models = [object]
|
15
|
+
model_names = models.map do |model|
|
16
|
+
# Set a model name if there isn't one
|
17
|
+
model.name ||= SecureRandom.uuid
|
18
|
+
# Store model
|
19
|
+
name = filesystem_safe_name(model)
|
20
|
+
store(zip, "3D/#{name}.model", model_file(model))
|
21
|
+
# Remember the name for later
|
22
|
+
name
|
23
|
+
end
|
24
|
+
# Add OPC rels file with list of contained models
|
25
|
+
store(zip, "_rels/.rels", rels_file(model_names))
|
26
|
+
end
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
# Parse is here for consistency with THREE.js's weird naming of exporter methods
|
31
|
+
alias_method :parse, :export
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def filesystem_safe_name(model)
|
36
|
+
model.name.delete("/\\?*:|\"<>")
|
37
|
+
end
|
38
|
+
|
39
|
+
def store(zip, filename, data)
|
40
|
+
zip.put_next_entry(filename)
|
41
|
+
zip.write(data)
|
42
|
+
end
|
43
|
+
|
44
|
+
def build &block
|
45
|
+
xml = Builder::XmlMarkup.new
|
46
|
+
xml.instruct! :xml, encoding: "UTF-8"
|
47
|
+
yield xml
|
48
|
+
xml.target!
|
49
|
+
end
|
50
|
+
|
51
|
+
def content_types_file
|
52
|
+
build do |xml|
|
53
|
+
xml.Types xmlns: "http://schemas.openxmlformats.org/package/2006/content-types" do
|
54
|
+
xml.Default Extension: "rels", ContentType: "application/vnd.openxmlformats-package.relationships+xml"
|
55
|
+
xml.Default Extension: "model", ContentType: "application/vnd.ms-package.3dmanufacturing-3dmodel+xml"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def rels_file(models)
|
61
|
+
build do |xml|
|
62
|
+
xml.Relationships xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" do
|
63
|
+
models.each do |name|
|
64
|
+
xml.Relationship Target: "/3D/#{name}.model", Id: name, ContentType: "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def model_file(object)
|
71
|
+
build do |xml|
|
72
|
+
xml.model unit: "millimeter", "xml:lang": "en-US", xmlns: "http://schemas.microsoft.com/3dmanufacturing/core/2015/02" do
|
73
|
+
object_ids = []
|
74
|
+
xml.resources do
|
75
|
+
object.traverse do |x|
|
76
|
+
if x.is_a? Mesh
|
77
|
+
object_ids << build_object(xml, x)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
xml.build do
|
82
|
+
object_ids.each do |id|
|
83
|
+
xml.item objectid: id
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_object(xml, object)
|
91
|
+
uuid = SecureRandom.uuid
|
92
|
+
xml.object id: uuid, type: "model" do
|
93
|
+
build_mesh_element(xml, object.geometry)
|
94
|
+
end
|
95
|
+
uuid
|
96
|
+
end
|
97
|
+
|
98
|
+
def build_mesh_element(xml, geometry)
|
99
|
+
xml.mesh do
|
100
|
+
xml.vertices do
|
101
|
+
geometry.vertices.each do |vertex|
|
102
|
+
xml.vertex x: vertex.x, y: vertex.y, z: vertex.z
|
103
|
+
end
|
104
|
+
end
|
105
|
+
xml.triangles do
|
106
|
+
geometry.faces.each do |face|
|
107
|
+
xml.triangle v1: face.a, v2: face.b, v3: face.c
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/mittsu/3mf.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mittsu-3mf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mittsu
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: builder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubyzip
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: standard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.41'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.41'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rexml
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.3'
|
111
|
+
description: 3MF file support for Mittsu
|
112
|
+
email:
|
113
|
+
- james@floppy.org.uk
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- lib/mittsu/3mf.rb
|
121
|
+
- lib/mittsu/3mf/exporter.rb
|
122
|
+
- lib/mittsu/3mf/version.rb
|
123
|
+
homepage: https://github.com/manyfold3d/mittsu-mesh_analysis
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata:
|
127
|
+
homepage_uri: https://github.com/manyfold3d/mittsu-mesh_analysis
|
128
|
+
source_code_uri: https://github.com/manyfold3d/mittsu-3mf
|
129
|
+
changelog_uri: https://github.com/manyfold3d/mittsu-3mf/releases
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.1'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubygems_version: 3.5.11
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: 3MF file support for Mittsu
|
149
|
+
test_files: []
|