Search in sources :

Example 96 with Box

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

the class MikktspaceTangentGenerator method generateSharedVerticesIndexList.

static void generateSharedVerticesIndexList(int[] piTriList_in_and_out, final MikkTSpaceContext mikkTSpace, final int iNrTrianglesIn) {
    // Generate bounding box
    TmpVert[] pTmpVert;
    Vector3f vMin = getPosition(mikkTSpace, 0);
    Vector3f vMax = vMin.clone();
    Vector3f vDim;
    float fMin, fMax;
    for (int i = 1; i < (iNrTrianglesIn * 3); i++) {
        final int index = piTriList_in_and_out[i];
        final Vector3f vP = getPosition(mikkTSpace, index);
        if (vMin.x > vP.x) {
            vMin.x = vP.x;
        } else if (vMax.x < vP.x) {
            vMax.x = vP.x;
        }
        if (vMin.y > vP.y) {
            vMin.y = vP.y;
        } else if (vMax.y < vP.y) {
            vMax.y = vP.y;
        }
        if (vMin.z > vP.z) {
            vMin.z = vP.z;
        } else if (vMax.z < vP.z) {
            vMax.z = vP.z;
        }
    }
    vDim = vMax.subtract(vMin);
    int iChannel = 0;
    fMin = vMin.x;
    fMax = vMax.x;
    if (vDim.y > vDim.x && vDim.y > vDim.z) {
        iChannel = 1;
        fMin = vMin.y;
        fMax = vMax.y;
    } else if (vDim.z > vDim.x) {
        iChannel = 2;
        fMin = vMin.z;
        fMax = vMax.z;
    }
    //TODO Nehon: this is really fishy... seems like a hashtable implementation with nasty array manipulation...
    int[] piHashTable = new int[iNrTrianglesIn * 3];
    int[] piHashCount = new int[CELLS];
    int[] piHashOffsets = new int[CELLS];
    int[] piHashCount2 = new int[CELLS];
    // count amount of elements in each cell unit
    for (int i = 0; i < (iNrTrianglesIn * 3); i++) {
        final int index = piTriList_in_and_out[i];
        final Vector3f vP = getPosition(mikkTSpace, index);
        final float fVal = iChannel == 0 ? vP.x : (iChannel == 1 ? vP.y : vP.z);
        final int iCell = findGridCell(fMin, fMax, fVal);
        ++piHashCount[iCell];
    }
    // evaluate start index of each cell.
    piHashOffsets[0] = 0;
    for (int k = 1; k < CELLS; k++) {
        piHashOffsets[k] = piHashOffsets[k - 1] + piHashCount[k - 1];
    }
    // insert vertices
    for (int i = 0; i < (iNrTrianglesIn * 3); i++) {
        final int index = piTriList_in_and_out[i];
        final Vector3f vP = getPosition(mikkTSpace, index);
        final float fVal = iChannel == 0 ? vP.x : (iChannel == 1 ? vP.y : vP.z);
        final int iCell = findGridCell(fMin, fMax, fVal);
        assert (piHashCount2[iCell] < piHashCount[iCell]);
        //    int * pTable = &piHashTable[piHashOffsets[iCell]];
        //    pTable[piHashCount2[iCell]] = i;  // vertex i has been inserted.
        // vertex i has been inserted.     
        piHashTable[piHashOffsets[iCell] + piHashCount2[iCell]] = i;
        ++piHashCount2[iCell];
    }
    for (int k = 0; k < CELLS; k++) {
        // verify the count
        assert (piHashCount2[k] == piHashCount[k]);
    }
    // find maximum amount of entries in any hash entry
    int iMaxCount = piHashCount[0];
    for (int k = 1; k < CELLS; k++) {
        if (iMaxCount < piHashCount[k]) {
            iMaxCount = piHashCount[k];
        }
    }
    pTmpVert = new TmpVert[iMaxCount];
    // complete the merge
    for (int k = 0; k < CELLS; k++) {
        // extract table of cell k and amount of entries in it
        // int * pTable = &piHashTable[piHashOffsets[k]];
        final int iEntries = piHashCount[k];
        if (iEntries < 2) {
            continue;
        }
        if (pTmpVert != null) {
            for (int e = 0; e < iEntries; e++) {
                int j = piHashTable[piHashOffsets[k] + e];
                final Vector3f vP = getPosition(mikkTSpace, piTriList_in_and_out[j]);
                pTmpVert[e] = new TmpVert();
                pTmpVert[e].vert[0] = vP.x;
                pTmpVert[e].vert[1] = vP.y;
                pTmpVert[e].vert[2] = vP.z;
                pTmpVert[e].index = j;
            }
            MergeVertsFast(piTriList_in_and_out, pTmpVert, mikkTSpace, 0, iEntries - 1);
        } else {
            //TODO Nehon: pTempVert is very unlikely to be null...maybe remove this...
            int[] pTable = Arrays.copyOfRange(piHashTable, piHashOffsets[k], piHashOffsets[k] + iEntries);
            MergeVertsSlow(piTriList_in_and_out, mikkTSpace, pTable, iEntries);
        }
    }
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 97 with Box

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

the class TestMotionPath method createScene.

private void createScene() {
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 1f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Black);
    mat.setColor("Diffuse", ColorRGBA.DarkGray);
    mat.setColor("Specular", ColorRGBA.White.mult(0.6f));
    Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Black);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Black);
    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setName("Teapot");
    teapot.setLocalScale(3);
    teapot.setMaterial(mat);
    rootNode.attachChild(teapot);
    Geometry soil = new Geometry("soil", new Box(50, 1, 50));
    soil.setLocalTranslation(0, -1, 0);
    soil.setMaterial(matSoil);
    rootNode.attachChild(soil);
    DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);
}
Also used : Geometry(com.jme3.scene.Geometry) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Example 98 with Box

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

the class TestAppStateLifeCycle 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);
    System.out.println("Attaching test state.");
    stateManager.attach(new TestState());
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 99 with Box

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

the class TestEnqueueRunnable method simpleInitApp.

@Override
public void simpleInitApp() {
    Geometry geom = new Geometry("Box", new Box(1, 1, 1));
    Material material = new Material(getAssetManager(), "/Common/MatDefs/Misc/Unshaded.j3md");
    //a color is needed to start with
    material.setColor("Color", ColorRGBA.Blue);
    geom.setMaterial(material);
    getRootNode().attachChild(geom);
    exampleAsyncTask = new ExampleAsyncTask(material);
    exampleAsyncTask.getThread().start();
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 100 with Box

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

the class TestResizableApp method simpleInitApp.

public void simpleInitApp() {
    flyCam.setDragToRotate(true);
    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);
    txt = new BitmapText(loadGuiFont(), false);
    txt.setText("Drag the corners of the application to resize it.\n" + "Current Size: " + settings.getWidth() + "x" + settings.getHeight());
    txt.setLocalTranslation(0, settings.getHeight(), 0);
    guiNode.attachChild(txt);
}
Also used : Geometry(com.jme3.scene.Geometry) BitmapText(com.jme3.font.BitmapText) TestBox(jme3test.model.shape.TestBox) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

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