Search in sources :

Example 76 with Sphere

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

the class TestLodStress method simpleInitApp.

public void simpleInitApp() {
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
    Geometry teapot = (Geometry) teapotNode.getChild(0);
    //        Sphere sph = new Sphere(16, 16, 4);
    //        Geometry teapot = new Geometry("teapot", sph);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 16f);
    mat.setBoolean("VertexLighting", true);
    teapot.setMaterial(mat);
    for (int y = -10; y < 10; y++) {
        for (int x = -10; x < 10; x++) {
            Geometry clonePot = teapot.clone();
            //clonePot.setMaterial(mat);
            clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
            clonePot.setLocalScale(.15f);
            LodControl control = new LodControl();
            clonePot.addControl(control);
            rootNode.attachChild(clonePot);
        }
    }
    cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
    cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
}
Also used : Geometry(com.jme3.scene.Geometry) LodControl(com.jme3.scene.control.LodControl) Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 77 with Sphere

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

the class TestSceneWater method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    Node mainScene = new Node();
    cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
    cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));
    // load sky
    mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    File file = new File("wildhouse.zip");
    if (file.exists()) {
        useHttp = false;
    }
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");
    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    //add lightPos Geometry
    Sphere lite = new Sphere(8, 8, 3.0f);
    Geometry lightSphere = new Geometry("lightsphere", lite);
    lightSphere.setMaterial(mat);
    Vector3f lightPos = lightDir.multLocal(-400);
    lightSphere.setLocalTranslation(lightPos);
    rootNode.attachChild(lightSphere);
    SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager);
    waterProcessor.setReflectionScene(mainScene);
    waterProcessor.setDebug(false);
    waterProcessor.setLightPosition(lightPos);
    waterProcessor.setRefractionClippingOffset(1.0f);
    //setting the water plane
    Vector3f waterLocation = new Vector3f(0, -20, 0);
    waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y)));
    WaterUI waterUi = new WaterUI(inputManager, waterProcessor);
    waterProcessor.setWaterColor(ColorRGBA.Brown);
    waterProcessor.setDebug(true);
    //lower render size for higher performance
    //        waterProcessor.setRenderSize(128,128);
    //raise depth to see through water
    //        waterProcessor.setWaterDepth(20);
    //lower the distortion scale if the waves appear too strong
    //        waterProcessor.setDistortionScale(0.1f);
    //lower the speed of the waves if they are too fast
    //        waterProcessor.setWaveSpeed(0.01f);
    Quad quad = new Quad(400, 400);
    //the texture coordinates define the general size of the waves
    quad.scaleTextureCoordinates(new Vector2f(6f, 6f));
    Geometry water = new Geometry("water", quad);
    water.setShadowMode(ShadowMode.Receive);
    water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    water.setMaterial(waterProcessor.getMaterial());
    water.setLocalTranslation(-200, -20, 250);
    rootNode.attachChild(water);
    viewPort.addProcessor(waterProcessor);
    mainScene.attachChild(scene);
    rootNode.attachChild(mainScene);
}
Also used : Quad(com.jme3.scene.shape.Quad) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) SimpleWaterProcessor(com.jme3.water.SimpleWaterProcessor) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) File(java.io.File)

Example 78 with Sphere

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

the class TestSimpleWater method initScene.

private void initScene() {
    //init cam location
    cam.setLocation(new Vector3f(0, 10, 10));
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
    //init scene
    sceneNode = new Node("Scene");
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    geom.setMaterial(mat);
    sceneNode.attachChild(geom);
    // load sky
    sceneNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    rootNode.attachChild(sceneNode);
    //add lightPos Geometry
    Sphere lite = new Sphere(8, 8, 3.0f);
    lightSphere = new Geometry("lightsphere", lite);
    lightSphere.setMaterial(mat);
    lightSphere.setLocalTranslation(lightPos);
    rootNode.attachChild(lightSphere);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Example 79 with Sphere

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

the class TerrainTestCollision method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
    setupKeys();
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
    matRock.setTexture("Alpha", 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("Tex1", grass);
    matRock.setFloat("Tex1Scale", 64f);
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex2", dirt);
    matRock.setFloat("Tex2Scale", 32f);
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("Tex3", rock);
    matRock.setFloat("Tex3Scale", 128f);
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
        heightmap.load();
    } catch (Exception e) {
    }
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
    // patch size, and a multiplier
    control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(2, 2, 2));
    // unlock it so we can edit the height
    terrain.setLocked(false);
    rootNode.attachChild(terrain);
    /**
         * Create PhysicsRigidBodyControl for collision
         */
    terrain.addControl(new RigidBodyControl(0));
    bulletAppState.getPhysicsSpace().addAll(terrain);
    // let them drop from the sky
    for (int i = 0; i < 5; i++) {
        float r = (float) (8 * Math.random());
        Geometry sphere = new Geometry("cannonball", new Sphere(10, 10, r));
        sphere.setMaterial(matWire);
        // random position
        float x = (float) (20 * Math.random()) - 40;
        // random position
        float y = (float) (20 * Math.random()) - 40;
        // random position
        float z = (float) (20 * Math.random()) - 40;
        sphere.setLocalTranslation(new Vector3f(x, 100 + y, z));
        sphere.addControl(new RigidBodyControl(new SphereCollisionShape(r), 2));
        rootNode.attachChild(sphere);
        bulletAppState.getPhysicsSpace().add(sphere);
    }
    collisionBox = new Geometry("collisionBox", new Box(2, 2, 2));
    collisionBox.setModelBound(new BoundingBox());
    collisionBox.setLocalTranslation(new Vector3f(20, 95, 30));
    collisionBox.setMaterial(matWire);
    rootNode.attachChild(collisionBox);
    selectedCollisionObject = collisionBox;
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
    rootNode.addLight(dl);
    cam.setLocation(new Vector3f(0, 25, -10));
    cam.lookAtDirection(new Vector3f(0, -1, 0).normalizeLocal(), Vector3f.UNIT_Y);
}
Also used : SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Material(com.jme3.material.Material) BoundingBox(com.jme3.bounding.BoundingBox) Box(com.jme3.scene.shape.Box) Texture(com.jme3.texture.Texture) DistanceLodCalculator(com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) ColorRGBA(com.jme3.math.ColorRGBA) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) DirectionalLight(com.jme3.light.DirectionalLight) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad)

