Compare commits

...

7 Commits

Author SHA1 Message Date
Oğuzhan Koral e76aeb80fd Fix (attributes): Use from_face method to face consider attributes 2023-01-11 12:05:47 +03:00
oguzhankoral 28292e59e2 Use from_face method to consider attributes 2023-01-11 11:59:50 +03:00
Oğuzhan Koral 25dda481b2 Comment out vertex count log 2023-01-10 16:47:42 +03:00
Oğuzhan Koral bbda233fd8 Comment out vertex count log 2023-01-10 16:46:56 +03:00
Oğuzhan Koral 349218f0b5 Feat (Mesh): mesh improvements
Mesh grouping methods are improved with options:

Shared vertices (It is not supported by viewer currently, but when available it is ready to approach)
Separated vertices
2023-01-10 14:36:11 +03:00
oguzhankoral f18d00a69d Remove disable rubocop issues 2023-01-10 14:30:28 +03:00
oguzhankoral 25ea6504de Note about when viewer supports shared vertices 2023-01-10 11:33:56 +03:00
2 changed files with 8 additions and 24 deletions
@@ -89,8 +89,6 @@ module SpeckleConnector
# @param face [Sketchup::Face] face to convert mesh
# rubocop:disable Style/MultilineTernaryOperator
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def self.from_face(face, units, model_preferences)
dictionaries = {}
if model_preferences[:include_entity_attributes]
@@ -114,8 +112,6 @@ module SpeckleConnector
speckle_mesh
end
# rubocop:enable Style/MultilineTernaryOperator
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
def face_to_mesh(face)
mesh = face.loops.count > 1 ? face.mesh : nil
@@ -135,7 +131,7 @@ module SpeckleConnector
end
def update_mesh
puts "Vertex count on mesh #{vertices.length}"
# puts "Vertex count on mesh #{vertices.length}"
self['@(31250)vertices'] = vertices_to_array(units)
self[:'@(62500)faces'] = polygons
end
@@ -145,6 +141,7 @@ module SpeckleConnector
def face_vertices_to_array(face)
face.vertices.each do |v|
pt = v.position
# FIXME: Enable previous line when viewer supports shared vertices
# vertices.push(pt) unless vertices.any? { |point| point == pt }
vertices.push(pt)
end
@@ -155,6 +152,7 @@ module SpeckleConnector
polygons.push(face.vertices.count)
face.vertices.each do |v|
pt = v.position
# FIXME: Enable previous line when viewer supports shared vertices
# global_vertex_index = vertices.reverse.find_index(pt)
global_vertex_index = vertices.length - vertices.reverse.find_index(pt) - 1
polygons.push(global_vertex_index)
@@ -165,6 +163,7 @@ module SpeckleConnector
# @param mesh [Geom::PolygonMesh] mesh to get points.
def mesh_points_to_array(mesh)
mesh.points.each do |pt|
# FIXME: Enable previous line when viewer supports shared vertices
# vertices.push(pt) unless vertices.any? { |point| point == pt }
vertices.push(pt)
end
@@ -176,6 +175,7 @@ module SpeckleConnector
mesh.polygons.each do |poly|
global_polygon_array = [poly.count]
poly.each do |index|
# FIXME: Enable previous line when viewer supports shared vertices
# global_vertex_index = vertices.reverse.find_index(mesh.points[index.abs - 1])
global_vertex_index = vertices.length - vertices.reverse.find_index(mesh.points[index.abs - 1]) - 1
global_polygon_array.push(global_vertex_index)
@@ -134,7 +134,7 @@ module SpeckleConnector
if preferences[:model][:combine_faces_by_material]
mesh_groups = {}
definition.entities.grep(Sketchup::Face).collect do |face|
group_meshes_by_material(definition, face, mesh_groups, units, preferences[:model])
group_meshes_by_material(face, mesh_groups, units, preferences[:model])
end
# Update mesh overwrites points and polygons into base object.
mesh_groups.each { |_, mesh| mesh.update_mesh }
@@ -153,29 +153,13 @@ module SpeckleConnector
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize
def self.group_meshes_by_material(definition, face, mat_groups, units, model_preferences)
def self.group_meshes_by_material(face, mat_groups, units, model_preferences)
# convert material
mat_id = get_mesh_group_id(face, model_preferences)
mat_groups[mat_id] = initialise_group_mesh(face, definition.bounds, units) unless mat_groups.key?(mat_id)
mat_groups[mat_id] = Geometry::Mesh.from_face(face, units, model_preferences) unless mat_groups.key?(mat_id)
mat_group = mat_groups[mat_id]
mat_group.face_to_mesh(face)
end
# rubocop:enable Metrics/AbcSize
def self.initialise_group_mesh(face, bounds, units)
has_any_soften_edge = face.edges.any?(&:soft?)
mesh = Geometry::Mesh.new(
units: units,
render_material: face.material.nil? ? nil : RenderMaterial.from_material(face.material),
bbox: Geometry::BoundingBox.from_bounds(bounds, units),
vertices: [],
faces: [],
sketchup_attributes: { is_soften: has_any_soften_edge }
)
mesh[:pt_count] = 0
mesh
end
# Mesh group id helps to determine how to group faces into meshes.
# @param face [Sketchup::Face] face to get mesh group id.