Sprite
을 만들 때 나는 Arial
만 사용할 수 있습니다. 다른 글꼴은 작동하지 않습니다. Roboto
과 같은 맞춤 글꼴을 추가하는 방법이 있습니까?스프라이트에 맞춤 글꼴을 추가하는 방법
코드 :
const makeTextSprite = (_text, properties) => {
const text = _text;
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
context.translate(0.5, 0.5);
const metrics = context.measureText(text);
const textWidth = metrics.width;
context.font = properties.font;
context.fillStyle = properties.fillStyle;
context.strokeStyle = properties.strokeStyle;
context.lineWidth = properties.lineWidth;
context.fillText(text, 125, 75);
const texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
return texture;
};
componentDidMount() {
const properties = {
font: '5px Arial',
fillStyle: 'rgb(142, 142, 142)',
strokeStyle: 'rgba(255,0,0,1)',
lineWidth: 4,
};
const texture1 = makeTextSprite('Text Here', properties);
this.spriteMaterial1.map = texture1;
}
render() {
return
<React3
mainCamera="camera" // this points to the perspectiveCamera which has the name set to "camera" below
width={canvasWidth}
height={canvasHeight}
clearColor={'#ffffff'}
antialias
>
<scene ref={(ref) => { this.scene = ref; }}>
<perspectiveCamera
name="camera"
fov={45}
aspect={canvasWidth/canvasHeight}
near={1}
far={1000}
position={this.cameraPosition}
ref={(ref) => { this.camera = ref; }}
/>
<sprite position={this.position1} scale={this.scale} >
<spriteMaterial ref={(ref) => { this.spriteMaterial1 = ref; }} />
</sprite>
</scene>
</React3>
}
는 properties
에서 나는 Roboto
와 Ariel
를 교체 시도했지만 작동하지 않았다. 어떤 아이디어?
위의 코드 (관련 부분을 작성한 것)가 작동하고 글꼴이 Ariel
에 있습니다. (조금 흐릿한 것이지만 선명하고 깨끗한 텍스트를 얻는 방법을 알고 싶습니다.)