コード例 #1
0
ファイル: BoneConstraint.java プロジェクト: btodorov88/IN4189
  @Override
  protected void prepareTracksForApplyingConstraints() {
    Long[] bonesOMAs = new Long[] {ownerOMA, targetOMA};
    Space[] spaces = new Space[] {ownerSpace, targetSpace};

    // creating animations for current objects if at least on of their parents have an animation
    for (int i = 0; i < bonesOMAs.length; ++i) {
      Long oma = bonesOMAs[i];
      if (this.hasAnimation(oma)) {
        Bone currentBone = blenderContext.getBoneContext(oma).getBone();
        Bone parent = currentBone.getParent();
        boolean foundAnimation = false;
        AnimData animData = null;
        while (parent != null && !foundAnimation) {
          BoneContext boneContext = blenderContext.getBoneByName(parent.getName());
          foundAnimation = this.hasAnimation(boneContext.getBoneOma());
          animData = blenderContext.getAnimData(boneContext.getBoneOma());
          parent = parent.getParent();
        }

        if (foundAnimation) {
          this.applyAnimData(blenderContext.getBoneContext(oma), spaces[i], animData);
        }
      }
    }

    // creating animation for owner if it doesn't have one already and if the target has it
    if (!this.hasAnimation(ownerOMA) && this.hasAnimation(targetOMA)) {
      AnimData targetAnimData = blenderContext.getAnimData(targetOMA);
      this.applyAnimData(blenderContext.getBoneContext(ownerOMA), ownerSpace, targetAnimData);
    }
  }
コード例 #2
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);
     }
   }
 }
コード例 #3
0
  private void boneRecursion(
      Spatial model,
      Bone bone,
      PhysicsRigidBody parent,
      int reccount,
      Map<Integer, List<Float>> pointsMap) {
    PhysicsRigidBody parentShape = parent;
    if (boneList.isEmpty() || boneList.contains(bone.getName())) {

      PhysicsBoneLink link = new PhysicsBoneLink();
      link.bone = bone;

      // creating the collision shape
      HullCollisionShape shape = null;
      if (pointsMap != null) {
        // build a shape for the bone, using the vertices that are most influenced by this bone
        shape =
            RagdollUtils.makeShapeFromPointMap(
                pointsMap,
                RagdollUtils.getBoneIndices(link.bone, skeleton, boneList),
                initScale,
                link.bone.getModelSpacePosition());
      } else {
        // build a shape for the bone, using the vertices associated with this bone with a weight
        // above the threshold
        shape =
            RagdollUtils.makeShapeFromVerticeWeights(
                model,
                RagdollUtils.getBoneIndices(link.bone, skeleton, boneList),
                initScale,
                link.bone.getModelSpacePosition(),
                weightThreshold);
      }

      PhysicsRigidBody shapeNode = new PhysicsRigidBody(shape, rootMass / (float) reccount);

      shapeNode.setKinematic(mode == Mode.Kinematic);
      totalMass += rootMass / (float) reccount;

      link.rigidBody = shapeNode;
      link.initalWorldRotation = bone.getModelSpaceRotation().clone();

      if (parent != null) {
        // get joint position for parent
        Vector3f posToParent = new Vector3f();
        if (bone.getParent() != null) {
          bone.getModelSpacePosition()
              .subtract(bone.getParent().getModelSpacePosition(), posToParent)
              .multLocal(initScale);
        }

        SixDofJoint joint =
            new SixDofJoint(parent, shapeNode, posToParent, new Vector3f(0, 0, 0f), true);
        preset.setupJointForBone(bone.getName(), joint);

        link.joint = joint;
        joint.setCollisionBetweenLinkedBodys(false);
      }
      boneLinks.put(bone.getName(), link);
      shapeNode.setUserObject(link);
      parentShape = shapeNode;
    }

    for (Iterator<Bone> it = bone.getChildren().iterator(); it.hasNext(); ) {
      Bone childBone = it.next();
      boneRecursion(model, childBone, parentShape, reccount + 1, pointsMap);
    }
  }