Skip to content

Commit

Permalink
Merge pull request #70 from rdeits/rd/new-meshcat
Browse files Browse the repository at this point in the history
update to the newest meshcat js
  • Loading branch information
rdeits authored Nov 16, 2018
2 parents 3ee73d1 + 7a23145 commit 3b46aea
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
2 changes: 1 addition & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion src/lowering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions test/scenes.jl
Original file line number Diff line number Diff line change
@@ -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 <object> here, see the documentation for
# set_property at https://github.com/rdeits/meshcat
setprop!(vis["/Lights/SpotLight/<object>"], "castShadow", true)
setprop!(vis["/Lights/DirectionalLight"], "visible", false)
# To understand why we need the <object> here, see the documentation for
# set_property at https://github.com/rdeits/meshcat
setprop!(vis["/Lights/AmbientLight/<object>"], "intensity", 0.44)
end
end
10 changes: 3 additions & 7 deletions test/visualizer.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Blink
import GeometryTypes

notinstalled = !AtomShell.isinstalled()
notinstalled && AtomShell.install()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3b46aea

Please sign in to comment.