awv3
Version:
⚡ AWV3 embedded CAD
1,033 lines (849 loc) • 35.3 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _from = require('babel-runtime/core-js/array/from');
var _from2 = _interopRequireDefault(_from);
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _three = require('three');
var THREE = _interopRequireWildcard(_three);
var _defaults = require('../core/defaults');
var _defaults2 = _interopRequireDefault(_defaults);
var _events = require('../core/events');
var _events2 = _interopRequireDefault(_events);
var _tween = require('../animation/tween');
var _tween2 = _interopRequireDefault(_tween);
var _raycaster = require('./raycaster');
var _raycaster2 = _interopRequireDefault(_raycaster);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Object3 = function (_THREE$Object3D) {
(0, _inherits3.default)(Object3, _THREE$Object3D);
function Object3() {
var objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
(0, _classCallCheck3.default)(this, Object3);
var _this = (0, _possibleConstructorReturn3.default)(this, (Object3.__proto__ || (0, _getPrototypeOf2.default)(Object3)).call(this));
if (!!options) _this.setValues(options);
if (!!objects) _this.add(objects);
return _this;
}
return Object3;
}(THREE.Object3D);
exports.default = Object3;
THREE.Object3D.Events = {
Lifecycle: {
Loaded: 'Loaded',
Added: 'Added',
ViewFound: 'ViewFound',
ChildAdded: 'ChildAdded',
Removed: 'Removed',
ChildRemoved: 'ChildRemoved',
Destroyed: 'Destroyed',
Rendered: 'Rendered'
},
Interaction: {
Clicked: 'Clicked',
Picked: 'Picked',
Dropped: 'Dropped',
Dragged: 'Dragged',
Hovered: 'Hovered',
Unhovered: 'Unhovered',
Missed: 'Missed'
}
};
THREE.Object3D.prototype.canvas = undefined;
THREE.Object3D.prototype.view = undefined;
THREE.Object3D.prototype.bounds = undefined;
THREE.Object3D.prototype.materials = undefined;
THREE.Object3D.prototype.updateParentMaterials = true;
THREE.Object3D.prototype.keep = false;
THREE.Object3D.prototype.measurable = true;
THREE.Object3D.prototype.tweens = true;
THREE.Object3D.prototype.interactive = true;
THREE.Object3D.prototype.interaction = undefined;
THREE.Object3D.prototype.interactionPriority = 0;
// Extend Object3D with event emitter
_events2.default.mixin(THREE.Object3D.prototype);
var copyObject3D = THREE.Object3D.prototype.copy;
THREE.Object3D.prototype.copy = function (source) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var copy = copyObject3D.bind(this).apply(undefined, [source].concat(args));
copy.updateParentMaterials = source.updateParentMaterials;
copy.keep = source.keep;
copy.measurable = source.measurable;
copy.tweens = source.tweens;
copy.interactive = source.interactive;
copy.interactionPriority = source.interactionPriority;
return copy;
};
THREE.Object3D.prototype.createInteraction = function () {
var _this2 = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (this.interaction) return this;
this.interaction = (0, _extends3.default)({
first: true,
faces: false,
priority: 0,
enabled: true,
recursive: false,
approach: _raycaster2.default.Approach.Default,
types: ['Mesh']
}, options);
var scope = this;
this.viewFound().then(function (view) {
if (view.interaction.targets.indexOf(scope) == -1) {
view.interaction.targets.push(scope);
var count = 0;
view.scene.traverse(function (item) {
return item.depthIndex = count++;
});
view.interaction.targets.sort(function (a, b) {
return a.depthIndex - b.depthIndex;
});
}
});
// _active controls if the interaction layer considers the object, depending if interaction-related events are registered
this.inspect(function (context) {
return _this2.interaction._active = !!(0, _keys2.default)(_this2._callbacks).find(function (item) {
return item in THREE.Object3D.Events.Interaction;
});
});
return this;
};
THREE.Object3D.prototype.removeInteraction = function () {
if (this.view && this.interaction) {
this.interaction = undefined;
this.view.interaction.removeTarget(this);
this.removeInspectors();
this.removeListener([Object3.Events.Interaction.Clicked, Object3.Events.Interaction.Picked, Object3.Events.Interaction.Dropped, Object3.Events.Interaction.Dragged, Object3.Events.Interaction.Hovered, Object3.Events.Interaction.Unhovered, Object3.Events.Interaction.Misses, Object3.Events.Lifecycle.Rendered]);
}
};
THREE.Object3D.prototype.viewFound = function () {
var scope = this;
return !!this.view ? _promise2.default.resolve(this.view) : new _promise2.default(function (resolve) {
return scope.once(THREE.Object3D.Events.Lifecycle.ViewFound, resolve);
});
};
THREE.Object3D.prototype._destroyRecursive = function (options) {
this.canvas = undefined;
this.view = undefined;
this.scene = undefined;
this.bounds = undefined;
this.userData = {};
if (!!this.geometry) {
this.geometry.dispose();
}
if (!!this.material) {
var isMultiMaterial = Array.isArray(this.material);
if (isMultiMaterial) {
this.material.forEach(function (material) {
material.dispose();
material.needsUpdate = true;
});
this.material = undefined;
} else {
this.material.dispose && this.material.dispose();
this.material.needsUpdate = true;
this.material = undefined;
}
}
if (!!this.materials) {
//this.materials.all.forEach(material => material.dispose());
this.materials.all = [];
this.materials.meshes = [];
this.materials.lines = [];
}
// Remove children
if (!options.async) {
for (var i = this.children.length - 1; i >= 0; i--) {
this.children[i].destroy(options);
}
} else {
return _promise2.default.all(this.children.map(function (child) {
return child.destroyAsync(options);
}));
}
};
THREE.Object3D.prototype.destroyAsync = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var view;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
view = this.view;
options = (0, _extends3.default)({ keep: true, data: true, interaction: true, listeners: true }, options);
if (!(options.keep && this.keep)) {
_context.next = 4;
break;
}
return _context.abrupt('return');
case 4:
_context.t0 = options.data;
if (!_context.t0) {
_context.next = 8;
break;
}
_context.next = 8;
return this._destroyRecursive((0, _extends3.default)({}, options, { async: true }));
case 8:
options.interaction && this.removeInteraction();
_context.next = 11;
return this.emit(Object3.Events.Lifecycle.Destroyed);
case 11:
_context.t1 = this.parent;
if (!_context.t1) {
_context.next = 15;
break;
}
_context.next = 15;
return this.parent.removeAsync(this);
case 15:
options.listeners && this.removeListeners();
this.removeObjectTweens();
view && view.invalidate();
case 18:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function () {
return _ref.apply(this, arguments);
};
}();
THREE.Object3D.prototype.destroy = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var view = this.view;
options = (0, _extends3.default)({ keep: true, data: true, interaction: true, listeners: true }, options);
if (options.keep && this.keep) return;
this.emit(Object3.Events.Lifecycle.Destroyed);
this.parent && this.parent.remove(this);
options.interaction && this.removeInteraction();
options.listeners && this.removeListeners();
this.removeObjectTweens();
options.data && this._destroyRecursive(options);
view && view.invalidate();
};
function updateReferences(parent, object) {
if (object.parent === parent && parent instanceof THREE.Scene || parent.view) {
object.traverse(function (child) {
child.scene = parent instanceof THREE.Scene ? parent : parent.scene;
child.view = parent.view;
child.canvas = parent.canvas;
child.emit(THREE.Object3D.Events.Lifecycle.ViewFound, child.view);
});
} else {
object.traverse(function (child) {
child.scene = undefined;
child.view = undefined;
child.canvas = undefined;
});
}
return object;
}
THREE.Object3D.prototype.addAsync = function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(object) {
var _this3 = this;
var _args2 = arguments;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
object = _args2.length > 1 ? (0, _from2.default)(_args2) : object;
if (!Array.isArray(object)) {
_context2.next = 3;
break;
}
return _context2.abrupt('return', _promise2.default.all(object.map(function (item) {
return _this3.addAsync(item);
})));
case 3:
if (!(object !== this && object instanceof THREE.Object3D)) {
_context2.next = 14;
break;
}
if (!object.parent) {
_context2.next = 7;
break;
}
_context2.next = 7;
return object.parent.removeAsync(object);
case 7:
object.parent = this;
this.children.push(updateReferences(this, object));
_context2.next = 11;
return this.emit(Object3.Events.Lifecycle.ChildAdded, { child: object });
case 11:
_context2.next = 13;
return object.emit(Object3.Events.Lifecycle.Added, { parent: this });
case 13:
!!this.view && this.view.invalidate();
case 14:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
return function (_x6) {
return _ref2.apply(this, arguments);
};
}();
THREE.Object3D.prototype.add = function (object) {
var _this4 = this;
object = arguments.length > 1 ? (0, _from2.default)(arguments) : object;
if (Array.isArray(object)) {
return _promise2.default.all(object.map(function (item) {
return _this4.add(item);
}));
}
if (object !== this && object instanceof THREE.Object3D) {
if (!!object.parent) object.parent.remove(object);
object.parent = this;
this.children.push(updateReferences(this, object));
this.emit(Object3.Events.Lifecycle.ChildAdded, { child: object });
object.emit(Object3.Events.Lifecycle.Added, { parent: this });
!!this.view && this.view.invalidate();
}
};
THREE.Object3D.prototype.removeAsync = function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(object) {
var _this5 = this;
var index,
_args3 = arguments;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
object = _args3.length > 1 ? (0, _from2.default)(_args3) : object;
if (!Array.isArray(object)) {
_context3.next = 3;
break;
}
return _context3.abrupt('return', _promise2.default.all(object.map(function (item) {
return _this5.removeAsync(item);
})));
case 3:
if (!(object instanceof THREE.Object3D)) {
_context3.next = 14;
break;
}
index = this.children.indexOf(object);
if (!(index !== -1)) {
_context3.next = 14;
break;
}
_context3.next = 8;
return this.emit(Object3.Events.Lifecycle.ChildRemoved, { child: object });
case 8:
_context3.next = 10;
return object.emit(Object3.Events.Lifecycle.Removed, { parent: this });
case 10:
this.children.splice(this.children.indexOf(object), 1);
object.parent = null;
updateReferences(this, object);
!!this.view && this.view.invalidate();
case 14:
case 'end':
return _context3.stop();
}
}
}, _callee3, this);
}));
return function (_x7) {
return _ref3.apply(this, arguments);
};
}();
THREE.Object3D.prototype.remove = function (object) {
var _this6 = this;
object = arguments.length > 1 ? (0, _from2.default)(arguments) : object;
if (Array.isArray(object)) {
return _promise2.default.all(object.map(function (item) {
return _this6.remove(item);
}));
}
if (object instanceof THREE.Object3D) {
var index = this.children.indexOf(object);
if (index !== -1) {
this.emit(Object3.Events.Lifecycle.ChildRemoved, { child: object });
object.emit(Object3.Events.Lifecycle.Removed, { parent: this });
this.children.splice(index, 1);
object.parent = null;
updateReferences(this, object);
!!this.view && this.view.invalidate();
}
}
};
THREE.Object3D.prototype.removeObjectTweens = function () {
_tween2.default.removeObjectTweens(this);
return this;
};
function traverse(obj, cb) {
if (!!obj.material) cb(obj);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(obj.children), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var child = _step.value;
child.updateParentMaterials && traverse(child, cb);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
THREE.Object3D.prototype.updateMaterials = function () {
var _this7 = this;
var colorMap = {};
this.materials = this.materials || {
updateParent: true,
all: [],
meshes: [],
lines: []
};
this.materials.all = [];
this.materials.meshes = [];
this.materials.lines = [];
traverse(this, function (child) {
return colorMap[child.material.uuid] = child.material;
});
(0, _keys2.default)(colorMap).forEach(function (key) {
var material = colorMap[key];
var isMultiMaterial = Array.isArray(material);
if (isMultiMaterial) {
material.forEach(function (material) {
_this7.materials.all.push(material);
if (material.type.indexOf('Mesh') > -1) _this7.materials.meshes.push(material);else if (material.type.indexOf('Line') > -1) _this7.materials.lines.push(material);
});
} else {
_this7.materials.all.push(material);
if (material.type.indexOf('Mesh') > -1) _this7.materials.meshes.push(material);else if (material.type.indexOf('Line') > -1) _this7.materials.lines.push(material);
}
});
return this;
};
THREE.Object3D.prototype.compress = function () {
var _this8 = this;
if (!this.materials) return;
var keys = (0, _keys2.default)(this.materials.all),
colorMap = {};
// Compress materials
var _loop = function _loop() {
material = _this8.materials.all[i];
index = '#' + material.color.getHexString() + '_' + material.opacity.toFixed(2) + '_' + material.type;
var entry = colorMap[index];
if (!entry) colorMap[index] = material;else {
// This material is already known
_this8.traverse(function (child) {
if (child.material) {
var isMultiMaterial = Array.isArray(material);
if (isMultiMaterial) {
for (var _i = 0, item, len = child.material.length; _i < len; _i++) {
item = child.material[_i];
if (item === material) {
item.dispose();
child.material[_i] = entry;
}
}
} else if (child.material === material) {
child.material.dispose();
child.material = entry;
}
}
});
}
};
for (var i = 0, l = this.materials.all.length; i < l; i++) {
var material, index;
_loop();
}
this.updateMaterials();
return this;
};
THREE.Object3D.prototype.animate = function (properties) {
return this.tweens ? new _tween2.default(this, properties) : new _tween2.default({}, {});
};
//some material properties cannot/shouldn't be animated
//change them immediately and remove from animation
function preprocessMaterialProps(obj, props) {
var _arr = ['polygonOffsetFactor', 'polygonOffsetUnits'];
for (var _i2 = 0; _i2 < _arr.length; _i2++) {
var key = _arr[_i2];
if (props[key] === undefined) continue;
obj[key] = props[key];
delete props[key];
}
}
THREE.Material.prototype.tweens = true;
THREE.Material.prototype.animate = function (properties) {
preprocessMaterialProps(this, properties);
return this.tweens ? new _tween2.default(this, properties) : new _tween2.default({}, {});
};
// This creates a property map for the animate function targeted to the material property
// It uses material meta data to restore defaults
THREE.Object3D.prototype.mapMaterial = function () {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
if (this.material) {
return {
material: Array.isArray(this.material) ? this.material.map(function (material) {
return (0, _extends3.default)({}, (material.meta || {}).material, typeof props === 'function' ? props(material) : props);
}) : (0, _extends3.default)({}, (material.meta || {}).material, typeof props === 'function' ? props(material) : props)
};
} else {
return {};
}
};
THREE.Object3D.prototype.animateMaterials = function (properties) {
return this.tweens ? new _tween2.default(this, { materials: properties }) : new _tween2.default({}, {});
};
THREE.Object3D.prototype.animateAllMaterials = function (properties) {
return this.tweens ? new _tween2.default(this, { materials: { all: [properties] } }) : new _tween2.default({}, {});
};
THREE.Object3D.prototype.animateMeshes = function (properties) {
return this.tweens ? new _tween2.default(this, { materials: { meshes: [properties] } }) : new _tween2.default({}, {});
};
THREE.Object3D.prototype.animateLines = function (properties) {
return this.tweens ? new _tween2.default(this, { materials: { lines: [properties] } }) : new _tween2.default({}, {});
};
THREE.Object3D.prototype.fadeOut = function (length) {
this.animate({
materials: {
meshes: [{ opacity: 0.0 }],
lines: [{ opacity: 0.0 }]
}
}).start(length || 0);
return this;
};
THREE.Object3D.prototype.fadeIn = function (length, value) {
this.animate({
materials: {
meshes: [{ opacity: value || 1.0 }],
lines: [{ opacity: value || 1.0 }]
}
}).start(length || 0);
return this;
};
THREE.Object3D.prototype.setValues = function (properties) {
return new _tween2.default(this, properties).start(0);
};
THREE.Object3D.prototype.root = function () {
var result,
current = this;
while (current) {
if (!current.parent || current.parent instanceof THREE.Scene) return current;
current = current.parent;
}
};
THREE.Object3D.prototype.isChildOf = function (parent) {
var current = this;
while (current) {
if (current == parent) return true;
current = current.parent;
}
return false;
};
THREE.Object3D.prototype.isVisible = function () {
if (!this.visible || this instanceof THREE.Mesh && this.material.opacity == 0) return false;
if (this.parent == null || this.parent instanceof THREE.Scene) return this.visible;else if (this.visible) return this.parent.isVisible();
return false;
};
THREE.Object3D.prototype.getObjectByMatch = function (name) {
for (var i = 0, l = this.children.length; i < l; i++) {
var child = this.children[i];
if (child.name.indexOf(name) > -1) return child;
}
return undefined;
};
THREE.Object3D.prototype.getObjectByUserId = function (id) {
if (!!this.userData && this.userData.id === id) return this;
for (var i = 0, l = this.children.length; i < l; i++) {
var child = this.children[i];
var object = child.getObjectByUserId(id);
if (object !== undefined) {
return object;
}
}
return undefined;
};
THREE.Object3D.prototype.lastChild = function () {
return this.children.length ? this.children[this.children.length - 1] : undefined;
};
THREE.Object3D.prototype.setPosition = function (vector) {
vector = arguments.length > 1 ? new (Function.prototype.bind.apply(THREE.Vector3, [null].concat(Array.prototype.slice.call(arguments))))() : vector;
this.position.copy(vector);
return this;
};
THREE.Object3D.prototype.setRotation = function (vector) {
vector = arguments.length > 1 ? new (Function.prototype.bind.apply(THREE.Euler, [null].concat(Array.prototype.slice.call(arguments))))() : vector;
this.rotation.copy(vector);
return this;
};
THREE.Object3D.prototype.setScale = function (vector) {
vector = arguments.length > 1 ? new (Function.prototype.bind.apply(THREE.Vector3, [null].concat(Array.prototype.slice.call(arguments))))() : vector;
this.scale.copy(vector);
return this;
};
THREE.Object3D.prototype.setRenderOrder = function (index, lines) {
this.traverse(function (item) {
if (item instanceof THREE.Mesh || !!lines && item instanceof THREE.Line) {
item.renderOrder = index;
}
});
return this;
};
THREE.Object3D.prototype.updateBounds = function () {
var box = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
this.bounds = this.bounds || {
box: new THREE.Box3(),
sphere: new THREE.Sphere()
};
this.bounds.box = !!box ? this.bounds.box.union(box) : new THREE.Box3().setFromObject(this);
this.bounds.sphere = this.bounds.box.getBoundingSphere();
return this;
};
THREE.Box3.prototype.expandByObject = function () {
var v1 = new THREE.Vector3();
return function expandByObject(object) {
var scope = this;
object.updateMatrixWorld(true);
object.traverseConditional(function (node) {
var i = void 0,
l = void 0;
var geometry = node.geometry;
var keepGoing = node.measurable && node.visible;
if (geometry !== undefined && keepGoing) {
if (geometry.isGeometry) {
var vertices = geometry.vertices;
for (i = 0, l = vertices.length; i < l; i++) {
v1.copy(vertices[i]);
v1.applyMatrix4(node.matrixWorld);
scope.expandByPoint(v1);
}
} else if (geometry.isBufferGeometry) {
var attribute = geometry.attributes.position;
if (attribute !== undefined) {
for (i = 0, l = attribute.count; i < l; i++) {
v1.fromBufferAttribute(attribute, i).applyMatrix4(node.matrixWorld);
scope.expandByPoint(v1);
}
}
}
}
return keepGoing;
});
return this;
};
}();
THREE.Object3D.prototype.getCenter = function (force) {
if (force || !this.bounds) this.updateBounds();
return this.bounds.sphere.center.clone();
};
THREE.Object3D.prototype.getRadius = function (force) {
if (force || !this.bounds) this.updateBounds();
return this.bounds.sphere.radius;
};
THREE.Object3D.prototype.centerGeometry = function () {
var center = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getCenter(true);
var setPosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
setPosition && this.position.copy(center);
if (!!this.geometry && (this.geometry instanceof THREE.Geometry || this.geometry instanceof THREE.BufferGeometry)) {
this.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(-center.x, -center.y, -center.z));
this.geometry.computeBoundingBox();
this.geometry.computeBoundingSphere();
}
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = (0, _getIterator3.default)(this.children), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var child = _step2.value;
child.centerGeometry(center, false);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return this;
};
THREE.Object3D.prototype.centerChildGeometry = function () {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = (0, _getIterator3.default)(this.children), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var child = _step3.value;
child.centerGeometry();
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
return this;
};
THREE.Object3D.prototype.addEventListener = function (type, listener) {
return this.on(type, listener);
};
THREE.Object3D.prototype.hasEventListener = function (type, listener) {
return this.hasListener(type, listener);
};
THREE.Object3D.prototype.removeEventListener = function (type, listener) {
return this.removeListener(type, listener);
};
THREE.Object3D.prototype.dispatchEvent = function (event) {
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
return this.emit.apply(this, [event].concat(args));
};
THREE.Object3D.prototype.setRenderOrder = function () {
var pairs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _defaults2.default.renderOrder;
this.traverse(function (item) {
var value = pairs[item.type];
if (value !== undefined) {
item.renderOrder = value;
}
});
return this;
};
THREE.Object3D.RenderOrder = {
Default: { Mesh: 0, LineSegments: 100 },
LinesFirst: { Mesh: 0, LineSegments: 100 },
MeshesFirst: { Mesh: 100, LineSegments: 0 }
};
THREE.Object3D.prototype.find = function (condition) {
if (condition(this)) return this;
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = (0, _getIterator3.default)(this.children), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var child = _step4.value;
var test = child.find(condition);
if (test) return test;
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
};
THREE.Object3D.prototype.traverseConditional = function (callback) {
if (callback(this)) {
var children = this.children;
for (var i = 0, l = children.length; i < l; i++) {
children[i].traverseConditional(callback);
}
}
};
THREE.Object3D.prototype.findMaterial = function (condition) {
var material = undefined;
var mesh = this.find(function (item) {
if (item.material) {
var materials = Array.isArray(item.material) ? item.material : [item.material];
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator5 = (0, _getIterator3.default)(materials), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var materialItem = _step5.value;
if (condition(materialItem, item)) {
material = materialItem;
return item;
}
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
}
}
}
}
});
return material ? { mesh: mesh, material: material } : undefined;
};
THREE.Object3D.prototype.traverseMaterials = function (callback) {
this.traverse(function (item) {
if (item.material) {
var isMultiMaterial = Array.isArray(item.material);
if (isMultiMaterial) {
item.material.forEach(function (multi) {
return callback(multi, item);
});
} else callback(item.material, item);
}
});
};