From 4950cf19691b6f3b37f133d6a1e3a85c6b443c83 Mon Sep 17 00:00:00 2001 From: piexel Date: Tue, 10 Nov 2026 12:15:21 +0100 Subject: [PATCH] Show far leaves in the studio scene view The engine makes leaves with no wood in reach persistent, but the studio gave no sign of which ones they are. The block list of a scene now counts the leaves too far from wood and can draw only them. The rule is kept in step with IrisProceduralBlocks.isLeafTooFarFromWood by a comment on both. v3: eb3bae72d --- .../procedural/IrisProceduralBlocks.java | 5 +- .../src/renderer/src/scene/farLeaves.test.ts | 32 +++++++ studio/src/renderer/src/scene/farLeaves.ts | 26 ++++++ studio/src/renderer/src/scene/sceneMesh.ts | 19 ++++- .../src/renderer/src/studio/SceneStudio.tsx | 83 ++++++++++++++----- 5 files changed, 141 insertions(+), 24 deletions(-) create mode 100644 studio/src/renderer/src/scene/farLeaves.test.ts create mode 100644 studio/src/renderer/src/scene/farLeaves.ts diff --git a/module/src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java b/module/src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java index 8328b8d65..231b80ca5 100644 --- a/module/src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java +++ b/module/src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java @@ -40,7 +40,10 @@ public final class IrisProceduralBlocks { private IrisProceduralBlocks() { } - /** Whether {@code state} is a leaf baked with no wood near enough for vanilla to keep it. */ + /** + * Whether {@code state} is a leaf baked with no wood near enough for vanilla to keep it. The studio counts these + * in {@code scene/farLeaves.ts} with the same rule; change both together. + */ public static boolean isLeafTooFarFromWood(BlockState state) { return hasProperty(state, "persistent") && String.valueOf(UNREACHED_LEAF_DISTANCE).equals(propertyValue(state, "distance")); } diff --git a/studio/src/renderer/src/scene/farLeaves.test.ts b/studio/src/renderer/src/scene/farLeaves.test.ts new file mode 100644 index 000000000..c58c31e14 --- /dev/null +++ b/studio/src/renderer/src/scene/farLeaves.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from 'vitest' +import { countFarLeaves, isFarLeaf } from './farLeaves' +import type { BlockScene } from './sceneDecoding' + +function sceneOf(palette: string[], ...indexes: number[]): BlockScene { + const blocks = new Int32Array(indexes.flatMap((index, position) => [position, 0, 0, index])) + return { palette, blocks, min: [0, 0, 0], max: [indexes.length, 1, 1] } +} + +describe('far leaves', () => { + it('takes a leaf with the persistent property at distance 7', () => { + expect(isFarLeaf('minecraft:oak_leaves[distance=7,persistent=true,waterlogged=false]')).toBe(true) + expect(isFarLeaf('minecraft:oak_leaves[distance=7,persistent=false]')).toBe(true) + }) + + it('leaves out leaves near wood, leaves without the persistent property, and other blocks', () => { + expect(isFarLeaf('minecraft:oak_leaves[distance=6,persistent=true]')).toBe(false) + expect(isFarLeaf('minecraft:oak_leaves[distance=7]')).toBe(false) + expect(isFarLeaf('minecraft:oak_log[axis=y]')).toBe(false) + expect(isFarLeaf('minecraft:stone')).toBe(false) + }) + + it('counts the blocks of the scene that are far leaves, not the palette entries', () => { + const scene = sceneOf(['minecraft:stone', 'minecraft:oak_leaves[distance=7,persistent=true]', 'minecraft:oak_leaves[distance=1,persistent=false]'], 1, 0, 1, 2, 1) + + expect(countFarLeaves(scene)).toBe(3) + }) + + it('counts none in a scene without leaves', () => { + expect(countFarLeaves(sceneOf(['minecraft:stone'], 0, 0))).toBe(0) + }) +}) diff --git a/studio/src/renderer/src/scene/farLeaves.ts b/studio/src/renderer/src/scene/farLeaves.ts new file mode 100644 index 000000000..6f1cd7d1a --- /dev/null +++ b/studio/src/renderer/src/scene/farLeaves.ts @@ -0,0 +1,26 @@ +import { parseState } from './blockModels' +import { INTS_PER_BLOCK, type BlockScene } from './sceneDecoding' + +const PERSISTENT_PROPERTY = 'persistent' +const DISTANCE_PROPERTY = 'distance' + +/** The distance vanilla gives a leaf with no wood near enough to keep it; IrisProceduralBlocks.UNREACHED_LEAF_DISTANCE. */ +const UNREACHED_LEAF_DISTANCE = '7' + +/** Whether a block state is a leaf baked with no wood near enough for vanilla to keep it; the rule of IrisProceduralBlocks.isLeafTooFarFromWood. */ +export function isFarLeaf(state: string): boolean { + const { properties } = parseState(state) + return PERSISTENT_PROPERTY in properties && properties[DISTANCE_PROPERTY] === UNREACHED_LEAF_DISTANCE +} + +/** How many blocks of the scene are leaves too far from wood. */ +export function countFarLeaves(scene: BlockScene): number { + const far = scene.palette.map(isFarLeaf) + let count = 0 + for (let offset = 3; offset < scene.blocks.length; offset += INTS_PER_BLOCK) { + if (far[scene.blocks[offset]]) { + count++ + } + } + return count +} diff --git a/studio/src/renderer/src/scene/sceneMesh.ts b/studio/src/renderer/src/scene/sceneMesh.ts index 07fd89746..b26b16bdf 100644 --- a/studio/src/renderer/src/scene/sceneMesh.ts +++ b/studio/src/renderer/src/scene/sceneMesh.ts @@ -2,6 +2,7 @@ import { Box3, BufferAttribute, BufferGeometry, Mesh, MeshBasicMaterial } from ' import type { ViewportContent } from '../studio/SceneViewport' import { cubeModel, parseState, type BlockModels, type BlockModel, type Direction, type Quad } from './blockModels' import { blockTint } from './blockTints' +import { countFarLeaves, isFarLeaf } from './farLeaves' import { INTS_PER_BLOCK, type BlockScene } from './sceneDecoding' import { TextureAtlas, type ImageSource } from './textureAtlas' @@ -35,10 +36,16 @@ interface PaletteEntry { properties: Record /** Hides the faces of its neighbours that touch it. */ solid: boolean + /** Whether its blocks are drawn at all. */ + shown: boolean } -/** One geometry for the whole scene, its faces against solid neighbours left out, textured from one atlas. */ -export async function buildSceneMesh(scene: BlockScene, models: BlockModels, images: ImageSource): Promise { +/** + * One geometry for the whole scene, its faces against solid neighbours left out, textured from one atlas. With + * `farLeavesOnly` and far leaves in the scene, nothing but them is drawn. + */ +export async function buildSceneMesh(scene: BlockScene, models: BlockModels, images: ImageSource, farLeavesOnly = false): Promise { + const singlingOutFarLeaves = farLeavesOnly && countFarLeaves(scene) > 0 const resolved = await Promise.all(scene.palette.map((state) => models.model(state))) const unknownStates = scene.palette.filter((_, index) => resolved[index] === null) const drawn = resolved.map((model) => drawnModel(model)) @@ -48,8 +55,9 @@ export async function buildSceneMesh(scene: BlockScene, models: BlockModels, ima ) const palette = drawn.map((model, index): PaletteEntry => { const state = parseState(scene.palette[index]) - const solid = model.fullCube && model.quads.every((quad) => atlas.cell(quad.texture).solid) - return { model, name: state.name, properties: state.properties, solid } + const shown = !singlingOutFarLeaves || isFarLeaf(scene.palette[index]) + const solid = shown && model.fullCube && model.quads.every((quad) => atlas.cell(quad.texture).solid) + return { model, name: state.name, properties: state.properties, solid, shown } }) const geometry = geometryOf(scene, palette, atlas) const material = new MeshBasicMaterial({ map: atlas.texture, vertexColors: true, alphaTest: CUTOUT_ALPHA }) @@ -83,6 +91,9 @@ function geometryOf(scene: BlockScene, palette: PaletteEntry[], atlas: TextureAt for (let offset = 0; offset < blocks.length; offset += INTS_PER_BLOCK) { const [x, y, z, paletteIndex] = [blocks[offset], blocks[offset + 1], blocks[offset + 2], blocks[offset + 3]] const entry = palette[paletteIndex] + if (!entry.shown) { + continue + } for (const quad of entry.model.quads) { if (quad.cullFace !== null && solids.besides(x, y, z, quad.cullFace)) { continue diff --git a/studio/src/renderer/src/studio/SceneStudio.tsx b/studio/src/renderer/src/studio/SceneStudio.tsx index a7c220733..63b364721 100644 --- a/studio/src/renderer/src/studio/SceneStudio.tsx +++ b/studio/src/renderer/src/studio/SceneStudio.tsx @@ -10,6 +10,7 @@ import { nodeWithPath } from '../editor/nodeLayout' import { useNodeEditor } from '../editor/useNodeEditor' import { BlockModels } from '../scene/blockModels' import { BridgeAssets } from '../scene/BridgeAssets' +import { countFarLeaves } from '../scene/farLeaves' import { INTS_PER_BLOCK, type BlockScene } from '../scene/sceneDecoding' import { buildSceneMesh, type SceneMesh } from '../scene/sceneMesh' import { BakeMeter, useBakeTiming } from './BakeMeter' @@ -20,6 +21,7 @@ import { SceneViewport } from './SceneViewport' const NUMBER = new Intl.NumberFormat('en-US') const DEFAULT_NAMESPACE_PREFIX = 'minecraft:' +const FAR_LEAVES_HINT = 'Leaves more than 6 blocks from wood. Vanilla would let them decay, so they are made persistent.' interface SceneStudioProps { client: BridgeClient @@ -43,7 +45,8 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce const [chosen, setChosen] = useState<{ key: string; variant: number } | null>(null) const entry = entries.find((candidate) => candidate.key === chosen?.key) ?? entries[0] ?? null const variant = entry !== null && chosen?.key === entry.key ? Math.min(chosen.variant, entry.variants - 1) : 0 - const { scene, mesh, building } = useSceneMesh(client, view.id, entry, variant, packRevision, models, images, tell) + const [farLeavesOnly, setFarLeavesOnly] = useState(false) + const { scene, shown, building } = useSceneMesh(client, view.id, entry, variant, packRevision, models, images, farLeavesOnly, tell) const chooseVariant = (next: number): void => { if (entry !== null) { setChosen({ key: entry.key, variant: (next + entry.variants) % entry.variants }) @@ -67,7 +70,7 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce @@ -81,7 +84,7 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce {selected !== null && editor.state !== null ? ( ) : ( - + )} @@ -91,16 +94,16 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce interface SceneAreaProps { entry: SceneEntry | null variant: number - mesh: SceneMesh | null + shown: ShownScene | null /** What is being built, or null when nothing is. */ status: string | null onVariant(variant: number): void } -function SceneArea({ entry, variant, mesh, status, onVariant }: SceneAreaProps): React.JSX.Element { +function SceneArea({ entry, variant, shown, status, onVariant }: SceneAreaProps): React.JSX.Element { return (
- + {entry !== null && entry.variants > 1 && (
+
+ )}
{counts.map(([state, count]) => (