Ejemplo n.º 1
0
  public Control cloneForSpatial(Spatial spatial) {
    Node clonedNode = (Node) spatial;
    AnimControl ctrl = spatial.getControl(AnimControl.class);
    SkeletonControl clone = new SkeletonControl();
    clone.setSpatial(clonedNode);

    clone.skeleton = ctrl.getSkeleton();
    // Fix animated targets for the cloned node
    clone.targets = findTargets(clonedNode);

    // Fix attachments for the cloned node
    for (int i = 0; i < clonedNode.getQuantity(); i++) {
      // go through attachment nodes, apply them to correct bone
      Spatial child = clonedNode.getChild(i);
      if (child instanceof Node) {
        Node clonedAttachNode = (Node) child;
        Bone originalBone = (Bone) clonedAttachNode.getUserData("AttachedBone");

        if (originalBone != null) {
          Bone clonedBone = clone.skeleton.getBone(originalBone.getName());

          clonedAttachNode.setUserData("AttachedBone", clonedBone);
          clonedBone.setAttachmentsNode(clonedAttachNode);
        }
      }
    }

    return clone;
  }
Ejemplo n.º 2
0
  /**
   * @param boneName the name of the bone
   * @return the node attached to this bone
   */
  public Node getAttachmentsNode(String boneName) {
    Bone b = skeleton.getBone(boneName);
    if (b == null) {
      throw new IllegalArgumentException("Given bone name does not exist " + "in the skeleton.");
    }

    Node n = b.getAttachmentsNode();
    Node model = (Node) spatial;
    model.attachChild(n);
    return n;
  }