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

@@ -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());
}
}