This commit is contained in:
xiao.xiong
2025-10-11 18:33:14 +08:00
parent 10cdbb2967
commit e974416760
3 changed files with 22 additions and 2 deletions

2
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,2 @@
onlyBuiltDependencies:
- esbuild

View File

@@ -2,7 +2,7 @@ import './style.css';
import * as THREE from 'three'; import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'; import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import { flyChaos } from './fly'; import { flyChaos } from './fly';
import { randomPng } from './random/png';
const gridSize = 10; const gridSize = 10;
const cardSize = 3; const cardSize = 3;
const scene = new THREE.Scene(); const scene = new THREE.Scene();
@@ -25,7 +25,9 @@ const cards: THREE.Mesh[] = [];
const geometry = new THREE.BoxGeometry(cardSize, cardSize, 0.1); const geometry = new THREE.BoxGeometry(cardSize, cardSize, 0.1);
const textureLoader = new THREE.TextureLoader(); const textureLoader = new THREE.TextureLoader();
const pandaTexture = textureLoader.load('./panda.png'); // const pandaTexture = textureLoader.load('./panda.png');
// const pandaTexture = textureLoader.load(randomPng(8));
const pandaTexture = textureLoader.load(randomPng("小熊猫"));
pandaTexture.colorSpace = THREE.SRGBColorSpace; pandaTexture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshStandardMaterial({ const material = new THREE.MeshStandardMaterial({
map: pandaTexture, map: pandaTexture,

16
src/random/png.ts Normal file
View File

@@ -0,0 +1,16 @@
// 数字图片然后base64的图片
export const randomPng = (content: number | string = 1) =>{
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d')!;
const size = 128;
canvas.width = size;
canvas.height = size;
ctx.fillStyle = '#'+Math.floor(Math.random()*16777215).toString(16);
ctx.fillRect(0, 0, size, size);
ctx.font = 'bold 32px Arial';
ctx.fillStyle = '#ffffff';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(content.toString(), size / 2, size / 2);
return canvas.toDataURL();
}