• three点击交互,改变材质颜色


     

    three点击交互,改变材质颜色

    一、在vue的的methods方法中写入

      // 模型点击改变颜色
        onmodelclick(event) {
          var raycaster = new THREE.Raycaster();
          let mouse = new THREE.Vector2();
          mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
          mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
          raycaster.setFromCamera(mouse, this.camera);
          const intersects = raycaster.intersectObjects(this.kechouObj);
          if (intersects.length > 0) {
            if(this.highlightFace){
              this.highlightFace.material = this.highlightFace.material0;;
            }
            intersects[0].object.material0 = intersects[0].object.material;
            intersects[0].object.material = new THREE.MeshBasicMaterial({
              color: "#FF00FF",
              transparent: true,
              opacity: 0.5
            });
            this.highlightFace = intersects[0].object;
          }
          return intersects;
        }

    二、在canvas画布中调用这个方法

     // 创建控件对象
        createControls() {
          this.controls = new OrbitControls(this.camera, this.renderer.domElement);
          this.renderer.domElement.addEventListener("click", this.onmodelclick);
        },

    更多疑问请加学习群:854184700

    欢迎学习讨论

  • 相关阅读:
    vim使用基础
    linux基本命令随笔
    linux学习笔记
    中台建设随笔
    数据密集型系统响应优化
    TCP断开连接的问题
    多渠道接入系统总结
    关于实践的认识
    博客说明
    python下载图片的问题思考
  • 原文地址:https://www.cnblogs.com/yaosusu/p/16265993.html
Copyright © 2020-2023  润新知