com.jme3.animation.AnimControl Java Examples

The following examples show how to use com.jme3.animation.AnimControl. 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: HelloAnimation.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
  viewPort.setBackgroundColor(ColorRGBA.LightGray);
  initKeys();

  /** Add a light source so we can see the model */
  DirectionalLight dl = new DirectionalLight();
  dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
  rootNode.addLight(dl);

  /** Load a model that contains animation */
  player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
  player.setLocalScale(0.5f);
  rootNode.attachChild(player);

  /** Create a controller and channels. */
  control = player.getControl(AnimControl.class);
  control.addListener(this);
  channel = control.createChannel();
  channel.setAnim("stand");
}
 
Example #3
Source File: AnimationUtils.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Get a free name to make an animation.
 *
 * @param control the animation control.
 * @param base    the base name.
 * @return the free name.
 */
@FromAnyThread
public static @NotNull String findFreeName(@NotNull AnimControl control, @NotNull String base) {

    if (control.getAnim(base) == null) {
        return base;
    }

    int i = 1;

    while (control.getAnim(base + "_" + i) != null) {
        i++;
    }

    return base + "_" + i;
}
 
Example #4
Source File: AnimationPerformer.java    From OpenRTS with MIT License 6 votes vote down vote up
@Override
public void perform(Actor a) {
	AnimationActor actor = (AnimationActor)a;
	if(actor.launched) {
		return;
	}
	actor.launched = true;
	Spatial s = actor.getParentModelActor().getViewElements().spatial;
	AnimChannel channel = s.getControl(AnimControl.class).getChannel(0);
	channel.setAnim(actor.animName);
	switch (actor.cycle){
		case Once : channel.setLoopMode(LoopMode.DontLoop); break;
		case Loop : channel.setLoopMode(LoopMode.Loop); break;
		case Cycle : channel.setLoopMode(LoopMode.Cycle); break;
	}
	channel.setSpeed((float)actor.speed);
}
 
Example #5
Source File: RemoveAnimationAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final TreeNode<?> node = getNode();
    final Object element = node.getElement();

    if (!(element instanceof Animation)) return;
    final Animation animation = (Animation) element;

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    final TreeNode<?> parentNode = nodeTree.findParent(node);

    if (parentNode == null) {
        LOGGER.warning("not found parent node for " + node);
        return;
    }

    final AnimControl parent = (AnimControl) parentNode.getElement();

    final ModelChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(new RemoveAnimationNodeOperation(animation, parent));
}
 
Example #6
Source File: PauseAnimationAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final AnimationTreeNode modelNode = (AnimationTreeNode) getNode();
    if (modelNode.getChannel() < 0) return;

    final AnimControl control = modelNode.getControl();
    if (control == null || control.getNumChannels() <= 0) return;

    final AnimChannel channel = control.getChannel(modelNode.getChannel());
    channel.setSpeed(0);
    modelNode.setSpeed(0);

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    nodeTree.update(modelNode);
}
 
Example #7
Source File: StopAnimationAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final AnimationTreeNode modelNode = (AnimationTreeNode) getNode();
    if (modelNode.getChannel() < 0) return;

    final AnimControl control = modelNode.getControl();
    if (control == null || control.getNumChannels() <= 0) return;

    final AnimChannel channel = control.getChannel(modelNode.getChannel());
    channel.setLoopMode(LoopMode.DontLoop);

    EXECUTOR_MANAGER.addJmeTask(control::clearChannels);

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    nodeTree.update(modelNode);
}
 
Example #8
Source File: ModelPerformer.java    From OpenRTS with MIT License 6 votes vote down vote up
@Override
public void perform(Actor a) {
	ModelActor actor = (ModelActor) a;
	if (actor.getViewElements().spatial == null) {
		Spatial s = actorDrawer.buildSpatial(actor);
		actor.getViewElements().spatial = s;
		// We force update here because we need imediatly to have access to bones' absolute position.
		AnimControl animControl = s.getControl(AnimControl.class);
		if (animControl != null) {
			animControl.update(0);
		} else if(actor.getComp() instanceof Unit &&
				!((Unit)actor.getComp()).getTurrets().isEmpty()) {
			throw new RuntimeException("The unit "+actor.getComp()+" attached to actor "+actor+" have one or more turret, but no AnimControl.");
		}
	}

	if (actor.getComp() != null) {
		drawAsComp(actor);
	}
}
 
