Browse Source

- Added ParticleBitmapMaterial.offset (Vector2)

Mr.doob 15 years ago
parent
commit
217b1505a3

File diff suppressed because it is too large
+ 0 - 0
build/three.js


+ 22 - 3
examples/particles.html

@@ -19,6 +19,7 @@
 	<body>
 	<body>
 
 
 		<script type="text/javascript" src="http://github.com/mrdoob/stats.js/raw/master/build/stats.js"></script>
 		<script type="text/javascript" src="http://github.com/mrdoob/stats.js/raw/master/build/stats.js"></script>
+		<script type="text/javascript" src="http://github.com/mrdoob/tween.js/raw/master/build/tween.js"></script>
 
 
 		<script type="text/javascript" src="../build/three.js"></script>
 		<script type="text/javascript" src="../build/three.js"></script>
 
 
@@ -30,7 +31,7 @@
 			var stats;
 			var stats;
 			var container;
 			var container;
 
 
-			var particle;
+			var particles, particle;
 
 
 			var camera;
 			var camera;
 			var scene;
 			var scene;
@@ -70,16 +71,24 @@
 				}
 				}
 
 
 				var material = loadTexture( 'textures/Tree_01.png' );
 				var material = loadTexture( 'textures/Tree_01.png' );
+				material.offset.y = 219;
+
+				particles = [];
 
 
 				for (var i = 0; i < 10; i++) {
 				for (var i = 0; i < 10; i++) {
 
 
-					particle = new THREE.Particle( material );
+					particles[ i ] = particle = new THREE.Particle( material );
 					particle.position.x = Math.random() * 2000 - 1000;
 					particle.position.x = Math.random() * 2000 - 1000;
 					// particle.position.y = Math.random() * 2000 - 1000;
 					// particle.position.y = Math.random() * 2000 - 1000;
 					particle.position.z = Math.random() * 2000 - 1000;
 					particle.position.z = Math.random() * 2000 - 1000;
 					// particle.rotation.z = 90 * Math.PI / 180;
 					// particle.rotation.z = 90 * Math.PI / 180;
-					// particle.scale.x = particle.scale.y = Math.random();
+					particle.scale.x = particle.scale.y = Math.random();
+					// particle.scale.y = 0;
 					scene.add(particle);
 					scene.add(particle);
+
+					// new TWEEN.Tween( particle.rotation ).to( 1, { z: Math.random() + 1 } );
+					new TWEEN.Tween( particle.scale ).to( 1, { x: Math.random() + 1, y: Math.random() + 1 } );
+
 				}
 				}
 
 
 				container.appendChild(renderer.domElement);
 				container.appendChild(renderer.domElement);
@@ -145,9 +154,19 @@
 
 
 			function loop() {
 			function loop() {
 
 
+				TWEEN_MANAGER.update();
+
 				camera.position.x += (mouseX - camera.position.x) * .05;
 				camera.position.x += (mouseX - camera.position.x) * .05;
 				camera.position.y += (-mouseY - camera.position.y) * .05;
 				camera.position.y += (-mouseY - camera.position.y) * .05;
 
 
+				/*
+				for ( var i = 0, l = particles.length; i < l; i ++ ) {
+
+					particles[ i ].rotation.z += 0.01;
+
+				}
+				*/
+
 				renderer.render(scene, camera);
 				renderer.render(scene, camera);
 
 
 				stats.update();
 				stats.update();

+ 6 - 0
src/core/UV.js

@@ -16,6 +16,12 @@ THREE.UV.prototype = {
 		this.u = uv.u;
 		this.u = uv.u;
 		this.v = uv.v;
 		this.v = uv.v;
 
 
+	},
+
+	toString: function () {
+
+		return 'THREE.UV (' + this.u + ', ' + this.v + ')';
+
 	}
 	}
 
 
 }
 }

+ 1 - 0
src/materials/ParticleBitmapMaterial.js

