ThreeJS Turn Texture

问题描述 投票:0回答:1

我用画布创建了纹理,但是我没什么问题。我无法像图像一样旋转纹理。我该怎么做?

   setTexture = (name, font = 20) => {    

      const canvas = window.document.createElement("canvas");
      canvas.width = 256;
      canvas.height = 128;
      const ctx = canvas.getContext("2d");

      ctx.fillStyle = "white";
      ctx.fillRect(0, 0, canvas.width, canvas.height);
      ctx.font = `${font}pt Arial`;
      ctx.fillStyle = "black";
      ctx.textAlign = "center";
      ctx.textBaseline = "middle";
      ctx.fillText(
          name || "unnamed",
          canvas.width / 2,
          canvas.height / 2
      );

      const texture = new THREE.Texture(canvas);
      texture.wrapS = THREE.RepeatWrapping;
      texture.repeat.x = -1;
      texture.needsUpdate = true;
      return texture;
  };

enter image description here

javascript reactjs three.js
1个回答
0
投票

如果要旋转纹理,可以更新几何中的UV,也可以使用texture.rotation修改器。

texture.rotation

如果旋转未围绕所需的点旋转,则可以将const texture = new THREE.Texture(canvas); texture.rotation = Math.PI; // 180 deg in radians 设置为texture.center范围内的另一个值。

texture.center
© www.soinside.com 2019 - 2024. All rights reserved.