Java Code Examples for com.jme3.animation.Bone#getChildren()

The following examples show how to use com.jme3.animation.Bone#getChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RagdollUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Updates a bone position and rotation. if the child bones are not in the
 * bone list this means, they are not associated with a physics shape. So
 * they have to be updated
 *
 * @param bone the bone
 * @param pos the position
 * @param rot the rotation
 * @param restoreBoneControl true → user-control flag should be set
 * @param boneList the names of all bones without collision shapes (not
 * null, unaffected)
 */
public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) {
    //we ensure that we have the control
    if (restoreBoneControl) {
        bone.setUserControl(true);
    }
    //we set te user transforms of the bone
    bone.setUserTransformsInModelSpace(pos, rot);
    for (Bone childBone : bone.getChildren()) {
        //each child bone that is not in the list is updated
        if (!boneList.contains(childBone.getName())) {
            Transform t = childBone.getCombinedTransform(pos, rot);
            setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList);
        }
    }
    //we give back the control to the keyframed animation
    if (restoreBoneControl) {
        bone.setUserControl(false);
    }
}
 
Example 2
Source File: SkeletonInterBoneWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The method updates the geometry according to the poitions of the bones.
 */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));

        for (Bone child : bone.getChildren()) {
            Vector3f childHead = child.getModelSpacePosition();
            Vector3f v = childHead.subtract(parentTail);
            float pointDelta = v.length() / POINT_AMOUNT;
            v.normalizeLocal().multLocal(pointDelta);
            Vector3f pointPosition = parentTail.clone();
            for (int j = 0; j < POINT_AMOUNT; ++j) {
                posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ());
                pointPosition.addLocal(v);
            }
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);

    this.updateBound();
}
 
Example 3
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Updates a bone position and rotation.
 * if the child bones are not in the bone list this means, they are not associated with a physic shape.
 * So they have to be updated
 * @param bone the bone
 * @param pos the position
 * @param rot the rotation
 */
public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) {
    //we ensure that we have the control
    if (restoreBoneControl) {
        bone.setUserControl(true);
    }
    //we set te user transforms of the bone
    bone.setUserTransformsWorld(pos, rot);
    for (Bone childBone : bone.getChildren()) {
        //each child bone that is not in the list is updated
        if (!boneList.contains(childBone.getName())) {
            Transform t = childBone.getCombinedTransform(pos, rot);
            setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList);
        }
    }
    //we give back the control to the keyframed animation
    if (restoreBoneControl) {
        bone.setUserControl(false);
    }
}
 
Example 4
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Updates a bone position and rotation.
 * if the child bones are not in the bone list this means, they are not associated with a physic shape.
 * So they have to be updated
 * @param bone the bone
 * @param pos the position
 * @param rot the rotation
 */
public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) {
    //we ensure that we have the control
    if (restoreBoneControl) {
        bone.setUserControl(true);
    }
    //we set te user transforms of the bone
    bone.setUserTransformsWorld(pos, rot);
    for (Bone childBone : bone.getChildren()) {
        //each child bone that is not in the list is updated
        if (!boneList.contains(childBone.getName())) {
            Transform t = childBone.getCombinedTransform(pos, rot);
            setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList);
        }
    }
    //we give back the control to the keyframed animation
    if (restoreBoneControl) {
        bone.setUserControl(false);
    }
}
 
Example 5
Source File: RagdollUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Enumerate the bone indices of the specified bone and all its descendents.
 *
 * @param bone the input bone (not null)
 * @param skeleton the skeleton containing the bone (not null)
 * @param boneList a set of bone names (not null, unaffected)
 *
 * @return a new list (not null)
 */
public static List<Integer> getBoneIndices(Bone bone, Skeleton skeleton, Set<String> boneList) {
    List<Integer> list = new LinkedList<Integer>();
    if (boneList.isEmpty()) {
        list.add(skeleton.getBoneIndex(bone));
    } else {
        list.add(skeleton.getBoneIndex(bone));
        for (Bone chilBone : bone.getChildren()) {
            if (!boneList.contains(chilBone.getName())) {
                list.addAll(getBoneIndices(chilBone, skeleton, boneList));
            }
        }
    }
    return list;
}
 
