Search in sources :

Example 6 with Control

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

the class TestOgreComplexAnim 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);
    Node model = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    control = model.getControl(AnimControl.class);
    AnimChannel feet = control.createChannel();
    AnimChannel leftHand = control.createChannel();
    AnimChannel rightHand = control.createChannel();
    // feet will dodge
    feet.addFromRootBone("hip.right");
    feet.addFromRootBone("hip.left");
    feet.setAnim("Dodge");
    feet.setSpeed(2);
    feet.setLoopMode(LoopMode.Cycle);
    // will blend over 15 seconds to stand
    feet.setAnim("Walk", 15);
    feet.setSpeed(0.25f);
    feet.setLoopMode(LoopMode.Cycle);
    // left hand will pull
    leftHand.addFromRootBone("uparm.right");
    leftHand.setAnim("pull");
    leftHand.setSpeed(.5f);
    // will blend over 15 seconds to stand
    leftHand.setAnim("stand", 15);
    // right hand will push
    rightHand.addBone("spinehigh");
    rightHand.addFromRootBone("uparm.left");
    rightHand.setAnim("push");
    SkeletonDebugger skeletonDebug = new SkeletonDebugger("skeleton", control.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);
    model.attachChild(skeletonDebug);
    rootNode.attachChild(model);
}
Also used : SkeletonDebugger(com.jme3.scene.debug.SkeletonDebugger) ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) AnimChannel(com.jme3.animation.AnimChannel) Material(com.jme3.material.Material) AnimControl(com.jme3.animation.AnimControl)

Example 7 with Control

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

the class TestBillboard method simpleInitApp.

public void simpleInitApp() {
    flyCam.setMoveSpeed(10);
    Quad q = new Quad(2, 2);
    Geometry g = new Geometry("Quad", q);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    g.setMaterial(mat);
    Quad q2 = new Quad(1, 1);
    Geometry g3 = new Geometry("Quad2", q2);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.Yellow);
    g3.setMaterial(mat2);
    g3.setLocalTranslation(.5f, .5f, .01f);
    Box b = new Box(.25f, .5f, .25f);
    Geometry g2 = new Geometry("Box", b);
    g2.setLocalTranslation(0, 0, 3);
    g2.setMaterial(mat);
    Node bb = new Node("billboard");
    BillboardControl control = new BillboardControl();
    bb.addControl(control);
    bb.attachChild(g);
    bb.attachChild(g3);
    n = new Node("parent");
    n.attachChild(g2);
    n.attachChild(bb);
    rootNode.attachChild(n);
    n2 = new Node("parentParent");
    n2.setLocalTranslation(Vector3f.UNIT_X.mult(5));
    n2.attachChild(n);
    rootNode.attachChild(n2);
//        rootNode.attachChild(bb);
//        rootNode.attachChild(g2);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) BillboardControl(com.jme3.scene.control.BillboardControl) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Example 8 with Control

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

the class TestCustomAnim method simpleInitApp.

@Override
public void simpleInitApp() {
    AmbientLight al = new AmbientLight();
    rootNode.addLight(al);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);
    Box box = new Box(1, 1, 1);
    VertexBuffer weightsHW = new VertexBuffer(Type.HWBoneWeight);
    VertexBuffer indicesHW = new VertexBuffer(Type.HWBoneIndex);
    indicesHW.setUsage(Usage.CpuOnly);
    weightsHW.setUsage(Usage.CpuOnly);
    box.setBuffer(weightsHW);
    box.setBuffer(indicesHW);
    // Setup bone weight buffer
    FloatBuffer weights = FloatBuffer.allocate(box.getVertexCount() * 4);
    VertexBuffer weightsBuf = new VertexBuffer(Type.BoneWeight);
    weightsBuf.setupData(Usage.CpuOnly, 4, Format.Float, weights);
    box.setBuffer(weightsBuf);
    // Setup bone index buffer
    ByteBuffer indices = ByteBuffer.allocate(box.getVertexCount() * 4);
    VertexBuffer indicesBuf = new VertexBuffer(Type.BoneIndex);
    indicesBuf.setupData(Usage.CpuOnly, 4, Format.UnsignedByte, indices);
    box.setBuffer(indicesBuf);
    // Create bind pose buffers
    box.generateBindPose(true);
    // Create skeleton
    bone = new Bone("root");
    bone.setBindTransforms(Vector3f.ZERO, Quaternion.IDENTITY, Vector3f.UNIT_XYZ);
    bone.setUserControl(true);
    skeleton = new Skeleton(new Bone[] { bone });
    // Assign all verticies to bone 0 with weight 1
    for (int i = 0; i < box.getVertexCount() * 4; i += 4) {
        // assign vertex to bone index 0
        indices.array()[i + 0] = 0;
        indices.array()[i + 1] = 0;
        indices.array()[i + 2] = 0;
        indices.array()[i + 3] = 0;
        // set weight to 1 only for first entry
        weights.array()[i + 0] = 1;
        weights.array()[i + 1] = 0;
        weights.array()[i + 2] = 0;
        weights.array()[i + 3] = 0;
    }
    // Maximum number of weights per bone is 1
    box.setMaxNumWeights(1);
    // Create model
    Geometry geom = new Geometry("box", box);
    geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
    Node model = new Node("model");
    model.attachChild(geom);
    // Create skeleton control
    SkeletonControl skeletonControl = new SkeletonControl(skeleton);
    model.addControl(skeletonControl);
    rootNode.attachChild(model);
}
Also used : Geometry(com.jme3.scene.Geometry) VertexBuffer(com.jme3.scene.VertexBuffer) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) SkeletonControl(com.jme3.animation.SkeletonControl) Box(com.jme3.scene.shape.Box) FloatBuffer(java.nio.FloatBuffer) Skeleton(com.jme3.animation.Skeleton) Bone(com.jme3.animation.Bone) ByteBuffer(java.nio.ByteBuffer) AmbientLight(com.jme3.light.AmbientLight)

