protected static ColorRGBA getAmbientColor(LightList lightList, boolean removeLights, ColorRGBA ambientLightColor) { ambientLightColor.set(0, 0, 0, 1); for (int j = 0; j < lightList.size(); j++) { Light l = lightList.get(j); if (l instanceof AmbientLight) { ambientLightColor.addLocal(l.getColor()); if (removeLights) { lightList.remove(l); } } } ambientLightColor.a = 1.0f; return ambientLightColor; }
@Test public void testSimpleSort() { Geometry g = new Geometry("test", new Mesh()); LightList list = new LightList(g); list.add(new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X)); list.add(new PointLight(Vector3f.UNIT_X)); list.add(new DirectionalLight(Vector3f.UNIT_X)); list.add(new AmbientLight()); list.sort(true); assert list.get(0) instanceof AmbientLight; // Ambients always first assert list.get(1) instanceof DirectionalLight; // .. then directionals assert list.get(2) instanceof SpotLight; // Spot is 0 units away from geom assert list.get(3) instanceof PointLight; // .. and point is 1 unit away. }
clear(); doubleSize(); int sz = local.listSize + parent.listSize; while (list.length <= sz) doubleSize();
public boolean hasNext() { return index < size(); }
@Override public void populateProbes(Geometry g, LightList lightList) { if (!lightProbes.isEmpty()) { //The first probe is actually the closest to the geometry since the //light list is sorted according to the distance to the geom. LightProbe p = lightProbes.get(0); if (p.isReady()) { lightList.add(p); } //clearing the list for next pass. lightProbes.clear(); } }
assert list.get(0) instanceof AmbientLight; assert list.get(1) instanceof DirectionalLight; assert list.get(2) instanceof SpotLight; assert list.get(3) instanceof PointLight; n.updateGeometricState(); assert list.get(0) instanceof AmbientLight; assert list.get(1) instanceof DirectionalLight; assert list.get(2) instanceof PointLight; assert list.get(3) instanceof SpotLight;
public void remove() { LightList.this.remove(--index); } };
@Override protected void updateWorldLightList() { super.updateWorldLightList(); // geometry requires lights to be sorted worldLights.sort(true); }
/** * 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; }
filteredLightList.clear(); lightFilter.filterLights(geom, filteredLightList); lightList = filteredLightList;
/** * Adds a light to the list. List size is doubled if there is no room. * * @param l * The light to add. */ public void add(Light l) { if (listSize == list.length) { doubleSize(); } list[listSize] = l; distToOwner[listSize++] = Float.NEGATIVE_INFINITY; }
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); }
@Override public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) { int nbRenderedLights = 0; Renderer renderer = renderManager.getRenderer(); int batchSize = renderManager.getSinglePassLightBatchSize(); if (lights.size() == 0) { updateLightListUniforms(shader, geometry, lights, batchSize, renderManager, 0); renderer.setShader(shader); renderMeshFromGeometry(renderer, geometry); } else { while (nbRenderedLights < lights.size()) { nbRenderedLights = updateLightListUniforms(shader, geometry, lights, batchSize, renderManager, nbRenderedLights); renderer.setShader(shader); renderMeshFromGeometry(renderer, geometry); } } } }