我用画布创建了纹理,但是我没什么问题。我无法像图像一样旋转纹理。我该怎么做?
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;
};
如果要旋转纹理,可以更新几何中的UV,也可以使用texture.rotation
修改器。
texture.rotation
如果旋转未围绕所需的点旋转,则可以将const texture = new THREE.Texture(canvas);
texture.rotation = Math.PI; // 180 deg in radians
设置为texture.center
范围内的另一个值。
texture.center