Skip to content

Commit 8f93663

Browse files
authored
Merge pull request #61 from demike/feat/use-new-control-flow
feat: use new control flow
2 parents 71d6822 + 93313e4 commit 8f93663

File tree

10 files changed

+147
-132
lines changed

10 files changed

+147
-132
lines changed

projects/ngx-three-demo/src/app/code/code.component.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
<mat-card-content>
33
<div class="code-wrapper hljs">
44
<mat-tab-group dynamicHeight color="primary" backgroundColor="primary">
5-
<mat-tab *ngFor="let codeUrl of codeUrls; let i = index" [label]="fileNames[i]">
6-
<pre>
7-
<code [highlight]="$any(codeUrl | codeFromUrl | async ) " [language]="getLanguage(fileNames[i])"></code>
8-
</pre>
9-
</mat-tab>
5+
@for (codeUrl of codeUrls; track codeUrl; let i = $index) {
6+
<mat-tab [label]="fileNames[i]">
7+
<pre>
8+
<code [highlight]="$any(codeUrl | codeFromUrl | async ) " [language]="getLanguage(fileNames[i])"></code>
9+
</pre>
10+
</mat-tab>
11+
}
1012
</mat-tab-group>
1113
</div>
1214
</mat-card-content>

projects/ngx-three-demo/src/app/css3d-renderer-example/css3d-renderer-example.component.html

+15-13
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88
<th-scene [thStats]="true">
99
<th-ambientLight [intensity]="3" />
1010

11-
<th-cSS3DObject *ngFor="let el of this.table; let i = index" [position]="poses[i].position">
12-
<div class="element" [style.background]="'rgba(0,127,127,' + (Math.random() * 0.5 + 0.25) + ')'">
13-
<div class="number">
14-
{{ i + 1 }}
11+
@for (el of this.table; track el; let i = $index) {
12+
<th-cSS3DObject [position]="poses[i].position">
13+
<div class="element" [style.background]="'rgba(0,127,127,' + (Math.random() * 0.5 + 0.25) + ')'">
14+
<div class="number">
15+
{{ i + 1 }}
16+
</div>
17+
<div class="symbol">
18+
{{ el[0] }}
19+
</div>
20+
<div class="details">
21+
{{ el[1] }} <br />
22+
{{ el[2] }}
23+
</div>
1524
</div>
16-
<div class="symbol">
17-
{{ el[0] }}
18-
</div>
19-
<div class="details">
20-
{{ el[1] }} <br />
21-
{{ el[2] }}
22-
</div>
23-
</div>
24-
</th-cSS3DObject>
25+
</th-cSS3DObject>
26+
}
2527

2628
<th-pointLight [position]="[10, 10, 10]" [intensity]="3" />
2729

projects/ngx-three-demo/src/app/events-example/events-example.component.html

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,34 @@
1010
[position]="this.position"
1111
(onUpdate)="logUpdates($event)"
1212
(onLoaded)="onLoaded()"
13-
/>
13+
/>
1414

1515
<th-gridHelper [args]="[10, 10]" />
1616
<th-pointLight [position]="[10, 10, 10]" [intensity]="3" />
1717

1818
<th-perspectiveCamera [args]="[45, 2, 0.1, 100]" [position]="[10, 10, 10]" [lookAt]="[0, 0, 0]">
19-
<!--
19+
<!--
2020
binding to three.js events:
21-
1) change: with bind directive for preserving this scope
22-
2) end: with using a fat arrow member function for preserving this scope
21+
1) change: with bind directive for preserving this scope
22+
2) end: with using a fat arrow member function for preserving this scope
2323
-->
2424
<th-orbitControls
2525
[threeEvents]="{
2626
change: onOrbitControlChange | bind: this,
2727
end: onOrbitControlEnd
2828
}"
29-
/>
29+
/>
3030
</th-perspectiveCamera>
3131
</th-scene>
3232
</th-canvas>
3333

3434
<div class="change-list">
3535
<h1>Updates</h1>
3636
<ol>
37-
<li *ngFor="let change of changes">
38-
{{ change }}
39-
</li>
37+
@for (change of changes; track change) {
38+
<li>
39+
{{ change }}
40+
</li>
41+
}
4042
</ol>
4143
</div>

projects/ngx-three-demo/src/app/navigation-shell/navigation-shell.component.html

