From e56f1610e3d8bbd3ad7efef91d01d0de957ead8d Mon Sep 17 00:00:00 2001 From: Henrique Ferrolho Date: Thu, 21 Nov 2024 17:20:47 +0000 Subject: [PATCH 1/2] Update MeshCat for GeometryBasics v0.5 refactor --- Project.toml | 4 ++-- notebooks/Project.toml | 4 ++-- src/MeshCat.jl | 3 +-- src/geometry.jl | 2 +- src/lowering.jl | 20 +++++++++----------- test/visualizer.jl | 4 ++-- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Project.toml b/Project.toml index 7939d85..17a312c 100644 --- a/Project.toml +++ b/Project.toml @@ -29,9 +29,9 @@ Colors = "0.9, 0.10, 0.11, 0.12, 0.13" CoordinateTransformations = "0.5, 0.6" DocStringExtensions = "0.5, 0.6, 0.7, 0.8, 0.9" FFMPEG = "0.2, 0.3, 0.4" -GeometryBasics = "0.3, 0.4" +GeometryBasics = "0.5" HTTP = "1" -MeshIO = "0.4" +MeshIO = "0.5" Meshing = "0.7" MsgPack = "1" Parameters = "0.10, 0.11, 0.12, 0.13" diff --git a/notebooks/Project.toml b/notebooks/Project.toml index 2f0d173..1a29a0a 100644 --- a/notebooks/Project.toml +++ b/notebooks/Project.toml @@ -11,6 +11,6 @@ Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc" [compat] Colors = "0.9, 0.10, 0.11, 0.12, 0.13" FileIO = "1" -GeometryBasics = "0.3, 0.4" +GeometryBasics = "0.5" Meshing = "0.7" -MeshIO = "0.4" +MeshIO = "0.5" diff --git a/src/MeshCat.jl b/src/MeshCat.jl index 8fa38ce..11e312f 100644 --- a/src/MeshCat.jl +++ b/src/MeshCat.jl @@ -10,7 +10,7 @@ using GeometryBasics: GeometryBasics, GeometryPrimitive, HyperRectangle, HyperSphere, - MeshMeta, + MetaMesh, NgonFace, OffsetInteger, Point, @@ -20,7 +20,6 @@ using GeometryBasics: GeometryBasics, Vec, decompose, meta, - metafree, origin, radius, texturecoordinates, diff --git a/src/geometry.jl b/src/geometry.jl index 5c391b9..b3d1a0c 100644 --- a/src/geometry.jl +++ b/src/geometry.jl @@ -71,7 +71,7 @@ intrinsic_transform(g::HyperRectangle) = Translation(center(g)...) intrinsic_transform(g::HyperSphere) = Translation(center(g)...) intrinsic_transform(g::HyperEllipsoid) = Translation(center(g)...) ∘ LinearMap(SMatrix{3, 3}(SDiagonal(radii(g)...))) -function intrinsic_transform(g::Cylinder{3}) +function intrinsic_transform(g::Cylinder) # Three.js wants a cylinder to lie along the y axis R = rotation_between(SVector(0, 1, 0), g.extremity - origin(g)) Translation(center(g)) ∘ LinearMap(R) diff --git a/src/lowering.jl b/src/lowering.jl index d902bd7..fcd6c01 100644 --- a/src/lowering.jl +++ b/src/lowering.jl @@ -61,7 +61,7 @@ function lower(box::HyperRectangle{3}) ) end -function lower(c::Cylinder{3}) +function lower(c::Cylinder) Dict{String, Any}( "uuid" => string(uuid1()), "type" => "CylinderGeometry", @@ -144,27 +144,25 @@ to_zero_index(f::AbstractNgonFace{N}) where {N} = SVector(raw.(convert(NgonFace{ lower(faces::Vector{<:AbstractFace}) = lower(to_zero_index.(faces)) -function lower(mesh_meta::M) where {M <: AbstractMesh} - mesh = metafree(mesh_meta) +function lower(meta_mesh::M) where {M <: AbstractMesh} attributes = Dict{String, Any}( - "position" => lower(convert(Vector{Point3f}, decompose(Point3f, mesh))), + "position" => lower(convert(Vector{Point3f}, decompose(Point3f, meta_mesh))), ) - if M <: MeshMeta - metadata = meta(mesh_meta) - if hasfield(typeof(metadata), :vertexColors) - attributes["color"] = lower(convert(Vector{RGB{Float32}}, metadata.vertexColors)) + if M <: MetaMesh + if haskey(meta_mesh, :vertexColors) + attributes["color"] = lower(convert(Vector{RGB{Float32}}, meta_mesh[:vertexColors])) end end - uv = texturecoordinates(mesh) + uv = texturecoordinates(meta_mesh) if uv !== nothing - attributes["uv"] = lower(uv) + attributes["uv"] = lower(GeometryBasics.values(uv)) end Dict{String, Any}( "uuid" => string(uuid1()), "type" => "BufferGeometry", "data" => Dict{String, Any}( "attributes" => attributes, - "index" => lower(decompose(GLTriangleFace, mesh)) + "index" => lower(decompose(GLTriangleFace, meta_mesh)) ) ) end diff --git a/test/visualizer.jl b/test/visualizer.jl index 7461e94..8edc7fb 100644 --- a/test/visualizer.jl +++ b/test/visualizer.jl @@ -160,11 +160,11 @@ end [Point(0., 0, 0), Point(1., 0, 0), Point(1., 1, 0)], [NgonFace(1, 2, 3)]) # Wrap that mesh with metadata encoding the vertex colors - mesh_meta = meta(geometry, vertexColors=[RGB(1, 0, 0), RGB(0, 1, 0), RGB(0, 0, 1)]) + meta_mesh = MetaMesh(geometry, vertexColors=[RGB(1, 0, 0), RGB(0, 1, 0), RGB(0, 0, 1)]) # Create a Gouraud-shaded material with vertex coloring enabled material = MeshLambertMaterial(vertexColors=true) # Add it to the scene - setobject!(v[:vertex_color_mesh], mesh_meta, material) + setobject!(v[:vertex_color_mesh], meta_mesh, material) settransform!(v[:vertex_color_mesh], Translation(1, -1.5, 0)) end From de26731569621c67bb46dd6c49f09d125c99884d Mon Sep 17 00:00:00 2001 From: Henrique Ferrolho Date: Wed, 4 Dec 2024 08:18:56 +0000 Subject: [PATCH 2/2] Bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 17a312c..d47bb19 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MeshCat" uuid = "283c5d60-a78f-5afe-a0af-af636b173e11" authors = ["Robin Deits "] -version = "1.0.0" +version = "1.0.1" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"