コード例 #1
0
  @Override
  @SuppressWarnings("unchecked")
  public Node apply(Node node, BlenderContext blenderContext) {
    if (invalid) {
      LOGGER.log(
          Level.WARNING, "Armature modifier is invalid! Cannot be applied to: {0}", node.getName());
    } // if invalid, animData will be null
    if (animData == null) {
      return node;
    }

    // setting weights for bones
    List<Geometry> geomList =
        (List<Geometry>)
            blenderContext.getLoadedFeature(this.meshOMA, LoadedFeatureDataType.LOADED_FEATURE);
    for (Geometry geom : geomList) {
      Mesh mesh = geom.getMesh();
      if (this.verticesWeights != null) {
        mesh.setMaxNumWeights(this.boneGroups);
        mesh.setBuffer(this.verticesWeights);
        mesh.setBuffer(this.verticesWeightsIndices);
      }
    }

    ArrayList<Animation> animList = animData.anims;
    if (animList != null && animList.size() > 0) {
      List<Constraint> constraints = blenderContext.getConstraints(this.armatureObjectOMA);
      HashMap<String, Animation> anims = new HashMap<String, Animation>();
      for (int i = 0; i < animList.size(); ++i) {
        Animation animation = (Animation) animList.get(i).clone();

        // baking constraints into animations
        if (constraints != null && constraints.size() > 0) {
          for (Constraint constraint : constraints) {
            Long boneOMA = constraint.getBoneOMA();
            Bone bone =
                (Bone)
                    blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE);
            int targetIndex =
                bone == null
                    ? 0
                    : animData.skeleton.getBoneIndex(
                        bone); // bone==null may mean the object animation
            constraint.affectAnimation(animation, targetIndex);
          }
        }

        anims.put(animation.getName(), animation);
      }

      // applying the control to the node
      SkeletonControl skeletonControl = new SkeletonControl(animData.skeleton);
      AnimControl control = new AnimControl(animData.skeleton);

      control.setAnimations(anims);
      node.addControl(control);
      node.addControl(skeletonControl);
    }
    return node;
  }
コード例 #2
0
  /**
   * The method applies animations to the given node. The names of the animations should be the same
   * as actions names in the blender file.
   *
   * @param node the node to whom the animations will be applied
   * @param animationMatchMethod the way animation should be matched with node
   */
  public void applyAnimations(Node node, AnimationMatchMethod animationMatchMethod) {
    List<BlenderAction> actions = this.getActions(node, animationMatchMethod);
    if (actions.size() > 0) {
      List<Animation> animations = new ArrayList<Animation>();
      for (BlenderAction action : actions) {
        SpatialTrack[] tracks = action.toTracks(node);
        if (tracks != null && tracks.length > 0) {
          Animation spatialAnimation = new Animation(action.getName(), action.getAnimationTime());
          spatialAnimation.setTracks(tracks);
          animations.add(spatialAnimation);
          blenderContext.addAnimation(
              (Long) node.getUserData(ObjectHelper.OMA_MARKER), spatialAnimation);
        }
      }

      if (animations.size() > 0) {
        AnimControl control = new AnimControl();
        HashMap<String, Animation> anims = new HashMap<String, Animation>(animations.size());
        for (int i = 0; i < animations.size(); ++i) {
          Animation animation = animations.get(i);
          anims.put(animation.getName(), animation);
        }
        control.setAnimations(anims);
        node.addControl(control);
      }
    }
  }
コード例 #3
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
 public void standUpAnimation() {
   setAnimationFullBody("StandUpGround", 0.5f, LoopMode.DontLoop);
   animControl
       .getSpatial()
       .getParent()
       .setLocalTranslation(animControl.getSpatial().getWorldTranslation().add(0f, 0.1f, 0f));
   animControl.getSpatial().setLocalTranslation(Vector3f.ZERO);
 }
コード例 #4
0
  public CreepAnimControl(Creep creep) {
    this.creep = creep;

    // animations of creep
    animControl = creep.getCreepModel().getControl(AnimControl.class);
    animControl.addListener(this);

    // chanels
    channelAttack = animControl.createChannel();
    channelDead = animControl.createChannel();
    channelRunBase = animControl.createChannel();
    channelRunTop = animControl.createChannel();

    // random tool
    random = new Random();
  }
