Search in sources :

Example 61 with Node

use of com.jme3.scene.Node 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 62 with Node

use of com.jme3.scene.Node 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 63 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class TestWalkingChar method collision.

public void collision(PhysicsCollisionEvent event) {
    if (event.getObjectA() instanceof BombControl) {
        final Spatial node = event.getNodeA();
        effect.killAllParticles();
        effect.setLocalTranslation(node.getLocalTranslation());
        effect.emitAllParticles();
    } else if (event.getObjectB() instanceof BombControl) {
        final Spatial node = event.getNodeB();
        effect.killAllParticles();
        effect.setLocalTranslation(node.getLocalTranslation());
        effect.emitAllParticles();
    }
}
Also used : Spatial(com.jme3.scene.Spatial)

Example 64 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method link.

@Override
public void link(FbxObject otherObject) {
    if (otherObject instanceof FbxMaterial) {
        FbxMaterial m = (FbxMaterial) otherObject;
        Material mat = m.material;
        if (cullMode != FaceCullMode.Back)
            mat.getAdditionalRenderState().setFaceCullMode(cullMode);
        for (Geometry g : mesh.geometries) {
            if (g.getUserData("FBXMaterial") != null) {
                if ((Integer) g.getUserData("FBXMaterial") == mesh.lastMaterialId)
                    g.setMaterial(mat);
            } else {
                g.setMaterial(mat);
            }
        }
        mesh.lastMaterialId++;
    } else if (otherObject instanceof FbxNode) {
        FbxNode n = (FbxNode) otherObject;
        node.attachChild(n.node);
        n.parentFbxNode = this;
        if (isLimb() && n.isLimb()) {
            if (bone == null)
                bone = new Bone(name);
            if (n.bone == null)
                n.bone = new Bone(n.name);
            bone.addChild(n.bone);
        }
    } else if (otherObject instanceof FbxMesh) {
        FbxMesh m = (FbxMesh) otherObject;
        m.setParent(node);
        m.parent = this;
        mesh = m;
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material) Bone(com.jme3.animation.Bone)

Example 65 with Node

use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.

the class FbxNode method fromElement.

@Override
public void fromElement(FbxElement element) {
    super.fromElement(element);
    Vector3f localTranslation = new Vector3f();
    Quaternion localRotation = new Quaternion();
    Vector3f localScale = new Vector3f(Vector3f.UNIT_XYZ);
    Quaternion preRotation = new Quaternion();
    for (FbxElement e2 : element.getFbxProperties()) {
        String propName = (String) e2.properties.get(0);
        String type = (String) e2.properties.get(3);
        if (propName.equals("Lcl Translation")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            //.divideLocal(unitSize);
            localTranslation.set((float) x, (float) y, (float) z);
        } else if (propName.equals("Lcl Rotation")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            localRotation.fromAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD);
        } else if (propName.equals("Lcl Scaling")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            //.multLocal(unitSize);
            localScale.set((float) x, (float) y, (float) z);
        } else if (propName.equals("PreRotation")) {
            double x = (Double) e2.properties.get(4);
            double y = (Double) e2.properties.get(5);
            double z = (Double) e2.properties.get(6);
            preRotation.set(FbxNodeUtil.quatFromBoneAngles((float) x * FastMath.DEG_TO_RAD, (float) y * FastMath.DEG_TO_RAD, (float) z * FastMath.DEG_TO_RAD));
        } else if (propName.equals("InheritType")) {
            int inheritType = (Integer) e2.properties.get(4);
            inheritMode = InheritMode.values()[inheritType];
        } else if (propName.equals("Visibility")) {
            visibility = (Double) e2.properties.get(4);
        } else if (type.contains("U")) {
            String userDataKey = (String) e2.properties.get(0);
            String userDataType = (String) e2.properties.get(1);
            Object userDataValue;
            if (userDataType.equals("KString")) {
                userDataValue = (String) e2.properties.get(4);
            } else if (userDataType.equals("int")) {
                userDataValue = (Integer) e2.properties.get(4);
            } else if (userDataType.equals("double")) {
                // NOTE: jME3 does not support doubles in UserData.
                //       Need to convert to float.
                userDataValue = ((Double) e2.properties.get(4)).floatValue();
            } else if (userDataType.equals("Vector")) {
                float x = ((Double) e2.properties.get(4)).floatValue();
                float y = ((Double) e2.properties.get(5)).floatValue();
                float z = ((Double) e2.properties.get(6)).floatValue();
                userDataValue = new Vector3f(x, y, z);
            } else {
                logger.log(Level.WARNING, "Unsupported user data type: {0}. Ignoring.", userDataType);
                continue;
            }
            userData.put(userDataKey, userDataValue);
        }
    }
    // Create local transform
    // TODO: take into account Maya-style transforms (pre / post rotation ..)
    jmeLocalNodeTransform.setTranslation(localTranslation);
    jmeLocalNodeTransform.setRotation(localRotation);
    jmeLocalNodeTransform.setScale(localScale);
    if (element.getChildById("Vertices") != null) {
        // This is an old-style FBX 6.1
        // Meshes could be embedded inside the node..
        // Inject the mesh into ourselves..
        FbxMesh mesh = new FbxMesh(assetManager, sceneFolderName);
        mesh.fromElement(element);
        connectObject(mesh);
    }
}
Also used : FbxElement(com.jme3.scene.plugins.fbx.file.FbxElement) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) FbxMesh(com.jme3.scene.plugins.fbx.mesh.FbxMesh) FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) CullHint(com.jme3.scene.Spatial.CullHint)

Aggregations

Node (com.jme3.scene.Node)135 Vector3f (com.jme3.math.Vector3f)81 Geometry (com.jme3.scene.Geometry)64 Spatial (com.jme3.scene.Spatial)53 Material (com.jme3.material.Material)51 DirectionalLight (com.jme3.light.DirectionalLight)35 Quaternion (com.jme3.math.Quaternion)32 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)26 Box (com.jme3.scene.shape.Box)24 Sphere (com.jme3.scene.shape.Sphere)19 AmbientLight (com.jme3.light.AmbientLight)17 BulletAppState (com.jme3.bullet.BulletAppState)16 ColorRGBA (com.jme3.math.ColorRGBA)15 AnimControl (com.jme3.animation.AnimControl)14 KeyTrigger (com.jme3.input.controls.KeyTrigger)14 FilterPostProcessor (com.jme3.post.FilterPostProcessor)14 HashMap (java.util.HashMap)14 CameraNode (com.jme3.scene.CameraNode)13 ArrayList (java.util.ArrayList)13 ActionListener (com.jme3.input.controls.ActionListener)12