Procházet zdrojové kódy

Implement makeDebugObj for SkinCollider (#975)

SkinCollider.makeDebugObj shows a box containing the whole collider,
and a box for each joint.
Note that these boxes are made using h3d.scene.Box, which is a
h3d.scene.Graphics, which means you cannot change its color through its
material, and there is no wireframe mainpass to disable
Leonardo Jeanteur před 4 roky
rodič
revize
c7eede9d28
2 změnil soubory, kde provedl 63 přidání a 3 odebrání
  1. 61 2
      h3d/col/SkinCollider.hx
  2. 2 1
      h3d/scene/Interactive.hx

+ 61 - 2
h3d/col/SkinCollider.hx

@@ -93,7 +93,9 @@ class SkinCollider implements hxd.impl.Serializable implements Collider {
 
 	#if !macro
 	public function makeDebugObj() : h3d.scene.Object {
-		return null;
+		var ret = new SkinColliderDebugObj(this);
+		ret.ignoreParentTransform = true;
+		return ret;
 	}
 	#if hxbit
 	function customSerialize( ctx : hxbit.Serializer ) {
@@ -105,4 +107,61 @@ class SkinCollider implements hxd.impl.Serializable implements Collider {
 	#end
 	#end
 
-}
+}
+
+#if !macro
+@:access(h3d.col.SkinCollider)
+@:access(h3d.scene.Skin)
+class SkinColliderDebugObj extends h3d.scene.Object {
+	var col : SkinCollider;
+	var skin : h3d.scene.Skin;
+
+	var box : h3d.scene.Box;
+	var boxes : Array<h3d.scene.Box> = [];
+
+	public function new(col : SkinCollider) {
+		super(null);
+		this.col = col;
+		this.skin = col.obj;
+		this.box = new h3d.scene.Box(0xFFFFFF, col.currentBounds);
+		addChild(box);
+		this.ignoreParentTransform = true;
+		createJoints();
+	}
+
+	function createJoints() {
+		var joints = skin.getSkinData().allJoints;
+		for( j in joints ) {
+			var b = new h3d.scene.Box(0xA0A0A0, h3d.col.Bounds.fromValues(-1,-1,-1,2,2,2), this);
+			if( j.offsets != null ) {
+				b.bounds.empty();
+				var pt = j.offsets.getMin();
+				b.bounds.addSpherePos(pt.x, pt.y, pt.z, j.offsetRay);
+				var pt = j.offsets.getMax();
+				b.bounds.addSpherePos(pt.x, pt.y, pt.z, j.offsetRay);
+			} else {
+				b.bounds.empty();
+				b.bounds.addSpherePos(0,0,0,0.1);
+			}
+			boxes.push(b);
+		}
+	}
+
+	function updateJoints() {
+		for( i in 0...boxes.length ) {
+			var j = skin.skinData.allJoints[i];
+			var b = boxes[i];
+			if( j.offsets != null ) {
+				var m = skin.currentPalette[j.bindIndex];
+				b.setTransform(m);
+			} else
+				b.setTransform(skin.currentAbsPose[j.index]);
+		}
+	}
+
+	override function sync( ctx : h3d.scene.RenderContext ) {
+		col.checkBounds();
+		updateJoints();
+	}
+}
+#end

+ 2 - 1
h3d/scene/Interactive.hx

@@ -72,7 +72,8 @@ class Interactive extends Object implements hxd.SceneEvents.Interactive {
 				m.mainPass.wireframe = true;
 			m.castShadows = false;
 			m.receiveShadows = false;
-			// m.blendMode = Alpha;
+			m.color.a = 0.7;
+			m.blendMode = Alpha;
 			// m.mainPass.depth(false, Always);
 		}
 	}