Allows the direct attachment of BaseMesh objects to the box-graph, and direct attachment of anything
| 13 | * Allows the direct attachment of BaseMesh objects to the box-graph, and direct attachment of anything |
| 14 | */ |
| 15 | public class Meshes extends Box implements Drawing.Drawer { |
| 16 | static public final Dict.Prop<IdempotencyMap<Supplier<BaseMesh>>> meshes = new Dict.Prop<>("meshes").type() |
| 17 | .toCanon() |
| 18 | .doc("Geometry (specifically instances of BaseMesh) to be drawn along with this box") |
| 19 | .autoConstructs(() -> new IdempotencyMap<>(Supplier.class)); |
| 20 | |
| 21 | static public final Dict.Prop<Scene> windowScene = new Dict.Prop<>("windowScene").type() |
| 22 | .toCanon() |
| 23 | .doc("Scenegraph of the main layer of the main window"); |
| 24 | |
| 25 | |
| 26 | public Meshes(Box root) { |
| 27 | this.properties.putToList(Drawing.drawers, this); |
| 28 | Optional<FieldBoxWindow> w = root.find(Boxes.window, root.both()) |
| 29 | .findFirst(); |
| 30 | this.properties.put(windowScene, w.get().getCompositor().getLayer("__main__").getScene()); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public void draw(DrawingInterface context) { |
| 35 | context.getShader().attach(new Scene.Transient(this::traverseAndDraw, 1).setOnceOnly()); |
| 36 | } |
| 37 | |
| 38 | // Exception handling! |
| 39 | protected void traverseAndDraw() { |
| 40 | this.forEach(x -> { |
| 41 | if (!x.properties.has(meshes)) return; |
| 42 | IdempotencyMap<Supplier<BaseMesh>> m = x.properties.get(meshes); |
| 43 | if (m.size() == 0) return; |
| 44 | |
| 45 | m.values().stream().filter(z -> z != null).map(z -> z.get()).filter(z -> z != null).forEach(z -> { |
| 46 | draw(z); |
| 47 | }); |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | private void draw(BaseMesh x) { |
| 52 | for (int i : x.getPasses()) { |
| 53 | x.perform(i); |
| 54 | } |
| 55 | } |
| 56 | } |
nothing calls this directly
no test coverage detected