use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class AbstractBlenderHelper method loadLibrary.
/**
* The method loads library of a given ID from linked blender file.
* @param id
* the ID of the linked feature (it contains its name and blender path)
* @return loaded feature or null if none was found
* @throws BlenderFileException
* and exception is throw when problems with reading a blend file occur
*/
protected Object loadLibrary(Structure id) throws BlenderFileException {
Pointer pLib = (Pointer) id.getFieldValue("lib");
if (pLib.isNotNull()) {
// we need full name with the prefix
String fullName = id.getFieldValue("name").toString();
String nameOfFeatureToLoad = id.getName();
Structure library = pLib.fetchData().get(0);
String path = library.getFieldValue("filepath").toString();
if (!blenderContext.getLinkedFeatures().keySet().contains(path)) {
Spatial loadedAsset = null;
BlenderKey blenderKey = new BlenderKey(path);
blenderKey.setLoadUnlinkedAssets(true);
try {
loadedAsset = blenderContext.getAssetManager().loadAsset(blenderKey);
} catch (AssetNotFoundException e) {
LOGGER.log(Level.FINEST, "Cannot locate linked resource at path: {0}.", path);
}
if (loadedAsset != null) {
Map<String, Map<String, Object>> linkedData = loadedAsset.getUserData("linkedData");
for (Entry<String, Map<String, Object>> entry : linkedData.entrySet()) {
String linkedDataFilePath = "this".equals(entry.getKey()) ? path : entry.getKey();
blenderContext.getLinkedFeatures().put(linkedDataFilePath, entry.getValue());
}
} else {
LOGGER.log(Level.WARNING, "No features loaded from path: {0}.", path);
}
}
Object result = blenderContext.getLinkedFeature(path, fullName);
if (result == null) {
LOGGER.log(Level.WARNING, "Could NOT find asset named {0} in the library of path: {1}.", new Object[] { nameOfFeatureToLoad, path });
} else {
blenderContext.addLoadedFeatures(id.getOldMemoryAddress(), LoadedDataType.STRUCTURE, id);
blenderContext.addLoadedFeatures(id.getOldMemoryAddress(), LoadedDataType.FEATURE, result);
}
return result;
} else {
LOGGER.warning("Library link points to nothing!");
}
return null;
}
use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class CachedOggStream method reloadLogicalOggStream.
public LogicalOggStream reloadLogicalOggStream() {
logicalStreams.clear();
LogicalOggStreamImpl los = new LogicalOggStreamImpl(this, serialno);
logicalStreams.put(serialno, los);
for (IntMap.Entry<OggPage> entry : oggPages) {
los.addPageNumberMapping(entry.getKey());
los.addGranulePosition(entry.getValue().getAbsoluteGranulePosition());
}
return los;
}
use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class BulletDebugAppState method updateCharacters.
private void updateCharacters() {
HashMap<PhysicsCharacter, Spatial> oldObjects = characters;
characters = new HashMap<PhysicsCharacter, Spatial>();
Collection<PhysicsCharacter> current = space.getCharacterList();
//create new map
for (Iterator<PhysicsCharacter> it = current.iterator(); it.hasNext(); ) {
PhysicsCharacter physicsObject = it.next();
//copy existing spatials
if (oldObjects.containsKey(physicsObject)) {
Spatial spat = oldObjects.get(physicsObject);
characters.put(physicsObject, spat);
oldObjects.remove(physicsObject);
} else {
if (filter == null || filter.displayObject(physicsObject)) {
logger.log(Level.FINE, "Create new debug Character");
//create new spatial
Node node = new Node(physicsObject.toString());
node.addControl(new BulletCharacterDebugControl(this, physicsObject));
characters.put(physicsObject, node);
physicsDebugRootNode.attachChild(node);
}
}
}
//remove leftover spatials
for (Map.Entry<PhysicsCharacter, Spatial> entry : oldObjects.entrySet()) {
PhysicsCharacter object = entry.getKey();
Spatial spatial = entry.getValue();
spatial.removeFromParent();
}
}
use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class IntMap method put.
public T put(int key, T value) {
int index = key & mask;
// Check if key already exists.
for (Entry e = table[index]; e != null; e = e.next) {
if (e.key != key) {
continue;
}
Object oldValue = e.value;
e.value = value;
return (T) oldValue;
}
table[index] = new Entry(key, value, table[index]);
if (size++ >= threshold) {
// Rehash.
int newCapacity = 2 * capacity;
Entry[] newTable = new Entry[newCapacity];
Entry[] src = table;
int bucketmask = newCapacity - 1;
for (int j = 0; j < src.length; j++) {
Entry e = src[j];
if (e != null) {
src[j] = null;
do {
Entry next = e.next;
index = e.key & bucketmask;
e.next = newTable[index];
newTable[index] = e;
e = next;
} while (e != null);
}
}
table = newTable;
capacity = newCapacity;
threshold = (int) (newCapacity * loadFactor);
mask = capacity - 1;
}
return null;
}
use of com.jme3.util.IntMap.Entry in project jmonkeyengine by jMonkeyEngine.
the class CurvesTemporalMesh method generateNormals.
/**
* The method generates normals for the curve. If any normals were already stored they are discarded.
*/
private void generateNormals() {
Map<Integer, Vector3f> normalMap = new TreeMap<Integer, Vector3f>();
for (Face face : faces) {
// the first 3 verts are enough here (all faces are triangles except for the caps, but those are fully flat anyway)
int index1 = face.getIndexes().get(0);
int index2 = face.getIndexes().get(1);
int index3 = face.getIndexes().get(2);
Vector3f n = FastMath.computeNormal(vertices.get(index1), vertices.get(index2), vertices.get(index3));
for (int index : face.getIndexes()) {
Vector3f normal = normalMap.get(index);
if (normal == null) {
normalMap.put(index, n.clone());
} else {
normal.addLocal(n).normalizeLocal();
}
}
}
normals.clear();
Collections.addAll(normals, new Vector3f[normalMap.size()]);
for (Entry<Integer, Vector3f> entry : normalMap.entrySet()) {
normals.set(entry.getKey(), entry.getValue());
}
}
Aggregations