block object
This commit is contained in:
14
engine.js
14
engine.js
@@ -1,6 +1,6 @@
|
||||
// engine.js
|
||||
import {mat4Identity, mat4Translate} from './math.js';
|
||||
import {ResourceCache} from "./resource-cache.js";
|
||||
import {Cache} from "./cache.js";
|
||||
import {Blockstate, BlockstateHandler} from "./blockstate.js";
|
||||
import {ModelHandler} from "./model.js";
|
||||
import {TextureHandler} from "./texture.js";
|
||||
@@ -94,7 +94,7 @@ export class Engine {
|
||||
this.atlasTexture = gl.createTexture();
|
||||
|
||||
// --- Initialize the new Resource Pipeline ---
|
||||
this.cache = new ResourceCache('assets');
|
||||
this.cache = new Cache('assets');
|
||||
this.atlas = new TextureHandler(256);
|
||||
this.cache.register('blockstates', new BlockstateHandler());
|
||||
this.cache.register('models', new ModelHandler());
|
||||
@@ -143,7 +143,7 @@ export class Engine {
|
||||
|
||||
addDiorama(diorama) {
|
||||
this.dioramas.push(diorama);
|
||||
if (!this.observedWorlds.has(diorama.world)) {
|
||||
if (!this.observedWorlds.has(diorama.worlds)) {
|
||||
this.observedWorlds.add(diorama.world);
|
||||
diorama.world.subscribe(() => this.requestUpdate());
|
||||
}
|
||||
@@ -168,7 +168,7 @@ export class Engine {
|
||||
const parsedBlocks = [];
|
||||
for (const block of world.blocks.values()) {
|
||||
const state = await this.cache.get(block.id, 'blockstates');
|
||||
const parts = state.resolveParts(block.props);
|
||||
const parts = state.resolveParts(block.state);
|
||||
parsedBlocks.push({block, parts});
|
||||
for (const p of parts) uniqueModelIds.add(p.model);
|
||||
}
|
||||
@@ -190,12 +190,12 @@ export class Engine {
|
||||
}
|
||||
|
||||
const matrix = mat4Identity(new Float32Array(16));
|
||||
mat4Translate(matrix, matrix, [block.x, block.y, block.z]);
|
||||
mat4Translate(matrix, matrix, block.pos);
|
||||
const pool = instancePool.get(hash);
|
||||
pool.matrices.push(...matrix);
|
||||
|
||||
if (block.props.power) {
|
||||
const p = parseInt(block.props.power, 10);
|
||||
if (block.state.power) {
|
||||
const p = parseInt(block.state.power, 10);
|
||||
pool.colors.push((0x4B + (p * 12)) / 255, 0.0, 0.0);
|
||||
} else {
|
||||
pool.colors.push(1.0, 1.0, 1.0);
|
||||
|
||||
Reference in New Issue
Block a user