Example 6
Source File: RagdollUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Alter the user-control flags of a bone and all its descendents.
 *
 * @param bone the ancestor bone (not null, modified)
 * @param bool true to enable user control, false to disable
 */
public static void setUserControl(Bone bone, boolean bool) {
    bone.setUserControl(bool);
    for (Bone child : bone.getChildren()) {
        setUserControl(child, bool);
    }
}
 
Example 7
Source File: SkeletonInterBoneWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Th method couns the connections between bones.
 * @param bone
 *            the bone where counting starts
 */
private void countConnections(Bone bone) {
    for (Bone child : bone.getChildren()) {
        ++connectionsAmount;
        this.countConnections(child);
    }
}
 
Example 8
Source File: SkeletonWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Th method couns the connections between bones.
 * @param bone
 *            the bone where counting starts
 */
private void countConnections(Bone bone) {
    for (Bone child : bone.getChildren()) {
        numConnections++;
        this.countConnections(child);
    }
}
 
Example 9
Source File: SkeletonWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * The method writes the indexes for the connection vertices. Used in non-length mode.
 * @param indexBuf
 *            the index buffer
 * @param bone
 *            the bone
 */
private void writeConnections(ShortBuffer indexBuf, Bone bone) {
    for (Bone child : bone.getChildren()) {
        // write myself
        indexBuf.put((short) skeleton.getBoneIndex(bone));
        // write the child
        indexBuf.put((short) skeleton.getBoneIndex(child));

        this.writeConnections(indexBuf, child);
    }
}
 
Example 10
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<Integer> getBoneIndices(Bone bone, Skeleton skeleton, Set<String> boneList) {
    List<Integer> list = new LinkedList<Integer>();
    if (boneList.isEmpty()) {
        list.add(skeleton.getBoneIndex(bone));
    } else {
        list.add(skeleton.getBoneIndex(bone));
        for (Bone chilBone : bone.getChildren()) {
            if (!boneList.contains(chilBone.getName())) {
                list.addAll(getBoneIndices(chilBone, skeleton, boneList));
            }
        }
    }
    return list;
}
 
Example 11
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<Integer> getBoneIndices(Bone bone, Skeleton skeleton, Set<String> boneList) {
    List<Integer> list = new LinkedList<Integer>();
    if (boneList.isEmpty()) {
        list.add(skeleton.getBoneIndex(bone));
    } else {
        list.add(skeleton.getBoneIndex(bone));
        for (Bone chilBone : bone.getChildren()) {
            if (!boneList.contains(chilBone.getName())) {
                list.addAll(getBoneIndices(chilBone, skeleton, boneList));
            }
        }
    }
    return list;
}
 
Example 12
Source File: IKControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void updateWorldVectors(Bone bone) {
//        pmdNode.getSkeleton().updateWorldVectors();
        bone.updateWorldVectors();
        final ArrayList<Bone> children = bone.getChildren();
        final int size = children.size();
        for(int i=0;i<size;i++) {
            Bone childBone = children.get(i);
            updateWorldVectors(childBone);
        }
    }
 
Example 13
Source File: SkeletonWire.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void writeConnections(ShortBuffer indexBuf, Bone bone){
    for (Bone child : bone.getChildren()){
        // write myself
        indexBuf.put( (short) skeleton.getBoneIndex(bone) );
        // write the child
        indexBuf.put( (short) skeleton.getBoneIndex(child) );

        writeConnections(indexBuf, child);
    }
}
 
Example 14
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void setUserControl(Bone bone, boolean bool) {
    bone.setUserControl(bool);
    for (Bone child : bone.getChildren()) {
        setUserControl(child, bool);
    }
}
 
Example 15
Source File: RagdollUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void setUserControl(Bone bone, boolean bool) {
    bone.setUserControl(bool);
    for (Bone child : bone.getChildren()) {
        setUserControl(child, bool);
    }
}
 
Example 16
Source File: SkeletonWire.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void countConnections(Bone bone){
    for (Bone child : bone.getChildren()){
        numConnections ++;
        countConnections(child);
    }
}