* Manually trigger the sort of all the childs in the container * @param {boolean} [recursive=false] - recursively sort all containers if true
(recursive)
| 952 | * @param {boolean} [recursive=false] - recursively sort all containers if true |
| 953 | */ |
| 954 | sort(recursive) { |
| 955 | // do nothing if there is already a pending sort |
| 956 | if (!this.pendingSort) { |
| 957 | if (recursive === true) { |
| 958 | this.forEach((child) => { |
| 959 | if (child instanceof Container) { |
| 960 | // note : this will generate one deferred sorting function |
| 961 | // for each existing containe |
| 962 | child.sort(recursive); |
| 963 | } |
| 964 | }); |
| 965 | } |
| 966 | this.pendingSort = defer(function () { |
| 967 | // refresh the cached camera + container offset so |
| 968 | // `_sortDepth` sees the current view in world space — |
| 969 | // no-op for x/y/z modes. |
| 970 | if (this._sortOn === "depth") { |
| 971 | captureDepthCamera(); |
| 972 | captureDepthOffset(this); |
| 973 | } |
| 974 | // sort everything in this container |
| 975 | this.getChildren().sort(this._comparator); |
| 976 | // clear the defer id |
| 977 | this.pendingSort = null; |
| 978 | // make sure we redraw everything |
| 979 | this.isDirty = true; |
| 980 | }, this); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | /** |
| 985 | * Synchronous variant of {@link Container#sort}. Sorts immediately |
no test coverage detected