瀏覽代碼

Replaced TypedArray experiments.
TypeArrayVector3 wasn't a good idea because TypedArray are very slow to initialise.

Mr.doob 12 年之前
父節點
當前提交
a6929f1489
共有 2 個文件被更改,包括 178 次插入128 次删除
  1. 178 0
      examples/js/core/TypedGeometry.js
  2. 0 128
      examples/js/math/TypeArrayVector3.js

+ 178 - 0
examples/js/core/TypedGeometry.js

@@ -0,0 +1,178 @@
+THREE.TypedVector2 = function ( array, offset ) {
+
+	this.array = array;
+	this.offset = offset * 2;
+
+};
+
+THREE.TypedVector2.prototype = {
+
+	constructor: THREE.TypedVector3,
+
+	get x () {
+
+		return this.array[ this.offset ];
+
+	},
+
+	set x ( value ) {
+
+		this.array[ this.offset ] = value;
+
+	},
+
+	get y () {
+
+		return this.array[ this.offset + 1 ];
+
+	},
+
+	set y ( value ) {
+
+		this.array[ this.offset + 1 ] = value;
+
+	},
+
+	set: function ( x, y ) {
+
+		this.array[ this.offset ] = x;
+		this.array[ this.offset + 1 ] = y;
+		return this;
+
+	}
+
+};
+
+THREE.TypedVector3 = function ( array, offset ) {
+
+	this.array = array;
+	this.offset = offset * 3;
+
+};
+
+THREE.TypedVector3.prototype = {
+
+	constructor: THREE.TypedVector3,
+
+	get x () {
+
+		return this.array[ this.offset ];
+
+	},
+
+	set x ( value ) {
+
+		this.array[ this.offset ] = value;
+
+	},
+
+	get y () {
+
+		return this.array[ this.offset + 1 ];
+
+	},
+
+	set y ( value ) {
+
+		this.array[ this.offset + 1 ] = value;
+
+	},
+
+	get z () {
+
+		return this.array[ this.offset + 2 ];
+
+	},
+
+	set z ( value ) {
+
+		this.array[ this.offset + 2 ] = value;
+
+	},
+
+	set: function ( x, y, z ) {
+
+		this.array[ this.offset ] = x;
+		this.array[ this.offset + 1 ] = y;
+		this.array[ this.offset + 2 ] = z;
+		return this;
+
+	},
+
+	toString: function () {
+
+		return '[' + this.array[ this.offset ] + ',' + this.array[ this.offset + 1 ] + ',' + this.array[ this.offset + 2 ] + ']';
+
+	}
+
+};
+
+THREE.TypedFace = function ( positions, normals, uvs, offset ) {
+
+	this.positions = positions;
+	this.normals = normals;
+	this.uvs = uvs;
+	this.offset = offset * 3;
+
+};
+
+THREE.TypedFace.prototype = {
+
+	constructor: THREE.TypedFace,
+
+	vertex: function ( index ) {
+
+		return new THREE.TypedVector3( this.positions, this.offset + index );
+
+	},
+
+	normal: function ( index ) {
+
+		return new THREE.TypedVector3( this.normals, this.offset + index );
+
+	},
+
+	uv: function ( index ) {
+
+		return new THREE.TypedVector2( this.uvs, this.offset + index );
+
+	}
+
+}
+
+
+THREE.TypedGeometry = function ( size ) {
+
+	this.id = THREE.GeometryIdCount ++;
+	this.uuid = THREE.Math.generateUUID();
+
+	this.name = '';
+
+	this.positions = new Float32Array( size * 3 * 3 );
+	this.normals = new Float32Array( size * 3 * 3 );
+	this.uvs = new Float32Array( size * 3 * 2 );
+
+	this.boundingBox = null;
+	this.boundingSphere = null;
+
+};
+
+THREE.TypedGeometry.prototype = {
+
+	constructor: THREE.TypedGeometry,
+
+	face: function ( index ) {
+
+		return new THREE.TypedFace( this.positions, this.normals, this.uvs, index );
+
+	},
+
+	dispose: function () {
+
+		this.dispatchEvent( { type: 'dispose' } );
+
+	}
+
+};
+
+THREE.EventDispatcher.prototype.apply( THREE.TypedGeometry.prototype );

+ 0 - 128
examples/js/math/TypeArrayVector3.js

@@ -1,128 +0,0 @@
-THREE.TypeArrayVector3 = function ( x, y, z ) {
-
-	this.elements = new Float64Array( 3 );
-	this.set( x, y, z );
-
-};
-
-
-THREE.TypeArrayVector3.prototype = {
-
-	constructor: THREE.TypeArrayVector3,
-
-	get x() {
-
-		return this.elements[ 0 ];
-
-	},
-
-	set x( value ) {
-
-		this.elements[ 0 ] = value;
-
-	},
-
-	get y() {
-
-		return this.elements[ 1 ];
-
-	},
-
-	set y( value ) {
-
-		this.elements[ 1 ] = value;
-
-	},
-
-	get z() {
-
-		return this.elements[ 2 ];
-
-	},
-
-	set z( value ) {
-
-		this.elements[ 2 ] = value;
-
-	},
-
-	set: function ( x, y, z ) {
-
-		var elements = this.elements;
-
-		elements[ 0 ] = x;
-		elements[ 1 ] = y;
-		elements[ 2 ] = z;
-
-		return this;
-
-	},
-
-	copy: function ( v ) {
-
-		var elements = this.elements;
-		var velements = v.elements;
-
-		elements[ 0 ] = velements[ 0 ];
-		elements[ 1 ] = velements[ 1 ];
-		elements[ 2 ] = velements[ 2 ];
-
-		return this;
-
-	},
-
-	add: function ( v ) {
-
-		var elements = this.elements;
-		var velements = v.elements;
-
-		elements[ 0 ] += velements[ 0 ];
-		elements[ 1 ] += velements[ 1 ];
-		elements[ 2 ] += velements[ 2 ];
-
-		return this;
-
-	},
-
-	addVectors: function ( a, b ) {
-
-		var elements = this.elements;
-		var aelements = a.elements;
-		var belements = b.elements;
-
-		elements[ 0 ] = aelements[ 0 ] + belements[ 0 ];
-		elements[ 1 ] = aelements[ 1 ] + belements[ 1 ];
-		elements[ 2 ] = aelements[ 2 ] + belements[ 2 ];
-
-		return this;
-
-	},
-
-	sub: function ( v, w ) {
-
-		var elements = this.elements;
-		var velements = v.elements;
-
-		elements[ 0 ] -= velements[ 0 ];
-		elements[ 1 ] -= velements[ 1 ];
-		elements[ 2 ] -= velements[ 2 ];
-
-		return this;
-
-	},
-
-	subVectors: function ( a, b ) {
-
-		var elements = this.elements;
-		var aelements = a.elements;
-		var belements = b.elements;
-
-		elements[ 0 ] = aelements[ 0 ] - belements[ 0 ];
-		elements[ 1 ] = aelements[ 1 ] - belements[ 1 ];
-		elements[ 2 ] = aelements[ 2 ] - belements[ 2 ];
-
-		return this;
-
-	}
-
-}