You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

38 lines
1.3 KiB

import { CSS2DRenderer, CSS2DObject } from 'jsm/renderers/CSS2DRenderer.js';
export default {
createButton: function (obj, perent, i) {
const btnDiv = document.createElement('button');
btnDiv.className = 'btn';
btnDiv.identifierName = 'btn';
btnDiv.textContent = 'Btn: Click ...';
btnDiv.style.marginTop = '-1em';
btnDiv.style.zIndex = 1000;
const css2dBtn = new CSS2DObject(btnDiv);
css2dBtn.position.set(obj.x + 2, obj.y, obj.z);
css2dBtn.name = "datalabel" + i;
css2dBtn.userData = { name: "datalable", id: "", url: "" }
// css2DLabelList.add(css2DLabel);
window.scene.add(css2dBtn);
},
//创建标签
createCSSLabel: function (text, x = 0, y = 0, z = 0, className = 'label') {
const labelDiv = document.createElement('div');
labelDiv.className = className;
labelDiv.name = "csslabeldiv"
labelDiv.textContent = text;
labelDiv.style.pointerEvents = 'none';//避免HTML标签遮挡三维场景的鼠标事件
const css2DLabel = new CSS2DObject(labelDiv);
css2DLabel.position.set(x, y, z);
css2DLabel.name = "datalabel"
css2DLabel.userData = { name: "datalable", id: "", url: "" }
return css2DLabel;
}
}