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

@@ -24,6 +24,7 @@ import com.volmit.geometry.BlockBox;
import com.volmit.geometry.BlockPosition;
import com.volmit.object.GeneratedObject;
import com.volmit.object.ObjectBlock;
import com.volmit.tooling.BlockParts;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -80,6 +81,19 @@ final class SceneEncoding {
return buffer.array();
}
/**
* The part of each block {@link #encode} writes, in the same order, as little endian i32 numbers; a block no part
* placed is {@link BlockParts#NO_PART}.
*/
static byte[] encodeParts(GeneratedObject scene, BlockParts parts) {
List<ObjectBlock> drawn = scene.blocks().stream().filter(block -> !isAir(block.state())).toList();
ByteBuffer buffer = ByteBuffer.allocate(drawn.size() * Integer.BYTES).order(ByteOrder.LITTLE_ENDIAN);
for (ObjectBlock block : drawn) {
buffer.putInt(parts.partAt(block.position()));
}
return buffer.array();
}
private static boolean isAir(BlockState state) {
return AIR.contains(state.material().toString());
}
@@ -54,6 +54,7 @@ import com.volmit.tooling.BlockPattern;
import com.volmit.tooling.PatternArea;
import com.volmit.tooling.PatternEntry;
import com.volmit.tooling.BakeRun;
import com.volmit.tooling.BlockParts;
import com.volmit.tooling.SceneEntry;
import java.io.IOException;
@@ -238,6 +239,7 @@ public final class StudioBridge implements AutoCloseable {
case "scene-entries" -> sendJson(exchange, STATUS_OK, sceneEntries(get(exchange).engine(), query));
case "scene-bake" -> sendJson(exchange, STATUS_OK, sceneBake(get(exchange).engine(), query));
case "scene" -> sendBytes(exchange, "application/octet-stream", scene(get(exchange).engine(), query));
case "scene-parts" -> sendBytes(exchange, "application/octet-stream", sceneParts(get(exchange).engine(), query));
case "saved-worlds" -> sendJson(exchange, STATUS_OK, savedWorlds(exchange));
case "saved-start" -> sendJson(exchange, STATUS_OK, savedStart(exchange, query));
case "saved-tile" -> sendBytes(exchange, "application/octet-stream", savedTile(get(exchange).engine(), query));
@@ -339,7 +341,7 @@ public final class StudioBridge implements AutoCloseable {
StudioEditors editors = StudioEditors.of(engine);
StudioScenes scenes = StudioScenes.of(engine);
return scenes.views().stream()
.map(view -> new SceneViewInfo(view.id(), view.label(), view.description(), editors.edits(view.id()), scenes.isBaked(view.id())))
.map(view -> new SceneViewInfo(view.id(), view.label(), view.description(), editors.edits(view.id()), scenes.isBaked(view.id()), scenes.hasParts(view.id())))
.toList();
}
@@ -422,6 +424,21 @@ public final class StudioBridge implements AutoCloseable {
return SceneEncoding.encode(scene.orElseThrow(() -> new RequestError(STATUS_NOT_FOUND, "No scene " + key)), gson);
}
private static byte[] sceneParts(Engine engine, Query query) {
String key = query.text("key");
int variant = query.whole("variant", 0);
try {
StudioScenes scenes = StudioScenes.of(engine);
GeneratedObject scene = scenes.scene(query.text("view"), key, variant)
.orElseThrow(() -> new RequestError(STATUS_NOT_FOUND, "No scene " + key));
BlockParts parts = scenes.parts(query.text("view"), key, variant)
.orElseThrow(() -> new RequestError(STATUS_NOT_FOUND, "No parts for " + key));
return SceneEncoding.encodeParts(scene, parts);
} catch (NoSuchElementException unknown) {
throw new RequestError(STATUS_NOT_FOUND, unknown.getMessage());
}
}
private static List<PatternEntryWire> patternEntries(Engine engine, Query query) {
try {
return StudioPatterns.of(engine).entries(query.text("view")).stream().map(PatternEntryWire::of).toList();
@@ -751,8 +768,8 @@ public final class StudioBridge implements AutoCloseable {
private record ErrorBody(String error) {
}
/** A scene view as the studio lists it; {@code editable} when its entries can be edited as nodes, {@code baked} when their bake can be timed. */
private record SceneViewInfo(String id, String label, String description, boolean editable, boolean baked) {
/** A scene view as the studio lists it; {@code editable} when its entries can be edited as nodes, {@code baked} when their bake can be timed, {@code parts} when the blocks of a scene can be told by the part that placed them. */
private record SceneViewInfo(String id, String label, String description, boolean editable, boolean baked, boolean parts) {
}
/** A {@link SceneEntry} as the studio reads it, with a blank group for none. */
@@ -21,6 +21,7 @@ package art.arcane.iris.core.studio.scene;
import art.arcane.iris.engine.framework.Engine;
import com.volmit.object.GeneratedObject;
import com.volmit.tooling.BakeRun;
import com.volmit.tooling.BlockParts;
import com.volmit.tooling.SceneEntry;
import com.volmit.tooling.SceneView;
@@ -58,6 +59,21 @@ public final class StudioScenes {
return views.ask(viewId, "build " + key, view -> view.scene(views.world(), key, variant));
}
/** @throws NoSuchElementException when no module registered a scene view {@code viewId} */
public boolean hasParts(String viewId) {
return views.ask(viewId, "say whether it has parts", SceneView::hasParts);
}
/**
* Which part placed each block of the scene {@link #scene} gives for the same arguments; empty when the view has no
* such entry or variant, or no parts.
*
* @throws NoSuchElementException when no module registered a scene view {@code viewId}
*/
public Optional<BlockParts> parts(String viewId, String key, int variant) {
return views.ask(viewId, "find the parts of " + key, view -> view.parts(views.world(), key, variant));
}
/** @throws NoSuchElementException when no module registered a scene view {@code viewId} */
public boolean isBaked(String viewId) {
return views.ask(viewId, "say whether it bakes", SceneView::isBaked);