Example #9
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 #10
Source File: AnimationTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void initEvent(Application app, Cinematic cinematic) {
    super.initEvent(app, cinematic);
    if (channel == null) {
        Object s = cinematic.getEventData("modelChannels", modelName);
        if (s != null && s instanceof AnimChannel) {
            this.channel = (AnimChannel) s;
        } else if (s == null) {
            Spatial model = cinematic.getScene().getChild(modelName);
            if (model != null) {
                channel = model.getControl(AnimControl.class).createChannel();
                cinematic.putEventData("modelChannels", modelName, channel);
            } else {
                log.log(Level.WARNING, "spatial {0} not found in the scene, cannot perform animation", modelName);
            }
        }

    }
}
 
Example #11
Source File: TestBlenderAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    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);

    BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend");
    
    Spatial scene = (Spatial) assetManager.loadModel(blenderKey);
    rootNode.attachChild(scene);
    
    Spatial model = this.findNode(rootNode, "BaseMesh_01");
    model.center();
    
    control = model.getControl(AnimControl.class);
    channel = control.createChannel();

    channel.setAnim("run_01");
}
 
Example #12
Source File: KinematicRagdollControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Enable or disable the ragdoll behaviour.
 * if ragdollEnabled is true, the character motion will only be powerd by physics
 * else, the characted will be animated by the keyframe animation, 
 * but will be able to physically interact with its physic environnement
 * @param ragdollEnabled 
 */
protected void setMode(Mode mode) {
    this.mode = mode;
    AnimControl animControl = targetModel.getControl(AnimControl.class);
    animControl.setEnabled(mode == Mode.Kinetmatic);

    baseRigidBody.setKinematic(mode == Mode.Kinetmatic);
    TempVars vars = TempVars.get();
    
    for (PhysicsBoneLink link : boneLinks.values()) {
        link.rigidBody.setKinematic(mode == Mode.Kinetmatic);
        if (mode == Mode.Ragdoll) {
            Quaternion tmpRot1 = vars.quat1;
            Vector3f position = vars.vect1;
            //making sure that the ragdoll is at the correct place.
            matchPhysicObjectToBone(link, position, tmpRot1);
        }

    }
    vars.release();

    for (Bone bone : skeleton.getRoots()) {
        RagdollUtils.setUserControl(bone, mode == Mode.Ragdoll);
    }
}
 
Example #13
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 #14
Source File: KinematicRagdollControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Enable or disable the ragdoll behaviour.
 * if ragdollEnabled is true, the character motion will only be powerd by physics
 * else, the characted will be animated by the keyframe animation, 
 * but will be able to physically interact with its physic environnement
 * @param ragdollEnabled 
 */
protected void setMode(Mode mode) {
    this.mode = mode;
    AnimControl animControl = targetModel.getControl(AnimControl.class);
    animControl.setEnabled(mode == Mode.Kinetmatic);

    baseRigidBody.setKinematic(mode == Mode.Kinetmatic);
    TempVars vars = TempVars.get();
    
    for (PhysicsBoneLink link : boneLinks.values()) {
        link.rigidBody.setKinematic(mode == Mode.Kinetmatic);
        if (mode == Mode.Ragdoll) {
            Quaternion tmpRot1 = vars.quat1;
            Vector3f position = vars.vect1;
            //making sure that the ragdoll is at the correct place.
            matchPhysicObjectToBone(link, position, tmpRot1);
        }

    }
    vars.release();

    for (Bone bone : skeleton.getRoots()) {
        RagdollUtils.setUserControl(bone, mode == Mode.Ragdoll);
    }
}
 
