API Docs for:
Show:

LS.Material Class

Module: LS

A Material is a class in charge of defining how to render an object, there are several classes for Materials but this class is more like a template for other material classes. The rendering of a material is handled by the material itself, if not provided then uses the Renderer default one

Constructor

LS.Material

(
  • object
)

Parameters:

  • object String

    to configure from

Methods

clone

() Material

Clone this material (keeping the class)

Returns:

Material:

Material instance

configure

(
  • object
)

Configure the material getting the info from the object

Parameters:

  • object Object

    to configure from

createProperty

(
  • name
  • value
  • type
)

Creates a new property in this material class. Helps with some special cases like when we have a Float32Array property and we dont want it to be replaced by another array, but setted

Parameters:

  • name String

    the property name as it should be accessed ( p.e. "color" -> material.color )

  • value
  • type String

    a valid value type ("Number","Boolean","Texture",...)

getProperties

() Object

gets all the properties and its types

Returns:

Object:

object with name:type

getPropertiesInfo

() Object

gets all the properties and its types

Returns:

Object:

object with name:type

getProperty

() Object

gets all the properties and its types

Returns:

Object:

object with name:type

getProperty

() Object

gets all the properties and its types

Returns:

Object:

object with name:type

getProperty

() Object

gets all the properties and its types

Returns:

Object:

object with name:type

getResources

(
  • resources
)
Texture

Collects all the resources needed by this material (textures)

Parameters:

  • resources Object

    object where all the resources are stored

Returns:

Texture:

getResources

(
  • resources
)
Texture

Collects all the resources needed by this material (textures)

Parameters:

  • resources Object

    object where all the resources are stored

Returns:

Texture:

getTexture

(
  • channel
)
Texture

Returns the texture in a channel

Parameters:

  • channel String

    default is COLOR

Returns:

Texture:

getTextureChannels

() Array

gets all the texture channels supported by this material

Returns:

Array:

array with the name of every channel supported by this material

getTextureSampler

(
  • channel
)
Texture

Returns the texture sampler info of one texture channel (filter, wrap, uvs)

Parameters:

  • channel String

    get available channels using getTextureChannels

Returns:

Texture:

loadAndSetTexture

(
  • texture_or_filename
  • channel
)

Loads and assigns a texture to a channel

Parameters:

  • texture_or_filename Texture | | url
  • channel String

loadTextures

()

Loads all the textures inside this material, by sending the through the ResourcesManager

onResourceRenamed

(
  • resources
)
Texture

Event used to inform if one resource has changed its name

Parameters:

  • resources Object

    object where all the resources are stored

Returns:

Texture:

onResourceRenamed

(
  • resources
)
Boolean

Event used to inform if one resource has changed its name

Parameters:

  • resources Object

    object where all the resources are stored

Returns:

Boolean:

true if something was modified

registerMaterial

(
  • name
)

Register this material in a materials pool to be shared with other nodes

Parameters:

  • name String

    name given to this material, it must be unique

serialize

() Object

Serialize this material

Returns:

Object:

object with the serialization info

setProperty

(
  • object
)

assign a value to a property in a safe way

Parameters:

  • object Object

    to configure from

setTexture

(
  • texture
  • channel
)

Assigns a texture to a channel

Parameters:

  • texture Texture
  • channel String

    default is COLOR

setTexture

(
  • channel
  • texture
  • sampler_options
)

Assigns a texture to a channel and its sampling parameters

Parameters:

  • channel String

    for a list of supported channels by this material call getTextureChannels()

  • texture Texture
  • sampler_options Object

setTextureInfo

(
  • channel
  • sampler
)

Assigns a texture sampler to one texture channel (filter, wrap, uvs)

Parameters:

  • channel String

    default is COLOR

  • sampler Object

    { texture, uvs, wrap, filter }

setTextureProperty

(
  • channel
  • property
  • value
)

Set a property of the sampling (wrap, uvs, filter)

Parameters:

  • channel String

    for a list of supported channels by this material call getTextureChannels()

  • property String

    could be "uvs", "filter", "wrap"

  • value

    the value, for uvs check Material.TEXTURE_COORDINATES, filter is gl.NEAREST or gl.LINEAR and wrap gl.CLAMP_TO_EDGE, gl.MIRROR or gl.REPEAT

Properties

color

[r,g,b]

materials have at least a basic color property and opacity

Default: [1,1,1]

color

Vec3

Surface color

Default: [1,1,1]

flags

Object

flags to control cast_shadows, receive_shadows or ignore_frustum

Default: { cast_shadows: true, receive_shadows: true, ignore_frutum: false }

opacity

Unknown

The alpha component to control opacity

Default: 1

opacity

Number

Opacity. It must be < 1 to enable alpha sorting. If it is <= 0 wont be visible.

Default: 1

query

LS.ShaderQuery

used internally by LS.StandardMaterial This will be gone in the future in order to use the new ShaderMaterial rendering system

queue

Number

render queue: which order should this be rendered

Default: LS.RenderQueue.DEFAULT

queue

Unknown

the render queue id where this instance belongs

Default: LS.RenderQueue.DEFAULT;

render_state

Unknown

the render state flags to control how the GPU behaves

render_state

LS.RenderState

render state: which flags should be used (in StandardMaterial this is overwritten due to the multipass lighting) TODO: render states should be moved to render passes defined by the shadercode in the future to allow multipasses like cellshading outline render

specular_gloss

Number

Specular glossiness: the glossines (exponent) of specular light

Default: 10

textures

Object

texture channels contains info about the samplers for every texture channel

uvs_matrix

Mat3

matrix used to define texture tiling in the shader (passed as u_texture_matrix)

Default: [1,0,0, 0,1,0, 0,0,1]