无法在查看器中更改元素颜色 [英] Unable to change element colour in Viewer
问题描述
为了测试PoC,我正在尝试将选定的元素涂成红色.为此,我创建了一个类,如下所示,但是当我选择元素时,元素没有任何反应.我在网络上尝试了许多示例(包括一些为渲染代理创建网状代理并添加叠加层的示例),但是没有任何效果.
To test out a PoC, I'm trying to colour a selected element red. To do this I have created a class, as below, but nothing happens to the elements when I select them. I've tried a number of the examples around the web (including some which create a mesh proxy for the render proxy and add an overlay) but nothing works.
如何更改给定元素( dbId
或 fragId
)的颜色?我在Forge API中找不到大部分关于此的API文档,所以我有点盲目.
How do I change the colour for a given element (either dbId
or fragId
)? I can't find API documentation for most of this in the Forge API, so I'm flying a little blind.
/* global Autodesk */
import * as three from "three";
import * as uuid from "uuid";
type SelectionChangedEvent = {
fragIdsArray: number[];
dbIdArray: number[];
nodeArray: number[];
model: object;
};
export default class ViewerInteractionHandler {
viewer: Autodesk.Viewing.Private.GuiViewer3D;
material: THREE.Material;
constructor(viewer: Autodesk.Viewing.Private.GuiViewer3D) {
this.viewer = viewer;
viewer.addEventListener(
Autodesk.Viewing.SELECTION_CHANGED_EVENT,
(e) => this.handleSelectionChange(e)
);
this.material = new three.MeshStandardMaterial({
name: "CustomMaterial",
color: 0xFF0000,
});
this.viewer.impl.matman().addMaterial(uuid(), this.material, true);
}
async handleSelectionChange(event: SelectionChangedEvent): Promise<void> {
this.changeMaterialsForFragments(event.fragIdsArray);
}
changeMaterialsForFragments(fragIdsArray: number[]) {
fragIdsArray.map((fragId) => {
this.viewer.model.getFragmentList().setMaterial(fragId, this.material);
});
this.viewer.impl.invalidate(true);
this.viewer.impl.sceneUpdated(true); // not sure which it is, trying both
}
}
推荐答案
尝试 viewer.setThemingColor
-参见doc [此处](
Try viewer.setThemingColor
- see doc [here] (https://autodeskviewer.com/viewers/latest/docs/Autodesk.Viewing.Viewer3D.html):
viewer.setThemingColor( dbId, color:THREE.Vector4, [, model [, recursive:boolean ] ] ) //starting from Viewer v6.3 you may recursively apply color to child nodes
要删除它们,请尝试 viewer.clearThemingColors
在此处
这篇关于无法在查看器中更改元素颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!