Compare commits

...

51 Commits

Author SHA1 Message Date
Oğuzhan Koral e3dceec63c Fix (Plane): Remove orthogonality checks 2023-05-01 19:09:27 +03:00
oguzhankoral e9d34d87cc Remove orthogonality checks 2023-05-01 19:06:16 +03:00
Oğuzhan Koral 5187fded02 Fix (Mesh): Non-planar quad mesh support 2023-05-01 18:08:11 +03:00
oguzhankoral 370825838a Add plane_utils to calculate planarity of 4 points for quad meshes 2023-05-01 17:56:28 +03:00
oguzhankoral bc8eece488 Split all quad meshes 2023-04-28 12:23:16 +01:00
Oğuzhan Koral 4222b1721d Fix (Views): Bug on views recieve 2023-04-12 13:39:01 +03:00
oguzhankoral b475bc96af Disable rubocop for to_native 2023-04-12 13:36:49 +03:00
oguzhankoral f9ac7319ae Fix bug on views recieve 2023-04-12 13:34:09 +03:00
Oğuzhan Koral 2ce3e9150f Release 2.13 2023-03-24 18:08:26 +03:00
Oğuzhan Koral 8e39832d3e Fix (Instancing): Definition uniqueness for mirrored definitions 2023-03-20 22:14:10 +03:00
oguzhankoral ce7ac6da16 Create definitions with it's id 2023-03-20 22:11:52 +03:00
oguzhankoral 57879a57cd Enable conversion for full assembly name block instance 2023-03-20 22:05:42 +03:00
Oğuzhan Koral 6f5b367028 Fix (Revit): Do not create layers in advance for revit receives 2023-03-20 13:04:42 +03:00
oguzhankoral 291948c1ef Do not create layers in advance for revit receives 2023-03-20 12:57:26 +03:00
Oğuzhan Koral 0ca6888fb1 Fix (Instancing): Support nested families re-fix 2023-03-20 10:56:50 +03:00
oguzhankoral 5e92236396 Remove skp attributes from transform 2023-03-20 10:45:45 +03:00
oguzhankoral 28db40112b Collect revit elements also into displayValue to handle later 2023-03-20 10:45:13 +03:00
Oğuzhan Koral b2153883ef Revert "Fix (Instancing): Support nested families" 2023-03-16 18:28:44 +03:00
Oğuzhan Koral 807cbeb75d Revert "Fix (Instancing): Support nested families" 2023-03-16 18:28:14 +03:00
Oğuzhan Koral 4730aebdc6 Fix (Instancing): Support nested families 2023-03-16 18:06:50 +03:00
oguzhankoral c2279eec87 Add elements of revit_definition to display value to handle all 2023-03-16 18:03:21 +03:00
Oğuzhan Koral f5567ae9ad Chore (Mixpanel): Send isMultiplayer parameter with Receive action 2023-03-16 11:50:45 +03:00
oguzhankoral 2fcba04cf5 Pass sourceHostApp with slug and sourceHostAppVersion full info on commit
For "Revit2022",
sourceHostApp: "revit"
sourceHostAppVersion: "Revit2022"
2023-03-16 11:13:49 +03:00
oguzhankoral 0eefd1605f Add static HostApplication instances per connector
- This helps to retrieve name and slug of the connector
2023-03-16 11:12:29 +03:00
oguzhankoral 7b88ea022d Send isMultiplayer parameter with Receive action 2023-03-15 12:35:57 +03:00
Oğuzhan Koral 7a922114ab Fix (Instancing): Split revit instance from block instance 2023-03-14 21:18:22 +03:00
oguzhankoral f717c270fd Collect views according to speckle_type 2023-03-14 21:16:56 +03:00
oguzhankoral ee5ed468c3 Fix rubocop issues 2023-03-14 20:18:28 +03:00
oguzhankoral a9ded445a7 Separate revit instance from block instance 2023-03-14 20:08:02 +03:00
oguzhankoral 9ecad52df2 Dont create speckle entity for sketchup materials 2023-03-14 17:48:20 +03:00
oguzhankoral 8c500985bf Flip soft edge check with hard edge 2023-03-14 16:37:16 +03:00
Oğuzhan Koral 3567f9ba5d Fix (Layers): Update level object's layer to Levels 2023-03-14 14:42:01 +03:00
oguzhankoral 852bfb716c Update level object's layer to Levels 2023-03-14 14:39:19 +03:00
Oğuzhan Koral 473956aa3c Fix (Update): Update behavior 2023-03-14 11:33:25 +03:00
oguzhankoral b22fc19400 Register component and groups by default for update behavior 2023-03-14 11:31:17 +03:00
oguzhankoral f6a8ece992 Check existing scene names to prevent duplications 2023-03-14 11:28:28 +03:00
oguzhankoral afc0c21aae Swap branch and stream name for commit obj 2023-03-14 11:10:05 +03:00
Oğuzhan Koral 08e6106c1f Fix (Levels): Levels should be visible 2023-03-13 14:20:01 +03:00
oguzhankoral 1f9f654e3d Add levels as cline 2023-03-13 14:11:10 +03:00
oguzhankoral 501e923760 Add section planes into received component
By this way these section planes will be active only in this commit objects
2023-03-13 09:58:32 +03:00
Oğuzhan Koral 37b716cfc5 Feat (Scene): Create scenes from revit views 2023-03-12 23:46:14 +03:00
oguzhankoral 8584db0ab5 Create scenes from revit views 2023-03-12 23:41:00 +03:00
Oğuzhan Koral 5aff3e9692 Feat (Instancing): Definition naming convention 2023-03-10 18:06:48 +03:00
oguzhankoral 5d8f03cbc3 Fix rubocop suggestions 2023-03-10 18:04:14 +03:00
oguzhankoral b6c85ac15a Group received objects with branch and stream name 2023-03-10 17:57:43 +03:00
oguzhankoral c2af757f4e Collect received objects under component 2023-03-10 16:08:17 +03:00
oguzhankoral 26252c55ac Pass branch and stream name to to_native converter 2023-03-10 16:07:34 +03:00
oguzhankoral 3ce547bcea Update naming convention 2023-03-09 19:04:01 +03:00
oguzhankoral e0492f589e Update will be soften list 2023-03-09 19:03:49 +03:00
oguzhankoral 4931288ffd Update will be hidden layers list 2023-03-09 19:03:26 +03:00
oguzhankoral 52e0f77a3c Remove category from definition names 2023-03-09 16:12:47 +03:00
18 changed files with 530 additions and 149 deletions
@@ -23,7 +23,7 @@ module SpeckleConnector
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
# @return [States::State] the new updated state object
def update_state(state)
converter = Converters::ToNative.new(state, @stream_id, @source_app)
converter = Converters::ToNative.new(state, @stream_id, @stream_name, @branch_name, @source_app)
# Have side effects on the sketchup model. It effects directly on the entities by adding new objects.
start_time = Time.now.to_f
state = converter.receive_commit_object(@base)
@@ -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'
@@ -352,7 +352,8 @@ module SpeckleConnector
speckle_state.speckle_entities[entity.persistent_id].with_valid_stream_id(stream_id)
else
children = traversed_base[:__closure].nil? ? {} : traversed_base[:__closure]
speckle_entity = SpeckleEntities::SpeckleEntity.new(entity, id, traversed_base[:speckle_type],
speckle_entity = SpeckleEntities::SpeckleEntity.new(entity, id, entity.persistent_id,
traversed_base[:speckle_type],
children.keys, [stream_id])
speckle_entity.write_initial_base_data
speckle_entity
+90 -63
View File
@@ -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
@@ -21,8 +24,10 @@ module SpeckleConnector
# @return [String] source application of received object that will be converted to native
attr_reader :source_app
def initialize(state, stream_id, source_app)
def initialize(state, stream_id, stream_name, branch_name, source_app)
super(state, stream_id)
@stream_name = stream_name
@branch_name = branch_name
@source_app = source_app.downcase
end
@@ -36,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
@@ -49,12 +55,17 @@ module SpeckleConnector
Objects.Other.Revit.RevitInstance
Objects.Other.BlockDefinition
Objects.Other.RenderMaterial
Objects.Other.Instance:Objects.Other.BlockInstance
].freeze
def from_revit
@from_revit ||= source_app.include?('revit')
end
def from_sketchup
@from_sketchup ||= source_app.include?('sketchup')
end
# ReceiveObjects action call this method by giving everything that comes from server.
# Upcoming object is a referencedObject of selected commit to receive.
# UI is responsible currently to fetch objects from ObjectLoader module by calling getAndConstruct method.
@@ -63,26 +74,82 @@ 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' }
traverse_commit_object(obj, sketchup_model.layers, default_commit_layer)
@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 = "#{@branch_name}-#{@stream_name}"
definition = sketchup_model.definitions.find { |d| d.name == @definition_name }
if definition.nil?
definition = sketchup_model.definitions.add(@definition_name)
sketchup_model.entities.add_instance(definition, Geom::Transformation.new)
end
definition.entities
end
LAYERS_WILL_BE_HIDDEN = [
'Rooms',
'Mass',
'Mass Floor'
'Mass Floor',
'Grid',
'Shaft Openings'
].freeze
def check_hiding_layers_needed
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
@@ -118,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)
@@ -197,9 +222,9 @@ module SpeckleConnector
# self-caller method means that call itself according to conditions inside of it.
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def traverse_commit_object(obj, commit_folder, layer)
def traverse_commit_object(obj, commit_folder, layer, entities)
if convertible_to_native?(obj)
@state = convert_to_native(@state, obj, layer)
@state = convert_to_native(@state, obj, layer, entities)
elsif obj.is_a?(Hash) && obj.key?('speckle_type')
return if ignored_speckle_type?(obj)
@@ -209,16 +234,16 @@ module SpeckleConnector
props.each do |prop|
layer_path = prop if prop.start_with?('@') && obj[prop].is_a?(Array)
layer = find_layer(layer_path, commit_folder, layer)
traverse_commit_object(obj[prop], commit_folder, layer)
traverse_commit_object(obj[prop], commit_folder, layer, entities)
end
else
# puts(">>> Found #{obj['speckle_type']}: #{obj['id']} with displayValue.")
@state = convert_to_native(@state, obj, layer)
@state = convert_to_native(@state, obj, layer, entities)
end
elsif obj.is_a?(Hash)
obj.each_value { |value| traverse_commit_object(value, commit_folder, layer) }
obj.each_value { |value| traverse_commit_object(value, commit_folder, layer, entities) }
elsif obj.is_a?(Array)
obj.each { |value| traverse_commit_object(value, commit_folder, layer) }
obj.each { |value| traverse_commit_object(value, commit_folder, layer, entities) }
end
end
# rubocop:enable Metrics/CyclomaticComplexity
@@ -269,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
@@ -323,30 +349,31 @@ 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|
ent = SpeckleEntities::SpeckleEntity.new(entity, speckle_id, speckle_type, children, [stream_id])
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
speckle_state = speckle_state.with_speckle_entity(ent)
end
@@ -30,11 +30,12 @@ module SpeckleConnector
def self.read_speckle_entity(entity)
dict = entity.attribute_dictionaries.to_a.find { |d| d.name == SPECKLE_BASE_OBJECT }
speckle_id = dict[:speckle_id]
application_id = dict[:application_id]
speckle_type = dict[:speckle_type]
children = dict[:children]
valid_stream_ids = dict[:valid_stream_ids]
invalid_stream_ids = dict[:invalid_stream_ids]
SpeckleEntities::SpeckleEntity.new(entity, speckle_id, speckle_type, children,
SpeckleEntities::SpeckleEntity.new(entity, speckle_id, application_id, speckle_type, children,
valid_stream_ids, invalid_stream_ids)
end
@@ -0,0 +1,84 @@
# 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
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
@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
@@ -41,14 +41,15 @@ module SpeckleConnector
# @param sketchup_entity [Sketchup::Entity] sketchup entity represents {SpeckleEntity} on the model.
# rubocop:disable Metrics/ParameterLists
def initialize(sketchup_entity, speckle_id, speckle_type, children, valid_stream_ids, invalid_stream_ids = [])
def initialize(sketchup_entity, speckle_id, application_id, speckle_type, children, valid_stream_ids,
invalid_stream_ids = [])
@status = SpeckleEntityStatus::UP_TO_DATE
@source_material = sketchup_entity.material
@active_diffing_stream_id = nil
@valid_stream_ids = valid_stream_ids
@invalid_stream_ids = invalid_stream_ids
@sketchup_entity = sketchup_entity
@application_id = @sketchup_entity.persistent_id
@application_id = application_id
@id = speckle_id
@total_children_count = children.length
@speckle_type = speckle_type
@@ -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,33 +100,9 @@ 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
].freeze
def self.get_definition_name(def_obj)
return def_obj['name'] unless def_obj['name'].nil?
# Check unique elements when instancing implemented to add it with element id.
if built_element?(def_obj) && unique_element?(def_obj)
return "#{def_obj['category']}-#{def_obj['family']}-#{def_obj['type']}-#{def_obj['elementId']}"
end
return "#{def_obj['category']}-#{def_obj['family']}-#{def_obj['type']}" if built_element?(def_obj)
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,45 +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
def self.instance_to_speckle_entity(state, instance, speckle_instance, stream_id)
return state unless state.user_state.user_preferences[:register_speckle_entity]
speckle_id = speckle_instance['id']
speckle_type = speckle_instance['speckle_type']
children = speckle_instance['__closure'].nil? ? [] : speckle_instance['__closure']
ent = SpeckleEntities::SpeckleEntity.new(instance, speckle_id, speckle_type, children, [stream_id])
ent.write_initial_base_data
new_speckle_state = state.speckle_state.with_speckle_entity(ent)
state.with_speckle_state(new_speckle_state)
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)
+6 -1
View File
@@ -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
+86
View File
@@ -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;
}
}