当前位置: 首页>>代码示例>>Java>>正文


Java Animation.setTracks方法代码示例

本文整理汇总了Java中com.jme3.animation.Animation.setTracks方法的典型用法代码示例。如果您正苦于以下问题:Java Animation.setTracks方法的具体用法?Java Animation.setTracks怎么用?Java Animation.setTracks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme3.animation.Animation的用法示例。


在下文中一共展示了Animation.setTracks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractAnimation

import com.jme3.animation.Animation; //导入方法依赖的package包/类
/**
 * Extract an animation from a source animation.
 *
 * @param source     the source animation.
 * @param newName    the new name of a sub animation.
 * @param startFrame the start frame.
 * @param endFrame   the end frame.
 * @return the new sub animation.
 */
@NotNull
@FromAnyThread
public static Animation extractAnimation(@NotNull final Animation source, @NotNull final String newName,
                                         final int startFrame, final int endFrame) {

    final Track[] sourceTracks = source.getTracks();
    final BoneTrack firstSourceTrack = (BoneTrack) sourceTracks[0];
    final float[] sourceTimes = firstSourceTrack.getTimes();

    final float newLength = (source.getLength() / (float) sourceTimes.length) * (float) (endFrame - startFrame);
    final Animation result = new Animation(newName, newLength);
    final Array<Track> newTracks = ArrayFactory.newArray(Track.class);

    for (final Track sourceTrack : sourceTracks) {
        if (sourceTrack instanceof BoneTrack) {
            newTracks.add(extractBoneTrack((BoneTrack) sourceTrack, startFrame, endFrame));
        }
    }

    result.setTracks(newTracks.toArray(Track.class));

    return result;
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:33,代码来源:AnimationUtils.java

示例2: ObjectAnimationModifier

import com.jme3.animation.Animation; //导入方法依赖的package包/类
/**
 * This constructor reads animation of the object itself (without bones) and
 * stores it as an ArmatureModifierData modifier. The animation is returned
 * as a modifier. It should be later applied regardless other modifiers. The
 * reason for this is that object may not have modifiers added but it's
 * animation should be working. The stored modifier is an anim data and
 * additional data is given object's OMA.
 * 
 * @param ipo
 *            the object's interpolation curves
 * @param objectAnimationName
 *            the name of object's animation
 * @param objectOMA
 *            the OMA of the object
 * @param blenderContext
 *            the blender context
 * @throws BlenderFileException
 *             this exception is thrown when the blender file is somehow
 *             corrupted
 */
public ObjectAnimationModifier(Ipo ipo, String objectAnimationName, Long objectOMA, BlenderContext blenderContext) throws BlenderFileException {
    int fps = blenderContext.getBlenderKey().getFps();

    Spatial object = (Spatial) blenderContext.getLoadedFeature(objectOMA, LoadedFeatureDataType.LOADED_FEATURE);
    // calculating track
    SpatialTrack track = (SpatialTrack) ipo.calculateTrack(-1, object.getLocalRotation(), 0, ipo.getLastFrame(), fps, true);

    Animation animation = new Animation(objectAnimationName, ipo.getLastFrame() / (float) fps);
    animation.setTracks(new SpatialTrack[] { track });
    ArrayList<Animation> animations = new ArrayList<Animation>(1);
    animations.add(animation);

    animationData = new AnimationData(animations);
    blenderContext.setAnimData(objectOMA, animationData);
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:36,代码来源:ObjectAnimationModifier.java

示例3: simpleInitApp

import com.jme3.animation.Animation; //导入方法依赖的package包/类
@Override
  public void simpleInitApp() {

      AmbientLight al = new AmbientLight();
      rootNode.addLight(al);

      DirectionalLight dl = new DirectionalLight();
      dl.setDirection(Vector3f.UNIT_XYZ.negate());
      rootNode.addLight(dl);

      // Create model
      Box box = new Box(1, 1, 1);
      Geometry geom = new Geometry("box", box);
      geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
      Node model = new Node("model");
      model.attachChild(geom);

      Box child = new Box(0.5f, 0.5f, 0.5f);
      Geometry childGeom = new Geometry("box", child);
      childGeom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
      Node childModel = new Node("childmodel");
      childModel.setLocalTranslation(2, 2, 2);
      childModel.attachChild(childGeom);
      model.attachChild(childModel);
      
      //animation parameters
      float animTime = 5;
      int fps = 25;
      float totalXLength = 10;
      
      //calculating frames
      int totalFrames = (int) (fps * animTime);
      float dT = animTime / totalFrames, t = 0;
      float dX = totalXLength / totalFrames, x = 0;
      float[] times = new float[totalFrames];
      Vector3f[] translations = new Vector3f[totalFrames];
      Quaternion[] rotations = new Quaternion[totalFrames];
      Vector3f[] scales = new Vector3f[totalFrames];
for (int i = 0; i < totalFrames; ++i) {
      	times[i] = t;
      	t += dT;
      	translations[i] = new Vector3f(x, 0, 0);
      	x += dX;
      	rotations[i] = Quaternion.IDENTITY;
      	scales[i] = Vector3f.UNIT_XYZ;
      }
      SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales);
      
      //creating the animation
      Animation spatialAnimation = new Animation("anim", animTime);
      spatialAnimation.setTracks(new SpatialTrack[] { spatialTrack });
      
      //create spatial animation control
      AnimControl control = new AnimControl();
      HashMap<String, Animation> animations = new HashMap<String, Animation>();
      animations.put("anim", spatialAnimation);
      control.setAnimations(animations);
      model.addControl(control);

      rootNode.attachChild(model);
      
      //run animation
      control.createChannel().setAnim("anim");
  }
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:65,代码来源:TestSpatialAnim.java


注:本文中的com.jme3.animation.Animation.setTracks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。