From 43f0d66139ed1b9acf8180903b0905c8991d97e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= Date: Tue, 24 Jun 2014 11:41:16 -0300 Subject: [PATCH] Object3D add() can take arbitrary arguments and is chainable. Now is possible to do: obj.add( obj2, obj3 ); As well as: obj.add( obj2 ).add( obj3 ); Fixes #4958. --- build/three.js | 16 +++++++++++++++- build/three.min.js | 12 ++++++------ examples/canvas_geometry_nurbs.html | 6 ++++-- src/core/Object3D.js | 16 +++++++++++++++- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/build/three.js b/build/three.js index dd73adae5b..160829d9e0 100644 --- a/build/three.js +++ b/build/three.js @@ -7360,10 +7360,22 @@ THREE.Object3D.prototype = { add: function ( object ) { + if ( arguments.length > 1 ) { + + for ( var i = 0; i < arguments.length; i++ ) { + + this.add( arguments[ i ] ); + + } + + return this; + + }; + if ( object === this ) { console.warn( "THREE.Object3D.add: An object can't be added as a child of itself." ); - return; + return this; } @@ -7398,6 +7410,8 @@ THREE.Object3D.prototype = { } + return this; + }, remove: function ( object ) { diff --git a/build/three.min.js b/build/three.min.js index 098bbc6bee..ff9b6425d8 100644 --- a/build/three.min.js +++ b/build/three.min.js @@ -148,12 +148,12 @@ THREE.Object3D.prototype={constructor:THREE.Object3D,get eulerOrder(){console.wa applyMatrix:function(a){this.matrix.multiplyMatrices(a,this.matrix);this.matrix.decompose(this.position,this.quaternion,this.scale)},setRotationFromAxisAngle:function(a,b){this.quaternion.setFromAxisAngle(a,b)},setRotationFromEuler:function(a){this.quaternion.setFromEuler(a,!0)},setRotationFromMatrix:function(a){this.quaternion.setFromRotationMatrix(a)},setRotationFromQuaternion:function(a){this.quaternion.copy(a)},rotateOnAxis:function(){var a=new THREE.Quaternion;return function(b,c){a.setFromAxisAngle(b, c);this.quaternion.multiply(a);return this}}(),rotateX:function(){var a=new THREE.Vector3(1,0,0);return function(b){return this.rotateOnAxis(a,b)}}(),rotateY:function(){var a=new THREE.Vector3(0,1,0);return function(b){return this.rotateOnAxis(a,b)}}(),rotateZ:function(){var a=new THREE.Vector3(0,0,1);return function(b){return this.rotateOnAxis(a,b)}}(),translateOnAxis:function(){var a=new THREE.Vector3;return function(b,c){a.copy(b).applyQuaternion(this.quaternion);this.position.add(a.multiplyScalar(c)); return this}}(),translate:function(a,b){console.warn("THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.");return this.translateOnAxis(b,a)},translateX:function(){var a=new THREE.Vector3(1,0,0);return function(b){return this.translateOnAxis(a,b)}}(),translateY:function(){var a=new THREE.Vector3(0,1,0);return function(b){return this.translateOnAxis(a,b)}}(),translateZ:function(){var a=new THREE.Vector3(0,0,1);return function(b){return this.translateOnAxis(a, -b)}}(),localToWorld:function(a){return a.applyMatrix4(this.matrixWorld)},worldToLocal:function(){var a=new THREE.Matrix4;return function(b){return b.applyMatrix4(a.getInverse(this.matrixWorld))}}(),lookAt:function(){var a=new THREE.Matrix4;return function(b){a.lookAt(b,this.position,this.up);this.quaternion.setFromRotationMatrix(a)}}(),add:function(a){if(a===this)console.warn("THREE.Object3D.add: An object can't be added as a child of itself.");else if(a instanceof THREE.Object3D){void 0!==a.parent&& -a.parent.remove(a);a.parent=this;a.dispatchEvent({type:"added"});this.children.push(a);for(var b=this;void 0!==b.parent;)b=b.parent;void 0!==b&&b instanceof THREE.Scene&&b.__addObject(a)}},remove:function(a){var b=this.children.indexOf(a);if(-1!==b){a.parent=void 0;a.dispatchEvent({type:"removed"});this.children.splice(b,1);for(b=this;void 0!==b.parent;)b=b.parent;void 0!==b&&b instanceof THREE.Scene&&b.__removeObject(a)}},raycast:function(){},traverse:function(a){a(this);for(var b=0,c=this.children.length;b< -c;b++)this.children[b].traverse(a)},getObjectById:function(a,b){for(var c=0,d=this.children.length;ce&&0>f||0>g&& +b)}}(),localToWorld:function(a){return a.applyMatrix4(this.matrixWorld)},worldToLocal:function(){var a=new THREE.Matrix4;return function(b){return b.applyMatrix4(a.getInverse(this.matrixWorld))}}(),lookAt:function(){var a=new THREE.Matrix4;return function(b){a.lookAt(b,this.position,this.up);this.quaternion.setFromRotationMatrix(a)}}(),add:function(a){if(1e&&0>f||0>g&& 0>h)return!1;0>e?c=Math.max(c,e/(e-f)):0>f&&(d=Math.min(d,e/(e-f)));0>g?c=Math.max(c,g/(g-h)):0>h&&(d=Math.min(d,g/(g-h)));if(d 1 ) { + + for ( var i = 0; i < arguments.length; i++ ) { + + this.add( arguments[ i ] ); + + } + + return this; + + }; + if ( object === this ) { console.warn( "THREE.Object3D.add: An object can't be added as a child of itself." ); - return; + return this; } @@ -335,6 +347,8 @@ THREE.Object3D.prototype = { } + return this; + }, remove: function ( object ) { -- GitLab