Example 80 with Sphere

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

the class UVProjectionGenerator method sphereProjection.

/**
     * Sphere projection for 2D textures.
     * 
     * @param positions
     *            points to be projected
     * @param bb
     *            the bounding box for projecting
     * @return UV coordinates after the projection
     */
public static float[] sphereProjection(float[] positions, BoundingSphere bs) {
    // TODO: rotate it to be vertical
    float[] uvCoordinates = new float[positions.length / 3 * 2];
    Vector3f v = new Vector3f();
    float cx = bs.getCenter().x, cy = bs.getCenter().y, cz = bs.getCenter().z;
    Vector3f uBase = new Vector3f(0, -1, 0);
    Vector3f vBase = new Vector3f(0, 0, -1);
    for (int i = 0, j = 0; i < positions.length; i += 3, j += 2) {
        // calculating U
        v.set(positions[i] - cx, positions[i + 1] - cy, 0);
        v.normalizeLocal();
        // result between [0; PI]
        float angle = v.angleBetween(uBase);
        if (v.x < 0) {
            // the angle should be greater than PI, we're on the other part of the image then
            angle = FastMath.TWO_PI - angle;
        }
        uvCoordinates[j] = angle / FastMath.TWO_PI;
        // calculating V
        v.set(positions[i] - cx, positions[i + 1] - cy, positions[i + 2] - cz);
        v.normalizeLocal();
        // result between [0; PI]
        angle = v.angleBetween(vBase);
        uvCoordinates[j + 1] = angle / FastMath.PI;
    }
    // looking for splitted triangles
    Triangle triangle = new Triangle();
    for (int i = 0; i < positions.length; i += 9) {
        triangle.set(0, positions[i], positions[i + 1], positions[i + 2]);
        triangle.set(1, positions[i + 3], positions[i + 4], positions[i + 5]);
        triangle.set(2, positions[i + 6], positions[i + 7], positions[i + 8]);
        float sgn1 = Math.signum(triangle.get1().x - cx);
        float sgn2 = Math.signum(triangle.get2().x - cx);
        float sgn3 = Math.signum(triangle.get3().x - cx);
        float xSideFactor = sgn1 + sgn2 + sgn3;
        float ySideFactor = Math.signum(triangle.get1().y - cy) + Math.signum(triangle.get2().y - cy) + Math.signum(triangle.get3().y - cy);
        if ((xSideFactor > -3 || xSideFactor < 3) && ySideFactor < 0) {
            // the triangle is on the splitting plane
            if (sgn1 == 1.0f) {
                uvCoordinates[i / 3 * 2] += 1.0f;
            }
            if (sgn2 == 1.0f) {
                uvCoordinates[(i / 3 + 1) * 2] += 1.0f;
            }
            if (sgn3 == 1.0f) {
                uvCoordinates[(i / 3 + 2) * 2] += 1.0f;
            }
        }
    }
    return uvCoordinates;
}
Also used : Vector3f(com.jme3.math.Vector3f) Triangle(com.jme3.math.Triangle)

Aggregations

Sphere (com.jme3.scene.shape.Sphere)63 Geometry (com.jme3.scene.Geometry)58 Vector3f (com.jme3.math.Vector3f)57 Material (com.jme3.material.Material)46 DirectionalLight (com.jme3.light.DirectionalLight)23 Box (com.jme3.scene.shape.Box)22 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)17 Node (com.jme3.scene.Node)17 PointLight (com.jme3.light.PointLight)15 BulletAppState (com.jme3.bullet.BulletAppState)13 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)13 BoundingSphere (com.jme3.bounding.BoundingSphere)12 AmbientLight (com.jme3.light.AmbientLight)12 Quaternion (com.jme3.math.Quaternion)11 ColorRGBA (com.jme3.math.ColorRGBA)10 Spatial (com.jme3.scene.Spatial)9 TempVars (com.jme3.util.TempVars)9 KeyTrigger (com.jme3.input.controls.KeyTrigger)8 Vector2f (com.jme3.math.Vector2f)8 MeshCollisionShape (com.jme3.bullet.collision.shapes.MeshCollisionShape)7