Esempio 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;
  }
Esempio n. 2
0
  /**
   * Constructor. Creates the basic set of bone's data.
   *
   * @param boneStructure the bone's structure
   * @param parent bone's parent (null if the bone is the root bone)
   * @param objectToArmatureMatrix object-to-armature transformation matrix
   * @param bonesPoseChannels a map of pose channels for each bone OMA
   * @param blenderContext the blender context
   * @throws BlenderFileException an exception is thrown when problem with blender data reading
   *     occurs
   */
  private BoneContext(
      Structure boneStructure,
      BoneContext parent,
      Matrix4f objectToArmatureMatrix,
      final Map<Long, Structure> bonesPoseChannels,
      BlenderContext blenderContext)
      throws BlenderFileException {
    this.parent = parent;
    this.boneStructure = boneStructure;
    boneName = boneStructure.getFieldValue("name").toString();
    ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
    armatureMatrix = objectHelper.getMatrix(boneStructure, "arm_mat", true);

    fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis();
    this.computeRestMatrix(objectToArmatureMatrix);
    List<Structure> childbase =
        ((Structure) boneStructure.getFieldValue("childbase")).evaluateListBase(blenderContext);
    for (Structure child : childbase) {
      this.children.add(
          new BoneContext(child, this, objectToArmatureMatrix, bonesPoseChannels, blenderContext));
    }

    poseChannel = bonesPoseChannels.get(boneStructure.getOldMemoryAddress());

    blenderContext.setBoneContext(boneStructure.getOldMemoryAddress(), this);
  }
Esempio 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;
 }