14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ruby3mf/mesh_analyzer.rb', line 14
def self.validate_object(object)
Log3mf.context "verifying object" do |l|
children = object.children.map { |child| child.name }
have_override = object.attributes["pid"] or object.attributes["pindex"]
l.error :object_with_components_and_pid if have_override && children.include?("components")
end
Log3mf.context "validating geometry" do |l|
list = EdgeList.new
has_triangle_pid = false
mesh = find_child(object, "mesh")
if mesh
triangles = find_child(mesh, "triangles")
if triangles
triangles.children.each do |triangle|
v1 = triangle.attributes["v1"].to_s().to_i()
v2 = triangle.attributes["v2"].to_s().to_i()
v3 = triangle.attributes["v3"].to_s().to_i()
if v1 == v2 || v2 == v3 || v3 == v1
l.error :non_distinct_indices
end
list.add_edge(v1, v2)
list.add_edge(v2, v3)
list.add_edge(v3, v1)
if not has_triangle_pid
has_triangle_pid = triangle.attributes["pid"] != nil
end
end
has_object_material = object.attributes["pid"] and object.attributes["pindex"]
if has_triangle_pid and not has_object_material
l.error :missing_object_pid
end
result = list.verify_edges()
if result == :bad_orientation
l.fatal_error :resource_3dmodel_orientation
elsif result == :hole
l.fatal_error :resource_3dmodel_hole
elsif result == :nonmanifold
l.fatal_error :resource_3dmodel_nonmanifold
end
end
end
end
end
|