简体   繁体   中英

ThreeJS Turn Texture

I created texture with canvas, but I have little problem. I couldn't turn my texture like in image. How can i make this?

   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;
  };

在此处输入图像描述

If you want to rotate your texture, you could either update the UVs in the geometry, or you could use the texture.rotation modifier.

const texture = new THREE.Texture(canvas);
texture.rotation = Math.PI; // 180 deg in radians

If the rotation isn't pivoting around the point you'd like, you can set texture.center to another value in the [0.0, 1.0] range.

const texture = new THREE.Texture(canvas);
texture.center = new THREE.Vector2(0.5, 0.7);
texture.rotation = Math.PI;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM