代码如下:
const css2DObjects = [];
const createLabelObj = (idText,) => {
let div = document.getElementById(idText);
for (var i = 0; i < css2DObjects.length; i++) {
const preDiv = css2DObjects[i].element;
if (preDiv.id === idText) {
// 如果已存在,则先移除
const divDom = css2Renderer.domElement;
if (divDom && divDom.contains(preDiv)) {
divDom.removeChild(preDiv)
}
}
}
// 给标签设置坐标位置
let pointLabel = new CSS2DObject(div);
css2DObjects.push({ element: div, object: pointLabel });
return pointLabel;
}
export const addTags = (item) => {
const item = model.getObjectByName(i.id)
const tag = createLabelObj(i.id)
item && item.add(tag)
}
标签:threejs,const,CSS2DObject,创建,divDom,pointLabel,css2DObjects,item,preDiv
From: https://www.cnblogs.com/ZerlinM/p/18683920