Compare commits

...

5 Commits

Author SHA1 Message Date
izzy lyseggen 4698799b43 ci: fix patch version script 2022-06-21 13:10:31 +01:00
izzy lyseggen 5d4e6ac89a ci: use semver tag for patching 2022-06-21 13:02:23 +01:00
izzy lyseggen b1c09c62d9 feat(converter): mesh enhancements (#50)
* feat(converter): smooth & preserve raw mesh

also only create components for `displayValue` geometry

wip - to try another edge strategy as this has caused quite a perf hit

* fix(converter): don't preserve edges for now

it is way too slow in the current implementation.
i think we can make it work in sketchup 2022 with the entities building,
but as of rn it seems like a no go for 2021
2022-06-21 12:58:59 +01:00
izzy lyseggen 2b7b74dbdd chore(ui): test removing core j (#48) 2022-06-20 16:28:07 +01:00
izzy lyseggen 42f3ae8490 ci: update tag parsing and ui build (#47)
* ci: update tag parsing and ui build

* chore(deps): stackoverflow and i are besties

testing out this workaround - will do a beta release

* ci: deploy filter tags

* ci: fix release label tag
2022-06-10 14:51:16 +01:00
7 changed files with 7502 additions and 4829 deletions
+8 -12
View File
@@ -12,9 +12,6 @@ jobs:
- image: "circleci/node:16"
steps:
- checkout
- run:
command: "rm package-lock.json"
working_directory: "ui"
- run:
command: "npm install"
working_directory: "ui"
@@ -43,15 +40,14 @@ jobs:
shell: powershell.exe
command:
| # If no tag, use 0.0.0.1 and don't make any YML (for testing only!)
$tag = if([string]::IsNullOrEmpty($env:CIRCLE_TAG)) { "0.0.1" } else { $env:CIRCLE_TAG }
$semver = $tag.replace("-beta","")
$version = "$($semver).$($env:CIRCLE_BUILD_NUM)"
$channel = "latest"
if($tag -like "*-beta") { $channel = "beta" }
# only create the yml if we have a tag
New-Item -Force "speckle-sharp-ci-tools/Installers/sketchup/$channel.yml" -ItemType File -Value "version: $version"
$tag = if([string]::IsNullOrEmpty($env:CIRCLE_TAG)) { "0.0.0" } else { $env:CIRCLE_TAG }
$semver = if($tag.Contains('/')) {$tag.Split("/")[1] } else { $tag }
$ver = if($semver.Contains('-')) {$semver.Split("-")[0] } else { $semver }
$channel = if($semver.Contains('-')) {$semver.Split("-")[1] } else { "latest" }
$version = "$($ver).$($env:CIRCLE_BUILD_NUM)"
New-Item -Force "speckle-sharp-ci-tools/Installers/sketchup/$channel.yml" -ItemType File -Value "version: $semver"
echo $version
python patch_version.py $version
python patch_version.py $semver
speckle-sharp-ci-tools\InnoSetup\ISCC.exe speckle-sharp-ci-tools\sketchup.iss
- persist_to_workspace:
root: ./
@@ -120,6 +116,6 @@ workflows:
- build-connector
filters:
tags:
only: /[0-9]+(\.[0-9]+)*/
only: /([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\w+)?$/
branches:
ignore: /.*/ # For testing only! /ci\/.*/
+3 -2
View File
@@ -25,7 +25,8 @@ def patch_installer(tag):
with open(iss_file, "r") as file:
lines = file.readlines()
lines.insert(11, f'#define AppVersion "{tag}"\n')
lines.insert(11, f'#define AppVersion "{tag.split("-")[0]}"\n')
lines.insert(12, f'#define AppInfoVersion "{tag}"\n')
with open(iss_file, "w") as file:
file.writelines(lines)
@@ -39,7 +40,7 @@ def main():
return
tag = sys.argv[1]
if not re.match(r"[0-9]+(\.[0-9]+)*$", tag):
if not re.match(r"([0-9]+)\.([0-9]+)\.([0-9]+)", tag):
raise ValueError(f"Invalid tag provided: {tag}")
print(f"Patching version: {tag}")
+66 -50
View File
@@ -8,9 +8,14 @@ module SpeckleSystems::SpeckleConnector::ToNative
elsif obj.is_a?(Hash) && obj.key?("speckle_type")
return if is_ignored_speckle_type(obj)
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]) }
if obj["displayValue"].nil?
puts(">>> Found #{obj["speckle_type"]}: #{obj["id"]}. Continuing traversal.")
props = obj.keys.filter_map { |key| key unless key.start_with?("_") }
props.each { |prop| traverse_commit_object(obj[prop]) }
else
puts(">>> Found #{obj["speckle_type"]}: #{obj["id"]} with displayValue.")
convert_to_native(obj)
end
elsif obj.is_a?(Hash)
obj.each_value { |value| traverse_commit_object(value) }
elsif obj.is_a?(Array)
@@ -39,32 +44,14 @@ module SpeckleSystems::SpeckleConnector::ToNative
end
def convert_to_native(obj, entities = Sketchup.active_model.entities)
puts(">>> Converting #{obj["speckle_type"]}: #{obj["id"]}")
return display_value_to_native_component(obj, entities) unless obj["displayValue"].nil?
case obj["speckle_type"]
when "Objects.Geometry.Line", "Objects.Geometry.Polyline" then if entities == Sketchup.active_model.entities
edge_to_native_component(obj, entities)
else
edge_to_native(obj, entities)
end
when "Objects.Geometry.Line", "Objects.Geometry.Polyline" then edge_to_native(obj, entities)
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 if entities == Sketchup.active_model.entities
mesh_to_native_component(obj, entities)
else
mesh_to_native(obj, entities)
end
when "Objects.Geometry.Brep" then if entities == Sketchup.active_model.entities
mesh_to_native_component(obj["displayMesh"], entities)
else
mesh_to_native(obj["displayMesh"], entities)
end
when obj.key?["displayValue"]
parent_id = obj["applicationId"] || obj["id"]
obj["displayValue"].each do |o|
o["applicationId"] = "#{parent_id}::#{o["id"]}" if o["applicationId"].nil?
convert_to_native(o, entities)
end
when "Objects.Geometry.Mesh" then mesh_to_native(obj, entities)
when "Objects.Geometry.Brep" then mesh_to_native(obj["displayValue"], entities)
else
nil
end
@@ -74,20 +61,6 @@ module SpeckleSystems::SpeckleConnector::ToNative
nil
end
# def register_receive(entity, id)
# # entity.add_observer(@entity_observer)
# # entity.set_attribute("speckle", "applicationId", id)
# @registry[id] = entity.persistent_id
# end
# def get_received_entity(app_id)
# return if @registry[app_id].nil?
# end
# def received?(id)
# !@registry[id].nil?
# end
def length_to_native(length, units = @units)
length.__send__(SpeckleSystems::SpeckleConnector::SKETCHUP_UNIT_STRINGS[units])
end
@@ -106,7 +79,7 @@ module SpeckleSystems::SpeckleConnector::ToNative
end
def edge_to_native_component(line, entities)
line_id = line["applicationId"] || line["id"]
line_id = line["applicationId"].to_s.empty? ? line["id"] : line["applicationId"]
definition = component_definition_to_native([line], "def::#{line_id}")
find_and_erase_existing_instance(definition, line_id)
instance = entities.add_instance(definition, Geom::Transformation.new)
@@ -122,8 +95,16 @@ module SpeckleSystems::SpeckleConnector::ToNative
Geom::Point3d.new(length_to_native(x, units), length_to_native(y, units), length_to_native(z, units))
end
def point_to_native_array(x ,y ,z ,units)
[length_to_native(x, units), length_to_native(y, units), length_to_native(z, units)]
end
# converts a mesh to a native mesh and adds the faces to the given entities collection
def mesh_to_native(mesh, entities)
_speckle_mesh_to_native_mesh(mesh, entities)
end
def _speckle_mesh_to_native_mesh(mesh, entities)
native_mesh = Geom::PolygonMesh.new(mesh["vertices"].count / 3)
points = []
mesh["vertices"].each_slice(3) do |pt|
@@ -138,18 +119,52 @@ module SpeckleSystems::SpeckleConnector::ToNative
native_mesh.add_polygon(indices.map { |index| points[index] })
end
entities.add_faces_from_mesh(native_mesh, 4, material_to_native(mesh["renderMaterial"]))
native_mesh
end
def _hidden_edges_mesh_to_native_mesh(mesh, entities)
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
edge_flags = mesh["faceEdgeFlags"]
faces = mesh["faces"]
loops = []
flags = []
while faces.count.positive?
num_pts = faces.shift
# 0 -> 3, 1 -> 4 to preserve backwards compatibility
num_pts += 3 if num_pts < 3
indices = faces.shift(num_pts)
current_edge_flags = edge_flags.shift(num_pts)
outer_loop = indices.map { |index| points[index] }
if current_edge_flags.include?(true)
loops << outer_loop
flags << current_edge_flags
else
native_mesh.add_polygon(outer_loop)
end
end
entities.add_faces_from_mesh(native_mesh, 0, material_to_native(mesh["renderMaterial"]))
loops.each do |l|
loop_flags = flags.shift
face = entities.add_face(l)
face.edges.each_with_index { |edge, index| edge.soft = edge.smooth = loop_flags[index] }
end
native_mesh
end
# creates a component definition and instance from a mesh
def mesh_to_native_component(mesh, entities)
mesh_id = mesh["applicationId"] || mesh["id"]
definition = component_definition_to_native([mesh], "def::#{mesh_id}")
find_and_erase_existing_instance(definition, mesh_id)
instance = entities.add_instance(definition, Geom::Transformation.new)
instance.name = mesh_id
instance.material = material_to_native(mesh["renderMaterial"])
# creates a component definition and instance from a speckle object with a display value
def display_value_to_native_component(obj, entities)
obj_id = obj["applicationId"].to_s.empty? ? obj["id"] : obj["applicationId"]
definition = component_definition_to_native(obj["displayValue"], "def::#{obj_id}")
find_and_erase_existing_instance(definition, obj_id)
transform = obj["transform"].nil? ? Geom::Transformation.new : transform_to_native(obj["transform"])
instance = entities.add_instance(definition, transform)
instance.name = obj_id
instance
end
@@ -162,7 +177,7 @@ module SpeckleSystems::SpeckleConnector::ToNative
definition ||= Sketchup.active_model.definitions.add(name)
geometry.each { |obj| convert_to_native(obj, definition.entities) }
puts("definition finished: #{name} (#{application_id})")
puts(" entity count: #{definition.entities.count}")
# puts(" entity count: #{definition.entities.count}")
definition
end
@@ -184,7 +199,6 @@ module SpeckleSystems::SpeckleConnector::ToNative
block["blockDefinition"]["applicationId"]
)
name = block["name"].nil? || block["name"].empty? ? block["id"] : block["name"]
find_and_erase_existing_instance(definition, name, block["applicationId"])
transform = transform_to_native(
block["transform"].is_a?(Hash) ? block["transform"]["value"] : block["transform"],
block["units"]
@@ -195,6 +209,8 @@ module SpeckleSystems::SpeckleConnector::ToNative
else
entities.add_instance(definition, transform)
end
# erase existing instances after creation and before rename because you can't have definitions without instances
find_and_erase_existing_instance(definition, name, block["applicationId"])
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"])
+53 -22
View File
@@ -63,27 +63,25 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
component_def.entities.each do |entity|
nested_blocks.push(component_instance_to_speckle(entity)) if entity.typename == "ComponentInstance"
next unless %w[Edge Face].include?(entity.typename)
next unless %w[Face].include?(entity.typename)
if entity.typename == "Edge"
lines.push(edge_to_speckle(entity))
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)
if face.loops.size > 1
mesh = face.mesh
mat_groups[mat_id]["@(31250)vertices"].push(*mesh_points_to_array(mesh))
mat_groups[mat_id]["@(62500)faces"].push(*mesh_faces_to_array(mesh, mat_groups[mat_id][:pt_count] - 1))
mat_groups[mat_id]["@(31250)faceEdgeFlags"].push(*mesh_edge_flags_to_array(mesh))
else
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)
if face.loops.size > 1
mesh = face.mesh
mat_groups[mat_id]["@(31250)vertices"].push(*mesh_points_to_array(mesh))
mat_groups[mat_id]["@(62500)faces"].push(*mesh_faces_to_array(mesh, mat_groups[mat_id][:pt_count] - 1))
else
mat_groups[mat_id]["@(31250)vertices"].push(*face_vertices_to_array(face))
mat_groups[mat_id]["@(62500)faces"].push(*face_indices_to_array(face, mat_groups[mat_id][:pt_count]))
end
mat_groups[mat_id][:pt_count] += face.vertices.count
mat_groups[mat_id]["@(31250)vertices"].push(*face_vertices_to_array(face))
mat_groups[mat_id]["@(62500)faces"].push(*face_indices_to_array(face, mat_groups[mat_id][:pt_count]))
mat_groups[mat_id]["@(31250)faceEdgeFlags"].push(*face_edge_flags_to_array(face))
end
mat_groups[mat_id][:pt_count] += face.vertices.count
end
mat_groups.values.map { |group| group.delete(:pt_count) }
@@ -123,6 +121,7 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
bbox: bounds_to_speckle(bounds),
"@(31250)vertices" => [],
"@(62500)faces" => [],
"@(31250)faceEdgeFlags" => [],
"@(31250)textureCoordinates" => [],
pt_count: 0,
renderMaterial: face.material.nil? ? nil : material_to_speckle(face.material)
@@ -130,9 +129,8 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
end
# get an array of face indices from a sketchup polygon mesh
def mesh_faces_to_array(mesh, offset)
def mesh_faces_to_array(mesh, offset = 0)
faces = []
puts(faces)
mesh.polygons.each do |poly|
faces.push(
poly.count, *poly.map { |index| index.abs + offset }
@@ -141,6 +139,17 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
faces
end
# get an array of face indices from a sketchup polygon mesh INCLUDING negative indices for hidden meshes
def mesh_faces_with_edges_to_array(mesh, offset)
faces = []
mesh.polygons.each do |poly|
faces.push(
poly.count, *poly.map { |index| index.positive? ? index + offset : index - offset }
)
end
faces
end
# get a flat array of vertices from a sketchup polygon mesh
def mesh_points_to_array(mesh)
pts_array = []
@@ -154,6 +163,16 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
pts_array
end
def mesh_edge_flags_to_array(mesh)
edge_flags = []
mesh.polygons.each do |poly|
edge_flags.push(
*poly.map(&:negative?)
)
end
edge_flags
end
# get a flat array of face indices from a sketchup face
def face_indices_to_array(face, offset)
face_array = [face.vertices.count]
@@ -161,6 +180,18 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
face_array
end
# get a flat array of face indices from a sketchup face
def face_indices_with_edges_to_array(face, offset = 1)
soft_edges = face.outer_loop.edges.map(&:soft?)
face_array = [face.vertices.count]
face_array.push(*face.vertices.count.times.map { |index| soft_edges[index] ? -(index + offset) : index + offset })
face_array
end
def face_edge_flags_to_array(face)
face.outer_loop.edges.map(&:soft?)
end
# get a flat array of vertices from a list of sketchup vertices
def face_vertices_to_array(face)
pts_array = []
@@ -171,7 +202,6 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
pts_array
end
def uvs_to_array(mesh)
uvs_array = []
@@ -192,7 +222,8 @@ module SpeckleSystems::SpeckleConnector::ToSpeckle
renderMaterial: face.material.nil? ? nil : material_to_speckle(face.material),
bbox: bounds_to_speckle(face.bounds),
"@(31250)vertices" => mesh.nil? ? face_vertices_to_array(face) : mesh_points_to_array(mesh),
"@(62500)faces" => mesh.nil? ? face_indices_to_array(face, 0) : mesh_faces_to_array(mesh, -1)
"@(62500)faces" => mesh.nil? ? face_indices_to_array(face, 0) : mesh_faces_to_array(mesh, -1),
"@(31250)faceEdgeFlags" => mesh.nil? ? face_edge_flags_to_array(face) : mesh_edge_flags_to_array(mesh),
}
end
+7369 -4742
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -13,9 +13,9 @@
"dependencies": {
"@speckle/objectloader": "^2.6.0",
"aws-sdk": "^2.981.0",
"core-js": "^3.6.5",
"debounce": "^1.2.1",
"mixpanel-browser": "^2.45.0",
"regenerator-runtime": "^0.13.9",
"register-service-worker": "^1.7.1",
"sqlite3": "^5.0.2",
"v-tooltip": "^2.1.3",
+2
View File
@@ -1,3 +1,5 @@
import 'regenerator-runtime/runtime'
import Vue from 'vue'
import App from './App.vue'
import router from './router'