Compare commits

...

23 Commits

Author SHA1 Message Date
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
9 changed files with 242 additions and 27 deletions
@@ -11,6 +11,7 @@ module SpeckleConnector
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'
+3 -21
View File
@@ -55,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
@@ -73,7 +74,7 @@ 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_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
@@ -184,26 +185,6 @@ module SpeckleConnector
create_folder_layers(folder_layer_arrays, folder)
end
# @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)
@@ -313,6 +294,7 @@ 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_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
@@ -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
@@ -50,6 +50,7 @@ module SpeckleConnector
# 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?
@@ -72,11 +73,35 @@ module SpeckleConnector
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 = []
@@ -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'])
@@ -16,12 +16,13 @@ module SpeckleConnector
type = def_obj['type']
category = def_obj['category']
return "#{family}-#{type}-#{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
@@ -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;
}
}