]> _ Git - fluidbook-html5.git/commitdiff
wip #809 @0:40
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 17 Aug 2018 18:03:05 +0000 (20:03 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 17 Aug 2018 18:03:05 +0000 (20:03 +0200)
js/libs/fluidbook/fluidbook.3dflip.js
js/libs/fluidbook/fluidbook.loader.js

index 9f11be0ad1df6d5cfb2163081066fdada2cf71ec..8c5a75b8f04f23e1cc76f85e25b7bd2a7d9c2544 100644 (file)
@@ -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();
                 }
index f06fbe085affd72f2b4fe6be854c1e27f8f0dd2a..d0610d11aad5633d18a3f0064e268899bac16362 100644 (file)
@@ -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();