Browse Source

chore: 去除无用warn

hujinliang 5 years ago
parent
commit
538e6d06a1

+ 1 - 1
web/demo/src/components/HelloWorld.vue

@@ -7,7 +7,7 @@
 </template>
 
 <script>
-import Vap from '../../../src/index'
+import Vap from '../../../dist/vap.js'
 import config from './demo.json'
 export default {
   name: 'vap',

+ 44 - 21
web/dist/vap.js

@@ -189,28 +189,37 @@
               var src = this.srcData = {};
               return Promise.all((dataJson.src || []).map(function (item) {
                   return Promise.resolve().then(function () {
-                      if (item.srcType === 'txt') {
-                          item.textStr = item.srcTag.replace(/\[(.*)\]/, function ($0, $1) {
-                              return _this.headData[$1];
-                          });
-                          item.img = _this.makeTextImg(item);
+                      item.img = null;
+                      if (!_this.headData[item.srcTag.slice(1, item.srcTag.length - 1)]) {
+                          console.warn('vap: \u878D\u5408\u4FE1\u606F\u6CA1\u6709\u4F20\u5165\uFF1A' + item.srcTag);
                       } else {
-                          if (item.srcType === 'img') {
-                              item.imgUrl = item.srcTag.replace(/\[(.*)\]/, function ($0, $1) {
-                                  return _this.headData[$1];
-                              });
-                              return Promise.resolve().then(function () {
-                                  return _this.loadImg(item.imgUrl + '?t=' + Date.now());
-                              }).then(function (_resp) {
-                                  item.img = _resp;
-                              }).catch(function (e) {
-                                  return Promise.resolve();
-                              });
-                          }
+                          return Promise.resolve().then(function () {
+                              if (item.srcType === 'txt') {
+                                  item.textStr = item.srcTag.replace(/\[(.*)\]/, function ($0, $1) {
+                                      return _this.headData[$1];
+                                  });
+                                  item.img = _this.makeTextImg(item);
+                              } else {
+                                  if (item.srcType === 'img') {
+                                      item.imgUrl = item.srcTag.replace(/\[(.*)\]/, function ($0, $1) {
+                                          return _this.headData[$1];
+                                      });
+                                      return Promise.resolve().then(function () {
+                                          return _this.loadImg(item.imgUrl + '?t=' + Date.now());
+                                      }).then(function (_resp) {
+                                          item.img = _resp;
+                                      }).catch(function (e) {
+                                          return Promise.resolve();
+                                      });
+                                  }
+                              }
+                          }).then(function () {
+                              if (item.img) {
+                                  src[item.srcId] = item;
+                              }
+                          });
                       }
-                  }).then(function () {
-                      src[item.srcId] = item;
-                  });
+                  }).then(function () {});
               }));
           }
           /**
@@ -365,6 +374,8 @@
               var video = this.video = document.createElement('video');
               video.crossOrigin = 'anonymous';
               video.autoplay = false;
+              video.preload = 'auto';
+              video.autoload = true;
               // video.muted = true
               // video.volume = 0
               video.style.display = 'none';
@@ -660,6 +671,11 @@
                   gl.uniform1i(_sampler, i);
                   this.vapFrameParser.textureMap[resource.srcId] = i++;
               }
+              var dumpTexture = gl.createTexture();
+              gl.activeTexture(gl.TEXTURE0);
+              gl.bindTexture(gl.TEXTURE_2D, dumpTexture);
+              gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
+
               this.videoTexture = createTexture(gl, i);
               var sampler = gl.getUniformLocation(this.program, 'u_image_video');
               gl.uniform1i(sampler, i);
@@ -767,8 +783,15 @@
       }, {
           key: 'destroy',
           value: function destroy() {
-              var canvas = this.instance.canvas;
+              var _instance2 = this.instance,
+                  canvas = _instance2.canvas,
+                  gl = _instance2.gl;
 
+              if (this.textures && this.textures.length) {
+                  for (var i = 0; i < this.textures.length; i++) {
+                      gl.deleteTexture(this.textures[i]);
+                  }
+              }
               if (canvas) {
                   canvas.parentNode && canvas.parentNode.removeChild(canvas);
               }

File diff suppressed because it is too large
+ 0 - 0
web/dist/vap.min.js


+ 1 - 1
web/package.json

@@ -1,6 +1,6 @@
 {
   "name": "video-animation-player",
-  "version": "0.1.1",
+  "version": "0.1.2",
   "description": "webgl动画特效组件",
   "main": "dist/vap.js",
   "scripts": {

+ 7 - 6
web/src/vap-frame-parser.js

@@ -57,7 +57,10 @@ export default class FrameParser {
         const src = (this.srcData = {})
         return Promise.all(
             (dataJson.src || []).map(async item => {
-                if (this.headData[item.srcTag.slice(1, item.srcTag.length - 1)]) {
+                item.img = null
+                if (!this.headData[item.srcTag.slice(1, item.srcTag.length - 1)]) {
+                    console.warn(`vap: 融合信息没有传入:${item.srcTag}`)
+                } else {
                     if (item.srcType === 'txt') {
                         item.textStr = item.srcTag.replace(/\[(.*)\]/, ($0, $1) => {
                             return this.headData[$1]
@@ -71,11 +74,9 @@ export default class FrameParser {
                             item.img = await this.loadImg(item.imgUrl + '?t=' + Date.now())
                         } catch (e) {}
                     }
-                } else {
-                    console.warn(`vap: 融合信息没有传入:${item.srcTag}`)
-                }
-                if (item.img) {
-                    src[item.srcId] = item
+                    if (item.img) {
+                        src[item.srcId] = item
+                    }
                 }
             })
         )

+ 2 - 0
web/src/video.js

@@ -52,6 +52,8 @@ export default class VapVideo {
         const video = (this.video = document.createElement('video'))
         video.crossOrigin = 'anonymous'
         video.autoplay = false
+        video.preload = 'auto'
+        video.autoload = true
         // video.muted = true
         // video.volume = 0
         video.style.display = 'none'

+ 6 - 1
web/src/webgl-render-vap.js

@@ -295,7 +295,12 @@ export default class WebglRenderVap extends VapVideo {
     }
 
     destroy() {
-        const { canvas } = this.instance
+        const { canvas, gl } = this.instance
+        if (this.textures && this.textures.length) {
+            for (let i = 0; i < this.textures.length; i++) {
+                gl.deleteTexture(this.textures[i])
+            }
+        }
         if (canvas) {
             canvas.parentNode && canvas.parentNode.removeChild(canvas)
         }

Some files were not shown because too many files changed in this diff