如何在three.js中设置canvasTexture的画布大小

时间:2018-09-04 08:16:43

标签: three.js

我尝试将画布的宽度和高度更改为以下

createText(text = 'example') {
        const canvas = document.createElement('canvas');
        const ctx = canvas.getContext('2d');

        canvas.width = 256;
        canvas.height = 64;

        ctx.fillStyle = '#796e8c';
        ctx.fillRect(0, 0, 600, 600);
        ctx.font='120px Arial';
        ctx.fillStyle = '#000000';
        ctx.fillText(text, 30, 100);

        const canvasTexture = new THREE.CanvasTexture(canvas);

        const spriteMaterail = new THREE.SpriteMaterial({
            map: canvasTexture,
            color: 0xffffff
        });
        const sprite = new THREE.Sprite(spriteMaterail);
        return sprite;
    }

,但是大小和比例总是一样的

enter image description here

0 个答案:

没有答案