mittsu-mesh_analysis 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
+ SHA256:
3
+ metadata.gz: 9d47802f05e6d13d939200e31a91f09ebf5e6ae2216ec16848de5d8bda17ac67
4
+ data.tar.gz: b6368785eea78b3bb306289e9cd7d029c65f25d27f7ebee3d337fa71dcf897d3
5
+ SHA512:
6
+ metadata.gz: 3910ffd5663e977d5458908c1068f6918f498d2508fe971ef4fb3d4fd9315adc62c895278633455a9da2cead18bf05ddfbcf48f7b906d0e80c1af443e414d8dd
7
+ data.tar.gz: cc3ca365897a18c83a8b746d872019179c043ab81a4f430358e52062c242a663e03bd6b8d5070aa7916aa7ea22a13bcdeac2321c757b3d63cee0efad8ff37e94
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Mittsu: Mesh Analysis
2
+
3
+ Mesh analysis methods for [Mittsu](https://github.com/danini-the-panini/mittsu).
4
+
5
+ Adds three methods:
6
+
7
+ * `Mittsu::Object3D#manifold?`: Detects if a mesh is a single valid surface; i.e. it has no holes, and faces are consistently oriented.
8
+ * `Mittsu::Object3D#solid?`: Detects if the faces of a manifold mesh are correctly oriented, giving the mesh a sensible inside and outside.
9
+ * `Mittsu::Face3#flip!`: Flips the vertex order, and thus orientation of a particular face.
10
+
11
+ ## Requirements
12
+
13
+ Ruby 3.1 or above, otherwise the same as for [Mittsu](https://github.com/danini-the-panini/mittsu) itself.
14
+
15
+ ## Usage
16
+
17
+ Just install:
18
+
19
+ `bundle add mittsu-mesh_analysis`
20
+
21
+ Then require in your code:
22
+
23
+ `require 'mittsu/mesh_analysis'`
24
+
25
+ The methods above should then be available for use.
26
+
27
+ ## About
28
+
29
+ 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,10 @@
1
+ require "bundler/setup"
2
+
3
+ require "rspec/core"
4
+ require "rspec/core/rake_task"
5
+ require "standard/rake"
6
+
7
+ desc "Run all specs in spec directory"
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
@@ -0,0 +1,52 @@
1
+ module Mittsu::MeshAnalysis::Analysis
2
+ def solid?
3
+ # Shortcut if there is nothing here
4
+ return true if geometry.nil? && children.empty?
5
+ # Recurse children to see if they are solid
6
+ children_are_solid = children.map { |x| x.solid? }.all?
7
+ solid = true
8
+ if geometry
9
+ # Make sure material is double sided
10
+ prev_side = material.side
11
+ material.side = Mittsu::DoubleSide
12
+ # Make a raycaster from a vertex and the face normal
13
+ face = geometry.faces.first
14
+ r = Mittsu::Raycaster.new(geometry.vertices[face.b], face.normal, 1e-9)
15
+ intersections = r.intersect_object(self, true)
16
+ # Restore material
17
+ material.side = prev_side
18
+ # We want an even number of intersections
19
+ solid = (intersections.length % 2 == 0)
20
+ end
21
+ solid && children_are_solid
22
+ end
23
+
24
+ def manifold?
25
+ # Shortcut if there is nothing here
26
+ return true if geometry.nil? && children.empty?
27
+ # Recurse children to see if they are manifold
28
+ children_are_manifold = children.map { |x| x.manifold? }.all?
29
+ # Detect manifold geometry in this object
30
+ edges = {}
31
+ # For each face, record its edges in the edge hash
32
+ geometry&.faces&.each do |face|
33
+ update_edge_hash face.a, face.b, edges
34
+ update_edge_hash face.b, face.c, edges
35
+ update_edge_hash face.c, face.a, edges
36
+ end
37
+ # If there's anything left in the edge hash, then either
38
+ # we have holes, or we have badly oriented faces
39
+ edges.empty? && children_are_manifold
40
+ end
41
+
42
+ private
43
+
44
+ # Updates edge hash with the passed vertex indexes
45
+ # First, the reverse edge is searched for in the hash
46
+ # If found, it's removed as we've got a match
47
+ # If not, we record this edge in the hash
48
+ def update_edge_hash(v1, v2, edges)
49
+ return if edges.delete "#{v2}->#{v1}"
50
+ edges["#{v1}->#{v2}"] = true
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module Mittsu
2
+ module MeshAnalysis
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require "mittsu"
2
+ require "mittsu/mesh_analysis/version"
3
+ require "mittsu/mesh_analysis/analysis"
4
+
5
+ module Mittsu
6
+ class Object3D
7
+ include Mittsu::MeshAnalysis::Analysis
8
+ end
9
+
10
+ class Face3
11
+ def flip!
12
+ tmp = @a
13
+ @a = @c
14
+ @c = tmp
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mittsu-mesh_analysis
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.41'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.41'
69
+ description: Mesh analysis tools (e.g. manifold checks) for Mittsu.
70
+ email:
71
+ - james@floppy.org.uk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - README.md
77
+ - Rakefile
78
+ - lib/mittsu/mesh_analysis.rb
79
+ - lib/mittsu/mesh_analysis/analysis.rb
80
+ - lib/mittsu/mesh_analysis/version.rb
81
+ homepage: https://github.com/manyfold3d/mittsu-mesh_analysis
82
+ licenses:
83
+ - MIT
84
+ metadata:
85
+ homepage_uri: https://github.com/manyfold3d/mittsu-mesh_analysis
86
+ source_code_uri: https://github.com/manyfold3d/mittsu-mesh_analysis
87
+ changelog_uri: https://github.com/manyfold3d/mittsu-mesh_analysis/releases
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.5.11
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Mesh analysis tools for Mittsu
107
+ test_files: []