com.jme3.util.SafeArrayList Java Examples

The following examples show how to use com.jme3.util.SafeArrayList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Node.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void read(JmeImporter e) throws IOException {
    // XXX: Load children before loading itself!!
    // This prevents empty children list if controls query
    // it in Control.setSpatial().
    children = new SafeArrayList(Spatial.class,
            e.getCapsule(this).readSavableArrayList("children", null));

    // go through children and set parent to this node
    if (children != null) {
        for (Spatial child : children.getArray()) {
            child.parent = this;
        }
    }
    super.read(e);
}
 
Example #2
Source File: Node.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void read(JmeImporter e) throws IOException {
    // XXX: Load children before loading itself!!
    // This prevents empty children list if controls query
    // it in Control.setSpatial().
    
    children = new SafeArrayList( Spatial.class, 
                                  e.getCapsule(this).readSavableArrayList("children", null) );

    // go through children and set parent to this node
    if (children != null) {
        for (Spatial child : children.getArray()) {
            child.parent = this;
        }
    }
    
    super.read(e);
}
 
Example #3
Source File: Bone.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Access the attachments node of this bone. If this bone doesn't already
 * have an attachments node, create one. Models and effects attached to the
 * attachments node will follow this bone's motions.
 *
 * @param boneIndex this bone's index in its skeleton (≥0)
 * @param targets a list of geometries animated by this bone's skeleton (not
 * null, unaffected)
 */
Node getAttachmentsNode(int boneIndex, SafeArrayList<Geometry> targets) {
    targetGeometry = null;
    /*
     * Search for a geometry animated by this particular bone.
     */
    for (Geometry geometry : targets) {
        Mesh mesh = geometry.getMesh();
        if (mesh != null && mesh.isAnimatedByBone(boneIndex)) {
            targetGeometry = geometry;
            break;
        }
    }

    if (attachNode == null) {
        attachNode = new Node(name + "_attachnode");
        attachNode.setUserData("AttachedBone", this);
        //We don't want the node to have a numBone set by a parent node so we force it to null
        attachNode.addMatParamOverride(new MatParamOverride(VarType.Int, "NumberOfBones", null));
    }

    return attachNode;
}
 
Example #4
Source File: Animation.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule in = im.getCapsule(this);
    name = in.readString("name", null);
    length = in.readFloat("length", 0f);

    Savable[] arr = in.readSavableArray("tracks", null);
    if (arr != null) {
        // NOTE: Backward compat only .. Some animations have no
        // tracks set at all even though it makes no sense.
        // Since there's a null check in setTime(),
        // it's only appropriate that the check is made here as well.
        tracks = new SafeArrayList<Track>(Track.class);
        for (Savable savable : arr) {
            tracks.add((Track) savable);
        }
    }
}
 
Example #5
Source File: Animation.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override   
public void cloneFields( Cloner cloner, Object original ) {
     
    // There is some logic here that I'm copying but I'm not sure if
    // it's a mistake or not.  If a track is not a CloneableTrack then it
    // isn't cloned at all... even though they all implement clone() methods. -pspeed
    SafeArrayList<Track> newTracks = new SafeArrayList<>(Track.class);
    for( Track track : tracks ) {
        if (track instanceof JmeCloneable) {
            newTracks.add(cloner.clone(track));
        } else {
            // this is the part that seems fishy 
            newTracks.add(track);
        }
    }
    this.tracks = newTracks;
}
 
Example #6
Source File: Animation.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 
 * @param spat
 * @return a new instance
 */
public Animation cloneForSpatial(Spatial spat) {
    try {
        Animation result = (Animation) super.clone();
        result.tracks = new SafeArrayList<Track>(Track.class);
        for (Track track : tracks) {
            if (track instanceof ClonableTrack) {
                result.tracks.add(((ClonableTrack) track).cloneForSpatial(spat));
            } else {
                result.tracks.add(track);
            }
        }
        return result;
    } catch (CloneNotSupportedException e) {
        throw new AssertionError();
    }
}
 
