1
1
import {
2
+ Attribute ,
2
3
ChangeDetectionStrategy ,
3
4
Component ,
4
5
CUSTOM_ELEMENTS_SCHEMA ,
7
8
signal ,
8
9
viewChild ,
9
10
} from '@angular/core' ;
10
- import { NgtArgs , NgtPortalDeclarations , NgtVector3 } from 'angular-three' ;
11
+ import { injectBeforeRender , injectStore , NgtArgs , NgtPortalDeclarations , NgtVector3 } from 'angular-three' ;
11
12
import * as THREE from 'three' ;
12
13
13
14
@Component ( {
@@ -56,85 +57,133 @@ export class Box {
56
57
position = input < NgtVector3 > ( 0 ) ;
57
58
color = input ( 'turquoise' ) ;
58
59
60
+ constructor ( @Attribute ( 'context' ) context : string ) {
61
+ const store = injectStore ( ) ;
62
+ console . log ( { context, store : store . snapshot . id , previous : store . snapshot . previousRoot } ) ;
63
+ }
64
+
59
65
onAttach ( event : any ) {
60
66
console . log ( 'in box' , event ) ;
61
67
}
62
68
}
63
69
70
+ @Component ( {
71
+ selector : 'app-nested-box' ,
72
+ template : `
73
+ <ngt-mesh [position]="position()">
74
+ <ngt-box-geometry *args="[0.5, 0.5, 0.5]" />
75
+ <ngt-mesh-basic-material [color]="color()" (attached)="onAttach($event)" />
76
+
77
+ <ng-content>
78
+ <app-box context="in nested box in root" [position]="position()" />
79
+ </ng-content>
80
+
81
+ <ng-content select="[data-children]" />
82
+ </ngt-mesh>
83
+ ` ,
84
+ imports : [ NgtArgs , Box ] ,
85
+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
86
+ changeDetection : ChangeDetectionStrategy . OnPush ,
87
+ } )
88
+ export class NestedBox {
89
+ position = input < NgtVector3 > ( 0 ) ;
90
+ color = input ( 'turquoise' ) ;
91
+
92
+ onAttach ( event : any ) {
93
+ console . log ( 'in nested box' , event ) ;
94
+ }
95
+ }
96
+
64
97
@Component ( {
65
98
selector : 'app-scene' ,
66
99
template : `
67
100
<ngt-ambient-light [intensity]="Math.PI" />
101
+ <ngt-directional-light [position]="5" [intensity]="Math.PI" />
68
102
69
103
<ngt-group #group>
104
+ <!-- regular old three element -->
70
105
<ngt-mesh (pointerover)="color.set('orange')" (pointerout)="color.set('hotpink')">
71
106
<ngt-sphere-geometry *args="[0.5, 32, 32]" />
72
107
<ngt-mesh-toon-material [color]="color()" (attached)="onAttach($event)" />
73
108
</ngt-mesh>
74
109
75
- <!--
76
- @if (show()) {
77
- <ngt-mesh [position]="[3, 0, 0]">
78
- <ngt-icosahedron-geometry />
79
- <ngt-mesh-normal-material />
80
- </ngt-mesh>
81
- }
82
- -->
83
-
84
- <!--
85
- <app-box [position]="[1, 0, 0]" />
86
- <app-box [position]="[-1, 0, 0]" color="red" />
87
- <app-box [position]="[0, 1, 0]">
88
- <ngt-mesh-standard-material color="green" />
89
- </app-box>
90
-
91
- <app-box [position]="[0, -1, 0]" color="purple" />
92
-
93
- @if (show()) {
94
- <app-box [position]="[1, 1, 0]">
95
- @if (show()) {
96
- <ngt-mesh-phong-material color="yellow" />
97
- }
98
- </app-box>
99
- }
100
-
101
- <app-box [position]="[-1, -1, 0]" color="brown">
102
- <app-box data-children [position]="[-0.5, -0.5, 0]" color="pink" />
103
- </app-box>
104
-
105
- <app-box [position]="[-1, 1, 0]">
106
- <ngt-mesh-lambert-material color="orange" />
107
- <app-box data-children [position]="[-0.5, 0.5, 0]" color="skyblue" />
108
- </app-box>
109
-
110
- <app-box [position]="[1, -1, 0]">
111
- @if (true) {
112
- <ngt-mesh-normal-material />
113
- }
114
-
115
- @if (show()) {
116
- <app-box data-children [position]="[0.5, -0.5, 0]" color="black" />
117
- }
118
- </app-box>
119
- -->
120
-
121
- <!--
122
- <app-condition-box [position]="[0, 2, 0]" />
123
- @if (show()) {
124
- <app-condition-box [position]="[0, -2, 0]" />
125
- }
126
- -->
110
+ <!-- <app-nested-box [position]="[-3, 0, 0]" />-->
111
+
112
+ <!-- <!– three element under condition –>-->
113
+ <!-- @if (show()) {-->
114
+ <!-- <ngt-mesh [position]="[3, 0, 0]">-->
115
+ <!-- <ngt-icosahedron-geometry />-->
116
+ <!-- <ngt-mesh-normal-material />-->
117
+ <!-- </ngt-mesh>-->
118
+ <!-- }-->
119
+
120
+ <!-- <!– component wrapping three elemnent –>-->
121
+ <!-- <app-box [position]="[1, 0, 0]" />-->
122
+
123
+ <!-- <!– with input for default content –>-->
124
+ <!-- <app-box [position]="[-1, 0, 0]" color="red" />-->
125
+
126
+ <!-- <!– with custom ng content –>-->
127
+ <!-- <app-box [position]="[0, 1, 0]">-->
128
+ <!-- <ngt-mesh-standard-material color="green" />-->
129
+ <!-- </app-box>-->
130
+
131
+ <!-- <!– with property binding for input for default content –>-->
132
+ <!-- <app-box [position]="[0, -1, 0]" [color]="color()" />-->
133
+
134
+ <!-- <!– component under condition –>-->
135
+ <!-- @if (show()) {-->
136
+ <!-- <app-box [position]="[1, 1, 0]">-->
137
+ <!-- @if (show()) {-->
138
+ <!-- <ngt-mesh-phong-material color="yellow" />-->
139
+ <!-- }-->
140
+ <!-- </app-box>-->
141
+ <!-- }-->
142
+
143
+ <!-- <!– component with component as content –>-->
144
+ <!-- <app-box [position]="[-1, -1, 0]" color="brown" context="in root">-->
145
+ <!-- <app-box data-children [position]="[-0.5, -0.5, 0]" color="pink" context="in box content in root" />-->
146
+ <!-- </app-box>-->
147
+
148
+ <!-- <!– component with both content projection slots –>-->
149
+ <!-- <app-box [position]="[-1, 1, 0]">-->
150
+ <!-- <ngt-mesh-lambert-material color="orange" />-->
151
+ <!-- <app-box data-children [position]="[-0.5, 0.5, 0]" color="skyblue" />-->
152
+ <!-- </app-box>-->
153
+
154
+ <!-- <!– component with conditional content slots –>-->
155
+ <!-- <app-box [position]="[1, -1, 0]">-->
156
+ <!-- @if (true) {-->
157
+ <!-- <ngt-mesh-normal-material />-->
158
+ <!-- }-->
159
+
160
+ <!-- @if (show()) {-->
161
+ <!-- <app-box data-children [position]="[0.5, -0.5, 0]" color="black" />-->
162
+ <!-- }-->
163
+ <!-- </app-box>-->
164
+
165
+ <!-- <!– component with conditional template –>-->
166
+ <!-- <app-condition-box [position]="[0, 2, 0]" />-->
167
+
168
+ <!-- <!– component with conditional template under condition –>-->
169
+ <!-- @if (show()) {-->
170
+ <!-- <app-condition-box [position]="[0, -2, 0]" />-->
171
+ <!-- }-->
127
172
</ngt-group>
128
- <!--
173
+
174
+ <!-- portal -->
129
175
<ngt-portal [container]="virtualScene">
130
176
<ngt-group *portalContent>
131
- <app-box />
132
- <app-condition-box />
177
+ <!-- component inside portal -->
178
+ <app-box context="in portal" />
179
+
180
+ @if (show()) {
181
+ <app-box context="in portal in condition" />
182
+ }
133
183
</ngt-group>
134
184
</ngt-portal>
135
- -->
136
185
` ,
137
- imports : [ NgtArgs , Box , ConditionBox , NgtPortalDeclarations ] ,
186
+ imports : [ NgtArgs , Box , ConditionBox , NgtPortalDeclarations , NestedBox ] ,
138
187
changeDetection : ChangeDetectionStrategy . OnPush ,
139
188
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
140
189
host : {
@@ -153,16 +202,16 @@ export class Scene {
153
202
private groupRef = viewChild . required < ElementRef < THREE . Group > > ( 'group' ) ;
154
203
155
204
constructor ( ) {
156
- // setInterval(() => {
157
- // this.show.update((v) => !v);
158
- // this.sphereArgs.update((v) => [v[0] === 0.5 ? 1 : 0.5, v[1], v[2]]);
159
- // }, 2500);
160
- //
161
- // injectBeforeRender(() => {
162
- // const group = this.groupRef().nativeElement;
163
- // group.rotation.x += 0.01 ;
164
- // group.rotation.y += 0.01 ;
165
- // });
205
+ setInterval ( ( ) => {
206
+ this . show . update ( ( v ) => ! v ) ;
207
+ this . sphereArgs . update ( ( v ) => [ v [ 0 ] === 0.5 ? 1 : 0.5 , v [ 1 ] , v [ 2 ] ] ) ;
208
+ } , 2500 ) ;
209
+
210
+ injectBeforeRender ( ( { delta } ) => {
211
+ const group = this . groupRef ( ) . nativeElement ;
212
+ group . rotation . x += delta ;
213
+ group . rotation . y += delta ;
214
+ } ) ;
166
215
}
167
216
168
217
onDocumentClick ( event : MouseEvent ) {
0 commit comments