Ejemplo n.º 1
0
  /**
   * This method retuns the bone tracks for animation for blender version 2.50 and higher.
   *
   * @param actionStructure the structure containing the tracks
   * @param blenderContext the blender context
   * @return a list of tracks for the specified animation
   * @throws BlenderFileException an exception is thrown when there are problems with the blend file
   */
  private BlenderAction getTracks250(Structure actionStructure, BlenderContext blenderContext)
      throws BlenderFileException {
    LOGGER.log(Level.FINE, "Getting tracks!");
    Structure groups = (Structure) actionStructure.getFieldValue("groups");
    List<Structure> actionGroups = groups.evaluateListBase(); // bActionGroup
    BlenderAction blenderAction =
        new BlenderAction(actionStructure.getName(), blenderContext.getBlenderKey().getFps());
    int lastFrame = 1;
    for (Structure actionGroup : actionGroups) {
      String name = actionGroup.getFieldValue("name").toString();
      List<Structure> channels =
          ((Structure) actionGroup.getFieldValue("channels")).evaluateListBase();
      BezierCurve[] bezierCurves = new BezierCurve[channels.size()];
      int channelCounter = 0;
      for (Structure c : channels) {
        int type = this.getCurveType(c, blenderContext);
        Pointer pBezTriple = (Pointer) c.getFieldValue("bezt");
        List<Structure> bezTriples = pBezTriple.fetchData();
        bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2);
      }

      Ipo ipo = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
      lastFrame = Math.max(lastFrame, ipo.getLastFrame());
      blenderAction.featuresTracks.put(name, ipo);
    }
    blenderAction.stopFrame = lastFrame;
    return blenderAction;
  }
  public void bake(
      Transform ownerTransform,
      Transform targetTransform,
      Track ownerTrack,
      Track targetTrack,
      Ipo influenceIpo) {
    TrackWrapper ownerWrapperTrack = ownerTrack != null ? new TrackWrapper(ownerTrack) : null;
    TrackWrapper targetWrapperTrack = targetTrack != null ? new TrackWrapper(targetTrack) : null;

    // uruchamiamy bake dla transformat zalenie od tego, ktre argumenty s nullami, a ktre - nie
    this.bake(ownerTransform, targetTransform, influenceIpo.calculateValue(0));
    if (ownerWrapperTrack != null) {
      float[] ownerTimes = ownerWrapperTrack.getTimes();
      Vector3f[] translations = ownerWrapperTrack.getTranslations();
      Quaternion[] rotations = ownerWrapperTrack.getRotations();
      Vector3f[] scales = ownerWrapperTrack.getScales();

      float[] targetTimes = targetWrapperTrack == null ? null : targetWrapperTrack.getTimes();
      Vector3f[] targetTranslations =
          targetWrapperTrack == null ? null : targetWrapperTrack.getTranslations();
      Quaternion[] targetRotations =
          targetWrapperTrack == null ? null : targetWrapperTrack.getRotations();
      Vector3f[] targetScales = targetWrapperTrack == null ? null : targetWrapperTrack.getScales();
      Vector3f translation = new Vector3f(), scale = new Vector3f();
      Quaternion rotation = new Quaternion();

      Transform ownerTemp = new Transform(), targetTemp = new Transform();
      for (int i = 0; i < ownerTimes.length; ++i) {
        float t = ownerTimes[i];
        ownerTemp.setTranslation(translations[i]);
        ownerTemp.setRotation(rotations[i]);
        ownerTemp.setScale(scales[i]);
        if (targetWrapperTrack == null) {
          this.bake(ownerTemp, targetTransform, influenceIpo.calculateValue(i));
        } else {
          // getting the values that are the interpolation of the target track for the time 't'
          this.interpolate(targetTranslations, targetTimes, t, translation);
          this.interpolate(targetRotations, targetTimes, t, rotation);
          this.interpolate(targetScales, targetTimes, t, scale);

          targetTemp.setTranslation(translation);
          targetTemp.setRotation(rotation);
          targetTemp.setScale(scale);

          this.bake(ownerTemp, targetTemp, influenceIpo.calculateValue(i));
        }
        // need to clone here because each of the arrays will reference the same instance if they
        // hold the same value in the compact array
        translations[i] = ownerTemp.getTranslation().clone();
        rotations[i] = ownerTemp.getRotation().clone();
        scales[i] = ownerTemp.getScale().clone();
      }
      ownerWrapperTrack.setKeyframes(ownerTimes, translations, rotations, scales);
    }
  }
Ejemplo n.º 3
0
 /**
  * This method retuns the bone tracks for animation for blender version 2.49 (and probably several
  * lower versions too).
  *
  * @param actionStructure the structure containing the tracks
  * @param blenderContext the blender context
  * @return a list of tracks for the specified animation
  * @throws BlenderFileException an exception is thrown when there are problems with the blend file
  */
 private BlenderAction getTracks249(Structure actionStructure, BlenderContext blenderContext)
     throws BlenderFileException {
   LOGGER.log(Level.FINE, "Getting tracks!");
   Structure chanbase = (Structure) actionStructure.getFieldValue("chanbase");
   List<Structure> actionChannels = chanbase.evaluateListBase(); // bActionChannel
   BlenderAction blenderAction =
       new BlenderAction(actionStructure.getName(), blenderContext.getBlenderKey().getFps());
   int lastFrame = 1;
   for (Structure bActionChannel : actionChannels) {
     String animatedFeatureName = bActionChannel.getFieldValue("name").toString();
     Pointer p = (Pointer) bActionChannel.getFieldValue("ipo");
     if (!p.isNull()) {
       Structure ipoStructure = p.fetchData().get(0);
       Ipo ipo = this.fromIpoStructure(ipoStructure, blenderContext);
       if (ipo != null) { // this can happen when ipo with no curves appear in blender file
         lastFrame = Math.max(lastFrame, ipo.getLastFrame());
         blenderAction.featuresTracks.put(animatedFeatureName, ipo);
       }
     }
   }
   blenderAction.stopFrame = lastFrame;
   return blenderAction;
 }