2
0
Эх сурвалжийг харах

added culled flag (separated from visible) to enable culling in renderer

ncannasse 11 жил өмнө
parent
commit
4e12f4a359
2 өөрчлөгдсөн 15 нэмэгдсэн , 12 устгасан
  1. 10 10
      h3d/scene/Object.hx
  2. 5 2
      h3d/scene/Skin.hx

+ 10 - 10
h3d/scene/Object.hx

@@ -15,7 +15,7 @@ class Object {
 	public var scaleX(default,set) : Float;
 	public var scaleY(default, set) : Float;
 	public var scaleZ(default,set) : Float;
-	public var visible : Bool = true;
+	public var visible(default,set) : Bool = true;
 
 	/**
 		Follow a given object or joint as if it was our parent. Ignore defaultTransform when set.
@@ -29,6 +29,9 @@ class Object {
 	public var defaultTransform(default, set) : h3d.Matrix;
 	public var currentAnimation(default, null) : h3d.anim.Animation;
 
+	// internal flag to inform that the object is not to be displayed
+	var culled : Bool;
+
 	var absPos : h3d.Matrix;
 	var invPos : h3d.Matrix;
 	var qRot : h3d.Quat;
@@ -50,6 +53,11 @@ class Object {
 		return currentAnimation = a.createInstance(this);
 	}
 
+	function set_visible(v) {
+		culled = !v;
+		return visible = v;
+	}
+
 	/**
 		Changes the current animation. This animation should be an instance that was created by playAnimation!
 	**/
@@ -278,7 +286,7 @@ class Object {
 	}
 
 	function emitRec( ctx : RenderContext ) {
-		if( !visible ) return;
+		if( culled ) return;
 		// fallback in case the object was added during a sync() event and we somehow didn't update it
 		if( posChanged ) {
 			// only sync anim, don't update() (prevent any event from occuring during draw())
@@ -335,14 +343,6 @@ class Object {
 		return v;
 	}
 
-	/*
-		Move along the current rotation axis
-	*/
-	public function move( dx : Float, dy : Float, dz : Float ) {
-		throw "TODO";
-		posChanged = true;
-	}
-
 	public inline function setPos( x : Float, y : Float, z : Float ) {
 		this.x = x;
 		this.y = y;

+ 5 - 2
h3d/scene/Skin.hx

@@ -58,7 +58,10 @@ class Skin extends MultiMaterial {
 	var skinShader : h3d.shader.Skin;
 
 	public var showJoints : Bool;
-	public var syncIfHidden : Bool = true;
+	/**
+		Always synchronize the joints position even if the object is invisible or culled.
+	**/
+	public var alwaysSync : Bool = false;
 
 	public function new(s, ?mat, ?parent) {
 		super(null, mat, parent);
@@ -141,7 +144,7 @@ class Skin extends MultiMaterial {
 	}
 
 	override function sync( ctx : RenderContext ) {
-		if( !(visible || syncIfHidden) )
+		if( culled && !alwaysSync )
 			return;
 		if( jointsUpdated || posChanged ) {
 			for( j in skinData.allJoints ) {