コード例 #5
0
 @Override
 public void setEnabled(boolean enabled) {
   // Pause and unpause
   super.setEnabled(enabled);
   if (enabled) {
     gameGUIManager.loadAndGotoScreen("editPlayer");
     model = (Node) app.getAssetManager().loadModel("Models/Player/PlayerAni.j3o");
     app.getRootNode().attachChild(model);
     app.getFlyByCamera().setDragToRotate(true);
     playerModel = (Node) model.getChild("PlayerMesh");
     AnimControl animControl = playerModel.getControl(AnimControl.class);
     AnimChannel animChannel = animControl.createChannel();
     animChannel.setAnim("Idle");
     // System.out.println("Call me!");
     app.getCamera().setLocation(model.getChild("CamNode").getWorldTranslation());
     app.getCamera().lookAt(model.getChild("LookAtNode").getWorldTranslation(), Vector3f.UNIT_Y);
   } else {
   }
 }
コード例 #6
0
  private void scanSpatial(Spatial model) {
    AnimControl animControl = model.getControl(AnimControl.class);
    Map<Integer, List<Float>> pointsMap = null;
    if (weightThreshold == -1.0f) {
      pointsMap = RagdollUtils.buildPointMap(model);
    }

    skeleton = animControl.getSkeleton();
    skeleton.resetAndUpdate();
    for (int i = 0; i < skeleton.getRoots().length; i++) {
      Bone childBone = skeleton.getRoots()[i];
      if (childBone.getParent() == null) {
        logger.log(Level.INFO, "Found root bone in skeleton {0}", skeleton);
        baseRigidBody =
            new PhysicsRigidBody(new BoxCollisionShape(Vector3f.UNIT_XYZ.mult(0.1f)), 1);
        baseRigidBody.setKinematic(mode == Mode.Kinematic);
        boneRecursion(model, childBone, baseRigidBody, 1, pointsMap);
      }
    }
  }
コード例 #7
0
 // Gerneral function
 void setupPlayerControl() {
   this.animControl = ((Node) spatial).getChild("PlayerMesh").getControl(AnimControl.class);
   animChannel = animControl.createChannel();
   if (playerInfo.getRole().equals(PlayerRole.GoalKeeper)) {
     animChannel.setAnim("Idle");
     chasingBall = false;
   } else {
     animChannel.setAnim("RunFast");
     chasingBall = true;
   }
 }
コード例 #8
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
 @Override
 public void onAnimCycleDone(AnimControl ac, AnimChannel ac1, String string) {
   if (string.equals("StandUpGround")) {
     characterControl.setWalkDirection(Vector3f.ZERO);
     characterControl.setEnabled(true);
     headChannel.setAnim("IdleStanding", 0.5f);
     // Vector3f center = animControl.getSpatial().getWorldBound().getCenter();
     animControl.getSpatial().setLocalTranslation(new Vector3f(0f, -1f, 0f));
     // animControl.getSpatial().getParent().setLocalTranslation(animControl.getSpatial().getParent().getLocalTranslation().add(0f,0.1f,0f));
   }
 }
コード例 #9
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
 public static void setBonesSuchAs(AnimControl animControl, String animationName) {
   Animation animation = animControl.getAnim(animationName);
   int size = animControl.getSkeleton().getBoneCount();
   for (int index = 0; index < size; index++) {
     Bone bone = animControl.getSkeleton().getBone(index);
     BoneTrack boneTrack = getFirstTrackForBone(animation, index);
     if (boneTrack != null) {
       Quaternion rotation = boneTrack.getRotations()[0];
       Vector3f translation = boneTrack.getTranslations()[0];
       Vector3f scale = boneTrack.getScales()[0];
       System.out.println("Bone = " + bone.getName());
       System.out.println("\tRotation = " + rotation);
       System.out.println("\tTranslation = " + translation);
       System.out.println("\tScale = " + scale);
       bone.setUserControl(true);
       bone.setUserTransforms(translation, rotation, scale);
       bone.updateWorldVectors();
       bone.setUserControl(false);
     }
   }
 }
