Skip to content

Commit c8b868d

Browse files
committed
chore(core): testing new renderer
1 parent c7bec7e commit c8b868d

File tree

20 files changed

+204
-171
lines changed

20 files changed

+204
-171
lines changed

apps/kitchen-sink-new/src/app/app.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ApplicationConfig, provideExperimentalZonelessChangeDetection } from '@angular/core';
22
import { provideRouter, withComponentInputBinding } from '@angular/router';
3-
import { provideNgtRenderer } from 'angular-three';
3+
import { provideNgtRenderer } from 'angular-three/dom';
44
import { appRoutes } from './app.routes';
55

66
export const appConfig: ApplicationConfig = {

apps/kitchen-sink-new/src/app/app.routes.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export const appRoutes: Route[] = [
3131
loadChildren: () => import('./misc/misc.routes'),
3232
title: 'Misc - Angular Three Demo',
3333
},
34-
// {
35-
// path: 'routed',
36-
// loadComponent: () => import('./routed/routed'),
37-
// loadChildren: () => import('./routed/routed.routes'),
38-
// title: 'Routed - Angular Three Demo',
39-
// },
34+
{
35+
path: 'routed',
36+
loadComponent: () => import('./routed/routed'),
37+
loadChildren: () => import('./routed/routed.routes'),
38+
title: 'Routed - Angular Three Demo',
39+
},
4040
// {
4141
// path: 'routed-rocks',
4242
// loadComponent: () => import('./routed-rocks/routed-rocks'),

apps/kitchen-sink-new/src/app/misc/basic/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChangeDetectionStrategy, Component } from '@angular/core';
2-
import { NgtCanvasDeclarations } from 'angular-three';
2+
import { NgtCanvasDeclarations } from 'angular-three/dom';
33
import { Scene } from './scene';
44

