@@ -16,29 +16,45 @@ import * as THREE from 'three';
16
16
import { CCDIKHelper , CCDIKSolver , DRACOLoader , GLTFLoader , IKS , OrbitControls , TransformControls } from 'three-stdlib' ;
17
17
import { DemoOrbitControls } from '../ui-orbit-controls/orbit-controls.component' ;
18
18
19
+ const iks = [
20
+ {
21
+ target : 22 , // "target_hand_l"
22
+ effector : 6 , // "hand_l"
23
+ links : [
24
+ {
25
+ index : 5 , // "lowerarm_l"
26
+ enabled : true ,
27
+ rotationMin : new THREE . Vector3 ( 1.2 , - 1.8 , - 0.4 ) ,
28
+ rotationMax : new THREE . Vector3 ( 1.7 , - 1.1 , 0.3 ) ,
29
+ } ,
30
+ {
31
+ index : 4 , // "Upperarm_l"
32
+ enabled : true ,
33
+ rotationMin : new THREE . Vector3 ( 0.1 , - 0.7 , - 1.8 ) ,
34
+ rotationMax : new THREE . Vector3 ( 1.1 , 0 , - 1.4 ) ,
35
+ } ,
36
+ ] ,
37
+ } ,
38
+ ] ;
39
+ const v0 = new THREE . Vector3 ( ) ;
40
+
19
41
extend ( { TransformControls, CCDIKHelper } ) ;
20
42
21
43
@Component ( {
22
44
standalone : true ,
23
45
template : `
24
46
<ngt-color *args="['#dddddd']" attach="background" />
25
47
<ngt-fog-exp2 *args="['#ffffff', 0.17]" attach="fog" />
26
-
27
48
<ngt-ambient-light [intensity]="8" color="#ffffff" />
28
-
29
49
<ngt-primitive *args="[model$ | ngtPush : null]" (afterAttach)="onAfterModelAttach()" />
30
-
31
50
<ngt-cube-camera #cubeCamera *args="[0.05, 50, cubeRenderTarget]" />
32
-
33
51
<ng-container *ngIf="ooi['kira']">
34
52
<ngt-cCDIK-helper *args="[ooi['kira'], iks, 0.01]" />
35
53
</ng-container>
36
-
37
54
<demo-orbit-controls [minDistance]="0.2" [maxDistance]="1.5" (ready)="orbitControls = $any($event)" />
38
-
39
55
<ngt-transform-controls
40
56
#transformControls
41
- *args="[camera, glDom ]"
57
+ *args="[store.get(' camera'), store.get('gl', 'domElement') ]"
42
58
[size]="0.75"
43
59
[showX]="false"
44
60
space="world"
@@ -48,42 +64,17 @@ extend({ TransformControls, CCDIKHelper });
48
64
schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
49
65
} )
50
66
export class Scene {
51
- readonly iks = [
52
- {
53
- target : 22 , // "target_hand_l"
54
- effector : 6 , // "hand_l"
55
- links : [
56
- {
57
- index : 5 , // "lowerarm_l"
58
- enabled : true ,
59
- rotationMin : new THREE . Vector3 ( 1.2 , - 1.8 , - 0.4 ) ,
60
- rotationMax : new THREE . Vector3 ( 1.7 , - 1.1 , 0.3 ) ,
61
- } ,
62
- {
63
- index : 4 , // "Upperarm_l"
64
- enabled : true ,
65
- rotationMin : new THREE . Vector3 ( 0.1 , - 0.7 , - 1.8 ) ,
66
- rotationMax : new THREE . Vector3 ( 1.1 , 0 , - 1.4 ) ,
67
- } ,
68
- ] ,
69
- } ,
70
- ] ;
71
-
67
+ readonly iks = iks ;
72
68
readonly cubeRenderTarget = new THREE . WebGLCubeRenderTarget ( 1024 ) ;
73
- readonly material = new THREE . MeshBasicMaterial ( { envMap : this . cubeRenderTarget . texture } ) ;
74
-
75
- private readonly store = inject ( NgtStore ) ;
76
- readonly camera = this . store . get ( 'camera' ) ;
77
- readonly glDom = this . store . get ( 'gl' , 'domElement' ) ;
78
69
79
70
private readonly cdr = inject ( ChangeDetectorRef ) ;
71
+ readonly store = inject ( NgtStore ) ;
80
72
81
73
@ViewChild ( 'transformControls' ) transformControls ?: ElementRef < TransformControls > ;
82
74
@ViewChild ( 'cubeCamera' ) cubeCamera ?: ElementRef < THREE . CubeCamera > ;
83
75
orbitControls ?: OrbitControls ;
84
76
solver ?: CCDIKSolver ;
85
77
86
- private readonly v0 = new THREE . Vector3 ( ) ;
87
78
readonly ooi : Record < string , THREE . Object3D > = { } ;
88
79
89
80
readonly model$ = injectNgtLoader (
@@ -98,8 +89,6 @@ export class Scene {
98
89
map ( ( gltf ) => {
99
90
gltf . scene . traverse ( ( n ) => {
100
91
if ( n . name === 'head' ) this . ooi [ 'head' ] = n ;
101
- if ( n . name === 'lowerarm_l' ) this . ooi [ 'lowerarm_l' ] = n ;
102
- if ( n . name === 'Upperarm_l' ) this . ooi [ 'Upperarm_l' ] = n ;
103
92
if ( n . name === 'hand_l' ) this . ooi [ 'hand_l' ] = n ;
104
93
if ( n . name === 'target_hand_l' ) this . ooi [ 'target_hand_l' ] = n ;
105
94
if ( n . name === 'boule' ) this . ooi [ 'sphere' ] = n ;
@@ -113,22 +102,23 @@ export class Scene {
113
102
114
103
constructor ( ) {
115
104
injectBeforeRender ( ( { gl, scene } ) => {
116
- if ( this . ooi [ 'sphere' ] && this . cubeCamera ) {
117
- this . ooi [ 'sphere' ] . visible = false ;
118
- this . ooi [ 'sphere' ] . getWorldPosition ( this . cubeCamera . nativeElement . position ) ;
105
+ const head = this . ooi [ 'head' ] ;
106
+ const sphere = this . ooi [ 'sphere' ] ;
107
+
108
+ if ( sphere && this . cubeCamera ) {
109
+ sphere . visible = false ;
110
+ sphere . getWorldPosition ( this . cubeCamera . nativeElement . position ) ;
119
111
this . cubeCamera . nativeElement . update ( gl , scene ) ;
120
- this . ooi [ ' sphere' ] . visible = true ;
112
+ sphere . visible = true ;
121
113
}
122
114
123
115
if ( this . solver ) {
124
116
this . solver . update ( ) ;
125
117
}
126
118
127
- const head = this . ooi [ 'head' ] ;
128
- const sphere = this . ooi [ 'sphere' ] ;
129
119
if ( head && sphere ) {
130
- sphere . getWorldPosition ( this . v0 ) ;
131
- head . lookAt ( this . v0 ) ;
120
+ sphere . getWorldPosition ( v0 ) ;
121
+ head . lookAt ( v0 ) ;
132
122
head . rotation . set ( head . rotation . x , head . rotation . y + Math . PI , head . rotation . z ) ;
133
123
}
134
124
} ) ;
@@ -137,7 +127,9 @@ export class Scene {
137
127
onAfterModelAttach ( ) {
138
128
this . orbitControls ?. target . copy ( this . ooi [ 'sphere' ] . position ) ;
139
129
this . ooi [ 'hand_l' ] . attach ( this . ooi [ 'sphere' ] ) ;
140
- applyProps ( this . ooi [ 'sphere' ] , { material : this . material } ) ;
130
+ applyProps ( this . ooi [ 'sphere' ] , {
131
+ material : new THREE . MeshBasicMaterial ( { envMap : this . cubeRenderTarget . texture } ) ,
132
+ } ) ;
141
133
142
134
this . transformControls ?. nativeElement . attach ( this . ooi [ 'target_hand_l' ] ) ;
143
135
this . ooi [ 'kira' ] . add ( ( this . ooi [ 'kira' ] as THREE . SkinnedMesh ) . skeleton . bones [ 0 ] ) ;
0 commit comments