minecraft-renderer 0.1.81 → 0.1.82
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 +19 -19
- package/dist/mesher.js.map +3 -3
- package/dist/mesherWasm.js +167 -167
- package/dist/minecraft-renderer.js +61 -61
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +406 -406
- package/package.json +1 -1
- package/src/mesher-shared/models.ts +2 -30
- package/src/mesher-shared/modelsGeometryCommon.ts +22 -0
- package/src/mesher-shared/standaloneRenderer.ts +2 -5
- package/src/wasm-mesher/bridge/render-from-wasm.ts +3 -5
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import worldBlockProvider, { WorldBlockProvider } from 'mc-assets/dist/worldBloc
|
|
|
4
4
|
import moreBlockDataGeneratedJson from '../lib/moreBlockDataGenerated.json'
|
|
5
5
|
import { BlockType } from '../playground/shared'
|
|
6
6
|
import { World, BlockModelPartsResolved, WorldBlock as Block, WorldBlock, worldColumnKey } from './world'
|
|
7
|
-
import { BlockElement, buildRotationMatrix, elemFaces, matmul3, matmulmat3, vecadd3, vecsub3 } from './modelsGeometryCommon'
|
|
7
|
+
import { BlockElement, buildElementRotation, buildRotationMatrix, elemFaces, matmul3, matmulmat3, vecadd3, vecsub3 } from './modelsGeometryCommon'
|
|
8
8
|
import { getSideShading } from './vertexShading'
|
|
9
9
|
import { INVISIBLE_BLOCKS } from './worldConstants'
|
|
10
10
|
import { MesherGeometryOutput, HighestBlockInfo } from './shared'
|
|
@@ -342,35 +342,7 @@ function renderElement(
|
|
|
342
342
|
let localShift = null as any
|
|
343
343
|
|
|
344
344
|
if (element.rotation && !needTiles) {
|
|
345
|
-
|
|
346
|
-
localMatrix = buildRotationMatrix(element.rotation.axis, element.rotation.angle)
|
|
347
|
-
|
|
348
|
-
localShift = vecsub3(element.rotation.origin, matmul3(localMatrix, element.rotation.origin))
|
|
349
|
-
|
|
350
|
-
// Apply rescale if specified
|
|
351
|
-
if (element.rotation.rescale) {
|
|
352
|
-
const FIT_TO_BLOCK_SCALE_MULTIPLIER = 2 - Math.sqrt(2)
|
|
353
|
-
const angleRad = (element.rotation.angle * Math.PI) / 180
|
|
354
|
-
const scale = Math.abs(Math.sin(angleRad)) * FIT_TO_BLOCK_SCALE_MULTIPLIER
|
|
355
|
-
|
|
356
|
-
// Get axis vector components (1 for the rotation axis, 0 for others)
|
|
357
|
-
const axisX = element.rotation.axis === 'x' ? 1 : 0
|
|
358
|
-
const axisY = element.rotation.axis === 'y' ? 1 : 0
|
|
359
|
-
const axisZ = element.rotation.axis === 'z' ? 1 : 0
|
|
360
|
-
|
|
361
|
-
// Create scale matrix: scale = (1 - axisComponent) * scaleFactor + 1
|
|
362
|
-
const scaleMatrix = [
|
|
363
|
-
[(1 - axisX) * scale + 1, 0, 0],
|
|
364
|
-
[0, (1 - axisY) * scale + 1, 0],
|
|
365
|
-
[0, 0, (1 - axisZ) * scale + 1]
|
|
366
|
-
]
|
|
367
|
-
|
|
368
|
-
// Apply scaling to the transformation matrix
|
|
369
|
-
localMatrix = matmulmat3(localMatrix, scaleMatrix)
|
|
370
|
-
|
|
371
|
-
// Recalculate shift with the new matrix
|
|
372
|
-
localShift = vecsub3(element.rotation.origin, matmul3(localMatrix, element.rotation.origin))
|
|
373
|
-
}
|
|
345
|
+
;({ localMatrix, localShift } = buildElementRotation(element.rotation))
|
|
374
346
|
}
|
|
375
347
|
|
|
376
348
|
const aos: number[] = []
|
|
@@ -88,6 +88,28 @@ export function matmulmat3(a, b) {
|
|
|
88
88
|
return te
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
export function buildElementRotation(rotation) {
|
|
92
|
+
let localMatrix = buildRotationMatrix(rotation.axis, rotation.angle)
|
|
93
|
+
let localShift = vecsub3(rotation.origin, matmul3(localMatrix, rotation.origin))
|
|
94
|
+
|
|
95
|
+
if (rotation.rescale) {
|
|
96
|
+
const FIT_TO_BLOCK_SCALE_MULTIPLIER = 2 - Math.sqrt(2)
|
|
97
|
+
const angleRad = (rotation.angle * Math.PI) / 180
|
|
98
|
+
const scale = Math.abs(Math.sin(angleRad)) * FIT_TO_BLOCK_SCALE_MULTIPLIER
|
|
99
|
+
const axisX = rotation.axis === 'x' ? 1 : 0
|
|
100
|
+
const axisY = rotation.axis === 'y' ? 1 : 0
|
|
101
|
+
const axisZ = rotation.axis === 'z' ? 1 : 0
|
|
102
|
+
const scaleMatrix = [
|
|
103
|
+
[(1 - axisX) * scale + 1, 0, 0],
|
|
104
|
+
[0, (1 - axisY) * scale + 1, 0],
|
|
105
|
+
[0, 0, (1 - axisZ) * scale + 1]
|
|
106
|
+
]
|
|
107
|
+
localMatrix = matmulmat3(localMatrix, scaleMatrix)
|
|
108
|
+
localShift = vecsub3(rotation.origin, matmul3(localMatrix, rotation.origin))
|
|
109
|
+
}
|
|
110
|
+
return { localMatrix, localShift }
|
|
111
|
+
}
|
|
112
|
+
|
|
91
113
|
export const elemFaces = {
|
|
92
114
|
up: {
|
|
93
115
|
dir: [0, 1, 0],
|
|
@@ -5,7 +5,7 @@ import { Block } from 'prismarine-block'
|
|
|
5
5
|
import { IndexedData } from 'minecraft-data'
|
|
6
6
|
import * as THREE from 'three'
|
|
7
7
|
import { BlockModelPartsResolved } from './world'
|
|
8
|
-
import { BlockElement, buildRotationMatrix, elemFaces, matmul3, matmulmat3, vecadd3, vecsub3 } from './modelsGeometryCommon'
|
|
8
|
+
import { BlockElement, buildElementRotation, buildRotationMatrix, elemFaces, matmul3, matmulmat3, vecadd3, vecsub3 } from './modelsGeometryCommon'
|
|
9
9
|
|
|
10
10
|
type NeighborSide = 'up' | 'down' | 'east' | 'west' | 'north' | 'south'
|
|
11
11
|
|
|
@@ -78,10 +78,7 @@ function renderElement(element: BlockElement, doAO: boolean, attr, globalMatrix,
|
|
|
78
78
|
let localShift = null as any
|
|
79
79
|
|
|
80
80
|
if (element.rotation) {
|
|
81
|
-
|
|
82
|
-
localMatrix = buildRotationMatrix(element.rotation.axis, element.rotation.angle)
|
|
83
|
-
|
|
84
|
-
localShift = vecsub3(element.rotation.origin, matmul3(localMatrix, element.rotation.origin))
|
|
81
|
+
;({ localMatrix, localShift } = buildElementRotation(element.rotation))
|
|
85
82
|
}
|
|
86
83
|
|
|
87
84
|
const aos: number[] = []
|
|
@@ -9,7 +9,7 @@ import blockStatesModels from 'mc-assets/dist/blockStatesModels.json'
|
|
|
9
9
|
import MinecraftData from 'minecraft-data'
|
|
10
10
|
import PrismarineBlockLoader from 'prismarine-block'
|
|
11
11
|
import { Vec3 } from 'vec3'
|
|
12
|
-
import { elemFaces, buildRotationMatrix, matmul3, matmulmat3, vecadd3, vecsub3 } from '../../mesher-shared/modelsGeometryCommon'
|
|
12
|
+
import { elemFaces, buildElementRotation, buildRotationMatrix, matmul3, matmulmat3, vecadd3, vecsub3 } from '../../mesher-shared/modelsGeometryCommon'
|
|
13
13
|
import type { ExportedWorldGeometry, ExportedSection } from '../../mesher-shared/exportedGeometryTypes'
|
|
14
14
|
import type { MesherGeometryOutput } from '../../mesher-shared/shared'
|
|
15
15
|
import { bakeLegacyVertexColors } from '../../lib/bakeLegacyLight'
|
|
@@ -290,8 +290,7 @@ function getCachedBlockModel(
|
|
|
290
290
|
let localMatrix = null as any
|
|
291
291
|
let localShift = null as any
|
|
292
292
|
if (element.rotation) {
|
|
293
|
-
localMatrix =
|
|
294
|
-
localShift = vecsub3(element.rotation.origin, matmul3(localMatrix, element.rotation.origin))
|
|
293
|
+
;({ localMatrix, localShift } = buildElementRotation(element.rotation))
|
|
295
294
|
}
|
|
296
295
|
return { element, localMatrix, localShift }
|
|
297
296
|
})
|
|
@@ -755,8 +754,7 @@ export function renderWasmOutputToGeometry(
|
|
|
755
754
|
let localMatrix = null as any
|
|
756
755
|
let localShift = null as any
|
|
757
756
|
if (element.rotation) {
|
|
758
|
-
localMatrix =
|
|
759
|
-
localShift = vecsub3(element.rotation.origin, matmul3(localMatrix, element.rotation.origin))
|
|
757
|
+
;({ localMatrix, localShift } = buildElementRotation(element.rotation))
|
|
760
758
|
}
|
|
761
759
|
|
|
762
760
|
// eslint-disable-next-line guard-for-in
|