LS.Material Class
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
Stringto configure from
Item Index
Methods
- clone
- configure
- createProperty
- getProperties
- getPropertiesInfo
- getProperty
- getProperty
- getProperty
- getResources
- getResources
- getTexture
- getTextureChannels
- getTextureSampler
- loadAndSetTexture
- loadTextures
- onResourceRenamed
- onResourceRenamed
- registerMaterial
- serialize
- setProperty
- setTexture
- setTexture
- setTextureInfo
- setTextureProperty
Methods
clone
()
Material
Clone this material (keeping the class)
Returns:
Material instance
configure
-
object
Configure the material getting the info from the object
Parameters:
-
object
Objectto 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
Stringthe property name as it should be accessed ( p.e. "color" -> material.color )
-
value
-
type
Stringa valid value type ("Number","Boolean","Texture",...)
getProperties
()
Object
gets all the properties and its types
Returns:
object with name:type
getPropertiesInfo
()
Object
gets all the properties and its types
Returns:
object with name:type
getProperty
()
Object
gets all the properties and its types
Returns:
object with name:type
getProperty
()
Object
gets all the properties and its types
Returns:
object with name:type
getProperty
()
Object
gets all the properties and its types
Returns:
object with name:type
getResources
-
resources
Collects all the resources needed by this material (textures)
Parameters:
-
resources
Objectobject where all the resources are stored
Returns:
getResources
-
resources
Collects all the resources needed by this material (textures)
Parameters:
-
resources
Objectobject where all the resources are stored
Returns:
getTexture
-
channel
Returns the texture in a channel
Parameters:
-
channel
Stringdefault is COLOR
Returns:
getTextureChannels
()
Array
gets all the texture channels supported by this material
Returns:
array with the name of every channel supported by this material
getTextureSampler
-
channel
Returns the texture sampler info of one texture channel (filter, wrap, uvs)
Parameters:
-
channel
Stringget available channels using getTextureChannels
Returns:
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
Event used to inform if one resource has changed its name
Parameters:
-
resources
Objectobject where all the resources are stored
Returns:
onResourceRenamed
-
resources
Event used to inform if one resource has changed its name
Parameters:
-
resources
Objectobject where all the resources are stored
Returns:
true if something was modified
registerMaterial
-
name
Register this material in a materials pool to be shared with other nodes
Parameters:
-
name
Stringname given to this material, it must be unique
serialize
()
Object
Serialize this material
Returns:
object with the serialization info
setProperty
-
object
assign a value to a property in a safe way
Parameters:
-
object
Objectto configure from
setTexture
-
texture
-
channel
Assigns a texture to a channel
Parameters:
-
texture
Texture -
channel
Stringdefault is COLOR
setTexture
-
channel
-
texture
-
sampler_options
Assigns a texture to a channel and its sampling parameters
Parameters:
-
channel
Stringfor 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
Stringdefault is COLOR
-
sampler
Object{ texture, uvs, wrap, filter }
setTextureProperty
-
channel
-
property
-
value
Set a property of the sampling (wrap, uvs, filter)
Parameters:
-
channel
Stringfor a list of supported channels by this material call getTextureChannels()
-
property
Stringcould 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]