Commit 7950a29d authored by iSergio's avatar iSergio
Browse files

Add ModelExperimentalAnimationCollection

parent 59dc6088
Loading
Loading
Loading
Loading
+145 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 iSergio, Gis4Fun.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.scene.experimental;

import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsFunction;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.core.Event;
import org.cesiumjs.cs.core.JulianDate;
import org.cesiumjs.cs.scene.enums.ModelAnimationLoop;

/**
 * An active animation derived from a glTF asset. An active animation is an animation that is either currently playing
 * or scheduled to be played due to being added to a model's {@link ModelExperimentalAnimationCollection}. An active
 * animation is an instance of an animation; for example, there can be multiple active animations for the same glTF
 * animation, each with a different start time.
 * Create this by calling {@link ModelExperimentalAnimationCollection#add}.
 */
@JsType(isNative = true, namespace = "Cesium", name = "ModelExperimentalAnimation")
public class ModelExperimentalAnimation {
    /**
     * If this is defined, it will be used to compute the local animation time instead of the scene's time.
     * Default: undefined
     */
    @JsProperty
    public AnimationTimeCallback animationTime;
    /**
     * The delay, in seconds, from ModelExperimentalAnimation#startTime to start playing.
     * Default: undefined
     */
    @JsProperty(name = "delay")
    public native double delay();
    /**
     * Determines if and how the animation is looped.
     * Default: {@link ModelAnimationLoop#NONE()}
     */
    @JsProperty(name = "loop")
    public native Number loop();
    /**
     * Values greater than 1.0 increase the speed that the animation is played relative to the scene clock speed;
     * values less than 1.0 decrease the speed. A value of 1.0 plays the animation at the speed in the
     * glTF animation mapped to the scene clock speed. For example, if the scene is played at 2x real-time,
     * a two-second glTF animation will play in one second even if multiplier is 1.0.
     * Default: 1.0
     */
    @JsProperty(name = "multiplier")
    public native double multiplier();
    /**
     * The name that identifies this animation in the model, if it exists.
     */
    @JsProperty(name = "name")
    public native String name();

    /**
     * When true, the animation is removed after it stops playing. This is slightly more efficient that not
     * removing it, but if, for example, time is reversed, the animation is not played again.
     * Default: false
     */
    @JsProperty
    public boolean removeOnStop;
    /**
     * When true, the animation is played in reverse.
     * Default: false
     */
    @JsProperty(name = "reverse")
    public native boolean reverse();
    /**
     * The event fired when this animation is started. This can be used, for example, to play a sound or start a particle system, when the animation starts.
     * This event is fired at the end of the frame after the scene is rendered.
     *
     * Default: new Event()
     */
    @JsProperty
    public Event<?> start;
    /**
     * The scene time to start playing this animation. When this is undefined, the animation starts at the next frame.
     * Default: undefined
     */
    @JsProperty
    public native JulianDate startTime();
    /**
     * The event fired when this animation is stopped. This can be used, for example, to play a sound or start a
     * particle system, when the animation stops.
     * This event is fired at the end of the frame after the scene is rendered.
     *
     * Default: new Event()
     */
    @JsProperty
    public Event<?> stop;
    /**
     * The scene time to stop playing this animation. When this is undefined, the animation is played for its full
     * duration and perhaps repeated depending on ModelExperimentalAnimation#loop.
     *  Default: undefined
     */
    @JsProperty(name = "stopTime")
    public native JulianDate stopTime();

    /**
     * The event fired when on each frame when this animation is updated. The current time of the animation,
     * relative to the glTF animation time span, is passed to the event, which allows, for example, starting
     * new animations at a specific time relative to a playing animation.
     * This event is fired at the end of the frame after the scene is rendered.
     *
     * Default Value: new Event()
     */
    @JsProperty
    public Event<?> update;

    /**
     * An active animation derived from a glTF asset. An active animation is an animation that is either currently playing
     * or scheduled to be played due to being added to a model's {@link ModelExperimentalAnimationCollection}. An active
     * animation is an instance of an animation; for example, there can be multiple active animations for the same glTF
     * animation, each with a different start time.
     * Create this by calling {@link ModelExperimentalAnimationCollection#add}.
     */
    @JsConstructor
    private ModelExperimentalAnimation() {}

    @JsFunction
    @FunctionalInterface
    public interface AnimationTimeCallback {
        /**
         * A function used to compute the local animation time for a ModelExperimentalAnimation.
         * @param duration The animation's original duration in seconds.
         * @param seconds The seconds since the animation started, in scene time.
         * @return Returns the local animation time.
         */
        double function(double duration, double seconds);
    }
}
+124 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 iSergio, Gis4Fun.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.scene.experimental;

import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.core.Event;
import org.cesiumjs.cs.js.JsArray;
import org.cesiumjs.cs.scene.experimental.options.ModelExperimentalAnimationOptions;

/**
 * A collection of active model animations. Access this using ModelExperimental#activeAnimations.
 * @see ModelExperimental#activeAnimations
 */
@JsType(isNative = true, namespace = "Cesium", name = "ModelExperimentalAnimationCollection")
public class ModelExperimentalAnimationCollection {
    /**
     * When true, the animation will play even when the scene time is paused. However, whether animation takes place
     * will depend on the animationTime functions assigned to the model's animations. By default,
     * this is based on scene time, so models using the default will not animate regardless of this setting.
     * Default: false
     */
    @JsProperty
    public boolean animateWhilePaused;

