Pick procedural parts by clicking blocks in the studio scene view

Authors could not tell which part of a procedural object placed a block. A click on a block in the Procedural view now finds its part and chooses the node that draws it; choosing a node lights up its blocks and draws everything else faintly. SceneView gains hasParts and parts (BlockParts), served as scene-parts, aligned with the scene's blocks. No pins moved: the trace bakes with its own builder and generation is untouched, ProceduralObjectsGoldenTest digests are unchanged.

v3: ff0190384
This commit is contained in:
piexel committed 2026-11-10 12:44:27 +01:00
1 parent a8aaa3c3cf
commit 8136fa857f
24 files changed
+719 -48

No files matched your search

+1 -1
View File
@@ -46,7 +46,7 @@ types that carry them and lists what the Iris adapter still owes.
| Dense chunk output | `Hunk<T>`, `GenerationContext.blocks`, reference `ArrayHunk<T>` |
| Positions, boxes and faces | `com.volmit.geometry`: `BlockPosition`, `BlockBox`, `BlockFace` |
| Sparse geometry | `GeneratedObject` |
| Studio views of what a module builds | `com.volmit.tooling`: `ModuleSetup.tooling()` (`ToolingRegistry.registerView`), sealed `StudioView` (`SceneView` with `SceneEntry`, `BakeRun` (`Stage`), `PatternView` with `PatternEntry`, `PatternArea`, `BlockPattern`), `EditableSceneView` (`SceneFile`, `NodeGraph`, `GraphNode` with `Link`, `NodeSettings`, `Edits`, `Addition`), `JsonText`, `JsonPath` (`Key`, `Index`), host `StudioViewRegistration` |
| Studio views of what a module builds | `com.volmit.tooling`: `ModuleSetup.tooling()` (`ToolingRegistry.registerView`), sealed `StudioView` (`SceneView` with `SceneEntry`, `BakeRun` (`Stage`), `BlockParts`, `PatternView` with `PatternEntry`, `PatternArea`, `BlockPattern`), `EditableSceneView` (`SceneFile`, `NodeGraph`, `GraphNode` with `Link`, `NodeSettings`, `Edits`, `Addition`), `JsonText`, `JsonPath` (`Key`, `Index`), host `StudioViewRegistration` |
| Commands of a module | `com.volmit.tooling`: `ToolingRegistry.registerCommand`, immutable `Command` (`named`, `alias`, `describe`, `child`, `argument`, `runs`, `openToEveryone`), typed `Argument` (`word`, `text`, `integer`, `decimal`, `flag`, `choice`, `resource`, `registered`, `orElse`, `suggesting`), `CommandAction`, `CommandContext` (`get`, `sender`, `pack`, `world`, `platform`), plain-text `Sender`, `ToolPack` (`edit` with `PackEdit`, `outputFolder`, `objects` with `ObjectCodec`), host `CommandRegistration` in `FeatureCatalog.commands()` |
| Buffered placement writes | `PlacementRequest`, `PlacementAccess`, host-owned `PlacementEdit` |
| Typed generation and persistent storage | `mantle` package |
+4
View File
@@ -521,6 +521,10 @@ final class RuinScenes implements SceneView {
- A `SceneView` whose entries are baked from settings says so (`isBaked`) and times a bake on request (`timeBake`, a
`BakeRun` with a time per stage). One call is one run; the studio asks five times off the server's threads and keeps
the median.
- A `SceneView` whose entries are built from parts says so (`hasParts`) and tells which part placed each block of a
scene (`parts`, a `BlockParts` keyed by the block's position in the scene). Parts are numbered as `GraphNode.part()`
numbers the nodes that draw them, so the studio lights up a node's blocks when it is chosen and chooses a node when
its block is clicked.
- A view's id is the module's id or starts with it and `/`. A second view with an id already registered fails the
pack load, naming both modules.
- The studio asks from its own threads, several at once, for a world of the pack it shows. A view keeps what it
@@ -0,0 +1,32 @@
package com.volmit.tooling;
import com.volmit.geometry.BlockPosition;
import java.util.Map;
import java.util.Objects;
/**
* Which part of an entry placed each block of one scene, as {@link SceneView#parts} reports it. A part is numbered the
* way {@link GraphNode#part()} numbers the node that draws it, so the studio can light up the blocks of a node and find
* the node of a block.
*
* @param partsByBlock the part of each block that has one, by the block's position in the scene
*/
public record BlockParts(Map<BlockPosition, Integer> partsByBlock) {
/** What {@link #partAt} answers for a block no part placed, such as a decoration. */
public static final int NO_PART = -1;
public BlockParts {
Objects.requireNonNull(partsByBlock, "partsByBlock");
partsByBlock = Map.copyOf(partsByBlock);
partsByBlock.forEach((position, part) -> {
if (part < 0) {
throw new IllegalArgumentException("Block " + position + " is in part " + part + "; parts are numbered from 0");
}
});
}
public int partAt(BlockPosition position) {
return partsByBlock.getOrDefault(position, NO_PART);
}
}
@@ -22,6 +22,20 @@ public non-sealed interface SceneView extends StudioView {
*/
Optional<GeneratedObject> scene(PackWorld world, String key, int variant);
/** Whether the entries are built from parts the studio can pick out of the scene, which {@link #parts} tells apart. */
default boolean hasParts() {
return false;
}
/**
* Which part placed each block of the scene {@link #scene} gives for the same arguments, found the way that scene
* was built. Asked off the server's threads; empty when the view has no parts, the pack has no such entry, or the
* entry has fewer variants.
*/
default Optional<BlockParts> parts(PackWorld world, String key, int variant) {
return Optional.empty();
}
/** Whether the entries are baked from settings, which costs generation time {@link #timeBake} can measure. */
default boolean isBaked() {
return false;
@@ -0,0 +1,78 @@
package com.volmit.tooling;
import com.volmit.geometry.BlockPosition;
import com.volmit.object.GeneratedObject;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class BlockPartsTest {
private static final BlockPosition TRUNK = new BlockPosition(0, 1, 0);
private static final BlockPosition DECORATION = new BlockPosition(2, 1, 0);
@Test
void answersNoPartForABlockNoPartPlaced() {
BlockParts parts = new BlockParts(Map.of(TRUNK, 3));
assertEquals(3, parts.partAt(TRUNK));
assertEquals(BlockParts.NO_PART, parts.partAt(DECORATION));
}
@Test
void keepsItsBlocksApartFromTheMapItWasGiven() {
Map<BlockPosition, Integer> given = new HashMap<>(Map.of(TRUNK, 3));
BlockParts parts = new BlockParts(given);
given.clear();
assertEquals(3, parts.partAt(TRUNK));
assertThrows(UnsupportedOperationException.class, () -> parts.partsByBlock().clear());
}
@Test
void refusesAPartBelowZero() {
assertThrows(IllegalArgumentException.class, () -> new BlockParts(Map.of(TRUNK, BlockParts.NO_PART)));
}
@Test
void aViewWithoutPartsSaysSoAndFindsNone() {
SceneView plain = new SceneView() {
@Override
public ResourceId id() {
return ResourceId.parse("test:plain");
}
@Override
public String label() {
return "Plain";
}
@Override
public String description() {
return "Plain";
}
@Override
public List<SceneEntry> entries(PackWorld world) {
return List.of();
}
@Override
public Optional<GeneratedObject> scene(PackWorld world, String key, int variant) {
return Optional.empty();
}
};
assertFalse(plain.hasParts());
assertTrue(plain.parts(null, "any", 0).isEmpty());
}
}