Prechádzať zdrojové kódy

Experimenting with beautifier.
Maybe it would be simpler if BufferGeometry had some sort of .makePretty() method that added all the arrays.

Mr.doob 11 rokov pred
rodič
commit
7c243d2a79

+ 5 - 1
examples/canvas_geometry_terrain.html

@@ -36,6 +36,8 @@
 
 		<script src="../build/three.min.js"></script>
 
+		<script src="js/wip/Geometry5b.js"></script>
+
 		<script src="js/ImprovedNoise.js"></script>
 		<script src="js/libs/stats.min.js"></script>
 
@@ -75,9 +77,11 @@
 				var plane = new THREE.PlaneGeometry( 2000, 2000, quality - 1, quality - 1 );
 				plane.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
 
+				plane = new THREE.Geometry5b( plane );
+
 				for ( var i = 0, l = plane.vertices.length; i < l; i ++ ) {
 
-					var x = i % quality, y = ~~ ( i / quality );
+					var x = i % quality, y = Math.floor( i / quality );
 					plane.vertices[ i ].y = data[ ( x * step ) + ( y * step ) * 1024 ] * 2 - 128;
 
 				}

+ 73 - 0
examples/js/wip/Geometry5b.js

@@ -0,0 +1,73 @@
+/**
+ * @author mrdoob / http://mrdoob.com/
+ */
+
+THREE.Geometry5b = function ( bufferGeometry ) {
+
+	THREE.BufferGeometry.call( this );
+
+	this.attributes = bufferGeometry.attributes;
+
+	var verticesBuffer = this.attributes.position.array;
+	var normalsBuffer = this.attributes.normal.array;
+	var uvsBuffer = this.attributes.uv.array;
+
+	this.vertices = [];
+	this.normals = [];
+	this.uvs = [];
+
+	for ( var i = 0; i < verticesBuffer.length; i ++ ) {
+
+		this.vertices.push( new THREE.TypedVector3( verticesBuffer, i * 3 ) );
+		this.normals.push( new THREE.TypedVector3( normalsBuffer, i * 3 ) );
+		this.uvs.push( new THREE.TypedVector2( uvsBuffer, i * 2 ) );
+
+	}
+
+};
+
+THREE.Geometry5b.prototype = Object.create( THREE.BufferGeometry.prototype );
+
+THREE.TypedVector2 = function ( array, offset ) {
+
+	this.array = array;
+	this.offset = offset;
+	
+};
+
+THREE.TypedVector2.prototype = Object.create( THREE.Vector2.prototype );
+
+Object.defineProperties( THREE.TypedVector2.prototype, {
+	'x': {
+		get: function () { return this.array[ this.offset ]; },
+		set: function ( v ) { this.array[ this.offset ] = v; }
+	},
+	'y': {
+		get: function () { return this.array[ this.offset + 1 ]; },
+		set: function ( v ) { this.array[ this.offset + 1 ] = v; }
+	}
+} );
+
+THREE.TypedVector3 = function ( array, offset ) {
+	
+	this.array = array;
+	this.offset = offset;
+
+};
+
+THREE.TypedVector3.prototype = Object.create( THREE.Vector3.prototype );
+
+Object.defineProperties( THREE.TypedVector3.prototype, {
+	'x': {
+		get: function () { return this.array[ this.offset ]; },
+		set: function ( v ) { this.array[ this.offset ] = v; }
+	},
+	'y': {
+		get: function () { return this.array[ this.offset + 1 ]; },
+		set: function ( v ) { this.array[ this.offset + 1 ] = v; }
+	},
+	'z': {
+		get: function () { return this.array[ this.offset + 2 ]; },
+		set: function ( v ) { this.array[ this.offset + 2 ] = v; }
+	}
+} );