Skip to content

Commit

Permalink
fix: Fix edgecase in AtlasParser to use image width and height variab…
Browse files Browse the repository at this point in the history
…les for rendering calculations
  • Loading branch information
zardoy committed Jul 25, 2024
1 parent f9abb04 commit 307cc7f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/consumer/atlasParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,18 @@ export class AtlasParser {
getLoadedImage: (name) => {
const texture = newTextures[name]!
const image = texture.img
const imgSize = image.width
const imgWidth = image.width
const imgHeight = image.height
//@ts-ignore we no longer need the image, remove from atlas
delete texture.img
return {
image,
renderWidth: texture.su * imgSize,
renderHeight: texture.sv * imgSize,
renderSourceStartX: texture.u * imgSize,
renderSourceStartY: texture.v * imgSize,
renderSourceWidth: texture.su * imgSize,
renderSourceHeight: texture.sv * imgSize,
renderWidth: texture.su * imgWidth,
renderHeight: texture.sv * imgHeight,
renderSourceStartX: texture.u * imgWidth,
renderSourceStartY: texture.v * imgHeight,
renderSourceWidth: texture.su * imgWidth,
renderSourceHeight: texture.sv * imgHeight,
}
},
tileSize: this.atlas.latest.tileSize,
Expand Down
1 change: 0 additions & 1 deletion web-demo/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default defineConfig({
},
},
server: {
strictPort: true,
},
plugins: [
pluginReact(),
Expand Down
17 changes: 14 additions & 3 deletions web-demo/src/pages/AtlasExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import { AtlasParser } from '../../../src/consumer/atlasParser'
globalThis.blockStatesModels = blockStatesModels

export default function AtlasExplorer() {
const qs = new URLSearchParams(window.location.search)
const canvasRef = useRef<HTMLCanvasElement>(null!)
const [selectedAtlas, setSelectedAtlas] = useState<'items' | 'items-legacy' | 'blocks' | 'blocks-legacy' | 'particles' | 'particles-legacy' | 'items-all-render' | 'blocks-all-render'>('items')
const [selectedAtlas, setSelectedAtlas] = useState<'items' | 'items-legacy' | 'blocks' | 'blocks-legacy' | 'particles' | 'particles-legacy' | 'items-all-render' | 'blocks-all-render'>(qs.get('type') as any ?? 'items')

const [legacyVariantVersion, setLegacyVariantVersion] = useState<string | undefined>()
const [legacyVariantVersion, setLegacyVariantVersion] = useState<string | undefined>(undefined)
const [customImage, setCustomImage] = useState<string | undefined>()
const [customAtlas, setCustomAtlas] = useState<any>()
useEffect(() => {
setCustomAtlas(undefined)
setCustomImage(undefined)
// setLegacyVariantVersion(qs.get('legacyVariantVersion') ?? undefined)
setLegacyVariantVersion(undefined)
}, [selectedAtlas])

Expand Down Expand Up @@ -146,6 +148,10 @@ export default function AtlasExplorer() {
ctx.fillStyle = 'red'
ctx.strokeRect(u * img.width, v * img.height, su * img.width, sv * img.height)
}

qs.set('type', selectedAtlas)
if (legacyVariantVersion) qs.set('legacyVariantVersion', legacyVariantVersion)
window.history.replaceState({}, '', `${window.location.pathname}?${qs.toString()}`)
}
}, [selectedAtlas, customImage, highlightTexture])

Expand Down Expand Up @@ -197,7 +203,12 @@ export default function AtlasExplorer() {
<select className='w-min border border-gray-700 rounded-lg' value={String(legacyVariantVersion)} onChange={(e) => {
setLegacyVariantVersion(e.target.value)
console.time('makeNewAtlas')
currentAtlasParser.makeNewAtlas(e.target.value, undefined).then(({ atlas, canvas }) => {
currentAtlasParser.makeNewAtlas(e.target.value, (path) => {
// if (path === testBlockOverridePath) {
// return testBlockOverride
// }
return
}).then(({ atlas, canvas }) => {
console.timeEnd('makeNewAtlas')
setCustomAtlas(atlas)
setCustomImage(canvas.toDataURL())
Expand Down

0 comments on commit 307cc7f

Please sign in to comment.