multiview. camera controls

This commit is contained in:
David Allemang
2026-07-04 10:43:11 -04:00
parent b4029d1bdf
commit 8249c4dd52
5 changed files with 352 additions and 141 deletions

View File

@@ -54,6 +54,7 @@ export class TextureAtlas {
this.map = new Map();
this.cellSize = 16;
this.padding = 2; // Add empty space between textures
this.x = 0;
this.y = 0;
this.rowHeight = 0;
@@ -64,10 +65,10 @@ export class TextureAtlas {
const url = resolveResourceLocation(id, 'textures', 'png');
// Calculate position before trying to load, so we can draw a fallback if it fails
// Include padding in the wrap calculation
if (this.x + this.cellSize > this.canvas.width) {
this.x = 0;
this.y += this.rowHeight;
this.y += this.rowHeight + this.padding;
this.rowHeight = 0;
}
@@ -86,27 +87,22 @@ export class TextureAtlas {
this.ctx.drawImage(img, currentX, currentY, this.cellSize, this.cellSize);
} catch (e) {
console.warn(`Texture missing: ${id}`);
// Draw magenta square ONLY for missing textures
this.ctx.fillStyle = '#ff00ff';
this.ctx.fillRect(currentX, currentY, this.cellSize, this.cellSize);
}
const epsU = 0.1 / this.canvas.width;
const epsV = 0.1 / this.canvas.height;
// Clean UV mapping (padding protects the edges natively)
const uvData = {
// Push the start coordinate slightly inward
u: (currentX / this.canvas.width) + epsU,
v: (currentY / this.canvas.height) + epsV,
// Shrink the total width/height to account for the inset on both sides
du: (this.cellSize / this.canvas.width) - (epsU * 2),
dv: (this.cellSize / this.canvas.height) - (epsV * 2)
u: currentX / this.canvas.width,
v: currentY / this.canvas.height,
du: this.cellSize / this.canvas.width,
dv: this.cellSize / this.canvas.height
};
this.map.set(id, uvData);
this.map.set(id, uvData);
this.x += this.cellSize;
// Advance X by cell size AND padding
this.x += this.cellSize + this.padding;
this.rowHeight = Math.max(this.rowHeight, this.cellSize);
return uvData;