/home/lindsay/xeolabs/xeogl-next/xeogl/src/materials/outlineMaterial.js
API Docs for:

File: /home/lindsay/xeolabs/xeogl-next/xeogl/src/materials/outlineMaterial.js

  1. /**
  2. An **OutlineMaterial** is a {{#crossLink "Material"}}{{/crossLink}} that's applied to {{#crossLink "Mesh"}}Meshes{{/crossLink}}
  3. to render an outline around them.
  4.  
  5. WIP
  6.  
  7. @class OutlineMaterial
  8. @module xeogl
  9. @submodule materials
  10. @constructor
  11. @extends Material
  12. @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.
  13. @param [cfg] {*} The OutlineMaterial configuration
  14. @param [cfg.id] {String} Optional ID, unique among all components in the parent {{#crossLink "Scene"}}Scene{{/crossLink}}, generated automatically when omitted.
  15. @param [cfg.meta=null] {String:Object} Metadata to attach to this OutlineMaterial.
  16. @param [cfg.color=[1.0,0.2,0.2]] {Array of Number} Outline RGB color.
  17. @param [cfg.alpha=1.0] {Number} Outline opacity. A value of 0.0 indicates fully transparent, 1.0 is fully opaque.
  18. @param [cfg.width=4] {Number} Outline width, in pixels.
  19. */
  20. import {core} from "./../core.js";
  21. import {Material} from './material.js';
  22. import {State} from '../renderer/state.js';
  23. import {componentClasses} from "./../componentClasses.js";
  24.  
  25. const type = "xeogl.OutlineMaterial";
  26.  
  27. class OutlineMaterial extends Material {
  28.  
  29. /**
  30. JavaScript class name for this Component.
  31.  
  32. For example: "xeogl.AmbientLight", "xeogl.MetallicMaterial" etc.
  33.  
  34. @property type
  35. @type String
  36. @final
  37. */
  38. get type() {
  39. return type;
  40. }
  41.  
  42. init(cfg) {
  43.  
  44. super.init(cfg);
  45.  
  46. this._state = new State({
  47. type: "OutlineMaterial",
  48. color: null,
  49. alpha: null,
  50. width: null
  51. });
  52. this.color = cfg.color;
  53. this.alpha = cfg.alpha;
  54. this.width = cfg.width;
  55. }
  56.  
  57. /**
  58. RGB outline color.
  59.  
  60. @property color
  61. @default [1.0, 0.2, 0.2]
  62. @type Float32Array
  63. */
  64. set color(value) {
  65. let color = this._state.color;
  66. if (!color) {
  67. color = this._state.color = new Float32Array(3);
  68. } else if (value && color[0] === value[0] && color[1] === value[1] && color[2] === value[2]) {
  69. return;
  70. }
  71. if (value) {
  72. color[0] = value[0];
  73. color[1] = value[1];
  74. color[2] = value[2];
  75. } else {
  76. color[0] = 1.0;
  77. color[1] = 0.2;
  78. color[2] = 0.2;
  79. }
  80. this._renderer.imageDirty();
  81. }
  82.  
  83. get color() {
  84. return this._state.color;
  85. }
  86.  
  87. /**
  88. Outline transparency.
  89.  
  90. A value of 0.0 indicates fully transparent, 1.0 is fully opaque.
  91.  
  92. @property alpha
  93. @default 1.0
  94. @type Number
  95. */
  96. set alpha(value) {
  97. value = (value !== undefined && value !== null) ? value : 1.0;
  98. if (this._state.alpha === value) {
  99. return;
  100. }
  101. this._state.alpha = value;
  102. this._renderer.imageDirty();
  103. }
  104.  
  105. get alpha() {
  106. return this._state.alpha;
  107. }
  108.  
  109. /**
  110. Outline width in pixels.
  111.  
  112. @property width
  113. @default 4.0
  114. @type Number
  115. */
  116. set width(value) {
  117. this._state.width = value || 4.0;
  118. this._renderer.imageDirty();
  119. }
  120.  
  121. get width() {
  122. return this._state.width;
  123. }
  124.  
  125. destroy() {
  126. super.destroy();
  127. this._state.destroy();
  128. }
  129. }
  130.  
  131. componentClasses[type] = OutlineMaterial;
  132.  
  133. export{OutlineMaterial};