Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3001a4af48 | |||
| eeaa69e7b4 | |||
| 5717022293 | |||
| b5c1ad1ea3 | |||
| ea56717594 | |||
| 2ffb4219fc | |||
| 08843689ec | |||
| 299109505c |
@@ -26,6 +26,9 @@ Style/DocumentationMethod:
|
||||
|
||||
Metrics/AbcSize:
|
||||
Enabled: false
|
||||
|
||||
Metrics/BlockLength:
|
||||
Enabled: false
|
||||
|
||||
Metrics/ClassLength:
|
||||
Enabled: false
|
||||
|
||||
@@ -50,11 +50,15 @@ 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"]) }
|
||||
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
|
||||
@@ -78,20 +82,15 @@ module SpeckleSystems::SpeckleConnector::ToNative
|
||||
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
|
||||
num_pts += 3 if num_pts < 3 # 0 -> 3, 1 -> 4 to preserve backwards compatibility
|
||||
indices = faces.shift(num_pts)
|
||||
native_mesh.add_polygon(indices.map { |index| points[index] })
|
||||
end
|
||||
|
||||
@@ -64,28 +64,59 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
|
||||
# convert material
|
||||
mat_id = face.material.nil? ? "none" : face.material.entityID
|
||||
mat_groups[mat_id] = initialise_group_mesh(face, component_def.bounds) unless mat_groups.key?(mat_id)
|
||||
|
||||
# add points and texture coordinates
|
||||
mesh = face.mesh(1)
|
||||
mat_groups[mat_id]["@(31250)vertices"].push(*points_to_array(mesh))
|
||||
mat_groups[mat_id]["@(31250)textureCoordinates"].push(*uvs_to_array(mesh))
|
||||
|
||||
# add faces
|
||||
mat_groups[mat_id]["@(62500)faces"].push(*faces_to_array(mesh, mat_groups[mat_id][:pt_count]))
|
||||
mat_groups[mat_id][:pt_count] += mesh.points.count
|
||||
points = mesh.points
|
||||
polys =
|
||||
mesh.polygons.map do |poly|
|
||||
poly.map { |coord| points[coord.abs - 1] }
|
||||
end
|
||||
polys.each do |poly|
|
||||
mat_groups[mat_id]["@(62500)faces"].push(
|
||||
case poly.count
|
||||
when 3 then 0 # tris
|
||||
when 4 then 1 # polys
|
||||
else
|
||||
poly.count # ngons
|
||||
end
|
||||
)
|
||||
poly.each do |pt|
|
||||
index = mat_groups[mat_id][:pt_log][pt.to_s]
|
||||
unless index
|
||||
mat_groups[mat_id]["@(31250)vertices"].push(
|
||||
length_to_speckle(pt[0]),
|
||||
length_to_speckle(pt[1]),
|
||||
length_to_speckle(pt[2])
|
||||
)
|
||||
index = mat_groups[mat_id][:pt_log][pt.to_s] = mat_groups[mat_id][:pt_log].count
|
||||
end
|
||||
mat_groups[mat_id]["@(62500)faces"].push(index)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mat_groups.values.map { |group| group.delete(:pt_count) }
|
||||
mat_groups.values.map { |group| group.delete(:pt_log) }
|
||||
mat_groups.values
|
||||
end
|
||||
|
||||
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 +128,7 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
|
||||
"@(31250)vertices" => [],
|
||||
"@(62500)faces" => [],
|
||||
"@(31250)textureCoordinates" => [],
|
||||
pt_count: -1, # faces are 1 indexed
|
||||
pt_log: {},
|
||||
renderMaterial: face.material.nil? ? nil : material_to_speckle(face.material)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -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 }) {
|
||||
|
||||
Reference in New Issue
Block a user