three.js 3D坐标转化为2D屏幕坐标_你蠢哭我咯的博客-CSDN博客

//创建一个3D坐标
var vector = new THREE.Vector3();  
//获取模型
var obj = scene.getObjectByName(modelName);
vector = vector.setFromMatrixPosition(obj.matrixWorld).project(camera);               
var halfWidth = window.innerWidth / 2;  
var halfHeight = window.innerHeight / 2;  
console.log(vector.x * halfWidth + halfWidth)
var result = {  
    x: Math.round(vector.x * halfWidth + halfWidth),  
    y: Math.round(-vector.y * halfHeight + halfHeight)
};  
//2D坐标
console.log(result)

原网址: 访问
创建于: 2023-01-12 16:29:54
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论