Skip to content

Commit f81f47e

Browse files
committed
docs: turn out args works just fine with rigidBody
1 parent 605816e commit f81f47e

File tree

6 files changed

+44
-58
lines changed

6 files changed

+44
-58
lines changed

apps/examples/src/app/rapier/active-collision-types/active-collision-types.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, signal, viewChild } from '@angular/core';
22
import { ActiveCollisionTypes } from '@dimforge/rapier3d-compat';
3-
import { injectBeforeRender } from 'angular-three';
3+
import { injectBeforeRender, NgtArgs } from 'angular-three';
44
import { NgtrRigidBody } from 'angular-three-rapier';
5-
import * as THREE from 'three';
65

76
@Component({
87
selector: 'app-ball',
@@ -44,20 +43,17 @@ export class Ball {
4443
selector: 'app-wall',
4544
template: `
4645
<ngt-object3D rigidBody="fixed" [options]="{ colliders: 'cuboid' }">
47-
<ngt-mesh [geometry]="boxGeometry">
48-
<!-- TODO: rigidBody does not work with *args -->
49-
<!-- <ngt-box-geometry *args="[0.5, 5, 2]" />-->
46+
<ngt-mesh>
47+
<ngt-box-geometry *args="[0.5, 5, 2]" />
5048
<ngt-mesh-standard-material transparent [opacity]="0.5" />
5149
</ngt-mesh>
5250
</ngt-object3D>
5351
`,
5452
changeDetection: ChangeDetectionStrategy.OnPush,
5553
schemas: [CUSTOM_ELEMENTS_SCHEMA],
56-
imports: [NgtrRigidBody],
54+
imports: [NgtrRigidBody, NgtArgs],
5755
})
58-
export class Wall {
59-
protected boxGeometry = new THREE.BoxGeometry(0.5, 5, 2);
60-
}
56+
export class Wall {}
6157

6258
@Component({
6359
selector: 'app-active-collision-types-rapier',

apps/examples/src/app/rapier/all-colliders/all-colliders.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ export class Suzanne {
104104
</ngt-object3D>
105105
106106
<ngt-object3D rigidBody [position]="[6, 0, 0]" [options]="{ colliders: false }">
107-
<ngt-mesh castShadow receiveShadow [geometry]="capsuleGeometry">
108-
<!-- TODO: rigidBody does not work with *args
107+
<ngt-mesh castShadow receiveShadow>
109108
<ngt-capsule-geometry *args="[0.5, 1, 4, 8]" />
110-
-->
111109
<ngt-mesh-physical-material color="orange" />
112110
</ngt-mesh>
113111
<ngt-object3D [capsuleCollider]="[0.5, 0.5]" />
@@ -117,10 +115,8 @@ export class Suzanne {
117115
</ngt-object3D>
118116
119117
<ngt-object3D rigidBody [position]="[15, 0, 0]" [options]="{ colliders: false }">
120-
<ngt-mesh castShadow receiveShadow [geometry]="cylinderGeometry">
121-
<!-- TODO: rigidBody does not work with *args
122-
<ngt-cylinder-geometry *args="[0.5, 0.5, 2]" />
123-
-->
118+
<ngt-mesh castShadow receiveShadow>
119+
<ngt-cylinder-geometry *args="[0.5, 0.5, 2]" />
124120
<ngt-mesh-physical-material color="orange" />
125121
</ngt-mesh>
126122
<ngt-object3D [cylinderCollider]="[1, 0.5]" />
@@ -154,10 +150,8 @@ export class Suzanne {
154150
</ngt-object3D>
155151
156152
<ngt-object3D rigidBody [options]="{ colliders: false }">
157-
<ngt-mesh castShadow receiveShadow [geometry]="coneGeometry">
158-
<!-- TODO: rigidBody does not work with *args
159-
<ngt-cone-geometry *args="[0.5, 2]" />
160-
-->
153+
<ngt-mesh castShadow receiveShadow>
154+
<ngt-cone-geometry *args="[0.5, 2]" />
161155
<ngt-mesh-physical-material color="orange" />
162156
</ngt-mesh>
163157
<ngt-object3D [coneCollider]="[1, 0.5]" />
@@ -167,10 +161,8 @@ export class Suzanne {
167161
</ngt-object3D>
168162
169163
<ngt-object3D rigidBody [position]="[0, 3, 0]" [options]="{ colliders: false }">
170-
<ngt-mesh castShadow receiveShadow [geometry]="coneGeometry">
171-
<!-- TODO: rigidBody does not work with *args
172-
<ngt-cone-geometry *args="[0.5, 2]" />
173-
-->
164+
<ngt-mesh castShadow receiveShadow>
165+
<ngt-cone-geometry *args="[0.5, 2]" />
174166
<ngt-mesh-physical-material color="orange" />
175167
</ngt-mesh>
176168
<ngt-object3D [roundConeCollider]="[1, 0.5, 0.1]" />
@@ -180,10 +172,8 @@ export class Suzanne {
180172
</ngt-object3D>
181173
182174
<ngt-object3D rigidBody [position]="[3, 3, 0]" [options]="{ colliders: false }">
183-
<ngt-mesh castShadow receiveShadow [geometry]="cylinderGeometry">
184-
<!-- TODO: rigidBody does not work with *args
185-
<ngt-cylinder-geometry *args="[0.5, 0.5, 2]" />
186-
-->
175+
<ngt-mesh castShadow receiveShadow>
176+
<ngt-cylinder-geometry *args="[0.5, 0.5, 2]" />
187177
<ngt-mesh-physical-material color="orange" />
188178
</ngt-mesh>
189179
<ngt-object3D [roundCylinderCollider]="[1, 0.4, 0.1]" />
@@ -227,6 +217,7 @@ export class Suzanne {
227217
NgtrRoundCylinderCollider,
228218
NgtrHeightfieldCollider,
229219
NgtsHTML,
220+
NgtArgs,
230221
],
231222
changeDetection: ChangeDetectionStrategy.OnPush,
232223
schemas: [CUSTOM_ELEMENTS_SCHEMA],
@@ -245,9 +236,6 @@ export default class AllCollidersExample {
245236
);
246237

247238
protected roundBoxGeometry = new RoundedBoxGeometry(1.4, 1.4, 1.4, 8, 0.2);
248-
protected capsuleGeometry = new THREE.CapsuleGeometry(0.5, 1, 4, 8);
249-
protected cylinderGeometry = new THREE.CylinderGeometry(0.5, 0.5, 2);
250-
protected coneGeometry = new THREE.ConeGeometry(0.5, 2);
251239

252240
constructor() {
253241
this.heightField.forEach((v, index) => {

apps/examples/src/app/rapier/attractors/attractors.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ import { NgtArgs, NgtVector3 } from 'angular-three';
33
import { NgtrInstancedRigidBodies, NgtrInteractionGroups, NgtrRigidBody } from 'angular-three-rapier';
44
import { NgtrAttractor } from 'angular-three-rapier/addons';
55
import { NgtsHTML } from 'angular-three-soba/misc';
6-
import * as THREE from 'three';
76

87
@Component({
98
selector: 'app-attractors-rapier',
109
template: `
1110
<ngt-group>
1211
<ngt-object3D [instancedRigidBodies]="instances" [options]="{ colliders: 'ball' }">
13-
<ngt-instanced-mesh *args="[ballGeometry, undefined, 100]" castShadow>
14-
<!-- // TODO: rigidBody does not work with *args-->
15-
<!-- <ngt-sphere-geometry *args="[1]" />-->
12+
<ngt-instanced-mesh *args="[undefined, undefined, 100]" castShadow>
13+
<ngt-sphere-geometry *args="[1]" />
1614
<ngt-mesh-physical-material [roughness]="0.5" [metalness]="0.5" color="green" />
1715
</ngt-instanced-mesh>
1816
</ngt-object3D>
@@ -57,5 +55,4 @@ export default class AttractorsExample {
5755
key: index,
5856
position: [Math.floor(Math.random() * 30), Math.random() * 30 * 0.5, 0] as NgtVector3,
5957
}));
60-
protected ballGeometry = new THREE.SphereGeometry(1);
6158
}

apps/examples/src/app/rapier/car/car.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import {
77
inject,
88
input,
99
} from '@angular/core';
10-
import { injectBeforeRender, NgtVector3 } from 'angular-three';
10+
import { injectBeforeRender, NgtArgs, NgtVector3 } from 'angular-three';
1111
import { injectRevoluteJoint, NgtrRigidBody } from 'angular-three-rapier';
12-
import * as THREE from 'three';
1312

1413
@Directive({ selector: '[rigidBody][wheel]' })
1514
export class WheelJoint {
@@ -50,9 +49,8 @@ export class WheelJoint {
5049
[options]="{ colliders: 'hull' }"
5150
[wheel]="body"
5251
>
53-
<ngt-mesh castShadow receiveShadow [rotation.x]="Math.PI / 2" [geometry]="cylinderGeometry">
54-
<!-- TODO: rigidBody does not work with *args-->
55-
<!-- <ngt-cylinder-geometry *args="[1, 1, 1, 32]" />-->
52+
<ngt-mesh castShadow receiveShadow [rotation.x]="Math.PI / 2">
53+
<ngt-cylinder-geometry *args="[1, 1, 1, 32]" />
5654
<ngt-mesh-standard-material color="grey" />
5755
</ngt-mesh>
5856
</ngt-object3D>
@@ -61,10 +59,9 @@ export class WheelJoint {
6159
`,
6260
changeDetection: ChangeDetectionStrategy.OnPush,
6361
schemas: [CUSTOM_ELEMENTS_SCHEMA],
64-
imports: [NgtrRigidBody, WheelJoint],
62+
imports: [NgtrRigidBody, WheelJoint, NgtArgs],
6563
})
6664
export default class CarExample {
67-
protected cylinderGeometry = new THREE.CylinderGeometry(1, 1, 1, 32);
6865
protected wheelPositions: NgtVector3[] = [
6966
[-3, 0, 2],
7067
[-3, 0, -2],

apps/examples/src/app/rapier/contact-force-events/contact-force-events.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, output, signal, viewChild } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
CUSTOM_ELEMENTS_SCHEMA,
5+
DestroyRef,
6+
inject,
7+
output,
8+
signal,
9+
viewChild,
10+
} from '@angular/core';
11+
import { NgtArgs } from 'angular-three';
212
import { NgtrContactForcePayload, NgtrRigidBody } from 'angular-three-rapier';
313
import * as THREE from 'three';
414

@@ -55,21 +65,18 @@ export class Ball {
5565
selector: 'app-floor',
5666
template: `
5767
<ngt-object3D rigidBody="fixed" [options]="{ colliders: 'cuboid' }">
58-
<ngt-mesh [geometry]="boxGeometry">
59-
<!-- TODO: rigidBody does not work with *args
60-
<ngt-box-geometry *args="[10, 1, 10]" />
61-
-->
68+
<ngt-mesh>
69+
<ngt-box-geometry *args="[10, 1, 10]" />
6270
<ngt-mesh-physical-material [color]="floorColor()" />
6371
</ngt-mesh>
6472
</ngt-object3D>
6573
`,
66-
imports: [NgtrRigidBody],
74+
imports: [NgtrRigidBody, NgtArgs],
6775
changeDetection: ChangeDetectionStrategy.OnPush,
6876
schemas: [CUSTOM_ELEMENTS_SCHEMA],
6977
})
7078
export class Floor {
7179
protected readonly floorColor = floorColor;
72-
protected boxGeometry = new THREE.BoxGeometry(10, 1, 10);
7380
}
7481

7582
@Component({
@@ -85,7 +92,11 @@ export class Floor {
8592
schemas: [CUSTOM_ELEMENTS_SCHEMA],
8693
})
8794
export default class ContactForceEventsExample {
88-
protected readonly floorColor = floorColor;
95+
constructor() {
96+
inject(DestroyRef).onDestroy(() => {
97+
floorColor.set(startColor.clone().getHex());
98+
});
99+
}
89100

90101
protected onContactForce(totalForceMagnitude: number) {
91102
const color = startColor.clone().multiplyScalar(1 - totalForceMagnitude / startForce);

apps/examples/src/app/rapier/kinematics/kinematics.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, viewChild } from '@angular/core';
2-
import { injectBeforeRender } from 'angular-three';
2+
import { injectBeforeRender, NgtArgs } from 'angular-three';
33
import { NgtrRigidBody } from 'angular-three-rapier';
44
import * as THREE from 'three';
55

@@ -60,21 +60,18 @@ export class Ball {
6060
[options]="{ colliders: 'cuboid' }"
6161
[position]="[0, -8, 0]"
6262
>
63-
<ngt-mesh castShadow receiveShadow [geometry]="boxGeometry">
64-
<!-- TODO: rigidBody does not work with *args-->
65-
<!-- <ngt-box-geometry *args="[40, 1, 40]" />-->
63+
<ngt-mesh castShadow receiveShadow>
64+
<ngt-box-geometry *args="[40, 1, 40]" />
6665
<ngt-mesh-physical-material />
6766
</ngt-mesh>
6867
</ngt-object3D>
6968
</ngt-group>
7069
`,
7170
changeDetection: ChangeDetectionStrategy.OnPush,
7271
schemas: [CUSTOM_ELEMENTS_SCHEMA],
73-
imports: [Ball, NgtrRigidBody],
72+
imports: [Ball, NgtrRigidBody, NgtArgs],
7473
})
7574
export default class KinematicsExample {
76-
protected boxGeometry = new THREE.BoxGeometry(40, 1, 40);
77-
7875
private torusRef = viewChild.required('torus', { read: NgtrRigidBody });
7976
private platformRef = viewChild.required('platform', { read: NgtrRigidBody });
8077

0 commit comments

Comments
 (0)