Question about new Animation System part 4: Layers

Hello everybody,
I’d like to access the AnimationMask variable of the Layer class. It would be possible to transform the inner class Layer into a separate class with getter / setter methods of this variable ?. I was thinking of a hypothetical graphic editor to modify the bones assigned to the mask at runtime, but it could be useful in other contexts. I checked the code a bit and changing the mask at runtime shouldn’t cause any problems. Here is the idea I had in mind:

/**
 * You could refine the class name in AnimLayer as it is only used in the AnimComposer class
 */
public class Layer implements JmeCloneable {
	
	private AnimComposer ac;
	private Action currentAction;
	private AnimationMask mask;
	private double time;
	private Object manager;

	public Layer(AnimComposer ac) {
		this.ac = ac;
	}
	
	/**
	 * This function is called only in the controlUpdate method of the AnimComposer class, 
	 * so it may become protected ?
	 * 
	 * @param tpf
	 */
	protected void advance(float tpf) {
		time += tpf * currentAction.getSpeed() * ac.getGlobalSpeed();
		// make sure negative time is in [0, length] range
		if (time < 0) {
			double length = currentAction.getLength();
			time = (time % length + length) % length;
		}

	}

	@Override
	public Object jmeClone() {
		try {
			Layer clone = (Layer) super.clone();
			return clone;
		} catch (CloneNotSupportedException ex) {
			throw new AssertionError();
		}
	}

	@Override
	public void cloneFields(Cloner cloner, Object original) {
		ac = cloner.clone(ac);
		currentAction = null;
	}

	public AnimationMask getAnimationMask() {
		return mask;
	}

	public void setAnimationMask(AnimationMask mask) {
		this.mask = mask;
	}
	
	public Object getManager() {
		return manager;
	}

	public void setManager(Object manager) {
		this.manager = manager;
	}
	
}

So a couple of methods would be needed in the AnimComposer class:

public Layer getLayer(String name) {
	return layers.get(name);
}

public Collection<Layer> getLayers() {
	return layers.values();
}

Let me know what you think.

2 Likes

These 2 methods in the AnimComposer class would become superfluous.

    /**
     * Access the manager of the named layer.
     *
     * @param layerName the name of the layer to access
     * @return the current manager (typically an AnimEvent) or null for none
     */
    public Object getLayerManager(String layerName) {
        Layer layer = layers.get(layerName);
        if (layer == null) {
            throw new IllegalArgumentException("Unknown layer " + layerName);
        }

        return layer.manager;
    }

    /**
     * Assign a manager to the named layer.
     *
     * @param layerName the name of the layer to modify
     * @param manager the desired manager (typically an AnimEvent) or null for
     * none
     */
    public void setLayerManager(String layerName, Object manager) {
        Layer layer = layers.get(layerName);
        if (layer == null) {
            throw new IllegalArgumentException("Unknown layer " + layerName);
        }

        layer.manager = manager;
    }

They are called only in the AnimEvent class. They would become like this:

// AnimEvent.class; line:155 and 168
composer.getLayer(layerName).setManager(this);

// AnimEvent.class; line:126 and 165 
Object layerManager = composer.getLayer(layerName).getManager();
3 Likes

Sounds a good idea to me.

2 Likes

I haven’t used AnimEvent before, what should the LayerManager do ?

1 Like

Layer managers are a new feature in v3.4 beta that solve an issue with cinematics.

Assigning a manager helps cinematics keep track of which AnimEvent is controlling each Layer. Thus, if 2 anim events take turns controlling the same Layer, they won’t interfere with each other.

1 Like

Is it possible to insert my proposed change to the Layers in the 3.4.0 release? Let me know if I can create an Issue to track this conversation.

I’m reluctant to make such a change so late in the beta testing period.

You’re welcome to open an issue at GitHub.

3 Likes
2 Likes

This is currently targeted for the 3.5 release. I’m working on the PR today.

2 Likes