mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Show decorators, snippets and ground cover in the studio
Decorators get their own pattern view from the decorant module: each biome's decorators from above, placed where their own noise allows. The Palettes and Decorators views list the pack's snippet files in a Snippets group, with the biomes that use each one, and mark entries read from a snippet. PackResources gains snippetOf and snippets so a module can tell where a settings value came from. The 3D world draws what stands on the ground, such as grass and flowers, as the block's own model. A plugin block that is solid on the server but shown to players as a plant no longer counts as ground.
This commit is contained in:
1 parent
67063b02d7
commit
55f6a06f9f
30 files changed
+1172
-71
No files matched your search
@@ -46,7 +46,7 @@ export function decodeTile(buffer: ArrayBuffer): MapTile {
|
||||
blocks:
|
||||
header.blocks == null
|
||||
? null
|
||||
: { names: header.blocks, ground: new Int16Array(buffer, groundAt, cells), cover: new Int16Array(buffer, coverAt, cells), colors: [], looks: [] }
|
||||
: { names: header.blocks, ground: new Int16Array(buffer, groundAt, cells), cover: new Int16Array(buffer, coverAt, cells), colors: [], looks: [], covers: [] }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** The shapes the Iris bridge answers with (Iris core, art.arcane.iris.core.studio). */
|
||||
|
||||
import type { BlockLook } from '../scene/blockLooks'
|
||||
import type { CoverLook } from '../scene/coverLooks'
|
||||
|
||||
export type LabelKind = 'BIOME' | 'REGION'
|
||||
|
||||
@@ -355,6 +356,8 @@ export interface TileBlocks {
|
||||
colors: number[]
|
||||
/** What each named block looks like on a column, where the tile is fine enough to show textures; else empty. */
|
||||
looks: (BlockLook | null)[]
|
||||
/** What each named block looks like standing on the ground, for the blocks {@link cover} names, on a tile that shows textures; else empty. */
|
||||
covers: (CoverLook | null)[]
|
||||
}
|
||||
|
||||
export const NO_BLOCK = -1
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('tile style', () => {
|
||||
const cells = tile.subjects.length
|
||||
const cover = new Int16Array(cells).fill(-1)
|
||||
cover[gridIndex(tile, 3, 3)] = 1
|
||||
const blocks = { names: ['stone', 'poppy'], ground: new Int16Array(cells).fill(0), cover, colors: [0x808080, 0xff0000], looks: [] }
|
||||
const blocks = { names: ['stone', 'poppy'], ground: new Int16Array(cells).fill(0), cover, colors: [0x808080, 0xff0000], looks: [], covers: [] }
|
||||
const pixels = stylePixels({ ...tile, blocks }, { ...FLAT, byBlock: true })
|
||||
|
||||
expect(pixel(pixels, 4, 0, 0)).toBe(0x808080)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { BridgeClient } from '../bridge/BridgeClient'
|
||||
import type { TileBlocks } from '../bridge/types'
|
||||
import { NO_BLOCK, type TileBlocks } from '../bridge/types'
|
||||
import { BlockColors } from './blockColors'
|
||||
import { BlockLooks } from './blockLooks'
|
||||
import { BlockModels } from './blockModels'
|
||||
@@ -15,6 +15,13 @@ export interface BlockArt {
|
||||
dispose(): void
|
||||
}
|
||||
|
||||
// Only these have their whole model's pictures placed, so the ground's blocks take no room in the atlas for faces a column never shows.
|
||||
function namesStandingOnGround(blocks: TileBlocks): string[] {
|
||||
const standing = new Set<number>(blocks.cover)
|
||||
standing.delete(NO_BLOCK)
|
||||
return [...standing].map((index) => blocks.names[index])
|
||||
}
|
||||
|
||||
/** Block art read from the Minecraft client's assets through the bridge; {@code textured} art can also show textures. */
|
||||
export function blockArt(client: BridgeClient, textured: boolean): BlockArt {
|
||||
const images = new BridgeAssets(client, () => {})
|
||||
@@ -25,9 +32,15 @@ export function blockArt(client: BridgeClient, textured: boolean): BlockArt {
|
||||
return {
|
||||
atlas,
|
||||
paint: async (blocks, withLooks) => {
|
||||
const [colorOf, lookOf] = await Promise.all([colors.colorsOf(blocks.names), withLooks && looks !== null ? looks.looksOf(blocks.names) : null])
|
||||
const shownLooks = withLooks ? looks : null
|
||||
const [colorOf, lookOf, coverOf] = await Promise.all([
|
||||
colors.colorsOf(blocks.names),
|
||||
shownLooks?.looksOf(blocks.names) ?? null,
|
||||
shownLooks?.coversOf(namesStandingOnGround(blocks)) ?? null
|
||||
])
|
||||
blocks.colors = blocks.names.map((name) => colorOf.get(name)!)
|
||||
blocks.looks = lookOf === null ? [] : blocks.names.map((name) => lookOf.get(name) ?? null)
|
||||
blocks.covers = coverOf === null ? [] : blocks.names.map((name) => coverOf.get(name) ?? null)
|
||||
},
|
||||
dispose: () => atlas?.dispose()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { parseState, type BlockModel, type Direction, type ParsedState } from './blockModels'
|
||||
import { blockTint } from './blockTints'
|
||||
import { coverLookOf, type CoverLook } from './coverLooks'
|
||||
import type { PictureSource, UvCell } from './terrainAtlas'
|
||||
|
||||
const NO_TINT_INDEX = -1
|
||||
@@ -68,6 +69,7 @@ function untintedFacing(model: BlockModel, facing: Direction): FaceTexture | nul
|
||||
/** The look of each block state the terrain draws, read once. */
|
||||
export class BlockLooks {
|
||||
private readonly looks = new Map<string, Promise<BlockLook | null>>()
|
||||
private readonly covers = new Map<string, Promise<CoverLook | null>>()
|
||||
private dirtBottom: Promise<string | null> | null = null
|
||||
|
||||
constructor(
|
||||
@@ -85,6 +87,25 @@ export class BlockLooks {
|
||||
return look
|
||||
}
|
||||
|
||||
/** What each block looks like standing on the ground, by name; null for one that is not drawn there. */
|
||||
async coversOf(blocks: Iterable<string>): Promise<Map<string, CoverLook | null>> {
|
||||
const names = [...new Set(blocks)]
|
||||
const looks = await Promise.all(names.map((name) => this.coverOf(name)))
|
||||
return new Map(names.map((name, index) => [name, looks[index]]))
|
||||
}
|
||||
|
||||
private coverOf(block: string): Promise<CoverLook | null> {
|
||||
let cover = this.covers.get(block)
|
||||
if (cover === undefined) {
|
||||
cover = this.models
|
||||
.model(block)
|
||||
.then((model) => coverLookOf(block, model, this.pictures))
|
||||
.catch(() => null)
|
||||
this.covers.set(block, cover)
|
||||
}
|
||||
return cover
|
||||
}
|
||||
|
||||
/** Every block's look, by name. */
|
||||
async looksOf(blocks: Iterable<string>): Promise<Map<string, BlockLook | null>> {
|
||||
const names = [...new Set(blocks)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { BlockLook } from './blockLooks'
|
||||
import type { CoverLook } from './coverLooks'
|
||||
import type { TerrainPictures } from './terrainAtlas'
|
||||
import type { TerrainSurface } from './terrainMesh'
|
||||
import type { ColumnArea } from './terrainTiles'
|
||||
@@ -21,6 +22,8 @@ export class ColumnField {
|
||||
readonly color: Int32Array
|
||||
/** What each column's block looks like, or null to show its colour. */
|
||||
readonly looks: (BlockLook | null)[]
|
||||
/** What stands on each column's ground, or null for nothing that is drawn. */
|
||||
readonly covers: (CoverLook | null)[]
|
||||
/** The atlas of the looks, or null where no column has one. */
|
||||
readonly pictures: TerrainPictures | null
|
||||
/** How low and high the top faces stand, ground and water alike; null where no column has ground. */
|
||||
@@ -37,6 +40,7 @@ export class ColumnField {
|
||||
this.waterTop = new Float32Array(count).fill(NO_VALUE)
|
||||
this.color = new Int32Array(count)
|
||||
this.looks = new Array<BlockLook | null>(count).fill(null)
|
||||
this.covers = new Array<CoverLook | null>(count).fill(null)
|
||||
const hasPictures = surface.pictures !== undefined
|
||||
let anyLook = false
|
||||
let [lowestTop, highestTop] = [Infinity, -Infinity]
|
||||
@@ -54,6 +58,7 @@ export class ColumnField {
|
||||
this.color[index] = surface.colorAt(column, row)
|
||||
const look = hasPictures ? (surface.lookAt?.(column, row) ?? null) : null
|
||||
this.looks[index] = look
|
||||
this.covers[index] = hasPictures ? (surface.coverAt?.(column, row) ?? null) : null
|
||||
anyLook ||= look !== null
|
||||
lowestTop = Math.min(lowestTop, ground + 1)
|
||||
highestTop = Math.max(highestTop, ground + 1, water === null ? ground : water + 1)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { BufferAttribute, BufferGeometry } from 'three'
|
||||
import type { ColumnField } from './columnField'
|
||||
|
||||
const CORNERS_PER_FACE = 4
|
||||
const INDICES_PER_FACE = 6
|
||||
|
||||
/**
|
||||
* What stands on the ground, such as grass, flowers and layers of snow: each column's cover as its block's own model,
|
||||
* set on the column's top face. Null where no column has a cover.
|
||||
*/
|
||||
export function coverGeometry(field: ColumnField): BufferGeometry | null {
|
||||
const faces = field.covers.reduce((count, cover) => count + (cover?.faces.length ?? 0), 0)
|
||||
if (faces === 0) {
|
||||
return null
|
||||
}
|
||||
const positions = new Float32Array(faces * CORNERS_PER_FACE * 3)
|
||||
const uvs = new Float32Array(faces * CORNERS_PER_FACE * 2)
|
||||
const colors = new Float32Array(faces * CORNERS_PER_FACE * 3)
|
||||
const indices = new Uint32Array(faces * INDICES_PER_FACE)
|
||||
const step = field.blocksPerColumn
|
||||
let face = 0
|
||||
for (let row = 0; row < field.rows; row++) {
|
||||
for (let column = 0; column < field.columns; column++) {
|
||||
const index = field.indexOf(column, row)
|
||||
const [x, y, z] = [field.originX + column * step, field.groundTop[index], field.originZ + row * step]
|
||||
for (const { corners, uvs: faceUvs, cell, color } of field.covers[index]?.faces ?? []) {
|
||||
const first = face * CORNERS_PER_FACE
|
||||
for (let corner = 0; corner < CORNERS_PER_FACE; corner++) {
|
||||
const [cornerX, cornerY, cornerZ] = corners[corner]
|
||||
positions.set([x + cornerX * step, y + cornerY, z + cornerZ * step], (first + corner) * 3)
|
||||
uvs.set([cell.u + faceUvs[corner][0] * cell.width, cell.v + faceUvs[corner][1] * cell.height], (first + corner) * 2)
|
||||
colors.set(color, (first + corner) * 3)
|
||||
}
|
||||
indices.set([first, first + 1, first + 2, first, first + 2, first + 3], face * INDICES_PER_FACE)
|
||||
face++
|
||||
}
|
||||
}
|
||||
}
|
||||
const geometry = new BufferGeometry()
|
||||
geometry.setAttribute('position', new BufferAttribute(positions, 3))
|
||||
geometry.setAttribute('uv', new BufferAttribute(uvs, 2))
|
||||
geometry.setAttribute('color', new BufferAttribute(colors, 3))
|
||||
geometry.setIndex(new BufferAttribute(indices, 1))
|
||||
return geometry
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { parseState, type BlockModel, type Direction, type Quad } from './blockModels'
|
||||
import { blockTint } from './blockTints'
|
||||
import type { PictureSource, UvCell } from './terrainAtlas'
|
||||
|
||||
/** The light Minecraft gives each side of a block without shadows: the top brightest, the bottom darkest. */
|
||||
export const FACE_LIGHT: Record<Direction, number> = { up: 1, down: 0.5, north: 0.8, south: 0.8, west: 0.6, east: 0.6 }
|
||||
|
||||
/** One face of a block that stands on the ground, in block units from the block's lowest corner. */
|
||||
export interface CoverFace {
|
||||
corners: Quad['corners']
|
||||
uvs: Quad['uvs']
|
||||
cell: UvCell
|
||||
/** The face's tint in its light, as red, green and blue from 0 to 1. */
|
||||
color: readonly [number, number, number]
|
||||
}
|
||||
|
||||
/** A block standing on a column's ground, such as grass, a flower or a layer of snow, as the faces of its model. */
|
||||
export interface CoverLook {
|
||||
faces: CoverFace[]
|
||||
}
|
||||
|
||||
/**
|
||||
* The block's model with its pictures placed; null for a block the client draws without a model, such as a chest, or
|
||||
* when one of its pictures cannot be placed, so a cover is drawn whole or not at all.
|
||||
*/
|
||||
export async function coverLookOf(block: string, model: BlockModel | null, pictures: PictureSource): Promise<CoverLook | null> {
|
||||
if (model === null || model.quads.length === 0) {
|
||||
return null
|
||||
}
|
||||
const state = parseState(block)
|
||||
const faces = await Promise.all(
|
||||
model.quads.map(async (quad): Promise<CoverFace | null> => {
|
||||
const cell = await pictures.cellOf(quad.texture)
|
||||
if (cell === null) {
|
||||
return null
|
||||
}
|
||||
const tint = blockTint(state.name, state.properties, quad.tintIndex)
|
||||
const light = quad.shade ? FACE_LIGHT[quad.facing] : 1
|
||||
const color = [(((tint >> 16) & 0xff) / 255) * light, (((tint >> 8) & 0xff) / 255) * light, ((tint & 0xff) / 255) * light] as const
|
||||
return { corners: quad.corners, uvs: quad.uvs, cell, color }
|
||||
})
|
||||
)
|
||||
return faces.includes(null) ? null : { faces: faces as CoverFace[] }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NO_BLOCK, NO_LABEL, type MapTile } from '../bridge/types'
|
||||
import { heightColor } from '../map/heightColors'
|
||||
import type { BlockLook } from './blockLooks'
|
||||
import type { CoverLook } from './coverLooks'
|
||||
import type { TerrainPictures } from './terrainAtlas'
|
||||
import type { TerrainSurface } from './terrainMesh'
|
||||
import { blocksPerColumn, originXOf, originZOf, type TerrainTile } from './terrainTiles'
|
||||
@@ -48,6 +49,14 @@ export class MapTerrain implements TerrainSurface {
|
||||
return ground === NO_BLOCK ? null : (this.tile.blocks!.looks[ground] ?? null)
|
||||
}
|
||||
|
||||
coverAt(column: number, row: number): CoverLook | null {
|
||||
if (this.groundBlockAt(column, row) === NO_BLOCK) {
|
||||
return null
|
||||
}
|
||||
const cover = this.tile.blocks!.cover[this.cellAt(column, row)]
|
||||
return cover === NO_BLOCK ? null : (this.tile.blocks!.covers[cover] ?? null)
|
||||
}
|
||||
|
||||
colorAt(column: number, row: number): number {
|
||||
if (this.coloring === 'height') {
|
||||
return heightColor(this.heightAt(column, row), this.fluidHeight)
|
||||
|
||||
@@ -9,7 +9,7 @@ const GRASS = 'minecraft:grass_block[snowy=false]'
|
||||
const STONE = 'minecraft:stone'
|
||||
const FACE = { cell: cellAt(1, 0x808080), tint: 0xffffff, color: 0x808080 }
|
||||
const LOOK: BlockLook = { top: FACE, side: FACE, below: FACE }
|
||||
const pictures: TerrainPictures = { texture: new Texture(), plain: cellAt(0, 0xffffff) }
|
||||
const pictures: TerrainPictures = { texture: new Texture(), cutouts: new Texture(), plain: cellAt(0, 0xffffff) }
|
||||
|
||||
// Two by two columns: grass, stone, then two of stone.
|
||||
const tile = {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Box3, BufferAttribute, BufferGeometry, Group, Mesh, MeshBasicMaterial }
|
||||
import type { ViewportContent } from '../studio/SceneViewport'
|
||||
import { cubeModel, parseState, type BlockModels, type BlockModel, type Direction, type Quad } from './blockModels'
|
||||
import { blockTint } from './blockTints'
|
||||
import { FACE_LIGHT } from './coverLooks'
|
||||
import { countFarLeaves, isFarLeaf } from './farLeaves'
|
||||
import { INTS_PER_BLOCK, type BlockScene } from './sceneDecoding'
|
||||
import { TextureAtlas, type ImageSource } from './textureAtlas'
|
||||
@@ -18,8 +19,6 @@ const CUTOUT_ALPHA = 0.1
|
||||
/** How much of a faint block shows, from 0 for none to 1 for all. */
|
||||
const FAINT_OPACITY = 0.12
|
||||
|
||||
/** The light Minecraft gives each side of a block without shadows: the top brightest, the bottom darkest. */
|
||||
const FACE_LIGHT: Record<Direction, number> = { up: 1, down: 0.5, north: 0.8, south: 0.8, west: 0.6, east: 0.6 }
|
||||
const MISSING_TEXTURE = 'iris:missing'
|
||||
const NEIGHBOUR_OFFSETS: Record<Direction, [number, number, number]> = {
|
||||
down: [0, -1, 0],
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface UvCell {
|
||||
/** The atlas as the terrain draws it. */
|
||||
export interface TerrainPictures {
|
||||
readonly texture: Texture
|
||||
/** Laid out as {@link texture}: white where a picture is drawn and black where it is open, for faces that are cut out. */
|
||||
readonly cutouts: Texture
|
||||
/** A cell of plain white, for faces that show only their colour. */
|
||||
readonly plain: UvCell
|
||||
}
|
||||
@@ -55,25 +57,21 @@ export const MOST_CELLS = CELLS_PER_SIDE * CELLS_PER_SIDE
|
||||
*/
|
||||
export class TerrainAtlas implements TerrainPictures, PictureSource {
|
||||
readonly texture: CanvasTexture
|
||||
readonly cutouts: CanvasTexture
|
||||
readonly plain = cellAt(PLAIN_CELL, WHITE_COLOR)
|
||||
|
||||
private readonly drawing: CanvasRenderingContext2D
|
||||
private readonly cutoutDrawing: CanvasRenderingContext2D
|
||||
private readonly cells = new Map<string, Promise<UvCell | null>>()
|
||||
private used = PLAIN_CELL + 1
|
||||
|
||||
constructor(private readonly images: ImageSource) {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = ATLAS_PIXELS
|
||||
canvas.height = ATLAS_PIXELS
|
||||
this.drawing = canvas.getContext('2d', { willReadFrequently: true })!
|
||||
this.drawing.imageSmoothingEnabled = false
|
||||
this.drawing.fillStyle = WHITE
|
||||
this.drawing.fillRect(0, 0, CELL_PIXELS, CELL_PIXELS)
|
||||
this.texture = new CanvasTexture(canvas)
|
||||
this.texture.magFilter = NearestFilter
|
||||
this.texture.minFilter = NearestFilter
|
||||
this.texture.generateMipmaps = false
|
||||
this.texture.flipY = false
|
||||
;[this.drawing, this.texture] = sheet()
|
||||
;[this.cutoutDrawing, this.cutouts] = sheet()
|
||||
for (const drawing of [this.drawing, this.cutoutDrawing]) {
|
||||
drawing.fillStyle = WHITE
|
||||
drawing.fillRect(0, 0, CELL_PIXELS, CELL_PIXELS)
|
||||
}
|
||||
}
|
||||
|
||||
cellOf(textureId: string): Promise<UvCell | null> {
|
||||
@@ -87,6 +85,7 @@ export class TerrainAtlas implements TerrainPictures, PictureSource {
|
||||
|
||||
dispose(): void {
|
||||
this.texture.dispose()
|
||||
this.cutouts.dispose()
|
||||
}
|
||||
|
||||
private async place(textureId: string): Promise<UvCell | null> {
|
||||
@@ -101,12 +100,38 @@ export class TerrainAtlas implements TerrainPictures, PictureSource {
|
||||
this.drawing.drawImage(bitmap, 0, 0, bitmap.width, Math.min(bitmap.width, bitmap.height), left, top, CELL_PIXELS, CELL_PIXELS)
|
||||
const picture = this.drawing.getImageData(left, top, CELL_PIXELS, CELL_PIXELS)
|
||||
const average = averageColor(picture)
|
||||
this.cutoutDrawing.putImageData(cutoutOf(picture), left, top)
|
||||
this.drawing.putImageData(withGapsFilled(picture, average), left, top)
|
||||
this.texture.needsUpdate = true
|
||||
this.cutouts.needsUpdate = true
|
||||
return { ...placed, average }
|
||||
}
|
||||
}
|
||||
|
||||
function sheet(): [CanvasRenderingContext2D, CanvasTexture] {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = ATLAS_PIXELS
|
||||
canvas.height = ATLAS_PIXELS
|
||||
const drawing = canvas.getContext('2d', { willReadFrequently: true })!
|
||||
drawing.imageSmoothingEnabled = false
|
||||
const texture = new CanvasTexture(canvas)
|
||||
texture.magFilter = NearestFilter
|
||||
texture.minFilter = NearestFilter
|
||||
texture.generateMipmaps = false
|
||||
texture.flipY = false
|
||||
return [drawing, texture]
|
||||
}
|
||||
|
||||
// A canvas keeps no colour under a transparent pixel, so the picture cannot carry both its filled gaps and where they were.
|
||||
function cutoutOf(picture: ImageData): ImageData {
|
||||
const cutout = new ImageData(picture.width, picture.height)
|
||||
for (let offset = 0; offset < picture.data.length; offset += 4) {
|
||||
const shade = picture.data[offset + 3] < OPAQUE_ENOUGH_ALPHA ? 0 : 255
|
||||
cutout.data.set([shade, shade, shade, OPAQUE_ALPHA], offset)
|
||||
}
|
||||
return cutout
|
||||
}
|
||||
|
||||
// The terrain draws whole faces, so what a picture leaves open, as leaves do between their twigs, would show as black:
|
||||
// it takes the picture's own colour instead, darker, as the shade seen through the gaps.
|
||||
function withGapsFilled(picture: ImageData, average: number): ImageData {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { DoubleSide, FrontSide, Group, Mesh, MeshBasicMaterial } from 'three'
|
||||
import type { BlockLook } from './blockLooks'
|
||||
import { groundFaces, waterFaces } from './columnFaces'
|
||||
import { ColumnField } from './columnField'
|
||||
import { coverGeometry } from './coverFaces'
|
||||
import type { CoverLook } from './coverLooks'
|
||||
import type { TerrainPictures } from './terrainAtlas'
|
||||
import type { ColumnArea } from './terrainTiles'
|
||||
import { WATER_SURFACE_COLOR, WATER_SURFACE_OPACITY } from './waterTint'
|
||||
@@ -27,8 +29,12 @@ export interface TerrainSurface {
|
||||
readonly pictures?: TerrainPictures
|
||||
/** What the block of the column looks like, or null to show the column in its colour. */
|
||||
lookAt?(column: number, row: number): BlockLook | null
|
||||
/** What stands on the column's ground, such as grass or a flower, or null for nothing that is drawn. */
|
||||
coverAt?(column: number, row: number): CoverLook | null
|
||||
}
|
||||
|
||||
const CUTOUT_ALPHA = 0.5
|
||||
|
||||
export interface TerrainMesh {
|
||||
object: Group
|
||||
field: ColumnField
|
||||
@@ -51,7 +57,9 @@ export function buildTerrainMesh(surface: TerrainSurface, base: number, holes: r
|
||||
const water = waterFaces(field).geometry()
|
||||
const groundMaterial = new MeshBasicMaterial({ vertexColors: true, side: FrontSide, map: field.pictures?.texture ?? null })
|
||||
const waterMaterial = new MeshBasicMaterial({ color: WATER_SURFACE_COLOR, transparent: true, opacity: WATER_SURFACE_OPACITY, depthWrite: false, side: DoubleSide })
|
||||
group.add(new Mesh(ground, groundMaterial), new Mesh(water, waterMaterial))
|
||||
const cover = field.pictures === null ? null : coverMesh(field, field.pictures)
|
||||
// The water is drawn last, over what stands under it.
|
||||
group.add(new Mesh(ground, groundMaterial), ...(cover === null ? [] : [cover.mesh]), new Mesh(water, waterMaterial))
|
||||
return {
|
||||
object: group,
|
||||
field,
|
||||
@@ -60,6 +68,22 @@ export function buildTerrainMesh(surface: TerrainSurface, base: number, holes: r
|
||||
water.dispose()
|
||||
groundMaterial.dispose()
|
||||
waterMaterial.dispose()
|
||||
cover?.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function coverMesh(field: ColumnField, pictures: TerrainPictures): { mesh: Mesh; dispose(): void } | null {
|
||||
const geometry = coverGeometry(field)
|
||||
if (geometry === null) {
|
||||
return null
|
||||
}
|
||||
const material = new MeshBasicMaterial({ vertexColors: true, map: pictures.texture, alphaMap: pictures.cutouts, alphaTest: CUTOUT_ALPHA, side: FrontSide })
|
||||
return {
|
||||
mesh: new Mesh(geometry, material),
|
||||
dispose: () => {
|
||||
geometry.dispose()
|
||||
material.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Texture, Vector3, type BufferGeometry, type Mesh, type MeshBasicMaterial } from 'three'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { BlockLook, FaceLook } from './blockLooks'
|
||||
import type { CoverLook } from './coverLooks'
|
||||
import { cellAt, type TerrainPictures } from './terrainAtlas'
|
||||
import { buildTerrainMesh, type TerrainSurface } from './terrainMesh'
|
||||
|
||||
@@ -16,7 +17,7 @@ const GRASS_TINT = 0x91bd59
|
||||
const WHITE = 0xffffff
|
||||
|
||||
const plain = cellAt(0, WHITE)
|
||||
const pictures: TerrainPictures = { texture: new Texture(), plain }
|
||||
const pictures: TerrainPictures = { texture: new Texture(), cutouts: new Texture(), plain }
|
||||
const cellWidth = plain.width
|
||||
|
||||
function face(index: number, tint = WHITE): FaceLook {
|
||||
@@ -143,6 +144,36 @@ describe('textured terrain', () => {
|
||||
expect((ground.material as MeshBasicMaterial).map).toBeNull()
|
||||
})
|
||||
|
||||
it('stands a cover on the top face of its column, cut out along its picture', () => {
|
||||
const blade: CoverLook = {
|
||||
faces: [
|
||||
{
|
||||
corners: [[0, 1, 0], [0, 0, 0], [1, 0, 1], [1, 1, 1]],
|
||||
uvs: [[0, 0], [0, 1], [1, 1], [1, 0]],
|
||||
cell: cellAt(4, WHITE),
|
||||
color: [0.5, 0.75, 0.25]
|
||||
}
|
||||
]
|
||||
}
|
||||
const terrain = { ...surfaceOf(() => grass), coverAt: (column: number, row: number) => (column === PEAK_COLUMN && row === PEAK_COLUMN ? blade : null) }
|
||||
const [, cover, water] = buildTerrainMesh(terrain, FLOOR).object.children as Mesh[]
|
||||
const positions = cover.geometry.getAttribute('position')
|
||||
const material = cover.material as MeshBasicMaterial
|
||||
|
||||
expect(water).toBeDefined()
|
||||
expect(positions.count).toBe(4)
|
||||
expect([positions.getX(1), positions.getY(1), positions.getZ(1)]).toEqual([ORIGIN_X + PEAK_COLUMN, PEAK_GROUND + 1, ORIGIN_Z + PEAK_COLUMN])
|
||||
expect([positions.getX(3), positions.getY(3), positions.getZ(3)]).toEqual([ORIGIN_X + PEAK_COLUMN + 1, PEAK_GROUND + 2, ORIGIN_Z + PEAK_COLUMN + 1])
|
||||
expect(uvOf(cover.geometry, 0, 2)).toEqual([blade.faces[0].cell.u + cellWidth, blade.faces[0].cell.v + cellWidth])
|
||||
expect(cover.geometry.getAttribute('color').getY(0)).toBeCloseTo(0.75)
|
||||
expect(material.alphaMap).toBe(pictures.cutouts)
|
||||
expect(material.alphaTest).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('draws no cover mesh where nothing stands on the ground', () => {
|
||||
expect(buildTerrainMesh(surfaceOf(() => grass), FLOOR).object.children).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('draws a surface without an atlas in its colour alone', () => {
|
||||
const ground = groundOf(surfaceOf(() => grass, LOW_GROUND, false))
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ import { Panel, SidebarPanel, Stepper, ViewIsland } from './Sidebar'
|
||||
import { TiledCanvas } from './TiledCanvas'
|
||||
|
||||
const DEFAULT_NAMESPACE_PREFIX = 'minecraft:'
|
||||
// A layer thinner than the depth shown, or a palette with no block for the spot.
|
||||
const NONE_LABEL = 'nothing at this depth'
|
||||
// A layer thinner than the depth shown, a palette with no block for the spot, or a spot a decorator leaves bare.
|
||||
const NONE_LABEL = 'nothing placed'
|
||||
|
||||
/** The blocks the shown layer's tiles placed so far by name, each with one state to draw its icon as, and whether some spots got none. */
|
||||
interface LegendBlocks {
|
||||
@@ -196,7 +196,7 @@ function Legend({ blocks, looks }: { blocks: LegendBlocks; looks: BlockColors })
|
||||
{blocks.someNone && (
|
||||
<div className="flex h-[26px] items-center gap-2 text-secondary-text">
|
||||
<span className="size-4 shrink-0 rounded-[2px] border border-foreground/25 bg-map-background" />
|
||||
<span className="min-w-0 flex-1 truncate">Nothing at this depth</span>
|
||||
<span className="min-w-0 flex-1 truncate">Nothing placed</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,7 @@ const VIEW_ICONS: Record<string, IdeIconName> = {
|
||||
world3d: 'views/world-3d',
|
||||
savedWorld: 'views/saved-world',
|
||||
'iris:terrain/palettes': 'views/palettes',
|
||||
'iris:decorant/decorators': 'decoration',
|
||||
'iris:objects': 'views/objects',
|
||||
'iris:objects/procedural': 'views/procedural',
|
||||
noise: 'views/noise'
|
||||
|
||||
Reference in new issue
Block a user