Example #7
Source File: TerrainGridLodControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void updateLOD(SafeArrayList<Vector3f> locations, LodCalculator lodCalculator) {
    TerrainGrid terrainGrid = (TerrainGrid)getSpatial();
    
    // for now, only the first camera is handled.
    // to accept more, there are two ways:
    // 1: every camera has an associated grid, then the location is not enough to identify which camera location has changed
    // 2: grids are associated with locations, and no incremental update is done, we load new grids for new locations, and unload those that are not needed anymore
    Vector3f cam = locations.isEmpty() ? Vector3f.ZERO.clone() : locations.get(0);
    Vector3f camCell = terrainGrid.getCamCell(cam); // get the grid index value of where the camera is (ie. 2,1)
    if (terrainGrid.cellsLoaded > 1) {                  // Check if cells are updated before updating gridoffset.
        terrainGrid.gridOffset[0] = Math.round(camCell.x * (terrainGrid.size / 2));
        terrainGrid.gridOffset[1] = Math.round(camCell.z * (terrainGrid.size / 2));
        terrainGrid.cellsLoaded = 0;
    }
    if (camCell.x != terrainGrid.currentCamCell.x || camCell.z != terrainGrid.currentCamCell.z || !terrainGrid.runOnce) {
        // if the camera has moved into a new cell, load new terrain into the visible 4 center quads
        terrainGrid.updateChildren(camCell);
        for (TerrainGridListener l : terrainGrid.listeners) {
            l.gridMoved(camCell);
        }
    }
    terrainGrid.runOnce = true;
    super.updateLOD(locations, lodCalculator);
}
 
Example #8
Source File: Animation.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    InputCapsule in = im.getCapsule(this);
    name = in.readString("name", null);
    length = in.readFloat("length", 0f);

    Savable[] arr = in.readSavableArray("tracks", null);
    if (arr != null) {
        // NOTE: Backward compat only .. Some animations have no
        // tracks set at all even though it makes no sense.
        // Since there's a null check in setTime(),
        // its only appropriate that the check is made here as well.
        tracks = new SafeArrayList<Track>(Track.class);
        for (Savable savable : arr) {
            tracks.add((Track) savable);
        }
    }
}
 
Example #9
Source File: Animation.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 
 * @param spat
 * @return 
 */
public Animation cloneForSpatial(Spatial spat) {
    try {
        Animation result = (Animation) super.clone();
        result.tracks = new SafeArrayList<Track>(Track.class);
        for (Track track : tracks) {
            if (track instanceof ClonableTrack) {
                result.tracks.add(((ClonableTrack) track).cloneForSpatial(spat));
            } else {
                result.tracks.add(track);
            }
        }
        return result;
    } catch (CloneNotSupportedException e) {
        throw new AssertionError();
    }
}
 
Example #10
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) {
    for (MatParamOverride override : overrides.getArray()) {
        VarType type = override.getVarType();

        MatParam paramDef = def.getMaterialParam(override.getName());

        if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) {
            continue;
        }

        Uniform uniform = shader.getUniform(override.getPrefixedName());

        if (override.getValue() != null) {
            if (type.isTextureType()) {
                renderer.setTexture(unit, (Texture) override.getValue());
                uniform.setValue(VarType.Int, unit);
                unit++;
            } else {
                uniform.setValue(type, override.getValue());
            }
        } else {
            uniform.clearValue();
        }
    }
    return unit;
}
 
Example #11
Source File: Material.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Preloads this material for the given render manager.
 * <p>
 * Preloading the material can ensure that when the material is first
 * used for rendering, there won't be any delay since the material has
 * been already been setup for rendering.
 *
 * @param renderManager The render manager to preload for
 */
