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

Commit

Permalink
feat(soba): adjust Billboard
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Apr 16, 2022
1 parent 5ce0ff0 commit 190c8c4
Showing 1 changed file with 44 additions and 21 deletions.
65 changes: 44 additions & 21 deletions libs/soba/abstractions/src/lib/billboard/billboard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {
BooleanInput,
coerceBooleanProperty,
NgtObjectInputs,
NgtRef,
NgtRenderState,
provideInstanceWrapperFactory,
provideObjectWrapperFactory,
Ref,
provideObjectHosRef,
} from '@angular-three/core';
import { NgtGroup, NgtGroupModule } from '@angular-three/core/group';
import { CommonModule } from '@angular/common';
Expand All @@ -26,13 +27,13 @@ import * as THREE from 'three';
})
export class NgtSobaBillboardContent {
constructor(
public templateRef: TemplateRef<{ billboard: Ref<THREE.Group> }>
public templateRef: TemplateRef<{ billboard: NgtRef<THREE.Group> }>
) {}

static ngTemplateContextGuard(
dir: NgtSobaBillboardContent,
ctx: any
): ctx is { billboard: Ref<THREE.Group> } {
): ctx is { billboard: NgtRef<THREE.Group> } {
return true;
}
}
Expand Down Expand Up @@ -82,23 +83,45 @@ export class NgtSobaBillboardContent {
`,
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
provideInstanceWrapperFactory(
provideObjectHosRef(
NgtSobaBillboard,
(billboard) => billboard.group.instance.value,
(billboard) => billboard.parentInstanceFactory
),
provideObjectWrapperFactory(
NgtSobaBillboard,
(billboard) => billboard.group.instance.value,
(billboard) => billboard.parentObjectFactory
(billboard) => billboard.group.instance,
(billboard) => billboard.parentRef
),
],
})
export class NgtSobaBillboard extends NgtObjectInputs<THREE.Group> {
@Input() follow = true;
@Input() lockX = false;
@Input() lockY = false;
@Input() lockZ = false;
get follow(): boolean {
return this._follow;
}
@Input() set follow(value: BooleanInput) {
this._follow = coerceBooleanProperty(value);
}
private _follow = true;

get lockX(): boolean {
return this._lockX;
}
@Input() set lockX(value: BooleanInput) {
this._lockX = coerceBooleanProperty(value);
}
private _lockX = false;

get lockY(): boolean {
return this._lockY;
}
@Input() set lockY(value: BooleanInput) {
this._lockY = coerceBooleanProperty(value);
}
private _lockY = false;

get lockZ(): boolean {
return this._lockZ;
}
@Input() set lockZ(value: BooleanInput) {
this._lockZ = coerceBooleanProperty(value);
}
private _lockZ = false;

@ContentChild(NgtSobaBillboardContent) content?: NgtSobaBillboardContent;

Expand All @@ -116,7 +139,7 @@ export class NgtSobaBillboard extends NgtObjectInputs<THREE.Group> {
state: NgtRenderState;
object: THREE.Group;
}) {
if (!this.follow) return;
if (!this._follow) return;

// save previous rotation in case we're locking an axis
const prevRotation = object.rotation.clone();
Expand All @@ -125,9 +148,9 @@ export class NgtSobaBillboard extends NgtObjectInputs<THREE.Group> {
object.quaternion.copy(camera.quaternion);

// readjust any axis that is locked
if (this.lockX) object.rotation.x = prevRotation.x;
if (this.lockY) object.rotation.y = prevRotation.y;
if (this.lockZ) object.rotation.z = prevRotation.z;
if (this._lockX) object.rotation.x = prevRotation.x;
if (this._lockY) object.rotation.y = prevRotation.y;
if (this._lockZ) object.rotation.z = prevRotation.z;
}
}

Expand Down

0 comments on commit 190c8c4

Please sign in to comment.