-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for global lights #2548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9d90dc2
0856599
3de0cd0
13edd16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import com.jme3.util.SortUtil; | ||
import java.io.IOException; | ||
import java.util.*; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* <code>LightList</code> is used internally by {@link Spatial}s to manage | ||
|
@@ -230,37 +231,53 @@ public void sort(boolean transformChanged) { | |
* @param parent the parent's world-space LightList | ||
*/ | ||
public void update(LightList local, LightList parent) { | ||
update(local, parent, null); | ||
} | ||
|
||
|
||
/** | ||
* Updates a "world-space" light list, using the spatial's local-space | ||
* light list, its parent's world-space light list and an optional filter. | ||
* | ||
* @param local the local-space LightList (not null) | ||
* @param parent the parent's world-space LightList | ||
* @param filter an optional filter to apply to the lights | ||
* (null means no filtering) | ||
*/ | ||
public void update(LightList local, LightList parent, Predicate<Light> filter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a filter here so that we can exclude global lights from being added the children's internal world lights list. That's because the rootNode propagates down all the global lights, so when a global light is owned by a children and it is propagated to the same children later, we would end up with the children having two references to the same light, one from its internal local light list and one from the rootNode global light list. |
||
// clear the list as it will be reconstructed | ||
// using the arguments | ||
clear(); | ||
|
||
while (list.length <= local.listSize) { | ||
doubleSize(); | ||
} | ||
|
||
// add the lights from the local list | ||
System.arraycopy(local.list, 0, list, 0, local.listSize); | ||
for (int i = 0; i < local.listSize; i++) { | ||
// list[i] = local.list[i]; | ||
distToOwner[i] = Float.NEGATIVE_INFINITY; | ||
|
||
int localListSize = 0;// local.listSize; | ||
for(int i=0;i<local.listSize;i++){ | ||
Light l = local.list[i]; | ||
if (filter != null && !filter.test(l)) continue; | ||
list[localListSize] = l; | ||
distToOwner[localListSize] = Float.NEGATIVE_INFINITY; | ||
localListSize++; | ||
} | ||
|
||
// if the spatial has a parent node, add the lights | ||
// from the parent list as well | ||
if (parent != null) { | ||
int sz = local.listSize + parent.listSize; | ||
int sz = localListSize + parent.listSize; | ||
while (list.length <= sz) | ||
doubleSize(); | ||
|
||
for (int i = 0; i < parent.listSize; i++) { | ||
int p = i + local.listSize; | ||
int p = i + localListSize; | ||
list[p] = parent.list[i]; | ||
distToOwner[p] = Float.NEGATIVE_INFINITY; | ||
} | ||
|
||
listSize = local.listSize + parent.listSize; | ||
listSize = localListSize + parent.listSize; | ||
} else { | ||
listSize = local.listSize; | ||
listSize = localListSize; | ||
} | ||
} | ||
|
||
|
@@ -361,4 +378,17 @@ public void read(JmeImporter im) throws IOException { | |
|
||
Arrays.fill(distToOwner, Float.NEGATIVE_INFINITY); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder("LightList["); | ||
for (int i = 0; i < listSize; i++) { | ||
sb.append(list[i]); | ||
if (i < listSize - 1) { | ||
sb.append(", "); | ||
} | ||
} | ||
sb.append("]"); | ||
return sb.toString(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is unrelated, but helped with the debug, so i've just left it here |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't make a setter for the global param, to make it defacto immutable.
This makes implementation much easier and performant, since we never need to check if the flag changed.