LS.Draw Class
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
()
Item Index
Methods
- createSurfaceShader
- identity
- init
- lookAt
- multMatrix
- project
- push
- push
- renderCircle
- renderCone
- renderCylinder
- renderGrid
- renderImage
- renderLines
- renderMesh
- renderPlane
- renderPoints
- renderPointsWithSize
- renderRectangle
- renderRoundPoints
- renderSolidBox
- renderSolidCircle
- renderSolidCube
- renderText
- renderWireBox
- renderWireCube
- renderWireSphere
- reset
- rotate
- scale
- setAlpha
- setCamera
- setCameraPosition
- setColor
- setMatrix
- setPointSize
- setViewProjectionMatrix
- translate
Methods
createSurfaceShader
-
surface_function -
macros -
uniforms
A helper to create shaders when you only want to specify some basic shading
Parameters:
-
surface_functionStringGLSL code like: "vec4 surface_function( vec3 pos, vec3 normal, vec2 coord ) { return vec4(1.0); } ";
-
macrosObject[optional] object containing the macros and value
-
uniformsObject[optional] object with name and type
Returns:
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:
-
positionVec3 -
targetVec3 -
upVec3
multMatrix
-
matrix
Multiplies the current matrix by a given one
Parameters:
-
matrixMat4
project
-
position -
dest
projects a point from 3D space to 2D space (multiply by MVP)
Parameters:
-
positionVec3 -
destVec3[optional]
Returns:
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:
-
radiusNumber -
segmentsNumber -
in_zBoolean[optional] if the circle is aligned with the z plane
-
filledBoolean[optional] renders the interior
renderCone
-
radius -
height -
segments -
in_z
Renders a cone
Parameters:
-
radiusNumber -
heightNumber -
segmentsNumber -
in_zBooleanaligned with z axis
renderCylinder
-
radius -
height -
segments -
in_z
Renders a cylinder
Parameters:
-
radiusNumber -
heightNumber -
segmentsNumber -
in_zBooleanaligned with z axis
renderGrid
-
dist -
num
Renders a grid of lines
Parameters:
-
distNumberdistance between lines
-
numNumbernumber of lines
renderImage
-
position -
image -
size -
fixed_size
Renders an image
Parameters:
-
positionVec3 -
imageImage | Texture | Stringfrom an URL, or a texture
-
sizeNumber[optional=10]
-
fixed_sizeBoolean[optional=false] (camera distance do not affect size)
renderLines
-
points -
colors -
strip -
loop
Render lines given a set of points
Parameters:
-
pointsFloat32Array | Array -
colorsFloat32Array | Array[optional]
-
stripBool[optional] if the lines are a line strip (one consecutive line)
-
loopBool[optional] if strip, close loop
renderMesh
-
mesh -
primitive -
indices -
range_start -
range_length
Renders a given mesh applyting the stack transformations
Parameters:
-
meshGL.Mesh -
primitiveEnum[optional=gl.TRIANGLES] GL.TRIANGLES, gl.LINES, gl.POINTS, ...
-
indicesString[optional="triangles"] the name of the buffer in the mesh with the indices
-
range_startNumber[optional] in case of rendering a range, the start primitive
-
range_lengthNumber[optional] in case of rendering a range, the number of primitives
renderPlane
-
position -
size -
texture -
shader
Renders a solid plane (could be textured or even with an specific shader)
Parameters:
-
positionVec3 -
sizeVec2 -
textureGL.Texture -
shaderGL.Shader
renderPoints
-
points -
colors -
shader
Render points given a set of positions (and colors)
Parameters:
-
pointsFloat32Array | Array -
colorsFloat32Array | Array[optional]
-
shaderGL.Shader[optional]
renderPointsWithSize
-
points -
colors -
sizes -
texture -
shader
Render points with color, size, and texture binded in 0
Parameters:
-
pointsFloat32Array | Array -
colorsFloat32Array | Array[optional]
-
sizesFloat32Array | Array[optional]
-
textureGL.Texture[optional]
-
shaderGL.Shader[optional]
renderRectangle
-
width -
height -
in_z
Render a wireframe rectangle of width x height
Parameters:
-
widthNumber -
heightNumber -
in_zBoolean[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:
-
pointsFloat32Array | Array -
colorsFloat32Array | Array[optional]
-
shaderGL.Shader[optional]
renderSolidBox
-
sizex -
sizey -
sizez
Renders a solid box
Parameters:
-
sizexNumber -
sizeyNumber -
sizezNumber
renderSolidCircle
-
radius -
segments -
in_z
Render a filled circle
Parameters:
-
radiusNumber -
segmentsNumber -
in_zBoolean[optional] if the circle is aligned with the z plane
renderSolidCube
-
size
Renders a solid cube of size size
Parameters:
-
sizeNumber
renderText
-
text
Renders a text in the current matrix position
Parameters:
-
textString
renderWireBox
-
sizex -
sizey -
sizez
Renders a wire box (box made of lines, not filled)
Parameters:
-
sizexNumber -
sizeyNumber -
sizezNumber
renderWireCube
-
size
Renders a wire cube of size size
Parameters:
-
sizeNumber
renderWireSphere
-
radius -
segments
Renders three circles to form a simple spherical shape
Parameters:
-
radiusNumber -
segmentsNumber
reset
()
clears the stack
rotate
-
angle -
x -
y -
z
applies a translation to the transform matrix
Parameters:
-
angleNumberin degrees
-
xNumber | Vec3could be the x component or the full axis
-
yNumber -
zNumber
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:
-
xVec3 | Array | Numbercould be an array of 3, one value (if no other values are specified then it is an uniform scaling)
-
yNumber -
zNumber
setAlpha
-
alpha
Sets the alpha used to paint primitives
Parameters:
-
alphaNumber
setCamera
-
camera
Sets the camera to use during the rendering, this is already done by LS.Renderer
Parameters:
-
cameraLS.Camera
setCameraPosition
-
center
Specifies the camera position (used to compute point size)
Parameters:
-
centerVec3
setColor
-
color
Sets the color used to paint primitives
Parameters:
-
colorVec3 | Vec4
setMatrix
-
matrix
Specifies the transformation matrix to apply to the mesh
Parameters:
-
matrixMat4
setPointSize
-
v
Sets the point size
Parameters:
-
vNumber
setViewProjectionMatrix
-
view -
projection -
vp
Specifies the camera view and projection matrices
Parameters:
-
viewMat4 -
projectionMat4 -
vpMat4viewprojection matrix [optional]
translate
-
x -
y -
z
applies a translation to the transform matrix
Parameters:
-
xVec3 | Numbercould be an array of 3 or the x transform
-
yNumber -
zNumber
