Skip to content

Commit

Permalink
Merge pull request #28 from rdeits/webio
Browse files Browse the repository at this point in the history
Switch to WebIO under the hood
  • Loading branch information
rdeits authored May 18, 2018
2 parents df327b6 + 9f4fbb5 commit ba65f7d
Show file tree
Hide file tree
Showing 19 changed files with 383 additions and 617 deletions.
41 changes: 21 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
## Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx
julia:
- 0.6
- nightly
matrix:
include:
- os: linux
julia: 0.6
env: TESTCMD="xvfb-run julia"
- os: linux
julia: nightly
env: TESTCMD="xvfb-run julia"
- os: osx
julia: 0.6
env: TESTCMD="julia"
- os: osx
julia: nightly
env: TESTCMD="julia"
allow_failures:
- julia: nightly

notifications:
email: false
git:
Expand All @@ -15,20 +26,10 @@ branches:
only:
- master

addons:
apt:
packages:
- libzmq3

# uncomment the following lines to allow failures on nightly julia
# (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia: nightly

## uncomment the following lines to override the default test script
#script:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("MeshCat"); Pkg.test("MeshCat"; coverage=true)'
# uncomment the following lines to override the default test script
script:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("MeshCat"); Pkg.test("MeshCat"; coverage=true)'
- $TESTCMD -e 'Pkg.clone(pwd()); Pkg.build("MeshCat"); Pkg.test("MeshCat"; coverage=true)'
after_success:
# push coverage results to Coveralls
# push coverage results to Codecov
Expand Down
7 changes: 3 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ DocStringExtensions 0.4

# Communication
MsgPack 0.1.1
WebSockets 0.3
HttpServer 0.2
URIParser 0.2
ZMQ 0.4.2
WebIO 0.1.8
Mux 0.2.3
JSExpr 0.1.0
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

# uncomment the following lines to allow failures on nightly julia
# (tests will run but not make your overall status red)
Expand Down
2 changes: 1 addition & 1 deletion assets/meshcat
62 changes: 43 additions & 19 deletions demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,48 @@
"vis = Visualizer()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Embed the visualizer inside this notebook\n",
"IJuliaCell(vis)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are several other ways you can open the visualizer if you like:\n",
"\n",
"### In-Browser\n",
"To open the meshcat viewer in your browser, you can simply do:\n",
"\n",
"```julia\n",
"open(vis)\n",
"```\n",
"\n",
"### Standalone (with Blink.jl)\n",
"\n",
"Blink.jl allows you to create standalone web apps with Electron. To use\n",
"Blink with MeshCat, you need to install Blink:\n",
"\n",
"```julia\n",
"Pkg.add(\"Blink\")\n",
"using Blink\n",
"Blink.AtomShell.install()\n",
"```\n",
"\n",
"Then you can open MeshCat in a Blink window with:\n",
"\n",
"```julia\n",
"open(vis, Blink.Window())\n",
"```\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -53,16 +95,6 @@
"# wait(vis)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# We can also embed the visualizer inside the notebook\n",
"IJuliaCell(vis)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -351,15 +383,6 @@
"`MeshCat.jl` supports a few extra types of geometry that you may want to visualize. One such geometry is a point cloud: "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"delete!(vis)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -375,6 +398,7 @@
"metadata": {},
"outputs": [],
"source": [
"delete!(vis)\n",
"pointcloud = PointCloud([[x, 0 + 0.01 * randn(), 0.5] for x in linspace(-1, 1, 1000)])\n",
"setobject!(vis[:pointcloud], pointcloud)"
]
Expand Down
72 changes: 63 additions & 9 deletions src/MeshCat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ module MeshCat
using GeometryTypes
using CoordinateTransformations
using Rotations: rotation_between
using ZMQ

using Colors: Color, Colorant, RGB, RGBA, alpha
using StaticArrays: StaticVector, SVector, SDiagonal
using GeometryTypes: raw
using Parameters: @with_kw
using Base.Random: UUID, uuid1
using URIParser: escape
using DocStringExtensions
using Requires
using Mux: page
using WebIO
using JSExpr

import Base: delete!, length
import MsgPack: pack, Ext
Expand All @@ -38,19 +40,71 @@ export Visualizer,
LineSegments,
setobject!,
settransform!,
delete!,
url

include("servers/trees.jl")
include("servers/zmqserver.jl")
using .ZMQServer: ZMQWebSocketBridge, zmq_url, web_url, VIEWER_ROOT
delete!

include("trees.jl")
using .SceneTrees
include("geometry.jl")
include("objects.jl")
include("commands.jl")
include("lowering.jl")
include("msgpack.jl")
include("visualizer.jl")
include("ijulia.jl")

const VIEWER_ROOT = joinpath(@__DIR__, "..", "assets", "meshcat", "dist")

Base.open(vis::Visualizer, args...; kw...) = open(vis.core, args...; kw...)

function Base.open(core::CoreVisualizer, port::Integer)
WebIO.webio_serve(page("/", req -> core.scope), port)
url = "http://127.0.0.1:$port"
info("Serving MeshCat visualizer at $url")
open_url(url)
end

function open_url(url)
try
if is_windows()
run(`start $url`)
elseif is_apple()
run(`open $url`)
elseif is_linux()
run(`xdg-open $url`)
end
catch e
println("Could not open browser automatically: $e")
println("Please open the following URL in your browser:")
println(url)
end
end

function Base.open(core::CoreVisualizer; default_port=8700, max_retries=500)
for port in default_port + (0:max_retries)
server = try
listen(port)
catch e
if e isa Base.UVError
continue
end
end
close(server)
# It is *possible* that a race condition could occur here, in which
# some other process grabs the given port in between the close() above
# and the open() below. But it's unlikely and would not be terribly
# damaging (the user would just have to call open() again).
return open(core, port)
end
end

@require Blink begin
function Base.open(core::CoreVisualizer, w::Blink.AtomShell.Window)
# Ensure the window is ready
Blink.js(w, "ok")
# Set its contents
Blink.body!(w, core.scope)
w
end
end


end
27 changes: 19 additions & 8 deletions src/commands.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
abstract type AbstractCommand end

struct Path
entries::Vector{String}
end

Base.convert(::Type{Path}, x::AbstractVector{<:AbstractString}) = Path(x)
Base.vcat(p::Path, s...) = Path(vcat(p.entries, s...))
Base.show(io::IO, p::Path) = print(io, string('/', join(p.entries, '/')))

struct SetObject{O <: AbstractObject} <: AbstractCommand
object::O
path::Path
Expand All @@ -21,3 +13,22 @@ end
struct Delete <: AbstractCommand
path::Path
end

abstract type AbstractControl end

struct Button <: AbstractControl
observer::Observable
name::String
end

struct NumericControl{T} <: AbstractControl
observer::Observable
name::String
value::T
min::T
max::T
end

struct SetControl <: AbstractCommand
control::AbstractControl
end
Loading

0 comments on commit ba65f7d

Please sign in to comment.