Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
fix(core): make ContentGeometry static. Geometry needs to be statical…
Browse files Browse the repository at this point in the history
…ly available for the mesh
  • Loading branch information
nartc committed Dec 6, 2021
1 parent 523573b commit f7197d1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Controller, createControllerProviderFactory } from './controller';
exportAs: 'ngtContentGeometryController',
})
export class NgtContentGeometryController extends Controller {
@ContentChild(NgtGeometry)
@ContentChild(NgtGeometry, { static: true })
set geometryDirective(v: NgtGeometry) {
if (this.geometry == null && v) {
this.geometry = v.geometry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ import { Controller, createControllerProviderFactory } from './controller';
exportAs: 'ngtContentMaterialController',
})
export class NgtContentMaterialController extends Controller {
@ContentChildren(NgtMaterial, { descendants: true }) set materialDirectives(
v: QueryList<NgtMaterial>
) {
@ContentChildren(NgtMaterial, {
descendants: true,
emitDistinctChangesOnly: true,
})
set materialDirectives(v: QueryList<NgtMaterial>) {
if (this.material == null && v) {
this.material =
v.length === 1
Expand Down
19 changes: 15 additions & 4 deletions packages/core/src/lib/controllers/material-geometry.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import {
AfterContentInit,
Directive,
Inject,
InjectionToken,
Input,
NgModule,
NgZone,
OnInit,
} from '@angular/core';
import * as THREE from 'three';
import { AnyConstructor, AnyExtenderFunction, UnknownRecord } from '../models';
import { NGT_OBJECT_POST_INIT, NGT_OBJECT_TYPE } from '../tokens';
import {
NGT_CONTENT_GEOMETRY_CONTROLLER_PROVIDER,
NGT_CONTENT_GEOMETRY_WATCHED_CONTROLLER,
Expand All @@ -28,6 +27,16 @@ import {
NgtObject3dController,
} from './object-3d.controller';

export const NGT_OBJECT_TYPE = new InjectionToken('Object3d Type', {
providedIn: 'root',
factory: () => THREE.Object3D,
});

export const NGT_OBJECT_POST_INIT = new InjectionToken('Object3d PostInit', {
providedIn: 'root',
factory: () => undefined,
});

@Directive({
selector: `
ngt-mesh,
Expand All @@ -46,7 +55,7 @@ import {
})
export class NgtMaterialGeometryController
extends Controller
implements AfterContentInit, OnInit
implements AfterContentInit
{
#meshArgs: unknown[] = [];
set meshArgs(v: unknown | unknown[]) {
Expand Down Expand Up @@ -115,7 +124,9 @@ export class NgtMaterialGeometryController
}

ngAfterContentInit() {
this.objectController.init();
this.ngZone.runOutsideAngular(() => {
this.objectController.init();
});
}

get controller(): Controller | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Controller, createControllerProviderFactory } from './controller';
exportAs: 'ngtContentGeometryController',
})
export class NgtContentGeometryController extends Controller {
@ContentChild(NgtGeometry)
@ContentChild(NgtGeometry, { static: true })
set geometryDirective(v: NgtGeometry) {
if (this.geometry == null && v) {
this.geometry = v.geometry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { Controller, createControllerProviderFactory } from './controller';
exportAs: 'ngtContentMaterialController',
})
export class NgtContentMaterialController extends Controller {
@ContentChildren(NgtMaterial, { descendants: true }) set materialDirectives(
@ContentChildren(NgtMaterial, {
descendants: true,
emitDistinctChangesOnly: true,
}) set materialDirectives(
v: QueryList<NgtMaterial>
) {
if (this.material == null && v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import {
Input,
NgModule,
NgZone,
OnInit,
} from '@angular/core';
import * as THREE from 'three';
import { AnyConstructor, AnyExtenderFunction, UnknownRecord } from '../models';
import { NGT_OBJECT_POST_INIT, NGT_OBJECT_TYPE } from '../tokens';
import {
NGT_CONTENT_GEOMETRY_CONTROLLER_PROVIDER,
NGT_CONTENT_GEOMETRY_WATCHED_CONTROLLER,
Expand All @@ -28,6 +26,16 @@ import {
NgtObject3dController,
} from './object-3d.controller';

export const NGT_OBJECT_TYPE = new InjectionToken('Object3d Type', {
providedIn: 'root',
factory: () => THREE.Object3D,
});

export const NGT_OBJECT_POST_INIT = new InjectionToken('Object3d PostInit', {
providedIn: 'root',
factory: () => undefined,
});

@Directive({
selector: `<% for (const mesh of meshSelectors) { %>
ngt-<%= mesh %>,<% } %><% for (const line of lineSelectors) { %>
Expand All @@ -42,7 +50,7 @@ import {
})
export class NgtMaterialGeometryController
extends Controller
implements AfterContentInit, OnInit
implements AfterContentInit
{
#meshArgs: unknown[] = [];
set meshArgs(v: unknown | unknown[]) {
Expand Down Expand Up @@ -111,7 +119,9 @@ export class NgtMaterialGeometryController
}

ngAfterContentInit() {
this.objectController.init();
this.ngZone.runOutsideAngular(() => {
this.objectController.init();
});
}

get controller(): Controller | undefined {
Expand Down

0 comments on commit f7197d1

Please sign in to comment.