@@ -16,29 +16,45 @@ import * as THREE from 'three';
1616import { CCDIKHelper , CCDIKSolver , DRACOLoader , GLTFLoader , IKS , OrbitControls , TransformControls } from 'three-stdlib' ;
1717import { DemoOrbitControls } from '../ui-orbit-controls/orbit-controls.component' ;
1818
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+
1941extend ( { TransformControls, CCDIKHelper } ) ;
2042
2143@Component ( {
2244 standalone : true ,
2345 template : `
2446 <ngt-color *args="['#dddddd']" attach="background" />
2547 <ngt-fog-exp2 *args="['#ffffff', 0.17]" attach="fog" />
26-
2748 <ngt-ambient-light [intensity]="8" color="#ffffff" />
28-
2949 <ngt-primitive *args="[model$ | ngtPush : null]" (afterAttach)="onAfterModelAttach()" />
30-
3150 <ngt-cube-camera #cubeCamera *args="[0.05, 50, cubeRenderTarget]" />
32-
3351 <ng-container *ngIf="ooi['kira']">
3452 <ngt-cCDIK-helper *args="[ooi['kira'], iks, 0.01]" />
3553 </ng-container>
36-
3754 <demo-orbit-controls [minDistance]="0.2" [maxDistance]="1.5" (ready)="orbitControls = $any($event)" />
38-
3955 <ngt-transform-controls
4056 #transformControls
41- *args="[camera, glDom ]"
57+ *args="[store.get(' camera'), store.get('gl', 'domElement') ]"
4258 [size]="0.75"
4359 [showX]="false"
4460 space="world"
@@ -48,42 +64,17 @@ extend({ TransformControls, CCDIKHelper });
4864 schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
4965} )
5066export 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 ;
7268 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' ) ;
7869
7970 private readonly cdr = inject ( ChangeDetectorRef ) ;
71+ readonly store = inject ( NgtStore ) ;
8072
8173 @ViewChild ( 'transformControls' ) transformControls ?: ElementRef < TransformControls > ;
8274 @ViewChild ( 'cubeCamera' ) cubeCamera ?: ElementRef < THREE . CubeCamera > ;
8375 orbitControls ?: OrbitControls ;
8476 solver ?: CCDIKSolver ;
8577
86- private readonly v0 = new THREE . Vector3 ( ) ;
8778 readonly ooi : Record < string , THREE . Object3D > = { } ;
8879
8980 readonly model$ = injectNgtLoader (
@@ -98,8 +89,6 @@ export class Scene {
9889 map ( ( gltf ) => {
9990 gltf . scene . traverse ( ( n ) => {
10091 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 ;
10392 if ( n . name === 'hand_l' ) this . ooi [ 'hand_l' ] = n ;
10493 if ( n . name === 'target_hand_l' ) this . ooi [ 'target_hand_l' ] = n ;
10594 if ( n . name === 'boule' ) this . ooi [ 'sphere' ] = n ;
@@ -113,22 +102,23 @@ export class Scene {
113102
114103 constructor ( ) {
115104 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 ) ;
119111 this . cubeCamera . nativeElement . update ( gl , scene ) ;
120- this . ooi [ ' sphere' ] . visible = true ;
112+ sphere . visible = true ;
121113 }
122114
123115 if ( this . solver ) {
124116 this . solver . update ( ) ;
125117 }
126118
127- const head = this . ooi [ 'head' ] ;
128- const sphere = this . ooi [ 'sphere' ] ;
129119 if ( head && sphere ) {
130- sphere . getWorldPosition ( this . v0 ) ;
131- head . lookAt ( this . v0 ) ;
120+ sphere . getWorldPosition ( v0 ) ;
121+ head . lookAt ( v0 ) ;
132122 head . rotation . set ( head . rotation . x , head . rotation . y + Math . PI , head . rotation . z ) ;
133123 }
134124 } ) ;
@@ -137,7 +127,9 @@ export class Scene {
137127 onAfterModelAttach ( ) {
138128 this . orbitControls ?. target . copy ( this . ooi [ 'sphere' ] . position ) ;
139129 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+ } ) ;
141133
142134 this . transformControls ?. nativeElement . attach ( this . ooi [ 'target_hand_l' ] ) ;
143135 this . ooi [ 'kira' ] . add ( ( this . ooi [ 'kira' ] as THREE . SkinnedMesh ) . skeleton . bones [ 0 ] ) ;
0 commit comments