瀏覽代碼

added priority

ncannasse 8 年之前
父節點
當前提交
d3c40cf9c3
共有 2 個文件被更改,包括 14 次插入0 次删除
  1. 5 0
      h3d/scene/Interactive.hx
  2. 9 0
      h3d/scene/Scene.hx

+ 5 - 0
h3d/scene/Interactive.hx

@@ -9,6 +9,11 @@ class Interactive extends Object implements hxd.SceneEvents.Interactive {
 	**/
 	public var preciseShape : Null<h3d.col.Collider>;
 
+	/**
+		In case of conflicting shapes, usually the one in front of the camera is prioritized, unless you set an higher priority.
+	**/
+	public var priority : Int;
+
 	public var cursor(default,set) : hxd.Cursor;
 	/**
 		Set the default `cancel` mode (see `hxd.Event`), default to false.

+ 9 - 0
h3d/scene/Scene.hx

@@ -94,9 +94,12 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 			var p1 = camera.unproject(screenX, screenY, 1);
 			var r = h3d.col.Ray.fromPoints(p0.toPoint(), p1.toPoint());
 			var saveR = r.clone();
+			var priority = 0x80000000;
 
 			for( i in interactives ) {
 
+				if( i.priority < priority ) continue;
+
 				var p : h3d.scene.Object = i;
 				while( p != null && p.visible )
 					p = p.parent;
@@ -123,6 +126,12 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 				i.hitPoint.x = hitPoint.x;
 				i.hitPoint.y = hitPoint.y;
 				i.hitPoint.z = hitPoint.z;
+
+				if( i.priority > priority ) {
+					while( hitInteractives.length > 0 ) hitInteractives.pop();
+					priority = i.priority;
+				}
+
 				hitInteractives.push(i);
 			}