/home/lindsay/xeolabs/xeogl-next/xeogl/examples/js/models/BIMServerModel.js
API Docs for:

File: /home/lindsay/xeolabs/xeogl-next/xeogl/examples/js/models/BIMServerModel.js

  1. /**
  2. An **BIMServerModel** is a {{#crossLink "Model"}}{{/crossLink}} that's loaded from an <a href="https://en.wikipedia.org/wiki/STL_(file_format)">STL</a> file.
  3.  
  4. @class BIMServerModel
  5. @module xeogl
  6. @submodule models
  7. @constructor
  8. @param [scene] {Scene} Parent {{#crossLink "Scene"}}Scene{{/crossLink}} - creates this BIMServerModel in the default
  9. {{#crossLink "Scene"}}Scene{{/crossLink}} when omitted.
  10. @param [cfg] {*} Configs
  11. @param [cfg.id] {String} Optional ID, unique among all components in the parent {{#crossLink "Scene"}}Scene{{/crossLink}},
  12. generated automatically when omitted.
  13. @param [cfg.entityType] {String} Optional entity classification when using within a semantic data model. See the {{#crossLink "Object"}}{{/crossLink}} documentation for usage.
  14. @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this BIMServerModel.
  15. @param [cfg.src] {String} Path to an STL file. You can set this to a new file path at any time, which will cause the
  16. @param [cfg.quantizeGeometry=true] {Boolean} When true, quantizes geometry to reduce memory and GPU bus usage.
  17. @param [cfg.combineGeometry=true] {Boolean} When true, combines geometry vertex buffers to improve rendering performance.
  18. @param [cfg.smoothNormals=false] {Boolean} When true, automatically converts face-oriented normals to vertex normals for a smooth appearance - see <a href="#smoothing-normals">Smoothing Normals</a>.
  19. @param [cfg.smoothNormalsAngleThreshold=20] {Number} See <a href="#smoothing-normals">Smoothing Normals</a>.
  20. @param [cfg.backfaces=false] {Boolean} When true, allows visible backfaces, wherever specified in the STL. When false, ignores backfaces.
  21. @param [cfg.ghosted=false] {Boolean} When true, sets all the Model's Meshes initially ghosted.
  22. @param [cfg.highlighted=false] {Boolean} When true, sets all the Model's Meshes initially highlighted.
  23. @param [cfg.outline=false] {Boolean} When true, sets all the Model's Meshes initially outlined.
  24. @param [cfg.edgeThreshold=2] {Number} When ghosting, this is the threshold angle between normals of adjacent triangles, below which their shared wireframe edge is not drawn.
  25. @param [cfg.transform] {Number|String|Transform} A Local-to-World-space (modelling) {{#crossLink "Transform"}}{{/crossLink}} to attach to this BIMServerModel.
  26. Must be within the same {{#crossLink "Scene"}}{{/crossLink}} as this BIMServerModel. Internally, the given
  27. {{#crossLink "Transform"}}{{/crossLink}} will be inserted above each top-most {{#crossLink "Transform"}}Transform{{/crossLink}}
  28. that the BIMServerModel attaches to its {{#crossLink "Mesh"}}Meshes{{/crossLink}}.
  29. @param [cfg.splitMeshes=true] {Boolean} When true, creates a separate {{#crossLink "Mesh"}}{{/crossLink}} for each group of faces that share the same vertex colors. Only works with binary STL.|
  30. @param [cfg.position=[0,0,0]] {Float32Array} The BIMServerModel's local 3D position.
  31. @param [cfg.scale=[1,1,1]] {Float32Array} The BIMServerModel's local scale.
  32. @param [cfg.rotation=[0,0,0]] {Float32Array} The BIMServerModel's local rotation, as Euler angles given in degrees.
  33. @param [cfg.matrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1] {Float32Array} The BIMServerModel's local transform matrix. Overrides the position, scale and rotation parameters.
  34. @extends Model
  35. */
  36. (function () {
  37.  
  38. "use strict";
  39.  
  40. xeogl.BIMServerModel = xeogl.Model.extend({
  41.  
  42. type: "xeogl.BIMServerModel",
  43.  
  44. _init: function (cfg) {
  45. this._super(cfg);
  46. this._src = null;
  47. this._options = {
  48. combineGeometry: cfg.combineGeometry !== false,
  49. quantizeGeometry: cfg.quantizeGeometry !== false,
  50. edgeThreshold: cfg.edgeThreshold,
  51. splitMeshes: cfg.splitMeshes,
  52. smoothNormals: cfg.smoothNormals,
  53. smoothNormalsAngleThreshold: cfg.smoothNormalsAngleThreshold
  54. };
  55. this.src = cfg.src;
  56. },
  57.  
  58. _props: {
  59.  
  60. /**
  61. Path to an STL file.
  62.  
  63. You can set this to a new file path at any time (except while loading), which will cause the BIMServerModel to load components from
  64. the new file (after first destroying any components loaded from a previous file path).
  65.  
  66. Fires a {{#crossLink "BIMServerModel/loaded:event"}}{{/crossLink}} event when the STL has loaded.
  67.  
  68. @property src
  69. @type String
  70. */
  71. src: {
  72. set: function (value) {
  73. if (!value) {
  74. return;
  75. }
  76. if (!xeogl._isString(value)) {
  77. this.error("Value for 'src' should be a string");
  78. return;
  79. }
  80. if (value === this._src) { // Already loaded this BIMServerModel
  81.  
  82. /**
  83. Fired whenever this BIMServerModel has finished loading components from the STL file
  84. specified by {{#crossLink "BIMServerModel/src:property"}}{{/crossLink}}.
  85. @event loaded
  86. */
  87. this.fire("loaded", true, true);
  88. return;
  89. }
  90. this.clear();
  91. this._src = value;
  92. xeogl.BIMServerModel.load(this, this._src, this._options);
  93. },
  94.  
  95. get: function () {
  96. return this._src;
  97. }
  98. }
  99. },
  100.  
  101. _destroy: function () {
  102. this.destroyAll();
  103. }
  104. });
  105.  
  106. /**
  107. * Loads STL from a URL into a {{#crossLink "Model"}}{{/crossLink}}.
  108. *
  109. * @method load
  110. * @static
  111. * @param {Model} model Model to load into.
  112. * @param {String} src Path to STL file.
  113. * @param {Object} options Loading options.
  114. * @param {Function} [ok] Completion callback.
  115. * @param {Function} [error] Error callback.
  116. */
  117. xeogl.BIMServerModel.load = function (model, src, options, ok, error) {
  118. var spinner = model.scene.canvas.spinner;
  119. spinner.processes++;
  120. load(model, src, options, function () {
  121. spinner.processes--;
  122. xeogl.scheduleTask(function () {
  123. model.fire("loaded", true, true);
  124. });
  125. if (ok) {
  126. ok();
  127. }
  128. },
  129. function (msg) {
  130. spinner.processes--;
  131. model.error(msg);
  132. if (error) {
  133. error(msg);
  134. }
  135. /**
  136. Fired whenever this BIMServerModel fails to load the STL file
  137. specified by {{#crossLink "BIMServerModel/src:property"}}{{/crossLink}}.
  138. @event error
  139. @param msg {String} Description of the error
  140. */
  141. model.fire("error", msg);
  142. });
  143. };
  144.  
  145.  
  146. })();
  147.