Skip to content

Commit ce5d327

Browse files
cache & reuse animated materials
1 parent f69811e commit ce5d327

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/model/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,15 @@ let createCube = function (width, height, depth, name, faces, fallbackFaces, tex
905905
};
906906

907907
let loadTextureWithMeta = function (canvas, meta) {
908+
let hash = canvas.dataUrlHash;
908909
let hasTransparency = canvas.hasTransparency;
910+
911+
if (materialCache.hasOwnProperty(hash)) {// Use material from cache
912+
console.debug("Using cached Material (" + hash + ")");
913+
resolve(materialCache[hash]);
914+
return;
915+
}
916+
909917
let frametime = 1;
910918
if (meta.hasOwnProperty("animation")) {
911919
if (meta.animation.hasOwnProperty("frametime")) {
@@ -978,6 +986,10 @@ let createCube = function (width, height, depth, name, faces, fallbackFaces, tex
978986
frameCounter += 0.1;// game ticks TODO: figure out the proper value for this
979987
})
980988

989+
// Add material to cache
990+
console.debug("Caching Material " + hash);
991+
materialCache[hash] = material;
992+
981993
resolve(material);
982994
});
983995
};

0 commit comments

Comments
 (0)