emacroh5lib 1.0.67 → 1.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,13 @@
23
23
  * Date: 2021-03-02T17:08Z
24
24
  */
25
25
 
26
+ /*!
27
+ fflate - fast JavaScript compression/decompression
28
+ <https://101arrowz.github.io/fflate>
29
+ Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
30
+ version 0.6.9
31
+ */
32
+
26
33
  /*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
27
34
 
28
35
  /*! xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emacroh5lib",
3
- "version": "1.0.67",
3
+ "version": "1.0.70",
4
4
  "description": "EMacro前端组件库",
5
5
  "main": "dist/emacroh5lib.min.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -5,11 +5,12 @@ import { EMacro } from "./utilities/File";
5
5
  import FileViewer from './views/FileViewer/index.vue'
6
6
  import ImageViewer from './views/ImageViewer/index.vue'
7
7
  import VideoViewer from './views/VideoViewer/index.vue'
8
+ import ModelViewer from './views/ModelViewer/index.vue'
8
9
  import DragResizeView from './views/DragResizeView/index.vue'
9
10
  import DragView from './views/Draw/index.vue'
10
11
  import MessageBoxTest from "@/components/MessageBoxTest";
11
12
 
12
- const components = [FileViewer, ImageViewer, VideoViewer, DragResizeView];
13
+ const components = [FileViewer, ImageViewer, VideoViewer, DragResizeView, ModelViewer];
13
14
 
14
15
  const install = (Vue: any) => {
15
16
  if ((install as any).installed) return;
@@ -32,4 +33,4 @@ if (typeof window !== 'undefined' && (window as any).Vue) {
32
33
 
33
34
 
34
35
  export default {}
35
- export { EMacro, FileViewer, ImageViewer, VideoViewer, DragResizeView }
36
+ export { EMacro, FileViewer, ImageViewer, VideoViewer, ModelViewer, DragResizeView }
@@ -198,6 +198,10 @@
198
198
 
199
199
  Promise.race(promises).then((data) => {
200
200
 
201
+ setTimeout(() => {
202
+ this.switchAction("prev");
203
+ }, 100);
204
+
201
205
  this.image = this.$refs["duoViewerImage"];
202
206
  this.initDrag();
203
207
  this.$emit("loadComplete");
@@ -271,8 +275,8 @@
271
275
  } else {
272
276
  rate = height / document.body.clientHeight
273
277
  }
274
- width = width / rate
275
- height = height / rate
278
+ width = (width / rate) * 0.8
279
+ height = (height / rate) * 0.8
276
280
  }
277
281
 
278
282
  $this.setStyleByName(image, "width", `${width}px`);
@@ -0,0 +1,508 @@
1
+ <template>
2
+ <div class="duo-viewer" v-if="show" ref="duoViewer" @click="clickAgent">
3
+ <div class="duo-viewer-mask">
4
+ <div id="WebGL-output" class="duo-viewer-mask__image" :style="viewerStyle()">
5
+ </div>
6
+ </div>
7
+ <div class="duo-viewer-footer" v-if="showThumbnail">
8
+ <div class="duo-viewer-footer__title">{{ realName }}</div>
9
+ <div class="duo-viewer-footer__toolbar">
10
+ <ul>
11
+ <li class="duo-viewer-footer__zoom-in" data-viewer-action="zoom-in"></li>
12
+ <li class="duo-viewer-footer__zoom-out" data-viewer-action="zoom-out"></li>
13
+ <li class="duo-viewer-footer__one-to-one" data-viewer-action="one-to-one"></li>
14
+ <li class="duo-viewer-footer__prev" data-viewer-action="prev"></li>
15
+
16
+ <li class="duo-viewer-footer__play" data-viewer-action="play"></li>
17
+
18
+ <li class="duo-viewer-footer__next" data-viewer-action="next"></li>
19
+ <li class="duo-viewer-footer__reset" data-viewer-action="reset"></li>
20
+ <li class="duo-viewer-footer__rotate-left" data-viewer-action="rotate-left"></li>
21
+ <li class="duo-viewer-footer__rotate-right" data-viewer-action="rotate-right"></li>
22
+ </ul>
23
+ </div>
24
+ <div class="duo-viewer-footer__navbar">
25
+ <div class="duo-viewer-footer__navbar-thumbnail-wrap">
26
+ <div ref="duoViewerImageThumbnailList" class="duo-viewer-footer__navbar-thumbnail-list"
27
+ :style="{ width: `${listLength * 34}px` }">
28
+ <div :key="item + i" v-for="(item, i) in list" :class="
29
+ i === index
30
+ ? 'duo-viewer-footer__navbar-thumbnail-item viewer-current'
31
+ : 'duo-viewer-footer__navbar-thumbnail-item'
32
+ ">
33
+ <img data-viewer-action="select" :data-viewer-action-index="i" :src="getModelImg(item, i)" :alt="alt"
34
+ class="duo-viewer-footer__navbar-thumbnail-image" />
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ <div class="duo-viewer-close" @click="handleClose">
41
+ <div class="duo-viewer-close__off"></div>
42
+ </div>
43
+ </div>
44
+ </template>
45
+
46
+ <script>
47
+
48
+ import * as THREE from "three";
49
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
50
+ import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader.js";
51
+ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
52
+ import { STLLoader } from "three/examples/jsm/loaders/STLLoader.js";
53
+ import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader.js";
54
+ import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader.js";
55
+ import { Line2 } from 'three/examples/jsm/lines/Line2'
56
+ import { CSS2DObject, CSS2DRenderer } from "three/examples/jsm/renderers/CSS2DRenderer";
57
+ import { AsciiEffect } from "three/examples/jsm/effects/AsciiEffect.js";
58
+ // import TWEEN from "@tweenjs/tween.js";
59
+ // import Stats from "stats.js";
60
+ // import * as dat from "dat.gui";
61
+
62
+ export default {
63
+ name: "ModelViewer",
64
+ data() {
65
+ return {
66
+ viewerSrc: "",
67
+ image: null,
68
+ listDataCache: [],
69
+ index: 0,
70
+ imgUrl: "",
71
+ isCreatePoster: false,
72
+ gl: {
73
+ scene: null,
74
+ renderer: null,
75
+ camera: null,
76
+ controls: null,
77
+ geometry: null,
78
+ isRotate: false,
79
+ isMove: false,
80
+ startEvent: null,
81
+ WebGLoutput: null,
82
+ animationFrame: null
83
+ }
84
+ };
85
+ },
86
+ props: {
87
+ list: {
88
+ type: Array,
89
+ default: () => [],
90
+ },
91
+ alt: {
92
+ type: String,
93
+ default: "预览图缺失",
94
+ },
95
+ // Control is show of viewer
96
+ show: {
97
+ type: Boolean,
98
+ default: false,
99
+ },
100
+ // Default index
101
+ currentIndex: {
102
+ type: Number,
103
+ default: 0,
104
+ },
105
+ width: {
106
+ type: String,
107
+ default: "80%",
108
+ },
109
+ height: {
110
+ type: String,
111
+ default: "80%",
112
+ },
113
+ showThumbnail: {
114
+ type: Boolean,
115
+ default: false,
116
+ }
117
+ },
118
+ computed: {
119
+ listLength() {
120
+ return this.list.length;
121
+ },
122
+ realName() {
123
+ return this.list[this.index].name;
124
+ },
125
+ currentData() {
126
+ return this.listDataCache[this.index];
127
+ },
128
+ currentModel() {
129
+ return this.list[this.index];
130
+ }
131
+ },
132
+ watch: {
133
+ show(val) {
134
+ if (val) {
135
+ this.$emit("open");
136
+ this.index = this.currentIndex;
137
+ this.loadModel(this.currentModel)
138
+ } else {
139
+ this.$emit("close");
140
+ }
141
+ },
142
+ },
143
+ mounted() {
144
+
145
+ },
146
+ methods: {
147
+ viewerStyle() {
148
+ return `width:${this.width};height:${this.height};`
149
+ },
150
+ getModelImg(item) {
151
+
152
+ },
153
+ // Global init
154
+ init() {
155
+ // this.initMouseWheel();
156
+ this.keydown();
157
+ },
158
+
159
+ loadModel(model) {
160
+
161
+ const loadObj = () => {
162
+
163
+ let mtlLoader = new MTLLoader();
164
+ let objLoader = new OBJLoader();
165
+
166
+ // const objPath = "/webgl-resources/test.obj"
167
+ const mtlPath = model.mtl
168
+ const objPath = model.obj
169
+
170
+ mtlLoader.load(mtlPath, materials => {
171
+
172
+ materials.preload();
173
+ const keys = Object.keys(materials.materials)
174
+ for (let i = 0; i < keys.length; i++) {
175
+ materials.materials[keys[i]].opacity = 1 - materials.materials[keys[i]].opacity // 解决tr解析问题
176
+ }
177
+ objLoader.setMaterials(materials);
178
+
179
+ objLoader.load(objPath, geometry => {
180
+
181
+ this.gl.geometry = geometry
182
+
183
+ geometry.position.x = 0
184
+ geometry.position.y = 0
185
+ geometry.position.z = -100
186
+
187
+ geometry.scale.x = 100
188
+ geometry.scale.y = 100
189
+ geometry.scale.z = 100
190
+ geometry.scale.set(200, 200, 200)
191
+
192
+ this.gl.scene.add(geometry);
193
+ })
194
+
195
+ })
196
+
197
+
198
+ }
199
+
200
+ const init = () => {
201
+
202
+ this.gl.scene = new THREE.Scene();
203
+
204
+ this.gl.scene.rotateY(45)
205
+
206
+
207
+ let axes = new THREE.AxisHelper(50);
208
+ this.gl.scene.add(axes);
209
+
210
+ //点光源
211
+ let point = new THREE.PointLight(0xffffff);
212
+ point.position.set(200, 300, 10); //点光源位置,参数分别代表:
213
+ this.gl.scene.add(point);
214
+ //环境光
215
+ let ambient = new THREE.AmbientLight(0x444444);
216
+ ambient.position.set(200, 300, 10); //点光源位置,参数分别代表:
217
+ this.gl.scene.add(ambient);
218
+ /**
219
+ * 相机设置
220
+ */
221
+ let width = window.innerWidth * 0.8; //窗口宽度
222
+ let height = window.innerHeight * 0.8; //窗口高度
223
+ let k = width / height; //窗口宽高比
224
+ let s = 200; //三维场景显示范围控制系数,系数越大,显示的范围越大
225
+ //创建相机对象
226
+ this.gl.camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000);
227
+ this.gl.camera.position.set(500, 300, 200); //设置相机位置
228
+ this.gl.camera.lookAt(this.gl.scene.position); //设置相机方向(指向的场景对象)
229
+ /**
230
+ * 创建渲染器对象
231
+ */
232
+ this.gl.renderer = new THREE.WebGLRenderer();
233
+ this.gl.renderer.setSize(width, height); //设置渲染区域尺寸
234
+ this.gl.renderer.setClearColor(0xb9d3ff, 1); //设置背景颜色
235
+
236
+ this.gl.WebGLoutput.innerHTML = ""
237
+ this.gl.renderer.domElement.style.width = "100%"
238
+ this.gl.renderer.domElement.style.height = "100%"
239
+ this.gl.WebGLoutput.appendChild(this.gl.renderer.domElement);//body元素中插入canvas对象
240
+
241
+ // controls = new OrbitControls(camera, renderer.domElement); //创建控件对象
242
+ // controls.addEventListener("change", render); //监听鼠标、键盘事件
243
+
244
+ this.gl.renderer.domElement.addEventListener("click", event => {
245
+ console.log("click", event);
246
+ })
247
+
248
+ this.gl.renderer.domElement.addEventListener("dblclick", event => {
249
+ console.log("dblclick", event);
250
+ })
251
+
252
+ this.gl.renderer.domElement.addEventListener("mousedown", event => {
253
+ console.log("mousedown", event);
254
+
255
+ if (event.which === 1) {
256
+ this.gl.isRotate = true
257
+ this.gl.startEvent = event
258
+ }
259
+
260
+ if (event.which === 3) {
261
+ this.gl.isMove = true
262
+ this.gl.startEvent = event
263
+ }
264
+
265
+ })
266
+
267
+ this.gl.renderer.domElement.addEventListener("mouseup", event => {
268
+ console.log("mouseup", event);
269
+ this.gl.isRotate = false
270
+ this.gl.isMove = false
271
+ })
272
+
273
+
274
+ this.gl.renderer.domElement.addEventListener("contextmenu", event => {
275
+ console.log("mouseup", event);
276
+ event.preventDefault();
277
+ })
278
+
279
+ this.gl.renderer.domElement.addEventListener("mousewheel", event => {
280
+ console.log("mousewheel", event);
281
+ event.preventDefault();
282
+
283
+ let velocity = 0.1
284
+ if (event.wheelDelta > 0) {
285
+ velocity = 1 - velocity
286
+ this.gl.geometry.scale.set(this.gl.geometry.scale.x * velocity, this.gl.geometry.scale.y * velocity, this.gl.geometry.scale.z * velocity)
287
+ } else {
288
+ velocity = 1 + velocity
289
+ this.gl.geometry.scale.set(this.gl.geometry.scale.x * velocity, this.gl.geometry.scale.y * velocity, this.gl.geometry.scale.z * velocity)
290
+ }
291
+
292
+ })
293
+
294
+ this.gl.renderer.domElement.addEventListener("mousemove", event => {
295
+ if (this.gl.isRotate) {
296
+
297
+ const x = -(this.gl.startEvent.offsetX - event.offsetX)
298
+ const y = -(this.gl.startEvent.offsetY - event.offsetY)
299
+
300
+ this.gl.geometry.rotateOnWorldAxis(new THREE.Vector3(1, 0, 0), y * 0.001)
301
+ this.gl.geometry.rotateOnWorldAxis(new THREE.Vector3(0, 1, 0), x * 0.001)
302
+ // this.gl.geometry.rotateX(y * 0.001)
303
+ // this.gl.geometry.rotateY(x * 0.001)
304
+ }
305
+
306
+ if (this.gl.isMove) {
307
+ const x = -(this.gl.startEvent.offsetX - event.offsetX) * 0.05
308
+ const y = (this.gl.startEvent.offsetY - event.offsetY) * 0.05
309
+ this.gl.geometry.position.set(this.gl.geometry.position.x + x, this.gl.geometry.position.y + y, this.gl.geometry.position.z)
310
+ }
311
+
312
+ })
313
+
314
+ }
315
+
316
+ const render = () => {
317
+ this.gl.renderer.render(this.gl.scene, this.gl.camera);
318
+ this.gl.animationFrame = requestAnimationFrame(render);
319
+ }
320
+
321
+ this.$nextTick(() => {
322
+ this.gl.WebGLoutput = document.querySelector("#WebGL-output");
323
+ init();
324
+ render();
325
+ loadObj();
326
+ })
327
+
328
+
329
+ },
330
+
331
+
332
+
333
+ // Next or prev action
334
+ switchAction(a) {
335
+ let lastIndex = this.index;
336
+ switch (a) {
337
+ case "prev":
338
+ // prev action
339
+ this.index += this.index <= 0 ? 0 : -1;
340
+ break;
341
+ case "next": {
342
+ // next action
343
+ let srcListLength = this.listLength - 1;
344
+
345
+ this.index +=
346
+ this.index >= srcListLength ? srcListLength - this.index : 1;
347
+ }
348
+ break;
349
+ default:
350
+ this.index = +a;
351
+ break;
352
+ }
353
+ this.judgeThumbnailListMove(lastIndex, this.index);
354
+
355
+ },
356
+ // To judge thumbnail list move
357
+ judgeThumbnailListMove(lastIndex, index) {
358
+ if (lastIndex == index) return;
359
+
360
+ let translateX = 0,
361
+ lastTransform = 0,
362
+ step = index - lastIndex,
363
+ move = step * 34,
364
+ length = this.listLength,
365
+ target = this.$refs["duoViewerImageThumbnailList"];
366
+
367
+ if (!target) return;
368
+
369
+ lastTransform = this.getCurrentTransform(target);
370
+
371
+ if (lastTransform) {
372
+ translateX = Math.abs(+lastTransform.translateX);
373
+ }
374
+
375
+ this.setTransform(target, {
376
+ scaleX: "1",
377
+ skewY: "0",
378
+ translateX: `-${translateX + move}px`,
379
+ translateY: "0%",
380
+ rotate: "0deg",
381
+ });
382
+ },
383
+
384
+
385
+ // FullScreen action
386
+ requestFullScreen() {
387
+ let element = this.$refs["duoViewer"],
388
+ requestMethod =
389
+ element.requestFullScreen ||
390
+ element.webkitRequestFullScreen ||
391
+ element.mozRequestFullScreen ||
392
+ element.msRequestFullScreen;
393
+
394
+ if (requestMethod) {
395
+ requestMethod.call(element);
396
+ }
397
+ },
398
+
399
+ // Keydown action
400
+ keydown() {
401
+ window.addEventListener("keydown", (e) => {
402
+ e = event || window.event
403
+
404
+ if (e && e.keyCode == 40) {
405
+ // down
406
+ this.zoom("out");
407
+ }
408
+ if (e && e.keyCode == 37) {
409
+ // left
410
+ this.switchAction("prev");
411
+ }
412
+ if (e && e.keyCode == 39) {
413
+ // right
414
+ this.switchAction("next");
415
+ }
416
+ if (e && e.keyCode == 38) {
417
+ // up
418
+ this.zoom("in");
419
+ }
420
+ if (e && e.keyCode == 27) {
421
+ // esc
422
+ this.handleClose()
423
+ }
424
+ });
425
+ },
426
+
427
+ // Init mouse wheel event
428
+ initMouseWheel() {
429
+ const scrollFn = (e) => {
430
+ e = e || window.event;
431
+ if (e.wheelDelta) {
432
+ // for IE/Google
433
+ if (e.wheelDelta > 0) {
434
+ this.zoom("out");
435
+ }
436
+ if (e.wheelDelta < 0) {
437
+ this.zoom("in");
438
+ }
439
+ } else if (e.detail) {
440
+ // for Firefox
441
+ if (e.detail > 0) {
442
+ this.zoom("out");
443
+ }
444
+ if (e.detail < 0) {
445
+ this.zoom("in");
446
+ }
447
+ }
448
+ };
449
+
450
+ document.addEventListener &&
451
+ document.addEventListener("DOMMouseScroll", scrollFn, false);
452
+ window.onmousewheel = document.onmousewheel = scrollFn;
453
+ },
454
+
455
+ // Agent
456
+ clickAgent(e) {
457
+ switch (e.target.getAttribute("data-viewer-action")) {
458
+ case "zoom-in":
459
+ this.zoom("in");
460
+ break;
461
+ case "zoom-out":
462
+ this.zoom("out");
463
+ break;
464
+ case "one-to-one":
465
+ this.resetZoom();
466
+ break;
467
+ case "prev":
468
+ this.switchAction("prev");
469
+ break;
470
+ case "play":
471
+ this.requestFullScreen();
472
+ break;
473
+ case "next":
474
+ this.switchAction("next");
475
+ break;
476
+ case "reset":
477
+ this.resetAll();
478
+ break;
479
+ case "select":
480
+ this.switchAction(e.target.getAttribute("data-viewer-action-index"));
481
+ break;
482
+ case "rotate-left":
483
+ this.rotate("left");
484
+ break;
485
+ case "rotate-right":
486
+ this.rotate("right");
487
+ break;
488
+ }
489
+ },
490
+ // On close
491
+ handleClose() {
492
+
493
+ cancelAnimationFrame(this.gl.animationFrame)
494
+
495
+ const keys = Object.keys(this.gl)
496
+ for (let i = 0; i < keys.length; i++) {
497
+ this.gl[keys[i]] = null
498
+ }
499
+ this.$emit("update:show", false);
500
+ },
501
+ },
502
+ };
503
+ </script>
504
+
505
+ <style lang="less" scoped>
506
+ @import "./style/css/index.css";
507
+ /* @import "./style/css/index.less"; */
508
+ </style>