This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(demo): adjust level of details demo
- Loading branch information
Showing
5 changed files
with
331 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
packages/demo/src/app/level-of-details/level-of-details.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { NgtCoreModule, NgtRepeatModule } from '@angular-three/core'; | ||
import { NgtIcosahedronGeometryModule } from '@angular-three/core/geometries'; | ||
import { | ||
NgtDirectionalLightModule, | ||
NgtPointLightModule, | ||
} from '@angular-three/core/lights'; | ||
import { NgtMeshLambertMaterialModule } from '@angular-three/core/materials'; | ||
import { NgtMeshModule } from '@angular-three/core/meshes'; | ||
import { NgtStatsModule } from '@angular-three/core/stats'; | ||
import { | ||
NgtSobaFlyControls, | ||
NgtSobaFlyControlsModule, | ||
} from '@angular-three/soba/controls'; | ||
import { NgtSobaDetailedModule } from '@angular-three/soba/performances'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
NgModule, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import * as THREE from 'three'; | ||
|
||
@Component({ | ||
selector: 'ngt-level-of-details', | ||
template: ` | ||
<ngt-canvas | ||
[linear]="true" | ||
[camera]="{ fov: 45, near: 1, far: 15000, position: [0, 0, 1000] }" | ||
[scene]="{ fog }" | ||
(created)=" | ||
$event.camera.updateProjectionMatrix(); | ||
$event.renderer.setClearColor('black') | ||
" | ||
> | ||
<ngt-point-light [position]="[0, 0, 0]" color="#ff2200"></ngt-point-light> | ||
<ngt-directional-light | ||
[position]="[0, 0, 1]" | ||
color="#ffffff" | ||
></ngt-directional-light> | ||
<ngt-stats></ngt-stats> | ||
<ngt-mesh-lambert-material | ||
#lambertMaterial="ngtMeshLambertMaterial" | ||
[parameters]="{ color: '#ffffff', wireframe: true }" | ||
></ngt-mesh-lambert-material> | ||
<ngt-icosahedron-geometry | ||
#geometry16="ngtIcosahedronGeometry" | ||
[args]="[100, 16]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry8="ngtIcosahedronGeometry" | ||
[args]="[100, 8]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry4="ngtIcosahedronGeometry" | ||
[args]="[100, 4]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry2="ngtIcosahedronGeometry" | ||
[args]="[100, 2]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry1="ngtIcosahedronGeometry" | ||
[args]="[100, 1]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-soba-detailed | ||
#lod="ngtSobaDetailed" | ||
*repeat="let _ of 1000" | ||
[position]="[ | ||
10000 * (0.5 - (1 | mathConst: 'random')), | ||
7500 * (0.5 - (1 | mathConst: 'random')), | ||
10000 * (0.5 - (1 | mathConst: 'random')) | ||
]" | ||
[distances]="[50, 300, 1000, 2000, 8000]" | ||
> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry16.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry8.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry4.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry2.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry1.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
</ngt-soba-detailed> | ||
<ngt-soba-fly-controls></ngt-soba-fly-controls> | ||
</ngt-canvas> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class LevelOfDetailsComponent { | ||
fog = new THREE.Fog('#000000', 1, 15000); | ||
|
||
@ViewChild(NgtSobaFlyControls, { static: true }) | ||
flyControls!: NgtSobaFlyControls; | ||
|
||
ngAfterViewInit() { | ||
this.flyControls.controls.movementSpeed = 1000; | ||
this.flyControls.controls.rollSpeed = Math.PI / 10; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [LevelOfDetailsComponent], | ||
exports: [LevelOfDetailsComponent], | ||
imports: [ | ||
NgtCoreModule, | ||
NgtStatsModule, | ||
NgtSobaFlyControlsModule, | ||
NgtPointLightModule, | ||
NgtDirectionalLightModule, | ||
NgtSobaDetailedModule, | ||
NgtRepeatModule, | ||
NgtMeshModule, | ||
NgtIcosahedronGeometryModule, | ||
NgtMeshLambertMaterialModule, | ||
], | ||
}) | ||
export class LevelOfDetailsModule {} |
156 changes: 156 additions & 0 deletions
156
packages/demo/src/app/level-of-details/level-of-details.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
This example shows the performance aspect of the LOD feature. This is ported from the original [THREE.js LOD example](https://threejs.org/examples/#webgl_lod) | ||
|
||
The code for this example is straightforward. There is only one strange place which is `<ngt-mesh [disabled]="true"></ngt-mesh>`. `ngt-mesh` is not the same as a mere `THREE.Mesh`, there are a bunch of other things going on to ensure all the props of a Mesh gets passed over in a declarative manner. However, in the case of LOD, Mesh becomes a special case where they're not on the scene as themselves but as LOD's levels. With this in mind, we do not need the extra functionality of `ngt-mesh` and therefore can `[disabled]` the controller underneath of `ngt-mesh`. | ||
|
||
Note that there will be no Events handled when `disabled` is true. | ||
|
||
```ts | ||
import { NgtCoreModule, NgtRepeatModule } from '@angular-three/core'; | ||
import { NgtIcosahedronGeometryModule } from '@angular-three/core/geometries'; | ||
import { | ||
NgtDirectionalLightModule, | ||
NgtPointLightModule, | ||
} from '@angular-three/core/lights'; | ||
import { NgtMeshLambertMaterialModule } from '@angular-three/core/materials'; | ||
import { NgtMeshModule } from '@angular-three/core/meshes'; | ||
import { NgtStatsModule } from '@angular-three/core/stats'; | ||
import { | ||
NgtSobaFlyControls, | ||
NgtSobaFlyControlsModule, | ||
} from '@angular-three/soba/controls'; | ||
import { NgtSobaDetailedModule } from '@angular-three/soba/performances'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
NgModule, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import * as THREE from 'three'; | ||
|
||
@Component({ | ||
selector: 'ngt-level-of-details', | ||
template: ` | ||
<ngt-canvas | ||
[linear]="true" | ||
[camera]="{ fov: 45, near: 1, far: 15000, position: [0, 0, 1000] }" | ||
[scene]="{ fog }" | ||
(created)=" | ||
$event.camera.updateProjectionMatrix(); | ||
$event.renderer.setClearColor('black') | ||
" | ||
> | ||
<ngt-point-light [position]="[0, 0, 0]" color="#ff2200"></ngt-point-light> | ||
<ngt-directional-light | ||
[position]="[0, 0, 1]" | ||
color="#ffffff" | ||
></ngt-directional-light> | ||
<ngt-stats></ngt-stats> | ||
<ngt-mesh-lambert-material | ||
#lambertMaterial="ngtMeshLambertMaterial" | ||
[parameters]="{ color: '#ffffff', wireframe: true }" | ||
></ngt-mesh-lambert-material> | ||
<ngt-icosahedron-geometry | ||
#geometry16="ngtIcosahedronGeometry" | ||
[args]="[100, 16]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry8="ngtIcosahedronGeometry" | ||
[args]="[100, 8]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry4="ngtIcosahedronGeometry" | ||
[args]="[100, 4]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry2="ngtIcosahedronGeometry" | ||
[args]="[100, 2]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-icosahedron-geometry | ||
#geometry1="ngtIcosahedronGeometry" | ||
[args]="[100, 1]" | ||
></ngt-icosahedron-geometry> | ||
<ngt-soba-detailed | ||
#lod="ngtSobaDetailed" | ||
*repeat="let _ of 1000" | ||
[position]="[ | ||
10000 * (0.5 - (1 | mathConst: 'random')), | ||
7500 * (0.5 - (1 | mathConst: 'random')), | ||
10000 * (0.5 - (1 | mathConst: 'random')) | ||
]" | ||
[distances]="[50, 300, 1000, 2000, 8000]" | ||
> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry16.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry8.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry4.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry2.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
<ngt-mesh | ||
#ngtMesh="ngtMesh" | ||
[disabled]="true" | ||
[geometry]="geometry1.geometry" | ||
[material]="lambertMaterial.material" | ||
[scale]="[1.5, 1.5, 1.5]" | ||
></ngt-mesh> | ||
</ngt-soba-detailed> | ||
<ngt-soba-fly-controls></ngt-soba-fly-controls> | ||
</ngt-canvas> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class LevelOfDetailsComponent { | ||
fog = new THREE.Fog('#000000', 1, 15000); | ||
|
||
@ViewChild(NgtSobaFlyControls, { static: true }) | ||
flyControls!: NgtSobaFlyControls; | ||
|
||
ngAfterViewInit() { | ||
this.flyControls.controls.movementSpeed = 1000; | ||
this.flyControls.controls.rollSpeed = Math.PI / 10; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [LevelOfDetailsComponent], | ||
exports: [LevelOfDetailsComponent], | ||
imports: [ | ||
NgtCoreModule, | ||
NgtStatsModule, | ||
NgtSobaFlyControlsModule, | ||
NgtPointLightModule, | ||
NgtDirectionalLightModule, | ||
NgtSobaDetailedModule, | ||
NgtRepeatModule, | ||
NgtMeshModule, | ||
NgtIcosahedronGeometryModule, | ||
NgtMeshLambertMaterialModule, | ||
], | ||
}) | ||
export class LevelOfDetailsModule {} | ||
``` |
23 changes: 23 additions & 0 deletions
23
packages/demo/src/app/level-of-details/level-of-details.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Meta, moduleMetadata } from '@storybook/angular'; | ||
import { LevelOfDetailsModule } from './level-of-details.component'; | ||
// @ts-ignore | ||
import levelOfDetailsDocs from './level-of-details.mdx'; | ||
|
||
export default { | ||
title: 'Examples/Level of Details', | ||
decorators: [ | ||
moduleMetadata({ | ||
imports: [LevelOfDetailsModule], | ||
}), | ||
], | ||
parameters: { | ||
docs: { page: levelOfDetailsDocs }, | ||
viewMode: 'story', | ||
}, | ||
} as Meta; | ||
|
||
export const Default = () => ({ | ||
template: ` | ||
<ngt-level-of-details></ngt-level-of-details> | ||
`, | ||
}); |