合并
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
import * as THREE from "three";
|
||||
/**
|
||||
* 返回一个带有文字的几何平面
|
||||
* @param {String} text 把输入的文字转化为base64的img图片
|
||||
* 返回一个带有文字的的#3D材质
|
||||
* 把输入的文字转化为base64的img图片
|
||||
* @param {String} text
|
||||
* @param {String} param 传感器实时检测参数
|
||||
*/
|
||||
export default function (text, width = 100, height = 50) {
|
||||
export default function (text = "", param = "50", width = 80, height = 50) {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.fillStyle = "white";
|
||||
ctx.fillStyle = "#00b8ec";
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
ctx.fillStyle = "black";
|
||||
ctx.font = "16px serif";
|
||||
ctx.fillText(text, (100 - text.length * 16.6) / 2, 30);
|
||||
ctx.fillStyle = "white";
|
||||
ctx.font = "12px serif";
|
||||
ctx.fillText(text, (100 - text.length * 15) / 2, 20);
|
||||
ctx.fillText(param, (100 - param.length * 10) / 2, 40);
|
||||
ctx.strokeStyle = "white";
|
||||
ctx.moveTo(0, 26);
|
||||
ctx.lineTo(100, 26);
|
||||
ctx.stroke();
|
||||
const base64 = canvas.toDataURL();
|
||||
return new THREE.MeshBasicMaterial({
|
||||
map: new THREE.TextureLoader().load(base64),
|
||||
|
||||
Reference in New Issue
Block a user