public void preload(RenderManager renderManager, Geometry geometry) {
    if (technique == null) {
        selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    }
    TechniqueDef techniqueDef = technique.getDef();
    Renderer renderer = renderManager.getRenderer();
    EnumSet<Caps> rendererCaps = renderer.getCaps();

    if (techniqueDef.isNoRender()) {
        return;
    }
    // Get world overrides
    SafeArrayList<MatParamOverride> overrides = geometry.getWorldMatParamOverrides();

    Shader shader = technique.makeCurrent(renderManager, overrides, null, null, rendererCaps);
    updateShaderMaterialParameters(renderer, shader, overrides, null);
    renderManager.getRenderer().setShader(shader);
}
 
Example #12
Source File: Technique.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Called by the material to determine which shader to use for rendering.
 * 
 * The {@link TechniqueDefLogic} is used to determine the shader to use
 * based on the {@link LightMode}.
 * 
 * @param renderManager The render manager for which the shader is to be selected.
 * @param rendererCaps The renderer capabilities which the shader should support.
 * @return A compatible shader.
 */
Shader makeCurrent(RenderManager renderManager, SafeArrayList<MatParamOverride> worldOverrides,
        SafeArrayList<MatParamOverride> forcedOverrides,
        LightList lights, EnumSet<Caps> rendererCaps) {
    TechniqueDefLogic logic = def.getLogic();
    AssetManager assetManager = owner.getMaterialDef().getAssetManager();

    dynamicDefines.clear();
    dynamicDefines.setAll(paramDefines);

    if (worldOverrides != null) {
        applyOverrides(dynamicDefines, worldOverrides);
    }
    if (forcedOverrides != null) {
        applyOverrides(dynamicDefines, forcedOverrides);
    }

    return logic.makeCurrent(assetManager, renderManager, rendererCaps, lights, dynamicDefines);
}
 
Example #13
Source File: Joint.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Access the attachments node of this joint. If this joint doesn't already
 * have an attachments node, create one. Models and effects attached to the
 * attachments node will follow this bone's motions.
 *
 * @param jointIndex this bone's index in its armature (&ge;0)
 * @param targets    a list of geometries animated by this bone's skeleton (not
 *                   null, unaffected)
 */
Node getAttachmentsNode(int jointIndex, SafeArrayList<Geometry> targets) {
    targetGeometry = null;
    /*
     * Search for a geometry animated by this particular bone.
     */
    for (Geometry geometry : targets) {
        Mesh mesh = geometry.getMesh();
        if (mesh != null && mesh.isAnimatedByJoint(jointIndex)) {
            targetGeometry = geometry;
            break;
        }
    }

    if (attachedNode == null) {
        attachedNode = new Node(name + "_attachnode");
        attachedNode.setUserData("AttachedBone", this);
        //We don't want the node to have a numBone set by a parent node so we force it to null
        attachedNode.addMatParamOverride(new MatParamOverride(VarType.Int, "NumberOfBones", null));
    }

    return attachedNode;
}
 
Example #14
Source File: Spatial.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);

    name = ic.readString("name", null);
    worldBound = (BoundingVolume) ic.readSavable("world_bound", null);
    cullHint = ic.readEnum("cull_mode", CullHint.class, CullHint.Inherit);
    batchHint = ic.readEnum("batch_hint", BatchHint.class, BatchHint.Inherit);
    queueBucket = ic.readEnum("queue", RenderQueue.Bucket.class,
            RenderQueue.Bucket.Inherit);
    shadowMode = ic.readEnum("shadow_mode", ShadowMode.class,
            ShadowMode.Inherit);

    localTransform = (Transform) ic.readSavable("transform", Transform.IDENTITY);

    localLights = (LightList) ic.readSavable("lights", null);
    localLights.setOwner(this);

    ArrayList<MatParamOverride> localOverridesList = ic.readSavableArrayList("overrides", null);
    if (localOverridesList == null) {
        localOverrides = new SafeArrayList<>(MatParamOverride.class);
    } else {
        localOverrides = new SafeArrayList(MatParamOverride.class, localOverridesList);
    }
    worldOverrides = new SafeArrayList<>(MatParamOverride.class);

    //changed for backward compatibility with j3o files
    //generated before the AnimControl/SkeletonControl split
    //the AnimControl creates the SkeletonControl for old files and add it to the spatial.
    //The SkeletonControl must be the last in the stack
    //so we add the list of all other control before it.
    //When backward compatibility won't be needed anymore this can be replaced by :
    //controls = ic.readSavableArrayList("controlsList", null));
    controls.addAll(0, ic.readSavableArrayList("controlsList", null));

    userData = (HashMap<String, Savable>) ic.readStringSavableMap("user_data", null);
}
 
