Skip to content

Commit 607633d

Browse files
committed
docs: clean up and add tweak pane for particles
1 parent aefaa8b commit 607633d

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

apps/examples/src/app/misc/particle-maxime/scene.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, viewChild } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
CUSTOM_ELEMENTS_SCHEMA,
5+
ElementRef,
6+
input,
7+
signal,
8+
viewChild,
9+
} from '@angular/core';
210
import { extend, injectBeforeRender, NgtArgs, NgtPortal } from 'angular-three';
311
import { NgtpBloom, NgtpEffectComposer } from 'angular-three-postprocessing';
412
import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';
@@ -8,6 +16,7 @@ import * as THREE from 'three';
816

917
import { SimulationMaterial } from './simulation-material';
1018

19+
import { NgtTweakNumber, NgtTweakPane } from 'angular-three-tweakpane';
1120
import fragmentShader from './fragment.glsl' with { loader: 'text' };
1221
import vertexShader from './vertex.glsl' with { loader: 'text' };
1322

@@ -66,6 +75,9 @@ export class FBOParticles {
6675
protected readonly fragmentShader = fragmentShader;
6776
protected readonly AdditiveBlending = THREE.AdditiveBlending;
6877

78+
frequency = input.required<number>();
79+
timeScale = input.required<number>();
80+
6981
protected size = 128;
7082
protected virtualScene = new THREE.Scene();
7183
protected virtualCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 1 / Math.pow(2, 53), 1);
@@ -124,7 +136,8 @@ export class FBOParticles {
124136
if (!simulationMaterial) return;
125137

126138
this.uniforms['uPositions'].value = this.renderTarget().texture;
127-
simulationMaterial.uniforms['uTime'].value = clock.elapsedTime;
139+
simulationMaterial.uniforms['uFrequency'].value = this.frequency();
140+
simulationMaterial.uniforms['uTime'].value = clock.elapsedTime * this.timeScale();
128141
});
129142
}
130143
}
@@ -137,18 +150,35 @@ export class FBOParticles {
137150
<ngt-color *args="['black']" attach="background" />
138151
<ngt-ambient-light [intensity]="Math.PI * 0.5" />
139152
140-
<app-fbo-particles />
153+
<app-fbo-particles [frequency]="frequency()" [timeScale]="timeScale()" />
141154
142155
<ngtp-effect-composer>
143156
<ngtp-bloom [options]="{ luminanceThreshold: 0, intensity: 4 }" />
144157
</ngtp-effect-composer>
145158
146159
<ngts-orbit-controls [options]="{ enablePan: false }" />
160+
161+
<ngt-tweak-pane title="Particles" [top]="48" [expanded]="true">
162+
<ngt-tweak-number [(value)]="frequency" label="frequency" [params]="{ min: 0.25, max: 1, step: 0.01 }" />
163+
<ngt-tweak-number [(value)]="timeScale" label="timeScale" [params]="{ min: 0.5, max: 1.5, step: 0.01 }" />
164+
</ngt-tweak-pane>
147165
`,
148-
imports: [NgtsPerspectiveCamera, NgtsOrbitControls, NgtArgs, FBOParticles, NgtpEffectComposer, NgtpBloom],
166+
imports: [
167+
NgtsPerspectiveCamera,
168+
NgtsOrbitControls,
169+
NgtArgs,
170+
FBOParticles,
171+
NgtpEffectComposer,
172+
NgtpBloom,
173+
NgtTweakPane,
174+
NgtTweakNumber,
175+
],
149176
changeDetection: ChangeDetectionStrategy.OnPush,
150177
schemas: [CUSTOM_ELEMENTS_SCHEMA],
151178
})
152179
export class SceneGraph {
153180
protected readonly Math = Math;
181+
182+
protected frequency = signal(0.5);
183+
protected timeScale = signal(1);
154184
}

apps/examples/src/app/misc/particle-maxime/simulation-material.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function generateRandomPointInTriangle(v1: THREE.Vector3, v2: THREE.Vector3, v3:
1717
.addScaledVector(v3, r3 / sum);
1818
}
1919

20-
function createGeometryFromCurve(curveData: any, matrix: THREE.Matrix4) {
20+
function createGeometryFromCurve(curveData: (typeof shapes)['curve']) {
2121
const geometry = new THREE.BufferGeometry();
2222
geometry.setAttribute('position', new THREE.Float32BufferAttribute(curveData.data.attributes.position.array, 3));
2323
geometry.setAttribute('normal', new THREE.Float32BufferAttribute(curveData.data.attributes.normal.array, 3));
@@ -44,7 +44,7 @@ function getRandomData(width: number, height: number) {
4444
.setPosition(positions[shapeIndex])
4545
.scale(new THREE.Vector3(scale, scale, scale));
4646

47-
const geometry = createGeometryFromCurve(curveData, matrix);
47+
const geometry = createGeometryFromCurve(curveData);
4848
const positionsArr = geometry.attributes['position'].array;
4949
const indices = curveData.data.index.array;
5050

0 commit comments

Comments
 (0)