vue 中使用7版本forge viewer 设置模型高亮
时间: 2024-03-20 22:42:16 浏览: 261
要在 Vue 中使用 Forge Viewer 7 版本设置模型高亮,可以通过以下步骤实现:
1. 在 Vue 组件中引入 Forge Viewer 的脚本文件和样式文件。
```javascript
import 'forge-apis';
import 'forge-viewer';
import 'forge-viewer/dist/forge.css';
```
2. 在 Vue 组件中创建 Forge Viewer 实例。
```javascript
mounted() {
this.viewer = new Autodesk.Viewing.GuiViewer3D(this.$refs.viewer);
this.viewer.start();
},
```
3. 加载模型并设置模型高亮。
```javascript
this.viewer.loadModel(modelUrl, {
globalOffset: { x: 0, y: 0, z: 0 },
sharedPropertyDbPath: propertyDbUrl,
}, async (model) => {
await this.viewer.impl.createOverlayScene('custom-scene');
const modelInstanceTree = model.getInstanceTree();
const fragList = model.getFragmentList();
const selectionColor = new THREE.Vector4(1.0, 1.0, 0.0, 1.0);
const selectedFragIds = [];
modelInstanceTree.enumNodeFragments(selectedDbId, (fragId) => {
selectedFragIds.push(fragId);
});
selectedFragIds.forEach((fragId) => {
fragList.setMaterial(fragId, this.viewer.impl.getMaterial('CustomMaterial'));
this.viewer.impl.addOverlay('custom-scene', this.createBox(fragList.getVurnetex3dMesh(fragId)), null, 'CustomMaterial');
});
});
createBox(geometry) {
const boundingBox = geometry.boundingBox;
const box = new THREE.Box3(
boundingBox.min.clone(),
boundingBox.max.clone(),
);
const center = box.getCenter(new THREE.Vector3());
const size = box.getSize(new THREE.Vector3());
const material = new THREE.MeshPhongMaterial({
color: 0xffff00,
transparent: true,
opacity: 0.5,
});
const mesh = new THREE.Mesh(new THREE.BoxGeometry(size.x, size.y, size.z), material);
mesh.position.copy(center);
return mesh;
},
```
以上代码中,`createBox` 函数用来创建高亮的盒子,选中的模型碎片会用盒子覆盖并设置为自定义材质。
阅读全文