Skip to content

Commit

Permalink
Lines and Line materials added.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvarkey committed Sep 15, 2015
1 parent 9e72d51 commit f184a91
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
66 changes: 65 additions & 1 deletion src/render.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Compat
using Colors
export mesh, box, sphere, pyramid, cylinder, torus, parametric, meshlines,
material, camera, pointlight, spotlight, ambientlight, vertex
material, camera, pointlight, spotlight, ambientlight, vertex, line,
linematerial

"""
Creates a Three-js mesh at position (`x`,`y`,`z`).
Expand Down Expand Up @@ -233,3 +234,66 @@ function ambientlight(color::Colors.RGB{U8}=colorant"white")
attributes = @compat Dict(:kind => "ambient", :color => colorString)
)
end

"""
Creates a line tag.
Line tags should be a child of the scene tag created by `initscene`.
Vertices of the line to be drawn should be nested inside this
tag using `vertex`.
The material to be associated with the line can be set using
`linematerial` which should also be a child of the line tag.
Requires the total number of vertices in the line as an argument.
A keyword argument, `kind` is also provided to set how the lines
should be drawn. `"strip"` and `"pieces"` are the possible values.
The line can be translated and rotated using keyword arguments,
`x`,`y`,`z` for the (x, y, z) coordinate and `rx`, `ry` and `rz`
as the rotation about the X, Y and Z axes respectively.
"""
function line(
totalvertices::Int;
x::Float64 = 0.0,
y::Float64 = 0.0,
z::Float64 = 0.0,
rx::Float64 = 0.0,
ry::Float64 = 0.0,
rz::Float64 = 0.0,
kind::String = "strip"
)
Elem(
:"three-js-line",
attributes = @compat Dict(
:totalvertices => totalvertices,
:x => x,
:y => y,
:z => z,
:rx => rx,
:ry => ry,
:rz => rz,
:kind => kind,
)
)
end

"""
Creates a line material tag.
These tags should be the child of a line tag.
Possible properties that can be set are:
- `kind` - `"basic"` or `"dashed"`
- `color` - Any CSS color value.
- `linewidth` - Sets the width of the line.
- `scale` - For `"dashed"` only. Scale of the dash.
- `dashSize` - For `"dashed"` only. Sets size of the dash.
- `linecap` - Ends of the line. Possible values are `"round"`, `"butt"`, and
`"square"`.
- `linejoin` - Appearance of line joins. Possible values are `"round"`,
`"bevel"` and `"miter"`.
Refer the ThreeJS docs for [`LineDashedMaterial`](http://threejs.org/docs/#Reference/Materials/LineDashedMaterial)
and [`LineBasicMaterial`](http://threejs.org/docs/#Reference/Materials/LineBasicMaterial)
for more details.
These properties should be passed in as a `Dict`.
"""
function linematerial(props = @compat Dict())
Elem(:"three-js-line-material", attributes = props)
end
42 changes: 42 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,48 @@ facts("Testing Render Elem Outputs") do
)
)
end
context("Testing line") do
@fact line(4, x = 10.0, y = 10.0, z = 10.0, rx = 20.0, ry = 15.0,
rz = 240.0, kind = "pieces") -->
Elem(
:"three-js-line",
attributes = @compat Dict(
:totalvertices => 4,
:kind => "pieces",
:x => 10.0,
:y => 10.0,
:z => 10.0,
:rx => 20.0,
:ry => 15.0,
:rz => 240.0
)
)
@fact line(4) -->
Elem(
:"three-js-line",
attributes = @compat Dict(
:totalvertices => 4,
:kind => "strip",
:x => 0.0,
:y => 0.0,
:z => 0.0,
:rx => 0.0,
:ry => 0.0,
:rz => 0.0
)
)
end
context("Testing line material") do
@fact linematerial() --> Elem(:"three-js-line-material", attributes=@compat Dict())
@fact linematerial(@compat Dict(:kind=>"dashed", :color=>"red")) -->
Elem(
:"three-js-line-material",
attributes = @compat Dict(
:kind => "dashed",
:color => "red"
)
)
end
end

facts("Testing property helpers") do
Expand Down

0 comments on commit f184a91

Please sign in to comment.