minecraft-renderer 0.1.81 → 0.1.83

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-renderer",
3
- "version": "0.1.81",
3
+ "version": "0.1.83",
4
4
  "description": "The most Modular Minecraft world renderer with Three.js WebGL backend",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -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
- // Rescale support for block model rotations
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
- // todo do we support rescale?
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,6 +9,12 @@ export const disposeObject = (obj: THREE.Object3D, cleanTextures = false) => {
9
9
  obj.geometry?.dispose?.()
10
10
  obj.material?.dispose?.()
11
11
  }
12
+ if (obj instanceof THREE.SkinnedMesh) {
13
+ // SkinnedMesh skeletons are not scene-graph children, so the recursion below never reaches them.
14
+ // skeleton.dispose() frees the lazily-created bone DataTexture (Skeleton.computeBoneTexture),
15
+ // which otherwise leaks +1 GPU texture per entity on every F3+A reload (issue #56).
16
+ obj.skeleton?.dispose?.()
17
+ }
12
18
  if (obj.children) {
13
19
  // eslint-disable-next-line unicorn/no-array-for-each
14
20
  obj.children.forEach(child => disposeObject(child, cleanTextures))
@@ -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 = buildRotationMatrix(element.rotation.axis, element.rotation.angle)
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 = buildRotationMatrix(element.rotation.axis, element.rotation.angle)
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