    /**
     * The event fired when an animation is added to the collection. This can be used, for example,
     * to keep a UI in sync.
     *  Default: new Event()
     */
    @JsProperty
    public Event<?> animationAdded;
    /**
     * The event fired when an animation is removed from the collection. This can be used, for example, to keep a UI in sync.
     * Default: new Event()
     */
    @JsProperty
    public Event<?> animationRemoved;
    /**
     * The number of animations in the collection.
     */
    @JsProperty(name = "length")
    public native int length();
    /**
     * The model that owns this animation collection.
     */
    @JsProperty(name = "model")
    public native ModelExperimental model();

    @JsConstructor
    public ModelExperimentalAnimationCollection() {}

    /**
     * Creates and adds an animation with the specified initial properties to the collection.
     *
     * This raises the ModelExperimentalAnimationCollection#animationAdded event so, for example, a UI can stay in sync.
     * @param options options object.
     * @return The animation that was added to the collection.
     */
    @JsMethod
    public native ModelExperimentalAnimation add(ModelExperimentalAnimationOptions options);

    /**
     * Creates and adds animations with the specified initial properties to the collection for all animations in the model.
     * This raises the ModelExperimentalAnimationCollection#animationAdded event for each model so, for example, a UI can stay in sync.
     * @param options array of options objects
     * @return An array of ModelExperimentalAnimation objects, one for each animation added to the collection. If there are no glTF animations, the array is empty.
     */
    @JsMethod
    public native JsArray<ModelExperimentalAnimation> addAll(JsArray<ModelExperimentalAnimationOptions> options);

    /**
     * Determines whether this collection contains a given animation.
     * @param runtimeAnimation The runtime animation to check for.
     * @return true if this collection contains the animation, false otherwise.
     */
    @JsMethod
    public native boolean contains(ModelExperimentalAnimation runtimeAnimation);

    /**
     * Returns the animation in the collection at the specified index. Indices are zero-based and increase as animations
     * are added. Removing an animation shifts all animations after it to the left, changing their indices.
     * This function is commonly used to iterate over all the animations in the collection.
     * @param index The zero-based index of the animation.
     * @return The runtime animation at the specified index.
     */
    @JsMethod
    public native ModelExperimentalAnimation get(int index);

    /**
     * Removes an animation from the collection.
     * <p>This raises the ModelExperimentalAnimationCollection#animationRemoved event so, for example, a UI can stay in sync.</p>
     *
     * <p>An animation can also be implicitly removed from the collection by setting ModelExperimentalAnimationCollection#removeOnStop to true. The ModelExperimentalAnimationCollection#animationRemoved event is still fired when the animation is removed.</p>
     * @param runtimeAnimation The runtime animation to remove.
     * @return true if the animation was removed; false if the animation was not found in the collection.
     */
    @JsMethod
    public native boolean remove(ModelExperimentalAnimation runtimeAnimation);

    /**
     * Removes all animations from the collection.
     * This raises the ModelExperimentalAnimationCollection#animationRemoved event for each animation so, for example,
     * a UI can stay in sync.
     */
    @JsMethod
    public native void removeAll();
}
+92 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 iSergio, Gis4Fun.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.scene.experimental.options;

import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.core.JulianDate;
import org.cesiumjs.cs.js.JsArray;
import org.cesiumjs.cs.scene.enums.ModelAnimationLoop;
import org.cesiumjs.cs.scene.experimental.ModelExperimentalAnimation;

/**
 * Options object for {@link org.cesiumjs.cs.scene.experimental.ModelExperimentalAnimationCollection#add(ModelExperimentalAnimationOptions)}
 */
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class ModelExperimentalAnimationOptions {
    /**
     * The glTF animation name that identifies the animation. Must be defined if options.index is undefined.
     */
    @JsProperty
    public String name;
    /**
     * The glTF animation index that identifies the animation. Must be defined if options.name is undefined.
     */
    @JsProperty
    public int index;
    /**
     * The scene time to start playing the animation. When this is undefined, the animation starts at the next frame.
     */
    @JsProperty
    public JulianDate startTime;
    /**
     * The delay, in seconds, from startTime to start playing. This will only affect the animation if options.loop
     * is ModelAnimationLoop.NONE.
     * Default: 0
     */
    @JsProperty
    public double delay;
    /**
     * The scene time to stop playing the animation. When this is undefined, the animation is played for its full duration.
     */
    @JsProperty
    public JulianDate stopTime;
    /**
     * When true, the animation is removed after it stops playing. This will only affect the animation if options.loop is ModelAnimationLoop.NONE.
     * Default: false
     */
    @JsProperty
    public boolean removeOnStop;
    /**
     * Values greater than 1.0 increase the speed that the animation is played relative to the scene clock speed; values less than 1.0 decrease the speed.
     * Default: 1.0
     */
    @JsProperty
    public double multiplier;
    /**
     * When true, the animation is played in reverse.
     * Default: false
     */
    @JsProperty
    public boolean reverse;
    /**
     * Determines if and how the animation is looped.
     * Default: {@link org.cesiumjs.cs.scene.enums.ModelAnimationLoop#NONE()}
     */
    @JsProperty
    public Number loop;
    /**
     * If defined, computes the local animation time for this animation.
     */
    @JsProperty
    public ModelExperimentalAnimation.AnimationTimeCallback animationTime;

    @JsConstructor
    public ModelExperimentalAnimationOptions() {}
}