Search in sources :

Example 16 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestOgreConvert method simpleInitApp.

@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();
    }
}
Also used : BinaryExporter(com.jme3.export.binary.BinaryExporter) BinaryImporter(com.jme3.export.binary.BinaryImporter) Spatial(com.jme3.scene.Spatial) ByteArrayInputStream(java.io.ByteArrayInputStream) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) AnimChannel(com.jme3.animation.AnimChannel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) AnimControl(com.jme3.animation.AnimControl)

Example 17 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestRagdollCharacter method simpleInitApp.

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);
}
Also used : BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) KinematicRagdollControl(com.jme3.bullet.control.KinematicRagdollControl) AnimControl(com.jme3.animation.AnimControl)

Example 18 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestQ3 method simpleInitApp.

public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    flyCam.setMoveSpeed(100);
    setupKeys();
    this.cam.setFrustumFar(2000);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.clone().multLocal(2));
    dl.setDirection(new Vector3f(-1, -1, -1).normalize());
    rootNode.addLight(dl);
    AmbientLight am = new AmbientLight();
    am.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(am);
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("quake3level.zip", ZipLocator.class);
    }
    // create the geometry and attach it
    MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
    OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
    gameLevel = (Node) assetManager.loadAsset(key);
    gameLevel.setLocalScale(0.1f);
    // add a physics control, it will generate a MeshCollisionShape based on the gameLevel
    gameLevel.addControl(new RigidBodyControl(0));
    player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
    player.setJumpSpeed(20);
    player.setFallSpeed(30);
    player.setGravity(30);
    player.setPhysicsLocation(new Vector3f(60, 10, -60));
    rootNode.attachChild(gameLevel);
    getPhysicsSpace().addAll(gameLevel);
    getPhysicsSpace().add(player);
}
Also used : PhysicsCharacter(com.jme3.bullet.objects.PhysicsCharacter) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) BulletAppState(com.jme3.bullet.BulletAppState) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) MaterialList(com.jme3.material.MaterialList) OgreMeshKey(com.jme3.scene.plugins.ogre.OgreMeshKey) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) AmbientLight(com.jme3.light.AmbientLight)

Example 19 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class HelloAnimation method simpleInitApp.

@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");
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) AnimControl(com.jme3.animation.AnimControl)

Example 20 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestWalkingChar method createTerrain.

private void createTerrain() {
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);
    matRock.setBoolean("WardIso", true);
    matRock.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap", grass);
    matRock.setFloat("DiffuseMap_0_scale", 64);
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_1", dirt);
    matRock.setFloat("DiffuseMap_1_scale", 16);
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_2", rock);
    matRock.setFloat("DiffuseMap_2_scale", 128);
    Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMap0.setWrap(WrapMode.Repeat);
    Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMap1.setWrap(WrapMode.Repeat);
    Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMap2.setWrap(WrapMode.Repeat);
    matRock.setTexture("NormalMap", normalMap0);
    matRock.setTexture("NormalMap_1", normalMap2);
    matRock.setTexture("NormalMap_2", normalMap2);
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    List<Camera> cameras = new ArrayList<Camera>();
    cameras.add(getCamera());
    TerrainLodControl control = new TerrainLodControl(terrain, cameras);
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(2, 2, 2));
    terrainPhysicsNode = new RigidBodyControl(CollisionShapeFactory.createMeshShape(terrain), 0);
    terrain.addControl(terrainPhysicsNode);
    rootNode.attachChild(terrain);
    getPhysicsSpace().add(terrainPhysicsNode);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) ChaseCamera(com.jme3.input.ChaseCamera) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Aggregations

Vector3f (com.jme3.math.Vector3f)51 DirectionalLight (com.jme3.light.DirectionalLight)24 Material (com.jme3.material.Material)23 Quaternion (com.jme3.math.Quaternion)21 Node (com.jme3.scene.Node)19 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)18 Texture (com.jme3.texture.Texture)16 AnimControl (com.jme3.animation.AnimControl)15 ColorRGBA (com.jme3.math.ColorRGBA)15 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)15 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)14 Geometry (com.jme3.scene.Geometry)14 Spatial (com.jme3.scene.Spatial)13 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)13 BulletAppState (com.jme3.bullet.BulletAppState)12 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)11 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)11 ArrayList (java.util.ArrayList)10 Box (com.jme3.scene.shape.Box)7 Animation (com.jme3.animation.Animation)5