Example #15
Source File: Spatial.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Constructor instantiates a new <code>Spatial</code> object setting the
 * rotation, translation and scale value to defaults.
 *
 * @param name
 *            the name of the scene element. This is required for
 *            identification and comparison purposes.
 */
protected Spatial(String name) {
    this.name = name;
    localTransform = new Transform();
    worldTransform = new Transform();

    localLights = new LightList(this);
    worldLights = new LightList(this);

    localOverrides = new SafeArrayList<>(MatParamOverride.class);
    worldOverrides = new SafeArrayList<>(MatParamOverride.class);
    refreshFlags |= RF_BOUND;
}
 
Example #16
Source File: AssetLinkNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(JmeExporter e) throws IOException {
    SafeArrayList<Spatial> childs = children;
    children = new SafeArrayList<>(Spatial.class);
    super.write(e);
    OutputCapsule capsule = e.getCapsule(this);
    capsule.writeSavableArrayList(assetLoaderKeys, "assetLoaderKeyList", null);
    children = childs;
}
 
Example #17
Source File: Animation.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method creates a clone of the current object.
 * @return a clone of the current object
 */
@Override
public Animation clone() {
    try {
        Animation result = (Animation) super.clone();
        result.tracks = new SafeArrayList<Track>(Track.class);
        for (Track track : tracks) {
            result.tracks.add(track.clone());
        }
        return result;
    } catch (CloneNotSupportedException e) {
        throw new AssertionError();
    }
}
 
Example #18
Source File: Node.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Spatial oldDeepClone() {
    Node nodeClone = (Node) super.clone();
    nodeClone.children = new SafeArrayList<Spatial>(Spatial.class);
    for (Spatial child : children) {
        Spatial childClone = child.deepClone();
        childClone.parent = nodeClone;
        nodeClone.children.add(childClone);
    }
    return nodeClone;
}
 
Example #19
Source File: Node.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private SafeArrayList<Spatial> getUpdateList() {
    if (updateListValid) {
        return updateList;
    }
    if (updateList == null) {
        updateList = new SafeArrayList<Spatial>(Spatial.class);
    } else {
        updateList.clear();
    }

    // Build the list
    addUpdateChildren(updateList);
    updateListValid = true;
    return updateList;
}
 
Example #20
Source File: Node.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addUpdateChildren(SafeArrayList<Spatial> results) {
    for (Spatial child : children.getArray()) {
        if (child.requiresUpdates()) {
            results.add(child);
        }
        if (child instanceof Node) {
            ((Node) child).addUpdateChildren(results);
        }
    }
}
 
Example #21
Source File: FilterPostProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    numSamples = ic.readInt("numSamples", 0);
    filters = new SafeArrayList<Filter>(Filter.class, ic.readSavableArrayList("filters", null));
    for (Filter filter : filters.getArray()) {
        filter.setProcessor(this);
        setFilterState(filter, filter.isEnabled());
    }
    assetManager = im.getAssetManager();
}
 
