Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 53 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,50 @@ pnpm preview

## Usage

Firstly, add the following dependencies into your package.json.
Firstly, add the following dependencies into your `package.json`.

- @mlightcad/cad-agent-plugin
- @mlightcad/cad-html-plugin
- @mlightcad/cad-pdf-plugin
- @mlightcad/cad-simple-viewer
- @mlightcad/cad-viewer
- @mlightcad/data-model
- @mlightcad/libredwg-converter (optional, GPL-3.0 — required for DWG)
- element-plus
- lodash-es
- three
- vue
- vue-i18n

Secondly, add the following code in your Vue component.
### Register a DWG converter (required for DWG since 1.6.0)

From `@mlightcad/cad-viewer` **1.6.0**, DXF parsing stays built-in, but **DWG is opt-in**. `@mlightcad/cad-simple-viewer` / `@mlightcad/cad-viewer` no longer depend on or register `@mlightcad/libredwg-converter`. Hosts that need open-source DWG support must:

1. Add `@mlightcad/libredwg-converter` (GPL-3.0)
2. Copy its worker **and** wasm next to each other
3. Register the converter **before** the viewer opens a `.dwg` file

```typescript
import {
AcDbDatabaseConverterManager,
AcDbFileType
} from '@mlightcad/data-model'
import { AcDbLibreDwgConverter } from '@mlightcad/libredwg-converter'
import { LIBREDWG_PARSER_WORKER_FILE } from '@mlightcad/cad-simple-viewer'

const converter = new AcDbLibreDwgConverter({
convertByEntityType: false,
useWorker: true,
parserWorkerUrl: `./assets/${LIBREDWG_PARSER_WORKER_FILE}`
})
AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, converter)
```

This example does that in `src/registerLibreDwg.ts` and calls it from `src/App.vue` before `MlCadViewer` mounts.

If you ship a closed-source product and cannot distribute GPL code, skip LibreDWG and use a proprietary DWG converter instead. See [cad-viewer proprietary parser](https://github.com/mlightcad/cad-viewer/blob/main/PROPRIETARY-PARSER.md).

### Use the Vue component

```vue
<template>
Expand All @@ -56,14 +84,17 @@ import { MlCadViewer } from '@mlightcad/cad-viewer'
</script>
```

Finally, copy the following files to **dist/assets** folder.
### Copy worker and runtime assets

Copy the following files to the **dist/assets** folder. The LibreDWG wasm file must sit next to `libredwg-parser-worker.js`.

- ./node_modules/@mlightcad/cad-simple-viewer/dist/libredwg-parser-worker.js
- ./node_modules/@mlightcad/cad-simple-viewer/dist/mtext-renderer-worker.js
- ./node_modules/@mlightcad/cad-html-plugin/dist/viewer-runtime.iife.js
- `./node_modules/@mlightcad/cad-simple-viewer/dist/mtext-renderer-worker.js`
- `./node_modules/@mlightcad/libredwg-converter/dist/libredwg-parser-worker.js`
- `./node_modules/@mlightcad/libredwg-converter/dist/libredwg-web.wasm`
- `./node_modules/@mlightcad/cad-html-plugin/dist/viewer-runtime.iife.js`

DXF parsing is built into `@mlightcad/data-model` (`AcDbNativeDxfConverter`, registered by default), so the old `dxf-json` parser worker is no longer needed.
The LibreDWG parser worker still runs DWG parsing off the main thread so the UI stays responsive; the MText renderer worker handles multiline text off the main thread.
DXF parsing is built into `@mlightcad/data-model` (`AcDbNativeDxfConverter`, registered by default), so no DXF parser worker is needed.
The LibreDWG parser worker runs DWG parsing off the main thread so the UI stays responsive; the MText renderer worker handles multiline text off the main thread.
`viewer-runtime.iife.js` is required by the HTML export plugin.
You can copy those files to **dist/assets** manually; `vite-plugin-static-copy` is recommended.

Expand All @@ -78,7 +109,17 @@ export default defineConfig(() => {
viteStaticCopy({
targets: [
{
src: './node_modules/@mlightcad/cad-simple-viewer/dist/*-worker.js',
src: './node_modules/@mlightcad/cad-simple-viewer/dist/mtext-renderer-worker.js',
dest: 'assets',
rename: { stripBase: true }
},
{
src: './node_modules/@mlightcad/libredwg-converter/dist/libredwg-parser-worker.js',
dest: 'assets',
rename: { stripBase: true }
},
{
src: './node_modules/@mlightcad/libredwg-converter/dist/libredwg-web.wasm',
dest: 'assets',
rename: { stripBase: true }
},
Expand Down Expand Up @@ -110,4 +151,6 @@ export default defineConfig(() => {

## License

[MIT](LICENSE)
[MIT](LICENSE)

DWG support in this example uses `@mlightcad/libredwg-converter`, which is licensed under GPL-3.0.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@mlightcad/cad-agent-plugin": "1.5.11",
"@mlightcad/cad-html-plugin": "1.5.11",
"@mlightcad/cad-pdf-plugin": "1.5.11",
"@mlightcad/cad-simple-viewer": "1.5.11",
"@mlightcad/cad-viewer": "1.5.11",
"@mlightcad/data-model": "^1.12.5",
"@mlightcad/cad-agent-plugin": "1.6.0",
"@mlightcad/cad-html-plugin": "1.6.0",
"@mlightcad/cad-pdf-plugin": "1.6.0",
"@mlightcad/cad-simple-viewer": "1.6.0",
"@mlightcad/cad-viewer": "1.6.0",
"@mlightcad/data-model": "^1.13.0",
"@mlightcad/libredwg-converter": "^3.13.0",
"element-plus": "^2.12.0",
"lodash-es": "4.17.21",
"three": "^0.172.0",
Expand Down
Loading
Loading