threejs将文字贴到物体面

 

场景

new THREE.Scene()

相机

new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000)

渲染器

new THREE.WebGLRenderer()

坐标轴

new THREE.AxesHelper(20)

平面

new THREE.PlaneGeometry(60, 20, 1, 1)

// 设置投影

        plane.receiveShadow = true;

物体(三个)

new THREE.BoxGeometry(4, 4, 4)

new THREE.MeshLambertMaterial( { color: 0x00ff00} )

new THREE.Mesh( geometry, material )

// 设置投影

        cube.castShadow = true;

光源

new THREE.SpotLight( 0xffffff )

// 设置投影

        spotLight.castShadow = true;

  methods: {
    getTextCanvas(text) {
      var width = 512, height = 256;
      var canvas = document.createElement('canvas');
      canvas.width = width;
      canvas.height = height;
      var ctx = canvas.getContext('2d');
      ctx.fillStyle = '#C3C3C3';
      ctx.fillRect(0, 0, width, height);
      ctx.font = 50 + 'px " bold';
      ctx.fillStyle = '#2891FF';
      ctx.textAlign = 'center';
      ctx.textBaseline = 'middle';
      ctx.fillText(text, width / 2, height / 2);
      return canvas;
    },
  },
  mounted() {
......
    this.material = [
      new THREE.MeshBasicMaterial({ color: '#fff' }), // right
      new THREE.MeshBasicMaterial({ map: texture, }), // left
      new THREE.MeshBasicMaterial({ map: new THREE.CanvasTexture(this.getTextCanvas('Leo Test Label')) }), // top
      new THREE.MeshBasicMaterial({ color: 'black' }), // bottom
      new THREE.MeshBasicMaterial({ map: texture, }), // back
      new THREE.MeshBasicMaterial({ color: 'red' }) // front 
    ];
.......
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值