Example #15
Source File: ExtractSubAnimationDialog.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
public ExtractSubAnimationDialog(@NotNull final NodeTree<?> nodeTree, @NotNull final AnimationTreeNode node) {
    this.nodeTree = nodeTree;
    this.node = node;

    final Animation animation = node.getElement();
    final AnimControl control = notNull(node.getControl());
    final int frameCount = AnimationUtils.getFrameCount(animation);

    final TextField nameField = getNameField();
    nameField.setText(AnimationUtils.findFreeName(control, Messages.MANUAL_EXTRACT_ANIMATION_DIALOG_NAME_EXAMPLE));

    final IntegerTextField startFrameField = getStartFrameField();
    startFrameField.setMinMax(0, frameCount - 2);
    startFrameField.setValue(0);

    final IntegerTextField endFrameField = getEndFrameField();
    endFrameField.setMinMax(1, frameCount - 1);
    endFrameField.setValue(frameCount - 1);
}
 
Example #16
Source File: TestBlenderObjectAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    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);

    BlenderKey blenderKey = new BlenderKey("Blender/2.4x/animtest.blend");
    
    Spatial scene = (Spatial) assetManager.loadModel(blenderKey);
    rootNode.attachChild(scene);
    
    Spatial model = this.findNode(rootNode, "TestAnim");
    model.center();
    
    control = model.getControl(AnimControl.class);
    channel = control.createChannel();

    channel.setAnim("TestAnim");
}
 
Example #17
Source File: JmeAnimControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected Sheet createSheet() {
    //TODO: multithreading..
    Sheet sheet = Sheet.createDefault();
    Sheet.Set set = Sheet.createPropertiesSet();
    set.setDisplayName("AnimControl");
    set.setName(AnimControl.class.getName());
    if (animControl == null) {
        return sheet;
    }

    set.put(new AnimationProperty(animControl));

    sheet.put(set);
    return sheet;

}
 
Example #18
Source File: TestOgreConvert.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Spatial ogreModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(new Vector3f(0,-1,-1).normalizeLocal());
    rootNode.addLight(dl);

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryExporter exp = new BinaryExporter();
        exp.save(ogreModel, baos);

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        BinaryImporter imp = new BinaryImporter();
        imp.setAssetManager(assetManager);
        Node ogreModelReloaded = (Node) imp.load(bais, null, null);
        
        AnimControl control = ogreModelReloaded.getControl(AnimControl.class);
        AnimChannel chan = control.createChannel();
        chan.setAnim("Walk");

        rootNode.attachChild(ogreModelReloaded);
    } catch (IOException ex){
        ex.printStackTrace();
    }
}
 
Example #19
Source File: AnimationTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void changeName(@NotNull final NodeTree<?> nodeTree, @NotNull final String newName) {
    if (StringUtils.equals(getName(), newName)) return;

    super.changeName(nodeTree, newName);

    final AnimationControlTreeNode controlModelNode = notNull(getControlModelNode());
    final AnimControl control = controlModelNode.getElement();
    final RenameAnimationNodeOperation operation = new RenameAnimationNodeOperation(getName(), newName, control);

    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());
    changeConsumer.execute(operation);
}
 
Example #20
Source File: TestOgreAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    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);

    Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model.center();

    control = model.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();

    for (String anim : control.getAnimationNames())
        System.out.println(anim);

    channel.setAnim("stand");

    SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);

    Box b = new Box(.25f,3f,.25f);
    Geometry item = new Geometry("Item", b);
    item.move(0, 1.5f, 0);
    item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    Node n = skeletonControl.getAttachmentsNode("hand.right");
    n.attachChild(item);

    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #21
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 #22
Source File: CinematicTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * No ClassCastException when clear() a Cinematic with AnimationEvent
 */
@Test
public void clearAnimationEvent() {
    Cinematic sut = new Cinematic();
    Node model = new Node("model");
    AnimControl ac = new AnimControl();
    ac.addAnim(new Animation("animName", 1.0f));
    model.addControl(ac);
    sut.enqueueCinematicEvent(new AnimationEvent(model, "animName"));
    sut.initialize(null, null);
    sut.clear();
}
 
Example #23
Source File: HelloAnimation.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Use this listener to trigger something after an animation is done. */
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
  if (animName.equals("Walk")) {
    /** After "walk", reset to "stand". */
    channel.setAnim("stand", 0.50f);
    channel.setLoopMode(LoopMode.DontLoop);
    channel.setSpeed(1f);
  }
}
 
