Java Code Examples for com.jme3.animation.AnimControl#getSkeleton()

The following examples show how to use com.jme3.animation.AnimControl#getSkeleton() . 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: KinematicRagdollControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void scanSpatial(Spatial model) {
    AnimControl animControl = model.getControl(AnimControl.class);
    Map<Integer, List<Float>> pointsMap = null;
    if (weightThreshold == -1.0f) {
        pointsMap = RagdollUtils.buildPointMap(model);
    }

    skeleton = animControl.getSkeleton();
    skeleton.resetAndUpdate();
    for (int i = 0; i < skeleton.getRoots().length; i++) {
        Bone childBone = skeleton.getRoots()[i];
        if (childBone.getParent() == null) {
            logger.log(Level.INFO, "Found root bone in skeleton {0}", skeleton);
            baseRigidBody = new PhysicsRigidBody(new BoxCollisionShape(Vector3f.UNIT_XYZ.mult(0.1f)), 1);
            baseRigidBody.setKinematic(mode == Mode.Kinetmatic);
            boneRecursion(model, childBone, baseRigidBody, 1, pointsMap);
        }
    }
}
 
Example 2
Source File: KinematicRagdollControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void scanSpatial(Spatial model) {
    AnimControl animControl = model.getControl(AnimControl.class);
    Map<Integer, List<Float>> pointsMap = null;
    if (weightThreshold == -1.0f) {
        pointsMap = RagdollUtils.buildPointMap(model);
    }

    skeleton = animControl.getSkeleton();
    skeleton.resetAndUpdate();
    for (int i = 0; i < skeleton.getRoots().length; i++) {
        Bone childBone = skeleton.getRoots()[i];
        if (childBone.getParent() == null) {
            logger.log(Level.INFO, "Found root bone in skeleton {0}", skeleton);
            baseRigidBody = new PhysicsRigidBody(new BoxCollisionShape(Vector3f.UNIT_XYZ.mult(0.1f)), 1);
            baseRigidBody.setKinematic(mode == Mode.Kinetmatic);
            boneRecursion(model, childBone, baseRigidBody, 1, pointsMap);
        }
    }
}
 
Example 3
Source File: AnimationBoneTrackTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
protected String computeName() {
    final BoneTrack boneTrack = getElement();
    final AnimControl control = notNull(getControl());
    final Skeleton skeleton = control.getSkeleton();
    final Bone bone = skeleton.getBone(boneTrack.getTargetBoneIndex());
    return "Bone track : " + bone.getName();
}
 
Example 4
Source File: ModelPerformer.java    From OpenRTS with MIT License 5 votes vote down vote up
private void updateBoneCoords(ModelActor actor) {
	AnimControl ctrl = actor.getViewElements().spatial.getControl(AnimControl.class);
	if(ctrl == null) {
		return;
	}
	Skeleton sk = ctrl.getSkeleton();
	for (int i = 0; i < sk.getBoneCount(); i++) {
		Bone b = sk.getBone(i);
		actor.setBone(b.getName(), getBoneWorldPos(actor, i));
	}
}
 
Example 5
Source File: TestAnimBlendBug.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        inputManager.addMapping("One", new KeyTrigger(KeyInput.KEY_1));
        inputManager.addListener(this, "One");

        flyCam.setMoveSpeed(100f);
        cam.setLocation( new Vector3f( 0f, 150f, -325f ) );
        cam.lookAt( new Vector3f( 0f, 100f, 0f ), Vector3f.UNIT_Y );

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
        dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
        rootNode.addLight(dl);

        Node model1 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
        Node model2 = (Node) assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
//        Node model2 = model1.clone();

        model1.setLocalTranslation(-60, 0, 0);
        model2.setLocalTranslation(60, 0, 0);

        AnimControl control1 = model1.getControl(AnimControl.class);
        animNames = control1.getAnimationNames().toArray(new String[0]);
        channel1 = control1.createChannel();
        
        AnimControl control2 = model2.getControl(AnimControl.class);
        channel2 = control2.createChannel();

        SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton1", control1.getSkeleton());
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.getAdditionalRenderState().setWireframe(true);
        mat.setColor("Color", ColorRGBA.Green);
        mat.getAdditionalRenderState().setDepthTest(false);
        skeletonDebug.setMaterial(mat);
        model1.attachChild(skeletonDebug);

        skeletonDebug = new SkeletonDebugger("skeleton2", control2.getSkeleton());
        skeletonDebug.setMaterial(mat);
        model2.attachChild(skeletonDebug);

        rootNode.attachChild(model1);
        rootNode.attachChild(model2);
    }