From 7f92496425eb75315711325072223e3ba3903709 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 3 Aug 2006 18:21:28 +0000 Subject: [PATCH] Hide nodes not included as targets in an animation. I haven't tested all the units with this; there's a chance some of the animations will have to be re-exported if they mistakenly omit nodes. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@24 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../jme/model/EmissionController.java | 5 ++ src/java/com/threerings/jme/model/Model.java | 8 ++++ .../com/threerings/jme/model/ModelNode.java | 48 ++++++++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/jme/model/EmissionController.java b/src/java/com/threerings/jme/model/EmissionController.java index a4da1adc..07d8499f 100644 --- a/src/java/com/threerings/jme/model/EmissionController.java +++ b/src/java/com/threerings/jme/model/EmissionController.java @@ -49,6 +49,11 @@ public abstract class EmissionController extends ModelController super.init(model); if (_hideTarget) { _target.setCullMode(Spatial.CULL_ALWAYS); + if (_target instanceof ModelNode) { + // make sure the node isn't turned back on by an + // animation + ((ModelNode)_target).setForceCull(true); + } } } diff --git a/src/java/com/threerings/jme/model/Model.java b/src/java/com/threerings/jme/model/Model.java index d11dd6a9..9b256870 100644 --- a/src/java/com/threerings/jme/model/Model.java +++ b/src/java/com/threerings/jme/model/Model.java @@ -508,6 +508,14 @@ public class Model extends ModelNode if (_anim != null) { _animObservers.apply(new AnimCancelledOp(_animName)); } + + // first cull all model nodes, then re-activate the ones in the + // target list + cullModelNodes(); + for (Spatial target : anim.transformTargets) { + ((ModelNode)target).updateCullMode(); + } + _paused = false; _anim = anim; _animName = name; diff --git a/src/java/com/threerings/jme/model/ModelNode.java b/src/java/com/threerings/jme/model/ModelNode.java index 10478582..8811dba9 100644 --- a/src/java/com/threerings/jme/model/ModelNode.java +++ b/src/java/com/threerings/jme/model/ModelNode.java @@ -282,6 +282,24 @@ public class ModelNode extends Node } } + /** + * Sets whether this node should be culled even if it has mesh + * descendants. + */ + public void setForceCull (boolean force) + { + _forceCull = force; + } + + /** + * Checks whether this node should be culled even if it has mesh + * descendants. + */ + public boolean getForceCull () + { + return _forceCull; + } + // documentation inherited from interface ModelSpatial public void writeBuffers (FileChannel out) throws IOException @@ -334,7 +352,7 @@ public class ModelNode extends Node _hasVisibleDescendants = true; } } - setCullMode(_hasVisibleDescendants ? CULL_INHERIT : CULL_ALWAYS); + updateCullMode(); return _hasVisibleDescendants; } @@ -372,6 +390,31 @@ public class ModelNode extends Node } } + /** + * Recursively culls all model nodes under this one in preparation for + * activating the ones listed in an animation. + */ + protected void cullModelNodes () + { + for (int ii = 0, nn = getQuantity(); ii < nn; ii++) { + Spatial child = getChild(ii); + if (child instanceof ModelNode) { + child.setCullMode(CULL_ALWAYS); + ((ModelNode)child).cullModelNodes(); + } + } + } + + /** + * Makes this node visible if and only if it has visible descendants and + * has not been specifically culled. + */ + protected void updateCullMode () + { + setCullMode((_hasVisibleDescendants && !_forceCull) ? + CULL_INHERIT : CULL_ALWAYS); + } + /** * Sets a matrix to the transform defined by the given translation, * rotation, and scale values. @@ -405,5 +448,8 @@ public class ModelNode extends Node /** Whether or not this node has mesh descendants. */ protected boolean _hasVisibleDescendants; + /** If true, cull the node even if it has mesh descendants. */ + protected boolean _forceCull; + private static final long serialVersionUID = 1; }