Layer & Transparency Logic
Relevant source files
The following files were used as context for generating this wiki page:
Layer and Transparency Logic in HoloPrint governs the visual representation of structural holograms, allowing users to isolate specific vertical sections of a build and adjust its visibility. This system utilizes a combination of Minecraft Bedrock's Molang scripting, render controllers, and web-based preview logic to ensure that ghost blocks are both navigable and visually distinct from the environment.
The logic is split between two primary concerns: Layer Management, which handles the vertical slicing of structures (Y-level isolation), and Transparency Logic, which manages the alpha-blending, tinting, and opacity levels of the rendered blocks.
Layer Management
HoloPrint organizes structure data into discrete vertical layers based on the Y-coordinate. This allows builders to focus on one floor or section at a time. The system supports two primary modes: SINGLE (rendering only the current Y-level) and ALL_BELOW (rendering the current Y-level and all blocks beneath it).
Layer Modes and Transitions
The layer state is managed via an animation controller that transitions between states based on the Molang variable v.hologram.layer and v.hologram.layer_mode. When in "Mini Display" mode, layers that are not currently active are scaled down using the config.MINI_SCALE value to provide context without obstructing the workspace.
Animation Controller Implementation
The makeLayerAnimations function dynamically generates the animation states for the Bedrock resource pack. It iterates through the structure's height and creates specific bone animations for each layer. If a layer is not active, its bone scale is set to the MINI_SCALE (defaulting to 0.125 or as configured in the UI).
| Component | Description | Molang / Config Reference |
|---|---|---|
| Current Layer | The Y-level currently selected by the user. | v.hologram.layer |
| Layer Mode | Determines if only one layer or all below are shown. | v.hologram.layer_mode |
| Mini Scale | The size multiplier for inactive context layers. | config.MINI_SCALE |
| Top Layer | The maximum height of the structure. | structureSizes[structureI][1] |
Sources: src/HoloPrint.js:525, src/HoloPrint.js:782-800, src/index.html:150-155
Transparency and Opacity Logic
Transparency is handled through Bedrock render controllers and a custom texture atlas system. The project supports both static opacity and dynamic "in-game" opacity switching by swapping texture indices.
Texture-Based Opacity
The resource pack includes multiple versions of the texture atlas with varying transparency levels. The render controller selects the appropriate texture from an array using v.hologram.texture_index.
Tinting and Overlays
A secondary layer of transparency is applied via the overlay_color. This allows a global tint to be applied to the hologram, which can be toggled in-game.
- Overlay Color: A quartet
[r, g, b, a]derived fromconfig.TINT_COLORandconfig.TINT_OPACITY. - Wrong Block Overlay: Uses a specific red overlay (
v.hologram.show_wrong_block_overlay) to highlight discrepancies during structure validation.
Sources: src/HoloPrint.js:476-483, src/packTemplate/render_controllers/holoprint.hologram.render_controllers.json:34-40
Web Preview Transparency Logic
In the web-based PreviewRenderer, transparency is managed using Three.js materials. The system performs an alpha test on block templates to determine if they should be treated as translucent.
- Alpha Test: A value of
0.2is used foralphaTestto discard near-transparent pixels. - Translucency Check: The
PreviewRendereriterates through the image data of the texture atlas. If any pixel in a block's UV range has an alpha value between 1 and 254, the entire block geometry is flagged astransparent: true.
Sources: src/PreviewRenderer.js:315-325, src/PreviewRenderer.js:462-491
Configuration Summary
The following settings in the generation phase directly influence the layer and transparency behaviors:
| Setting | Type | Default | Description |
|---|---|---|---|
SCALE | Number | 0.95 | The overall scale of the ghost blocks (preventing Z-fighting). |
OPACITY | Number | 0.90 | The alpha value for the single-option opacity mode. |
TINT_OPACITY | Number | 0.20 | The alpha value for the color overlay. |
MINI_SCALE | Number | 0.125 | The scale of inactive layers in the UI view. |
MULTIPLE_OPACITIES | Boolean | true | Whether to allow switching opacity levels in-game. |
Sources: src/HoloPrint.js:520-535, src/index.js:424-440
Conclusion
The Layer & Transparency Logic provides a highly configurable visualization system. By leveraging Bedrock's render_controllers for texture swapping and Molang-driven animations for vertical slicing, the system achieves complex UI-like behavior (such as "Mini Display" layers) within the constraints of a Minecraft resource pack. This ensures that users can maintain clarity even when working with large, complex structures.