use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class BatchNode method doBatch.
protected void doBatch() {
Map<Material, List<Geometry>> matMap = new HashMap<Material, List<Geometry>>();
int nbGeoms = 0;
gatherGeometries(matMap, this, needsFullRebatch);
if (needsFullRebatch) {
for (Batch batch : batches.getArray()) {
batch.geometry.removeFromParent();
}
batches.clear();
batchesByGeom.clear();
}
//only reset maxVertCount if there is something new to batch
if (matMap.size() > 0) {
maxVertCount = 0;
}
for (Map.Entry<Material, List<Geometry>> entry : matMap.entrySet()) {
Mesh m = new Mesh();
Material material = entry.getKey();
List<Geometry> list = entry.getValue();
nbGeoms += list.size();
String batchName = name + "-batch" + batches.size();
Batch batch;
if (!needsFullRebatch) {
batch = findBatchByMaterial(material);
if (batch != null) {
list.add(0, batch.geometry);
batchName = batch.geometry.getName();
batch.geometry.removeFromParent();
} else {
batch = new Batch();
}
} else {
batch = new Batch();
}
mergeGeometries(m, list);
m.setDynamic();
batch.updateGeomList(list);
batch.geometry = new Geometry(batchName);
batch.geometry.setMaterial(material);
this.attachChild(batch.geometry);
batch.geometry.setMesh(m);
batch.geometry.getMesh().updateCounts();
batch.geometry.updateModelBound();
batches.add(batch);
}
if (batches.size() > 0) {
needsFullRebatch = false;
}
logger.log(Level.FINE, "Batched {0} geometries in {1} batches.", new Object[] { nbGeoms, batches.size() });
//init the temp arrays if something has been batched only.
if (matMap.size() > 0) {
//TODO these arrays should be allocated by chunk instead to avoid recreating them each time the batch is changed.
//init temp float arrays
tmpFloat = new float[maxVertCount * 3];
tmpFloatN = new float[maxVertCount * 3];
if (useTangents) {
tmpFloatT = new float[maxVertCount * 4];
}
}
}
use of com.jme3.util.IntMap.Entry 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.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class IntMap method remove.
public T remove(int key) {
int index = key & mask;
Entry prev = table[index];
Entry e = prev;
while (e != null) {
Entry next = e.next;
if (e.key == key) {
size--;
if (prev == e) {
table[index] = next;
} else {
prev.next = next;
}
return (T) e.value;
}
prev = e;
e = next;
}
return null;
}
use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class GlfwJoystickInput method update.
public void update() {
for (final Map.Entry<Integer, GlfwJoystick> entry : joysticks.entrySet()) {
// Axes
final FloatBuffer axisValues = glfwGetJoystickAxes(entry.getKey());
for (final JoystickAxis axis : entry.getValue().getAxes()) {
final float value = axisValues.get(axis.getAxisId());
listener.onJoyAxisEvent(new JoyAxisEvent(axis, value));
}
// Buttons
final ByteBuffer byteBuffer = glfwGetJoystickButtons(entry.getKey());
for (final JoystickButton button : entry.getValue().getButtons()) {
final boolean pressed = byteBuffer.get(button.getButtonId()) == GLFW_PRESS;
listener.onJoyButtonEvent(new JoyButtonEvent(button, pressed));
}
}
}
use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class FbxLoader method applyBindPoses.
/**
* Copies the bind poses from FBX BindPose objects to FBX nodes.
* Must be called prior to {@link #updateWorldTransforms()}.
*/
private void applyBindPoses() {
for (FbxBindPose bindPose : bindPoses) {
Map<FbxId, Matrix4f> bindPoseData = bindPose.getJmeObject();
logger.log(Level.INFO, "Applying {0} bind poses", bindPoseData.size());
for (Map.Entry<FbxId, Matrix4f> entry : bindPoseData.entrySet()) {
FbxObject obj = objectMap.get(entry.getKey());
if (obj instanceof FbxNode) {
FbxNode node = (FbxNode) obj;
node.setWorldBindPose(entry.getValue());
} else {
logger.log(Level.WARNING, "Bind pose can only be applied to FBX nodes. Ignoring.");
}
}
}
}
Aggregations