1
Showing
3 changed files
with
32 additions
and
52 deletions
... | @@ -15,21 +15,18 @@ | ... | @@ -15,21 +15,18 @@ |
15 | "bpmn-js-properties-panel": "^0.37.2", | 15 | "bpmn-js-properties-panel": "^0.37.2", |
16 | "bpmn-js-token-simulation": "^0.10.0", | 16 | "bpmn-js-token-simulation": "^0.10.0", |
17 | "core-js": "^3.6.5", | 17 | "core-js": "^3.6.5", |
18 | "dat.gui": "^0.7.9", | ||
19 | "diagram-js": "^6.8.2", | 18 | "diagram-js": "^6.8.2", |
20 | "js-cookie": "2.2.0", | 19 | "js-cookie": "2.2.0", |
21 | "lodash": "^4.17.21", | 20 | "lodash": "^4.17.21", |
21 | "mxdraw": "^0.1.157", | ||
22 | "node-sass": "^4.14.1", | 22 | "node-sass": "^4.14.1", |
23 | "normalize.css": "7.0.0", | 23 | "normalize.css": "7.0.0", |
24 | "nprogress": "0.2.0", | 24 | "nprogress": "0.2.0", |
25 | "oimo": "^1.0.9", | ||
26 | "three": "^0.152.2", | ||
27 | "vue": "2.6.10", | 25 | "vue": "2.6.10", |
28 | "vue-json-editor": "^1.4.3", | 26 | "vue-json-editor": "^1.4.3", |
29 | "vue-quill-editor": "^3.0.6", | 27 | "vue-quill-editor": "^3.0.6", |
30 | "vue-router": "3.0.2", | 28 | "vue-router": "3.0.2", |
31 | "vue-seamless-scroll": "^1.1.23", | 29 | "vue-seamless-scroll": "^1.1.23", |
32 | "vue-threejs": "^0.2.0-alpha.1", | ||
33 | "vuex": "3.1.0", | 30 | "vuex": "3.1.0", |
34 | "x2js": "^3.4.4" | 31 | "x2js": "^3.4.4" |
35 | }, | 32 | }, | ... | ... |
1 | <!-- | ||
2 | 功能:初始化功能描述 | ||
3 | 作者:calliope | ||
4 | --> | ||
1 | <template> | 5 | <template> |
2 | <div ref="canvas"></div> | 6 | <canvas id="mxcad"> |
7 | </canvas> | ||
3 | </template> | 8 | </template> |
4 | |||
5 | <script> | 9 | <script> |
6 | import * as THREE from 'three' | 10 | import Mx from "mxdraw" |
7 | import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader' | ||
8 | import { VueThreejs } from 'vue-threejs' | ||
9 | |||
10 | export default { | 11 | export default { |
11 | mixins: [VueThreejs], | ||
12 | |||
13 | mounted () { | 12 | mounted () { |
14 | this.initCADViewer() | 13 | // 动态加载 js库核心代码 |
14 | Mx.loadCoreCode().then(() => { | ||
15 | // Mx.MxFun.setMxServer("ws://localhost:5090") // 开启socket通信 可编辑图纸 | ||
16 | // 创建控件对象 | ||
17 | Mx.MxFun.createMxObject({ | ||
18 | canvasId: "mxcad", // canvas元素的id | ||
19 | cadFile: "./cad.dwg", // http方式(预览): 加载public/demo文件夹下转换后的图纸 | ||
20 | // cadFile: "test2.dwg", // socket通信方式请直接提供图纸名称 如:text.dwg | ||
21 | callback: (mxDraw, { | ||
22 | canvas, | ||
23 | canvasParent | ||
24 | }) => { | ||
25 | // 可以拿到canvas元素和它的父级元素 | ||
26 | console.log(canvas, canvasParent) | ||
27 | console.log(mxDraw) | ||
28 | // 拿到图层数据 | ||
29 | mxDraw.addEvent('uiSetLayerData', (listLayer) => { | ||
30 | console.log(listLayer) | ||
31 | }) | ||
15 | }, | 32 | }, |
16 | 33 | isNewFile: true // 是否新建文件 | |
17 | methods: { | 34 | }) |
18 | initCADViewer () { | ||
19 | const container = this.$refs.canvas | ||
20 | |||
21 | // 创建场景 | ||
22 | const scene = new THREE.Scene() | ||
23 | |||
24 | // 创建相机 | ||
25 | const camera = new THREE.PerspectiveCamera(45, container.offsetWidth / container.offsetHeight, 0.1, 1000) | ||
26 | camera.position.set(0, 0, 10) | ||
27 | |||
28 | // 创建渲染器 | ||
29 | const renderer = new THREE.WebGLRenderer({ antialias: true }) | ||
30 | renderer.setSize(container.offsetWidth, container.offsetHeight) | ||
31 | container.appendChild(renderer.domElement) | ||
32 | |||
33 | // 添加灯光 | ||
34 | const light = new THREE.DirectionalLight(0xffffff, 1) | ||
35 | light.position.set(0, 0, 1) | ||
36 | scene.add(light) | ||
37 | |||
38 | // 加载CAD文件 | ||
39 | const loader = new GLTFLoader() | ||
40 | loader.load('./cad.dwg', (gltf) => { | ||
41 | scene.add(gltf.scene) | ||
42 | renderer.render(scene, camera) | ||
43 | }) | 35 | }) |
44 | |||
45 | // 动画循环 | ||
46 | const animate = () => { | ||
47 | requestAnimationFrame(animate) | ||
48 | renderer.render(scene, camera) | ||
49 | } | ||
50 | animate() | ||
51 | } | ||
52 | } | 36 | } |
53 | } | 37 | } |
54 | </script> | 38 | </script> |
55 | 39 | <style scoped lang='scss'> | |
56 | <style> | 40 | #cad-container { |
57 | div { | ||
58 | width: 100%; | 41 | width: 100%; |
59 | height: 100%; | 42 | height: 100%; |
60 | } | 43 | } | ... | ... |
-
Please register or sign in to post a comment