@@ -5,6 +5,7 @@
 THREE.ParticleBitmapMaterial = function ( bitmap ) {
 THREE.ParticleBitmapMaterial = function ( bitmap ) {
 
 
 	this.bitmap = bitmap;
 	this.bitmap = bitmap;
+	this.offset = new THREE.Vector2();
 
 
 	this.toString = function () {
 	this.toString = function () {
 
 

+ 23 - 5
src/renderers/CanvasRenderer.js

@@ -43,7 +43,7 @@ THREE.CanvasRenderer = function () {
 	this.render = function ( scene, camera ) {
 	this.render = function ( scene, camera ) {
 
 
 		var e, el, m, ml, element, material, pi2 = Math.PI * 2,
 		var e, el, m, ml, element, material, pi2 = Math.PI * 2,
-		v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y, width, height,
+		v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y, width, height, scaleX, scaleY,
 
 
 		uv1 = new THREE.UV(), uv2 = new THREE.UV(), uv3 = new THREE.UV(), uv4 = new THREE.UV(),
 		uv1 = new THREE.UV(), uv2 = new THREE.UV(), uv3 = new THREE.UV(), uv4 = new THREE.UV(),
 		bitmap, bitmapWidth, bitmapHeight;
 		bitmap, bitmapWidth, bitmapHeight;
@@ -108,8 +108,13 @@ THREE.CanvasRenderer = function () {
 						bitmapWidth = bitmap.width / 2;
 						bitmapWidth = bitmap.width / 2;
 						bitmapHeight = bitmap.height / 2;
 						bitmapHeight = bitmap.height / 2;
 
 
-						width = element.scale.x * _widthHalf * bitmapWidth;
-						height = element.scale.y * _heightHalf * bitmapHeight;
+						scaleX = element.scale.x * _widthHalf;
+						scaleY = element.scale.y * _heightHalf;
+
+						width = scaleX * bitmapWidth;
+						height = scaleY * bitmapHeight;
+
+						// TODO: Rotations, offset break this...
 
 
 						_bboxRect.set( v1x - width, v1y - height, v1x + width, v1y + height );
 						_bboxRect.set( v1x - width, v1y - height, v1x + width, v1y + height );
 
 
@@ -120,14 +125,26 @@ THREE.CanvasRenderer = function () {
 						}
 						}
 
 
 						_context.save();
 						_context.save();
-						_context.translate( v1x - width, v1y + height );
+						_context.translate( v1x, v1y );
 						_context.rotate( - element.rotation );
 						_context.rotate( - element.rotation );
-						_context.scale( element.scale.x * _widthHalf, - ( element.scale.y * _heightHalf ) );
+						_context.scale( scaleX, - scaleY );
+						_context.translate( - bitmapWidth + material.offset.x, - bitmapHeight - material.offset.y );
 
 
 						_context.drawImage( bitmap, 0, 0 );
 						_context.drawImage( bitmap, 0, 0 );
 
 
 						_context.restore();
 						_context.restore();
 
 
+						/*
+						_context.beginPath();
+						_context.moveTo( v1x - 10, v1y );
+						_context.lineTo( v1x + 10, v1y );
+						_context.moveTo( v1x, v1y - 10 );
+						_context.lineTo( v1x, v1y + 10 );
+						_context.closePath();
+						_context.strokeStyle = 'rgb(255,255,0)';
+						_context.stroke();
+						*/
+
 					}
 					}
 
 
 				}
 				}
@@ -455,6 +472,7 @@ THREE.CanvasRenderer = function () {
 
 
 			_clearRect.addRectangle( _bboxRect );
 			_clearRect.addRectangle( _bboxRect );
 
 
+
 		}
 		}
 
 
 		/* DEBUG
 		/* DEBUG

+ 0 - 0
utils/deployer.py → utils/builder.py


+ 0 - 0
utils/deployer_debug.py → utils/builder_debug.py


Some files were not shown because too many files changed in this diff