Compare commits

...

16 Commits

Author SHA1 Message Date
izzy lyseggen c8c94184df Merge pull request #15 from specklesystems/izzy/blocks
fix(converter): receiving blocks
2021-11-16 15:57:51 +00:00
izzy lyseggen 62c436131c fix(converter): receiving blocks
WE OUT HERE BOIIIII
📦 Block Receive Failing #10
2021-11-16 15:52:52 +00:00
izzy lyseggen ac3579de46 Merge pull request #14 from specklesystems/izzy/blocks
fix(converter): revert mesh squish & fix closed polylines
2021-11-16 10:55:01 +00:00
izzy lyseggen e7a72b25d7 fix(converter): revert mesh squish 2021-11-16 10:54:00 +00:00
izzy lyseggen 6d155d987a fix(converter): only return component def if exists 2021-11-15 17:30:47 +00:00
izzy lyseggen e4a78e4c6e feat(converter): add explicit brep to native mesh 2021-11-15 17:30:27 +00:00
izzy lyseggen 35c819dab0 fix(convert): closed polylines 2021-11-15 16:55:50 +00:00
izzy lyseggen 3001a4af48 Merge pull request #13 from specklesystems/izzy/mesh-experiments
feat(converter): improved meshes!
2021-11-15 14:59:39 +00:00
izzy lyseggen eeaa69e7b4 feat(convert): mesh to native polycount cleanup 2021-11-15 14:58:51 +00:00
izzy lyseggen 5717022293 chore: pls leave me alone rubocop 2021-11-15 14:51:18 +00:00
izzy lyseggen b5c1ad1ea3 feat(convert): additional mesh improvements 2021-11-12 11:34:39 +00:00
izzy lyseggen ea56717594 fix(convert): simple line fixes 2021-11-12 11:33:58 +00:00
izzy lyseggen 2ffb4219fc feat(convert): initial mesh squish fix
🍙 Remove duplicate vertices when building meshes `to_speckle` #12
2021-11-11 17:48:56 +00:00
izzy lyseggen 08843689ec feat(ui): move read receipt to end of receive method 2021-11-10 16:22:33 +00:00
izzy lyseggen 299109505c feat(ui): Sketchup: Add Read receipts call #7 2021-11-10 16:06:54 +00:00
izzy lyseggen 520dccc674 fix(convert): traverse all base props
not just dynamically detached ones
2021-11-09 18:19:43 +00:00
4 changed files with 93 additions and 45 deletions
+3
View File
@@ -26,6 +26,9 @@ Style/DocumentationMethod:
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
+56 -40
View File
@@ -6,8 +6,8 @@ module SpeckleSystems::SpeckleConnector::ToNative
if can_convert_to_native(obj)
convert_to_native(obj, Sketchup.active_model.entities)
elsif obj.is_a?(Hash) && obj.key?("speckle_type")
props = obj.keys.filter_map { |key| key if key.start_with?("@") }
%w[displayMesh displayValue data].each { |prop| props.push(prop) if obj.key?(prop) }
puts(">>> Found #{obj["speckle_type"]}: #{obj["id"]}")
props = obj.keys.filter_map { |key| key unless key.start_with?("_") }
props.each { |prop| traverse_commit_object(obj[prop]) }
elsif obj.is_a?(Hash)
obj.each_value { |value| traverse_commit_object(value) }
@@ -25,6 +25,7 @@ module SpeckleSystems::SpeckleConnector::ToNative
"Objects.Geometry.Line",
"Objects.Geometry.Polyline",
"Objects.Geometry.Mesh",
"Objects.Geometry.Brep",
"Objects.Other.BlockInstance",
"Objects.Other.BlockDefinition",
"Objects.Other.RenderMaterial"
@@ -37,13 +38,14 @@ module SpeckleSystems::SpeckleConnector::ToNative
when "Objects.Other.BlockInstance" then component_instance_to_native(obj, entities)
when "Objects.Other.BlockDefinition" then component_definition_to_native(obj)
when "Objects.Geometry.Mesh" then mesh_to_native(obj, entities)
when "Objects.Geometry.Brep" then mesh_to_native(obj["displayMesh"], entities)
else
nil
end
# rescue StandardError => e
# puts("Failed to convert #{obj["speckle_type"]} (id: #{obj["id"]})")
# puts(e)
# nil
# rescue StandardError => e
# puts("Failed to convert #{obj["speckle_type"]} (id: #{obj["id"]})")
# puts(e)
# nil
end
def length_to_native(length, units = @units)
@@ -51,11 +53,16 @@ module SpeckleSystems::SpeckleConnector::ToNative
end
def edge_to_native(line, entities)
return unless line.key?("value")
values = line["value"]
points = values.each_slice(3).to_a.map { |pt| point_to_native(pt[0], pt[1], pt[2], line["units"]) }
entities.add_edges(*points)
if line.key?("value")
values = line["value"]
points = values.each_slice(3).to_a.map { |pt| point_to_native(pt[0], pt[1], pt[2], line["units"]) }
points.push(points[0]) if line["closed"]
entities.add_edges(*points)
else
start_pt = point_to_native(line["start"]["x"], line["start"]["y"], line["start"]["z"], line["units"])
end_pt = point_to_native(line["end"]["x"], line["end"]["y"], line["end"]["z"], line["units"])
entities.add_edges(start_pt, end_pt)
end
end
def face_to_native
@@ -66,31 +73,17 @@ module SpeckleSystems::SpeckleConnector::ToNative
Geom::Point3d.new(length_to_native(x, units), length_to_native(y, units), length_to_native(z, units))
end
def component_definition_to_native(block_def)
definition = Sketchup.active_model.definitions[block_def["name"]]
return definition if definition&.guid == block_def["applicationId"]
definition&.entities&.clear!
definition ||= Sketchup.active_model.definitions.add(block_def["name"])
block_def["geometry"].each { |obj| convert_to_native(obj, definition.entities) }
definition
end
def mesh_to_native(mesh, entities)
native_mesh = Geom::PolygonMesh.new
points = [] # to preserve indices - duplicate points won't be added in `point_to_native`
native_mesh = Geom::PolygonMesh.new(mesh["vertices"].count / 3)
points = []
mesh["vertices"].each_slice(3) do |pt|
points.push(point_to_native(pt[0], pt[1], pt[2], mesh["units"]))
end
faces = mesh["faces"]
while faces.count.positive?
size = faces.shift
num_pts =
case size
when 0 then 3
when 1 then 4
else size
end
num_pts = faces.shift
# 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] })
end
@@ -99,11 +92,25 @@ module SpeckleSystems::SpeckleConnector::ToNative
native_mesh
end
def component_definition_to_native(block_def)
definition = Sketchup.active_model.definitions[block_def["name"]]
return definition if definition && (definition.name == block_def["name"] || definition.guid == block_def["applicationId"])
definition&.entities&.clear!
definition ||= Sketchup.active_model.definitions.add(block_def["name"])
block_def["geometry"].each { |obj| convert_to_native(obj, definition.entities) }
puts("definition finished: #{block_def["name"]} (#{block_def["id"]})")
puts(" entity count: #{definition.entities.count}")
definition
end
def component_instance_to_native(block, entities)
is_group = block.key?("is_sketchup_group") && block["is_sketchup_group"]
# 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
# so this is set to false always until I can figure this out
is_group = false
definition = component_definition_to_native(block["blockDefinition"])
# return unless definition.entities.count.positive?
transform = transform_to_native(block["transform"], block["units"])
instance =
@@ -112,7 +119,7 @@ module SpeckleSystems::SpeckleConnector::ToNative
else
entities.add_instance(definition, transform)
end
puts("Failed to create instance for speckle object #{block["id"]}") if instance.nil?
puts("Failed to create instance for speckle block instance #{block["id"]}") if instance.nil?
instance.transformation = transform if is_group
instance.material = material_to_native(block["renderMaterial"])
instance
@@ -121,13 +128,22 @@ module SpeckleSystems::SpeckleConnector::ToNative
def transform_to_native(t_arr, units = @units)
Geom::Transformation.new(
[
t_arr[0], t_arr[4], t_arr[8], t_arr[12],
t_arr[1], t_arr[5], t_arr[9], t_arr[13],
t_arr[2], t_arr[6], t_arr[10], t_arr[14],
length_to_native(t_arr[3], units),
length_to_native(t_arr[7], units),
length_to_native(t_arr[11], units),
t_arr[15]
t_arr[0],
t_arr[4],
t_arr[8],
t_arr[12],
t_arr[1],
t_arr[5],
t_arr[9],
t_arr[13],
t_arr[2],
t_arr[6],
t_arr[10],
t_arr[14],
length_to_native(t_arr[3], units),
length_to_native(t_arr[7], units),
length_to_native(t_arr[11], units),
t_arr[15]
]
)
end
+17 -5
View File
@@ -82,10 +82,22 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
def transform_to_speckle(transform)
t_arr = transform.to_a
[
t_arr[0], t_arr[4], t_arr[8], length_to_speckle(t_arr[12]),
t_arr[1], t_arr[5], t_arr[9], length_to_speckle(t_arr[13]),
t_arr[2], t_arr[6], t_arr[10], length_to_speckle(t_arr[14]),
t_arr[3], t_arr[7], t_arr[11], t_arr[15]
t_arr[0],
t_arr[4],
t_arr[8],
length_to_speckle(t_arr[12]),
t_arr[1],
t_arr[5],
t_arr[9],
length_to_speckle(t_arr[13]),
t_arr[2],
t_arr[6],
t_arr[10],
length_to_speckle(t_arr[14]),
t_arr[3],
t_arr[7],
t_arr[11],
t_arr[15]
]
end
@@ -97,7 +109,7 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
"@(31250)vertices" => [],
"@(62500)faces" => [],
"@(31250)textureCoordinates" => [],
pt_count: -1, # faces are 1 indexed
pt_count: -1,
renderMaterial: face.material.nil? ? nil : material_to_speckle(face.material)
}
end
+17
View File
@@ -332,7 +332,24 @@ export default {
let rootObj = await loader.getAndConstructObject(this.updateLoadingStage)
console.log(rootObj)
sketchup.receive_objects(rootObj, this.streamId)
await this.$apollo.mutate({
mutation: gql`
mutation commitReceive($input: CommitReceivedInput!) {
commitReceive(input: $input)
}
`,
variables: {
input: {
sourceApplication: 'sketchup',
streamId: this.streamId,
commitId: this.selectedCommit.id
}
}
})
this.loadingStage = 'converting'
},
updateLoadingStage({ stage }) {