Search in sources :

Example 41 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TestBrickWall method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    initMaterial();
    initWall();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 6f, 6f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(15);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
    inputManager.addListener(actionListener, "gc");
    rootNode.setShadowMode(ShadowMode.Off);
    bsr = new BasicShadowRenderer(assetManager, 256);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Vector2f(com.jme3.math.Vector2f) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) BasicShadowRenderer(com.jme3.shadow.BasicShadowRenderer)

Example 42 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TestFancyCar method findGeom.

//    public void setupFloor() {
//        Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
//        mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
////        mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
////        mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
//
//        Box floor = new Box(Vector3f.ZERO, 140, 1f, 140);
//        floor.scaleTextureCoordinates(new Vector2f(112.0f, 112.0f));
//        Geometry floorGeom = new Geometry("Floor", floor);
//        floorGeom.setShadowMode(ShadowMode.Receive);
//        floorGeom.setMaterial(mat);
//
//        PhysicsNode tb = new PhysicsNode(floorGeom, new MeshCollisionShape(floorGeom.getMesh()), 0);
//        tb.setLocalTranslation(new Vector3f(0f, -6, 0f));
////        tb.attachDebugShape(assetManager);
//        rootNode.attachChild(tb);
//        getPhysicsSpace().add(tb);
//    }
private Geometry findGeom(Spatial spatial, String name) {
    if (spatial instanceof Node) {
        Node node = (Node) spatial;
        for (int i = 0; i < node.getQuantity(); i++) {
            Spatial child = node.getChild(i);
            Geometry result = findGeom(child, name);
            if (result != null) {
                return result;
            }
        }
    } else if (spatial instanceof Geometry) {
        if (spatial.getName().startsWith(name)) {
            return (Geometry) spatial;
        }
    }
    return null;
}
Also used : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 43 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TestBatchNodeTower method initFloor.

public void initFloor() {
    Box floorBox = new Box(10f, 0.1f, 5f);
    floorBox.scaleTextureCoordinates(new Vector2f(3, 6));
    Geometry floor = new Geometry("floor", floorBox);
    floor.setMaterial(mat3);
    floor.setShadowMode(ShadowMode.Receive);
    floor.setLocalTranslation(0, 0, 0);
    floor.addControl(new RigidBodyControl(0));
    this.rootNode.attachChild(floor);
    this.getPhysicsSpace().add(floor);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector2f(com.jme3.math.Vector2f) Box(com.jme3.scene.shape.Box) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 44 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method linkVertices.

private static ArrayList<VertexInfo> linkVertices(Mesh mesh, boolean splitMirrored) {
    ArrayList<VertexInfo> vertexMap = new ArrayList<VertexInfo>();
    FloatBuffer vertexBuffer = mesh.getFloatBuffer(Type.Position);
    FloatBuffer normalBuffer = mesh.getFloatBuffer(Type.Normal);
    FloatBuffer texcoordBuffer = mesh.getFloatBuffer(Type.TexCoord);
    Vector3f position = new Vector3f();
    Vector3f normal = new Vector3f();
    Vector2f texCoord = new Vector2f();
    final int size = vertexBuffer.limit() / 3;
    for (int i = 0; i < size; i++) {
        populateFromBuffer(position, vertexBuffer, i);
        populateFromBuffer(normal, normalBuffer, i);
        populateFromBuffer(texCoord, texcoordBuffer, i);
        boolean found = false;
        //separate vertice should have separate tangent space   
        if (!splitMirrored) {
            for (int j = 0; j < vertexMap.size(); j++) {
                VertexInfo vertexInfo = vertexMap.get(j);
                if (approxEqual(vertexInfo.position, position) && approxEqual(vertexInfo.normal, normal) && approxEqual(vertexInfo.texCoord, texCoord)) {
                    vertexInfo.indices.add(i);
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            VertexInfo vertexInfo = new VertexInfo(position.clone(), normal.clone(), texCoord.clone());
            vertexInfo.indices.add(i);
            vertexMap.add(vertexInfo);
        }
    }
    return vertexMap;
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) FloatBuffer(java.nio.FloatBuffer)

Example 45 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method processTriangleFan.

private static List<VertexData> processTriangleFan(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t) {
    IndexBuffer indexBuffer = mesh.getIndexBuffer();
    FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
    List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
    index[0] = indexBuffer.get(0);
    index[1] = indexBuffer.get(1);
    populateFromBuffer(v[0], vertexBuffer, index[0]);
    populateFromBuffer(v[1], vertexBuffer, index[1]);
    populateFromBuffer(t[0], textureBuffer, index[0]);
    populateFromBuffer(t[1], textureBuffer, index[1]);
    for (int i = 2; i < vertexBuffer.limit() / 3; i++) {
        index[2] = indexBuffer.get(i);
        populateFromBuffer(v[2], vertexBuffer, index[2]);
        populateFromBuffer(t[2], textureBuffer, index[2]);
        TriangleData triData = processTriangle(index, v, t);
        vertices.get(index[0]).triangles.add(triData);
        vertices.get(index[1]).triangles.add(triData);
        vertices.get(index[2]).triangles.add(triData);
        Vector3f vTemp = v[1];
        v[1] = v[2];
        v[2] = vTemp;
        Vector2f tTemp = t[1];
        t[1] = t[2];
        t[2] = tTemp;
        index[1] = index[2];
    }
    return vertices;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Aggregations

Vector2f (com.jme3.math.Vector2f)80 Vector3f (com.jme3.math.Vector3f)38 Geometry (com.jme3.scene.Geometry)22 Material (com.jme3.material.Material)20 Box (com.jme3.scene.shape.Box)17 ArrayList (java.util.ArrayList)14 Texture (com.jme3.texture.Texture)9 List (java.util.List)9 Node (com.jme3.scene.Node)8 Sphere (com.jme3.scene.shape.Sphere)8 FloatBuffer (java.nio.FloatBuffer)8 InputCapsule (com.jme3.export.InputCapsule)7 Spatial (com.jme3.scene.Spatial)7 DirectionalLight (com.jme3.light.DirectionalLight)6 Mesh (com.jme3.scene.Mesh)6 AmbientLight (com.jme3.light.AmbientLight)5 Quad (com.jme3.scene.shape.Quad)5 BoundingBox (com.jme3.bounding.BoundingBox)4 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 CollisionResult (com.jme3.collision.CollisionResult)4