55
@Component({
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, viewChild } from '@angular/core';
2+
import { injectBeforeRender } from 'angular-three';
3+
import * as THREE from 'three';
4+
5+
@Component({
6+
template: `
7+
<ngt-mesh #mesh>
8+
<ngt-box-geometry />
9+
<ngt-mesh-basic-material color="blue" />
10+
</ngt-mesh>
11+
`,
12+
changeDetection: ChangeDetectionStrategy.OnPush,
13+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
14+
})
15+
export default class BlueScene {
16+
private meshRef = viewChild.required<ElementRef<THREE.Mesh>>('mesh');
17+
18+
constructor() {
19+
injectBeforeRender(() => {
20+
const mesh = this.meshRef().nativeElement;
21+
mesh.rotation.x += 0.01;
22+
mesh.rotation.y += 0.01;
23+
});
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, viewChild } from '@angular/core';
2+
import { injectBeforeRender } from 'angular-three';
3+
import * as THREE from 'three';
4+
5+
@Component({
6+
template: `
7+
<ngt-mesh #mesh>
8+
<ngt-box-geometry />
9+
<ngt-mesh-basic-material color="red" />
10+
</ngt-mesh>
11+
`,
12+
changeDetection: ChangeDetectionStrategy.OnPush,
13+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
14+
})
15+
export default class RedScene {
16+
private meshRef = viewChild.required<ElementRef<THREE.Mesh>>('mesh');
17+
18+
constructor() {
19+
injectBeforeRender(() => {
20+
const mesh = this.meshRef().nativeElement;
21+
mesh.rotation.x += 0.01;
22+
mesh.rotation.y += 0.01;
23+
});
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Routes } from '@angular/router';
2+
3+
const routes: Routes = [
4+
{
5+
path: 'red',
6+
loadComponent: () => import('./red'),
7+
},
8+
{
9+
path: 'blue',
10+
loadComponent: () => import('./blue'),
11+
},
12+
{
13+
path: '',
14+
redirectTo: 'red',
15+
pathMatch: 'full',
16+
},
17+
];
18+
19+
export default routes;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { RouterLink, RouterLinkActive } from '@angular/router';
3+
import { extend, NgtRoutedScene } from 'angular-three';
4+
import { NgtCanvasDeclarations } from 'angular-three/dom';
5+
import * as THREE from 'three';
6+
7+
extend(THREE);
8+
9+
@Component({
10+
template: `
11+
<div class="h-svh">
12+
<ngt-canvas>
13+
<ngt-routed-scene *canvasContent />
14+
</ngt-canvas>
15+
</div>
16+
17+
<ul class="absolute bottom-0 left-0 flex items-center gap-2">
18+
<li>
19+
<a
20+
routerLink="red"
21+
class="underline"
22+
routerLinkActive="text-blue-500"
23+
[routerLinkActiveOptions]="{ exact: true }"
24+
>
25+
red
26+
</a>
27+
</li>
28+
<li>
29+
<a
30+
routerLink="blue"
31+
class="underline"
32+
routerLinkActive="text-blue-500"
33+
[routerLinkActiveOptions]="{ exact: true }"
34+
>
35+
blue
36+
</a>
37+
</li>
38+
</ul>
39+
`,
40+
imports: [NgtRoutedScene, RouterLink, RouterLinkActive, NgtCanvasDeclarations],
41+
changeDetection: ChangeDetectionStrategy.OnPush,
42+
host: { class: 'routed' },
43+
})
44+
export default class Routed {}

libs/core/dom/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# angular-three/dom
2+
3+
Secondary entry point of `angular-three`. It can be used by importing from `angular-three/dom`.

libs/core/dom/ng-package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"lib": {
3+
"entryFile": "src/index.ts"
4+
}
5+
}

libs/core/dom/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './lib/canvas';
2+
export * from './lib/renderer';

libs/core/src/lib/canvas.ts renamed to libs/core/dom/src/lib/canvas.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ import {
2222
ViewContainerRef,
2323
} from '@angular/core';
2424
import { outputFromObservable } from '@angular/core/rxjs-interop';
25-
import { NgxResize, provideResizeOptions, ResizeOptions, ResizeResult } from 'ngxtension/resize';
26-
import * as THREE from 'three';
27-
import { createPointerEvents } from './dom/events';
28-
import { CANVAS_CONTENT_FLAG } from './renderer/constants';
29-
import { injectCanvasRootInitializer, NgtCanvasConfigurator } from './roots';
30-
import { injectStore, provideStore } from './store';
31-
import type { NgtVector3 } from './three-types';
32-
import type {
25+
import {
26+
CANVAS_CONTENT_FLAG,
27+
injectCanvasRootInitializer,
28+
injectStore,
29+
is,
3330
NgtCamera,
3431
NgtCameraParameters,
32+
NgtCanvasConfigurator,
3533
NgtDomEvent,
3634
NgtDpr,
3735
NgtEventPrefix,
@@ -41,8 +39,12 @@ import type {
4139
NgtShadows,
4240
NgtSize,
4341
NgtState,
44-
} from './types';
45-
import { is } from './utils/is';
42+
NgtVector3,
43+
provideStore,
44+
} from 'angular-three';
45+
import { NgxResize, provideResizeOptions, ResizeOptions, ResizeResult } from 'ngxtension/resize';
46+
import * as THREE from 'three';
47+
import { createPointerEvents } from './events';
4648

4749
@Directive({ selector: 'ng-template[canvasContent]' })
4850
export class NgtCanvasContent {

libs/core/src/lib/dom/events.ts renamed to libs/core/dom/src/lib/events.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { createEvents } from '../events';
2-
import type { NgtAnyRecord, NgtDomEvent, NgtEventManager, NgtEvents, NgtState } from '../types';
3-
import { SignalState } from '../utils/signal-state';
1+
import {
2+
createEvents,
3+
NgtAnyRecord,
4+
NgtDomEvent,
5+
NgtEventManager,
6+
NgtEvents,
7+
NgtState,
8+
SignalState,
9+
} from 'angular-three';
410

511
const DOM_EVENTS = {
612
click: false,

libs/core/dom/src/lib/renderer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { makeEnvironmentProviders, RendererFactory2 } from '@angular/core';
2+
import { ɵDomRendererFactory2 as DomRendererFactory2 } from '@angular/platform-browser';
3+
import { NgtRendererFactory2 } from 'angular-three';
4+
5+
export function provideNgtRenderer() {
6+
return makeEnvironmentProviders([
7+
{
8+
provide: RendererFactory2,
9+
useFactory: (domRendererFactory: RendererFactory2) => new NgtRendererFactory2(domRendererFactory),
10+
deps: [DomRendererFactory2],
11+
},
12+
]);
13+
}

libs/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './lib/canvas';
21
export * from './lib/directives/args';
32
export * from './lib/directives/parent';
43
export * from './lib/directives/selection';
@@ -9,7 +8,9 @@ export * from './lib/loop';
98
export * from './lib/pipes/hexify';
109
export * from './lib/portal';
1110
// export * from './lib/renderer-old';
11+
export * from './lib/events';
1212
export * from './lib/renderer/catalogue';
13+
export * from './lib/renderer/constants';
1314
export * from './lib/renderer/renderer';
1415
export * from './lib/roots';
1516
export * from './lib/routed-scene';

libs/core/src/lib/directives/args.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export class NgtArgs {
4545
});
4646

4747
inject(DestroyRef).onDestroy(() => {
48-
console.log('destroy args');
4948
this.view?.destroy();
5049
});
5150
}

libs/core/src/lib/renderer/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export const NGT_RENDERER_NODE_FLAG = '__ngt_renderer__';
22
export const CANVAS_CONTENT_FLAG = '__ngt_renderer_canvas_content_flag__';
33
export const SPECIAL_INTERNAL_ADD_COMMENT_FLAG = '__ngt_renderer_add_comment__';
44
export const SPECIAL_INTERNAL_SET_PARENT_COMMENT_FLAG = '__ngt_renderer_set_parent_comment__';
5+
export const NGT_MANUAL_INJECTED_STORE = '__ngt_manual_injected_store__';
56

67
export const THREE_NATIVE_EVENTS = ['added', 'removed', 'childadded', 'childremoved', 'disposed'];

0 commit comments

Comments
 (0)