コード例 #10
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
  @Override
  public void setSpatial(Spatial spatial) {
    super.setSpatial(spatial);

    if (spatial != null) {
      animControl = ActorFactory.findControl(spatial, AnimControl.class);
      characterControl = ActorFactory.findControl(spatial, CharacterControl.class);
      if (animControl != null && characterControl != null) {
        initChannels();
        animControl.addListener(this);
      }
    }
  }
コード例 #11
0
  /**
   * The method applies skeleton animations to the given node.
   *
   * @param node the node where the animations will be applied
   * @param skeleton the skeleton of the node
   * @param animationMatchMethod the way animation should be matched with skeleton
   */
  public void applyAnimations(
      Node node, Skeleton skeleton, AnimationMatchMethod animationMatchMethod) {
    node.addControl(new SkeletonControl(skeleton));
    blenderContext.setNodeForSkeleton(skeleton, node);
    List<BlenderAction> actions = this.getActions(skeleton, animationMatchMethod);

    if (actions.size() > 0) {
      List<Animation> animations = new ArrayList<Animation>();
      for (BlenderAction action : actions) {
        BoneTrack[] tracks = action.toTracks(skeleton);
        if (tracks != null && tracks.length > 0) {
          Animation boneAnimation = new Animation(action.getName(), action.getAnimationTime());
          boneAnimation.setTracks(tracks);
          animations.add(boneAnimation);
          Long animatedNodeOMA =
              ((Number) blenderContext.getMarkerValue(ObjectHelper.OMA_MARKER, node)).longValue();
          blenderContext.addAnimation(animatedNodeOMA, boneAnimation);
        }
      }
      if (animations.size() > 0) {
        AnimControl control = new AnimControl(skeleton);
        HashMap<String, Animation> anims = new HashMap<String, Animation>(animations.size());
        for (int i = 0; i < animations.size(); ++i) {
          Animation animation = animations.get(i);
          anims.put(animation.getName(), animation);
        }
        control.setAnimations(anims);
        node.addControl(control);

        // make sure that SkeletonControl is added AFTER the AnimControl
        SkeletonControl skeletonControl = node.getControl(SkeletonControl.class);
        if (skeletonControl != null) {
          node.removeControl(SkeletonControl.class);
          node.addControl(skeletonControl);
        }
      }
    }
  }
コード例 #12
0
  protected boolean isDefaultAnimationRunning() {
    // See if the default animation is the one currently playing
    List<Mapping> list = getMappings(defaultAnimation, false);
    if (list == null) {
      return false; // no real way to tell
    }

    if (list.size() < anim.getNumChannels()) {
      return false;
    }

    for (int i = 0; i < list.size(); i++) {
      Mapping m = list.get(i);
      AnimChannel channel = anim.getChannel(i);
      if (channel == null) {
        return false;
      }
      if (!m.animation.equals(channel.getAnimationName())) {
        return false;
      }
    }
    return true;
  }
コード例 #13
0
  /**
   * Enable or disable the ragdoll behaviour. if ragdollEnabled is true, the character motion will
   * only be powerd by physics else, the characted will be animated by the keyframe animation, but
   * will be able to physically interact with its physic environnement
   *
   * @param ragdollEnabled
   */
  protected void setMode(Mode mode) {
    this.mode = mode;
    AnimControl animControl = targetModel.getControl(AnimControl.class);
    animControl.setEnabled(mode == Mode.Kinematic);

    baseRigidBody.setKinematic(mode == Mode.Kinematic);
    TempVars vars = TempVars.get();

    for (PhysicsBoneLink link : boneLinks.values()) {
      link.rigidBody.setKinematic(mode == Mode.Kinematic);
      if (mode == Mode.Ragdoll) {
        Quaternion tmpRot1 = vars.quat1;
        Vector3f position = vars.vect1;
        // making sure that the ragdoll is at the correct place.
        matchPhysicObjectToBone(link, position, tmpRot1);
      }
    }
    vars.release();

    for (Bone bone : skeleton.getRoots()) {
      RagdollUtils.setUserControl(bone, mode == Mode.Ragdoll);
    }
  }
