faster texture loading

This commit is contained in:
David Allemang
2026-07-04 12:35:49 -04:00
parent 57660397aa
commit ffd48b2585
3 changed files with 105 additions and 120 deletions

View File

@@ -54,40 +54,34 @@
async function initDocument() {
try {
// 1. Initialize the global background renderer
const engine = new Engine();
// Append the texture atlas to the bottom for debugging
document.getElementById('atlas-container')?.appendChild(engine.atlas.canvas);
// 2. Setup Figure 1 (Shared: Wire & Repeater | Unique: Trapdoor)
const demo1 = new Diorama('demo-1', engine);
// Adjust camera to fit the small viewport
// Pass the render trigger directly
const demo1 = new Diorama('demo-1', () => engine.requestRender());
demo1.camera.radius = 2;
demo1.camera.phi = 10
demo1.camera.theta = -5
demo1.world.setBlock('minecraft:redstone_wire', 0, 0, 0, {
east: 'side',
demo1.camera.phi = 10;
demo1.camera.theta = -5;
demo1.world.setBlock('minecraft:redstone_wire', -1, 0, 0, {
east: 'none',
west: 'none',
north: 'none',
south: 'none',
power: '15'
});
demo1.world.setBlock('minecraft:repeater', 1, 0, 0, {
demo1.world.setBlock('minecraft:repeater', 0, 0, 0, {
facing: 'east',
delay: '1',
locked: 'false',
powered: 'true'
});
demo1.world.setBlock('minecraft:oak_trapdoor', 2, 0, 0, {facing: 'east', half: 'bottom', open: 'true'});
demo1.world.setBlock('lodestone', 0, -1, 0);
demo1.world.setBlock('piston', 0, -2, 0, {facing: 'north', extended: 'false'});
// 3. Setup Figure 2 (Shared: Wire & Repeater | Unique: Piston & Redstone Block)
const demo2 = new Diorama('demo-2', engine);
// Adjust camera to fit the small viewport
const demo2 = new Diorama('demo-2', () => engine.requestRender());
demo2.camera.radius = 3;
// View from a slightly different angle
demo2.world.setBlock('minecraft:redstone_wire', 0, 0, 0, {
east: 'side',
west: 'none',
@@ -106,25 +100,20 @@
demo2.world.setBlock('minecraft:sticky_piston', 2, 0, 2, {facing: 'east', extended: 'true'});
demo2.world.setBlock('minecraft:piston_head', 2.5, 0, 1, {facing: 'east', short: 'true', type: 'sticky'});
demo2.world.setBlock('minecraft:piston_head', 3, 0, 2, {facing: 'east', short: 'false', type: 'sticky'});
demo2.world.setBlock('minecraft:glass', 3, 0, 0);
demo2.world.setBlock('minecraft:observer', 3.5, 0, 1, {facing: 'up', powered: 'true'});
demo2.world.setBlock('minecraft:redstone_block', 4, 0, 2);
demo1.centerView()
demo1.centerView();
demo1.camera.saveState();
demo2.centerView()
demo2.centerView();
demo2.camera.saveState();
engine.addDiorama(demo1);
engine.addDiorama(demo2);
// 4. Build geometries and draw
// We await these so the meshes are fully baked and the atlas is populated
await demo1.update();
await demo2.update();
// Fetch and build everything concurrently!
await engine.updateAll();
} catch (err) {
console.error("Renderer Initialization Failed:", err);
}