Skip to content

Commit

Permalink
Merge pull request #261 from rdeits/hf/dev
Browse files Browse the repository at this point in the history
Update MeshCat for GeometryBasics v0.5 refactor
  • Loading branch information
ferrolho authored Dec 4, 2024
2 parents 39d8b51 + de26731 commit 0386317
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshCat"
uuid = "283c5d60-a78f-5afe-a0af-af636b173e11"
authors = ["Robin Deits <[email protected]>"]
version = "1.0.0"
version = "1.0.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 1 addition & 2 deletions src/MeshCat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using GeometryBasics: GeometryBasics,
GeometryPrimitive,
HyperRectangle,
HyperSphere,
MeshMeta,
MetaMesh,
NgonFace,
OffsetInteger,
Point,
Expand All @@ -20,7 +20,6 @@ using GeometryBasics: GeometryBasics,
Vec,
decompose,
meta,
metafree,
origin,
radius,
texturecoordinates,
Expand Down
2 changes: 1 addition & 1 deletion src/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 9 additions & 11 deletions src/lowering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

2 comments on commit 0386317

@ferrolho
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/120651

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.1 -m "<description of version>" 03863175e639f7436736800270ae76880e4fe7e0
git push origin v1.0.1

Please sign in to comment.