Search in sources :

Example 11 with Entry

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;
}
Also used : Spatial(com.jme3.scene.Spatial) Pointer(com.jme3.scene.plugins.blender.file.Pointer) BlenderKey(com.jme3.asset.BlenderKey) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) Structure(com.jme3.scene.plugins.blender.file.Structure) Map(java.util.Map)

Example 12 with Entry

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;
}
Also used : IntMap(com.jme3.util.IntMap) OggPage(de.jarnbjo.ogg.OggPage) LogicalOggStreamImpl(de.jarnbjo.ogg.LogicalOggStreamImpl)

Example 13 with Entry

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();
    }
}
Also used : PhysicsCharacter(com.jme3.bullet.objects.PhysicsCharacter) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with Entry

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;
}
Also used : Entry(com.jme3.util.IntMap.Entry)

Example 15 with Entry

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());
    }
}
Also used : Vector3f(com.jme3.math.Vector3f) TreeMap(java.util.TreeMap) Face(com.jme3.scene.plugins.blender.meshes.Face)

Aggregations

HashMap (java.util.HashMap)17 Map (java.util.Map)13 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Vector2f (com.jme3.math.Vector2f)8 Vector3f (com.jme3.math.Vector3f)7 Node (com.jme3.scene.Node)6 Spatial (com.jme3.scene.Spatial)6 VertexBuffer (com.jme3.scene.VertexBuffer)5 Material (com.jme3.material.Material)4 FloatBuffer (java.nio.FloatBuffer)4 Bone (com.jme3.animation.Bone)3 Geometry (com.jme3.scene.Geometry)3 Mesh (com.jme3.scene.Mesh)3 Pointer (com.jme3.scene.plugins.blender.file.Pointer)3 Structure (com.jme3.scene.plugins.blender.file.Structure)3 Face (com.jme3.scene.plugins.blender.meshes.Face)3 Image (com.jme3.texture.Image)3 IntMap (com.jme3.util.IntMap)3 ByteBuffer (java.nio.ByteBuffer)3