Skip to content

Commit c03f5e2

Browse files
author
Sascha Braun
committed
increment package version to 1.0.0 and remove old version files
1 parent bb26859 commit c03f5e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+471
-2939
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-threejs-composer",
3-
"version": "0.5.0",
3+
"version": "1.0.0",
44
"main": "build/src/index.js",
55
"typings": "build/src/index.d.ts",
66
"repository": "https://github.com/sascha245/vue-threejs-composer",

src/components/AssetBundle.ts

Lines changed: 34 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import Vue, { VNode } from "vue";
2-
import { Component, Mixins, Prop } from "vue-property-decorator";
1+
import { Component, Mixins, Prop, Provide, Vue } from "vue-property-decorator";
32

4-
import { AssetBundle as Bundle } from "../core";
5-
import { isThreeAssetComponent, ThreeComponent } from "./base";
3+
import { BundleHandle } from "../core";
4+
import { AppComponent } from "../mixins";
5+
import { stringToArray } from "../utils/toArray";
66

77
@Component
8-
export class AssetBundle extends Mixins(ThreeComponent) {
9-
@Prop({ type: String, default: "" })
8+
export class AssetBundle extends Mixins(AppComponent) {
9+
@Prop({ type: String, required: true })
1010
public name!: string;
1111

1212
@Prop({ type: Boolean, default: false })
@@ -15,82 +15,57 @@ export class AssetBundle extends Mixins(ThreeComponent) {
1515
@Prop({ type: [String, Array], default: () => [] })
1616
public dependencies!: string | string[];
1717

18-
private m_isActive = false;
19-
private m_bundle!: Bundle;
18+
@Provide("bundle")
19+
private provideBundle = this.getBundle;
2020

21-
public mounted() {
22-
const manager = this.app().assets;
23-
this.m_bundle = manager.createBundle(this.name);
21+
private getBundle() {
22+
return this.m_bundle;
23+
}
2424

25-
this.m_bundle.on("load", this.onLoadBundle);
26-
this.m_bundle.on("unload", this.onUnloadBundle);
25+
private m_active = false;
26+
private m_bundle!: BundleHandle;
27+
28+
public mounted() {
29+
this.m_bundle = this.app().assets.bundles.create(this.name);
30+
this.m_bundle.onLoad.on(this.onLoad);
31+
this.m_bundle.onUnload.on(this.onUnload);
2732

28-
// TODO handle preload on / off
29-
// this.m_bundle.preload = this.preload;
33+
this.m_bundle.preload = this.preload;
3034
}
3135

32-
public beforeDestroy() {
33-
const manager = this.app().assets;
34-
manager.deleteBundle(this.name);
36+
public destroyed() {
37+
this.app().assets.bundles.dispose(this.name);
3538
}
3639

3740
public render(h: any) {
38-
if (!this.m_isActive) {
41+
if (!this.m_active) {
3942
return null;
4043
}
4144
return h("div", this.$slots.default);
4245
}
4346

44-
private async onLoadBundle(): Promise<void> {
45-
this.m_isActive = true;
47+
private async onLoad(): Promise<void> {
48+
this.m_active = true;
4649

4750
const bundles = this.getBundles(this.dependencies);
48-
const depsPromises = this.m_bundle.registerDependencies(bundles);
51+
const deps = this.m_bundle.registerDependencies(bundles);
4952

5053
await Vue.nextTick();
51-
await depsPromises;
52-
53-
this.registerAssets(this.$slots.default);
54-
55-
// console.log("registration for bundle done", this.name);
54+
await deps;
5655
}
5756

58-
private async onUnloadBundle() {
59-
this.m_isActive = false;
57+
private async onUnload(): Promise<void> {
58+
this.m_active = false;
6059
await Vue.nextTick();
6160
}
6261

63-
private registerAssets(nodes: VNode[] | undefined) {
64-
if (nodes) {
65-
for (const node of nodes) {
66-
const component = node.componentInstance;
67-
if (component && isThreeAssetComponent(component)) {
68-
this.m_bundle.registerAsset(component.asset);
69-
}
70-
this.registerAssets(node.children);
71-
}
72-
}
73-
}
74-
75-
private getBundles(dependencies: string | string[]): Bundle[] {
76-
const manager = this.app().assets;
77-
const bundles: Bundle[] = [];
62+
private getBundles(pDependencies: string | string[]): BundleHandle[] {
63+
const bundles: BundleHandle[] = [];
64+
const dependencies = stringToArray(",", pDependencies);
65+
const app = this.app();
7866

79-
if (!dependencies) {
80-
return bundles;
81-
}
82-
if (typeof dependencies === "string") {
83-
dependencies = dependencies.split(",").map(mat => mat.trim());
84-
}
85-
if (!Array.isArray(dependencies)) {
86-
throw new Error(
87-
`AssetBundle "${
88-
this.name
89-
}" could not be loaded: "dependencies" have to be either a string or an array`
90-
);
91-
}
92-
(dependencies as string[]).forEach(dep => {
93-
const bundle = manager.getBundle(dep);
67+
dependencies.forEach(name => {
68+
const bundle = app.assets.bundles.get(name);
9469
if (bundle) {
9570
bundles.push(bundle);
9671
}

src/components/Axes.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import * as THREE from "three";
1+
import { AxesHelper } from "three";
22
import { Component, Mixins, Prop, Provide } from "vue-property-decorator";
33

4-
import { AssetTypes, GeometryType, MaterialType } from "../types";
5-
import { ThreeComponent, ThreeObjectComponent, ThreeSceneComponent } from "./base";
4+
import { ObjectComponent } from "../mixins";
65

76
@Component
8-
export class Axes extends Mixins(
9-
ThreeComponent,
10-
ThreeSceneComponent,
11-
ThreeObjectComponent
12-
) {
7+
export class Axes extends Mixins(ObjectComponent) {
138
@Prop({ type: String, default: "" })
149
private name!: string;
1510

@@ -22,29 +17,31 @@ export class Axes extends Mixins(
2217
private m_axes!: THREE.AxesHelper;
2318
private m_created = false;
2419

25-
public getObject(): THREE.Object3D {
20+
public getObject() {
2621
return this.m_axes;
2722
}
2823

2924
public async created() {
30-
if (!this.scene && !this.object) {
25+
const scene = this.scene() ? this.scene()!.get() : undefined;
26+
if (!scene && !this.object()) {
3127
throw new Error(
3228
"Grid component can only be added as child to an object or mesh component"
3329
);
3430
}
3531

36-
this.m_axes = new THREE.AxesHelper(this.size);
32+
this.m_axes = new AxesHelper(this.size);
3733
this.m_axes.name = this.name;
3834

39-
const parent = this.object ? this.object() : this.scene();
40-
parent.add(this.m_axes);
35+
const parent = this.object ? this.object() : scene;
36+
parent!.add(this.m_axes);
4137

4238
this.m_created = true;
4339
}
4440

45-
public beforeDestroy() {
46-
const parent = this.object ? this.object() : this.scene();
47-
parent.remove(this.m_axes);
41+
public destroyed() {
42+
const scene = this.scene() ? this.scene()!.get() : undefined;
43+
const parent = this.object ? this.object() : scene;
44+
parent!.remove(this.m_axes);
4845
}
4946

5047
public render(h: any) {

src/components/Behaviour.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/components/Camera.ts

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,68 @@
1-
import * as THREE from "three";
2-
import { Component, Mixins, Prop, Provide, Vue, Watch } from "vue-property-decorator";
1+
import { Component, Mixins, Prop, Provide, Vue } from "vue-property-decorator";
32

4-
import { CameraFactory } from "../types";
5-
import { ThreeComponent, ThreeSceneComponent } from "./base";
3+
import { CameraFactory, CameraHandle } from "../core";
4+
import { ObjectComponent } from "../mixins";
65

76
@Component
8-
export class Camera extends Mixins(ThreeComponent, ThreeSceneComponent) {
7+
export class Camera extends Mixins(ObjectComponent) {
98
@Prop({ required: true, type: String })
109
private name!: string;
1110

1211
@Prop({ required: true, type: Function })
1312
public factory!: CameraFactory;
1413

1514
@Provide("object")
16-
public provideObject = this.object;
15+
public provideObject = this.getObject;
1716

18-
private m_created = false;
19-
private m_camera!: THREE.Camera;
17+
private m_active = false;
18+
private m_camera!: CameraHandle;
2019

21-
public object(): THREE.Object3D {
22-
return this.m_camera;
20+
public getObject() {
21+
return this.m_camera.get();
2322
}
2423

24+
public onActivate = async () => {
25+
this.m_active = true;
26+
};
27+
public onDeactivate = async () => {
28+
this.m_active = false;
29+
await Vue.nextTick();
30+
};
31+
2532
public async created() {
26-
this.m_camera = await this.factory(this.app());
27-
this.m_camera.name = this.name;
28-
this.app().cameraManager.set(this.name, this.m_camera);
29-
this.m_created = true;
33+
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+
}
41+
42+
const camera = await this.factory(app);
43+
camera.name = this.name;
44+
45+
this.m_camera = sceneHandle!.cameras.create(this.name);
46+
this.m_camera.set(camera);
47+
this.m_camera.onActivate.on(this.onActivate);
48+
this.m_camera.onDeactivate.on(this.onDeactivate);
49+
50+
this.m_active = true;
51+
52+
const parent = this.object ? this.object() : scene;
53+
parent!.add(this.m_camera.get()!);
3054
}
3155

32-
public beforeDestroy() {
33-
this.app().cameraManager.remove(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);
3462
}
3563

3664
public render(h: any) {
37-
if (!this.m_created) {
65+
if (!this.m_active) {
3866
return null;
3967
}
4068
return h("div", this.$slots.default);

0 commit comments

Comments
 (0)