Skip to content

Commit bb26859

Browse files
author
Sascha Braun
committed
last fixes and remove logs
1 parent c65e34f commit bb26859

27 files changed

+129
-139
lines changed

src/v2/components/AssetBundle.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ export class AssetBundle extends Mixins(AppComponent) {
2626
private m_bundle!: BundleHandle;
2727

2828
public mounted() {
29-
console.log("mounted asset bundle", this.name);
3029
this.m_bundle = this.app().assets.bundles.create(this.name);
3130
this.m_bundle.onLoad.on(this.onLoad);
3231
this.m_bundle.onUnload.on(this.onUnload);
3332

34-
//TODO handle preload
33+
this.m_bundle.preload = this.preload;
3534
}
3635

37-
public beforeDestroy() {
36+
public destroyed() {
3837
this.app().assets.bundles.dispose(this.name);
3938
}
4039

@@ -53,21 +52,11 @@ export class AssetBundle extends Mixins(AppComponent) {
5352

5453
await Vue.nextTick();
5554
await deps;
56-
57-
console.log("registered bundle", this.name, this.m_bundle.countAssets());
5855
}
5956

6057
private async onUnload(): Promise<void> {
6158
this.m_active = false;
6259
await Vue.nextTick();
63-
64-
const assets = this.app().assets;
65-
console.log(
66-
assets.textures.size(),
67-
assets.materials.size(),
68-
assets.geometries.size(),
69-
assets.models.size()
70-
);
7160
}
7261

7362
private getBundles(pDependencies: string | string[]): BundleHandle[] {

src/v2/components/Axes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class Axes extends Mixins(ObjectComponent) {
2222
}
2323

2424
public async created() {
25-
if (!this.scene() && !this.object()) {
25+
const scene = this.scene() ? this.scene()!.get() : undefined;
26+
if (!scene && !this.object()) {
2627
throw new Error(
2728
"Grid component can only be added as child to an object or mesh component"
2829
);
@@ -31,14 +32,15 @@ export class Axes extends Mixins(ObjectComponent) {
3132
this.m_axes = new AxesHelper(this.size);
3233
this.m_axes.name = this.name;
3334

34-
const parent = this.object ? this.object() : this.scene();
35+
const parent = this.object ? this.object() : scene;
3536
parent!.add(this.m_axes);
3637

3738
this.m_created = true;
3839
}
3940

40-
public beforeDestroy() {
41-
const parent = this.object ? this.object() : this.scene();
41+
public destroyed() {
42+
const scene = this.scene() ? this.scene()!.get() : undefined;
43+
const parent = this.object ? this.object() : scene;
4244
parent!.remove(this.m_axes);
4345
}
4446

src/v2/components/Camera.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,34 @@ export class Camera extends Mixins(ObjectComponent) {
3131

3232
public async created() {
3333
const app = this.app();
34+
const sceneHandle = this.scene();
35+
const scene = sceneHandle ? this.scene()!.get() : undefined;
36+
if (!scene) {
37+
throw new Error(
38+
"Camera component can only be added as child to an object or scene component"
39+
);
40+
}
3441

3542
const camera = await this.factory(app);
3643
camera.name = this.name;
3744

38-
this.m_camera = app.cameras.create(this.name);
45+
this.m_camera = sceneHandle!.cameras.create(this.name);
3946
this.m_camera.set(camera);
4047
this.m_camera.onActivate.on(this.onActivate);
4148
this.m_camera.onDeactivate.on(this.onDeactivate);
4249

4350
this.m_active = true;
4451

45-
console.log("camera created", this.name);
52+
const parent = this.object ? this.object() : scene;
53+
parent!.add(this.m_camera.get()!);
4654
}
4755

48-
public beforeDestroy() {
49-
this.app().cameras.dispose(this.name);
50-
console.log("camera disposed", this.name);
56+
public destroyed() {
57+
const sceneHandle = this.scene();
58+
const scene = sceneHandle ? this.scene()!.get() : undefined;
59+
const parent = this.object ? this.object() : scene;
60+
parent!.remove(this.m_camera.get()!);
61+
sceneHandle!.cameras.dispose(this.name);
5162
}
5263

5364
public render(h: any) {

src/v2/components/Fog.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ export class Fog extends Mixins(SceneComponent) {
2828

2929
@Watch("exp2")
3030
public watchExp() {
31+
const scene = this.scene() ? this.scene()!.get() : undefined;
3132
if (this.exp2) {
3233
this.m_fog = new ThreeFogExp2(this.color, this.density);
3334
} else {
3435
this.m_fog = new ThreeFog(this.color, this.near, this.far);
3536
}
36-
this.scene()!.fog = this.m_fog;
37+
scene!.fog = this.m_fog;
3738
}
3839
@Watch("near")
3940
public watchNear() {
@@ -58,7 +59,7 @@ export class Fog extends Mixins(SceneComponent) {
5859
private m_fog!: IFog;
5960

6061
public created() {
61-
const scene = this.scene();
62+
const scene = this.scene() ? this.scene()!.get() : undefined;
6263
if (!scene) {
6364
throw new Error(
6465
"Fog component can only be added as a child to a scene component"
@@ -76,8 +77,8 @@ export class Fog extends Mixins(SceneComponent) {
7677
scene.fog = this.m_fog;
7778
}
7879

79-
public beforeDestroy() {
80-
const scene = this.scene();
80+
public destroyed() {
81+
const scene = this.scene() ? this.scene()!.get() : undefined;
8182
scene!.fog = null;
8283
}
8384

src/v2/components/Geometry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Geometry extends Mixins(AssetComponent) {
1919
this.app().assets.geometries.set(this.name, geometry);
2020
}
2121

22-
public async beforeDestroy() {
22+
public async destroyed() {
2323
if (this.bundle()) {
2424
this.bundle()!.unregisterAsset(this.name);
2525
}

src/v2/components/Grid.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export class Grid extends Mixins(ObjectComponent) {
2525
}
2626

2727
public async created() {
28-
if (!this.scene() && !this.object()) {
28+
const scene = this.scene() ? this.scene()!.get() : undefined;
29+
if (!scene && !this.object()) {
2930
throw new Error(
3031
"Grid component can only be added as child to an object or mesh component"
3132
);
@@ -34,14 +35,15 @@ export class Grid extends Mixins(ObjectComponent) {
3435
this.m_grid = new THREE.GridHelper(this.size, this.divisions);
3536
this.m_grid.name = this.name;
3637

37-
const parent = this.object ? this.object() : this.scene();
38+
const parent = this.object ? this.object() : scene;
3839
parent!.add(this.m_grid);
3940

4041
this.m_created = true;
4142
}
4243

43-
public beforeDestroy() {
44-
const parent = this.object ? this.object() : this.scene();
44+
public destroyed() {
45+
const scene = this.scene() ? this.scene()!.get() : undefined;
46+
const parent = this.object ? this.object() : scene;
4547
parent!.remove(this.m_grid);
4648
}
4749

src/v2/components/Group.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ export class Group extends Mixins(ObjectComponent) {
1919
}
2020

2121
public async created() {
22-
if (!this.scene() && !this.object()) {
22+
const scene = this.scene() ? this.scene()!.get() : undefined;
23+
if (!scene && !this.object()) {
2324
throw new Error(
2425
"Group component can only be added as child to an object or scene component"
2526
);
2627
}
2728

2829
this.m_group = new THREE.Group();
2930
this.m_group.name = this.name;
30-
const parent = this.object ? this.object() : this.scene();
31+
const parent = this.object ? this.object() : scene;
3132
parent!.add(this.m_group);
3233

3334
this.m_created = true;
3435
}
3536

36-
public beforeDestroy() {
37-
const parent = this.object ? this.object() : this.scene();
37+
public destroyed() {
38+
const scene = this.scene() ? this.scene()!.get() : undefined;
39+
const parent = this.object ? this.object() : scene;
3840
parent!.remove(this.m_group);
3941
}
4042

src/v2/components/Light.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ export class Light extends Mixins(ObjectComponent) {
2323
}
2424

2525
public async created() {
26-
if (!this.scene() && !this.object()) {
26+
const scene = this.scene() ? this.scene()!.get() : undefined;
27+
if (!scene && !this.object()) {
2728
throw new Error(
2829
"Light component can only be added as child to an object or scene component"
2930
);
3031
}
3132

3233
this.m_light = await this.factory(this.app());
3334
this.m_light.name = this.name;
34-
const parent = this.object ? this.object() : this.scene();
35+
const parent = this.object ? this.object() : scene;
3536
parent!.add(this.m_light);
3637

3738
this.m_created = true;
3839
}
3940

40-
public beforeDestroy() {
41-
const parent = this.object ? this.object() : this.scene();
41+
public destroyed() {
42+
const scene = this.scene() ? this.scene()!.get() : undefined;
43+
const parent = this.object ? this.object() : scene;
4244
parent!.remove(this.m_light);
4345
}
4446

src/v2/components/Material.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ export class Material extends Mixins(AssetComponent) {
1717
this.bundle()!.registerAsset(this.name, material);
1818
}
1919
this.app().assets.materials.set(this.name, material);
20-
console.log("material created", this.name);
2120
}
2221

23-
public async beforeDestroy() {
22+
public async destroyed() {
2423
if (this.bundle()) {
2524
this.bundle()!.unregisterAsset(this.name);
2625
}
2726
this.app().assets.materials.dispose(this.name);
28-
console.log("material disposed", this.name);
2927
}
3028

3129
public render(h: any) {

src/v2/components/Mesh.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export class Mesh extends Mixins(ObjectComponent) {
2929
}
3030

3131
public async created() {
32-
if (!this.scene() && !this.object()) {
32+
const scene = this.scene() ? this.scene()!.get() : undefined;
33+
if (!scene && !this.object()) {
3334
throw new Error(
3435
"Mesh component could not be created: can only be added as child to an object or mesh component"
3536
);
@@ -50,14 +51,15 @@ export class Mesh extends Mixins(ObjectComponent) {
5051

5152
this.m_mesh.name = this.name;
5253

53-
const parent = this.object ? this.object() : this.scene();
54+
const parent = this.object ? this.object() : scene;
5455
parent!.add(this.m_mesh);
5556

5657
this.m_created = true;
5758
}
5859

59-
public beforeDestroy() {
60-
const parent = this.object ? this.object() : this.scene();
60+
public destroyed() {
61+
const scene = this.scene() ? this.scene()!.get() : undefined;
62+
const parent = this.object ? this.object() : scene;
6163
parent!.remove(this.m_mesh);
6264
}
6365

0 commit comments

Comments
 (0)