Skip to content

Angular-based Level of Detail (LOD) implementation#82

Open
ericleib wants to merge 5 commits intoangular-threejs:mainfrom
ericleib:dev/angular-lod
Open

Angular-based Level of Detail (LOD) implementation#82
ericleib wants to merge 5 commits intoangular-threejs:mainfrom
ericleib:dev/angular-lod

Conversation

@ericleib
Copy link
Contributor

Implements Level of Detail (LOD) rendering. Automatically switches between different detail levels of child objects based on camera distance.

Unlike NgtsDetailed, this is an implementation based on Angular and angular-three APIs rather than Three's LOD class.
The component adds and remove objects from the scene graph rather than hiding them with visible = false.
This solves a number of issues such as avoid raycasting over hidden objects.

Usage:

<ngt-group lod>
  <ngt-mesh *lodLevel="{distance: 0}" />
  <ngt-mesh *lodLevel="{distance: 100}" />
  <ngt-mesh *lodLevel="{distance: 1000}" />
</ngt-group>

The [lodLevel] directive (NgtsLODLevel) supports the following options:

Property Description Default Value
distance Threshold above which to display the object 0
hysteresis Prevents rapid switching near distance thresholds 0

This directive may also be used with the following syntax:

<ngt-group lod>
  <ng-template [lodLevel]="{distance: 0}">
    <ngt-mesh />
    <ngt-mesh />
  </ng-template>
</ngt-group>

@netlify
Copy link

netlify bot commented Mar 16, 2026

Deploy Preview for angularthreedemo ready!

Name Link
🔨 Latest commit 6037a2e
🔍 Latest deploy log https://app.netlify.com/projects/angularthreedemo/deploys/69b9163aa3678a0007556de8
😎 Deploy Preview https://deploy-preview-82--angularthreedemo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Mar 16, 2026

Deploy Preview for angularthreesoba ready!

Name Link
🔨 Latest commit 6037a2e
🔍 Latest deploy log https://app.netlify.com/projects/angularthreesoba/deploys/69b9163aa9094a000885bbdd
😎 Deploy Preview https://deploy-preview-82--angularthreesoba.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Component({
template: `
<ngt-group lod>
<ngt-mesh *lodLevel="{}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's make the input default value {} so we don't have to have this empty object {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, Angular doesn't let me write <ngt-mesh *lodLevel>.

Perhaps a lighter syntax could be <ngt-mesh *lodLevel="100" [hysteresis]="0.2"> ?

<ngt-mesh-basic-material color="hotpink" wireframe />
</ngt-mesh>

<ngt-mesh *lodLevel="{distance: 50}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: also let's add some event to one of these lod's level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean an output event on the LODLevel directive ?

eg. <ngt-mesh *lodLevel="{distance: 50}" (visibilityChange)="onVisibilityChange($event)"> ?

@Component({
selector: '[lod]',
template: `
<ng-container *ngTemplateOutlet="level()?.template" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: it's less known but you typically don't need *ngTemplateOutlet here, just [ngTemplateOutlet] would work

@nartc
Copy link
Member

nartc commented Mar 16, 2026

See this issue in the deploy preview

ReferenceError: Cannot access 'lod_stories' before initialization
    at Module.default (https://deploy-preview-82--angularthreesoba.netlify.app/src-performances-lod-stories.4693c114.iframe.bundle.js:1:374)
    at processCSFFile (https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:34890:18)
    at StoryStore.memoizerific [as processCSFFileWithCache] (https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:10105:196)
    at StoryStore.loadCSFFileByStoryId (https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:35642:17)
    at async StoryStore.loadStory (https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:35671:19)
    at async https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:35904:20
    at async StoryRender.runPhase (https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:35893:21)
    at async StoryRender.prepare (https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:35903:9)
    at async PreviewWeb.renderSelection (https://deploy-preview-82--angularthreesoba.netlify.app/sb-preview/runtime.js:36784:7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants