Skip to content

Commit 5a2ac26

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
chore: clean up
1 parent 3106b79 commit 5a2ac26

File tree

8 files changed

+127
-0
lines changed

8 files changed

+127
-0
lines changed

apps/.gitkeep

Whitespace-only changes.

apps/sandbox/src/app/pages/animation-keyframes/index.page.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RouteMeta } from '@analogjs/router';
12
import { CUSTOM_ELEMENTS_SCHEMA, Component, computed, inject } from '@angular/core';
23
import { NgtArgs, NgtCanvas, NgtStore } from 'angular-three';
34
import { NgtsOrbitControls } from 'angular-three-soba/controls';
@@ -7,6 +8,10 @@ import { NgtsStats } from 'angular-three-soba/performance';
78
import * as THREE from 'three';
89
import { RoomEnvironment } from 'three-stdlib';
910

11+
export const routeMeta: RouteMeta = {
12+
title: 'THREE.js Animation keyframes',
13+
};
14+
1015
@Component({
1116
standalone: true,
1217
templateUrl: 'scene.html',

apps/sandbox/src/app/pages/camera/index.page.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RouteMeta } from '@analogjs/router';
12
import {
23
AfterViewInit,
34
CUSTOM_ELEMENTS_SCHEMA,
@@ -12,6 +13,10 @@ import {
1213
import { NgtArgs, NgtCanvas, NgtRenderState, NgtState, NgtStore, injectBeforeRender } from 'angular-three';
1314
import * as THREE from 'three';
1415

16+
export const routeMeta: RouteMeta = {
17+
title: 'THREE.js Camera',
18+
};
19+
1520
@Component({
1621
standalone: true,
1722
templateUrl: 'scene.html',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ngt-canvas [sceneGraph]="scene" [shadows]="true" [camera]="{ position: [0, 0, 20], fov: 35, near: 1, far: 40 }" />
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { RouteMeta } from '@analogjs/router';
2+
import { CUSTOM_ELEMENTS_SCHEMA, Component, Directive } from '@angular/core';
3+
import { NgtArgs, NgtCanvas, injectBeforeRender } from 'angular-three';
4+
import { NgtcPhysics } from 'angular-three-cannon';
5+
import { injectSphere } from 'angular-three-cannon/services';
6+
import { NgtpEffectComposer } from 'angular-three-postprocessing';
7+
import { NgtpBloom } from 'angular-three-postprocessing/effects';
8+
import { injectNgtsTextureLoader } from 'angular-three-soba/loaders';
9+
import { NgtsEnvironment, NgtsSky } from 'angular-three-soba/staging';
10+
import * as THREE from 'three';
11+
12+
export const routeMeta: RouteMeta = {
13+
title: 'Object Clump w/ Physics',
14+
};
15+
16+
@Directive({ selector: 'clump-pointer', standalone: true })
17+
class Pointer {
18+
readonly pointerBody = injectSphere(() => ({ type: 'Kinematic', args: [3], position: [0, 0, 0] }));
19+
20+
constructor() {
21+
injectBeforeRender(({ pointer, viewport }) => {
22+
this.pointerBody.api().position.set((pointer.x * viewport.width) / 2, (pointer.y * viewport.height) / 2, 0);
23+
});
24+
}
25+
}
26+
27+
const mat = new THREE.Matrix4();
28+
const vec = new THREE.Vector3();
29+
30+
@Component({
31+
selector: 'object-clump',
32+
standalone: true,
33+
templateUrl: 'object-clump.html',
34+
imports: [NgtArgs],
35+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
36+
})
37+
class ObjectClump {
38+
readonly count = 40;
39+
readonly texture = injectNgtsTextureLoader(() => 'cross.jpg');
40+
41+
readonly sphereBody = injectSphere<THREE.InstancedMesh>(() => ({
42+
args: [1],
43+
mass: 1,
44+
angularDamping: 0.1,
45+
linearDamping: 0.65,
46+
position: [
47+
THREE.MathUtils.randFloatSpread(20),
48+
THREE.MathUtils.randFloatSpread(20),
49+
THREE.MathUtils.randFloatSpread(20),
50+
],
51+
}));
52+
53+
onBeforeRender(object: THREE.InstancedMesh) {
54+
for (let i = 0; i < this.count; i++) {
55+
// Get current whereabouts of the instanced sphere
56+
object.getMatrixAt(i, mat);
57+
// Normalize the position and multiply by a negative force.
58+
// This is enough to drive it towards the center-point.
59+
this.sphereBody
60+
.api()
61+
.at(i)
62+
.applyForce(vec.setFromMatrixPosition(mat).normalize().multiplyScalar(-50).toArray(), [0, 0, 0]);
63+
}
64+
}
65+
}
66+
67+
@Component({
68+
standalone: true,
69+
templateUrl: 'scene.html',
70+
imports: [NgtArgs, NgtcPhysics, NgtsEnvironment, NgtsSky, NgtpEffectComposer, NgtpBloom, ObjectClump, Pointer],
71+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
72+
})
73+
class SceneGraph {}
74+
75+
@Component({
76+
standalone: true,
77+
templateUrl: 'index.html',
78+
imports: [NgtCanvas],
79+
})
80+
export default class Clump {
81+
readonly scene = SceneGraph;
82+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<ngt-instanced-mesh
2+
*args="[undefined, undefined, count]"
3+
[ref]="sphereBody.ref"
4+
[castShadow]="true"
5+
[receiveShadow]="true"
6+
(beforeRender)="onBeforeRender($event.object)"
7+
>
8+
<ngt-sphere-geometry *args="[1, 32, 32]" />
9+
<ngt-mesh-standard-material
10+
color="red"
11+
emissive="#370037"
12+
[roughness]="0"
13+
[envMapIntensity]="0.2"
14+
[map]="texture()"
15+
/>
16+
</ngt-instanced-mesh>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<ngt-ambient-light [intensity]="0.25" />
2+
<ngt-spot-light [position]="30" [angle]="0.2" [penumbra]="1" [castShadow]="true">
3+
<ngt-vector2 *args="[512, 512]" attach="shadow.mapSize" />
4+
</ngt-spot-light>
5+
<ngt-directional-light [position]="-10" [intensity]="5" color="purple" />
6+
7+
<ngtc-physics [gravity]="[0, 2, 0]" [iterations]="10">
8+
<clump-pointer />
9+
<object-clump />
10+
</ngtc-physics>
11+
12+
<ngts-environment files="adamsbridge.hdr" />
13+
14+
<ngtp-effect-composer>
15+
<ngtp-bloom />
16+
</ngtp-effect-composer>
17+
18+
<ngts-sky />

libs/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)