+36-31
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,50 @@
66
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
77
[mode]="(isHandset$ | async) ? 'over' : 'side'"
88
[opened]="(isHandset$ | async) === false"
9-
>
9+
>
1010
<mat-toolbar>ngx-three</mat-toolbar>
1111
<mat-nav-list>
12-
<a mat-list-item *ngFor="let route of routes" [routerLink]="route.path">{{
13-
route.data.title
14-
}}</a>
12+
@for (route of routes; track route) {
13+
<a mat-list-item [routerLink]="route.path">{{
14+
route.data.title
15+
}}</a>
16+
}
1517
</mat-nav-list>
1618
</mat-sidenav>
1719
<mat-sidenav-content class="content">
1820
<mat-toolbar color="primary">
19-
<button
20-
type="button"
21-
aria-label="Toggle sidenav"
22-
mat-icon-button
23-
(click)="drawer.toggle()"
24-
*ngIf="isHandset$ | async"
25-
>
26-
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
27-
</button>
21+
@if (isHandset$ | async) {
22+
<button
23+
type="button"
24+
aria-label="Toggle sidenav"
25+
mat-icon-button
26+
(click)="drawer.toggle()"
27+
>
28+
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
29+
</button>
30+
}
2831
<span>ngx-three-demo</span>
2932
<span class="toolbar-spacer"></span>
30-
<button
31-
mat-button
32-
*ngIf="this.editorService.urls.length"
33-
(click)="this.editorService.toCodeSandbox($event)"
34-
href="#"
35-
>
36-
<mat-icon>crop_din</mat-icon>
37-
CodeSandbox
38-
</button>
39-
<button
40-
mat-button
41-
*ngIf="this.editorService.urls.length"
42-
(click)="this.editorService.toStackblitz($event)"
43-
href="#"
44-
>
45-
<mat-icon>bolt</mat-icon>
46-
Stackblitz
47-
</button>
33+
@if (this.editorService.urls.length) {
34+
<button
35+
mat-button
36+
(click)="this.editorService.toCodeSandbox($event)"
37+
href="#"
38+
>
39+
<mat-icon>crop_din</mat-icon>
40+
CodeSandbox
41+
</button>
42+
}
43+
@if (this.editorService.urls.length) {
44+
<button
45+
mat-button
46+
(click)="this.editorService.toStackblitz($event)"
47+
href="#"
48+
>
49+
<mat-icon>bolt</mat-icon>
50+
Stackblitz
51+
</button>
52+
}
4853
</mat-toolbar>
4954
<!-- Add Content Here -->
5055
<div class="main-route-content">

projects/ngx-three-demo/src/app/on-demand-example/on-demand-example.component.html

+18-18
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@
2727
<th-gridHelper [args]="[10, 10]" />
2828
<th-pointLight [position]="[10, 10, 10]" [decay]="0" />
2929

30-
<th-perspectiveCamera
31-
[ngSwitch]="controlType"
32-
#camera
33-
[args]="[45, 2, 0.1, 100]"
34-
[position]="[10, 10, 10]"
35-
[lookAt]="[0, 0, 0]"
36-
>
37-
<th-orbitControls *ngSwitchCase="'orbit'" />
38-
<th-mapControls *ngSwitchCase="'map'" />
39-
<th-arcballControls *ngSwitchCase="'arcball'" />
40-
<th-transformControls *ngSwitchCase="'transform'" [object]="model.objRef" />
41-
<th-dragControls
42-
*ngSwitchCase="'drag'"
43-
[args]="[[model.objRef], camera.objRef, canvas.hostElement.nativeElement]"
44-
/>
45-
<th-flyControls *ngSwitchCase="'fly'" />
46-
<th-trackballControls *ngSwitchCase="'trackball'" />
47-
<th-firstPersonControls *ngSwitchCase="'firstpersion'" />
30+
<th-perspectiveCamera #camera [args]="[45, 2, 0.1, 100]" [position]="[10, 10, 10]" [lookAt]="[0, 0, 0]">
31+
@switch (controlType) { @case ('orbit') {
32+
<th-orbitControls />
33+
} @case ('map') {
34+
<th-mapControls />
35+
} @case ('arcball') {
36+
<th-arcballControls />
37+
} @case ('transform') {
38+
<th-transformControls [object]="model.objRef" />
39+
} @case ('drag') {
40+
<th-dragControls [args]="[[model.objRef], camera.objRef, canvas.hostElement.nativeElement]" />
41+
} @case ('fly') {
42+
<th-flyControls />
43+
} @case ('trackball') {
44+
<th-trackballControls />
45+
} @case ('firstpersion') {
46+
<th-firstPersonControls />
47+
} }
4848
</th-perspectiveCamera>
4949
</th-scene>
5050
</th-canvas>

projects/ngx-three-demo/src/app/outline-pass-events-example/outline-pass-events-example.component.html

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88
<th-directionalLight #light [color]="['#ddffdd']" [intensity]="1.8" />
99

1010
<th-sphereGeometry #geometry [args]="[3, 48, 24]" />
11-
<th-mesh
12-
*ngFor="let data of meshData"
13-
[geometry]="geometry.objRef"
14-
[position]="[data.x, data.y, data.z]"
15-
[scale]="[data.scale, data.scale, data.scale]"
16-
[receiveShadow]="true"
17-
[castShadow]="true"
18-
(onMouseEnter)="onHover($event)"
19-
(onMouseExit)="onBlur()"
20-
(onPointerDown)="onPointerDown($event)"
21-
>
22-
<th-meshPhongMaterial [flatShading]="true" [color]="data.color" />
23-
</th-mesh>
11+
@for (data of meshData; track data) {
12+
<th-mesh
13+
[geometry]="geometry.objRef"
14+
[position]="[data.x, data.y, data.z]"
15+
[scale]="[data.scale, data.scale, data.scale]"
16+
[receiveShadow]="true"
17+
[castShadow]="true"
18+
(onMouseEnter)="onHover($event)"
19+
(onMouseExit)="onBlur()"
20+
(onPointerDown)="onPointerDown($event)"
21+
>
22+
<th-meshPhongMaterial [flatShading]="true" [color]="data.color" />
23+
</th-mesh>
24+
}
2425
</th-scene>
2526
<th-effectComposer>
2627
<th-renderPass />
@@ -33,6 +34,6 @@
3334
[edgeGlow]="edgeGlow"
3435
[edgeThickness]="edgeThickness"
3536
[pulsePeriod]="pulsePeriod"
36-
/>
37+
/>
3738
</th-effectComposer>
3839
</th-canvas>

