1
- import {
2
- ChangeDetectionStrategy ,
3
- Component ,
4
- computed ,
5
- CUSTOM_ELEMENTS_SCHEMA ,
6
- effect ,
7
- ElementRef ,
8
- inject ,
9
- viewChild ,
10
- } from '@angular/core' ;
11
- import { injectStore , NgtArgs , NgtEuler , NgtVector3 } from 'angular-three' ;
1
+ import { ChangeDetectionStrategy , Component , CUSTOM_ELEMENTS_SCHEMA , inject } from '@angular/core' ;
2
+ import { NgtArgs , NgtEuler , NgtParent , NgtVector3 } from 'angular-three' ;
12
3
import { NgtsText } from 'angular-three-soba/abstractions' ;
13
- import { FrontSide , Group } from 'three' ;
4
+ import { FrontSide } from 'three' ;
14
5
import { RockStore } from './store' ;
15
6
16
7
@Component ( {
17
8
template : `
18
- <ngt-group #group attach="none">
19
- @if (selectedRock(); as rock) {
9
+ @if (selectedRock(); as rock) {
10
+ <ngt-group *parent=" rock.name">
20
11
<ngt-mesh
21
12
[castShadow]="true"
22
13
[receiveShadow]="true"
@@ -43,10 +34,10 @@ import { RockStore } from './store';
43
34
/>
44
35
}
45
36
</ngt-group>
46
- }
47
- </ngt-group>
37
+ </ngt-group>
38
+ }
48
39
` ,
49
- imports : [ NgtArgs , NgtsText ] ,
40
+ imports : [ NgtArgs , NgtsText , NgtParent ] ,
50
41
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
51
42
changeDetection : ChangeDetectionStrategy . OnPush ,
52
43
host : { class : 'colored-rock' } ,
@@ -64,35 +55,6 @@ export default class ColoredRock {
64
55
] as NgtVector3 ,
65
56
} ) ) ;
66
57
67
- private groupRef = viewChild . required < ElementRef < Group > > ( 'group' ) ;
68
-
69
58
private rockStore = inject ( RockStore ) ;
70
59
protected readonly selectedRock = this . rockStore . selectedRock ;
71
-
72
- private store = injectStore ( ) ;
73
- private scene = this . store . select ( 'scene' ) ;
74
-
75
- private parent = computed ( ( ) => {
76
- const selected = this . selectedRock ( ) ;
77
- if ( ! selected ) return null ;
78
-
79
- const parent = this . scene ( ) . getObjectByName ( selected . name ) ;
80
- if ( ! parent ) return null ;
81
-
82
- return parent ;
83
- } ) ;
84
-
85
- constructor ( ) {
86
- effect ( ( onCleanup ) => {
87
- const parent = this . parent ( ) ;
88
- if ( ! parent ) return ;
89
-
90
- const group = this . groupRef ( ) . nativeElement ;
91
-
92
- parent . add ( group ) ;
93
- onCleanup ( ( ) => {
94
- parent . remove ( group ) ;
95
- } ) ;
96
- } ) ;
97
- }
98
60
}
0 commit comments