Skip to content

Commit

Permalink
Can create polyhedrons now specifying vertices and faces.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvarkey committed Sep 15, 2015
1 parent 46f3fa1 commit 672edce
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/render.jl
Expand Up @@ -2,7 +2,7 @@ import Compat
using Colors
export mesh, box, sphere, pyramid, cylinder, torus, parametric, meshlines,
material, camera, pointlight, spotlight, ambientlight, vertex, line,
linematerial
linematerial, geometry, face

"""
Creates a Three-js mesh at position (`x`,`y`,`z`).
Expand Down Expand Up @@ -74,6 +74,41 @@ function torus(radius::Float64,tube::Float64)
)
end

"""
Creates a geometry.
This should be a child of a `mesh`.
Vertices of the geometry are specified as `vertex` children of the `geometry`
element. Faces are specified as `face` children.
Total number of vertices and total number of faces are arguments to this
function.
"""
function geometry(totalvertices::Int, totalfaces::Int)
Elem(
:"three-js-geometry",
attributes = @compat Dict(
:totalvertices => totalvertices,
:totalfaces => totalfaces
)
)
end

"""
Creates a face with vertex indices `a`, `b` and `c`.
A keyword argument `color` is accepted setting the color of the face.
NOTE: Face colors come into effect only when the related material has
`FaceColors` as its `colorkind` property.
"""
function face(a::Int, b::Int, c::Int; color::RGB{U8} = colorant"white")
colorString = string("#"*hex(color))
Elem(
:"three-js-face",
attributes = @compat Dict(
:a => a, :b => b, :c => c, :faceColor => colorString
)
)
end

"""
Creates a vertex at position `(x,y,z)`.
"""
Expand Down
23 changes: 23 additions & 0 deletions test/runtests.jl
Expand Up @@ -190,6 +190,29 @@ facts("Testing Render Elem Outputs") do
attributes = @compat Dict(:x => 2.0, :y => 3.0, :z => 4.0)
)
end
context("Testing face") do
@fact face(1, 2, 3) -->
Elem(
:"three-js-face",
attributes = @compat Dict(
:a => 1, :b => 2, :c => 3, :faceColor => "#FFFFFF"
)
)
@fact face(1, 2, 3; color = colorant"red") -->
Elem(
:"three-js-face",
attributes = @compat Dict(
:a => 1, :b => 2, :c => 3, :faceColor => "#FF0000"
)
)
end
context("Testing geometry") do
@fact geometry(4, 5) -->
Elem(
:"three-js-geometry",
attributes = @compat Dict(:totalvertices => 4, :totalfaces => 5)
)
end
context("Testing light tags") do
@fact pointlight(10.0, 11.0, 12.0) -->
Elem(
Expand Down

0 comments on commit 672edce

Please sign in to comment.