Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a8955a435f | |||
| 80f25eb1a2 | |||
| 5716f92fbf | |||
| 63e7aaa661 | |||
| 7234a4be79 | |||
| e1cceb9bba | |||
| 30157b5ac2 | |||
| f9b1628c18 | |||
| 9429a11fa7 | |||
| af4c6d9f71 | |||
| a4f23e060c | |||
| d2099c98e0 | |||
| c21b51135a | |||
| c5c8bf6b6f | |||
| d9a92e90ec | |||
| 79ae201646 | |||
| 01b32d2558 | |||
| b3067aa346 | |||
| d1349c5df1 | |||
| d44365a6d4 | |||
| c8c94184df | |||
| 62c436131c | |||
| ac3579de46 | |||
| e7a72b25d7 | |||
| 6d155d987a | |||
| e4a78e4c6e | |||
| 35c819dab0 | |||
| 3001a4af48 | |||
| eeaa69e7b4 | |||
| 5717022293 | |||
| b5c1ad1ea3 | |||
| ea56717594 | |||
| 2ffb4219fc | |||
| 08843689ec | |||
| 299109505c | |||
| 520dccc674 | |||
| 22e6ea7515 | |||
| 81af3da8b4 |
@@ -26,6 +26,9 @@ Style/DocumentationMethod:
|
||||
|
||||
Metrics/AbcSize:
|
||||
Enabled: false
|
||||
|
||||
Metrics/BlockLength:
|
||||
Enabled: false
|
||||
|
||||
Metrics/ClassLength:
|
||||
Enabled: false
|
||||
|
||||
@@ -77,15 +77,15 @@ This should have also have set up the package installer `gem` and interactive ru
|
||||
gem -v
|
||||
irb -v
|
||||
|
||||
Let's also install our first gem `bundle` which is a package manager that will help us with development.
|
||||
Let's also install our first gem `bundler` which is a package manager that will help us with development.
|
||||
|
||||
gem install bundle
|
||||
gem install bundler
|
||||
|
||||
### Editor Setup
|
||||
|
||||
Clone this repo and run:
|
||||
|
||||
bundle install
|
||||
bundler install
|
||||
|
||||
This will install all the necessary packages for the connector.
|
||||
|
||||
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
require "net/http"
|
||||
|
||||
require "json"
|
||||
|
||||
require "uri"
|
||||
|
||||
server = "https://latest.speckle.dev"
|
||||
|
||||
token = "1dc2e3330a56371dc9011e5bed406264c9e65dd355"
|
||||
|
||||
limit = 20
|
||||
streams_list = "
|
||||
query User {
|
||||
user {
|
||||
id
|
||||
email
|
||||
name
|
||||
bio
|
||||
company
|
||||
avatar
|
||||
verified
|
||||
profiles
|
||||
role
|
||||
streams(limit: #{limit}) {
|
||||
totalCount
|
||||
cursor
|
||||
items {
|
||||
id
|
||||
name
|
||||
description
|
||||
isPublic
|
||||
createdAt
|
||||
updatedAt
|
||||
collaborators {
|
||||
id
|
||||
name
|
||||
role
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"
|
||||
|
||||
endpoint = URI("#{server}/graphql")
|
||||
|
||||
res =
|
||||
::Net::HTTP.start(endpoint.host, endpoint.port, use_ssl: true) do |http|
|
||||
req = ::Net::HTTP::Post.new(endpoint)
|
||||
req["Content-Type"] = "application/json"
|
||||
req["Authorization"] = "Bearer #{token}"
|
||||
# The body needs to be a JSON string.
|
||||
req.body = ::JSON[{ query: streams_list }]
|
||||
puts(req.body)
|
||||
http.request(req)
|
||||
end
|
||||
|
||||
streams = ::JSON.parse(res.body)["data"]["user"]["streams"]["items"]
|
||||
puts(streams)
|
||||
@@ -21,6 +21,8 @@ module SpeckleSystems
|
||||
|
||||
# Run from localhost or from build files
|
||||
DEV_MODE = false
|
||||
puts("Loading Speckle Connector v#{CONNECTOR_VERSION} from #{DEV_MODE ? 'dev' : 'build'}")
|
||||
|
||||
|
||||
unless file_loaded?(__FILE__)
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ begin
|
||||
rescue LoadError
|
||||
# ty msp-greg! https://github.com/MSP-Greg/SUMisc/releases/tag/sqlite3-mingw-1
|
||||
Gem.install(File.join(File.dirname(File.expand_path(__FILE__)), "utils/sqlite3-1.4.2.mspgreg-x64-mingw32.gem"))
|
||||
else
|
||||
require("sqlite3")
|
||||
end
|
||||
|
||||
@@ -33,22 +32,20 @@ module SpeckleSystems::SpeckleConnector
|
||||
end
|
||||
|
||||
def self._get_speckle_dir
|
||||
platform = RUBY_PLATFORM.downcase
|
||||
|
||||
speckle_dir =
|
||||
if platform =~ (/mingw/) || platform =~ (/win/)
|
||||
# win
|
||||
File.join(Dir.home, "AppData/Roaming/Speckle")
|
||||
elsif platform =~ /linux/
|
||||
# linux
|
||||
File.expand_path("~/.local/share/Speckle")
|
||||
case Sketchup.platform
|
||||
when :platform_win then File.join(Dir.home, "AppData/Roaming/Speckle")
|
||||
when :platform_osx then File.join(Dir.home, ".config", "Speckle")
|
||||
else
|
||||
# mac
|
||||
File.expand_path("~/.config/Speckle")
|
||||
nil
|
||||
end
|
||||
|
||||
return speckle_dir if Dir.exist?(speckle_dir)
|
||||
|
||||
raise(IOError, "No Speckle Directory exists. Please read the guide to get Speckle set up on your machine: \nhttps://speckle.guide/user/manager.html")
|
||||
raise(
|
||||
IOError,
|
||||
"No Speckle Directory exists. Please read the guide to get Speckle set up on your machine: \nhttps://speckle.guide/user/manager.html"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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,20 +92,36 @@ 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"])
|
||||
transform = transform_to_native(
|
||||
block["transform"].is_a?(Hash) ? block["transform"]["value"] : block["transform"],
|
||||
block["units"]
|
||||
)
|
||||
instance =
|
||||
if is_group
|
||||
entities.add_group(definition.entities.to_a)
|
||||
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 +130,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
|
||||
|
||||
@@ -40,7 +40,6 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
|
||||
|
||||
def component_instance_to_speckle(instance, is_group: false)
|
||||
transform = instance.transformation
|
||||
origin = transform.origin
|
||||
{
|
||||
speckle_type: "Objects.Other.BlockInstance",
|
||||
applicationId: instance.guid,
|
||||
@@ -50,17 +49,19 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
|
||||
name: instance.name,
|
||||
renderMaterial: instance.material.nil? ? nil : material_to_speckle(instance.material),
|
||||
transform: transform_to_speckle(transform),
|
||||
insertionPoint: speckle_point(origin[0], origin[1], origin[2]),
|
||||
"@blockDefinition" => component_definition_to_speckle(instance.definition)
|
||||
}
|
||||
end
|
||||
|
||||
def group_mesh_to_speckle(component_def)
|
||||
mat_groups = {}
|
||||
nested_blocks = []
|
||||
|
||||
component_def.entities.each do |face|
|
||||
next unless face.typename == "Face"
|
||||
component_def.entities.each do |entity|
|
||||
nested_blocks.push(component_instance_to_speckle(entity)) if entity.typename == "ComponentInstance"
|
||||
next unless entity.typename == "Face"
|
||||
|
||||
face = entity
|
||||
# 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)
|
||||
@@ -76,17 +77,33 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
|
||||
end
|
||||
|
||||
mat_groups.values.map { |group| group.delete(:pt_count) }
|
||||
mat_groups.values
|
||||
mat_groups.values + nested_blocks
|
||||
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]
|
||||
]
|
||||
{
|
||||
speckle_type: "Objects.Other.Transform",
|
||||
units: @units,
|
||||
value: [
|
||||
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
|
||||
|
||||
def initialise_group_mesh(face, bounds)
|
||||
@@ -97,7 +114,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
|
||||
|
||||
@@ -42,13 +42,13 @@ module SpeckleSystems::SpeckleConnector
|
||||
init_local_accounts
|
||||
|
||||
end
|
||||
puts DEV_MODE
|
||||
if DEV_MODE
|
||||
puts('Launching Speckle Connector from http://localhost:8081')
|
||||
@dialog.set_url("http://localhost:8081")
|
||||
else
|
||||
basedir = File.join(File.dirname(File.expand_path(__FILE__)), "html")
|
||||
html = File.read(File.join(basedir, "index.html"))
|
||||
@dialog.set_html(html)
|
||||
html_file = File.join(File.dirname(File.expand_path(__FILE__)), "html", "index.html")
|
||||
puts("Launching Speckle Connector from #{html_file}")
|
||||
@dialog.set_file(html_file)
|
||||
end
|
||||
|
||||
@dialog.show
|
||||
@@ -81,10 +81,12 @@ module SpeckleSystems::SpeckleConnector
|
||||
end
|
||||
|
||||
def self.init_local_accounts
|
||||
puts("Initialisation of Speckle accounts requested by plugin")
|
||||
@dialog.execute_script("loadAccounts(#{Accounts.load_accounts.to_json}, #{Accounts.get_suuid.to_json})")
|
||||
end
|
||||
|
||||
def self.reload_accounts
|
||||
puts("Reload of Speckle accounts requested by plugin")
|
||||
@dialog.execute_script("loadAccounts(#{Accounts.load_accounts.to_json})")
|
||||
end
|
||||
end
|
||||
|
||||
Generated
+7437
-3216
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -9,7 +9,7 @@
|
||||
"lint": "vue-cli-service lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@speckle/objectloader": "^2.1.1",
|
||||
"@speckle/objectloader": "^2.3.0",
|
||||
"aws-sdk": "^2.981.0",
|
||||
"core-js": "^3.6.5",
|
||||
"debounce": "^1.2.1",
|
||||
|
||||
@@ -96,6 +96,7 @@ import userQuery from './graphql/user.gql'
|
||||
import { onLogin } from './vue-apollo'
|
||||
|
||||
global.loadAccounts = function (accounts, suuid) {
|
||||
console.log('>>> SpeckleSketchup: Loading accounts', accounts, `suuid: ${suuid}`)
|
||||
localStorage.setItem('localAccounts', JSON.stringify(accounts))
|
||||
if (suuid) {
|
||||
localStorage.setItem('suuid', suuid)
|
||||
|
||||
@@ -15,14 +15,12 @@
|
||||
<v-card-text class="transparent elevation-0 mt-0 pt-0" dense>
|
||||
<div class="text-caption">
|
||||
Updated
|
||||
<timeago :datetime="stream.updatedAt" />
|
||||
<timeago class="mr-1" :datetime="stream.updatedAt" />
|
||||
|
|
||||
<v-icon class="ml-1" small>mdi-account-key-outline</v-icon>
|
||||
{{ stream.role.split(':')[1] }}
|
||||
</div>
|
||||
<v-toolbar-title>
|
||||
<v-chip v-if="stream.role" small class="mr-1">
|
||||
<v-icon small left>mdi-account-key-outline</v-icon>
|
||||
{{ stream.role.split(':')[1] }}
|
||||
</v-chip>
|
||||
|
||||
<v-menu offset-y>
|
||||
<template #activator="{ on, attrs }">
|
||||
<v-chip v-if="stream.branches" small v-bind="attrs" class="mr-1" v-on="on">
|
||||
@@ -150,13 +148,29 @@
|
||||
</v-tooltip>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-progress-linear
|
||||
v-if="(loadingSend || loadingReceive) && loadingStage"
|
||||
height="14"
|
||||
indeterminate
|
||||
>
|
||||
<div class="text-caption">{{ loadingStage }}</div>
|
||||
</v-progress-linear>
|
||||
<transition-group name="expand">
|
||||
<v-card-text v-if="hover && !$apollo.loading" key="commit-message-field" class="mt-0 pt-0">
|
||||
<transition name="fade">
|
||||
<v-text-field
|
||||
v-model="commitMessage"
|
||||
class="small-text-field"
|
||||
hide-details
|
||||
dense
|
||||
flat
|
||||
label="Commit Message"
|
||||
placeholder="Write your commit message here"
|
||||
></v-text-field>
|
||||
</transition>
|
||||
</v-card-text>
|
||||
<v-progress-linear
|
||||
v-if="(loadingSend || loadingReceive) && loadingStage"
|
||||
key="progress-bar"
|
||||
height="14"
|
||||
indeterminate
|
||||
>
|
||||
<div class="text-caption">{{ loadingStage }}</div>
|
||||
</v-progress-linear>
|
||||
</transition-group>
|
||||
</v-card>
|
||||
</v-hover>
|
||||
</template>
|
||||
@@ -195,7 +209,8 @@ export default {
|
||||
loadingReceive: false,
|
||||
loadingStage: null,
|
||||
branchName: 'main',
|
||||
commitId: 'latest'
|
||||
commitId: 'latest',
|
||||
commitMessage: null
|
||||
}
|
||||
},
|
||||
apollo: {
|
||||
@@ -278,19 +293,19 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
bus.$on(`sketchup-objects-${this.streamId}`, async (objects) => {
|
||||
console.log('received objects from sketchup', objects)
|
||||
console.log('>>> SpeckleSketchUp: Received objects from sketchup')
|
||||
|
||||
await this.createCommit(objects)
|
||||
})
|
||||
bus.$on(`sketchup-received-${this.streamId}`, () => {
|
||||
console.log('finished receiving in sketchup', this.streamId)
|
||||
console.log('>>> SpeckleSketchUp: Finished receiving in sketchup', this.streamId)
|
||||
this.loadingReceive = false
|
||||
this.loadingStage = null
|
||||
})
|
||||
bus.$on(`sketchup-fail-${this.streamId}`, () => {
|
||||
this.$matomo && this.$matomo.setCustomUrl(`http://connectors/SketchUp/stream/fail`)
|
||||
this.$matomo && this.$matomo.trackPageView(`stream/fail`)
|
||||
console.log('sketchup operation failed', this.streamId)
|
||||
console.log('>>> SpeckleSketchUp: operation failed', this.streamId)
|
||||
this.loadingReceive = this.loadingSend = false
|
||||
this.loadingStage = null
|
||||
})
|
||||
@@ -332,7 +347,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 }) {
|
||||
@@ -344,7 +376,7 @@ export default {
|
||||
this.$matomo && this.$matomo.setCustomUrl(`http://connectors/SketchUp/send`)
|
||||
this.$matomo && this.$matomo.trackPageView(`send`)
|
||||
sketchup.send_selection(this.streamId)
|
||||
console.log('request for data sent to sketchup')
|
||||
console.log('>>> SpeckleSketchUp: Objects requested from SketchUp')
|
||||
await this.sleep(2000)
|
||||
},
|
||||
async createCommit(objects) {
|
||||
@@ -362,16 +394,21 @@ export default {
|
||||
this.loadingStage = 'uploading'
|
||||
this.loadingSend = true
|
||||
let batches = s.batchObjects()
|
||||
const totBatches = batches.length
|
||||
console.log(`>>> SpeckleSketchUp: ${totBatches} batches ready for sending`)
|
||||
let batchesSent = 0
|
||||
for (const batch of batches) {
|
||||
let res = await this.sendBatch(batch)
|
||||
if (res.status !== 201) throw `Upload request failed: ${res}`
|
||||
if (res.status !== 201) throw `Upload request failed: ${res.status}`
|
||||
batchesSent++
|
||||
this.loadingStage = `uploading: ${Math.round((batchesSent / totBatches) * 100)}%`
|
||||
}
|
||||
|
||||
let commit = {
|
||||
streamId: this.streamId,
|
||||
branchName: this.branchName,
|
||||
objectId: hash,
|
||||
message: 'sent from sketchup',
|
||||
message: this.commitMessage ?? 'sent from sketchup',
|
||||
sourceApplication: 'sketchup',
|
||||
totalChildrenCount: s.objects[hash].totalChildrenCount
|
||||
}
|
||||
@@ -385,7 +422,7 @@ export default {
|
||||
commit: commit
|
||||
}
|
||||
})
|
||||
console.log('sent to stream: ' + this.streamId, commit)
|
||||
console.log('>>> SpeckleSketchUp: Sent to stream: ' + this.streamId, commit)
|
||||
|
||||
this.loadingSend = false
|
||||
this.loadingStage = null
|
||||
@@ -397,7 +434,7 @@ export default {
|
||||
},
|
||||
async sendBatch(batch) {
|
||||
let formData = new FormData()
|
||||
formData.append(`batch-1`, new Blob([JSON.stringify(batch)], { type: 'application/json' }))
|
||||
formData.append(`batch-1`, new Blob([batch], { type: 'application/json' }))
|
||||
let token = localStorage.getItem('SpeckleSketchup.AuthToken')
|
||||
let res = await fetch(`${localStorage.getItem('serverUrl')}/objects/${this.streamId}`, {
|
||||
method: 'POST',
|
||||
@@ -410,7 +447,39 @@ export default {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
<style scoped>
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.2s ease-in;
|
||||
}
|
||||
.fade-enter,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.expand-enter-active {
|
||||
transition: all 0.2s ease;
|
||||
max-height: 1200px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.expand-leave-active {
|
||||
transition: all 0.3s ease;
|
||||
max-height: 1200px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.expand-enter,
|
||||
.expand-leave-to {
|
||||
max-height: 0;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.v-text-field >>> input {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
.v-text-field >>> label {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.btn-fix:focus::before {
|
||||
opacity: 0 !important;
|
||||
}
|
||||
|
||||
@@ -170,21 +170,21 @@ export class BaseObjectSerializer {
|
||||
batchObjects(maxBatchSizeMb = 1) {
|
||||
const maxSize = maxBatchSizeMb * 1000 * 1000
|
||||
let batches = []
|
||||
let batch = []
|
||||
let batch = '['
|
||||
let batchSize = 0
|
||||
let objects = Object.values(this.objects)
|
||||
objects.forEach((obj) => {
|
||||
let objString = JSON.stringify(obj)
|
||||
if (batchSize + objString.length < maxSize) {
|
||||
batch.push(obj)
|
||||
batch += objString + ','
|
||||
batchSize += objString.length
|
||||
} else {
|
||||
batches.push(batch)
|
||||
batch = [obj]
|
||||
batches.push(batch.slice(0, -1) + ']')
|
||||
batch = '[' + objString + ','
|
||||
batchSize = objString.length
|
||||
}
|
||||
})
|
||||
batches.push(batch)
|
||||
batches.push(batch.slice(0, -1) + ']')
|
||||
|
||||
return batches
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ const AUTH_TOKEN = `SpeckleSketchup.AuthToken`
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
localStorage.setItem(AUTH_TOKEN, process.env.VUE_APP_DEV_TOKEN)
|
||||
localStorage.setItem('serverUrl', process.env.VUE_APP_DEFAULT_SERVER)
|
||||
} else if (!localStorage.getItem('serverUrl')) {
|
||||
localStorage.setItem('serverUrl', 'https://speckle.xyz')
|
||||
}
|
||||
|
||||
const authLink = setContext((_, { headers }) => {
|
||||
|
||||
+1
-4
@@ -1,10 +1,7 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = {
|
||||
publicPath:
|
||||
process.env.NODE_ENV === 'production'
|
||||
? path.resolve(__dirname, '../speckle_connector', 'html')
|
||||
: '/',
|
||||
publicPath: "./",
|
||||
outputDir: path.resolve(__dirname, '../speckle_connector', 'html'),
|
||||
transpileDependencies: ['vuetify', '@speckle/objectloader']
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user