From 21f309c8a95db874d77ba441cad948c71147fda0 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 17 Aug 2018 20:03:05 +0200 Subject: [PATCH] wip #809 @0:40 --- js/libs/fluidbook/fluidbook.3dflip.js | 39 +++++++++++++-------------- js/libs/fluidbook/fluidbook.loader.js | 18 ++++++++++--- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.3dflip.js b/js/libs/fluidbook/fluidbook.3dflip.js index 9f11be0a..8c5a75b8 100644 --- a/js/libs/fluidbook/fluidbook.3dflip.js +++ b/js/libs/fluidbook/fluidbook.3dflip.js @@ -127,7 +127,7 @@ Fluidbook3DFlip.prototype = { this.sizePlane = new THREE.Mesh(geometry3); this.sizePlane.castShadow = this.sizePlane.receiveShadow = false; - this.sizePlane.visible=false; + this.sizePlane.visible = false; this.scene.add(this.sizePlane); this.scene.add(this.plane); @@ -188,7 +188,6 @@ Fluidbook3DFlip.prototype = { }, prepareTurn: function (turning, callback) { - var $this = this; this.prepareTexture(turning.flip[1], function (t1) { $this.prepareTexture(turning.flip[0], function (t2) { @@ -209,25 +208,24 @@ Fluidbook3DFlip.prototype = { callback(); }, + disposeTextures: function () { + if (this.textures[0].map !== null) { + this.textures[0].map.dispose(); + } + if (this.textures[1].map !== null) { + this.textures[1].map.dispose(); + } + }, + prepareTexture: function (page, callback) { - var d = 1024; - var c = document.getElementById("pscanvas"); - c.width = d; - c.height = d; - var ctx = c.getContext("2d"); - ctx.clearRect(0, 0, d, d); - var img = new Image(); - img.src = "data/background/150/t" + page + ".jpg"; - img.onload = function () { - ctx.drawImage(img, 0, 0, d, d); - var i = new Image(); - var texture = new THREE.Texture(i); - i.onload = function () { - texture.needsUpdate = true; - callback(texture); - } - i.src = c.toDataURL("image/png"); - }; + this.disposeTextures(); + + var $this = this; + this.fluidbook.loader.loadTexture(page, function () { + var texture = new THREE.Texture($this.fluidbook.loader.getTexture(page)); + texture.needsUpdate = true; + callback(texture); + }); }, playTurn: function (dir, callback) { @@ -254,6 +252,7 @@ Fluidbook3DFlip.prototype = { ease: Power0.easeIn, onComplete: function () { $this.turnRunning = false; + $this.disposeTextures(); this.tlname = ''; callback(); } diff --git a/js/libs/fluidbook/fluidbook.loader.js b/js/libs/fluidbook/fluidbook.loader.js index f06fbe08..d0610d11 100644 --- a/js/libs/fluidbook/fluidbook.loader.js +++ b/js/libs/fluidbook/fluidbook.loader.js @@ -21,6 +21,7 @@ FluidbookLoader.prototype = { return 'raster'; }, + preloadPagesBeforeTransition: function (pages, callback) { var $this = this; var $pages = pages.slice(0); @@ -66,6 +67,11 @@ FluidbookLoader.prototype = { }, _preloadPage: function (page, callback) { + if (page == undefined || page == 'undefined' || page > this.fluidbook.getMaxPage() || page < 1) { + callback(); + return; + } + var $this = this; if (this.backgrounds[page] != undefined) { callback(); @@ -74,7 +80,7 @@ FluidbookLoader.prototype = { if (this.fluidbook.support.transitions3dacc) { $_callback = function () { - $this._loadTexture(page, callback); + $this.loadTexture(page, callback); }; } else { $_callback = callback; @@ -277,7 +283,7 @@ FluidbookLoader.prototype = { } this.backgrounds[page] = this.loadImage(url, null, null, null, callback); }, - _loadTexture: function (page, callback) { + loadTexture: function (page, callback) { if (page <= 0 || page > this.fluidbook.datas.pages) { callback(); return; @@ -285,11 +291,11 @@ FluidbookLoader.prototype = { if (this.textures[page] != undefined) { callback(); } else { - this.__loadTexture(page, callback); + this._loadTexture(page, callback); } }, - __loadTexture: function (page, callback) { + _loadTexture: function (page, callback) { if (page <= 0 || page > this.fluidbook.datas.pages) { callback(); return; @@ -302,6 +308,10 @@ FluidbookLoader.prototype = { this.textures[page] = this.loadImage(url, null, null, null, callback); }, + getTexture: function (page) { + return this.textures[page].get(0); + }, + loadTexts: function (pageNr, callback) { if (pageNr <= 0 || pageNr > this.fluidbook.datas.pages) { callback(); -- 2.39.5