Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MeshCat for GeometryBasics v0.5 refactor #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
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
Loading