use of com.jme3.animation.SkeletonControl in project jmonkeyengine by jMonkeyEngine.
the class TestHWSkinning method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(10f);
cam.setLocation(new Vector3f(3.8664846f, 6.2704787f, 9.664585f));
cam.setRotation(new Quaternion(-0.054774776f, 0.94064945f, -0.27974048f, -0.18418397f));
makeHudText();
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);
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
model.setLocalScale(0.1f);
model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
control = model.getControl(AnimControl.class);
channel = control.createChannel();
channel.setAnim(animNames[(i + j) % 4]);
SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
skControls.add(skeletonControl);
rootNode.attachChild(model);
}
}
inputManager.addListener(this, "toggleHWS");
inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
}
use of com.jme3.animation.SkeletonControl in project jmonkeyengine by jMonkeyEngine.
the class TestOgreAnim method simpleInitApp.
@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");
geom = (Geometry) ((Node) model).getChild(0);
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));
}
use of com.jme3.animation.SkeletonControl in project jmonkeyengine by jMonkeyEngine.
the class TestSkeletonControlRefresh method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.White);
flyCam.setMoveSpeed(10f);
cam.setLocation(new Vector3f(3.8664846f, 6.2704787f, 9.664585f));
cam.setRotation(new Quaternion(-0.054774776f, 0.94064945f, -0.27974048f, -0.18418397f));
makeHudText();
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);
Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey k = new TextureKey("Models/Oto/Oto.jpg", false);
m.setTexture("ColorMap", assetManager.loadTexture(k));
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
//setting a different material
model.setMaterial(m.clone());
model.setLocalScale(0.1f);
model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
control = model.getControl(AnimControl.class);
channel = control.createChannel();
channel.setAnim(animNames[(i + j) % 4]);
channel.setLoopMode(LoopMode.DontLoop);
SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
//This is a workaround the issue. this call will make the SkeletonControl gather the targets again.
//skeletonControl.setSpatial(model);
skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
skControls.add(skeletonControl);
rootNode.attachChild(model);
}
}
rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
setupFloor();
inputManager.addListener(this, "toggleHWS");
inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
// DirectionalLightShadowRenderer pssm = new DirectionalLightShadowRenderer(assetManager, 1024, 2);
// pssm.setLight(dl);
// viewPort.addProcessor(pssm);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
DirectionalLightShadowFilter sf = new DirectionalLightShadowFilter(assetManager, 1024, 2);
sf.setLight(dl);
fpp.addFilter(sf);
fpp.addFilter(new SSAOFilter());
viewPort.addProcessor(fpp);
}
use of com.jme3.animation.SkeletonControl in project jmonkeyengine by jMonkeyEngine.
the class TestLodGeneration method simpleInitApp.
public void simpleInitApp() {
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.6f));
rootNode.addLight(al);
// model = (Node) assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
BoundingBox b = ((BoundingBox) model.getWorldBound());
model.setLocalScale(1.2f / (b.getYExtent() * 2));
// model.setLocalTranslation(0,-(b.getCenter().y - b.getYExtent())* model.getLocalScale().y, 0);
for (Spatial spatial : model.getChildren()) {
if (spatial instanceof Geometry) {
listGeoms.add((Geometry) spatial);
}
}
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
model.addControl(chaseCam);
chaseCam.setLookAtOffset(b.getCenter());
chaseCam.setDefaultDistance(5);
chaseCam.setMinVerticalRotation(-FastMath.HALF_PI + 0.01f);
chaseCam.setZoomSensitivity(0.5f);
// ch = model.getControl(AnimControl.class).createChannel();
// ch.setAnim("Wave");
SkeletonControl c = model.getControl(SkeletonControl.class);
if (c != null) {
c.setEnabled(false);
}
reductionvalue = 0.80f;
lodLevel = 1;
for (final Geometry geometry : listGeoms) {
LodGenerator lodGenerator = new LodGenerator(geometry);
lodGenerator.bakeLods(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue);
geometry.setLodLevel(lodLevel);
}
rootNode.attachChild(model);
flyCam.setEnabled(false);
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
hudText = new BitmapText(guiFont, false);
hudText.setSize(guiFont.getCharSet().getRenderedSize());
hudText.setText(computeNbTri() + " tris");
hudText.setLocalTranslation(cam.getWidth() / 2, hudText.getLineHeight(), 0);
guiNode.attachChild(hudText);
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed) {
if (name.equals("plus")) {
// lodLevel++;
// for (Geometry geometry : listGeoms) {
// if (geometry.getMesh().getNumLodLevels() <= lodLevel) {
// lodLevel = 0;
// }
// geometry.setLodLevel(lodLevel);
// }
// jaimeText.setText(computeNbTri() + " tris");
reductionvalue += 0.05f;
updateLod();
}
if (name.equals("minus")) {
// lodLevel--;
// for (Geometry geometry : listGeoms) {
// if (lodLevel < 0) {
// lodLevel = geometry.getMesh().getNumLodLevels() - 1;
// }
// geometry.setLodLevel(lodLevel);
// }
// jaimeText.setText(computeNbTri() + " tris");
reductionvalue -= 0.05f;
updateLod();
}
if (name.equals("wireFrame")) {
wireFrame = !wireFrame;
for (Geometry geometry : listGeoms) {
geometry.getMaterial().getAdditionalRenderState().setWireframe(wireFrame);
}
}
}
}
private void updateLod() {
reductionvalue = FastMath.clamp(reductionvalue, 0.0f, 1.0f);
makeLod(LodGenerator.TriangleReductionMethod.PROPORTIONAL, reductionvalue, 1);
}
}, "plus", "minus", "wireFrame");
inputManager.addMapping("plus", new KeyTrigger(KeyInput.KEY_ADD));
inputManager.addMapping("minus", new KeyTrigger(KeyInput.KEY_SUBTRACT));
inputManager.addMapping("wireFrame", new KeyTrigger(KeyInput.KEY_SPACE));
}
use of com.jme3.animation.SkeletonControl in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method applySkinning.
private void applySkinning() {
for (FbxBindPose pose : bindMap.values()) pose.fillBindTransforms();
if (limbMap == null)
return;
List<Bone> bones = new ArrayList<>();
for (FbxNode limb : limbMap.values()) {
if (limb.bone != null) {
bones.add(limb.bone);
limb.buildBindPoseBoneTransform();
}
}
skeleton = new Skeleton(bones.toArray(new Bone[bones.size()]));
skeleton.setBindingPose();
for (FbxNode limb : limbMap.values()) limb.setSkeleton(skeleton);
for (FbxSkin skin : skinMap.values()) skin.generateSkinning();
// Attach controls
animControl = new AnimControl(skeleton);
sceneNode.addControl(animControl);
SkeletonControl control = new SkeletonControl(skeleton);
sceneNode.addControl(control);
}
Aggregations