API Docs for:
Show:

LS.Draw Class

Module: LS

LS.Draw allows to render basic primitives, similar to the OpenGL Fixed pipeline. It reuses local meshes when possible to avoid fragmenting the VRAM.

Constructor

LS.Draw

()

Methods

createSurfaceShader

(
  • surface_function
  • macros
  • uniforms
)
GL.Shader

A helper to create shaders when you only want to specify some basic shading

Parameters:

  • surface_function String

    GLSL code like: "vec4 surface_function( vec3 pos, vec3 normal, vec2 coord ) { return vec4(1.0); } ";

  • macros Object

    [optional] object containing the macros and value

  • uniforms Object

    [optional] object with name and type

Returns:

GL.Shader:

the resulting shader

identity

()

clears the transform matrix setting it to an identity

init

()

Sets up everything (prepare meshes, shaders, and so)

lookAt

(
  • position
  • target
  • up
)

moves an object to a given position and forces it to look to another direction Warning: it doesnt changes the camera in any way, only the transform matrix

Parameters:

  • position Vec3
  • target Vec3
  • up Vec3

multMatrix

(
  • matrix
)

Multiplies the current matrix by a given one

Parameters:

  • matrix Mat4

project

(
  • position
  • dest
)
Vec3

projects a point from 3D space to 2D space (multiply by MVP)

Parameters:

  • position Vec3
  • dest Vec3

    [optional]

Returns:

Vec3:

the point in screen space (in normalized coordinates)

push

()

pushes the transform matrix into the stack to save the state

push

()

takes the matrix from the top position of the stack to restore the last saved state

renderCircle

(
  • radius
  • segments
  • in_z
  • filled
)

Renders a circle

Parameters:

  • radius Number
  • segments Number
  • in_z Boolean

    [optional] if the circle is aligned with the z plane

  • filled Boolean

    [optional] renders the interior

renderCone

(
  • radius
  • height
  • segments
  • in_z
)

Renders a cone

Parameters:

  • radius Number
  • height Number
  • segments Number
  • in_z Boolean

    aligned with z axis

renderCylinder

(
  • radius
  • height
  • segments
  • in_z
)

Renders a cylinder

Parameters:

  • radius Number
  • height Number
  • segments Number
  • in_z Boolean

    aligned with z axis

renderGrid

(
  • dist
  • num
)

Renders a grid of lines

Parameters:

  • dist Number

    distance between lines

  • num Number

    number of lines

renderImage

(
  • position
  • image
  • size
  • fixed_size
)

Renders an image

Parameters:

  • position Vec3
  • image Image | Texture | String

    from an URL, or a texture

  • size Number

    [optional=10]

  • fixed_size Boolean

    [optional=false] (camera distance do not affect size)

renderLines

(
  • points
  • colors
  • strip
  • loop
)

Render lines given a set of points

Parameters:

  • points Float32Array | Array
  • colors Float32Array | Array

    [optional]

  • strip Bool

    [optional] if the lines are a line strip (one consecutive line)

  • loop Bool

    [optional] if strip, close loop

renderMesh

(
  • mesh
  • primitive
  • indices
  • range_start
  • range_length
)

Renders a given mesh applyting the stack transformations

Parameters:

  • mesh GL.Mesh
  • primitive Enum

    [optional=gl.TRIANGLES] GL.TRIANGLES, gl.LINES, gl.POINTS, ...

  • indices String

    [optional="triangles"] the name of the buffer in the mesh with the indices

  • range_start Number

    [optional] in case of rendering a range, the start primitive

  • range_length Number

    [optional] in case of rendering a range, the number of primitives

renderMeshesInstanced

(
  • mesh
  • matrices
  • primitive
  • indices
)

Renders several meshes in one draw call, keep in mind the shader and the browser should support instancing

Parameters:

  • mesh GL.Mesh
  • matrices Array

    an array containing all the matrices

  • primitive Enum

    [optional=gl.TRIANGLES] GL.TRIANGLES, gl.LINES, gl.POINTS, ...

  • indices String

    [optional="triangles"] the name of the buffer in the mesh with the indices

renderPlane

(
  • position
  • size
  • texture
  • shader
)

Renders a solid plane (could be textured or even with an specific shader)