Example #24
Source File: HelloAnimation.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.LightGray);
    initKeys();
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
    rootNode.addLight(dl);
    player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    player.setLocalScale(0.5f);
    rootNode.attachChild(player);
    control = player.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim("stand");
}
 
Example #25
Source File: HelloAnimation.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
    if (animName.equals("Walk")) {
        channel.setAnim("stand", 0.50f);
        channel.setLoopMode(LoopMode.DontLoop);
        channel.setSpeed(1f);
    }
}
 
Example #26
Source File: TestRagdollCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

        if (channel.getAnimationName().equals("SliceHorizontal")) {
            channel.setLoopMode(LoopMode.DontLoop);
            channel.setAnim("IdleTop", 5);
            channel.setLoopMode(LoopMode.Loop);
        }

    }
 
Example #27
Source File: KinematicRagdollControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Smoothly blend from Ragdoll mode to Kinematic mode
 * This is useful to blend ragdoll actual position to a keyframe animation for example
 * @param blendTime the blending time between ragdoll to anim.
 */
public void blendToKinematicMode(float blendTime) {
    if (mode == Mode.Kinetmatic) {
        return;
    }
    blendedControl = true;
    this.blendTime = blendTime;
    mode = Mode.Kinetmatic;
    AnimControl animControl = targetModel.getControl(AnimControl.class);
    animControl.setEnabled(true);


    TempVars vars = TempVars.get();        
    for (PhysicsBoneLink link : boneLinks.values()) {

        Vector3f p = link.rigidBody.getMotionState().getWorldLocation();
        Vector3f position = vars.vect1;

        targetModel.getWorldTransform().transformInverseVector(p, position);

        Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
        Quaternion q2 = vars.quat1;
        Quaternion q3 = vars.quat2;

        q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal();
        q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
        q2.normalizeLocal();
        link.startBlendingPos.set(position);
        link.startBlendingRot.set(q2);
        link.rigidBody.setKinematic(true);
    }
    vars.release();

    for (Bone bone : skeleton.getRoots()) {
        RagdollUtils.setUserControl(bone, false);
    }

    blendStart = 0;
}
 
Example #28
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 #29
Source File: TestRagdollCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
        setupKeys();

        bulletAppState = new BulletAppState();
        bulletAppState.setEnabled(true);
        stateManager.attach(bulletAppState);


//        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
        PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
        initWall(2,1,1);
        setupLight();

        cam.setLocation(new Vector3f(-8,0,-4));
        cam.lookAt(new Vector3f(4,0,-7), Vector3f.UNIT_Y);

        model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
        model.lookAt(new Vector3f(0,0,-1), Vector3f.UNIT_Y);
        model.setLocalTranslation(4, 0, -7f);

        ragdoll = new KinematicRagdollControl(0.5f);
        model.addControl(ragdoll);

        getPhysicsSpace().add(ragdoll);
        speed = 1.3f;

        rootNode.attachChild(model);


        AnimControl control = model.getControl(AnimControl.class);
        animChannel = control.createChannel();
        animChannel.setAnim("IdleTop");
        control.addListener(this);

    }
 
Example #30
Source File: ModelPerformer.java    From OpenRTS with MIT License 5 votes vote down vote up
private Point3D getBoneWorldPos(ModelActor actor, Point3D actorPos, double actorYaw, String boneName) {
	Spatial s = actor.getViewElements().spatial;
	Vector3f modelSpacePos = s.getControl(AnimControl.class).getSkeleton().getBone(boneName).getModelSpacePosition();
	Quaternion q = actor.getViewElements().spatial.getLocalRotation();
	modelSpacePos = q.mult(modelSpacePos);
	modelSpacePos.multLocal(s.getLocalScale());
	modelSpacePos = modelSpacePos.add(s.getLocalTranslation());
	// float scale
	// Point2D p2D = Translator.toPoint2D(modelSpacePos);
	// p2D = p2D.getRotation(actorYaw+Angle.RIGHT);
	// Point3D p3D = new Point3D(p2D.getMult(DEFAULT_SCALE), modelSpacePos.z*DEFAULT_SCALE, 1);
	// p3D = p3D.getAddition(actorPos);
	// return p3D;
	return TranslateUtil.toPoint3D(modelSpacePos);
}