diff --git a/deps/build.jl b/deps/build.jl index 5bf9f95..0b90528 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -2,7 +2,7 @@ using Base.Filesystem using BinDeps: unpack_cmd, download_cmd -const meshcat_sha = "b34c2668c94675aa582c5dc2024fdff052db9511" +const meshcat_sha = "33c1213a26d2e05a3b6ca95c7bcb94689f99e005" const meshcat_url = "https://github.com/rdeits/meshcat/archive/$meshcat_sha.zip" const assets_dir = normpath(joinpath(@__DIR__, "..", "assets")) diff --git a/src/lowering.jl b/src/lowering.jl index a5f644c..c4cedfc 100644 --- a/src/lowering.jl +++ b/src/lowering.jl @@ -8,7 +8,7 @@ function lower end lower(x::Vector) = x lower(x::String) = x -lower(x::Union{Int32, Int64, Float32, Float64}) = x +lower(x::Union{Bool, Int32, Int64, Float32, Float64}) = x function lower(t::Transformation) H = [transform_deriv(t, Vec(0., 0, 0)) t(Vec(0., 0, 0)); diff --git a/src/visualizer.jl b/src/visualizer.jl index 47cdda8..ff0b527 100644 --- a/src/visualizer.jl +++ b/src/visualizer.jl @@ -18,6 +18,7 @@ mutable struct CoreVisualizer this.viewer = @new mc.Viewer(element) $request_channel[] = String(Date.now()) window.document.body.style.margin = "0" + window.meshcat_viewer = this.viewer end) onjs(command_channel, @js function(val) diff --git a/test/runtests.jl b/test/runtests.jl index d0945ea..eff7250 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,8 +11,11 @@ using MeshIO, FileIO include("paths.jl") include("visualizer.jl") include("notebook.jl") + include("scenes.jl") end +sleep(10) + module ModuleTest # Test for any https://github.com/JuliaLang/julia/issues/21653 # related issues when MeshCat is included in another module diff --git a/test/scenes.jl b/test/scenes.jl new file mode 100644 index 0000000..21020d0 --- /dev/null +++ b/test/scenes.jl @@ -0,0 +1,48 @@ +using Test +using MeshCat +using FileIO +using CoordinateTransformations +import GeometryTypes + +# Demonstrate a couple of different lighting configurations, and +# show how the lighting settings can be manipulated programmatically. +@testset "Lighting Scenes" begin + cat_mesh_path = joinpath(dirname(pathof(GeometryTypes)), "..", "test", "data", "cat.obj") + cat = load(cat_mesh_path) + + function add_cats!(vis::Visualizer) + setobject!(vis["floor"], HyperRectangle(Vec(-10, -10, -0.01), Vec(20, 20, 0.01))) + for x in range(-5, stop=5, step=2) + for y in range(-5, stop=5, step=2) + setobject!(vis["cat"][string(x)][string(y)], cat) + settransform!(vis["cat"][string(x)][string(y)], Translation(x, y, 0) ∘ LinearMap(RotZ(π)) ∘ LinearMap(RotX(π/2))) + end + end + end + + @testset "Default" begin + vis = Visualizer() + if !haskey(ENV, "CI") + open(vis) + wait(vis) + end + add_cats!(vis) + end + + @testset "SpotLight with shadows" begin + vis = Visualizer() + if !haskey(ENV, "CI") + open(vis) + wait(vis) + end + add_cats!(vis) + setprop!(vis["/Lights/SpotLight"], "visible", true) + # To understand why we need the here, see the documentation for + # set_property at https://github.com/rdeits/meshcat + setprop!(vis["/Lights/SpotLight/"], "castShadow", true) + setprop!(vis["/Lights/DirectionalLight"], "visible", false) + # To understand why we need the here, see the documentation for + # set_property at https://github.com/rdeits/meshcat + setprop!(vis["/Lights/AmbientLight/"], "intensity", 0.44) + end +end diff --git a/test/visualizer.jl b/test/visualizer.jl index 25b3a95..947696f 100644 --- a/test/visualizer.jl +++ b/test/visualizer.jl @@ -1,4 +1,5 @@ using Blink +import GeometryTypes notinstalled = !AtomShell.isinstalled() notinstalled && AtomShell.install() @@ -36,14 +37,9 @@ function GeometryTypes.decompose(::Type{P}, c::CustomGeometry) where {P <: Point convert(Vector{P}, [Point(0., 0, 0), Point(0., 1, 0), Point(0., 0, 1)]) end -@static if VERSION < v"0.7-" - const cat_mesh_path = joinpath(Pkg.dir("GeometryTypes"), "test", "data", "cat.obj") -else - import GeometryTypes - const cat_mesh_path = joinpath(dirname(pathof(GeometryTypes)), "..", "test", "data", "cat.obj") -end - @testset "self-contained visualizer" begin + cat_mesh_path = joinpath(dirname(pathof(GeometryTypes)), "..", "test", "data", "cat.obj") + @testset "shapes" begin v = vis[:shapes] delete!(v)