minecraft-renderer 0.1.43 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mesher.js +35 -35
- package/dist/mesher.js.map +4 -4
- package/dist/mesherWasm.js +61 -61
- package/dist/minecraft-renderer.js +59 -59
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +458 -458
- package/package.json +1 -1
- package/src/graphicsBackend/appViewer.ts +19 -7
- package/src/graphicsBackend/types.ts +5 -1
- package/src/index.ts +33 -0
- package/src/lib/ui/newStats.ts +16 -2
- package/src/lib/worldrendererCommon.ts +2 -2
- package/src/mesher-shared/models.ts +28 -11
- package/src/mesher-shared/vertexShading.ts +35 -0
- package/src/three/entities.ts +22 -6
- package/src/three/graphicsBackendBase.ts +28 -20
- package/src/three/graphicsBackendOffThread.ts +1 -2
- package/src/three/menuBackground/activeView.ts +19 -0
- package/src/three/menuBackground/classic.ts +148 -0
- package/src/three/menuBackground/config.ts +23 -0
- package/src/three/menuBackground/defaultOptions.ts +141 -0
- package/src/three/menuBackground/futuristic.ts +859 -0
- package/src/three/menuBackground/index.ts +36 -0
- package/src/three/menuBackground/renderer.ts +97 -0
- package/src/three/menuBackground/shared.ts +3 -0
- package/src/three/menuBackground/types.ts +37 -0
- package/src/three/menuBackground/worldBlocks.ts +144 -0
- package/src/three/modules/rain.ts +21 -3
- package/src/three/waypointSprite.ts +108 -106
- package/src/three/worldRendererThree.ts +9 -12
- package/src/wasm-mesher/bridge/render-from-wasm.ts +57 -12
- package/src/three/panorama.ts +0 -312
- package/src/three/panoramaShared.ts +0 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
export { MENU_BACKGROUND_MC_VERSION } from './shared'
|
|
3
|
+
export type { MenuBackgroundView } from './activeView'
|
|
4
|
+
export { resizeMenuBackgroundCamera } from './activeView'
|
|
5
|
+
export type { MenuBackgroundMode, MenuBackgroundOptions } from './types'
|
|
6
|
+
export { resolveMenuBackgroundMode } from './types'
|
|
7
|
+
export { ClassicMenuBackground } from './classic'
|
|
8
|
+
export type {
|
|
9
|
+
FuturisticSceneId,
|
|
10
|
+
FuturisticCameraId,
|
|
11
|
+
FuturisticMenuBackgroundOptions,
|
|
12
|
+
MinecraftBlockGroupId
|
|
13
|
+
} from './futuristic'
|
|
14
|
+
export {
|
|
15
|
+
FuturisticMenuBackground,
|
|
16
|
+
FUTURISTIC_SCENE_IDS,
|
|
17
|
+
FUTURISTIC_CAMERA_IDS,
|
|
18
|
+
FUTURISTIC_SCENE_LABELS,
|
|
19
|
+
FUTURISTIC_CAMERA_LABELS,
|
|
20
|
+
MINECRAFT_BLOCK_GROUPS,
|
|
21
|
+
MINECRAFT_BLOCK_GROUP_IDS,
|
|
22
|
+
MINECRAFT_BLOCK_GROUP_LABELS
|
|
23
|
+
} from './futuristic'
|
|
24
|
+
export { WorldBlocksMenuBackground } from './worldBlocks'
|
|
25
|
+
export { MenuBackgroundRenderer } from './renderer'
|
|
26
|
+
export {
|
|
27
|
+
MENU_BACKGROUND_OPTION_DEFAULTS,
|
|
28
|
+
MENU_BACKGROUND_MOTION_DEFAULTS,
|
|
29
|
+
menuBackgroundSpeedToMultiplier
|
|
30
|
+
} from './config'
|
|
31
|
+
export {
|
|
32
|
+
RENDERER_DEFAULT_OPTIONS,
|
|
33
|
+
RENDERER_OPTIONS_META,
|
|
34
|
+
RENDERER_RENDER_GUI_SECTIONS
|
|
35
|
+
} from './defaultOptions'
|
|
36
|
+
export type { RendererDefaultOptionKey, RendererOptionMeta } from './defaultOptions'
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import type { GraphicsInitOptions } from '../../graphicsBackend/types'
|
|
4
|
+
import type { DocumentRenderer } from '../documentRenderer'
|
|
5
|
+
import { ClassicMenuBackground } from './classic'
|
|
6
|
+
import { FuturisticMenuBackground } from './futuristic'
|
|
7
|
+
import { WorldBlocksMenuBackground } from './worldBlocks'
|
|
8
|
+
import type { MenuBackgroundView } from './activeView'
|
|
9
|
+
import type { MenuBackgroundOptions } from './types'
|
|
10
|
+
import { resolveMenuBackgroundMode } from './types'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Orchestrates main-menu background rendering (dispatches to classic / futuristic / world-blocks).
|
|
14
|
+
*/
|
|
15
|
+
export class MenuBackgroundRenderer {
|
|
16
|
+
private active?: MenuBackgroundView
|
|
17
|
+
private readonly abortController = new AbortController()
|
|
18
|
+
private readonly mode: ReturnType<typeof resolveMenuBackgroundMode>
|
|
19
|
+
private lastFrameTime = 0
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private readonly documentRenderer: DocumentRenderer,
|
|
23
|
+
private readonly options: GraphicsInitOptions,
|
|
24
|
+
menuBackgroundOptions: MenuBackgroundOptions = {},
|
|
25
|
+
singleFileBuild = false
|
|
26
|
+
) {
|
|
27
|
+
this.mode = resolveMenuBackgroundMode(menuBackgroundOptions, singleFileBuild)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Active futuristic instance when that style is running. */
|
|
31
|
+
get futuristic(): FuturisticMenuBackground | undefined {
|
|
32
|
+
return this.active instanceof FuturisticMenuBackground ? this.active : undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get scene(): THREE.Scene | undefined {
|
|
36
|
+
return this.active?.scene
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get camera(): THREE.PerspectiveCamera | undefined {
|
|
40
|
+
return this.active?.camera
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async start(menuBackgroundOptions: MenuBackgroundOptions = {}) {
|
|
44
|
+
this.active = this.createImplementation(menuBackgroundOptions)
|
|
45
|
+
await this.active.init()
|
|
46
|
+
|
|
47
|
+
if (this.active.scene.background instanceof THREE.Color) {
|
|
48
|
+
this.documentRenderer.renderer.setClearColor(this.active.scene.background)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.lastFrameTime = performance.now()
|
|
52
|
+
this.documentRenderer.render = (sizeChanged = false) => {
|
|
53
|
+
const now = performance.now()
|
|
54
|
+
const dt = Math.min((now - this.lastFrameTime) / 1000, 0.05)
|
|
55
|
+
this.lastFrameTime = now
|
|
56
|
+
|
|
57
|
+
const view = this.active
|
|
58
|
+
if (!view) return
|
|
59
|
+
|
|
60
|
+
view.update(dt, sizeChanged)
|
|
61
|
+
this.documentRenderer.renderer.render(view.scene, view.camera)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private createImplementation(options: MenuBackgroundOptions): MenuBackgroundView {
|
|
66
|
+
switch (this.mode) {
|
|
67
|
+
case 'futuristic':
|
|
68
|
+
return new FuturisticMenuBackground(
|
|
69
|
+
this.documentRenderer,
|
|
70
|
+
{
|
|
71
|
+
useMinecraftTextures: options.useMinecraftTextures,
|
|
72
|
+
initialScene: options.futuristicScene,
|
|
73
|
+
initialCamera: options.futuristicCamera,
|
|
74
|
+
initialBlockGroup: options.futuristicBlockGroup,
|
|
75
|
+
initialCameraSpeed: options.futuristicCameraSpeed,
|
|
76
|
+
initialBlockSpeed: options.futuristicBlockSpeed,
|
|
77
|
+
resourcesManager: options.resourcesManager
|
|
78
|
+
},
|
|
79
|
+
this.abortController.signal
|
|
80
|
+
)
|
|
81
|
+
case 'worldBlocks':
|
|
82
|
+
return new WorldBlocksMenuBackground(
|
|
83
|
+
this.documentRenderer,
|
|
84
|
+
this.options,
|
|
85
|
+
this.abortController.signal
|
|
86
|
+
)
|
|
87
|
+
default:
|
|
88
|
+
return new ClassicMenuBackground(this.documentRenderer)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
dispose() {
|
|
93
|
+
this.active?.dispose()
|
|
94
|
+
this.active = undefined
|
|
95
|
+
this.abortController.abort()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
import type { ResourcesManager } from '../../resourcesManager/resourcesManager'
|
|
3
|
+
import type { FuturisticCameraId, FuturisticSceneId, MinecraftBlockGroupId } from './futuristic'
|
|
4
|
+
import { MENU_BACKGROUND_OPTION_DEFAULTS } from './config'
|
|
5
|
+
|
|
6
|
+
export type { FuturisticCameraId, FuturisticSceneId, MinecraftBlockGroupId } from './futuristic'
|
|
7
|
+
|
|
8
|
+
export type MenuBackgroundMode = 'classic' | 'futuristic' | 'worldBlocks'
|
|
9
|
+
|
|
10
|
+
export interface MenuBackgroundOptions {
|
|
11
|
+
/** Visual style. Defaults to {@link MENU_BACKGROUND_OPTION_DEFAULTS.mode}, or `worldBlocks` in single-file build. */
|
|
12
|
+
mode?: MenuBackgroundMode
|
|
13
|
+
/** Futuristic style: load block atlas and render textured cubes (requires assets / mcData). */
|
|
14
|
+
useMinecraftTextures?: boolean
|
|
15
|
+
futuristicScene?: FuturisticSceneId
|
|
16
|
+
futuristicCamera?: FuturisticCameraId
|
|
17
|
+
/** Block pool when {@link useMinecraftTextures} is enabled. */
|
|
18
|
+
futuristicBlockGroup?: MinecraftBlockGroupId
|
|
19
|
+
/** Camera path speed (1 = 100%). */
|
|
20
|
+
futuristicCameraSpeed?: number
|
|
21
|
+
/** Block fly-through + sky drift speed (1 = 100%). */
|
|
22
|
+
futuristicBlockSpeed?: number
|
|
23
|
+
/**
|
|
24
|
+
* Optional shared resource manager (e.g. appViewer.resourcesManager).
|
|
25
|
+
* Caller should run `updateAssetsData` after mcData is loaded when using textured cubes.
|
|
26
|
+
*/
|
|
27
|
+
resourcesManager?: ResourcesManager
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function resolveMenuBackgroundMode(
|
|
31
|
+
options?: MenuBackgroundOptions,
|
|
32
|
+
singleFileBuild = false
|
|
33
|
+
): MenuBackgroundMode {
|
|
34
|
+
if (options?.mode) return options.mode
|
|
35
|
+
if (singleFileBuild) return 'worldBlocks'
|
|
36
|
+
return MENU_BACKGROUND_OPTION_DEFAULTS.mode
|
|
37
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
//@ts-nocheck
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import { Vec3 } from 'vec3'
|
|
4
|
+
import * as tweenJs from '@tweenjs/tween.js'
|
|
5
|
+
import { getSyncWorld } from '../../playground/shared'
|
|
6
|
+
import type { GraphicsInitOptions } from '../../graphicsBackend/types'
|
|
7
|
+
import { WorldRendererCommon } from '../../lib/worldrendererCommon'
|
|
8
|
+
import { defaultWorldRendererConfig, getDefaultRendererState } from '../../graphicsBackend/config'
|
|
9
|
+
import { ResourcesManager, ResourcesManagerTransferred } from '../../resourcesManager/resourcesManager'
|
|
10
|
+
import { getInitialPlayerStateRenderer } from '../../graphicsBackend/playerState'
|
|
11
|
+
import { WorldRendererThree } from '../worldRendererThree'
|
|
12
|
+
import type { DocumentRenderer } from '../documentRenderer'
|
|
13
|
+
import { MENU_BACKGROUND_MC_VERSION } from './shared'
|
|
14
|
+
import { WorldView } from '../../worldView'
|
|
15
|
+
import type { MenuBackgroundView } from './activeView'
|
|
16
|
+
import { resizeMenuBackgroundCamera } from './activeView'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Menu background built from a wall of random stained-glass blocks (single-file / demo style).
|
|
20
|
+
*/
|
|
21
|
+
export class WorldBlocksMenuBackground implements MenuBackgroundView {
|
|
22
|
+
private _scene: THREE.Scene
|
|
23
|
+
private _camera: THREE.PerspectiveCamera
|
|
24
|
+
|
|
25
|
+
get scene() { return this._scene }
|
|
26
|
+
get camera() { return this._camera }
|
|
27
|
+
|
|
28
|
+
private worldRenderer?: WorldRendererCommon | WorldRendererThree
|
|
29
|
+
WorldRendererClass = WorldRendererThree
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
private readonly documentRenderer: DocumentRenderer,
|
|
33
|
+
private readonly options: GraphicsInitOptions,
|
|
34
|
+
private readonly abortSignal: AbortSignal
|
|
35
|
+
) {
|
|
36
|
+
this._scene = new THREE.Scene()
|
|
37
|
+
this._scene.background = new THREE.Color(0x32_45_68)
|
|
38
|
+
this._camera = new THREE.PerspectiveCamera(
|
|
39
|
+
85,
|
|
40
|
+
documentRenderer.canvas.width / documentRenderer.canvas.height,
|
|
41
|
+
0.05,
|
|
42
|
+
1000
|
|
43
|
+
)
|
|
44
|
+
this.camera.position.set(0, 0, 0)
|
|
45
|
+
this.camera.rotation.set(0, 0, 0)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async init() {
|
|
49
|
+
const version = MENU_BACKGROUND_MC_VERSION
|
|
50
|
+
const fullResourceManager = new ResourcesManager()
|
|
51
|
+
fullResourceManager.currentConfig = { version, noInventoryGui: true }
|
|
52
|
+
await fullResourceManager.updateAssetsData?.({})
|
|
53
|
+
if (this.abortSignal.aborted) return
|
|
54
|
+
|
|
55
|
+
console.time('load menu background scene')
|
|
56
|
+
const world = getSyncWorld(version)
|
|
57
|
+
const PrismarineBlock = require('prismarine-block')
|
|
58
|
+
const Block = PrismarineBlock(version)
|
|
59
|
+
const mcData = (globalThis as any).mcData
|
|
60
|
+
const fullBlocks = mcData.blocksArray.filter((block: { name: string, defaultState: number }) => {
|
|
61
|
+
if (!block.name.includes('stained_glass')) return false
|
|
62
|
+
const b = Block.fromStateId(block.defaultState, 0)
|
|
63
|
+
if (b.shapes?.length !== 1) return false
|
|
64
|
+
const shape = b.shapes[0]
|
|
65
|
+
return shape[0] === 0 && shape[1] === 0 && shape[2] === 0 && shape[3] === 1 && shape[4] === 1 && shape[5] === 1
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const Z = -15
|
|
69
|
+
const sizeX = 100
|
|
70
|
+
const sizeY = 100
|
|
71
|
+
for (let x = -sizeX; x < sizeX; x++) {
|
|
72
|
+
for (let y = -sizeY; y < sizeY; y++) {
|
|
73
|
+
const block = fullBlocks[Math.floor(Math.random() * fullBlocks.length)]
|
|
74
|
+
world.setBlockStateId(new Vec3(x, y, Z), block.defaultState)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this._camera.updateProjectionMatrix()
|
|
79
|
+
this._camera.position.set(0.5, sizeY / 2 + 0.5, 0.5)
|
|
80
|
+
this._camera.rotation.set(0, 0, 0)
|
|
81
|
+
const initPos = new Vec3(...this._camera.position.toArray())
|
|
82
|
+
const worldView = new WorldView(world, 2, initPos)
|
|
83
|
+
if (this.abortSignal.aborted) return
|
|
84
|
+
|
|
85
|
+
this.worldRenderer = new this.WorldRendererClass(
|
|
86
|
+
this.documentRenderer.renderer,
|
|
87
|
+
this.options,
|
|
88
|
+
{
|
|
89
|
+
version,
|
|
90
|
+
worldView,
|
|
91
|
+
inWorldRenderingConfig: defaultWorldRendererConfig,
|
|
92
|
+
playerStateReactive: getInitialPlayerStateRenderer().reactive,
|
|
93
|
+
rendererState: getDefaultRendererState().reactive,
|
|
94
|
+
nonReactiveState: getDefaultRendererState().nonReactive,
|
|
95
|
+
resourcesManager: fullResourceManager as ResourcesManagerTransferred
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
if (this.worldRenderer instanceof WorldRendererThree) {
|
|
100
|
+
this._scene = this.worldRenderer.realScene
|
|
101
|
+
this._camera = this.worldRenderer.camera
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void worldView.init(initPos)
|
|
105
|
+
await this.worldRenderer.waitForChunksToRender()
|
|
106
|
+
if (this.abortSignal.aborted) return
|
|
107
|
+
|
|
108
|
+
this.setupMouseParallax()
|
|
109
|
+
console.timeEnd('load menu background scene')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
update(_dt: number, sizeChanged: boolean) {
|
|
113
|
+
if (sizeChanged) {
|
|
114
|
+
resizeMenuBackgroundCamera(this.camera, this.documentRenderer.canvas)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
dispose() {
|
|
119
|
+
this.worldRenderer?.destroy()
|
|
120
|
+
this.worldRenderer = undefined
|
|
121
|
+
this._scene.clear()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private setupMouseParallax() {
|
|
125
|
+
const camera = this._camera
|
|
126
|
+
const initX = camera.position.x
|
|
127
|
+
const initY = camera.position.y
|
|
128
|
+
let prevTween: tweenJs.Tween<THREE.Vector3> | undefined
|
|
129
|
+
|
|
130
|
+
document.body.addEventListener('pointermove', (e) => {
|
|
131
|
+
if (e.pointerType !== 'mouse') return
|
|
132
|
+
const SCALE = 0.2
|
|
133
|
+
const xRel = e.clientX / window.innerWidth - 0.5
|
|
134
|
+
const yRel = -(e.clientY / window.innerHeight - 0.5)
|
|
135
|
+
prevTween?.stop()
|
|
136
|
+
prevTween = new tweenJs.Tween(camera.position).to({
|
|
137
|
+
x: initX + xRel * SCALE,
|
|
138
|
+
y: initY + yRel * SCALE
|
|
139
|
+
}, 0)
|
|
140
|
+
prevTween.start()
|
|
141
|
+
camera.updateProjectionMatrix()
|
|
142
|
+
}, { signal: this.abortSignal })
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -58,7 +58,9 @@ export class RainModule implements RendererModuleController {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
render?: (deltaTime: number) => void = (deltaTime) => {
|
|
61
|
-
if (!this.enabled || !this.instancedMesh) return
|
|
61
|
+
if (!this.enabled || !this.instancedMesh || !this.material) return
|
|
62
|
+
|
|
63
|
+
this.syncMaterialToSceneFog()
|
|
62
64
|
|
|
63
65
|
const cameraPos = this.worldRenderer.getCameraPosition()
|
|
64
66
|
this.instancedMesh.position.set(0, 0, 0)
|
|
@@ -135,16 +137,32 @@ export class RainModule implements RendererModuleController {
|
|
|
135
137
|
this.particles = []
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
/** Match scene fog so rain fades with distance instead of a flat blue sheet. */
|
|
141
|
+
private syncMaterialToSceneFog(): void {
|
|
142
|
+
if (!this.material) return
|
|
143
|
+
const fog = this.worldRenderer.scene.fog
|
|
144
|
+
if (fog instanceof THREE.Fog || fog instanceof THREE.FogExp2) {
|
|
145
|
+
this.material.color.copy(fog.color)
|
|
146
|
+
} else {
|
|
147
|
+
this.material.color.set(0xcc_dd_ee)
|
|
148
|
+
}
|
|
149
|
+
this.material.fog = true
|
|
150
|
+
}
|
|
151
|
+
|
|
138
152
|
private createRain(): void {
|
|
139
153
|
this.geometry = new THREE.BoxGeometry(0.03, 0.3, 0.03)
|
|
140
154
|
this.material = new THREE.MeshBasicMaterial({
|
|
141
|
-
color:
|
|
155
|
+
color: 0xcc_dd_ee,
|
|
142
156
|
transparent: true,
|
|
143
|
-
opacity: 0.
|
|
157
|
+
opacity: 0.35,
|
|
158
|
+
depthWrite: false,
|
|
159
|
+
fog: true,
|
|
144
160
|
})
|
|
145
161
|
|
|
146
162
|
this.instancedMesh = new THREE.InstancedMesh(this.geometry, this.material, PARTICLE_COUNT)
|
|
147
163
|
this.instancedMesh.name = 'rain-particles'
|
|
164
|
+
this.instancedMesh.frustumCulled = false
|
|
165
|
+
this.syncMaterialToSceneFog()
|
|
148
166
|
|
|
149
167
|
const dummy = new THREE.Matrix4()
|
|
150
168
|
const position = new THREE.Vector3()
|