UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

2 lines (1 loc) 5.82 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t,r,e,n,a=require("./core/Base.js"),o=require("./math/Vector3.js"),i=require("./math/Quaternion.js"),s=require("./math/Matrix4.js"),l=require("./glmatrix/mat4.js"),f=require("./math/BoundingBox.js"),d=0,h=a.default.extend({name:"",position:null,rotation:null,scale:null,worldTransform:null,localTransform:null,autoUpdateLocalTransform:!0,_parent:null,_scene:null,_needsUpdateWorldTransform:!0,_inIterating:!1,__depth:0},(function(){this.name||(this.name=(this.type||"NODE")+"_"+d++),this.position||(this.position=new o.default),this.rotation||(this.rotation=new i.default),this.scale||(this.scale=new o.default(1,1,1)),this.worldTransform=new s.default,this.localTransform=new s.default,this._children=[]}),{target:null,invisible:!1,isSkinnedMesh:function(){return!1},isRenderable:function(){return!1},setName:function(t){var r=this._scene;if(r){var e=r._nodeRepository;delete e[this.name],e[t]=this}this.name=t},add:function(t){var r=t._parent;if(r!==this){r&&r.remove(t),t._parent=this,this._children.push(t);var e=this._scene;e&&e!==t.scene&&t.traverse(this._addSelfToScene,this),t._needsUpdateWorldTransform=!0}},remove:function(t){var r=this._children,e=r.indexOf(t);e<0||(r.splice(e,1),t._parent=null,this._scene&&t.traverse(this._removeSelfFromScene,this))},removeAll:function(){for(var t=this._children,r=0;r<t.length;r++)t[r]._parent=null,this._scene&&t[r].traverse(this._removeSelfFromScene,this);this._children=[]},getScene:function(){return this._scene},getParent:function(){return this._parent},_removeSelfFromScene:function(t){t._scene.removeFromScene(t),t._scene=null},_addSelfToScene:function(t){this._scene.addToScene(t),t._scene=this._scene},isAncestor:function(t){for(var r=t._parent;r;){if(r===this)return!0;r=r._parent}return!1},children:function(){return this._children.slice()},childAt:function(t){return this._children[t]},getChildByName:function(t){for(var r=this._children,e=0;e<r.length;e++)if(r[e].name===t)return r[e]},getDescendantByName:function(t){for(var r=this._children,e=0;e<r.length;e++){var n=r[e];if(n.name===t)return n;var a=n.getDescendantByName(t);if(a)return a}},queryNode:function(t){if(t){for(var r=t.split("/"),e=this,n=0;n<r.length;n++){var a=r[n];if(a){for(var o=!1,i=e._children,s=0;s<i.length;s++){var l=i[s];if(l.name===a){e=l,o=!0;break}}if(!o)return}}return e}},getPath:function(t){if(!this._parent)return"/";for(var r=this._parent,e=this.name;r._parent&&(e=r.name+"/"+e,r._parent!=t);)r=r._parent;return!r._parent&&t?null:e},traverse:function(t,r){t.call(r,this);for(var e=this._children,n=0,a=e.length;n<a;n++)e[n].traverse(t,r)},eachChild:function(t,r){for(var e=this._children,n=0,a=e.length;n<a;n++){var o=e[n];t.call(r,o,n)}},setLocalTransform:function(t){l.default.copy(this.localTransform.array,t.array),this.decomposeLocalTransform()},decomposeLocalTransform:function(t){var r=t?null:this.scale;this.localTransform.decomposeMatrix(r,this.rotation,this.position)},setWorldTransform:function(t){l.default.copy(this.worldTransform.array,t.array),this.decomposeWorldTransform()},decomposeWorldTransform:(n=l.default.create(),function(t){var r=this.localTransform,e=this.worldTransform;this._parent?(l.default.invert(n,this._parent.worldTransform.array),l.default.multiply(r.array,n,e.array)):l.default.copy(r.array,e.array);var a=t?null:this.scale;r.decomposeMatrix(a,this.rotation,this.position)}),transformNeedsUpdate:function(){return this.position._dirty||this.rotation._dirty||this.scale._dirty},updateLocalTransform:function(){var t=this.position,r=this.rotation,e=this.scale;if(this.transformNeedsUpdate()){var n=this.localTransform.array;l.default.fromRotationTranslation(n,r.array,t.array),l.default.scale(n,n,e.array),r._dirty=!1,e._dirty=!1,t._dirty=!1,this._needsUpdateWorldTransform=!0}},_updateWorldTransformTopDown:function(){var t=this.localTransform.array,r=this.worldTransform.array;this._parent?l.default.multiplyAffine(r,this._parent.worldTransform.array,t):l.default.copy(r,t)},updateWorldTransform:function(){for(var t=this;t&&t.getParent()&&t.getParent().transformNeedsUpdate();)t=t.getParent();t.update()},update:function(t){this.autoUpdateLocalTransform?this.updateLocalTransform():t=!0,(t||this._needsUpdateWorldTransform)&&(this._updateWorldTransformTopDown(),t=!0,this._needsUpdateWorldTransform=!1);for(var r=this._children,e=0,n=r.length;e<n;e++)r[e].update(t)},getBoundingBox:function(){function t(t){return!t.invisible&&t.geometry}var r=new f.default,e=new s.default,n=new s.default;return function(a,o){return o=o||new f.default,this._parent?s.default.invert(n,this._parent.worldTransform):s.default.identity(n),this.traverse((function(t){t.geometry&&t.geometry.boundingBox&&(r.copy(t.geometry.boundingBox),s.default.multiply(e,n,t.worldTransform),r.applyTransform(e),o.union(r))}),this,t),o}}(),getWorldPosition:function(t){this.transformNeedsUpdate()&&this.updateWorldTransform();var r=this.worldTransform.array;if(t){var e=t.array;return e[0]=r[12],e[1]=r[13],e[2]=r[14],t}return new o.default(r[12],r[13],r[14])},clone:function(){var t=new this.constructor,r=this._children;t.setName(this.name),t.position.copy(this.position),t.rotation.copy(this.rotation),t.scale.copy(this.scale);for(var e=0;e<r.length;e++)t.add(r[e].clone());return t},rotateAround:(r=new o.default,e=new s.default,function(t,n,a){r.copy(this.position).subtract(t);var o=this.localTransform;o.identity(),o.translate(t),o.rotate(a,n),e.fromRotationTranslation(this.rotation,r),o.multiply(e),o.scale(this.scale),this.decomposeLocalTransform(),this._needsUpdateWorldTransform=!0}),lookAt:(t=new s.default,function(r,e){t.lookAt(this.position,r,e||this.localTransform.y).invert(),this.setLocalTransform(t),this.target=r})});exports.default=h;