Skip to content

Commit c41bf3b

Browse files
committed
feat: add type sprite on threejs engine
1 parent fd73b3c commit c41bf3b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/scripts/three.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class ThreeEngine extends Engine {
5050
if (this.type === 'fill')
5151
lineMaterial = new THREE.LineBasicMaterial({ color: 0x000000 });
5252

53+
// Sprite texture
54+
const map = new THREE.TextureLoader().load('/sprite.png');
55+
const material = new THREE.SpriteMaterial({ map: map });
56+
5357
for (let i = 0; i < this.count; i++) {
5458
const size = 10 + Math.random() * 80;
5559
const x = Math.random() * this.width;
@@ -60,14 +64,20 @@ class ThreeEngine extends Engine {
6064
];
6165

6266
const geometry = new THREE.CircleGeometry(size);
63-
let plane;
64-
if (this.type === 'fill') {
65-
plane = new THREE.Mesh(geometry, meshMaterial);
66-
plane.position.set(x, y, 0);
67-
this.scene.add(plane);
67+
let line, plane;
68+
if (this.type === 'sprite') {
69+
line = new THREE.Sprite(material);
70+
line.scale.x = 64;
71+
line.scale.y = 64;
72+
} else {
73+
if (this.type === 'fill') {
74+
plane = new THREE.Mesh(geometry, meshMaterial);
75+
plane.position.set(x, y, 0);
76+
this.scene.add(plane);
77+
}
78+
const edges = new THREE.EdgesGeometry(geometry);
79+
line = new THREE.LineSegments(edges, lineMaterial);
6880
}
69-
const edges = new THREE.EdgesGeometry(geometry);
70-
const line = new THREE.LineSegments(edges, lineMaterial);
7181
line.position.set(x, y, 0);
7282
this.scene.add(line);
7383
particles[i] = { x, y, size: size, dx, dy, el: [line, plane] };

0 commit comments

Comments
 (0)