浏览代码

Merge branch 'master' of https://github.com/ncannasse/heaps into lime

kiroukou 9 年之前
父节点
当前提交
77bdc54a7f

+ 27 - 1
h2d/Font.hx

@@ -36,6 +36,12 @@ class FontChar {
 		}
 		}
 		return 0;
 		return 0;
 	}
 	}
+	
+	public function clone() {
+		var c = new FontChar(t.clone(), width);
+		c.kerning = kerning;
+		return c;
+	}
 
 
 }
 }
 
 
@@ -66,6 +72,23 @@ class Font {
 		}
 		}
 		return c;
 		return c;
 	}
 	}
+	
+	public function clone() {
+		var f = new Font(name, size);
+		f.baseLine = baseLine;
+		f.lineHeight = lineHeight;
+		f.tile = tile.clone();
+		f.charset = charset;
+		f.defaultChar = defaultChar.clone();
+		for( g in glyphs.keys() ) {
+			var c = glyphs.get(g);
+			var c2 = c.clone();
+			if( c == defaultChar )
+				f.defaultChar = c2;
+			f.glyphs.set(g, c2);
+		}
+		return f;
+	}
 
 
 	/**
 	/**
 		This is meant to create smoother fonts by creating them with double size while still keeping the original glyph size.
 		This is meant to create smoother fonts by creating them with double size while still keeping the original glyph size.
@@ -75,8 +98,11 @@ class Font {
 		for( c in glyphs ) {
 		for( c in glyphs ) {
 			c.width = Std.int(c.width * ratio);
 			c.width = Std.int(c.width * ratio);
 			c.t.scaleToSize(Std.int(c.t.width * ratio), Std.int(c.t.height * ratio));
 			c.t.scaleToSize(Std.int(c.t.width * ratio), Std.int(c.t.height * ratio));
-		}
+			c.t.dx = Std.int(c.t.dx * ratio);
+			c.t.dy = Std.int(c.t.dy * ratio);
+		}		
 		lineHeight = Std.int(lineHeight * ratio);
 		lineHeight = Std.int(lineHeight * ratio);
+		baseLine = Std.int(baseLine * ratio);
 		this.size = size;
 		this.size = size;
 	}
 	}
 
 

+ 4 - 3
h2d/Text.hx

@@ -187,7 +187,7 @@ class Text extends Drawable {
 		case Center, Right:
 		case Center, Right:
 			lines = [];
 			lines = [];
 			initGlyphs(text, false, lines);
 			initGlyphs(text, false, lines);
-			var max = maxWidth == null ? calcWidth : Std.int(maxWidth);
+			var max = maxWidth == null ? 0 : Std.int(maxWidth);
 			var k = align == Center ? 1 : 0;
 			var k = align == Center ? 1 : 0;
 			for( i in 0...lines.length )
 			for( i in 0...lines.length )
 				lines[i] = (max - lines[i]) >> k;
 				lines[i] = (max - lines[i]) >> k;
@@ -201,7 +201,8 @@ class Text extends Drawable {
 			var cc = text.charCodeAt(i);
 			var cc = text.charCodeAt(i);
 			var e = font.getChar(cc);
 			var e = font.getChar(cc);
 			var newline = cc == '\n'.code;
 			var newline = cc == '\n'.code;
-			var esize = e.width + e.getKerningOffset(prevChar);
+			var offs = e.getKerningOffset(prevChar);
+			var esize = e.width + offs;
 			// if the next word goes past the max width, change it into a newline
 			// if the next word goes past the max width, change it into a newline
 			if( font.charset.isBreakChar(cc) && maxWidth != null ) {
 			if( font.charset.isBreakChar(cc) && maxWidth != null ) {
 				var size = x + esize + letterSpacing;
 				var size = x + esize + letterSpacing;
@@ -220,7 +221,7 @@ class Text extends Drawable {
 				}
 				}
 			}
 			}
 			if( e != null ) {
 			if( e != null ) {
-				if( rebuild ) glyphs.add(x, y, e.t);
+				if( rebuild ) glyphs.add(x + offs, y, e.t);
 				if( y == 0 && e.t.dy < yMin ) yMin = e.t.dy;
 				if( y == 0 && e.t.dy < yMin ) yMin = e.t.dy;
 				x += esize + letterSpacing;
 				x += esize + letterSpacing;
 			}
 			}

+ 2 - 2
h3d/col/Bounds.hx

@@ -1,7 +1,7 @@
 package h3d.col;
 package h3d.col;
 import hxd.Math;
 import hxd.Math;
 
 
-class Bounds implements RayCollider {
+class Bounds implements Collider {
 
 
 	public var xMin : Float;
 	public var xMin : Float;
 	public var xMax : Float;
 	public var xMax : Float;
@@ -163,7 +163,7 @@ class Bounds implements RayCollider {
 		return !(xMin > b.xMax || yMin > b.yMax || zMin > b.zMax || xMax < b.xMin || yMax < b.yMin || zMax < b.zMin);
 		return !(xMin > b.xMax || yMin > b.yMax || zMin > b.zMax || xMax < b.xMin || yMax < b.yMin || zMax < b.zMin);
 	}
 	}
 
 
-	public inline function include( p : Point ) {
+	public inline function contains( p : Point ) {
 		return p.x >= xMin && p.x < xMax && p.y >= yMin && p.y < yMax && p.z >= zMin && p.z < zMax;
 		return p.x >= xMin && p.x < xMax && p.y >= yMin && p.y < yMax && p.z >= zMin && p.z < zMax;
 	}
 	}
 
 

+ 36 - 0
h3d/col/Collider.hx

@@ -0,0 +1,36 @@
+package h3d.col;
+
+interface Collider {
+
+	public function rayIntersection( r : Ray, ?p : Point ) : Null<Point>;
+	public function contains( p : Point ) : Bool;
+	public function inFrustum( mvp : h3d.Matrix ) : Bool;
+
+}
+
+
+class OptimizedCollider implements Collider {
+
+	public var a : Collider;
+	public var b : Collider;
+
+	public function new(a, b) {
+		this.a = a;
+		this.b = b;
+	}
+
+	public function rayIntersection( r : Ray, ?p : Point ) : Null<Point> {
+		if( a.rayIntersection(r, p) == null )
+			return null;
+		return b.rayIntersection(r, p);
+	}
+	
+	public function contains( p : Point ) {
+		return a.contains(p) && b.contains(p);
+	}
+	
+	public function inFrustum( mvp : h3d.Matrix ) {
+		return a.inFrustum(mvp) && b.inFrustum(mvp);
+	}
+
+}

+ 37 - 2
h3d/col/Polygon.hx

@@ -1,6 +1,6 @@
 package h3d.col;
 package h3d.col;
 
 
-class TriPlane implements RayCollider {
+class TriPlane implements Collider {
 
 
 	public var next : TriPlane;
 	public var next : TriPlane;
 
 
@@ -52,6 +52,19 @@ class TriPlane implements RayCollider {
 		dot11 = d2.dot(d2);
 		dot11 = d2.dot(d2);
 		invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
 		invDenom = 1 / (dot00 * dot11 - dot01 * dot01);
 	}
 	}
+	
+	public inline function contains( p : Point ) {
+		return isPointInTriangle(p.x, p.y, p.z);
+	}
+	
+	public inline function side( p : Point ) {
+		return nx * p.x + ny * p.y + nz * p.z - d >= 0;
+	}
+	
+	public function inFrustum( m : h3d.Matrix ) {
+		throw "Not implemented";
+		return false;
+	}
 
 
 	inline public function rayIntersection( r : Ray, ?pt : Point ) @:privateAccess {
 	inline public function rayIntersection( r : Ray, ?pt : Point ) @:privateAccess {
 		var dr = r.lx * nx + r.ly * ny + r.lz * nz;
 		var dr = r.lx * nx + r.ly * ny + r.lz * nz;
@@ -90,7 +103,7 @@ class TriPlane implements RayCollider {
 }
 }
 
 
 
 
-class Polygon implements RayCollider {
+class Polygon implements Collider {
 
 
 	var triPlanes : TriPlane;
 	var triPlanes : TriPlane;
 
 
@@ -117,6 +130,23 @@ class Polygon implements RayCollider {
 			triPlanes = t;
 			triPlanes = t;
 		}
 		}
 	}
 	}
+	
+	public function isConvex() {
+		// TODO : check + cache result
+		return true;
+	}
+	
+	public function contains( p : Point ) {	
+		if( !isConvex() )
+			throw "Not implemented for concave polygon";
+		var t = triPlanes;
+		while( t != null ) {
+			if( t.side(p) )
+				return false;
+			t = t.next;
+		}
+		return true;
+	}
 
 
 	public function rayIntersection( r : Ray, ?pt : Point ) {
 	public function rayIntersection( r : Ray, ?pt : Point ) {
 		var t = triPlanes;
 		var t = triPlanes;
@@ -128,4 +158,9 @@ class Polygon implements RayCollider {
 		return null;
 		return null;
 	}
 	}
 
 
+	public function inFrustum( m : h3d.Matrix ) {
+		throw "Not implemented";
+		return false;
+	}
+
 }
 }

+ 0 - 26
h3d/col/RayCollider.hx

@@ -1,26 +0,0 @@
-package h3d.col;
-
-interface RayCollider {
-
-	public function rayIntersection( r : Ray, ?p : Point ) : Null<Point>;
-
-}
-
-
-class OptimizedCollider implements RayCollider {
-
-	public var a : RayCollider;
-	public var b : RayCollider;
-
-	public function new(a, b) {
-		this.a = a;
-		this.b = b;
-	}
-
-	public function rayIntersection( r : Ray, ?p : Point ) : Null<Point> {
-		if( a.rayIntersection(r, p) == null )
-			return null;
-		return b.rayIntersection(r, p);
-	}
-
-}

+ 8 - 1
h3d/col/Sphere.hx

@@ -1,6 +1,6 @@
 package h3d.col;
 package h3d.col;
 
 
-class Sphere implements RayCollider {
+class Sphere implements Collider {
 
 
 	public var x : Float;
 	public var x : Float;
 	public var y : Float;
 	public var y : Float;
@@ -17,6 +17,13 @@ class Sphere implements RayCollider {
 	public inline function getCenter() {
 	public inline function getCenter() {
 		return new Point(x, y, z);
 		return new Point(x, y, z);
 	}
 	}
+	
+	public inline function contains( p : Point ) {
+		var dx = p.x - x;
+		var dy = p.y - y;
+		var dz = p.z - z;
+		return dx * dx + dy * dy + dz * dz < r * r;
+	}
 
 
 	public function rayIntersection( r : Ray, ?p : Point ) : Null<Point> {
 	public function rayIntersection( r : Ray, ?p : Point ) : Null<Point> {
 		var r2 = this.r * this.r;
 		var r2 = this.r * this.r;

+ 1 - 1
h3d/prim/Cube.hx

@@ -62,7 +62,7 @@ class Cube extends Polygon {
 		];
 		];
 	}
 	}
 
 
-	override public function getCollider() : h3d.col.RayCollider {
+	override public function getCollider() : h3d.col.Collider {
 		return h3d.col.Bounds.fromValues(translatedX, translatedY, translatedZ, sizeX * scaled, sizeY * scaled, sizeZ * scaled);
 		return h3d.col.Bounds.fromValues(translatedX, translatedY, translatedZ, sizeX * scaled, sizeY * scaled, sizeZ * scaled);
 	}
 	}
 
 

+ 2 - 2
h3d/prim/HMDModel.hx

@@ -8,7 +8,7 @@ class HMDModel extends MeshPrimitive {
 	var indexesTriPos : Array<Int>;
 	var indexesTriPos : Array<Int>;
 	var lib : hxd.fmt.hmd.Library;
 	var lib : hxd.fmt.hmd.Library;
 	var curMaterial : Int;
 	var curMaterial : Int;
-	var collider : h3d.col.RayCollider;
+	var collider : h3d.col.Collider;
 	var normalsRecomputed : String;
 	var normalsRecomputed : String;
 
 
 	public function new(data, dataPos, lib) {
 	public function new(data, dataPos, lib) {
@@ -140,7 +140,7 @@ class HMDModel extends MeshPrimitive {
 		var poly = new h3d.col.Polygon();
 		var poly = new h3d.col.Polygon();
 		poly.addBuffers(pos.vertexes, pos.indexes);
 		poly.addBuffers(pos.vertexes, pos.indexes);
 		var sphere = data.bounds.toSphere();
 		var sphere = data.bounds.toSphere();
-		collider = new h3d.col.RayCollider.OptimizedCollider(sphere, poly);
+		collider = new h3d.col.Collider.OptimizedCollider(sphere, poly);
 		return collider;
 		return collider;
 	}
 	}
 
 

+ 1 - 1
h3d/prim/Polygon.hx

@@ -178,7 +178,7 @@ class Polygon extends Primitive {
 		return points.length;
 		return points.length;
 	}
 	}
 
 
-	override function getCollider() : h3d.col.RayCollider {
+	override function getCollider() : h3d.col.Collider {
 		var vertexes = new haxe.ds.Vector<hxd.impl.Float32>(points.length * 3);
 		var vertexes = new haxe.ds.Vector<hxd.impl.Float32>(points.length * 3);
 		var indexes = new haxe.ds.Vector<hxd.impl.UInt16>(idx.length);
 		var indexes = new haxe.ds.Vector<hxd.impl.UInt16>(idx.length);
 		var vid = 0;
 		var vid = 0;

+ 1 - 1
h3d/prim/Primitive.hx

@@ -13,7 +13,7 @@ class Primitive {
 		return 0;
 		return 0;
 	}
 	}
 
 
-	public function getCollider() : h3d.col.RayCollider {
+	public function getCollider() : h3d.col.Collider {
 		throw "not implemented";
 		throw "not implemented";
 		return null;
 		return null;
 	}
 	}

+ 1 - 1
h3d/prim/Sphere.hx

@@ -40,7 +40,7 @@ class Sphere extends Polygon {
 		super(pts, idx);
 		super(pts, idx);
 	}
 	}
 
 
-	override public function getCollider() : h3d.col.RayCollider {
+	override public function getCollider() : h3d.col.Collider {
 		return new h3d.col.Sphere(translatedX, translatedY, translatedZ, ray * scaled);
 		return new h3d.col.Sphere(translatedX, translatedY, translatedZ, ray * scaled);
 	}
 	}
 
 

+ 1 - 1
h3d/scene/Interactive.hx

@@ -2,7 +2,7 @@ package h3d.scene;
 
 
 class Interactive extends Object implements hxd.SceneEvents.Interactive {
 class Interactive extends Object implements hxd.SceneEvents.Interactive {
 
 
-	public var shape : h3d.col.RayCollider;
+	public var shape : h3d.col.Collider;
 	public var cursor(default,set) : hxd.System.Cursor;
 	public var cursor(default,set) : hxd.System.Cursor;
 	/**
 	/**
 		Set the default `cancel` mode (see `hxd.Event`), default to false.
 		Set the default `cancel` mode (see `hxd.Event`), default to false.

+ 7 - 0
h3d/scene/Scene.hx

@@ -72,6 +72,13 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 				var minv = i.getInvPos();
 				var minv = i.getInvPos();
 				r.transform(minv);
 				r.transform(minv);
 				r.normalize();
 				r.normalize();
+				
+				// check for NaN
+				if( r.lx != r.lx ) {
+					r.load(saveR);
+					continue;
+				}
+				
 				var hit = i.shape.rayIntersection(r, hitTmp);
 				var hit = i.shape.rayIntersection(r, hitTmp);
 				r.load(saveR);
 				r.load(saveR);
 				if( hit == null ) continue;
 				if( hit == null ) continue;

+ 1 - 1
hxd/fmt/fbx/HMDOut.hx

@@ -325,7 +325,7 @@ class HMDOut extends BaseLibrary {
 					if( p != null ) p.childs.remove(o);
 					if( p != null ) p.childs.remove(o);
 					// move not joint to new parent
 					// move not joint to new parent
 					// (only first level, others will follow their respective joint)
 					// (only first level, others will follow their respective joint)
-					for( c in o.childs )
+					for( c in o.childs.copy() )
 						if( !c.isJoint ) {
 						if( !c.isJoint ) {
 							o.childs.remove(c);
 							o.childs.remove(c);
 							o2.childs.push(c);
 							o2.childs.push(c);

+ 2 - 2
hxd/net/Macros.hx

@@ -850,7 +850,7 @@ class Macros {
 				public inline function networkCancelProperty( props : hxd.net.NetworkSerializable.NetworkProperty ) {
 				public inline function networkCancelProperty( props : hxd.net.NetworkSerializable.NetworkProperty ) {
 					__bits &= ~props.toInt();
 					__bits &= ~props.toInt();
 				}
 				}
-				inline function networkLocalChange( f : Void -> Void ) {
+				public inline function networkLocalChange( f : Void -> Void ) {
 					var old = __host;
 					var old = __host;
 					__host = null;
 					__host = null;
 					f();
 					f();
@@ -997,7 +997,7 @@ class Macros {
 					var __ctx = @:privateAccess __host.beginRPC(this,$v{id},$resultCall);
 					var __ctx = @:privateAccess __host.beginRPC(this,$v{id},$resultCall);
 					$b{[
 					$b{[
 						for( a in f.args )
 						for( a in f.args )
-							macro hxd.net.Macros.serializeValue(__ctx,$i{a.name})
+							withPos(macro hxd.net.Macros.serializeValue(__ctx, $i{a.name}), f.expr.pos)
 					] };
 					] };
 					@:privateAccess __host.endRPC();
 					@:privateAccess __host.endRPC();
 				};
 				};

+ 1 - 1
tools/fbx/TreeView.hx

@@ -10,7 +10,7 @@ class Joint {
 	public function new (j : h3d.anim.Skin.Joint, parent: h3d.scene.Skin) {
 	public function new (j : h3d.anim.Skin.Joint, parent: h3d.scene.Skin) {
 		this.j = j;
 		this.j = j;
 
 
-		var p = new h3d.prim.Sphere(16, 16);
+		var p = new h3d.prim.Sphere(1, 16, 16);
 		p.addNormals();
 		p.addNormals();
 		s = new h3d.scene.Mesh(p, parent);
 		s = new h3d.scene.Mesh(p, parent);
 		s.setScale(0.015);
 		s.setScale(0.015);