Parameters:

  • position Vec3
  • size Vec2
  • texture GL.Texture
  • shader GL.Shader

renderPoints

(
  • points
  • colors
  • shader
)

Render points given a set of positions (and colors)

Parameters:

  • points Float32Array | Array
  • colors Float32Array | Array

    [optional]

  • shader GL.Shader

    [optional]

renderPointsWithSize

(
  • points
  • colors
  • sizes
  • texture
  • shader
)

Render points with color, size, and texture binded in 0

Parameters:

  • points Float32Array | Array
  • colors Float32Array | Array

    [optional]

  • sizes Float32Array | Array

    [optional]

  • texture GL.Texture

    [optional]

  • shader GL.Shader

    [optional]

renderRectangle

(
  • width
  • height
  • in_z
)

Render a wireframe rectangle of width x height

Parameters:

  • width Number
  • height Number
  • in_z Boolean

    [optional] if the plane is aligned with the z plane

renderRoundPoints

(
  • points
  • colors
  • shader
)

Render round points given a set of positions (and colors)

Parameters:

  • points Float32Array | Array
  • colors Float32Array | Array

    [optional]

  • shader GL.Shader

    [optional]

renderSolidBox

(
  • sizex
  • sizey
  • sizez
)

Renders a solid box

Parameters:

  • sizex Number
  • sizey Number
  • sizez Number

renderSolidCircle

(
  • radius
  • segments
  • in_z
)

Render a filled circle

Parameters:

  • radius Number
  • segments Number
  • in_z Boolean

    [optional] if the circle is aligned with the z plane

renderSolidCube

(
  • size
)

Renders a solid cube of size size

Parameters:

  • size Number

renderSolidSphere

(
  • radius
)

Renders an sphere

Parameters:

  • radius Number

renderText

(
  • text
  • position
)

Renders a text in 3D, in the XY plane, using the current matrix position

Parameters:

  • text String
  • position Vec3

    [optional] 3D coordinate in relation to matrix

renderWireBox

(
  • sizex
  • sizey
  • sizez
)

Renders a wire box (box made of lines, not filled)

Parameters:

  • sizex Number
  • sizey Number
  • sizez Number

renderWireCube

(
  • size
)

Renders a wire cube of size size

Parameters:

  • size Number

renderWireSphere

(
  • radius
  • segments
)

Renders three circles to form a simple spherical shape

Parameters:

  • radius Number
  • segments Number

reset

()

clears the stack

rotate

(
  • angle
  • x
  • y
  • z
)

applies a translation to the transform matrix

Parameters:

  • angle Number

    in degrees

  • x Number | Vec3

    could be the x component or the full axis

  • y Number
  • z Number

scale

(
  • x
  • y
  • z
)

changes the scale of the transform matrix. The parameters could be a vec3, a single number (then the scale is uniform in all axis) or three numbers

Parameters:

  • x Vec3 | Array | Number

    could be an array of 3, one value (if no other values are specified then it is an uniform scaling)

  • y Number
  • z Number

setAlpha

(
  • alpha
)

Sets the alpha used to paint primitives

Parameters:

  • alpha Number

setCamera

(
  • camera
)

Sets the camera to use during the rendering, this is already done by LS.Renderer

Parameters:

  • camera LS.Camera

setCameraPosition

(
  • center
)

Specifies the camera position (used to compute point size)

Parameters:

  • center Vec3

setColor

(
  • color
)

Sets the color used to paint primitives

Parameters:

  • color Vec3 | Vec4

setLineWidth

(
  • v
)

Sets the line width

Parameters:

  • v Number

    width in pixels

setMatrix

(
  • matrix
)

Specifies the transformation matrix to apply to the mesh

Parameters:

  • matrix Mat4

setPointSize

(
  • v
  • perspective
)

Sets the point size

Parameters:

  • v Number

    size of points

  • perspective Number

    [optional] if set to true, the points will be affected by perspective

setViewProjectionMatrix

(
  • view
  • projection
  • vp
)

Specifies the camera view and projection matrices

Parameters:

  • view Mat4
  • projection Mat4
  • vp Mat4

    viewprojection matrix [optional]

translate

(
  • x
  • y
  • z
)

applies a translation to the transform matrix

Parameters:

  • x Vec3 | Number

    could be an array of 3 or the x transform

  • y Number
  • z Number