Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
add a better mesh creation example (@timholy)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Feb 17, 2016
1 parent b2b5b0a commit 513ed78
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 16 deletions.
90 changes: 90 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
`GLVisualize.clicked`
args: `(::GLAbstraction.RenderObject, ::GLAbstraction.MouseButton, ::GLWindow.Screen)`
Returns two signals, one boolean signal if clicked over `robj` and another one that consists of the object clicked on and another argument indicating that it's the first click



`GLVisualize.sprites`
args: `(::Any, ::Any, ::Any)`
Main assemble functions for sprite particles. Sprites are anything like distance fields, images and simple geometries



`GLVisualize.is_hovering`
args: `(::GLAbstraction.RenderObject, ::GLWindow.Screen)`
Returns a boolean signal indicating if the mouse hovers over `robj`



`GLVisualize._default`
args: `(::Union{Array{T<:AbstractFloat,2},GLAbstraction.GPUArray{T<:AbstractFloat,2},Reactive.Signal{Array{T<:AbstractFloat,2}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
Matrices of floats are represented as 3D barplots with cubes as primitive

args: `(::Tuple{P<:Union{Char,GLVisualize.Shape,GeometryTypes.AbstractGeometry{N,T}},Union{Array{T<:FixedSizeArrays.Vec{N,T},N},GLAbstraction.GPUArray{T<:FixedSizeArrays.Vec{N,T},N},Reactive.Signal{Array{T<:FixedSizeArrays.Vec{N,T},N}}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
Vectors with `Vec` as element type are treated as vectors of rotations. The position is assumed to be implicitely on the grid the vector defines (1D,2D,3D grid)

args: `(::GeometryTypes.GeometryPrimitive{T,N}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
We plot simple Geometric primitives as particles with length one. At some point, this should all be appended to the same particle system to increase performance.

args: `(::Union{Array{T<:FixedSizeArrays.Point{N,T},1},GLAbstraction.GPUArray{T<:FixedSizeArrays.Point{N,T},1},Reactive.Signal{Array{T<:FixedSizeArrays.Point{N,T},1}}}, ::GLAbstraction.Style{:speed}, ::Dict{K,V})`
This is the most primitive particle system, which uses simple points as primitives. This is supposed to be very fast!

args: `(::Union{Array{T<:AbstractFloat,1},GLAbstraction.GPUArray{T<:AbstractFloat,1},Reactive.Signal{Array{T<:AbstractFloat,1}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
Vectors of floats are treated as barplots, so they get a HyperRectangle as default primitive.

args: `(::Union{Array{T<:FixedSizeArrays.Vec{N,T},3},GLAbstraction.GPUArray{T<:FixedSizeArrays.Vec{N,T},3},Reactive.Signal{Array{T<:FixedSizeArrays.Vec{N,T},3}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
3D matrices of vectors are 3D vector field with a pyramid (arrow) like default primitive.

args: `(::Tuple{P<:Union{Char,GLVisualize.Shape,GeometryTypes.AbstractGeometry{2,T},Type{T}},Union{Array{T<:AbstractFloat,N},GLAbstraction.GPUArray{T<:AbstractFloat,N},Reactive.Signal{Array{T<:AbstractFloat,N}}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
arrays of floats with the sprite primitive type (2D geometry + picture like), will be spaced out on a grid defined by `ranges` and will use the floating points as the z position for the primitives.

args: `(::Union{Array{T<:FixedSizeArrays.Vec{N,T},2},GLAbstraction.GPUArray{T<:FixedSizeArrays.Vec{N,T},2},Reactive.Signal{Array{T<:FixedSizeArrays.Vec{N,T},2}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
2D matrices of vectors are 2D vector field with a an unicode arrow as the default primitive.

args: `(::Union{Reactive.Signal{S<:AbstractString},S<:AbstractString}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
Transforms text into a particle system of sprites, by inferring the texture coordinates in the texture atlas, widths and positions of the characters.

args: `(::Union{Array{FixedSizeArrays.Point{N,T},1},GLAbstraction.GPUArray{FixedSizeArrays.Point{N,T},1},Reactive.Signal{Array{FixedSizeArrays.Point{N,T},1}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
Vectors of n-dimensional points get ndimensional rectangles as default primitives. (Particles)

args: `(::Tuple{P<:GeometryTypes.AbstractGeometry{N,T},Union{Array{T<:AbstractFloat,N},GLAbstraction.GPUArray{T<:AbstractFloat,N},Reactive.Signal{Array{T<:AbstractFloat,N}}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
arrays of floats with any geometry primitive, will be spaced out on a grid defined by `ranges` and will use the floating points as the height for the primitives (`scale_z`)

args: `(::Tuple{P<:Union{Char,GLVisualize.Shape,GeometryTypes.AbstractGeometry{2,T},Type{T}},Union{Array{T<:AbstractFloat,1},GLAbstraction.GPUArray{T<:AbstractFloat,1},Reactive.Signal{Array{T<:AbstractFloat,1}}}}, ::GLAbstraction.Style{StyleValue}, ::Dict{K,V})`
Sprites primitives with a vector of floats are treated as something barplot like



`GLVisualize.dragged_on`
args: `(::GLAbstraction.RenderObject, ::GLAbstraction.MouseButton, ::GLWindow.Screen)`
Returns a signal with the difference from dragstart and current mouse position, and the index from the current ROBJ id.



`GLVisualize.meshparticle`
args: `(::Any, ::Any, ::Any)`
This is the main function to assemble particles with a GLNormalMesh as a primitive



`GLVisualize.projection_switch`
args: `(::Any, ::Any, ::Any)`
creates a button that can switch between orthographic and perspective projection



`GLVisualize.Grid{N,T<:Range{T}}`
args: `(::AbstractArray{T,N}, ::Tuple)`
This constructor constructs a grid from ranges given as a tuple. Due to the approach, the tuple `ranges` can consist of NTuple(2, T) and all kind of range types. The constructor will make sure that all ranges match the size of the dimension of the array `a`.



`GLVisualize.cubecamera`
args: `(::Any)`
Creates a camera which is steered by a cube for `window`.



`GLVisualize.visualize`
args: `(::Tuple{Any}, ::Tuple{Any,Symbol})`
Creates a default visualization for any value. The dafaults can be customized via the key word arguments and the style parameter. The style can change the the look completely (e.g points displayed as lines, or particles), while the key word arguments just alter the parameters of one visualization. Always returns a context, which can be displayed on a window via view(::Context, [display]).
47 changes: 47 additions & 0 deletions examples/meshes/meshcreation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using GLVisualize, GeometryTypes, GLAbstraction, Colors

if !isdefined(:runtests)
window = glscreen()
end

baselen = 0.4f0
dirlen = 2f0
# create an array of differently colored boxes in the direction of the 3 axes
rectangles = [
(HyperRectangle{3,Float32}(Vec3f0(baselen), Vec3f0(dirlen, baselen, baselen)), RGBA(1f0,0f0,0f0,1f0)),
(HyperRectangle{3,Float32}(Vec3f0(baselen), Vec3f0(baselen, dirlen, baselen)), RGBA(0f0,1f0,0f0,1f0)),
(HyperRectangle{3,Float32}(Vec3f0(baselen), Vec3f0(baselen, baselen, dirlen)), RGBA(0f0,0f0,1f0,1f0))
]
# convert to an array of normal meshes
# note, that the constructor is a bit weird. GLNormalMesh takes a tuple of
# a geometry and a color. This means, the geometry will be converted to a GLNormalMesh
# and the color will be added afterwards, so the resulting type is a GLNormalColorMesh
meshes = map(GLNormalMesh, rectangles)
# merge them into one big mesh
# the resulting type is a GLNormalAttributeMesh, since we merged meshes with different
# attributes (colors). An array of the colors will be created and each vertex in the
# mesh will be asigned to one of the colors found there.
colored_mesh = merge(meshes)
view(visualize(colored_mesh), window)

# one could also create a GLNormalAttributeMesh manually:
colors = RGBA{U8}[RGBA{U8}(rand(), rand(), rand(), 1.0) for i=1:50]
sphere = Sphere{Float32}(Point3f0(0), 2f0)
vertices = decompose(Point3f0, sphere)
faces = decompose(GLTriangle, sphere)
# assign every vertice a random index into the color array (0-based indexes)
attribute_ids = Float32[rand(0:49) for i=1:length(vertices)]

sphere_mesh = GLNormalAttributeMesh(
vertices=vertices, faces=faces,
attributes=colors, attribute_id=attribute_ids
)

# move the model a bit to the right
moveright = translationmatrix(Vec3f0(5,0,0))

view(visualize(sphere_mesh, model=moveright), window)

if !isdefined(:runtests)
renderloop(window)
end
13 changes: 0 additions & 13 deletions examples/meshes/meshes.jl

This file was deleted.

7 changes: 6 additions & 1 deletion src/visualize/mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ function _default{M<:GLNormalMesh}(mesh::TOrSignal{M}, s::Style, data::Dict)
end
end

function _default(mesh::GLNormalColorMesh, s::Style, data::Dict)
data[:color] = decompose(RGBA{Float32}, mesh)
println(GLNormalMesh(mesh))
_default(GLNormalMesh(mesh), s, data)
end

function _default{M<:GLPlainMesh}(main::TOrSignal{M}, ::style"grid", data::Dict)
@gen_defaults! data begin
primitive = main
Expand All @@ -26,4 +32,3 @@ function _default{M<:GLPlainMesh}(main::TOrSignal{M}, ::style"grid", data::Dict)
shader = GLVisualizeShader("grid.vert", "grid.frag")
end
end

6 changes: 4 additions & 2 deletions src/visualize/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ We plot simple Geometric primitives as particles with length one.
At some point, this should all be appended to the same particle system to increase
performance.
"""
function _default{T, N}(main::GeometryPrimitive{T, N}, s::Style, data::Dict)
_default((main, [zero(Point{N, Float32})]), s, data)
function _default{G<:GeometryPrimitive}(
geometry::TOrSignal{G}, s::Style, data::Dict
)
_default((main, zeros(Point{N, Float32}, 1)), s, data)
end

"""
Expand Down

0 comments on commit 513ed78

Please sign in to comment.