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

added setobject! for HomogenousMesh that uses the color in HMesh #62

Merged
merged 6 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 0 additions & 2 deletions src/abstract_visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ function setcontrol! end
# Convenient shortcuts for creating new objects
setobject!(vis::AbstractVisualizer, geom::GeometryLike) = setobject!(vis, Object(geom))
setobject!(vis::AbstractVisualizer, geom::GeometryLike, material::AbstractMaterial) = setobject!(vis, Object(geom, material))


13 changes: 12 additions & 1 deletion src/objects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ geometry(o::Object) = o.geometry
material(o::Object) = o.material
threejs_type(o::Object) = o._type

defaultmaterial(args...; kw...) = MeshLambertMaterial(args...; kw...)

# Default object types for geometries, point clouds, and triads
Object(g::GeometryLike) = Mesh(g)
Object(g::GeometryLike, m::AbstractMaterial) = Mesh(g, m)
Expand All @@ -20,7 +22,16 @@ Object(c::PointCloud, m::AbstractMaterial) = Points(c, m)
Object(t::Triad) = LineSegments(t, LineBasicMaterial(vertexColors=2))

Mesh(g, m) = Object(g, m, "Mesh")
Mesh(geometry::GeometryLike) = Mesh(geometry, MeshLambertMaterial())
Mesh(geometry::GeometryLike) = Mesh(geometry, defaultmaterial())

function Mesh(g::HomogenousMesh)
if g.color == nothing
Mesh(g, defaultmaterial())
else
Mesh(g, defaultmaterial(color=g.color))
end
end

Points(g, m) = Object(g, m, "Points")
Points(geometry::GeometryLike; kw...) = Points(geometry, PointsMaterial(kw...))
LineSegments(g, m) = Object(g, m, "LineSegments")
Expand Down
10 changes: 10 additions & 0 deletions test/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ end
settransform!(v[:cat], Translation(0, -1, 0) ∘ LinearMap(RotZ(π)) ∘ LinearMap(RotX(π/2)))
end

@testset "cat_color" begin
mesh = load(cat_mesh_path)
color = RGBA{Float32}(0.5, 0.5, 0.5, 0.5)
mesh_color = HomogenousMesh(vertices=mesh.vertices, faces=mesh.faces, color=color)
object = Object(mesh_color)
@test material(object).color == color
mesh_color = setobject!(v[:cat_color], mesh_color)
settransform!(v[:cat_color], Translation(0, -2.0, 0) ∘ LinearMap(RotZ(π)) ∘ LinearMap(RotX(π/2)))
end

@testset "textured valkyrie" begin
head = Mesh(
load(joinpath(MeshCat.VIEWER_ROOT, "..", "data", "head_multisense.obj"), GLUVMesh),
Expand Down