|
| 1 | +import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; |
| 2 | +import { injectGLTF } from 'angular-three-soba/loaders'; |
| 3 | +import { injectSuzanne } from '../suzanne'; |
| 4 | + |
| 5 | +import { |
| 6 | + NgtrBallCollider, |
| 7 | + NgtrConeCollider, |
| 8 | + NgtrConvexHullCollider, |
| 9 | + NgtrCuboidCollider, |
| 10 | + NgtrRigidBody, |
| 11 | + NgtrTrimeshCollider, |
| 12 | +} from 'angular-three-rapier'; |
| 13 | +import { NgtsHTML } from 'angular-three-soba/misc'; |
| 14 | +import { ResetOrbitControls } from '../reset-orbit-controls'; |
| 15 | +import offsetTorusGLB from './offset-torus.glb' with { loader: 'file' }; |
| 16 | + |
| 17 | +injectGLTF.preload(() => offsetTorusGLB); |
| 18 | + |
| 19 | +@Component({ |
| 20 | + selector: 'app-offset-torus', |
| 21 | + template: ` |
| 22 | + @if (gltf(); as gltf) { |
| 23 | + <ngt-mesh |
| 24 | + castShadow |
| 25 | + [geometry]="gltf.meshes['Torus'].geometry" |
| 26 | + [material]="gltf.meshes['Torus'].material" |
| 27 | + /> |
| 28 | + } |
| 29 | + `, |
| 30 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 31 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 32 | +}) |
| 33 | +export class OffsetTorus { |
| 34 | + protected gltf = injectGLTF(() => offsetTorusGLB); |
| 35 | +} |
| 36 | + |
| 37 | +@Component({ |
| 38 | + selector: 'app-suzanne', |
| 39 | + template: ` |
| 40 | + @if (gltf(); as gltf) { |
| 41 | + <ngt-mesh castShadow [geometry]="gltf.nodes.Suzanne.geometry" [material]="gltf.nodes.Suzanne.material" /> |
| 42 | + } |
| 43 | + `, |
| 44 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 45 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 46 | +}) |
| 47 | +export class Suzanne { |
| 48 | + protected gltf = injectSuzanne(); |
| 49 | +} |
| 50 | + |
| 51 | +@Component({ |
| 52 | + selector: 'app-all-shapes-rapier-example', |
| 53 | + template: ` |
| 54 | + <ngt-group> |
| 55 | + <ngt-object3D rigidBody [options]="{ colliders: 'cuboid' }"> |
| 56 | + <app-suzanne /> |
| 57 | + <ngts-html> |
| 58 | + <div htmlContent>Auto Cuboid</div> |
| 59 | + </ngts-html> |
| 60 | + </ngt-object3D> |
| 61 | +
|
| 62 | + <ngt-object3D rigidBody [position]="[4, 0, 0]" [options]="{ colliders: 'ball' }"> |
| 63 | + <app-suzanne /> |
| 64 | + <ngts-html> |
| 65 | + <div htmlContent>Auto Ball</div> |
| 66 | + </ngts-html> |
| 67 | + </ngt-object3D> |
| 68 | +
|
| 69 | + <ngt-object3D rigidBody [position]="[8, 0, 0]" [options]="{ colliders: 'hull' }"> |
| 70 | + <app-suzanne /> |
| 71 | + <ngts-html> |
| 72 | + <div htmlContent>Auto Hull</div> |
| 73 | + </ngts-html> |
| 74 | + </ngt-object3D> |
| 75 | +
|
| 76 | + <ngt-object3D rigidBody [position]="[12, 0, 0]" [options]="{ colliders: 'trimesh' }"> |
| 77 | + <app-suzanne /> |
| 78 | + <ngts-html> |
| 79 | + <div htmlContent>Auto Trimesh</div> |
| 80 | + </ngts-html> |
| 81 | + </ngt-object3D> |
| 82 | +
|
| 83 | + <ngt-object3D rigidBody [position]="[0, 4, 0]" [options]="{ colliders: false }"> |
| 84 | + <app-suzanne /> |
| 85 | + <ngt-object3D [cuboidCollider]="[1, 1, 1]" /> |
| 86 | + <ngts-html> |
| 87 | + <div htmlContent>Custom Cuboid</div> |
| 88 | + </ngts-html> |
| 89 | + </ngt-object3D> |
| 90 | +
|
| 91 | + <ngt-object3D rigidBody [position]="[4.1, 4, 0]" [options]="{ colliders: false }"> |
| 92 | + <app-suzanne /> |
| 93 | + <ngt-object3D [ballCollider]="[1]" /> |
| 94 | + <ngts-html> |
| 95 | + <div htmlContent>Custom Ball</div> |
| 96 | + </ngts-html> |
| 97 | + </ngt-object3D> |
| 98 | +
|
| 99 | + <ngt-object3D rigidBody [position]="[8, 4, 0]" [options]="{ colliders: false }"> |
| 100 | + <app-suzanne /> |
| 101 | + <ngt-object3D [coneCollider]="[1, 1]" /> |
| 102 | + <ngts-html> |
| 103 | + <div htmlContent>Custom Cone</div> |
| 104 | + </ngts-html> |
| 105 | + </ngt-object3D> |
| 106 | +
|
| 107 | + @if (gltf(); as gltf) { |
| 108 | + @let geometry = gltf.nodes.Suzanne.geometry; |
| 109 | +
|
| 110 | + <ngt-object3D rigidBody [position]="[5, 8, 0]" [options]="{ colliders: false }"> |
| 111 | + <app-suzanne /> |
| 112 | + <ngt-object3D |
| 113 | + [trimeshCollider]="[geometry.attributes['position'].array, geometry.index?.array || []]" |
| 114 | + [options]="{ mass: 1 }" |
| 115 | + /> |
| 116 | + <ngts-html> |
| 117 | + <div htmlContent>Custom Trimesh</div> |
| 118 | + </ngts-html> |
| 119 | + </ngt-object3D> |
| 120 | +
|
| 121 | + <ngt-object3D rigidBody [position]="[0, 8, 0]" [options]="{ colliders: false }"> |
| 122 | + <app-suzanne /> |
| 123 | + <ngt-object3D [convexHullCollider]="[geometry.attributes['position'].array]" /> |
| 124 | + <ngts-html> |
| 125 | + <div htmlContent>Custom Convex Hull</div> |
| 126 | + </ngts-html> |
| 127 | + </ngt-object3D> |
| 128 | + } |
| 129 | +
|
| 130 | + <ngt-object3D rigidBody [position]="[8, 8, 0]" [options]="{ colliders: false }"> |
| 131 | + <app-suzanne /> |
| 132 | + <ngt-object3D [cuboidCollider]="[0.5, 0.5, 0.5]" [position]="[1, 1, 1]" /> |
| 133 | + <ngt-object3D [ballCollider]="[0.5]" [position]="[-1, -1, 1]" /> |
| 134 | + <ngts-html> |
| 135 | + <div htmlContent>Custom Combound shape</div> |
| 136 | + </ngts-html> |
| 137 | + </ngt-object3D> |
| 138 | +
|
| 139 | + <ngt-object3D rigidBody [position]="[4, 10, 0]" [options]="{ colliders: 'ball' }"> |
| 140 | + <app-suzanne /> |
| 141 | + <ngt-object3D [cuboidCollider]="[0.5, 0.5, 0.5]" [position]="[1, 1, 1]" /> |
| 142 | + <ngt-object3D [ballCollider]="[0.5]" [position]="[-1, -1, 1]" /> |
| 143 | + <ngts-html> |
| 144 | + <div htmlContent>Auto and Custom Combound shape</div> |
| 145 | + </ngts-html> |
| 146 | + </ngt-object3D> |
| 147 | +
|
| 148 | + <ngt-group [scale]="1.5" [position]="[5, 10, 0]"> |
| 149 | + <ngt-object3D rigidBody [options]="{ colliders: 'ball' }"> |
| 150 | + <ngt-group [position]="-2" [scale]="1.2"> |
| 151 | + <app-offset-torus /> |
| 152 | + </ngt-group> |
| 153 | + <ngts-html> |
| 154 | + <div htmlContent>Mesh with offset geometry</div> |
| 155 | + </ngts-html> |
| 156 | + </ngt-object3D> |
| 157 | + </ngt-group> |
| 158 | + </ngt-group> |
| 159 | + `, |
| 160 | + hostDirectives: [ResetOrbitControls], |
| 161 | + schemas: [CUSTOM_ELEMENTS_SCHEMA], |
| 162 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 163 | + imports: [ |
| 164 | + NgtrRigidBody, |
| 165 | + Suzanne, |
| 166 | + NgtsHTML, |
| 167 | + NgtrCuboidCollider, |
| 168 | + NgtrBallCollider, |
| 169 | + NgtrConeCollider, |
| 170 | + NgtrTrimeshCollider, |
| 171 | + NgtrConvexHullCollider, |
| 172 | + OffsetTorus, |
| 173 | + ], |
| 174 | +}) |
| 175 | +export default class AllShapesExample { |
| 176 | + protected gltf = injectSuzanne(); |
| 177 | +} |
0 commit comments