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);
}
}
}
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);
}
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());
}
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();
}
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);
}
Aggregations