mission impossible

This commit is contained in:
oguzhankoral
2024-12-02 19:37:07 +03:00
parent 3e5ba136be
commit 9f781b151f
3 changed files with 27 additions and 4 deletions
@@ -39,7 +39,7 @@ module SpeckleConnector3
.new(units)
.unpack_entities(entities)
unpacked_materials = SketchupModel::Materials::MaterialManager.new.unpack_materials(entities)
unpacked_materials = SketchupModel::Materials::MaterialManager.new.unpack_materials(unpacked_entities.atomic_objects, state.sketchup_state.sketchup_model)
unpacked_colors = SketchupModel::Colors::ColorManager.new.unpack_colors(state.sketchup_state.sketchup_model)
@@ -19,9 +19,17 @@ module SpeckleConnector3
end
# @param entities [Sketchup::Entities, Array<Sketchup::Entity>] entities to unpack their materials
def unpack_materials(entities)
def unpack_materials(entities, sketchup_model)
unpacked_group_meshes_and_entities = []
entities.each do |entity|
if entity.is_a?(SpeckleObjects::Geometry::GroupedMesh)
unpacked_group_meshes_and_entities += entity.faces
else
unpacked_group_meshes_and_entities << entity
end
end
flat_entities = SketchupModel::Query::Entity.flat_entities(
entities, [Sketchup::ComponentInstance, Sketchup::Group, Sketchup::Face]
unpacked_group_meshes_and_entities, [Sketchup::ComponentInstance, Sketchup::Group, Sketchup::Face]
)
flat_entities.each do |entity|
material = entity.material
@@ -30,7 +38,12 @@ module SpeckleConnector3
back_material = entity.back_material
end
next if material.nil? && back_material.nil?
if material.nil? && back_material.nil?
next unless entity.parent.is_a?(Sketchup::ComponentDefinition)
path = SketchupModel::Query::Entity.path_from_bottom_to_top(entity)
parent_material = SketchupModel::Query::Entity.parent_material(path.reverse)
material = parent_material
end
unless material.nil?
if render_material_proxies.has_key?(material.persistent_id.to_s)
@@ -84,6 +84,16 @@ module SpeckleConnector3
transformation
end
def path_from_bottom_to_top(entity)
parents = []
parent = parent_or_model(entity)
parents.push(parent) unless parent.is_a?(Sketchup::Model)
until parent.is_a?(Sketchup::Model) || parent.nil?
parent = parent_or_model(parent)
end
parents
end
# Parent search for entity from bottom to top. It is not ideal if entity lives in different instances.
def parent_or_model(entity)
parent = entity.parent