Преглед на файлове

emit particles in global space by default, minor fixes in editor

ncannasse преди 11 години
родител
ревизия
81fd3572e4
променени са 3 файла, в които са добавени 35 реда и са изтрити 11 реда
  1. 3 1
      h3d/parts/Data.hx
  2. 19 9
      h3d/parts/Editor.hx
  3. 13 1
      h3d/parts/Emitter.hx

+ 3 - 1
h3d/parts/Data.hx

@@ -84,6 +84,7 @@ class State {
 	public var maxParts : Int;
 	public var shape : Shape;
 	public var emitFromShell : Bool;
+	public var emitLocal : Bool;
 	public var randomDir : Bool;
 
 	// system globals
@@ -132,6 +133,7 @@ class State {
 		maxParts = 1000;
 		shape = SCone(VConst(1),VConst(Math.PI/4));
 		emitFromShell = false;
+		emitLocal = false;
 		randomDir = false;
 		// system globals
 		globalLife = 1;
@@ -157,7 +159,7 @@ class State {
 		delay = 0.;
 	}
 	
-	public /*inline*/ function eval( v : Value, time : Float, rand : Void -> Float ) : Float {
+	public inline function eval( v : Value, time : Float, rand : Void -> Float ) : Float {
 		return switch( v ) {
 		case VConst(c): c;
 		case VRandom(s, l, c): s + (switch( c ) { case No: l; case Start: l * time; case End: l * (1 - time); }) * rand();

+ 19 - 9
h3d/parts/Editor.hx

@@ -49,7 +49,7 @@ class Editor extends h2d.Sprite {
 	var cedit : h2d.Interactive;
 	var undo : Array<History>;
 	var redo : Array<History>;
-	var currentFilePath : String;
+	public var currentFilePath : String;
 	public var autoLoop : Bool = true;
 	
 	static var CURVES : Array<{ name : String, f : Curve -> Data.Value }> = [
@@ -92,13 +92,7 @@ class Editor extends h2d.Sprite {
 	public dynamic function onTextureSelect() {
 		hxd.File.browse(function(sel) {
 			sel.load(function(bytes) {
-				var bmp = hxd.res.Any.fromBytes(sel.fileName, bytes).toBitmap();
-				var t = h2d.Tile.fromBitmap(bmp);
-				bmp.dispose();
-				state.textureName = sel.fileName;
-				curState = null; // force reload (if texture was changed)
-				setTexture(t);
-				buildUI();
+				changeTexture(sel.fileName, hxd.res.Any.fromBytes(sel.fileName, bytes).toTile());
 			});
 		},{
 			defaultPath : currentFilePath,
@@ -108,6 +102,13 @@ class Editor extends h2d.Sprite {
 		});
 	}
 	
+	public function changeTexture( name : String, t : h2d.Tile ) {
+		state.textureName = name;
+		curState = null; // force reload (if texture was changed)
+		setTexture(t);
+		buildUI();
+	}
+	
 	public dynamic function loadTexture( textureName : String ) : h2d.Tile {
 		var bytes = null;
 		try {
@@ -145,6 +146,12 @@ class Editor extends h2d.Sprite {
 	}
 	
 	public dynamic function onSave( saveData ) {
+		if( currentFilePath != null )
+			try {
+				hxd.File.saveBytes(currentFilePath, saveData);
+				return;
+			} catch( e : Dynamic ) {
+			}
 		if( currentFilePath == null ) currentFilePath = "default.p";
 		hxd.File.saveAs(saveData, {
 			defaultPath : currentFilePath,
@@ -429,6 +436,9 @@ class Editor extends h2d.Sprite {
 								<button class="ic" value="Angle" onclick="api.editCurve(\'angle\',true)"/>
 							</div>
 						</div>
+						<div class="line">
+							<checkbox checked="${state.emitLocal}" onchange="api.s.emitLocal = this.checked"/> <span>Emit Local</span>
+						</div>
 						<div class="line">
 							<checkbox checked="${state.emitFromShell}" onchange="api.s.emitFromShell = this.checked"/> <span>Emit from Shell</span>
 						</div>
@@ -884,7 +894,7 @@ class Editor extends h2d.Sprite {
 		rebuildCurve();
 	}
 
-	public function setTexture( t : h2d.Tile ) {
+	function setTexture( t : h2d.Tile ) {
 		state.frames = [t];
 		curTile = t;
 		state.initFrames();

+ 13 - 1
h3d/parts/Emitter.hx

@@ -156,6 +156,18 @@ class Emitter extends h3d.scene.Object {
 	
 	function initPart(p:Particle) {
 		initPosDir(p);
+		if( !state.emitLocal ) {
+			var pos = new h3d.Vector(p.x, p.y, p.z);
+			pos.transform3x4(absPos);
+			p.x = pos.x;
+			p.y = pos.y;
+			p.z = pos.z;
+			var v = new h3d.Vector(p.dx, p.dy, p.dz);
+			v.transform3x3(absPos);
+			p.dx = v.x;
+			p.dy = v.y;
+			p.dz = v.z;
+		}
 		p.time = 0;
 		p.lifeTimeFactor = 1 / eval(state.life, time, rand);
 	}
@@ -417,7 +429,7 @@ class Emitter extends h3d.scene.Object {
 		buffer.uploadVector(tmpBuf, 0, nverts);
 		var size = eval(state.globalSize, time, rand);
 		
-		material.pshader.mpos = this.absPos;
+		material.pshader.mpos = state.emitLocal ? this.absPos : h3d.Matrix.I();
 		material.pshader.mproj = ctx.camera.m;
 		material.pshader.partSize = new h3d.Vector(size, size * ctx.engine.width / ctx.engine.height);
 		material.pshader.hasColor = hasColor;