/**
   * This method creates an ipo object used for interpolation calculations.
   *
   * @param ipoStructure the structure with ipo definition
   * @param blenderContext the blender context
   * @return the ipo object
   * @throws BlenderFileException this exception is thrown when the blender file is somehow
   *     corrupted
   */
  public Ipo fromIpoStructure(Structure ipoStructure, BlenderContext blenderContext)
      throws BlenderFileException {
    Structure curvebase = (Structure) ipoStructure.getFieldValue("curve");

    // preparing bezier curves
    Ipo result = null;
    List<Structure> curves = curvebase.evaluateListBase(); // IpoCurve
    if (curves.size() > 0) {
      BezierCurve[] bezierCurves = new BezierCurve[curves.size()];
      int frame = 0;
      for (Structure curve : curves) {
        Pointer pBezTriple = (Pointer) curve.getFieldValue("bezt");
        List<Structure> bezTriples = pBezTriple.fetchData();
        int type = ((Number) curve.getFieldValue("adrcode")).intValue();
        bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2);
      }
      curves.clear();
      result = new Ipo(bezierCurves, fixUpAxis, blenderContext.getBlenderVersion());
      Long ipoOma = ipoStructure.getOldMemoryAddress();
      blenderContext.addLoadedFeatures(ipoOma, LoadedDataType.STRUCTURE, ipoStructure);
      blenderContext.addLoadedFeatures(ipoOma, LoadedDataType.FEATURE, result);
    }
    return result;
  }
Beispiel #2
0
  /**
   * This method builds the bone. It recursively builds the bone's children.
   *
   * @param bones a list of bones where the newly created bone will be added
   * @param boneOMAs the map between bone and its old memory address
   * @param blenderContext the blender context
   * @return newly created bone
   */
  public Bone buildBone(List<Bone> bones, Map<Bone, Long> boneOMAs, BlenderContext blenderContext) {
    Long boneOMA = boneStructure.getOldMemoryAddress();
    bone = new Bone(boneName);
    bones.add(bone);
    boneOMAs.put(bone, boneOMA);
    blenderContext.addLoadedFeatures(boneOMA, boneName, boneStructure, bone);

    Matrix4f pose = this.restMatrix.clone();
    ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);

    Vector3f poseLocation = pose.toTranslationVector();
    Quaternion rotation = pose.toRotationQuat();
    Vector3f scale = objectHelper.getScale(pose);

    bone.setBindTransforms(poseLocation, rotation, scale);
    for (BoneContext child : children) {
      bone.addChild(child.buildBone(bones, boneOMAs, blenderContext));
    }

    this.computePoseTransform();

    return bone;
  }