Search in sources :

Example 11 with Quad

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

the class BitmapTextPage method assemble.

// Here is where one might add JmeCloneable related stuff except
// the old clone() method doesn't actually bother to clone anything.
// The arrays and the pageQuads are shared across all BitmapTextPage
// clones and it doesn't seem to bother anything.  That means the
// fields could probably just as well be static... but this code is
// all very fragile.  I'm not tipping that particular boat today. -pspeed
void assemble(Letters quads) {
    pageQuads.clear();
    quads.rewind();
    while (quads.nextCharacter()) {
        if (quads.isPrintable()) {
            if (quads.getCharacterSetPage() == page) {
                pageQuads.add(quads.getQuad());
            }
        }
    }
    Mesh m = getMesh();
    int vertCount = pageQuads.size() * 4;
    int triCount = pageQuads.size() * 2;
    VertexBuffer pb = m.getBuffer(Type.Position);
    VertexBuffer tb = m.getBuffer(Type.TexCoord);
    VertexBuffer ib = m.getBuffer(Type.Index);
    VertexBuffer cb = m.getBuffer(Type.Color);
    FloatBuffer fpb = (FloatBuffer) pb.getData();
    FloatBuffer ftb = (FloatBuffer) tb.getData();
    ShortBuffer sib = (ShortBuffer) ib.getData();
    ByteBuffer bcb = (ByteBuffer) cb.getData();
    // increase capacity of buffers as needed
    fpb.rewind();
    fpb = BufferUtils.ensureLargeEnough(fpb, vertCount * 3);
    fpb.limit(vertCount * 3);
    pb.updateData(fpb);
    ftb.rewind();
    ftb = BufferUtils.ensureLargeEnough(ftb, vertCount * 2);
    ftb.limit(vertCount * 2);
    tb.updateData(ftb);
    bcb.rewind();
    bcb = BufferUtils.ensureLargeEnough(bcb, vertCount * 4);
    bcb.limit(vertCount * 4);
    cb.updateData(bcb);
    sib.rewind();
    sib = BufferUtils.ensureLargeEnough(sib, triCount * 3);
    sib.limit(triCount * 3);
    ib.updateData(sib);
    m.updateCounts();
    // go for each quad and append it to the buffers
    if (pos != null) {
        for (int i = 0; i < pageQuads.size(); i++) {
            LetterQuad fq = pageQuads.get(i);
            fq.storeToArrays(pos, tc, idx, color, i);
            fpb.put(pos);
            ftb.put(tc);
            sib.put(idx);
            bcb.put(color);
        }
    } else {
        for (int i = 0; i < pageQuads.size(); i++) {
            LetterQuad fq = pageQuads.get(i);
            fq.appendPositions(fpb);
            fq.appendTexCoords(ftb);
            fq.appendIndices(sib, i);
            fq.appendColors(bcb);
        }
    }
    fpb.rewind();
    ftb.rewind();
    sib.rewind();
    bcb.rewind();
    updateModelBound();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) Mesh(com.jme3.scene.Mesh) FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 12 with Quad

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

the class TestUrlLoading method simpleInitApp.

@Override
public void simpleInitApp() {
    // create a simple plane/quad
    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1, true);
    Geometry quad = new Geometry("Textured Quad", quadMesh);
    assetManager.registerLocator("https://raw.githubusercontent.com/jMonkeyEngine/BookSamples/master/assets/Textures/", UrlLocator.class);
    TextureKey key = new TextureKey("mucha-window.png", false);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);
    quad.setMaterial(mat);
    float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight();
    quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1));
    quad.center();
    rootNode.attachChild(quad);
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) TextureKey(com.jme3.asset.TextureKey) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 13 with Quad

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

the class SimpleWaterProcessor method createWaterGeometry.

/**
     * Creates a quad with the water material applied to it.
     * @param width
     * @param height
     * @return
     */
public Geometry createWaterGeometry(float width, float height) {
    Quad quad = new Quad(width, height);
    Geometry geom = new Geometry("WaterGeometry", quad);
    geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    geom.setMaterial(material);
    return geom;
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad)

Example 14 with Quad

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

the class TestColoredTexture method simpleInitApp.

@Override
public void simpleInitApp() {
    Quad quadMesh = new Quad(512, 512);
    Geometry quad = new Geometry("Quad", quadMesh);
    quad.setQueueBucket(Bucket.Gui);
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
    quad.setMaterial(mat);
    guiNode.attachChildAt(quad, 0);
    nextColor = ColorRGBA.randomColor();
    prevColor = ColorRGBA.Black;
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Material(com.jme3.material.Material)

Example 15 with Quad

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

the class TestCameraNode method simpleInitApp.

public void simpleInitApp() {
    // load a teapot model 
    teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat);
    //create a node to attach the geometry and the camera node
    teaNode = new Node("teaNode");
    teaNode.attachChild(teaGeom);
    rootNode.attachChild(teaNode);
    // create a floor
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Geometry ground = new Geometry("ground", new Quad(50, 50));
    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    ground.setLocalTranslation(-25, -1, 25);
    ground.setMaterial(mat);
    rootNode.attachChild(ground);
    //creating the camera Node
    camNode = new CameraNode("CamNode", cam);
    //Setting the direction to Spatial to camera, this means the camera will copy the movements of the Node
    camNode.setControlDir(ControlDirection.SpatialToCamera);
    //attaching the camNode to the teaNode
    teaNode.attachChild(camNode);
    //setting the local translation of the cam node to move it away from the teanNode a bit
    camNode.setLocalTranslation(new Vector3f(-10, 0, 0));
    //setting the camNode to look at the teaNode
    camNode.lookAt(teaNode.getLocalTranslation(), Vector3f.UNIT_Y);
    //disable the default 1st-person flyCam (don't forget this!!)
    flyCam.setEnabled(false);
    registerInput();
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) CameraNode(com.jme3.scene.CameraNode) CameraNode(com.jme3.scene.CameraNode) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material)

Aggregations

Geometry (com.jme3.scene.Geometry)36 Quad (com.jme3.scene.shape.Quad)35 Material (com.jme3.material.Material)30 Vector3f (com.jme3.math.Vector3f)23 Node (com.jme3.scene.Node)11 Spatial (com.jme3.scene.Spatial)10 DirectionalLight (com.jme3.light.DirectionalLight)9 Quaternion (com.jme3.math.Quaternion)9 Texture (com.jme3.texture.Texture)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)7 ColorRGBA (com.jme3.math.ColorRGBA)6 Vector2f (com.jme3.math.Vector2f)6 AmbientLight (com.jme3.light.AmbientLight)5 Mesh (com.jme3.scene.Mesh)5 Texture2D (com.jme3.texture.Texture2D)5 Picture (com.jme3.ui.Picture)5 File (java.io.File)5 ScreenshotAppState (com.jme3.app.state.ScreenshotAppState)4 BulletAppState (com.jme3.bullet.BulletAppState)4 CapsuleCollisionShape (com.jme3.bullet.collision.shapes.CapsuleCollisionShape)4