/**
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.
@class BIMServerModel
@module xeogl
@submodule models
@constructor
@param [scene] {Scene} Parent {{#crossLink "Scene"}}Scene{{/crossLink}} - creates this BIMServerModel in the default
{{#crossLink "Scene"}}Scene{{/crossLink}} when omitted.
@param [cfg] {*} Configs
@param [cfg.id] {String} Optional ID, unique among all components in the parent {{#crossLink "Scene"}}Scene{{/crossLink}},
generated automatically when omitted.
@param [cfg.entityType] {String} Optional entity classification when using within a semantic data model. See the {{#crossLink "Object"}}{{/crossLink}} documentation for usage.
@param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this BIMServerModel.
@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
@param [cfg.quantizeGeometry=true] {Boolean} When true, quantizes geometry to reduce memory and GPU bus usage.
@param [cfg.combineGeometry=true] {Boolean} When true, combines geometry vertex buffers to improve rendering performance.
@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>.
@param [cfg.smoothNormalsAngleThreshold=20] {Number} See <a href="#smoothing-normals">Smoothing Normals</a>.
@param [cfg.backfaces=false] {Boolean} When true, allows visible backfaces, wherever specified in the STL. When false, ignores backfaces.
@param [cfg.ghosted=false] {Boolean} When true, sets all the Model's Meshes initially ghosted.
@param [cfg.highlighted=false] {Boolean} When true, sets all the Model's Meshes initially highlighted.
@param [cfg.outline=false] {Boolean} When true, sets all the Model's Meshes initially outlined.
@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.
@param [cfg.transform] {Number|String|Transform} A Local-to-World-space (modelling) {{#crossLink "Transform"}}{{/crossLink}} to attach to this BIMServerModel.
Must be within the same {{#crossLink "Scene"}}{{/crossLink}} as this BIMServerModel. Internally, the given
{{#crossLink "Transform"}}{{/crossLink}} will be inserted above each top-most {{#crossLink "Transform"}}Transform{{/crossLink}}
that the BIMServerModel attaches to its {{#crossLink "Mesh"}}Meshes{{/crossLink}}.
@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.|
@param [cfg.position=[0,0,0]] {Float32Array} The BIMServerModel's local 3D position.
@param [cfg.scale=[1,1,1]] {Float32Array} The BIMServerModel's local scale.
@param [cfg.rotation=[0,0,0]] {Float32Array} The BIMServerModel's local rotation, as Euler angles given in degrees.
@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.
@extends Model
*/
(function () {
"use strict";
xeogl.BIMServerModel = xeogl.Model.extend({
type: "xeogl.BIMServerModel",
_init: function (cfg) {
this._super(cfg);
this._src = null;
this._options = {
combineGeometry: cfg.combineGeometry !== false,
quantizeGeometry: cfg.quantizeGeometry !== false,
edgeThreshold: cfg.edgeThreshold,
splitMeshes: cfg.splitMeshes,
smoothNormals: cfg.smoothNormals,
smoothNormalsAngleThreshold: cfg.smoothNormalsAngleThreshold
};
this.src = cfg.src;
},
_props: {
/**
Path to an STL file.
You can set this to a new file path at any time (except while loading), which will cause the BIMServerModel to load components from
the new file (after first destroying any components loaded from a previous file path).
Fires a {{#crossLink "BIMServerModel/loaded:event"}}{{/crossLink}} event when the STL has loaded.
@property src
@type String
*/
src: {
set: function (value) {
if (!value) {
return;
}
if (!xeogl._isString(value)) {
this.error("Value for 'src' should be a string");
return;
}
if (value === this._src) { // Already loaded this BIMServerModel
/**
Fired whenever this BIMServerModel has finished loading components from the STL file
specified by {{#crossLink "BIMServerModel/src:property"}}{{/crossLink}}.
@event loaded
*/
this.fire("loaded", true, true);
return;
}
this.clear();
this._src = value;
xeogl.BIMServerModel.load(this, this._src, this._options);
},
get: function () {
return this._src;
}
}
},
_destroy: function () {
this.destroyAll();
}
});
/**
* Loads STL from a URL into a {{#crossLink "Model"}}{{/crossLink}}.
*
* @method load
* @static
* @param {Model} model Model to load into.
* @param {String} src Path to STL file.
* @param {Object} options Loading options.
* @param {Function} [ok] Completion callback.
* @param {Function} [error] Error callback.
*/
xeogl.BIMServerModel.load = function (model, src, options, ok, error) {
var spinner = model.scene.canvas.spinner;
spinner.processes++;
load(model, src, options, function () {
spinner.processes--;
xeogl.scheduleTask(function () {
model.fire("loaded", true, true);
});
if (ok) {
ok();
}
},
function (msg) {
spinner.processes--;
model.error(msg);
if (error) {
error(msg);
}
/**
Fired whenever this BIMServerModel fails to load the STL file
specified by {{#crossLink "BIMServerModel/src:property"}}{{/crossLink}}.
@event error
@param msg {String} Description of the error
*/
model.fire("error", msg);
});
};
})();