Search in sources :

Example 41 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestBox method simpleInitApp.

@Override
public void simpleInitApp() {
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 42 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestBloomAlphaThreshold method simpleInitApp.

@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -10));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
    // cam.setFrustumFar(1000);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));
    mat.setColor("GlowColor", ColorRGBA.Green);
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0, 0, 10);
    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(new Vector3f(0, -13, 550), 800, 10, 700));
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);
    Material matBox = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matBox.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
    matBox.setFloat("AlphaDiscardThreshold", 0.5f);
    Geometry box = new Geometry("box", new Box(new Vector3f(-3.5f, 10, -2), 2, 2, 2));
    box.setMaterial(matBox);
    box.setQueueBucket(RenderQueue.Bucket.Translucent);
    // box.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(box);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    BloomFilter bloom = new BloomFilter(GlowMode.Objects);
    bloom.setDownSamplingFactor(2);
    bloom.setBlurScale(1.37f);
    bloom.setExposurePower(3.30f);
    bloom.setExposureCutOff(0.2f);
    bloom.setBloomIntensity(2.45f);
    BloomUI ui = new BloomUI(inputManager, bloom);
    viewPort.addProcessor(fpp);
    fpp.addFilter(bloom);
    initInputs();
}
Also used : Geometry(com.jme3.scene.Geometry) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Example 43 with Box

use of com.jme3.scene.shape.Box 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 44 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestToneMapFilter method createHDRBox.

public Geometry createHDRBox() {
    Box boxMesh = new Box(1, 1, 1);
    Geometry box = new Geometry("Box", boxMesh);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Textures/HdrTest/Memorial.hdr"));
    box.setMaterial(mat);
    return box;
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 45 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method transform.

/**
     * <code>transform</code> modifies the center of the box to reflect the
     * change made via a rotation, translation and scale.
     * 
     * @param trans 
     *            the transform to apply
     * @param store
     *            box to store result in
     */
public BoundingVolume transform(Transform trans, BoundingVolume store) {
    BoundingBox box;
    if (store == null || store.getType() != Type.AABB) {
        box = new BoundingBox();
    } else {
        box = (BoundingBox) store;
    }
    center.mult(trans.getScale(), box.center);
    trans.getRotation().mult(box.center, box.center);
    box.center.addLocal(trans.getTranslation());
    TempVars vars = TempVars.get();
    Matrix3f transMatrix = vars.tempMat3;
    transMatrix.set(trans.getRotation());
    // Make the rotation matrix all positive to get the maximum x/y/z extent
    transMatrix.absoluteLocal();
    Vector3f scale = trans.getScale();
    vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z));
    transMatrix.mult(vars.vect1, vars.vect2);
    // Assign the biggest rotations after scales.
    box.xExtent = FastMath.abs(vars.vect2.getX());
    box.yExtent = FastMath.abs(vars.vect2.getY());
    box.zExtent = FastMath.abs(vars.vect2.getZ());
    vars.release();
    return box;
}
Also used : TempVars(com.jme3.util.TempVars)

Aggregations

Geometry (com.jme3.scene.Geometry)106 Box (com.jme3.scene.shape.Box)99 Material (com.jme3.material.Material)83 Vector3f (com.jme3.math.Vector3f)77 Node (com.jme3.scene.Node)31 DirectionalLight (com.jme3.light.DirectionalLight)27 Sphere (com.jme3.scene.shape.Sphere)23 Quaternion (com.jme3.math.Quaternion)20 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)19 Spatial (com.jme3.scene.Spatial)19 BoundingBox (com.jme3.bounding.BoundingBox)17 Vector2f (com.jme3.math.Vector2f)15 Texture (com.jme3.texture.Texture)15 AmbientLight (com.jme3.light.AmbientLight)13 TempVars (com.jme3.util.TempVars)12 BulletAppState (com.jme3.bullet.BulletAppState)11 KeyTrigger (com.jme3.input.controls.KeyTrigger)11 FilterPostProcessor (com.jme3.post.FilterPostProcessor)11 BoundingSphere (com.jme3.bounding.BoundingSphere)8 BoxCollisionShape (com.jme3.bullet.collision.shapes.BoxCollisionShape)8