Luz
Descripción
Este componente hace que una entidad emita luz.
Propiedades
Propiedad | Tipo | Por defecto | Descripción |
---|---|---|---|
type | string | '' | Allowed values: 'directional' , 'point' , 'ambient' , 'spot' , 'area' |
castShadow | boolean | true | If the light source should cast shadows |
intensity | number | 0.5 | The light's intensity, or strength |
r | number | 255 | The amount of red the light emits. A value between 0 and 255. |
g | number | 255 | The amount of green the light emits. A value between 0 and 255. |
b | number | 255 | The amount of blue the light emits. A value between 0 and 255. |
colorMap | string | '' | The color map source |
shadowBias | number | -0.005 | How much to add or subtract from the normalized depth when deciding whether a surface is in shadow |
shadowNormalBias | number | 0 | How much the position used to query the shadow map is offset along the object normal |
shadowRadius | number | 1 | The radius of the shadow |
shadowAutoUpdate | boolean | true | Should the shadow be automatically calculated and updated |
shadowBlurSamples | number | 8 | The amount of samples to use when calculating the Virtual Shadow Map |
shadowMapSizeHeight | number | 1024 | The height of the Shadow Map. Values must be powers of 2. |
shadowMapSizeWidth | number | 1024 | The width of the Shadow Map. Values must be powers of 2. |
shadowCameraNear | number | 0.5 | Camera frustum near-pane for calculating shadows |
shadowCameraFar | number | 200 | Camera frustum far-pane for calculating shadows |
shadowCameraLeft | number | -50 | Camera frustum left-pane for calculating shadows |
shadowCameraRight | number | 50 | Camera frustum right-pane for calculating shadows |
shadowCameraBottom | number | -50 | Camera frustum bottom-pane for calculating shadows |
shadowCameraTop | number | 50 | Camera frustum top-pane for calculating shadows |
targetX | number | 0 | The target X coordinate of the light (Directional only) |
targetY | number | 0 | The target Y coordinate of the light (Directional only) |
targetZ | number | 0 | The target Z coordinate of the light (Directional only) |
width | number | 10 | Width of the light source (Area only) |
height | number | 10 | Height of the light source (Area only) |
penumbra | number | 0 | Percent of the spotlight cone that is attenuated due to penumbra. Accepted values between 0 and 1. (Spot only) |
decay | number | 2 | The amount the light dims along the distance of the light |
angle | number | Math.PI / 3 | Maximum extent of the spotlight, in radians, from its direction. Should be no more than Math.PI / 2. |
followCamera | boolean | true | Whether the light should follow where the camera is moving (Directional only) |
distance | number | 0 | When distance is zero, light will attenuate according to inverse-square law to infinite distance. When distance is non-zero, light will attenuate according to inverse-square law until near the distance cutoff, where it will then attenuate quickly and smoothly to 0. Inherently, cutoffs are not physically correct. |
Funciones
Get
Returns a read-only reference.
Example
ecs.Luz.get(world, component.eid)
Set
Ensures the component exists on the entity, then assigns the (optional) data to the component.
Example
ecs.Luz.set(world, component.eid, {
type: 'directional',
castShadow: true,
intensity: 0.5,
r: 255,
g: 255,
b: 255,
shadowBias: -0.005,
shadowNormalBias: 0,
shadowRadius: 1,
shadowAutoUpdate: true,
shadowBlurSamples: 8,
shadowMapSizeHeight: 1024,
shadowMapSizeWidth: 1024,
shadowCameraNear: 0.5,
shadowCameraFar: 200,
shadowCameraLeft: -50,
shadowCameraRight: 50,
shadowCameraBottom: -50,
shadowCameraTop: 50,
targetX: 0,
targetY: 0,
targetZ: 0
})
Mutate
Perform an update to the component within a callback function. Return true
to indicate no changes made.
Example
ecs.Luz.mutate(world, component.eid, (cursor) => {
cursor.intensidad = 1,0;
cursor.castShadow = false;
return false;
})
Remove
Removes the component from the entity.
Example
ecs.Luz.remove(world, component.eid)
Has
Returns true
if the component is present on the entity.
Example
ecs.Luz.has(world, component.eid)
Reset
Adds, or resets the component to its default state.
Example
ecs.Luz.reset(world, component.eid)
Advanced Functions
Cursor
Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.
Example
ecs.Luz.cursor(world, component.eid)
Acquire
Same behavior as cursor, but commit must be called after the cursor is done being used.
Example
ecs.Luz.acquire(world, component.eid)
Commit
Called after acquire. An optional third argument determines whether the cursor was mutated or not.
Example
ecs.Luz.commit(world, component.eid)
ecs.Luz.commit(world, component.eid, false)
Dirty
Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.
Example
ecs.Luz.dirty(world, component.eid)