diff --git a/prismarine-viewer/viewer/lib/mesher/models.ts b/prismarine-viewer/viewer/lib/mesher/models.ts index 9b3a1ecd..c9e2bd3b 100644 --- a/prismarine-viewer/viewer/lib/mesher/models.ts +++ b/prismarine-viewer/viewer/lib/mesher/models.ts @@ -120,7 +120,7 @@ function getLiquidRenderHeight (world, block, type, pos) { } const isCube = (block) => { - if (!block) return false + if (!block || block.transparent) return false if (block.isCube) return true if (!block.variant) block.variant = getModelVariants(block) return block.variant.every(v => v?.model?.elements.every(e => { @@ -147,7 +147,8 @@ function renderLiquid (world, cursor, texture, type, biome, water, attr) { const { dir, corners } = elemFaces[face] const isUp = dir[1] === 1 - const neighbor = world.getBlock(cursor.offset(...dir)) + const neighborPos = cursor.offset(...dir) + const neighbor = world.getBlock(neighborPos) if (!neighbor) continue if (neighbor.type === type) continue if ((isCube(neighbor) && !isUp) || neighbor.material === 'plant' || neighbor.getProperties().waterlogged) continue @@ -161,6 +162,18 @@ function renderLiquid (world, cursor, texture, type, biome, water, attr) { tint = [tint[0] * m, tint[1] * m, tint[2] * m] } + if (needTiles) { + attr.tiles[`${cursor.x},${cursor.y},${cursor.z}`] ??= { + block: 'water', + faces: [], + } + attr.tiles[`${cursor.x},${cursor.y},${cursor.z}`].faces.push({ + face, + neighbor: `${neighborPos.x},${neighborPos.y},${neighborPos.z}`, + // texture: eFace.texture.name, + }) + } + const u = texture.u const v = texture.v const su = texture.su @@ -268,6 +281,7 @@ function renderElement (world: World, cursor: Vec3, element, doAO: boolean, attr if (!neighbor.transparent && isCube(neighbor)) continue } else { needRecompute = true + continue } } diff --git a/prismarine-viewer/viewer/lib/utils.web.js b/prismarine-viewer/viewer/lib/utils.web.js index cbb94222..ffa22808 100644 --- a/prismarine-viewer/viewer/lib/utils.web.js +++ b/prismarine-viewer/viewer/lib/utils.web.js @@ -3,12 +3,12 @@ const THREE = require('three') const textureCache = {} function loadTexture (texture, cb, onLoad) { - if (!textureCache[texture]) { + const cached = textureCache[texture] + if (!cached) { textureCache[texture] = new THREE.TextureLoader().load(texture, onLoad) - } else { - onLoad?.() } cb(textureCache[texture]) + if (cached) onLoad?.() } function loadJSON (url, callback) { diff --git a/src/panorama.ts b/src/panorama.ts index 1f614371..3d7aec32 100644 --- a/src/panorama.ts +++ b/src/panorama.ts @@ -69,7 +69,8 @@ export async function addPanoramaCubeMap () { shouldDisplayPanorama = true let time = 0 - viewer.camera = new THREE.PerspectiveCamera(85, window.innerWidth / window.innerHeight, 0.05, 1000) + viewer.camera.fov = 85 + viewer.camera.near = 0.05 viewer.camera.updateProjectionMatrix() viewer.camera.position.set(0, 0, 0) viewer.camera.rotation.set(0, 0, 0) @@ -119,7 +120,8 @@ export async function addPanoramaCubeMap () { export function removePanorama () { shouldDisplayPanorama = false if (!panoramaCubeMap) return - viewer.camera = new THREE.PerspectiveCamera(options.fov, window.innerWidth / window.innerHeight, 0.1, 1000) + viewer.camera.fov = options.fov + viewer.camera.near = 0.1 viewer.camera.updateProjectionMatrix() viewer.scene.remove(panoramaCubeMap) panoramaCubeMap = null