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

Commit

Permalink
feat(core): replace onCanvasReady with onReady
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jul 22, 2022
1 parent f174630 commit 2083c50
Show file tree
Hide file tree
Showing 62 changed files with 321 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class HeightFieldGeometryComponent extends NgtBufferGeometry {
override ngOnInit() {
super.ngOnInit();
this.zone.runOutsideAngular(() => {
this.onCanvasReady(this.store.ready$, () => {
this.store.onReady(() => {
this.effect(
tap(() => {
if (!this.instanceValue) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import { ChangeDetectionStrategy, Component, Injectable, Input, NgModule, NgZone
import { RouterModule } from '@angular/router';
import { BlendFunction, KernelSize, SSAOEffect } from 'postprocessing';
import { Observable } from 'rxjs';
import * as THREE from 'three';
// @ts-ignore
import { FlakesTexture, GLTF, RectAreaLightUniformsLib } from 'three-stdlib';
import * as THREE from 'three';

RectAreaLightUniformsLib.init();
THREE.Vector2.prototype.equals = function (v, epsilon = 0.001) {
Expand All @@ -48,23 +48,19 @@ export class LerpedPointer extends NgtComponentStore {

load() {
this.zone.runOutsideAngular(() => {
this.onCanvasReady(
this.store.ready$,
() => {
this.pointerRef.set(this.store.get((s) => s.pointer).clone());
return this.store.registerBeforeRender({
callback: ({ performance, pointer }) => {
this.previous.copy(this.pointerRef.value);
this.pointerRef.value.lerp(pointer, 0.1);
// Regress system when the mouse is moved
if (!this.previous.equals(this.pointerRef.value)) {
performance.regress();
}
},
});
},
true
);
this.store.onReady(() => {
this.pointerRef.set(this.store.get((s) => s.pointer).clone());
return this.store.registerBeforeRender({
callback: ({ performance, pointer }) => {
this.previous.copy(this.pointerRef.value);
this.pointerRef.value.lerp(pointer, 0.1);
// Regress system when the mouse is moved
if (!this.previous.equals(this.pointerRef.value)) {
performance.regress();
}
},
});
});
});
}
}
Expand Down Expand Up @@ -262,18 +258,15 @@ export class Effects extends NgtComponentStore implements OnInit {
}

ngOnInit() {
this.onCanvasReady(
this.store.ready$,
() =>
this.store.registerBeforeRender({
callback: ({ performance }) => {
if (this.ssaoRef.value) {
this.ssaoRef.value.blendMode.blendFunction =
performance.current! < 1 ? BlendFunction.SKIP : BlendFunction.MULTIPLY;
}
},
}),
true
this.store.onReady(() =>
this.store.registerBeforeRender({
callback: ({ performance }) => {
if (this.ssaoRef.value) {
this.ssaoRef.value.blendMode.blendFunction =
performance.current && performance.current < 1 ? BlendFunction.SKIP : BlendFunction.MULTIPLY;
}
},
})
);
}
}
Expand Down
15 changes: 6 additions & 9 deletions apps/sandbox/src/app/object-clump/object-clump.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,12 @@ export class Pointer extends NgtComponentStore implements OnInit {

ngOnInit() {
this.zone.runOutsideAngular(() => {
this.onCanvasReady(
this.store.ready$,
() =>
this.store.registerBeforeRender({
callback: ({ pointer, viewport }) => {
this.pointerRef.api.position.set((pointer.x * viewport.width) / 2, (pointer.y * viewport.height) / 2, 0);
},
}),
true
this.store.onReady(() =>
this.store.registerBeforeRender({
callback: ({ pointer, viewport }) => {
this.pointerRef.api.position.set((pointer.x * viewport.width) / 2, (pointer.y * viewport.height) / 2, 0);
},
})
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion libs/cannon/src/lib/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class NgtPhysicBody extends NgtComponentStore {

const physicsStore = this.physicsStore;

this.onCanvasReady(this.store.ready$, () => {
this.store.onReady(() => {
this.effect<[CannonWorkerAPI, THREE.Object3D]>(
tapEffect(() => {
const { worker, refs, events } = physicsStore.get();
Expand Down
2 changes: 1 addition & 1 deletion libs/cannon/src/lib/constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class NgtPhysicConstraint extends NgtComponentStore {
const physicsStore = this.physicsStore;
const uuid = makeId();

this.onCanvasReady(this.store.ready$, () => {
this.store.onReady(() => {
this.effect<[CannonWorkerAPI, TObjectA, TObjectB]>(
tapEffect(([worker, a, b]) => {
worker.addConstraint({
Expand Down
2 changes: 1 addition & 1 deletion libs/cannon/src/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class NgtCannonDebug extends NgtInstance<THREE.Scene, NgtCannonDebugState
override ngOnInit() {
super.ngOnInit();
this.zone.runOutsideAngular(() => {
this.onCanvasReady(this.store.ready$, () => {
this.store.onReady(() => {
this.prepareInstance(new THREE.Scene());
this.set((state) => ({
cannonDebugger: state.impl(this.instance.value, { bodies: state.bodies } as World, {
Expand Down
2 changes: 1 addition & 1 deletion libs/cannon/src/lib/ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class NgtPhysicRaycast extends NgtComponentStore {
this.zone.runOutsideAngular(() => {
const uuid = makeId();

this.onCanvasReady(this.store.ready$, () => {
this.store.onReady(() => {
this.effect<CannonWorkerAPI>(
tapEffect((worker) => {
const events = this.physicsStore.get((s) => s.events);
Expand Down
2 changes: 1 addition & 1 deletion libs/cannon/src/lib/raycast-vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class NgtPhysicRaycastVehicle extends NgtComponentStore {
const { chassisBody, indexForwardAxis = 2, indexRightAxis = 0, indexUpAxis = 1, wheelInfos, wheels } = fn();
const physicsStore = this.physicsStore;

this.onCanvasReady(this.store.ready$, () => {
this.store.onReady(() => {
this.effect<[CannonWorkerAPI, THREE.Object3D, THREE.Object3D, THREE.Object3D[]]>(
tapEffect(() => {
const worker = physicsStore.get((s) => s.worker);
Expand Down
2 changes: 1 addition & 1 deletion libs/cannon/src/lib/spring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class NgtPhysicSpring extends NgtComponentStore {
const physicsStore = this.physicsStore;
const uuid = makeId();

this.onCanvasReady(this.store.ready$, () => {
this.store.onReady(() => {
this.effect<[CannonWorkerAPI, THREE.Object3D, THREE.Object3D]>(
tapEffect(([worker, a, b]) => {
worker.addSpring({
Expand Down
18 changes: 7 additions & 11 deletions libs/core/attributes/src/lib/color-attribute/color-attribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// GENERATED
import { makeColor, NgtInstance, provideInstanceRef, NgtColor } from '@angular-three/core';
import { makeColor, NgtColor, NgtInstance, provideInstanceRef } from '@angular-three/core';
import { ChangeDetectionStrategy, Component, Input, NgModule } from '@angular/core';
import type { Subscription } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -18,16 +18,12 @@ export class NgtColorAttribute extends NgtInstance<THREE.Color> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(makeColor(color));
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(makeColor(color));
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
18 changes: 7 additions & 11 deletions libs/core/attributes/src/lib/fog-attribute/fog-attribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// GENERATED
import { make, NgtInstance, provideInstanceRef, NgtFog } from '@angular-three/core';
import { make, NgtFog, NgtInstance, provideInstanceRef } from '@angular-three/core';
import { ChangeDetectionStrategy, Component, Input, NgModule } from '@angular/core';
import type { Subscription } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -18,16 +18,12 @@ export class NgtFogAttribute extends NgtInstance<THREE.Fog> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(make(THREE.Fog, fog));
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(make(THREE.Fog, fog));
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// GENERATED
import { make, NgtInstance, provideInstanceRef, NgtFogExp2 } from '@angular-three/core';
import { make, NgtFogExp2, NgtInstance, provideInstanceRef } from '@angular-three/core';
import { ChangeDetectionStrategy, Component, Input, NgModule } from '@angular/core';
import type { Subscription } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -18,16 +18,12 @@ export class NgtFogExp2Attribute extends NgtInstance<THREE.FogExp2> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(make(THREE.FogExp2, fogExp2));
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(make(THREE.FogExp2, fogExp2));
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// GENERATED
import { make, NgtInstance, provideInstanceRef, NgtMatrix3 } from '@angular-three/core';
import { make, NgtInstance, NgtMatrix3, provideInstanceRef } from '@angular-three/core';
import { ChangeDetectionStrategy, Component, Input, NgModule } from '@angular/core';
import type { Subscription } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -18,16 +18,12 @@ export class NgtMatrix3Attribute extends NgtInstance<THREE.Matrix3> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(make(THREE.Matrix3, matrix3));
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(make(THREE.Matrix3, matrix3));
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// GENERATED
import { make, NgtInstance, provideInstanceRef, NgtMatrix4 } from '@angular-three/core';
import { make, NgtInstance, NgtMatrix4, provideInstanceRef } from '@angular-three/core';
import { ChangeDetectionStrategy, Component, Input, NgModule } from '@angular/core';
import type { Subscription } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -18,16 +18,12 @@ export class NgtMatrix4Attribute extends NgtInstance<THREE.Matrix4> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(make(THREE.Matrix4, matrix4));
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(make(THREE.Matrix4, matrix4));
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
16 changes: 6 additions & 10 deletions libs/core/attributes/src/lib/value-attribute/value-attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ export class NgtValueAttribute extends NgtInstance<any> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(value);
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(value);
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// GENERATED
import { makeVector2, NgtInstance, provideInstanceRef, NgtVector2 } from '@angular-three/core';
import { makeVector2, NgtInstance, NgtVector2, provideInstanceRef } from '@angular-three/core';
import { ChangeDetectionStrategy, Component, Input, NgModule } from '@angular/core';
import type { Subscription } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -18,16 +18,12 @@ export class NgtVector2Attribute extends NgtInstance<THREE.Vector2> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(makeVector2(vector2));
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(makeVector2(vector2));
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// GENERATED
import { makeVector3, NgtInstance, provideInstanceRef, NgtVector3 } from '@angular-three/core';
import { makeVector3, NgtInstance, NgtVector3, provideInstanceRef } from '@angular-three/core';
import { ChangeDetectionStrategy, Component, Input, NgModule } from '@angular/core';
import type { Subscription } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -18,16 +18,12 @@ export class NgtVector3Attribute extends NgtInstance<THREE.Vector3> {
this.initSubscription.unsubscribe();
}

this.initSubscription = this.onCanvasReady(
this.store.ready$,
() => {
this.prepareInstance(makeVector3(vector3));
return () => {
this.initSubscription?.unsubscribe();
};
},
true
);
this.initSubscription = this.store.onReady(() => {
this.prepareInstance(makeVector3(vector3));
return () => {
this.initSubscription?.unsubscribe();
};
});
});
}

Expand Down
Loading

0 comments on commit 2083c50

Please sign in to comment.