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

The following examples show how to use com.jme3.animation.Bone#setUserControl() . 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: ModelPerformer.java    From OpenRTS with MIT License 6 votes vote down vote up
private void orientTurret(ModelActor actor) {
	for (Turret t : ((Unit) actor.getComp()).getTurrets()) {
		Bone turretBone = actor.getViewElements().spatial.getControl(AnimControl.class).getSkeleton().getBone(t.boneName);
		if (turretBone == null) {
			throw new RuntimeException("Can't find the bone " + t.boneName + " for turret.");
		}

		//			Vector3f axis;
		//			switch (t.boneAxis){
		//			case "X" : axis = Vector3f.UNIT_X; break;
		//			case "Y" : axis = Vector3f.UNIT_Y; break;
		//			case "Z" : axis = Vector3f.UNIT_Z; break;
		//			default : throw new IllegalArgumentException("Wrong bone axis for "+((Unit)actor.getComp()).builderID+" : "+t.boneAxis);
		//			}
		//			Quaternion r = new Quaternion().fromAngleAxis((float) t.yaw, axis);
		Quaternion r = new Quaternion().fromAngleAxis((float) t.yaw, Vector3f.UNIT_Y);
		turretBone.setUserControl(true);
		turretBone.setUserTransforms(Vector3f.ZERO, r, Vector3f.UNIT_XYZ);
	}
}
 
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: TestOgreComplexAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    Bone b = control.getSkeleton().getBone("spinehigh");
    Bone b2 = control.getSkeleton().getBone("uparm.left");
    
    angle += tpf * rate;        
    if (angle > FastMath.HALF_PI / 2f){
        angle = FastMath.HALF_PI / 2f;
        rate = -1;
    }else if (angle < -FastMath.HALF_PI / 2f){
        angle = -FastMath.HALF_PI / 2f;
        rate = 1;
    }

    Quaternion q = new Quaternion();
    q.fromAngles(0, angle, 0);

    b.setUserControl(true);
    b.setUserTransforms(Vector3f.ZERO, q, Vector3f.UNIT_XYZ);
    
    b2.setUserControl(true);
    b2.setUserTransforms(Vector3f.ZERO, Quaternion.IDENTITY, new Vector3f(1+angle,1+ angle, 1+angle));
  
  
}
 
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: 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 8
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 9
Source File: TestCustomAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {

    AmbientLight al = new AmbientLight();
    rootNode.addLight(al);

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);

    Box box = new Box(1, 1, 1);

    // Setup bone weight buffer
    FloatBuffer weights = FloatBuffer.allocate( box.getVertexCount() * 4 );
    VertexBuffer weightsBuf = new VertexBuffer(Type.BoneWeight);
    weightsBuf.setupData(Usage.CpuOnly, 4, Format.Float, weights);
    box.setBuffer(weightsBuf);

    // Setup bone index buffer
    ByteBuffer indices = ByteBuffer.allocate( box.getVertexCount() * 4 );
    VertexBuffer indicesBuf = new VertexBuffer(Type.BoneIndex);
    indicesBuf.setupData(Usage.CpuOnly, 4, Format.UnsignedByte, indices);
    box.setBuffer(indicesBuf);

    // Create bind pose buffers
    box.generateBindPose(true);

    // Create skeleton
    bone = new Bone("root");
    bone.setBindTransforms(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ);
    bone.setUserControl(true);
    skeleton = new Skeleton(new Bone[]{ bone });

    // Assign all verticies to bone 0 with weight 1
    for (int i = 0; i < box.getVertexCount() * 4; i += 4){
        // assign vertex to bone index 0
        indices.array()[i+0] = 0;
        indices.array()[i+1] = 0;
        indices.array()[i+2] = 0;
        indices.array()[i+3] = 0;

        // set weight to 1 only for first entry
        weights.array()[i+0] = 1;
        weights.array()[i+1] = 0;
        weights.array()[i+2] = 0;
        weights.array()[i+3] = 0;
    }

    // Maximum number of weights per bone is 1
    box.setMaxNumWeights(1);

    // Create model
    Geometry geom = new Geometry("box", box);
    geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
    Node model = new Node("model");
    model.attachChild(geom);

    // Create skeleton control
    SkeletonControl skeletonControl = new SkeletonControl(skeleton);
    model.addControl(skeletonControl);

    rootNode.attachChild(model);
}