Compare commits

...

21 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
oguzhankoral 43081c70e2 Send vertices separately 2023-01-10 10:51:03 +03:00
oguzhankoral 0fde1c2026 Optimize meshes with dynamic vertex adding 2023-01-10 09:14:11 +03:00
Oğuzhan Koral b35383571e Merge pull request #126 from specklesystems/gergo/updateCiContext
use innosetup context in the windows build
2023-01-09 14:57:18 +03:00
Oğuzhan Koral 45a84847a2 Fix (block): Base point for block definition 2023-01-08 17:41:56 +03:00
oguzhankoral 70d92f26d6 Note for reason to having block definition base points 2023-01-08 17:40:57 +03:00
oguzhankoral 737ed86e69 Comparison method for point object 2023-01-08 15:15:17 +03:00
oguzhankoral 3865057b7a Fallback geometry for block definition 2023-01-08 14:50:47 +03:00
oguzhankoral 42a84dcd86 Receive blocks from rhino 2023-01-07 00:35:02 +03:00
Gergő Jedlicska e2d819c59d Merge branch 'main' of github.com:specklesystems/speckle-sketchup into gergo/updateCiContext 2023-01-06 14:30:16 +01:00
oguzhankoral bfee6a88dc Add base point for block definition 2023-01-06 16:28:32 +03:00
Oğuzhan Koral 68f3be17df Fix (UI): closing UI cause state loss 2023-01-06 16:25:52 +03:00
oguzhankoral 929c97ff5e Bring to front dialog if it is minimized when user reclicked UI button 2023-01-06 16:20:53 +03:00
oguzhankoral 4b66a2e4d0 Reset dialog if it's closed 2023-01-06 16:20:32 +03:00
Gergő Jedlicska 46e740154e use innosetup context in the windows build 2023-01-06 14:03:50 +01:00
7 changed files with 131 additions and 94 deletions
+1 -1
View File
@@ -65,7 +65,6 @@ jobs:
name: I know Github as a host
command: |
mkdir ~/.ssh
touch ~/.ssh/known_hosts
ssh-keyscan github.com >> ~/.ssh/known_hosts
- run:
name: Clone
@@ -116,6 +115,7 @@ workflows:
only: /.*/
- build-connector:
context: innosetup
slug: sketchup
requires:
- get-ci-tools
+19 -2
View File
@@ -198,16 +198,30 @@ module SpeckleConnector
# rubocop:enable Metrics/MethodLength
# Creates a component definition and instance from a speckle object with a display value
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength
def display_value_to_native_component(obj, layer, entities, model_preferences, &convert)
obj_id = obj['applicationId'].to_s.empty? ? obj['id'] : obj['applicationId']
block_definition = obj['@blockDefinition'] || obj['blockDefinition']
definition = BLOCK_DEFINITION.to_native(
sketchup_model,
obj['displayValue'],
layer,
"def::#{obj_id}",
obj['@blockDefinition']['always_face_camera'],
if block_definition.nil?
false
else
block_definition['always_face_camera'].nil? ? false : block_definition['always_face_camera']
end,
model_preferences,
obj['@blockDefinition']['sketchup_attributes'],
if block_definition.nil?
nil
else
block_definition['sketchup_attributes'].nil? ? nil : block_definition['sketchup_attributes']
end,
obj_id,
&convert
)
@@ -219,6 +233,9 @@ module SpeckleConnector
instance.name = obj_id
instance
end
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength
# Takes a component definition and finds and erases the first instance with the matching name
# (and optionally the applicationId)
@@ -14,27 +14,37 @@ module SpeckleConnector
class Mesh < Base
SPECKLE_TYPE = 'Objects.Geometry.Mesh'
# @return [Array<Geom::Point3d>] points that construct mesh.
attr_accessor :vertices
# @return [Array] polygons
attr_accessor :polygons
# @return [String] speckle units.
attr_reader :units
# @param units [String] units of the speckle mesh.
# @param render_material [Other::RenderMaterial, nil] render material of the speckle mesh.
# @param bbox [Geometry::BoundingBox] bounding box speckle object of the speckle mesh.
# @param vertices [Array] vertices of the speckle mesh.
# @param faces [Array] faces of the speckle mesh.
# @param face_edge_flags [Array] face edge flags of the speckle mesh.
# @param sketchup_attributes [Hash] additional information about speckle mesh.
# rubocop:disable Metrics/ParameterLists
def initialize(units:, render_material:, bbox:, vertices:, faces:, face_edge_flags:, sketchup_attributes:)
def initialize(units:, render_material:, bbox:, vertices:, faces:, sketchup_attributes:)
super(
speckle_type: SPECKLE_TYPE,
total_children_count: 0,
application_id: nil,
id: nil
)
@vertices = []
@polygons = []
@units = units
self[:units] = units
self[:renderMaterial] = render_material
self[:bbox] = bbox
self[:'@(31250)vertices'] = vertices
self[:'@(62500)faces'] = faces
self[:'@(31250)faceEdgeFlags'] = face_edge_flags
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
end
# rubocop:enable Metrics/ParameterLists
@@ -79,37 +89,40 @@ 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]
dictionaries = SketchupModel::Dictionary::DictionaryHandler.attribute_dictionaries_to_speckle(face)
end
mesh = face.loops.count > 1 ? face.mesh : nil
has_any_soften_edge = face.edges.any?(&:soft?)
att = dictionaries.any? ? { is_soften: has_any_soften_edge, dictionaries: dictionaries }
: { is_soften: has_any_soften_edge }
Mesh.new(
speckle_mesh = Mesh.new(
units: units,
render_material: face.material.nil? && face.back_material.nil? ? nil : Other::RenderMaterial
.from_material(face.material || face.back_material),
bbox: Geometry::BoundingBox.from_bounds(face.bounds, units),
vertices: mesh.nil? ? face_vertices_to_array(face, units) : mesh_points_to_array(mesh, units),
faces: mesh.nil? ? face_indices_to_array(face, 0) : mesh_faces_to_array(mesh, -1),
face_edge_flags: mesh.nil? ? face_edge_flags_to_array(face) : mesh_edge_flags_to_array(mesh),
vertices: [], # mesh.nil? ? face_vertices_to_array(face, units) : mesh_points_to_array(mesh, units),
faces: [], # mesh.nil? ? face_indices_to_array(face, 0) : mesh_faces_to_array(mesh, -1),
# face_edge_flags: [], # mesh.nil? ? face_edge_flags_to_array(face) : mesh_edge_flags_to_array(mesh),
sketchup_attributes: att
)
speckle_mesh.face_to_mesh(face)
speckle_mesh.update_mesh
speckle_mesh
end
# rubocop:enable Style/MultilineTernaryOperator
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# get a flat array of vertices from a list of sketchup vertices
def self.face_vertices_to_array(face, units)
def face_to_mesh(face)
mesh = face.loops.count > 1 ? face.mesh : nil
mesh.nil? ? face_vertices_to_array(face) : mesh_points_to_array(mesh)
mesh.nil? ? face_indices_to_array(face) : mesh_faces_to_array(mesh)
end
# Collects indexed Sketchup vertices into flat array for Speckle use.
def vertices_to_array(units)
pts_array = []
face.vertices.each do |v|
pt = v.position
vertices.each do |pt|
pts_array.push(Geometry.length_to_speckle(pt[0], units),
Geometry.length_to_speckle(pt[1], units),
Geometry.length_to_speckle(pt[2], units))
@@ -117,49 +130,58 @@ module SpeckleConnector
pts_array
end
# get a flat array of vertices from a sketchup polygon mesh
def self.mesh_points_to_array(mesh, units)
pts_array = []
def update_mesh
# puts "Vertex count on mesh #{vertices.length}"
self['@(31250)vertices'] = vertices_to_array(units)
self[:'@(62500)faces'] = polygons
end
# Get a flat array of vertices from a list of sketchup vertices
# @param face [Sketchup::Face] face to get vertices.
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
end
# Get a flat array of face indices from a sketchup face
def face_indices_to_array(face)
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)
end
end
# Get a flat array of vertices from a sketchup polygon mesh
# @param mesh [Geom::PolygonMesh] mesh to get points.
def mesh_points_to_array(mesh)
mesh.points.each do |pt|
pts_array.push(
Geometry.length_to_speckle(pt[0], units),
Geometry.length_to_speckle(pt[1], units),
Geometry.length_to_speckle(pt[2], units)
)
# FIXME: Enable previous line when viewer supports shared vertices
# vertices.push(pt) unless vertices.any? { |point| point == pt }
vertices.push(pt)
end
pts_array
end
# get a flat array of face indices from a sketchup face
def self.face_indices_to_array(face, offset)
face_array = [face.vertices.count]
face_array.push(*face.vertices.count.times.map { |index| index + offset })
face_array
end
# get an array of face indices from a sketchup polygon mesh
def self.mesh_faces_to_array(mesh, offset = 0)
faces = []
# Get an array of face indices from a sketchup polygon mesh
# @param mesh [Geom::PolygonMesh] mesh to convert into polygons.
def mesh_faces_to_array(mesh)
mesh.polygons.each do |poly|
faces.push(
poly.count, *poly.map { |index| index.abs + offset }
)
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)
end
polygons.push(*global_polygon_array)
end
faces
end
def self.face_edge_flags_to_array(face)
face.outer_loop.edges.map(&:soft?)
end
def self.mesh_edge_flags_to_array(mesh)
edge_flags = []
mesh.polygons.each do |poly|
edge_flags.push(
*poly.map(&:negative?)
)
end
edge_flags
end
def self.get_soften_setting(mesh)
@@ -28,6 +28,17 @@ module SpeckleConnector
self[:units] = units
end
# Compare this point with other point those are reference to same coordinate.
# @param other [SpeckleObjects::Geometry::Point] other point to compare.
def ==(other, tolerance: 1e-15)
return false if (self[:x] - other[:x]).abs > tolerance
return false if (self[:y] - other[:y]).abs > tolerance
return false if (self[:z] - other[:z]).abs > tolerance
return false if self[:units] != other[:units]
true
end
# @param vertex [Geom::Point3d] sketchup point to convert speckle point.
# @param units [String] unit of the point.
def self.from_vertex(vertex, units)
@@ -17,11 +17,13 @@ module SpeckleConnector
SPECKLE_TYPE = 'Objects.Other.BlockDefinition'
# @param geometry [Object] geometric definition of the block.
# @param base_point [Geometry::Point] base point of the block definition.
# @param name [String] name of the block definition.
# @param units [String] units of the block definition.
# @param application_id [String, NilClass] application id of the block definition.
# rubocop:disable Metrics/ParameterLists
def initialize(geometry:, name:, units:, always_face_camera:, sketchup_attributes: {}, application_id: nil)
def initialize(geometry:, base_point:, name:, units:, always_face_camera:, sketchup_attributes: {},
application_id: nil)
super(
speckle_type: SPECKLE_TYPE,
total_children_count: 0,
@@ -30,8 +32,10 @@ module SpeckleConnector
)
self[:units] = units
self[:name] = name
self[:basePoint] = base_point
self[:always_face_camera] = always_face_camera
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
# FIXME: Since geometry sends with @ as detached, block basePlane renders on viewer.
self['@geometry'] = geometry
end
# rubocop:enable Metrics/ParameterLists
@@ -66,6 +70,7 @@ module SpeckleConnector
BlockDefinition.new(
units: units,
name: definition.name,
base_point: Geometry::Point.new(0, 0, 0, units),
geometry: geometry,
always_face_camera: definition.behavior.always_face_camera?,
sketchup_attributes: att,
@@ -129,8 +134,10 @@ 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 }
lines + nested_blocks + nested_groups + mesh_groups.values
else
@@ -146,39 +153,12 @@ 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]
if face.loops.size > 1
mesh = face.mesh
mat_group[:'@(31250)vertices'].push(*Geometry::Mesh.mesh_points_to_array(mesh, units))
mat_group[:'@(62500)faces'].push(*Geometry::Mesh.mesh_faces_to_array(mesh, mat_group[:pt_count] - 1))
mat_group[:'@(31250)faceEdgeFlags'].push(*Geometry::Mesh.mesh_edge_flags_to_array(mesh))
else
mat_group[:'@(31250)vertices'].push(*Geometry::Mesh.face_vertices_to_array(face, units))
mat_group[:'@(62500)faces'].push(*Geometry::Mesh.face_indices_to_array(face, mat_group[:pt_count]))
mat_group[:'@(31250)faceEdgeFlags'].push(*Geometry::Mesh.face_edge_flags_to_array(face))
end
mat_group[:pt_count] += face.vertices.count
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: [],
face_edge_flags: [],
sketchup_attributes: { is_soften: has_any_soften_edge }
)
mesh[:pt_count] = 0
mesh
mat_group.face_to_mesh(face)
end
# Mesh group id helps to determine how to group faces into meshes.
@@ -37,6 +37,7 @@ module SpeckleConnector
self[:renderMaterial] = render_material
self[:transform] = transform
self[:sketchup_attributes] = sketchup_attributes if sketchup_attributes.any?
# FIXME: Since blockDefinition sends with @ as detached, block basePlane renders on viewer.
self['@blockDefinition'] = block_definition
end
# rubocop:enable Metrics/ParameterLists
@@ -104,15 +105,17 @@ module SpeckleConnector
# so this is set to false always until I can figure this out
is_group = false
# is_group = block['is_sketchup_group']
block_definition = block['@blockDefinition'] || block['blockDefinition']
geometry = block_definition['@geometry'] || block_definition['geometry']
definition = BlockDefinition.to_native(
sketchup_model,
block['@blockDefinition']['@geometry'],
geometry,
layer,
block['@blockDefinition']['name'],
block['@blockDefinition']['always_face_camera'],
block_definition['name'],
block_definition['always_face_camera'].nil? ? false : block_definition['always_face_camera'],
model_preferences,
block['@blockDefinition']['sketchup_attributes'],
block['@blockDefinition']['applicationId'],
block_definition['sketchup_attributes'],
block_definition['applicationId'],
&convert
)
+5 -1
View File
@@ -29,11 +29,12 @@ module SpeckleConnector
# Show dialog if it's not visible yet
def show
bring_to_front if html_dialog.visible?
return if html_dialog.visible?
# reset dialog only if it is marked ready, otherwise
# add_exec_callback is triggered twice upon first initialization
reset_dialog! if @ready
reset_dialog!
html_dialog.show
end
@@ -73,6 +74,9 @@ module SpeckleConnector
# @return [UI::HtmlDialog] the Sketchup interface to html dialog
def init_dialog
dialog = UI::HtmlDialog.new(@dialog_specs)
dialog.set_can_close do
true
end
File.exist?(@htm_file) ? dialog.set_file(@htm_file) : dialog.set_url('http://localhost:8081')
# dialog.set_url('http://localhost:8081') # uncomment this line if you want to use your local version of ui
add_exec_callback(dialog)