minecraft-renderer 0.1.0
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/README.md +297 -0
- package/dist/index.html +83 -0
- package/dist/static/image/arrow.6f27b59f.png +0 -0
- package/dist/static/image/blocksAtlasLatest.7850afa3.png +0 -0
- package/dist/static/image/blocksAtlasLegacy.5c76823d.png +0 -0
- package/dist/static/image/itemsAtlasLatest.36036f95.png +0 -0
- package/dist/static/image/itemsAtlasLegacy.dcb1b58d.png +0 -0
- package/dist/static/image/tipped_arrow.6f27b59f.png +0 -0
- package/dist/static/js/365.f05233ab.js +8462 -0
- package/dist/static/js/365.f05233ab.js.LICENSE.txt +52 -0
- package/dist/static/js/async/738.efa27644.js +1 -0
- package/dist/static/js/index.092ec5be.js +56 -0
- package/dist/static/js/lib-polyfill.98986ac5.js +1 -0
- package/dist/static/js/lib-react.5c9129e0.js +2 -0
- package/dist/static/js/lib-react.5c9129e0.js.LICENSE.txt +39 -0
- package/package.json +104 -0
- package/src/assets/destroy_stage_0.png +0 -0
- package/src/assets/destroy_stage_1.png +0 -0
- package/src/assets/destroy_stage_2.png +0 -0
- package/src/assets/destroy_stage_3.png +0 -0
- package/src/assets/destroy_stage_4.png +0 -0
- package/src/assets/destroy_stage_5.png +0 -0
- package/src/assets/destroy_stage_6.png +0 -0
- package/src/assets/destroy_stage_7.png +0 -0
- package/src/assets/destroy_stage_8.png +0 -0
- package/src/assets/destroy_stage_9.png +0 -0
- package/src/examples/README.md +146 -0
- package/src/examples/appViewerExample.ts +205 -0
- package/src/examples/initialMenuStart.ts +161 -0
- package/src/graphicsBackend/appViewer.ts +297 -0
- package/src/graphicsBackend/config.ts +119 -0
- package/src/graphicsBackend/index.ts +10 -0
- package/src/graphicsBackend/playerState.ts +61 -0
- package/src/graphicsBackend/types.ts +143 -0
- package/src/index.ts +97 -0
- package/src/lib/DebugGui.ts +190 -0
- package/src/lib/animationController.ts +85 -0
- package/src/lib/buildSharedConfig.mjs +1 -0
- package/src/lib/cameraBobbing.ts +94 -0
- package/src/lib/canvas2DOverlay.example.ts +361 -0
- package/src/lib/canvas2DOverlay.quickstart.ts +242 -0
- package/src/lib/canvas2DOverlay.ts +381 -0
- package/src/lib/cleanupDecorator.ts +29 -0
- package/src/lib/createPlayerObject.ts +55 -0
- package/src/lib/frameTimingCollector.ts +164 -0
- package/src/lib/guiRenderer.ts +283 -0
- package/src/lib/items.ts +140 -0
- package/src/lib/mesherlogReader.ts +131 -0
- package/src/lib/moreBlockDataGenerated.json +714 -0
- package/src/lib/preflatMap.json +1741 -0
- package/src/lib/simpleUtils.ts +40 -0
- package/src/lib/smoothSwitcher.ts +168 -0
- package/src/lib/spiral.ts +29 -0
- package/src/lib/ui/newStats.ts +120 -0
- package/src/lib/utils/proxy.ts +23 -0
- package/src/lib/utils/skins.ts +63 -0
- package/src/lib/utils.ts +76 -0
- package/src/lib/workerProxy.ts +342 -0
- package/src/lib/worldrendererCommon.ts +1088 -0
- package/src/mesher/mesher.ts +253 -0
- package/src/mesher/models.ts +769 -0
- package/src/mesher/modelsGeometryCommon.ts +142 -0
- package/src/mesher/shared.ts +80 -0
- package/src/mesher/standaloneRenderer.ts +270 -0
- package/src/mesher/test/a.ts +3 -0
- package/src/mesher/test/mesherTester.ts +76 -0
- package/src/mesher/test/playground.ts +19 -0
- package/src/mesher/test/test-perf.ts +74 -0
- package/src/mesher/test/tests.test.ts +56 -0
- package/src/mesher/world.ts +294 -0
- package/src/mesher/worldConstants.ts +1 -0
- package/src/modules/index.ts +11 -0
- package/src/modules/starfield.ts +313 -0
- package/src/modules/types.ts +110 -0
- package/src/playerState/playerState.ts +78 -0
- package/src/playerState/types.ts +36 -0
- package/src/playground/allEntitiesDebug.ts +170 -0
- package/src/playground/baseScene.ts +587 -0
- package/src/playground/mobileControls.tsx +268 -0
- package/src/playground/playground.html +83 -0
- package/src/playground/playground.ts +11 -0
- package/src/playground/playgroundUi.tsx +140 -0
- package/src/playground/reactUtils.ts +71 -0
- package/src/playground/scenes/allEntities.ts +13 -0
- package/src/playground/scenes/entities.ts +37 -0
- package/src/playground/scenes/floorRandom.ts +33 -0
- package/src/playground/scenes/frequentUpdates.ts +148 -0
- package/src/playground/scenes/geometryExport.ts +142 -0
- package/src/playground/scenes/index.ts +12 -0
- package/src/playground/scenes/lightingStarfield.ts +40 -0
- package/src/playground/scenes/main.ts +313 -0
- package/src/playground/scenes/railsCobweb.ts +14 -0
- package/src/playground/scenes/rotationIssue.ts +7 -0
- package/src/playground/scenes/slabsOptimization.ts +16 -0
- package/src/playground/scenes/transparencyIssue.ts +11 -0
- package/src/playground/shared.ts +79 -0
- package/src/resourcesManager/index.ts +5 -0
- package/src/resourcesManager/resourcesManager.ts +314 -0
- package/src/shims/minecraftData.ts +41 -0
- package/src/sign-renderer/index.html +21 -0
- package/src/sign-renderer/index.ts +216 -0
- package/src/sign-renderer/noop.js +1 -0
- package/src/sign-renderer/playground.ts +38 -0
- package/src/sign-renderer/tests.test.ts +69 -0
- package/src/sign-renderer/vite.config.ts +10 -0
- package/src/three/appShared.ts +75 -0
- package/src/three/bannerRenderer.ts +275 -0
- package/src/three/cameraShake.ts +120 -0
- package/src/three/cinimaticScript.ts +350 -0
- package/src/three/documentRenderer.ts +491 -0
- package/src/three/entities.ts +1580 -0
- package/src/three/entity/EntityMesh.ts +707 -0
- package/src/three/entity/animations.js +171 -0
- package/src/three/entity/armorModels.json +204 -0
- package/src/three/entity/armorModels.ts +36 -0
- package/src/three/entity/entities.json +6230 -0
- package/src/three/entity/exportedModels.js +38 -0
- package/src/three/entity/externalTextures.json +1 -0
- package/src/three/entity/models/allay.obj +325 -0
- package/src/three/entity/models/arrow.obj +60 -0
- package/src/three/entity/models/axolotl.obj +509 -0
- package/src/three/entity/models/blaze.obj +601 -0
- package/src/three/entity/models/boat.obj +417 -0
- package/src/three/entity/models/camel.obj +1061 -0
- package/src/three/entity/models/cat.obj +509 -0
- package/src/three/entity/models/chicken.obj +371 -0
- package/src/three/entity/models/cod.obj +371 -0
- package/src/three/entity/models/creeper.obj +279 -0
- package/src/three/entity/models/dolphin.obj +371 -0
- package/src/three/entity/models/ender_dragon.obj +2993 -0
- package/src/three/entity/models/enderman.obj +325 -0
- package/src/three/entity/models/endermite.obj +187 -0
- package/src/three/entity/models/fox.obj +463 -0
- package/src/three/entity/models/frog.obj +739 -0
- package/src/three/entity/models/ghast.obj +463 -0
- package/src/three/entity/models/goat.obj +601 -0
- package/src/three/entity/models/guardian.obj +1015 -0
- package/src/three/entity/models/horse.obj +1061 -0
- package/src/three/entity/models/llama.obj +509 -0
- package/src/three/entity/models/minecart.obj +233 -0
- package/src/three/entity/models/parrot.obj +509 -0
- package/src/three/entity/models/piglin.obj +739 -0
- package/src/three/entity/models/pillager.obj +371 -0
- package/src/three/entity/models/rabbit.obj +555 -0
- package/src/three/entity/models/sheep.obj +555 -0
- package/src/three/entity/models/shulker.obj +141 -0
- package/src/three/entity/models/sniffer.obj +693 -0
- package/src/three/entity/models/spider.obj +509 -0
- package/src/three/entity/models/tadpole.obj +95 -0
- package/src/three/entity/models/turtle.obj +371 -0
- package/src/three/entity/models/vex.obj +325 -0
- package/src/three/entity/models/villager.obj +509 -0
- package/src/three/entity/models/warden.obj +463 -0
- package/src/three/entity/models/witch.obj +647 -0
- package/src/three/entity/models/wolf.obj +509 -0
- package/src/three/entity/models/zombie_villager.obj +463 -0
- package/src/three/entity/objModels.js +1 -0
- package/src/three/fireworks.ts +661 -0
- package/src/three/fireworksRenderer.ts +434 -0
- package/src/three/globals.d.ts +7 -0
- package/src/three/graphicsBackend.ts +274 -0
- package/src/three/graphicsBackendOffThread.ts +107 -0
- package/src/three/hand.ts +89 -0
- package/src/three/holdingBlock.ts +926 -0
- package/src/three/index.ts +20 -0
- package/src/three/itemMesh.ts +427 -0
- package/src/three/modules.d.ts +14 -0
- package/src/three/panorama.ts +308 -0
- package/src/three/panoramaShared.ts +1 -0
- package/src/three/renderSlot.ts +82 -0
- package/src/three/skyboxRenderer.ts +406 -0
- package/src/three/starField.ts +13 -0
- package/src/three/threeJsMedia.ts +731 -0
- package/src/three/threeJsMethods.ts +15 -0
- package/src/three/threeJsParticles.ts +160 -0
- package/src/three/threeJsSound.ts +95 -0
- package/src/three/threeJsUtils.ts +90 -0
- package/src/three/waypointSprite.ts +435 -0
- package/src/three/waypoints.ts +163 -0
- package/src/three/world/cursorBlock.ts +172 -0
- package/src/three/world/vr.ts +257 -0
- package/src/three/worldGeometryExport.ts +259 -0
- package/src/three/worldGeometryHandler.ts +279 -0
- package/src/three/worldRendererThree.ts +1381 -0
- package/src/worldView/index.ts +6 -0
- package/src/worldView/types.ts +66 -0
- package/src/worldView/worldView.ts +424 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { join } from 'path'
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import { getSyncWorld } from '../playground/shared'
|
|
4
|
+
import { Vec3 } from 'vec3'
|
|
5
|
+
import * as tweenJs from '@tweenjs/tween.js'
|
|
6
|
+
import type { GraphicsInitOptions } from '../graphicsBackend/types'
|
|
7
|
+
import { defaultWorldRendererConfig, WorldRendererCommon } from '../lib/worldrendererCommon'
|
|
8
|
+
import { getDefaultRendererState } from '../graphicsBackend/config'
|
|
9
|
+
import { ResourcesManager } from '../resourcesManager/resourcesManager'
|
|
10
|
+
import { getInitialPlayerStateRenderer } from '../graphicsBackend/playerState'
|
|
11
|
+
import { loadThreeJsTextureFromUrl, loadThreeJsTextureFromUrlSync } from './threeJsUtils'
|
|
12
|
+
import { WorldRendererThree } from './worldRendererThree'
|
|
13
|
+
import { EntityMesh } from './entity/EntityMesh'
|
|
14
|
+
import { DocumentRenderer } from './documentRenderer'
|
|
15
|
+
import { PANORAMA_VERSION } from './panoramaShared'
|
|
16
|
+
import { WorldView } from '../worldView'
|
|
17
|
+
|
|
18
|
+
const date = new Date()
|
|
19
|
+
const isChristmas = date.getMonth() === 11 && date.getDate() >= 24 && date.getDate() <= 26
|
|
20
|
+
|
|
21
|
+
const panoramaFiles = [
|
|
22
|
+
'panorama_3.webp', // right (+x)
|
|
23
|
+
'panorama_1.webp', // left (-x)
|
|
24
|
+
'panorama_4.webp', // top (+y)
|
|
25
|
+
'panorama_5.webp', // bottom (-y)
|
|
26
|
+
'panorama_0.webp', // front (+z)
|
|
27
|
+
'panorama_2.webp', // back (-z)
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
export class PanoramaRenderer {
|
|
31
|
+
private readonly camera: THREE.PerspectiveCamera
|
|
32
|
+
private scene: THREE.Scene
|
|
33
|
+
private readonly ambientLight: THREE.AmbientLight
|
|
34
|
+
private readonly directionalLight: THREE.DirectionalLight
|
|
35
|
+
private panoramaGroup: THREE.Object3D | null = null
|
|
36
|
+
private time = 0
|
|
37
|
+
private readonly abortController = new AbortController()
|
|
38
|
+
private worldRenderer: WorldRendererCommon | WorldRendererThree | undefined
|
|
39
|
+
public WorldRendererClass = WorldRendererThree
|
|
40
|
+
public startTimes = new Map<THREE.MeshBasicMaterial, number>()
|
|
41
|
+
|
|
42
|
+
constructor(private readonly documentRenderer: DocumentRenderer, private readonly options: GraphicsInitOptions, private readonly doWorldBlocksPanorama = false) {
|
|
43
|
+
this.scene = new THREE.Scene()
|
|
44
|
+
// #324568
|
|
45
|
+
this.scene.background = new THREE.Color(0x32_45_68)
|
|
46
|
+
|
|
47
|
+
// Add ambient light
|
|
48
|
+
this.ambientLight = new THREE.AmbientLight(0xcc_cc_cc)
|
|
49
|
+
this.scene.add(this.ambientLight)
|
|
50
|
+
|
|
51
|
+
// Add directional light
|
|
52
|
+
this.directionalLight = new THREE.DirectionalLight(0xff_ff_ff, 0.5)
|
|
53
|
+
this.directionalLight.position.set(1, 1, 0.5).normalize()
|
|
54
|
+
this.directionalLight.castShadow = true
|
|
55
|
+
this.scene.add(this.directionalLight)
|
|
56
|
+
|
|
57
|
+
this.camera = new THREE.PerspectiveCamera(85, this.documentRenderer.canvas.width / this.documentRenderer.canvas.height, 0.05, 1000)
|
|
58
|
+
this.camera.position.set(0, 0, 0)
|
|
59
|
+
this.camera.rotation.set(0, 0, 0)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async start() {
|
|
63
|
+
if (this.doWorldBlocksPanorama) {
|
|
64
|
+
await this.worldBlocksPanorama()
|
|
65
|
+
} else {
|
|
66
|
+
this.addClassicPanorama()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
this.documentRenderer.render = (sizeChanged = false) => {
|
|
71
|
+
if (sizeChanged) {
|
|
72
|
+
this.camera.aspect = this.documentRenderer.canvas.width / this.documentRenderer.canvas.height
|
|
73
|
+
this.camera.updateProjectionMatrix()
|
|
74
|
+
}
|
|
75
|
+
this.documentRenderer.renderer.render(this.scene, this.camera)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async debugImageInFrontOfCamera() {
|
|
80
|
+
const image = await loadThreeJsTextureFromUrl(join('background', 'panorama_0.webp'))
|
|
81
|
+
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(1000, 1000), new THREE.MeshBasicMaterial({ map: image }))
|
|
82
|
+
mesh.position.set(0, 0, -500)
|
|
83
|
+
mesh.rotation.set(0, 0, 0)
|
|
84
|
+
this.scene.add(mesh)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
addClassicPanorama() {
|
|
88
|
+
const panorGeo = new THREE.BoxGeometry(1000, 1000, 1000)
|
|
89
|
+
const panorMaterials = [] as THREE.MeshBasicMaterial[]
|
|
90
|
+
const fadeInDuration = 200
|
|
91
|
+
|
|
92
|
+
// void this.debugImageInFrontOfCamera()
|
|
93
|
+
|
|
94
|
+
for (const file of panoramaFiles) {
|
|
95
|
+
const load = async () => {
|
|
96
|
+
const { texture } = loadThreeJsTextureFromUrlSync(join('background', isChristmas ? 'christmas' : '', file))
|
|
97
|
+
|
|
98
|
+
// Instead of using repeat/offset to flip, we'll use the texture matrix
|
|
99
|
+
texture.matrixAutoUpdate = false
|
|
100
|
+
texture.matrix.set(
|
|
101
|
+
-1, 0, 1, 0, 1, 0, 0, 0, 1
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
texture.wrapS = THREE.ClampToEdgeWrapping
|
|
105
|
+
texture.wrapT = THREE.ClampToEdgeWrapping
|
|
106
|
+
texture.minFilter = THREE.LinearFilter
|
|
107
|
+
texture.magFilter = THREE.LinearFilter
|
|
108
|
+
|
|
109
|
+
const material = new THREE.MeshBasicMaterial({
|
|
110
|
+
map: texture,
|
|
111
|
+
transparent: true,
|
|
112
|
+
side: THREE.DoubleSide,
|
|
113
|
+
depthWrite: false,
|
|
114
|
+
opacity: 0 // Start with 0 opacity
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// Start fade-in when texture is loaded
|
|
118
|
+
this.startTimes.set(material, Date.now())
|
|
119
|
+
panorMaterials.push(material)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
void load()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const panoramaBox = new THREE.Mesh(panorGeo, panorMaterials)
|
|
126
|
+
panoramaBox.onBeforeRender = () => {
|
|
127
|
+
this.time += 0.01
|
|
128
|
+
panoramaBox.rotation.y = Math.PI + this.time * 0.01
|
|
129
|
+
panoramaBox.rotation.z = Math.sin(-this.time * 0.001) * 0.001
|
|
130
|
+
|
|
131
|
+
// Time-based fade in animation for each material
|
|
132
|
+
for (const material of panorMaterials) {
|
|
133
|
+
const startTime = this.startTimes.get(material)
|
|
134
|
+
if (startTime) {
|
|
135
|
+
const elapsed = Date.now() - startTime
|
|
136
|
+
const progress = Math.min(1, elapsed / fadeInDuration)
|
|
137
|
+
material.opacity = progress
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const group = new THREE.Object3D()
|
|
143
|
+
group.add(panoramaBox)
|
|
144
|
+
|
|
145
|
+
if (!isChristmas) {
|
|
146
|
+
// Add entities
|
|
147
|
+
for (let i = 0; i < 20; i++) {
|
|
148
|
+
const m = new EntityMesh('1.16.4', 'squid').mesh
|
|
149
|
+
m.position.set(Math.random() * 30 - 15, Math.random() * 20 - 10, Math.random() * 10 - 17)
|
|
150
|
+
m.rotation.set(0, Math.PI + Math.random(), -Math.PI / 4, 'ZYX')
|
|
151
|
+
const v = Math.random() * 0.01
|
|
152
|
+
m.children[0].onBeforeRender = () => {
|
|
153
|
+
m.rotation.y += v
|
|
154
|
+
m.rotation.z = Math.cos(panoramaBox.rotation.y * 3) * Math.PI / 4 - Math.PI / 2
|
|
155
|
+
}
|
|
156
|
+
group.add(m)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this.scene.add(group)
|
|
161
|
+
this.panoramaGroup = group
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async worldBlocksPanorama() {
|
|
165
|
+
const version = PANORAMA_VERSION
|
|
166
|
+
const fullResourceManager = this.options.resourcesManager
|
|
167
|
+
fullResourceManager.currentConfig = { version, noInventoryGui: true, }
|
|
168
|
+
await fullResourceManager.updateAssetsData?.({})
|
|
169
|
+
if (this.abortController.signal.aborted) return
|
|
170
|
+
console.time('load panorama scene')
|
|
171
|
+
const world = getSyncWorld(version)
|
|
172
|
+
const PrismarineBlock = require('prismarine-block')
|
|
173
|
+
const Block = PrismarineBlock(version)
|
|
174
|
+
const mcData = (globalThis as any).mcData
|
|
175
|
+
const fullBlocks = mcData.blocksArray.filter(block => {
|
|
176
|
+
// if (block.name.includes('leaves')) return false
|
|
177
|
+
if (/* !block.name.includes('wool') && */!block.name.includes('stained_glass')/* && !block.name.includes('terracotta') */) return false
|
|
178
|
+
const b = Block.fromStateId(block.defaultState, 0)
|
|
179
|
+
if (b.shapes?.length !== 1) return false
|
|
180
|
+
const shape = b.shapes[0]
|
|
181
|
+
return shape[0] === 0 && shape[1] === 0 && shape[2] === 0 && shape[3] === 1 && shape[4] === 1 && shape[5] === 1
|
|
182
|
+
})
|
|
183
|
+
const Z = -15
|
|
184
|
+
const sizeX = 100
|
|
185
|
+
const sizeY = 100
|
|
186
|
+
for (let x = -sizeX; x < sizeX; x++) {
|
|
187
|
+
for (let y = -sizeY; y < sizeY; y++) {
|
|
188
|
+
const block = fullBlocks[Math.floor(Math.random() * fullBlocks.length)]
|
|
189
|
+
world.setBlockStateId(new Vec3(x, y, Z), block.defaultState)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
this.camera.updateProjectionMatrix()
|
|
193
|
+
this.camera.position.set(0.5, sizeY / 2 + 0.5, 0.5)
|
|
194
|
+
this.camera.rotation.set(0, 0, 0)
|
|
195
|
+
const initPos = new Vec3(...this.camera.position.toArray())
|
|
196
|
+
const worldView = new WorldView(world, 2, initPos)
|
|
197
|
+
// worldView.addWaitTime = 0
|
|
198
|
+
if (this.abortController.signal.aborted) return
|
|
199
|
+
|
|
200
|
+
this.worldRenderer = new this.WorldRendererClass(
|
|
201
|
+
this.documentRenderer.renderer,
|
|
202
|
+
this.options,
|
|
203
|
+
{
|
|
204
|
+
version,
|
|
205
|
+
worldView,
|
|
206
|
+
inWorldRenderingConfig: defaultWorldRendererConfig,
|
|
207
|
+
playerStateReactive: getInitialPlayerStateRenderer().reactive,
|
|
208
|
+
rendererState: getDefaultRendererState().reactive,
|
|
209
|
+
nonReactiveState: getDefaultRendererState().nonReactive
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
if (this.worldRenderer instanceof WorldRendererThree) {
|
|
213
|
+
this.scene = this.worldRenderer.scene
|
|
214
|
+
}
|
|
215
|
+
void worldView.init(initPos)
|
|
216
|
+
|
|
217
|
+
await this.worldRenderer.waitForChunksToRender()
|
|
218
|
+
if (this.abortController.signal.aborted) return
|
|
219
|
+
// add small camera rotation to side on mouse move depending on absolute position of the cursor
|
|
220
|
+
const { camera } = this
|
|
221
|
+
const initX = camera.position.x
|
|
222
|
+
const initY = camera.position.y
|
|
223
|
+
let prevTwin: tweenJs.Tween<THREE.Vector3> | undefined
|
|
224
|
+
document.body.addEventListener('pointermove', (e) => {
|
|
225
|
+
if (e.pointerType !== 'mouse') return
|
|
226
|
+
const pos = new THREE.Vector2(e.clientX, e.clientY)
|
|
227
|
+
const SCALE = 0.2
|
|
228
|
+
/* -0.5 - 0.5 */
|
|
229
|
+
const xRel = pos.x / window.innerWidth - 0.5
|
|
230
|
+
const yRel = -(pos.y / window.innerHeight - 0.5)
|
|
231
|
+
prevTwin?.stop()
|
|
232
|
+
const to = {
|
|
233
|
+
x: initX + (xRel * SCALE),
|
|
234
|
+
y: initY + (yRel * SCALE)
|
|
235
|
+
}
|
|
236
|
+
prevTwin = new tweenJs.Tween(camera.position).to(to, 0) // todo use the number depending on diff // todo use the number depending on diff
|
|
237
|
+
// prevTwin.easing(tweenJs.Easing.Exponential.InOut)
|
|
238
|
+
prevTwin.start()
|
|
239
|
+
camera.updateProjectionMatrix()
|
|
240
|
+
}, {
|
|
241
|
+
signal: this.abortController.signal
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
console.timeEnd('load panorama scene')
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
dispose() {
|
|
248
|
+
this.scene.clear()
|
|
249
|
+
this.worldRenderer?.destroy()
|
|
250
|
+
this.abortController.abort()
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// export class ClassicPanoramaRenderer {
|
|
255
|
+
// panoramaGroup: THREE.Object3D
|
|
256
|
+
|
|
257
|
+
// constructor (private readonly backgroundFiles: string[], onRender: Array<(sizeChanged: boolean) => void>, addSquids = true) {
|
|
258
|
+
// const panorGeo = new THREE.BoxGeometry(1000, 1000, 1000)
|
|
259
|
+
// const loader = new THREE.TextureLoader()
|
|
260
|
+
// const panorMaterials = [] as THREE.MeshBasicMaterial[]
|
|
261
|
+
|
|
262
|
+
// for (const file of this.backgroundFiles) {
|
|
263
|
+
// const texture = loader.load(file)
|
|
264
|
+
|
|
265
|
+
// // Instead of using repeat/offset to flip, we'll use the texture matrix
|
|
266
|
+
// texture.matrixAutoUpdate = false
|
|
267
|
+
// texture.matrix.set(
|
|
268
|
+
// -1, 0, 1, 0, 1, 0, 0, 0, 1
|
|
269
|
+
// )
|
|
270
|
+
|
|
271
|
+
// texture.wrapS = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
|
|
272
|
+
// texture.wrapT = THREE.ClampToEdgeWrapping // Changed from RepeatWrapping
|
|
273
|
+
// texture.minFilter = THREE.LinearFilter
|
|
274
|
+
// texture.magFilter = THREE.LinearFilter
|
|
275
|
+
|
|
276
|
+
// panorMaterials.push(new THREE.MeshBasicMaterial({
|
|
277
|
+
// map: texture,
|
|
278
|
+
// transparent: true,
|
|
279
|
+
// side: THREE.DoubleSide,
|
|
280
|
+
// depthWrite: false,
|
|
281
|
+
// }))
|
|
282
|
+
// }
|
|
283
|
+
|
|
284
|
+
// const panoramaBox = new THREE.Mesh(panorGeo, panorMaterials)
|
|
285
|
+
// panoramaBox.onBeforeRender = () => {
|
|
286
|
+
// }
|
|
287
|
+
|
|
288
|
+
// const group = new THREE.Object3D()
|
|
289
|
+
// group.add(panoramaBox)
|
|
290
|
+
|
|
291
|
+
// if (addSquids) {
|
|
292
|
+
// // Add squids
|
|
293
|
+
// for (let i = 0; i < 20; i++) {
|
|
294
|
+
// const m = new EntityMesh('1.16.4', 'squid').mesh
|
|
295
|
+
// m.position.set(Math.random() * 30 - 15, Math.random() * 20 - 10, Math.random() * 10 - 17)
|
|
296
|
+
// m.rotation.set(0, Math.PI + Math.random(), -Math.PI / 4, 'ZYX')
|
|
297
|
+
// const v = Math.random() * 0.01
|
|
298
|
+
// onRender.push(() => {
|
|
299
|
+
// m.rotation.y += v
|
|
300
|
+
// m.rotation.z = Math.cos(panoramaBox.rotation.y * 3) * Math.PI / 4 - Math.PI / 2
|
|
301
|
+
// })
|
|
302
|
+
// group.add(m)
|
|
303
|
+
// }
|
|
304
|
+
// }
|
|
305
|
+
|
|
306
|
+
// this.panoramaGroup = group
|
|
307
|
+
// }
|
|
308
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PANORAMA_VERSION = '1.21.4'
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { getRenamedData } from 'mineflayer-mouse/dist/blockRenames'
|
|
2
|
+
import { BlockModel } from 'mc-assets'
|
|
3
|
+
import { versionToNumber } from 'mc-assets/dist/utils'
|
|
4
|
+
import type { ResourcesManagerCommon } from '@/resourcesManager'
|
|
5
|
+
|
|
6
|
+
export type ResolvedItemModelRender = {
|
|
7
|
+
modelName: string,
|
|
8
|
+
originalItemName?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const renderSlot = (model: ResolvedItemModelRender, resourcesManager: ResourcesManagerCommon, debugIsQuickbar = false, fullBlockModelSupport = false): {
|
|
12
|
+
texture: string,
|
|
13
|
+
blockData: Record<string, { slice, path }> & { resolvedModel: BlockModel } | null,
|
|
14
|
+
scale: number | null,
|
|
15
|
+
slice: number[] | null,
|
|
16
|
+
modelName: string | null,
|
|
17
|
+
} => {
|
|
18
|
+
let itemModelName = model.modelName
|
|
19
|
+
const isItem = loadedData.itemsByName[itemModelName]
|
|
20
|
+
|
|
21
|
+
// #region normalize item name
|
|
22
|
+
if (versionToNumber(bot.version) < versionToNumber('1.13')) itemModelName = getRenamedData(isItem ? 'items' : 'blocks', itemModelName, bot.version, '1.13.1') as string
|
|
23
|
+
// #endregion
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
let itemTexture
|
|
27
|
+
|
|
28
|
+
if (!fullBlockModelSupport) {
|
|
29
|
+
const atlas = resourcesManager.currentResources?.guiAtlas?.json
|
|
30
|
+
// todo atlas holds all rendered blocks, not all possibly rendered item/block models, need to request this on demand instead (this is how vanilla works)
|
|
31
|
+
const tryGetAtlasTexture = (name?: string) => name && atlas?.textures[name.replace('minecraft:', '').replace('block/', '').replace('blocks/', '').replace('item/', '').replace('items/', '').replace('_inventory', '')]
|
|
32
|
+
const item = tryGetAtlasTexture(itemModelName) ?? tryGetAtlasTexture(model.originalItemName)
|
|
33
|
+
if (item) {
|
|
34
|
+
const x = item.u * atlas.width
|
|
35
|
+
const y = item.v * atlas.height
|
|
36
|
+
return {
|
|
37
|
+
texture: 'gui',
|
|
38
|
+
slice: [x, y, atlas.tileSize, atlas.tileSize],
|
|
39
|
+
scale: 0.25,
|
|
40
|
+
blockData: null,
|
|
41
|
+
modelName: null
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const blockToTopTexture = (r) => r.top ?? r
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
if (!appViewer.resourcesManager.currentResources?.itemsRenderer) throw new Error('Items renderer is not available')
|
|
50
|
+
itemTexture =
|
|
51
|
+
appViewer.resourcesManager.currentResources.itemsRenderer.getItemTexture(itemModelName, {}, false, fullBlockModelSupport)
|
|
52
|
+
?? (model.originalItemName ? appViewer.resourcesManager.currentResources.itemsRenderer.getItemTexture(model.originalItemName, {}, false, fullBlockModelSupport) : undefined)
|
|
53
|
+
?? appViewer.resourcesManager.currentResources.itemsRenderer.getItemTexture('item/missing_texture')!
|
|
54
|
+
} catch (err) {
|
|
55
|
+
// get resourcepack from resource manager
|
|
56
|
+
reportError?.(`Failed to render item ${itemModelName} (original: ${model.originalItemName}) on ${bot.version} (resourcepack: TODO!): ${err.stack}`)
|
|
57
|
+
itemTexture = blockToTopTexture(appViewer.resourcesManager.currentResources!.itemsRenderer!.getItemTexture('errored')!)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
itemTexture ??= blockToTopTexture(appViewer.resourcesManager.currentResources!.itemsRenderer!.getItemTexture('unknown')!)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if ('type' in itemTexture) {
|
|
64
|
+
// is item
|
|
65
|
+
return {
|
|
66
|
+
texture: itemTexture.type,
|
|
67
|
+
slice: itemTexture.slice,
|
|
68
|
+
modelName: itemModelName,
|
|
69
|
+
blockData: null,
|
|
70
|
+
scale: null
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
// is block
|
|
74
|
+
return {
|
|
75
|
+
texture: 'blocks',
|
|
76
|
+
blockData: itemTexture,
|
|
77
|
+
modelName: itemModelName,
|
|
78
|
+
slice: null,
|
|
79
|
+
scale: null
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|