threejs让模型始终面向相机

需求:threejs导入3D模型,改变相机位置的同时,让模型始终面向相机。
实现方式:使用模型的lookAt()方法,设置模型lookAt的值

  1. 首次加载模型时,面向相机
	load.load('/model5.glb', g => {
    
    
		// 获取相机位置
      const {
    
     x, y, z } = camera.position
       // 设置模型的lookAt
      g.scene.lookAt(x, y, z)
      scene && scene.add(g.scene);
    })
  1. 相机云顶==运动时,模型面向相机
	function animation() {
    
    
			// 获取相机位置
	    const {
    
     x, y, z } = camera.position
	    if (scene && scene.children[4]) {
    
    
	       // 设置模型的lookAt
	      scene.children[4].lookAt(x, y, z)
	    }
	    render()
	    requestAnimationFrame(animation);
	  }

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_45142260/article/details/131416727