Example 9 with Control

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

the class TestHoverTank method simpleInitApp.

@Override
public void simpleInitApp() {
    Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    flyCam.setEnabled(false);
    ChaseCamera chaseCam = new ChaseCamera(cam, tank, inputManager);
    chaseCam.setSmoothMotion(true);
    chaseCam.setMaxDistance(100000);
    chaseCam.setMinVerticalRotation(-FastMath.PI / 2);
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    Geometry tankGeom = (Geometry) tank.getChild(0);
    LodControl control = new LodControl();
    tankGeom.addControl(control);
    rootNode.attachChild(tank);
    Vector3f lightDir = new Vector3f(-0.8719428f, -0.46824604f, 0.14304268f);
    DirectionalLight dl = new DirectionalLight();
    dl.setColor(new ColorRGBA(1.0f, 0.92f, 0.75f, 1f));
    dl.setDirection(lightDir);
    Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
    DirectionalLight dl2 = new DirectionalLight();
    dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
    dl2.setDirection(lightDir2);
    rootNode.addLight(dl);
    rootNode.addLight(dl2);
    rootNode.attachChild(tank);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
    bf.setBloomIntensity(2.0f);
    bf.setExposurePower(1.3f);
    fpp.addFilter(bf);
    BloomUI bui = new BloomUI(inputManager, bf);
    viewPort.addProcessor(fpp);
}
Also used : Geometry(com.jme3.scene.Geometry) BloomUI(jme3test.post.BloomUI) LodControl(com.jme3.scene.control.LodControl) ColorRGBA(com.jme3.math.ColorRGBA) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 10 with Control

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

the class Curve method createBezierMesh.

/**
     * This method creates the Bezier path for this curve.
     *
     * @param nbSubSegments amount of subsegments between position control
     * points
     */
private void createBezierMesh(int nbSubSegments) {
    if (nbSubSegments == 0) {
        nbSubSegments = 1;
    }
    int centerPointsAmount = (spline.getControlPoints().size() + 2) / 3;
    //calculating vertices
    float[] array = new float[((centerPointsAmount - 1) * nbSubSegments + 1) * 3];
    int currentControlPoint = 0;
    List<Vector3f> controlPoints = spline.getControlPoints();
    int lineIndex = 0;
    for (int i = 0; i < centerPointsAmount - 1; ++i) {
        Vector3f vector3f = controlPoints.get(currentControlPoint);
        array[lineIndex++] = vector3f.x;
        array[lineIndex++] = vector3f.y;
        array[lineIndex++] = vector3f.z;
        for (int j = 1; j < nbSubSegments; ++j) {
            spline.interpolate((float) j / nbSubSegments, currentControlPoint, temp);
            array[lineIndex++] = temp.getX();
            array[lineIndex++] = temp.getY();
            array[lineIndex++] = temp.getZ();
        }
        currentControlPoint += 3;
    }
    Vector3f vector3f = controlPoints.get(currentControlPoint);
    array[lineIndex++] = vector3f.x;
    array[lineIndex++] = vector3f.y;
    array[lineIndex++] = vector3f.z;
    //calculating indexes
    int i = 0, k;
    short[] indices = new short[(centerPointsAmount - 1) * nbSubSegments << 1];
    for (int j = 0; j < (centerPointsAmount - 1) * nbSubSegments; ++j) {
        k = j;
        indices[i++] = (short) k;
        ++k;
        indices[i++] = (short) k;
    }
    this.setMode(Mesh.Mode.Lines);
    this.setBuffer(VertexBuffer.Type.Position, 3, array);
    this.setBuffer(VertexBuffer.Type.Index, 2, indices);
    this.updateBound();
    this.updateCounts();
}
Also used : Vector3f(com.jme3.math.Vector3f)

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