Example #22
Source File: Node.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Spatial deepClone(){
    Node nodeClone = (Node) super.clone();
    nodeClone.children = new SafeArrayList<Spatial>(Spatial.class);
    for (Spatial child : children){
        Spatial childClone = child.deepClone();
        childClone.parent = nodeClone;
        nodeClone.children.add(childClone);
    }
    return nodeClone;
}
 
Example #23
Source File: Technique.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void applyOverrides(DefineList defineList, SafeArrayList<MatParamOverride> overrides) {
    for (MatParamOverride override : overrides.getArray()) {
        if (!override.isEnabled()) {
            continue;
        }
        Integer defineId = def.getShaderParamDefineId(override.name);
        if (defineId != null) {
            if (def.getDefineIdType(defineId) == override.type) {
                defineList.set(defineId, override.type, override.value);
            }
        }
    }
}
 
Example #24
Source File: BaseAction.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BaseAction(Tween tween) {
    this.tween = tween;
    setLength(tween.getLength());
    List<Action> subActions = new SafeArrayList<>(Action.class);
    gatherActions(tween, subActions);
    actions = new Action[subActions.size()];
    subActions.toArray(actions);
}
 
Example #25
Source File: Animation.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This method creates a clone of the current object.
 * @return a clone of the current object
 */
@Override
public Animation clone() {
    try {
        Animation result = (Animation) super.clone();
        result.tracks = new SafeArrayList<Track>(Track.class);
        for (Track track : tracks) {
            result.tracks.add(track.clone());
        }
        return result;
    } catch (CloneNotSupportedException e) {
        throw new AssertionError();
    }
}
 
Example #26
Source File: BufferObject.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BufferObject(final int binding, final Layout layout, final BufferType bufferType) {
    this.handleRef = new Object();
    this.bufferType = bufferType;
    this.binding = binding;
    this.layout = layout;
    this.fields = new HashMap<>();
    this.fieldArray = new SafeArrayList<>(BufferObjectField.class);
}
 
Example #27
Source File: TerrainLodControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void cloneFields(final Cloner cloner, final Object original) {
    super.cloneFields(cloner, original);

    this.lodCalculator = cloner.clone(lodCalculator);
    this.cameras = new SafeArrayList<>(Camera.class, cameras);
    this.cameraLocations = new SafeArrayList<>(Vector3f.class);
    this.lastCameraLocations = new SafeArrayList<>(Vector3f.class);
    this.lodCalcRunning = new AtomicBoolean();
    this.previousCameraLocation = new Vector3f();
}
 
Example #28
Source File: TerrainLodControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TerrainLodControl() {
    hasResetLod = false;
    forceUpdate = true;
    previousCameraLocation = new Vector3f();
    cameras = new SafeArrayList<>(Camera.class);
    cameraLocations = new SafeArrayList<>(Vector3f.class);
    lastCameraLocations = new SafeArrayList<>(Vector3f.class);
    lodCalcRunning = new AtomicBoolean(false);
    lodOffCount = 0;
    lodCalculator = makeLodCalculator(); // a default calculator
}
 
Example #29
Source File: SceneFiltersTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) {

    if (!(nodeTree instanceof SceneNodeTree)) {
        return super.getChildren(nodeTree);
    }

    final SafeArrayList<SceneFilter> filters = getElement().getFilters();

    final Array<TreeNode<?>> result = ArrayFactory.newArray(TreeNode.class);
    filters.forEach(sceneFilter -> result.add(FACTORY_REGISTRY.createFor(sceneFilter.get())));

    return result;
}
 
Example #30
Source File: SceneAppStatesTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) {

    if (!(nodeTree instanceof SceneNodeTree)) {
        return super.getChildren(nodeTree);
    }

    final @NotNull SafeArrayList<SceneAppState> appStates = getElement().getAppStates();

    final Array<TreeNode<?>> result = ArrayFactory.newArray(TreeNode.class);
    appStates.forEach(appState -> result.add(FACTORY_REGISTRY.createFor(appState)));

    return result;
}