/home/lindsay/xeolabs/xeogl-next/xeogl/src/lighting/shadow.js
API Docs for:

File: /home/lindsay/xeolabs/xeogl-next/xeogl/src/lighting/shadow.js

  1. /**
  2. A **Shadow** defines a shadow cast by a {{#crossLink "DirLight"}}{{/crossLink}} or a {{#crossLink "SpotLight"}}{{/crossLink}}.
  3.  
  4. Work in progress!
  5.  
  6. ## Overview
  7.  
  8. * Shadows are attached to {{#crossLink "DirLight"}}{{/crossLink}} and {{#crossLink "SpotLight"}}{{/crossLink}} components.
  9.  
  10. TODO
  11.  
  12. ## Examples
  13.  
  14. TODO
  15.  
  16. ## Usage
  17.  
  18. ```` javascript
  19. var mesh = new xeogl.Mesh(scene, {
  20.  
  21. lights: new xeogl.Lights({
  22. lights: [
  23.  
  24. new xeogl.SpotLight({
  25. pos: [0, 100, 100],
  26. dir: [0, -1, 0],
  27. color: [0.5, 0.7, 0.5],
  28. intensity: 1
  29. constantAttenuation: 0,
  30. linearAttenuation: 0,
  31. quadraticAttenuation: 0,
  32. space: "view",
  33.  
  34. shadow: new xeogl.Shadow({
  35. resolution: [1000, 1000],
  36. intensity: 0.7,
  37. sampling: "stratified" // "stratified" | "poisson" | "basic"
  38. });
  39. })
  40. ]
  41. }),
  42. ,
  43. material: new xeogl.PhongMaterial({
  44. diffuse: [0.5, 0.5, 0.0]
  45. }),
  46.  
  47. geometry: new xeogl.BoxGeometry()
  48. });
  49. ````
  50.  
  51. @class Shadow
  52. @module xeogl
  53. @submodule lighting
  54. @constructor
  55. @extends Component
  56. @param [owner] {Component} Owner component. When destroyed, the owner will destroy this component as well. Creates this component within the default {{#crossLink "Scene"}}{{/crossLink}} when omitted.
  57. @param [cfg] {*} The Shadow configuration
  58. @param [cfg.id] {String} Optional ID, unique among all components in the parent {{#crossLink "Scene"}}Scene{{/crossLink}}, generated automatically when omitted.
  59. @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this Shadow.
  60. @param [cfg.resolution=[1000,1000]] {Uint16Array} Resolution of the texture map for this Shadow.
  61. @param [cfg.intensity=1.0] {Number} Intensity of this Shadow.
  62. */
  63. import {Component} from '../component.js';
  64. import {math} from '../math/math.js';
  65. import {componentClasses} from "./../componentClasses.js";
  66.  
  67. const type = "xeogl.Shadow";
  68.  
  69. class Shadow extends Component {
  70.  
  71. /**
  72. JavaScript class name for this Component.
  73.  
  74. For example: "xeogl.AmbientLight", "xeogl.MetallicMaterial" etc.
  75.  
  76. @property type
  77. @type String
  78. @final
  79. */
  80. get type() {
  81. return type;
  82. }
  83.  
  84. init(cfg) {
  85. super.init(cfg);
  86. this._state = {
  87. resolution: math.vec3([1000, 1000]),
  88. intensity: 1.0
  89. };
  90. this.resolution = cfg.resolution;
  91. this.intensity = cfg.intensity;
  92. }
  93.  
  94. /**
  95. The resolution of the texture map for this Shadow.
  96.  
  97. This will be either World- or View-space, depending on the value of {{#crossLink "Shadow/space:property"}}{{/crossLink}}.
  98.  
  99. Fires a {{#crossLink "Shadow/resolution:event"}}{{/crossLink}} event on change.
  100.  
  101. @property resolution
  102. @default [1000, 1000]
  103. @type Uint16Array
  104. */
  105. set resolution(value) {
  106.  
  107. this._state.resolution.set(value || [1000.0, 1000.0]);
  108.  
  109. this._renderer.imageDirty();
  110.  
  111. /**
  112. Fired whenever this Shadow's {{#crossLink "Shadow/resolution:property"}}{{/crossLink}} property changes.
  113. @event resolution
  114. @param value The property's new value
  115. */
  116. this.fire("resolution", this._state.resolution);
  117. }
  118.  
  119. get resolution() {
  120. return this._state.resolution;
  121. }
  122.  
  123. /**
  124. The intensity of this Shadow.
  125.  
  126. Fires a {{#crossLink "Shadow/intensity:event"}}{{/crossLink}} event on change.
  127.  
  128. @property intensity
  129. @default 1.0
  130. @type Number
  131. */
  132. set intensity(value) {
  133.  
  134. value = value !== undefined ? value : 1.0;
  135.  
  136. this._state.intensity = value;
  137.  
  138. this._renderer.imageDirty();
  139.  
  140. /**
  141. * Fired whenever this Shadow's {{#crossLink "Shadow/intensity:property"}}{{/crossLink}} property changes.
  142. * @event intensity
  143. * @param value The property's new value
  144. */
  145. this.fire("intensity", this._state.intensity);
  146. }
  147.  
  148. get intensity() {
  149. return this._state.intensity;
  150. }
  151.  
  152. destroy() {
  153. super.destroy();
  154. //this._state.destroy();
  155. }
  156. }
  157.  
  158. componentClasses[type] = Shadow;
  159.  
  160. export{Shadow};
  161.