コード例 #14
0
  /**
   * Smoothly blend from Ragdoll mode to Kinematic mode This is useful to blend ragdoll actual
   * position to a keyframe animation for example
   *
   * @param blendTime the blending time between ragdoll to anim.
   */
  public void blendToKinematicMode(float blendTime) {
    if (mode == Mode.Kinematic) {
      return;
    }
    blendedControl = true;
    this.blendTime = blendTime;
    mode = Mode.Kinematic;
    AnimControl animControl = targetModel.getControl(AnimControl.class);
    animControl.setEnabled(true);

    TempVars vars = TempVars.get();
    for (PhysicsBoneLink link : boneLinks.values()) {

      Vector3f p = link.rigidBody.getMotionState().getWorldLocation();
      Vector3f position = vars.vect1;

      targetModel.getWorldTransform().transformInverseVector(p, position);

      Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
      Quaternion q2 = vars.quat1;
      Quaternion q3 = vars.quat2;

      q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal();
      q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
      q2.normalizeLocal();
      link.startBlendingPos.set(position);
      link.startBlendingRot.set(q2);
      link.rigidBody.setKinematic(true);
    }
    vars.release();

    for (Bone bone : skeleton.getRoots()) {
      RagdollUtils.setUserControl(bone, false);
    }

    blendStart = 0;
  }
コード例 #15
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
  private void initChannels() {
    fullBodyChannel = animControl.createChannel();
    headChannel.setLoopMode(LoopMode.Loop);

    headChannel = animControl.createChannel();
    headChannel.setLoopMode(LoopMode.Loop);

    leftArmChannel = animControl.createChannel();
    leftArmChannel.setLoopMode(LoopMode.Loop);

    rightArmChannel = animControl.createChannel();
    rightArmChannel.setLoopMode(LoopMode.Loop);

    leftLegChannel = animControl.createChannel();
    leftLegChannel.setLoopMode(LoopMode.Loop);

    rightLegChannel = animControl.createChannel();
    rightLegChannel.setLoopMode(LoopMode.Loop);
  }
コード例 #16
0
  /** Plays the specified animation or does nothing if the animation is not mapped. */
  public void play(String animation) {
    log.debug("play(" + animation + ")");

    if (Objects.equal(this.animation, animation)) {
      return;
    }

    List<Mapping> list = getMappings(animation, false);
    if (list == null) {
      list = getMappings(defaultAnimation, false);
      if (list == null) {
        // Just clear everything and hope for the best
        anim.clearChannels();
        return;
      }
    }

    // Make sure there are enough channels
    while (anim.getNumChannels() < list.size()) {
      anim.createChannel();
    }

    // Set the channels to the appropriate animation
    int i;
    for (i = 0; i < list.size(); i++) {
      Mapping m = list.get(i);
      AnimChannel channel = anim.getChannel(i);
      channel.setAnim(m.animation);
      channel.setSpeed(m.speed);
    }

    // Reset the rest
    for (; i < anim.getNumChannels(); i++) {
      AnimChannel channel = anim.getChannel(i);
      channel.reset(true);
    }
  }
コード例 #17
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
 private AnimChannel createRightArmChannels() {
   AnimChannel channel = animControl.createChannel();
   channel.addFromRootBone("RightShoulder");
   return channel;
 }
コード例 #18
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
 private AnimChannel createNeckChannel() {
   AnimChannel channel = animControl.createChannel();
   channel.addFromRootBone("Neck");
   return channel;
 }
コード例 #19
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
 private void setAnimationFullBody(String animationName, float blendTime, LoopMode loopMode) {
   animControl.clearChannels();
   fullBodyChannel = animControl.createChannel();
   fullBodyChannel.setLoopMode(loopMode);
   fullBodyChannel.setAnim(animationName, blendTime);
 }
コード例 #20
0
ファイル: AnimationManager.java プロジェクト: Grasia/phatsim
 private static BoneTrack getFirstTrackForBone(
     AnimControl animControl, Animation animation, String boneName) {
   int boneIndex = animControl.getSkeleton().getBoneIndex(boneName);
   return getFirstTrackForBone(animation, boneIndex);
 }