Compare commits

...

3 Commits

Author SHA1 Message Date
oguzhankoral b4761650b9 Calculate rotation of family instance 2023-12-08 02:15:56 +03:00
oguzhankoral 7921ab1f36 Add direct shape option to components back 2023-12-07 21:22:04 +03:00
oguzhankoral 3f793dc9db Exclude definitions from conversion escape
- Previously we were using definition mappings only for direct shape conversions but now they can live in instances
2023-12-07 21:19:02 +03:00
5 changed files with 35 additions and 4 deletions
@@ -102,12 +102,12 @@ module SpeckleConnector
if source_exist
{
selection: SketchupModel::Reader::MapperReader.entities_schema_details(selection),
mappingMethods: ['New Revit Family', 'Family Instance']
mappingMethods: ['Direct Shape', 'New Revit Family', 'Family Instance']
}.freeze
else
{
selection: SketchupModel::Reader::MapperReader.entities_schema_details(selection),
mappingMethods: ['New Revit Family']
mappingMethods: ['Direct Shape', 'New Revit Family']
}.freeze
end
end
@@ -64,7 +64,8 @@ module SpeckleConnector
def convert(entity, preferences, speckle_state, parent = :base)
convert = method(:convert)
unless SketchupModel::Reader::MapperReader.mapped_with_schema?(entity)
unless SketchupModel::Reader::MapperReader.mapped_with_schema?(entity) &&
!entity.is_a?(Sketchup::ComponentDefinition)
return from_native_to_speckle(entity, preferences, speckle_state, parent, &convert)
end
@@ -15,7 +15,7 @@ module SpeckleConnector
DICTIONARY = SketchupModel::Dictionary
# rubocop:disable Metrics/ParameterLists
def initialize(family:, type:, level:, units:, base_point:, application_id: nil)
def initialize(family:, type:, level:, units:, base_point:, rotation:, application_id: nil)
super(
speckle_type: SPECKLE_TYPE,
total_children_count: 0,
@@ -27,6 +27,7 @@ module SpeckleConnector
self[:level] = level
self[:units] = units
self[:basePoint] = base_point
self[:rotation] = rotation
end
# rubocop:enable Metrics/ParameterLists
end
@@ -89,6 +89,11 @@ module SpeckleConnector
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler
.speckle_schema_to_speckle(component_instance)
if speckle_schema.empty?
speckle_schema = SketchupModel::Dictionary::SpeckleSchemaDictionaryHandler
.speckle_schema_to_speckle(component_instance.definition)
end
# transform into global if any path provided
transformation = component_instance.transformation
transformation = SketchupModel::Query::Entity.global_transformation(component_instance, path) if path
@@ -133,6 +138,7 @@ module SpeckleConnector
units: units,
base_point: SpeckleObjects::Geometry::Point
.from_vertex(component_instance.bounds.min.transform(transformation), units),
rotation: calculate_rotation(transformation.to_a),
application_id: component_instance.persistent_id.to_s
)
end
@@ -263,6 +269,26 @@ module SpeckleConnector
instance_transform = instance.transformation
instance.transform!(instance_transform * transform.inverse * instance_transform.inverse)
end
def self.calculate_rotation(matrix)
# Ensure the matrix is a flat array with 16 elements
unless matrix.is_a?(Array) && matrix.size == 16
raise ArgumentError, 'Matrix must be an array with 16 elements'
end
# Extract the elements of the 2x2 rotation sub-matrix
cos_theta = matrix[0] # First column, first row
sin_theta = matrix[1] # Second column, first row
# Calculate the rotation angle in radians
theta = Math.atan2(sin_theta, cos_theta)
# Ensure the angle is between -π and π
theta -= 2 * Math::PI while theta > Math::PI
theta += 2 * Math::PI while theta < -Math::PI
theta
end
end
end
end
@@ -89,6 +89,9 @@ module SpeckleConnector
entity = entity_with_path[0]
path = entity_with_path[1..-1]
method = SPECKLE_SCHEMA_DICTIONARY_HANDLER.get_attribute(entity, 'method')
if entity.is_a?(Sketchup::ComponentInstance) && method.nil?
method = SPECKLE_SCHEMA_DICTIONARY_HANDLER.get_attribute(entity.definition, 'method')
end
if !method.nil? && (method.include?('Floor') || method.include?('Wall')) && entity.is_a?(Sketchup::Face)
global_transformation = QUERY::Entity.global_transformation(entity, path)