projects/ngx-three-demo/src/app/post-processing-example/post-processing-example.component.html

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717
<th-sphereGeometry #geometry [args]="[1, 4, 4]" />
1818
<th-object3D #object>
19-
<th-mesh
20-
*ngFor="let data of meshData"
21-
[geometry]="geometry.objRef"
22-
[position]="data.pos"
23-
[rotation]="data.rotation"
24-
[scale]="data.scale"
25-
>
26-
<th-meshPhongMaterial [flatShading]="true" [color]="data.color" />
27-
</th-mesh>
19+
@for (data of meshData; track data) {
20+
<th-mesh
21+
[geometry]="geometry.objRef"
22+
[position]="data.pos"
23+
[rotation]="data.rotation"
24+
[scale]="data.scale"
25+
>
26+
<th-meshPhongMaterial [flatShading]="true" [color]="data.color" />
27+
</th-mesh>
28+
}
2829
</th-object3D>
2930
</th-scene>
3031
</th-canvas>

projects/ngx-three-demo/src/app/views-example/views-example.component.html

+24-23
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
width: 0.5 * canvasWidth,
88
height: canvasHeight
99
}"
10-
>
10+
>
1111
<th-scene #scene>
1212
<th-directionalLight [position]="[0, 0, 1]" [args]="['#ffffff']" [intensity]="3" />
1313
<th-mesh [position]="[0, 0, 0]" [rotation]="[-Math.PI / 2, 0, 0]">
@@ -18,45 +18,46 @@
1818
[shininess]="30"
1919
[specular]="['#fac400']"
2020
[color]="['#f83f0d']"
21-
/>
21+
/>
2222
</th-mesh>
2323
<th-mesh
2424
[position]="[-400, 0, 0]"
2525
[rotation]="[-Math.PI / 2, 0, 0]"
2626
[geometry]="geo.objRef"
2727
[material]="mat.objRef"
28-
/>
28+
/>
2929
<th-mesh
3030
[position]="[400, 0, 0]"
3131
[rotation]="[-Math.PI / 2, 0, 0]"
3232
[geometry]="geo.objRef"
3333
[material]="mat.objRef"
34-
/>
34+
/>
3535
</th-scene>
3636

37-
<th-view
38-
#thview
39-
*ngFor="let view of views; let i = index"
40-
[scene]="scene"
37+
@for (view of views; track view; let i = $index) {
38+
<th-view
39+
#thview
40+
[scene]="scene"
4141
[viewPort]="{
4242
x: view.left * canvasWidth,
4343
y: view.bottom * canvasHeight,
4444
width: view.width * canvasWidth,
4545
height: view.height * canvasHeight
4646
}"
47-
[scissor]="thview.viewPort"
48-
[scissorTest]="true"
49-
[clearColor]="view.background"
50-
(onRender)="view.updateCamera(camera.objRef, scene.objRef)"
51-
>
52-
<th-perspectiveCamera
53-
#camera
54-
[position]="$any(view.eye)"
55-
[up]="$any(view.up)"
56-
[fov]="view.fov"
57-
[aspect]="(view.width * canvasWidth) / (view.height * canvasHeight)"
58-
[near]="1"
59-
[far]="10000"
60-
/>
61-
</th-view>
47+
[scissor]="thview.viewPort"
48+
[scissorTest]="true"
49+
[clearColor]="view.background"
50+
(onRender)="view.updateCamera(camera.objRef, scene.objRef)"
51+
>
52+
<th-perspectiveCamera
53+
#camera
54+
[position]="$any(view.eye)"
55+
[up]="$any(view.up)"
56+
[fov]="view.fov"
57+
[aspect]="(view.width * canvasWidth) / (view.height * canvasHeight)"
58+
[near]="1"
59+
[far]="10000"
60+
/>
61+
</th-view>
62+
}
6263
</th-canvas>

projects/ngx-three/src/lib/ThCanvas.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function provideDefaultRenderer(): StaticProvider[] {
5656
@Component({
5757
selector: 'th-canvas',
5858
styleUrls: ['./ThCanvas.scss'],
59-
template: '<ng-content *ngIf="isDevMode()" ></ng-content>',
59+
template: '@if (isDevMode()) {<ng-content ></ng-content>}',
6060
changeDetection: ChangeDetectionStrategy.OnPush,
6161
providers: [
6262
{ provide: HOST_ELEMENT, useFactory: () => inject(ElementRef) },

0 commit comments

Comments
 (0)