Compare commits
40 Commits
2.13.0-rc9
...
2.13.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 5187fded02 | |||
| 370825838a | |||
| bc8eece488 | |||
| 4222b1721d | |||
| b475bc96af | |||
| f9ac7319ae | |||
| 2ce3e9150f | |||
| 8e39832d3e | |||
| ce7ac6da16 | |||
| 57879a57cd | |||
| 6f5b367028 | |||
| 291948c1ef | |||
| 0ca6888fb1 | |||
| 5e92236396 | |||
| 28db40112b | |||
| b2153883ef | |||
| 807cbeb75d | |||
| 4730aebdc6 | |||
| c2279eec87 | |||
| f5567ae9ad | |||
| 2fcba04cf5 | |||
| 0eefd1605f | |||
| 7b88ea022d | |||
| 7a922114ab | |||
| f717c270fd | |||
| ee5ed468c3 | |||
| a9ded445a7 | |||
| 9ecad52df2 | |||
| 8c500985bf | |||
| 3567f9ba5d | |||
| 852bfb716c | |||
| 473956aa3c | |||
| b22fc19400 | |||
| f6a8ece992 | |||
| afc0c21aae | |||
| 08e6106c1f | |||
| 1f9f654e3d | |||
| 501e923760 | |||
| 37b716cfc5 | |||
| 8584db0ab5 |
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../speckle_objects/geometry/length'
|
||||
|
||||
module SpeckleConnector
|
||||
COMBINE_FACES_BY_MATERIAL = :combine_faces_by_material
|
||||
INCLUDE_ENTITY_ATTRIBUTES = :include_entity_attributes
|
||||
@@ -9,6 +11,8 @@ module SpeckleConnector
|
||||
INCLUDE_COMPONENT_ENTITY_ATTRIBUTES = :include_component_entity_attributes
|
||||
MERGE_COPLANAR_FACES = :merge_coplanar_faces
|
||||
|
||||
LEVEL_SHIFT_VALUE = SpeckleObjects::Geometry.length_to_native(1.5, 'm')
|
||||
|
||||
DEFAULT_MODEL_PREFERENCES = {
|
||||
COMBINE_FACES_BY_MATERIAL => true,
|
||||
INCLUDE_ENTITY_ATTRIBUTES => true,
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
module SpeckleConnector
|
||||
BASE_OBJECT = 'Base'
|
||||
|
||||
OBJECTS_BUILTELEMENTS_VIEW3D = 'Objects.BuiltElements.View:Objects.BuiltElements.View3D'
|
||||
|
||||
OBJECTS_GEOMETRY_LINE = 'Objects.Geometry.Line'
|
||||
OBJECTS_GEOMETRY_POLYLINE = 'Objects.Geometry.Polyline'
|
||||
OBJECTS_GEOMETRY_MESH = 'Objects.Geometry.Mesh'
|
||||
OBJECTS_GEOMETRY_BREP = 'Objects.Geometry.Brep'
|
||||
|
||||
OBJECTS_OTHER_BLOCKINSTANCE = 'Objects.Other.BlockInstance'
|
||||
OBJECTS_OTHER_BLOCKINSTANCE_FULL = 'Objects.Other.Instance:Objects.Other.BlockInstance'
|
||||
OBJECTS_OTHER_INSTANCE = 'Objects.Other.Instance:Objects.Other.Instance'
|
||||
OBJECTS_OTHER_REVIT_REVITINSTANCE = 'Objects.Other.Revit.RevitInstance'
|
||||
OBJECTS_OTHER_BLOCKDEFINITION = 'Objects.Other.BlockDefinition'
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'converter'
|
||||
require_relative '../constants/type_constants'
|
||||
require_relative '../speckle_objects/other/transform'
|
||||
require_relative '../speckle_objects/other/render_material'
|
||||
require_relative '../speckle_objects/other/block_definition'
|
||||
require_relative '../speckle_objects/other/block_instance'
|
||||
require_relative '../speckle_objects/other/display_value'
|
||||
require_relative '../speckle_objects/other/revit/revit_instance'
|
||||
require_relative '../speckle_objects/geometry/point'
|
||||
require_relative '../speckle_objects/geometry/line'
|
||||
require_relative '../speckle_objects/geometry/mesh'
|
||||
require_relative '../speckle_objects/built_elements/view3d'
|
||||
|
||||
module SpeckleConnector
|
||||
module Converters
|
||||
@@ -38,6 +41,7 @@ module SpeckleConnector
|
||||
MESH = GEOMETRY::Mesh
|
||||
BLOCK_DEFINITION = OTHER::BlockDefinition
|
||||
BLOCK_INSTANCE = OTHER::BlockInstance
|
||||
REVIT_INSTANCE = OTHER::Revit::RevitInstance
|
||||
RENDER_MATERIAL = OTHER::RenderMaterial
|
||||
DISPLAY_VALUE = OTHER::DisplayValue
|
||||
|
||||
@@ -51,6 +55,7 @@ module SpeckleConnector
|
||||
Objects.Other.Revit.RevitInstance
|
||||
Objects.Other.BlockDefinition
|
||||
Objects.Other.RenderMaterial
|
||||
Objects.Other.Instance:Objects.Other.BlockInstance
|
||||
].freeze
|
||||
|
||||
def from_revit
|
||||
@@ -69,23 +74,61 @@ module SpeckleConnector
|
||||
# First create layers on the sketchup before starting traversing
|
||||
# @Named Views are exception here. It does not mean a layer. But it is anti-pattern for now.
|
||||
filtered_layer_containers = obj.keys.filter_map { |key| key if key.start_with?('@') && key != '@Named Views' }
|
||||
create_layers(filtered_layer_containers, sketchup_model.layers)
|
||||
create_views(obj.filter_map { |key, value| value if key == '@Named Views' }, sketchup_model)
|
||||
create_layers(filtered_layer_containers, sketchup_model.layers) unless from_revit
|
||||
# Convert views to sketchup scenes
|
||||
SpeckleObjects::BuiltElements::View3d.to_native(obj, sketchup_model)
|
||||
# Get default commit layer from sketchup model which will be used as fallback
|
||||
default_commit_layer = sketchup_model.layers.layers.find { |layer| layer.display_name == '@Untagged' }
|
||||
entities_to_fill = entities_to_fill(obj)
|
||||
traverse_commit_object(obj, sketchup_model.layers, default_commit_layer, entities_to_fill)
|
||||
@entities_to_fill = entities_to_fill(obj)
|
||||
traverse_commit_object(obj, sketchup_model.layers, default_commit_layer, @entities_to_fill)
|
||||
create_levels_from_section_planes
|
||||
check_hiding_layers_needed
|
||||
@state
|
||||
end
|
||||
|
||||
def levels_layer
|
||||
@levels_layer ||= sketchup_model.layers.add('Levels')
|
||||
end
|
||||
|
||||
# Create levels from section planes that already created for this commit object.
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def create_levels_from_section_planes
|
||||
return unless from_revit
|
||||
|
||||
section_planes = @entities_to_fill.grep(Sketchup::SectionPlane)
|
||||
bbox = @entities_to_fill.parent.bounds
|
||||
c_1 = bbox.corner(0)
|
||||
c_2 = bbox.corner(1)
|
||||
c_3 = bbox.corner(3)
|
||||
c_4 = bbox.corner(2)
|
||||
section_planes.each do |section_plane|
|
||||
level_name = "#{@definition_name}-#{section_plane.name}"
|
||||
definition = sketchup_model.definitions.add(level_name)
|
||||
@entities_to_fill.add_instance(definition, Geom::Transformation.new)
|
||||
elevation = section_plane.bounds.center.z
|
||||
c1_e = Geom::Point3d.new(c_1.x, c_1.y, elevation - LEVEL_SHIFT_VALUE)
|
||||
c2_e = Geom::Point3d.new(c_2.x, c_2.y, elevation - LEVEL_SHIFT_VALUE)
|
||||
c3_e = Geom::Point3d.new(c_3.x, c_3.y, elevation - LEVEL_SHIFT_VALUE)
|
||||
c4_e = Geom::Point3d.new(c_4.x, c_4.y, elevation - LEVEL_SHIFT_VALUE)
|
||||
cline_1 = definition.entities.add_cline(c1_e, c2_e)
|
||||
cline_2 = definition.entities.add_cline(c2_e, c3_e)
|
||||
cline_3 = definition.entities.add_cline(c3_e, c4_e)
|
||||
cline_4 = definition.entities.add_cline(c4_e, c1_e)
|
||||
text = definition.entities.add_text(" #{section_plane.name}", c1_e)
|
||||
[cline_1, cline_2, cline_3, cline_4, text, definition].each { |o| o.layer = levels_layer }
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def entities_to_fill(_obj)
|
||||
return sketchup_model.entities if from_sketchup
|
||||
|
||||
definition_name = "#{@stream_name}-#{@branch_name}"
|
||||
definition = sketchup_model.definitions.find { |d| d.name == definition_name }
|
||||
@definition_name = "#{@branch_name}-#{@stream_name}"
|
||||
definition = sketchup_model.definitions.find { |d| d.name == @definition_name }
|
||||
if definition.nil?
|
||||
definition = sketchup_model.definitions.add(definition_name)
|
||||
definition = sketchup_model.definitions.add(@definition_name)
|
||||
sketchup_model.entities.add_instance(definition, Geom::Transformation.new)
|
||||
end
|
||||
definition.entities
|
||||
@@ -103,7 +146,10 @@ module SpeckleConnector
|
||||
return unless from_revit
|
||||
|
||||
sketchup_model.layers.each do |layer|
|
||||
layer.visible = false if LAYERS_WILL_BE_HIDDEN.any? { |layer_name| layer.display_name.include?(layer_name) }
|
||||
if LAYERS_WILL_BE_HIDDEN.any? { |layer_name| layer.display_name.include?(layer_name) }
|
||||
layer.visible = false
|
||||
sketchup_model.pages.each { |page| page.update(PAGE_USE_LAYER_VISIBILITY) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -139,48 +185,6 @@ module SpeckleConnector
|
||||
create_folder_layers(folder_layer_arrays, folder)
|
||||
end
|
||||
|
||||
# @param views [Array] views.
|
||||
# @param sketchup_model [Sketchup::Model] active sketchup model.
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def create_views(views, sketchup_model)
|
||||
return if views.empty?
|
||||
|
||||
views.first.each do |view|
|
||||
origin = view['origin']
|
||||
target = view['target']
|
||||
origin = SpeckleObjects::Geometry::Point.to_native(origin['x'], origin['y'], origin['z'], origin['units'])
|
||||
target = SpeckleObjects::Geometry::Point.to_native(target['x'], target['y'], target['z'], target['units'])
|
||||
# Set camera position before creating scene on it.
|
||||
my_camera = Sketchup::Camera.new(origin, target, [0, 0, 1], !view['isOrthogonal'], view['lens'])
|
||||
sketchup_model.active_view.camera = my_camera
|
||||
sketchup_model.pages.add(view['name'])
|
||||
page = sketchup_model.pages[view['name']]
|
||||
set_page_update_properties(page, view['update_properties'])
|
||||
set_rendering_options(page.rendering_options, view['rendering_options'])
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
# @param page [Sketchup::Page] scene to update -update properties-
|
||||
def set_page_update_properties(page, update_properties)
|
||||
update_properties.each do |prop, value|
|
||||
page.instance_variable_set(:"@#{prop}", value)
|
||||
end
|
||||
end
|
||||
|
||||
# @param rendering_options [Sketchup::RenderingOptions] rendering options of scene (page)
|
||||
def set_rendering_options(rendering_options, speckle_rendering_options)
|
||||
speckle_rendering_options.each do |prop, value|
|
||||
next if rendering_options[prop].nil?
|
||||
|
||||
rendering_options[prop] = if value.is_a?(Hash)
|
||||
SpeckleObjects::Others::Color.to_native(value)
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# @param headless_layers [Array<String>] headless layer names.
|
||||
# @param folder [Sketchup::Layers, Sketchup::LayerFolder] layer folder to create commit layers under it.
|
||||
def create_headless_layers(headless_layers, folder)
|
||||
@@ -290,7 +294,8 @@ module SpeckleConnector
|
||||
OBJECTS_GEOMETRY_BREP => MESH.method(:to_native),
|
||||
OBJECTS_OTHER_BLOCKDEFINITION => BLOCK_DEFINITION.method(:to_native),
|
||||
OBJECTS_OTHER_BLOCKINSTANCE => BLOCK_INSTANCE.method(:to_native),
|
||||
OBJECTS_OTHER_REVIT_REVITINSTANCE => BLOCK_INSTANCE.method(:to_native),
|
||||
OBJECTS_OTHER_BLOCKINSTANCE_FULL => BLOCK_INSTANCE.method(:to_native),
|
||||
OBJECTS_OTHER_REVIT_REVITINSTANCE => REVIT_INSTANCE.method(:to_native),
|
||||
OBJECTS_OTHER_RENDERMATERIAL => RENDER_MATERIAL.method(:to_native)
|
||||
}.freeze
|
||||
|
||||
@@ -344,30 +349,29 @@ module SpeckleConnector
|
||||
return state unless speckle_object['level']['speckle_type'].include?('Objects.BuiltElements.Level')
|
||||
|
||||
level_name = speckle_object['level']['name'] || speckle_object['level']['id']
|
||||
entities = state.sketchup_state.sketchup_model.entities
|
||||
is_exist = entities.grep(Sketchup::SectionPlane).any? { |sp| sp.name == level_name }
|
||||
is_exist = @entities_to_fill.grep(Sketchup::SectionPlane).any? { |sp| sp.name == level_name }
|
||||
return state if is_exist
|
||||
|
||||
elevation = SpeckleObjects::Geometry.length_to_native(speckle_object['level']['elevation'],
|
||||
speckle_object['level']['units'])
|
||||
|
||||
shift_value = SpeckleObjects::Geometry.length_to_native(1.5, 'm')
|
||||
|
||||
section_plane = entities.add_section_plane([0, 0, elevation + shift_value], [0, 0, -1])
|
||||
section_plane = @entities_to_fill.add_section_plane([0, 0, elevation + LEVEL_SHIFT_VALUE], [0, 0, -1])
|
||||
section_plane.name = level_name
|
||||
state
|
||||
end
|
||||
|
||||
# @param state [States::State] state of the application
|
||||
def convert_to_speckle_entities(state, speckle_object, entities)
|
||||
return state unless state.user_state.user_preferences[:register_speckle_entity]
|
||||
|
||||
speckle_id = speckle_object['id']
|
||||
application_id = speckle_object['applicationId']
|
||||
speckle_type = speckle_object['speckle_type']
|
||||
children = speckle_object['__closure'].nil? ? [] : speckle_object['__closure']
|
||||
speckle_state = state.speckle_state
|
||||
entities.each do |entity|
|
||||
next if entity.is_a?(Sketchup::Material)
|
||||
next if (entity.is_a?(Sketchup::Face) || entity.is_a?(Sketchup::Edge)) &&
|
||||
!state.user_state.user_preferences[:register_speckle_entity]
|
||||
|
||||
ent = SpeckleEntities::SpeckleEntity.new(entity, speckle_id, application_id, speckle_type, children,
|
||||
[stream_id])
|
||||
ent.write_initial_base_data
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module SpeckleConnector
|
||||
# Operations related to {SketchupModel}.
|
||||
module SketchupModel
|
||||
# Works directly with/on SketchUp Entities of different kinds (Groups, Faces, Edges, ...).
|
||||
module Utils
|
||||
# Static methods to do plane calculations with sketchup geom objects like Point3d and Vector3d.
|
||||
class Plane
|
||||
ORTHOGONAL_TOLERANCE = 1e-5
|
||||
LENGTH_TOLERANCE = 1e-8
|
||||
|
||||
# Create plane from 3 points
|
||||
# @param origin [Geom::Point3d] the point on the plane that wil become the origin of the local coordinate system
|
||||
# @param point_1 [Geom::Point3d] the point that defines first direction
|
||||
# @param point_2 [Geom::Point3d] the third point on the plane
|
||||
# @return [Plane] the parametrization of the plane that goes through the given points
|
||||
def self.from_points(origin, point_1, point_2)
|
||||
direction_x = origin.vector_to(point_1).normalize
|
||||
direction_x = direction_x.normalize
|
||||
normal = direction_x.cross(origin.vector_to(point_2))
|
||||
direction_y = direction_x.cross(normal.normalize)
|
||||
new(origin: origin, direction_u: direction_x, direction_v: direction_y)
|
||||
end
|
||||
|
||||
# @return [Geom::Vector3d] the direction of the u-axis on the plane
|
||||
attr_reader :direction_u
|
||||
|
||||
# @return [Geom::Vector3d] the direction of the v-axis on the plane
|
||||
attr_reader :direction_v
|
||||
|
||||
# @return [Geom::Point3d] the origin of the local coordinate system on the plane
|
||||
attr_reader :origin
|
||||
|
||||
# @param origin [Geom::Point3d] the origin of the coordinate system on the plane
|
||||
# @param direction_u [Geom::Vector3d] the direction of the x-axis
|
||||
# @param direction_v [Geom::Vector3d] the direction of the y-axis
|
||||
def initialize(origin:, direction_u:, direction_v:)
|
||||
@origin = origin
|
||||
raise ArgumentError, 'directions must me orthogonal' if direction_u.dot(direction_v) > ORTHOGONAL_TOLERANCE
|
||||
raise ArgumentError, 'directions must be of length 1' if (direction_u.length - 1).abs > LENGTH_TOLERANCE
|
||||
raise ArgumentError, 'directions must be of length 1' if (direction_v.length - 1).abs > LENGTH_TOLERANCE
|
||||
|
||||
@direction_u = direction_u
|
||||
@direction_v = direction_v
|
||||
end
|
||||
|
||||
# Get the point object in global coordinates for the point on the plane with local coordinates (u,v).
|
||||
# @param coordinate_u [Float] the u-coordinate on the plane
|
||||
# @param coordinate_v [Float] the v-coordinate on the plane
|
||||
# @return [Geom::Point3d] the point in space that corresponds to the given (u, v) coordinates
|
||||
def point_at(coordinate_u, coordinate_v)
|
||||
scaled_direction_u = Geom::Vector3d.new(direction_u.x * coordinate_u,
|
||||
direction_u.y * coordinate_u,
|
||||
direction_u.z * coordinate_u)
|
||||
scaled_direction_v = Geom::Vector3d.new(direction_v.x * coordinate_v,
|
||||
direction_v.y * coordinate_v,
|
||||
direction_v.z * coordinate_v)
|
||||
origin + scaled_direction_u + scaled_direction_v
|
||||
end
|
||||
|
||||
# Find local (u, v) coordinates of the projection of the given point to the plane
|
||||
# @param point [Geom::Point3d] the point that will be projected to the plane
|
||||
# @return [(Float, Float)] the local coordinates on the plane that correspond to the projected point
|
||||
def plane_coordinates(point)
|
||||
origin_to_point = origin.vector_to(point)
|
||||
coordinate_u = origin_to_point.dot(direction_u)
|
||||
coordinate_v = origin_to_point.dot(direction_v)
|
||||
[coordinate_u, coordinate_v]
|
||||
end
|
||||
|
||||
# Project a given point to the plane
|
||||
# @param point [Geom::Point3d] the point that will be projected to the plane
|
||||
# @return [Geom::Point3d] the projected point on the plane
|
||||
def project_to_plane(point)
|
||||
coordinate_u, coordinate_v = plane_coordinates(point)
|
||||
point_at(coordinate_u, coordinate_v)
|
||||
end
|
||||
|
||||
# Check if the given point lies on the plane
|
||||
# @param point [Geom::Point3d] the point to check
|
||||
# @return [Boolean] whether the point lies on the plane
|
||||
def on_plane?(point)
|
||||
point.distance(project_to_plane(point)).to_m < LENGTH_TOLERANCE
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../base'
|
||||
require_relative '../../constants/type_constants'
|
||||
require_relative '../../speckle_objects/geometry/point'
|
||||
require_relative '../../speckle_objects/geometry/vector'
|
||||
|
||||
@@ -9,7 +10,7 @@ module SpeckleConnector
|
||||
module BuiltElements
|
||||
# View3d object represents scenes on Sketchup.
|
||||
class View3d < Base
|
||||
SPECKLE_TYPE = 'Objects.BuiltElements.View:Objects.BuiltElements.View3D'
|
||||
SPECKLE_TYPE = OBJECTS_BUILTELEMENTS_VIEW3D
|
||||
|
||||
# @param name [String] name of the scene
|
||||
# @param origin [SpeckleObjects::Geometry::Point] origin (eye) of the view.
|
||||
@@ -43,6 +44,75 @@ module SpeckleConnector
|
||||
self[:rendering_options] = rendering_options
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# @param obj [Hash] commit object.
|
||||
# @param sketchup_model [Sketchup::Model] active sketchup model.
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def self.to_native(obj, sketchup_model)
|
||||
views = collect_views(obj)
|
||||
return if views.empty?
|
||||
|
||||
views.each do |view|
|
||||
next unless view['speckle_type'] == 'Objects.BuiltElements.View:Objects.BuiltElements.View3D'
|
||||
|
||||
name = view['name'] || view['id']
|
||||
next if sketchup_model.pages.any? { |page| page.name == name }
|
||||
|
||||
origin = view['origin']
|
||||
target = view['target']
|
||||
lens = view['lens'] || 50
|
||||
origin = SpeckleObjects::Geometry::Point.to_native(origin['x'], origin['y'], origin['z'], origin['units'])
|
||||
target = SpeckleObjects::Geometry::Point.to_native(target['x'], target['y'], target['z'], target['units'])
|
||||
# Set camera position before creating scene on it.
|
||||
my_camera = Sketchup::Camera.new(origin, target, [0, 0, 1], !view['isOrthogonal'], lens)
|
||||
sketchup_model.active_view.camera = my_camera
|
||||
sketchup_model.pages.add(name)
|
||||
page = sketchup_model.pages[name]
|
||||
set_page_update_properties(page, view['update_properties']) if view['update_properties']
|
||||
set_rendering_options(page.rendering_options, view['rendering_options']) if view['rendering_options']
|
||||
rescue StandardError => e
|
||||
puts("Failed to convert view (name: #{name})")
|
||||
puts(e)
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
# @param page [Sketchup::Page] scene to update -update properties-
|
||||
def self.set_page_update_properties(page, update_properties)
|
||||
update_properties.each do |prop, value|
|
||||
page.instance_variable_set(:"@#{prop}", value)
|
||||
end
|
||||
end
|
||||
|
||||
# @param rendering_options [Sketchup::RenderingOptions] rendering options of scene (page)
|
||||
def self.set_rendering_options(rendering_options, speckle_rendering_options)
|
||||
speckle_rendering_options.each do |prop, value|
|
||||
next if rendering_options[prop].nil?
|
||||
|
||||
rendering_options[prop] = if value.is_a?(Hash)
|
||||
SpeckleObjects::Others::Color.to_native(value)
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.collect_views(obj)
|
||||
views = []
|
||||
views += obj.filter_map do |_key, value|
|
||||
if value.is_a?(Array) &&
|
||||
value.any? { |v| v['speckle_type'] == OBJECTS_BUILTELEMENTS_VIEW3D }
|
||||
value
|
||||
end
|
||||
end
|
||||
views.flatten.select { |view| view['speckle_type'] == OBJECTS_BUILTELEMENTS_VIEW3D }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ require_relative '../geometry/bounding_box'
|
||||
require_relative '../other/render_material'
|
||||
require_relative '../../convertors/clean_up'
|
||||
require_relative '../../sketchup_model/dictionary/dictionary_handler'
|
||||
require_relative '../../sketchup_model/utils/plane_utils'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
@@ -48,6 +49,25 @@ module SpeckleConnector
|
||||
end
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
# Checks 4 points are planar or not.
|
||||
def self.check_4_points_planar(points)
|
||||
plane = SketchupModel::Utils::Plane.from_points(points[0], points[1], points[2])
|
||||
plane.on_plane?(points[3])
|
||||
end
|
||||
|
||||
# Add quad mesh to sketchup native mesh by checking planarity.
|
||||
# @param native_mesh [Geom::Mesh] sketchup mesh to convert them later faces.
|
||||
# @param polygon_points [Array<Geom::Point3d>] sketchup points to add them with polygon to mesh.
|
||||
def self.add_quad_mesh(native_mesh, polygon_points)
|
||||
is_planar = check_4_points_planar(polygon_points)
|
||||
if is_planar
|
||||
native_mesh.add_polygon(polygon_points)
|
||||
else
|
||||
native_mesh.add_polygon([polygon_points[0], polygon_points[1], polygon_points[2]])
|
||||
native_mesh.add_polygon([polygon_points[0], polygon_points[2], polygon_points[3]])
|
||||
end
|
||||
end
|
||||
|
||||
# @param entities [Sketchup::Entities] entities to add
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
@@ -68,7 +88,13 @@ module SpeckleConnector
|
||||
# 0 -> 3, 1 -> 4 to preserve backwards compatibility
|
||||
num_pts += 3 if num_pts < 3
|
||||
indices = faces.shift(num_pts)
|
||||
native_mesh.add_polygon(indices.map { |index| points[index] })
|
||||
polygon_points = indices.map { |index| points[index] }
|
||||
# Quad mesh
|
||||
if num_pts == 4
|
||||
add_quad_mesh(native_mesh, polygon_points)
|
||||
else
|
||||
native_mesh.add_polygon(polygon_points)
|
||||
end
|
||||
end
|
||||
state, _materials = Other::RenderMaterial.to_native(state, mesh['renderMaterial'],
|
||||
layer, entities, &convert_to_native)
|
||||
@@ -84,6 +110,8 @@ module SpeckleConnector
|
||||
added_faces = entities.grep(Sketchup::Face).last(native_mesh.polygons.length)
|
||||
added_faces.each do |face|
|
||||
face.layer = layer
|
||||
# Smooth edges if they already soft
|
||||
face.edges.each { |edge| edge.smooth = true if edge.soft? }
|
||||
unless mesh['sketchup_attributes'].nil?
|
||||
SketchupModel::Dictionary::DictionaryHandler
|
||||
.attribute_dictionaries_to_native(face, mesh['sketchup_attributes']['dictionaries'])
|
||||
@@ -199,13 +227,13 @@ module SpeckleConnector
|
||||
end
|
||||
end
|
||||
|
||||
DEFINITIONS_WILL_BE_SOFT_EDGE = %w[
|
||||
Furniture
|
||||
Topography
|
||||
Column
|
||||
Lighting Fixtures
|
||||
Railings
|
||||
Roofs
|
||||
DEFINITIONS_WILL_BE_HARD_EDGE = %w[
|
||||
Walls
|
||||
Floors
|
||||
Stairs
|
||||
Structural Foundations
|
||||
Doors
|
||||
Windows
|
||||
].freeze
|
||||
|
||||
# @param mesh [Object] speckle mesh object
|
||||
@@ -215,7 +243,7 @@ module SpeckleConnector
|
||||
return mesh['sketchup_attributes']['is_soften'].nil? ? true : mesh['sketchup_attributes']['is_soften']
|
||||
end
|
||||
|
||||
return DEFINITIONS_WILL_BE_SOFT_EDGE.any? { |def_name| entities.parent.name.include?(def_name) }
|
||||
return DEFINITIONS_WILL_BE_HARD_EDGE.none? { |def_name| entities.parent.name.include?(def_name) }
|
||||
end
|
||||
|
||||
def self.get_native_points(mesh)
|
||||
|
||||
@@ -100,40 +100,8 @@ module SpeckleConnector
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
|
||||
def self.built_element?(definition_object)
|
||||
definition_object['speckle_type'].include?('Objects.BuiltElements')
|
||||
end
|
||||
|
||||
def self.unique_element?(definition_object)
|
||||
UNIQUE_DEFINITIONS.any? { |d| definition_object['speckle_type'].include?(d) }
|
||||
end
|
||||
|
||||
UNIQUE_DEFINITIONS = %w[
|
||||
Objects.BuiltElements.Wall
|
||||
Objects.BuiltElements.Floor
|
||||
Objects.BuiltElements.Ceiling
|
||||
Objects.BuiltElements.Column
|
||||
Objects.BuiltElements.Beam
|
||||
Objects.BuiltElements.Roof
|
||||
Objects.BuiltElements.Room
|
||||
Objects.BuiltElements.Topography
|
||||
].freeze
|
||||
|
||||
def self.get_definition_name(def_obj)
|
||||
return def_obj['name'] if !def_obj['name'].nil? && !def_obj['is_sketchup_group'].nil?
|
||||
|
||||
family = def_obj['family']
|
||||
type = def_obj['type']
|
||||
category = def_obj['category']
|
||||
|
||||
# Check unique elements when instancing implemented to add it with element id.
|
||||
if built_element?(def_obj) && unique_element?(def_obj)
|
||||
element_id = def_obj['elementId']
|
||||
|
||||
return "#{family}-#{type}-#{category}-#{element_id}"
|
||||
end
|
||||
|
||||
return "#{family}-#{type}-#{category}" if built_element?(def_obj)
|
||||
return def_obj['name'] unless def_obj['name'].nil?
|
||||
|
||||
return "def::#{def_obj['applicationId']}"
|
||||
end
|
||||
|
||||
@@ -108,10 +108,6 @@ module SpeckleConnector
|
||||
# @param block [Object] block object that represents Speckle block.
|
||||
# @param layer [Sketchup::Layer] layer to add {Sketchup::Edge} into it.
|
||||
# @param entities [Sketchup::Entities] entities collection to add {Sketchup::Edge} into it.
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
def self.to_native(state, block, layer, entities, &convert_to_native)
|
||||
# is_group = block.key?("is_sketchup_group") && block["is_sketchup_group"]
|
||||
# something about this conversion is freaking out if nested block geo is a group
|
||||
@@ -132,6 +128,42 @@ module SpeckleConnector
|
||||
definition = state.sketchup_state.sketchup_model
|
||||
.definitions[BlockDefinition.get_definition_name(block_definition)]
|
||||
|
||||
return add_instance_from_definition(state, block, layer, entities, definition, is_group, &convert_to_native)
|
||||
end
|
||||
|
||||
def self.get_transform_matrix(block)
|
||||
if block['transform'].is_a?(Hash)
|
||||
block['transform']['matrix'] || block['transform']['value']
|
||||
else
|
||||
block['transform']
|
||||
end
|
||||
end
|
||||
|
||||
# takes a component definition and finds and erases the first instance with the matching name
|
||||
# (and optionally the applicationId)
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.find_and_erase_existing_instance(definition, upcoming_speckle_id, upcoming_app_id = '')
|
||||
definition.instances.find do |ins|
|
||||
next if ins.attribute_dictionaries.nil?
|
||||
next if ins.attribute_dictionaries.to_a.empty?
|
||||
next if ins.attribute_dictionaries.to_a.none? { |dict| dict.name == SPECKLE_BASE_OBJECT }
|
||||
|
||||
dict = ins.attribute_dictionaries.to_a.find { |d| d.name == SPECKLE_BASE_OBJECT }
|
||||
speckle_id = dict[:speckle_id]
|
||||
application_id = dict[:application_id]
|
||||
speckle_id == upcoming_speckle_id || application_id == upcoming_app_id
|
||||
end&.erase!
|
||||
end
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/ParameterLists
|
||||
def self.add_instance_from_definition(state, block, layer, entities, definition, is_group, &convert_to_native)
|
||||
t_arr = get_transform_matrix(block)
|
||||
transform = Other::Transform.to_native(t_arr, block['units'])
|
||||
instance = if is_group
|
||||
@@ -173,33 +205,7 @@ module SpeckleConnector
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
def self.get_transform_matrix(block)
|
||||
if block['transform'].is_a?(Hash)
|
||||
block['transform']['matrix'] || block['transform']['value']
|
||||
else
|
||||
block['transform']
|
||||
end
|
||||
end
|
||||
|
||||
# takes a component definition and finds and erases the first instance with the matching name
|
||||
# (and optionally the applicationId)
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def self.find_and_erase_existing_instance(definition, upcoming_speckle_id, upcoming_app_id = '')
|
||||
definition.instances.find do |ins|
|
||||
next if ins.attribute_dictionaries.nil?
|
||||
next if ins.attribute_dictionaries.to_a.empty?
|
||||
next if ins.attribute_dictionaries.to_a.none? { |dict| dict.name == SPECKLE_BASE_OBJECT }
|
||||
|
||||
dict = ins.attribute_dictionaries.to_a.find { |d| d.name == SPECKLE_BASE_OBJECT }
|
||||
speckle_id = dict[:speckle_id]
|
||||
application_id = dict[:application_id]
|
||||
speckle_id == upcoming_speckle_id || application_id == upcoming_app_id
|
||||
end&.erase!
|
||||
end
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/ParameterLists
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,11 +14,37 @@ module SpeckleConnector
|
||||
module Other
|
||||
# DisplayValue object definition for Speckle that represents as BlockInstance in Sketchup.
|
||||
class DisplayValue
|
||||
def self.get_definition_name(def_obj)
|
||||
family = def_obj['family']
|
||||
type = def_obj['type']
|
||||
category = def_obj['category']
|
||||
element_id = def_obj['elementId']
|
||||
|
||||
return format_naming_convention([family, type, category, element_id]) unless element_id.nil?
|
||||
|
||||
return "def::#{def_obj['applicationId']}"
|
||||
end
|
||||
|
||||
def self.format_naming_convention(entries)
|
||||
name = ''
|
||||
entries.each_with_index do |entry, index|
|
||||
next if entry.nil?
|
||||
|
||||
name += if index == entries.length - 1
|
||||
entry.to_s
|
||||
else
|
||||
"#{entry}-"
|
||||
end
|
||||
end
|
||||
name
|
||||
end
|
||||
|
||||
# Creates a component definition and instance from a speckle object with a display value
|
||||
# @param state [States::State] state of the application.
|
||||
def self.to_native(state, obj, layer, entities, &convert_to_native)
|
||||
# Switch displayValue with geometry
|
||||
obj = collect_definition_geometries(obj)
|
||||
obj['name'] = get_definition_name(obj)
|
||||
|
||||
state, _definitions = BlockDefinition.to_native(
|
||||
state,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../block_definition'
|
||||
require_relative '../../base'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Other
|
||||
module Revit
|
||||
# RevitDefinition for Speckle.
|
||||
class RevitDefinition < Base
|
||||
SPECKLE_TYPE = OBJECTS_OTHER_REVIT_REVITINSTANCE
|
||||
|
||||
def self.get_definition_name(def_obj)
|
||||
family = def_obj['family']
|
||||
type = def_obj['type']
|
||||
category = def_obj['category']
|
||||
|
||||
return "#{family}-#{type}-#{category}-#{def_obj['id']}"
|
||||
end
|
||||
|
||||
def self.to_native(state, definition, layer, entities, &convert_to_native)
|
||||
definition_name = get_definition_name(definition)
|
||||
definition['name'] = definition_name
|
||||
definition['displayValue'] += definition['elements'] unless definition['elements'].nil?
|
||||
BlockDefinition.to_native(state, definition, layer, entities, &convert_to_native)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'revit_definition'
|
||||
require_relative '../render_material'
|
||||
require_relative '../transform'
|
||||
require_relative '../block_definition'
|
||||
require_relative '../../base'
|
||||
require_relative '../../geometry/bounding_box'
|
||||
require_relative '../../../sketchup_model/dictionary/dictionary_handler'
|
||||
|
||||
module SpeckleConnector
|
||||
module SpeckleObjects
|
||||
module Other
|
||||
module Revit
|
||||
# RevitInstance object definition for Speckle.
|
||||
class RevitInstance < Base
|
||||
SPECKLE_TYPE = OBJECTS_OTHER_REVIT_REVITINSTANCE
|
||||
|
||||
# Creates a component instance from a block
|
||||
# @param state [States::State] state of the application.
|
||||
# @param block [Object] block object that represents Speckle block.
|
||||
# @param layer [Sketchup::Layer] layer to add {Sketchup::Edge} into it.
|
||||
# @param entities [Sketchup::Entities] entities collection to add {Sketchup::Edge} into it.
|
||||
def self.to_native(state, block, layer, entities, &convert_to_native)
|
||||
block_definition = block['definition']
|
||||
|
||||
state, _definitions = RevitDefinition.to_native(
|
||||
state,
|
||||
block_definition,
|
||||
layer,
|
||||
entities,
|
||||
&convert_to_native
|
||||
)
|
||||
|
||||
definition = state.sketchup_state.sketchup_model
|
||||
.definitions[RevitDefinition.get_definition_name(block_definition)]
|
||||
|
||||
return BlockInstance.add_instance_from_definition(state, block, layer, entities,
|
||||
definition, false, &convert_to_native)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,8 +11,7 @@ module SpeckleConnector
|
||||
|
||||
# @param units [String] units of the transform.
|
||||
# @param value [Array<Numeric>] values of the transform.
|
||||
# @param sketchup_attributes [Other::BlockDefinition] sketchup attributes of the transform.
|
||||
def initialize(units:, value:, sketchup_attributes: {})
|
||||
def initialize(units:, value:)
|
||||
super(
|
||||
speckle_type: SPECKLE_TYPE,
|
||||
total_children_count: 0,
|
||||
@@ -21,7 +20,6 @@ module SpeckleConnector
|
||||
)
|
||||
self[:units] = units
|
||||
self[:value] = value
|
||||
self[:sketchup_attributes] = sketchup_attributes
|
||||
end
|
||||
|
||||
def self.from_transformation(transformation, units)
|
||||
|
||||
@@ -161,6 +161,7 @@ import gql from 'graphql-tag'
|
||||
import { bus } from '../main'
|
||||
import streamQuery from '../graphql/stream.gql'
|
||||
import ObjectLoader from '@speckle/objectloader'
|
||||
import {HostApplications} from '@/utils/hostApplications'
|
||||
|
||||
global.convertedFromSketchup = function (streamId, batches, commitId, totalChildrenCount) {
|
||||
bus.$emit(`sketchup-objects-${streamId}`, batches, commitId, totalChildrenCount)
|
||||
@@ -376,7 +377,11 @@ export default {
|
||||
async receive() {
|
||||
this.loadingStage = 'requesting'
|
||||
this.loadingReceive = true
|
||||
this.$mixpanel.track('Receive')
|
||||
const selectedAccount = JSON.parse(localStorage.getItem('selectedAccount'))
|
||||
const isMultiplayer = this.selectedCommit.authorId !== selectedAccount['userInfo']['id']
|
||||
const sourceApp = this.selectedCommit.sourceApplication
|
||||
const sourceAppSlug = HostApplications.GetHostAppFromString(sourceApp).slug
|
||||
this.$mixpanel.track('Receive', { isMultiplayer: isMultiplayer, sourceHostApp: sourceAppSlug, sourceHostAppVersion: sourceApp})
|
||||
const refId = this.selectedCommit?.referencedObject
|
||||
if (!refId) {
|
||||
this.loadingReceive = false
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
class HostApplication {
|
||||
constructor(name, slug) {
|
||||
this.name = name;
|
||||
this.slug = slug;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Static class to retrieve host application names and their shortened name(slug).
|
||||
* Call HostApplications.GetHostAppFromString(appname) method to get name and slug.
|
||||
* @example
|
||||
* const hostApp = HostApplications.GetHostAppFromString("Revit2022")
|
||||
* console.log(hostApp.name) -> "Revit"
|
||||
* console.log(hostApp.slug) -> "revit"
|
||||
*/
|
||||
export class HostApplications {
|
||||
static Rhino = new HostApplication("Rhino", "rhino");
|
||||
static Grasshopper = new HostApplication("Grasshopper", "grasshopper");
|
||||
static Revit = new HostApplication("Revit", "revit");
|
||||
static Dynamo = new HostApplication("Dynamo", "dynamo");
|
||||
static Unity = new HostApplication("Unity", "unity");
|
||||
static GSA = new HostApplication("GSA", "gsa");
|
||||
static Civil = new HostApplication("Civil 3D", "civil3d");
|
||||
static AutoCAD = new HostApplication("AutoCAD", "autocad");
|
||||
static MicroStation = new HostApplication("MicroStation", "microstation");
|
||||
static OpenRoads = new HostApplication("OpenRoads", "openroads");
|
||||
static OpenRail = new HostApplication("OpenRail", "openrail");
|
||||
static OpenBuildings = new HostApplication("OpenBuildings", "openbuildings");
|
||||
static ETABS = new HostApplication("ETABS", "etabs");
|
||||
static SAP2000 = new HostApplication("SAP2000", "sap2000");
|
||||
static CSIBridge = new HostApplication("CSIBridge", "csibridge");
|
||||
static SAFE = new HostApplication("SAFE", "safe");
|
||||
static TeklaStructures = new HostApplication("Tekla Structures", "teklastructures");
|
||||
static Dxf = new HostApplication("DXF Converter", "dxf");
|
||||
static Excel = new HostApplication("Excel", "excel");
|
||||
static Unreal = new HostApplication("Unreal", "unreal");
|
||||
static PowerBI = new HostApplication("Power BI", "powerbi");
|
||||
static Blender = new HostApplication("Blender", "blender");
|
||||
static QGIS = new HostApplication("QGIS", "qgis");
|
||||
static ArcGIS = new HostApplication("ArcGIS", "arcgis");
|
||||
static SketchUp = new HostApplication("SketchUp", "sketchup");
|
||||
static Archicad = new HostApplication("Archicad", "archicad");
|
||||
static TopSolid = new HostApplication("TopSolid", "topsolid");
|
||||
static Python = new HostApplication("Python", "python");
|
||||
static NET = new HostApplication(".NET", "net");
|
||||
static Navisworks = new HostApplication("Navisworks", "navisworks");
|
||||
static AdvanceSteel = new HostApplication("Advance Steel", "advancesteel");
|
||||
static Other = new HostApplication("Other", "other");
|
||||
|
||||
static GetHostAppFromString(appname){
|
||||
if (!appname) return HostApplications.Other;
|
||||
appname = appname.toLowerCase().replace(/ /g, "");
|
||||
if (appname.includes("dynamo")) return HostApplications.Dynamo;
|
||||
if (appname.includes("revit")) return HostApplications.Revit;
|
||||
if (appname.includes("autocad")) return HostApplications.AutoCAD;
|
||||
if (appname.includes("civil")) return HostApplications.Civil;
|
||||
if (appname.includes("rhino")) return HostApplications.Rhino;
|
||||
if (appname.includes("grasshopper")) return HostApplications.Grasshopper;
|
||||
if (appname.includes("unity")) return HostApplications.Unity;
|
||||
if (appname.includes("gsa")) return HostApplications.GSA;
|
||||
if (appname.includes("microstation")) return HostApplications.MicroStation;
|
||||
if (appname.includes("openroads")) return HostApplications.OpenRoads;
|
||||
if (appname.includes("openrail")) return HostApplications.OpenRail;
|
||||
if (appname.includes("openbuildings")) return HostApplications.OpenBuildings;
|
||||
if (appname.includes("etabs")) return HostApplications.ETABS;
|
||||
if (appname.includes("sap")) return HostApplications.SAP2000;
|
||||
if (appname.includes("csibridge")) return HostApplications.CSIBridge;
|
||||
if (appname.includes("safe")) return HostApplications.SAFE;
|
||||
if (appname.includes("teklastructures")) return HostApplications.TeklaStructures;
|
||||
if (appname.includes("dxf")) return HostApplications.Dxf;
|
||||
if (appname.includes("excel")) return HostApplications.Excel;
|
||||
if (appname.includes("unreal")) return HostApplications.Unreal;
|
||||
if (appname.includes("powerbi")) return HostApplications.PowerBI;
|
||||
if (appname.includes("blender")) return HostApplications.Blender;
|
||||
if (appname.includes("qgis")) return HostApplications.QGIS;
|
||||
if (appname.includes("arcgis")) return HostApplications.ArcGIS;
|
||||
if (appname.includes("sketchup")) return HostApplications.SketchUp;
|
||||
if (appname.includes("archicad")) return HostApplications.Archicad;
|
||||
if (appname.includes("topsolid")) return HostApplications.TopSolid;
|
||||
if (appname.includes("python")) return HostApplications.Python;
|
||||
if (appname.includes(".net")) return HostApplications.NET;
|
||||
if (appname.includes("navisworks")) return HostApplications.Navisworks;
|
||||
if (appname.includes("advancesteel")) return HostApplications.AdvanceSteel;
|
||||
return appname;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user