style:宗地图
Showing
4 changed files
with
32 additions
and
93 deletions
No preview for this file type
1 | <!-- | ||
2 | * @Description: | ||
3 | * @Autor: renchao | ||
4 | * @LastEditTime: 2023-06-01 09:48:15 | ||
5 | --> | ||
1 | <template> | 6 | <template> |
2 | <div ref="canvas"></div> | 7 | <canvas id="mxcad"> |
8 | </canvas> | ||
3 | </template> | 9 | </template> |
4 | |||
5 | <script> | 10 | <script> |
6 | import * as THREE from 'three' | 11 | import Mx from "mxdraw" |
7 | import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader' | ||
8 | import { VueThreejs } from 'vue-threejs' | ||
9 | |||
10 | export default { | 12 | export default { |
11 | mixins: [VueThreejs], | ||
12 | |||
13 | mounted () { | 13 | mounted () { |
14 | this.initCADViewer() | 14 | // 动态加载 js库核心代码 |
15 | }, | 15 | Mx.loadCoreCode().then(() => { |
16 | 16 | // Mx.MxFun.setMxServer("ws://localhost:5090") // 开启socket通信 可编辑图纸 | |
17 | methods: { | 17 | // 创建控件对象 |
18 | initCADViewer () { | 18 | Mx.MxFun.createMxObject({ |
19 | const container = this.$refs.canvas | 19 | canvasId: "mxcad", // canvas元素的id |
20 | 20 | cadFile: "/buf/hhhh.dwg", // http方式(预览): 加载public/demo文件夹下转换后的图纸 | |
21 | // 创建场景 | 21 | // cadFile: "test2.dwg", // socket通信方式请直接提供图纸名称 如:text.dwg |
22 | const scene = new THREE.Scene() | 22 | callback: (mxDraw, { |
23 | 23 | canvas, | |
24 | // 创建相机 | 24 | canvasParent |
25 | const camera = new THREE.PerspectiveCamera(45, container.offsetWidth / container.offsetHeight, 0.1, 1000) | 25 | }) => { |
26 | camera.position.set(0, 0, 10) | 26 | // 可以拿到canvas元素和它的父级元素 |
27 | 27 | console.log(canvas, canvasParent) | |
28 | // 创建渲染器 | 28 | console.log(mxDraw) |
29 | const renderer = new THREE.WebGLRenderer({ antialias: true }) | 29 | // 拿到图层数据 |
30 | renderer.setSize(container.offsetWidth, container.offsetHeight) | 30 | mxDraw.addEvent('uiSetLayerData', (listLayer) => { |
31 | container.appendChild(renderer.domElement) | 31 | console.log(listLayer) |
32 | 32 | }) | |
33 | // 添加灯光 | 33 | }, |
34 | const light = new THREE.DirectionalLight(0xffffff, 1) | 34 | 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 | }) | 35 | }) |
44 | 36 | }) | |
45 | // 动画循环 | ||
46 | const animate = () => { | ||
47 | requestAnimationFrame(animate) | ||
48 | renderer.render(scene, camera) | ||
49 | } | ||
50 | animate() | ||
51 | } | ||
52 | } | 37 | } |
53 | } | 38 | } |
54 | </script> | 39 | </script> |
55 | 40 | <style scoped lang='scss'> | |
56 | <style> | 41 | #cad-container { |
57 | div { | ||
58 | width: 100%; | 42 | width: 100%; |
59 | height: 100%; | 43 | height: 100%; |
60 | } | 44 | } | ... | ... |
No preview for this file type
1 | <!-- | ||
2 | * @Description: | ||
3 | * @Autor: renchao | ||
4 | * @LastEditTime: 2023-06-01 09:58:47 | ||
5 | --> | ||
6 | <template> | ||
7 | <canvas id="mxcad"> | ||
8 | </canvas> | ||
9 | </template> | ||
10 | <script> | ||
11 | import Mx from "mxdraw" | ||
12 | export default { | ||
13 | mounted () { | ||
14 | // 动态加载 js库核心代码 | ||
15 | Mx.loadCoreCode().then(() => { | ||
16 | // Mx.MxFun.setMxServer("ws://localhost:5090") // 开启socket通信 可编辑图纸 | ||
17 | // 创建控件对象 | ||
18 | Mx.MxFun.createMxObject({ | ||
19 | canvasId: "mxcad", // canvas元素的id | ||
20 | cadFile: "/buf/hhhh.dwg", // http方式(预览): 加载public/demo文件夹下转换后的图纸 | ||
21 | // cadFile: "test2.dwg", // socket通信方式请直接提供图纸名称 如:text.dwg | ||
22 | callback: (mxDraw, { | ||
23 | canvas, | ||
24 | canvasParent | ||
25 | }) => { | ||
26 | // 可以拿到canvas元素和它的父级元素 | ||
27 | console.log(canvas, canvasParent) | ||
28 | console.log(mxDraw) | ||
29 | // 拿到图层数据 | ||
30 | mxDraw.addEvent('uiSetLayerData', (listLayer) => { | ||
31 | console.log(listLayer) | ||
32 | }) | ||
33 | }, | ||
34 | isNewFile: true // 是否新建文件 | ||
35 | }) | ||
36 | }) | ||
37 | } | ||
38 | } | ||
39 | </script> | ||
40 | <style scoped lang='scss'> | ||
41 | #cad-container { | ||
42 | width: 100%; | ||
43 | height: 100%; | ||
44 | } | ||
45 | </style> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment