1
+ import { NgTemplateOutlet } from '@angular/common' ;
1
2
import {
2
3
ChangeDetectionStrategy ,
3
4
Component ,
@@ -8,33 +9,29 @@ import {
8
9
signal ,
9
10
viewChild ,
10
11
} from '@angular/core' ;
11
- import { extend , injectBeforeRender , injectStore } from 'angular-three' ;
12
+ import { extend , injectBeforeRender , injectLoader , injectStore } from 'angular-three' ;
12
13
import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras' ;
13
14
import { NgtsOrbitControls } from 'angular-three-soba/controls' ;
14
15
import { injectGLTF } from 'angular-three-soba/loaders' ;
16
+ import { NgtTweakCheckbox , NgtTweakColor , NgtTweakNumber , NgtTweakPane } from 'angular-three-tweakpane' ;
17
+ import { GLTF , RGBELoader } from 'three-stdlib' ;
15
18
import * as THREE from 'three/webgpu' ;
19
+ import { DirectionalLight , MeshPhysicalNodeMaterial } from 'three/webgpu' ;
20
+ import { SliceMaterial } from './slice-material' ;
16
21
17
- import { NgTemplateOutlet } from '@angular/common' ;
18
- import { NgtsEnvironment } from 'angular-three-soba/staging' ;
19
- import { NgtTweakCheckbox , NgtTweakColor , NgtTweakNumber , NgtTweakPane } from 'angular-three-tweakpane' ;
20
- import { GLTF } from 'three-stdlib' ;
21
22
import gearsGLB from './gears.glb' with { loader : 'file' } ;
22
- import { SliceMaterial } from './slice-material' ;
23
+ import royalHDR from './royal_esplanade_1k.hdr' with { loader : 'file' } ;
23
24
24
25
injectGLTF . preload ( ( ) => gearsGLB ) ;
25
26
26
27
interface GearsGLB extends GLTF {
27
- nodes : {
28
- axle : THREE . Mesh ;
29
- gears : THREE . Mesh ;
30
- outerHull : THREE . Mesh ;
31
- } ;
28
+ nodes : { axle : THREE . Mesh ; gears : THREE . Mesh ; outerHull : THREE . Mesh } ;
32
29
}
33
30
34
31
@Component ( {
35
32
selector : 'app-scene-graph' ,
36
33
template : `
37
- <ngts-perspective-camera [options]="{ makeDefault: true, position: [-5, 5, 12 ] }" />
34
+ <ngts-perspective-camera [options]="{ makeDefault: true, position: [-5, 5, 5 ] }" />
38
35
39
36
<ngt-directional-light
40
37
castShadow
@@ -64,7 +61,7 @@ interface GearsGLB extends GLTF {
64
61
</ngt-mesh>
65
62
</ng-template>
66
63
67
- <ngt-group #gears [position]="gearsPosition" >
64
+ <ngt-group #gears>
68
65
@if (gltf(); as gltf) {
69
66
@let gears = gltf.nodes.gears;
70
67
@let axle = gltf.nodes.axle;
@@ -86,19 +83,18 @@ interface GearsGLB extends GLTF {
86
83
[arcAngle]="arcAngle()"
87
84
[startAngle]="startAngle()"
88
85
[sliceColor]="sliceColor()"
89
- [parameters]="{ metalness, roughness, envMapIntensity, color, side: DoubleSide }"
86
+ [parameters]="{ metalness, roughness, envMapIntensity, color }"
90
87
/>
91
88
</ngt-mesh>
92
89
}
93
90
</ngt-group>
94
91
95
- <ngt-mesh #plane [position]="[-4, -3, -4]" [scale]="10" receiveShadow>
92
+ <ngt-mesh [position]="[-4, -3, -4]" [scale]="10" receiveShadow (updated)="$event.lookAt(0, 0, 0)" >
96
93
<ngt-plane-geometry />
97
94
<ngt-mesh-standard-material color="#aaaaaa" />
98
95
</ngt-mesh>
99
96
100
- <ngts-environment [options]="{ preset: 'warehouse', background: true, blur: 0.5 }" />
101
- <ngts-orbit-controls />
97
+ <ngts-orbit-controls [options]="{ zoomSpeed: 0.2 }" />
102
98
103
99
<ngt-tweak-pane title="Slice Material" left="8px">
104
100
<ngt-tweak-checkbox [(value)]="rotate" label="rotate" />
@@ -120,7 +116,6 @@ interface GearsGLB extends GLTF {
120
116
imports : [
121
117
NgtsPerspectiveCamera ,
122
118
NgtsOrbitControls ,
123
- NgtsEnvironment ,
124
119
NgTemplateOutlet ,
125
120
SliceMaterial ,
126
121
NgtTweakPane ,
@@ -132,21 +127,21 @@ interface GearsGLB extends GLTF {
132
127
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
133
128
} )
134
129
export class SceneGraph {
135
- protected readonly DoubleSide = THREE . DoubleSide ;
136
-
137
130
private gearsRef = viewChild . required < ElementRef < THREE . Group > > ( 'gears' ) ;
138
- private planeRef = viewChild . required < ElementRef < THREE . Mesh > > ( 'plane' ) ;
139
131
132
+ protected environmentMap = injectLoader (
133
+ ( ) => RGBELoader ,
134
+ ( ) => royalHDR ,
135
+ ) ;
140
136
protected gltf = injectGLTF < GearsGLB > ( ( ) => gearsGLB ) ;
137
+
141
138
private store = injectStore ( ) ;
142
139
143
140
protected metalness = 0.5 ;
144
141
protected roughness = 0.25 ;
145
142
protected envMapIntensity = 0.5 ;
146
143
protected color = '#858080' ;
147
144
148
- protected gearsPosition = new THREE . Vector3 ( ) ;
149
-
150
145
protected rotate = signal ( true ) ;
151
146
protected sliceColor = signal ( '#9370DB' ) ;
152
147
protected startAngleDegrees = signal ( 60 ) ;
@@ -156,29 +151,33 @@ export class SceneGraph {
156
151
protected startAngle = computed ( ( ) => THREE . MathUtils . DEG2RAD * this . startAngleDegrees ( ) ) ;
157
152
158
153
constructor ( ) {
159
- extend ( THREE ) ;
154
+ extend ( { MeshPhysicalNodeMaterial , DirectionalLight } ) ;
160
155
161
156
injectBeforeRender ( ( { delta } ) => {
162
- const [ gears , plane ] = [ this . gearsRef ( ) . nativeElement , this . planeRef ( ) . nativeElement ] ;
163
- plane . lookAt ( gears . position ) ;
164
-
165
157
if ( ! this . rotate ( ) ) return ;
166
-
167
- gears . rotation . y += 0.1 * delta ;
158
+ this . gearsRef ( ) . nativeElement . rotation . y += 0.1 * delta ;
168
159
} ) ;
169
160
170
161
effect ( ( onCleanup ) => {
171
- const [ scene , gl ] = [ this . store . scene ( ) , this . store . gl ( ) ] ;
162
+ const environmentMap = this . environmentMap ( ) ;
163
+ if ( ! environmentMap ) return ;
164
+
165
+ const scene = this . store . scene ( ) ;
172
166
167
+ const oldBackground = scene . background ;
168
+ const oldEnvironment = scene . environment ;
173
169
const blurriness = scene . backgroundBlurriness ;
174
- const lastToneMapping = gl . toneMapping ;
175
170
171
+ environmentMap . mapping = THREE . EquirectangularReflectionMapping ;
172
+
173
+ scene . background = environmentMap ;
176
174
scene . backgroundBlurriness = 0.5 ;
177
- gl . toneMapping = THREE . ACESFilmicToneMapping ;
175
+ scene . environment = environmentMap ;
178
176
179
177
onCleanup ( ( ) => {
178
+ scene . background = oldBackground ;
179
+ scene . environment = oldEnvironment ;
180
180
scene . backgroundBlurriness = blurriness ;
181
- gl . toneMapping = lastToneMapping ;
182
181
} ) ;
183
182
} ) ;
184
183
}
0 commit comments