ac02a49d by renchao@pashanhoo.com

1

2 parents 6eb4c219 fd57039a
...@@ -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 /* 1 /*
2 * @Description: 2 * @Description:
3 * @Autor: renchao 3 * @Autor: renchao
4 * @LastEditTime: 2023-05-30 15:28:52 4 * @LastEditTime: 2023-05-31 16:00:26
5 */ 5 */
6 import Vue from 'vue' 6 import Vue from 'vue'
7 import App from './App' 7 import App from './App'
......
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库核心代码
15 }, 14 Mx.loadCoreCode().then(() => {
16 15 // Mx.MxFun.setMxServer("ws://localhost:5090") // 开启socket通信 可编辑图纸
17 methods: { 16 // 创建控件对象
18 initCADViewer () { 17 Mx.MxFun.createMxObject({
19 const container = this.$refs.canvas 18 canvasId: "mxcad", // canvas元素的id
20 19 cadFile: "./cad.dwg", // http方式(预览): 加载public/demo文件夹下转换后的图纸
21 // 创建场景 20 // cadFile: "test2.dwg", // socket通信方式请直接提供图纸名称 如:text.dwg
22 const scene = new THREE.Scene() 21 callback: (mxDraw, {
23 22 canvas,
24 // 创建相机 23 canvasParent
25 const camera = new THREE.PerspectiveCamera(45, container.offsetWidth / container.offsetHeight, 0.1, 1000) 24 }) => {
26 camera.position.set(0, 0, 10) 25 // 可以拿到canvas元素和它的父级元素
27 26 console.log(canvas, canvasParent)
28 // 创建渲染器 27 console.log(mxDraw)
29 const renderer = new THREE.WebGLRenderer({ antialias: true }) 28 // 拿到图层数据
30 renderer.setSize(container.offsetWidth, container.offsetHeight) 29 mxDraw.addEvent('uiSetLayerData', (listLayer) => {
31 container.appendChild(renderer.domElement) 30 console.log(listLayer)
32 31 })
33 // 添加灯光 32 },
34 const light = new THREE.DirectionalLight(0xffffff, 1) 33 isNewFile: true // 是否新建文件
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 }) 34 })
44 35 })
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 }
......