Permalink
Browse files

added convert.Vector3

  • Loading branch information...
1 parent 86847fe commit f7cf82513d4552adde458394748bb78e6ffa3fb1 @jeromeetienne committed Feb 27, 2013
Showing with 27 additions and 7 deletions.
  1. +3 −6 js/plugins/tquery.object3d.geometry.js
  2. +15 −0 js/tquery.convert.js
  3. +9 −1 js/tquery.object3d.js
@@ -10,13 +10,10 @@ tQuery.Object3D.registerInstance('position', function(vector3){
// handle the getter
if( vector3 === undefined ) return this.get(0).position;
// handle parameters
- if( typeof vector3 === "number" && arguments.length === 3 ){
- vector3 = new THREE.Vector3(arguments[0], arguments[1], arguments[2]);
- }
- console.assert(vector3 instanceof THREE.Vector3, "Object3D.position parameter error");
+ vector3 = tQuery.convert.toVector3.apply(null, arguments);
// do the operation on each node
- this.each(function(object3d){
- object3d.position.copy(vector3);
+ this.each(function(tObject3d){
+ tObject3d.position.copy(vector3);
});
// return this, to get chained API
return this;
View
@@ -20,6 +20,21 @@ tQuery.convert.toThreeColor = function(/* arguments */){
return undefined; // never reached - just to workaround linter complaint
};
+/**
+ * Convert the arguments into a THREE.Vector3
+ * @return {THREE.Vector3} the resulting THREE.Vector3
+ */
+tQuery.convert.toVector3 = function(/* arguments */){
+ // handle parameters
+ if( arguments[0] instanceof THREE.Vector3 && arguments.length === 1 ){
+ return arguments[0]
+ }else if( typeof arguments[0] === "number" && arguments.length === 3 ){
+ return new THREE.Vector3(arguments[0], arguments[1], arguments[2]);
+ }else{
+ console.assert(false, "invalid parameter for Vector3");
+ }
+};
+
tQuery.convert.toNumber = function(value){
if( arguments.length === 1 && typeof(value) === 'number'){
return value;
View
@@ -106,13 +106,21 @@ tQuery.Object3D.prototype.material = function(){
*/
tQuery.Object3D.prototype.clone = function(){
var clones = [];
- this._lists.forEach(function(tObject3d){
+ this.each(function(tObject3d){
var clone = tObject3d.clone();
clones.push(clone);
})
return tQuery(clones)
}
+tQuery.Object3D.prototype.lookAt = function(position){
+ position = tQuery.convert.toVector3.apply(null, arguments);
+ this.each(function(tObject3d){
+ tObject3d.lookAt(position)
+ })
+ return this;
+};
+
//////////////////////////////////////////////////////////////////////////////////
// addTo/removeFrom tQuery.World/tQuery.Object3d //
//////////////////////////////////////////////////////////////////////////////////

0 comments on commit f7cf825

Please sign in to comment.