Skip to content

Commit 796d6ca

Browse files
author
Sascha Braun
committed
adapted components to rewritten core
started testing and fixing bugs (not totally done yet)
1 parent a4c5e03 commit 796d6ca

Some content is hidden

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

45 files changed

+1413
-170
lines changed

samples/factories/geometries.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as THREE from "three";
2+
3+
import { Application, GeometryFactory } from "../../src";
4+
5+
export const cubeFactory: GeometryFactory = async (app: Application) => {
6+
return new THREE.BoxBufferGeometry(1, 1, 1);
7+
};
8+
9+
export const planeFactory: GeometryFactory = async () => {
10+
return new THREE.PlaneBufferGeometry(100, 100);
11+
};

samples/views/Demo.ts

Lines changed: 30 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,54 @@ import "../FbxLoader";
33
import * as THREE from "three";
44
import { Component, Vue } from "vue-property-decorator";
55

6-
import {
7-
Application, AssetTypes, CameraFactory, components, GeometryFactory, LightFactory,
8-
MaterialFactory
9-
} from "../../src";
6+
import { CameraFactory, components, LightFactory, Loader } from "../../src";
7+
import { cubeFactory, planeFactory } from "../factories/geometries";
108
import { HoverBehaviour } from "./HoverBehaviour";
119
import { MyBehaviour } from "./MyBehaviour";
10+
import StandardMaterial from "./StandardMaterial";
11+
12+
Loader.registerExtension("fbx", THREE.FBXLoader);
1213

1314
(window as any).THREE = THREE;
1415

1516
@Component({
1617
components: {
1718
...components,
19+
HoverBehaviour,
1820
MyBehaviour,
19-
HoverBehaviour
21+
StandardMaterial
2022
}
2123
})
22-
export default class About extends Vue {
23-
public cubeFactory: GeometryFactory | null = null;
24-
public planeFactory: GeometryFactory | null = null;
25-
public cubeMaterialFactory: MaterialFactory | null = null;
26-
public waterMaterialFactory: MaterialFactory | null = null;
24+
export default class Demo extends Vue {
25+
public cubeFactory = cubeFactory;
26+
public planeFactory = planeFactory;
2727

28-
public polygonMaterialFactory: MaterialFactory = async (app: Application) => {
29-
const texture = await app.assets.get("PolygonMini_Tex", AssetTypes.TEXTURE);
28+
public lightFactory: LightFactory = async () => {
29+
const light = new THREE.PointLight(0xffffff, 1, 100);
3030

31-
if (!texture) {
32-
throw new Error("Could not find 'PolygonMini_Tex' texture");
33-
}
31+
light.shadow.mapSize.width = 512; // default
32+
light.shadow.mapSize.height = 512; // default
33+
light.shadow.camera.near = 0.3; // default
34+
light.shadow.camera.far = 500; // default
3435

35-
const mat = new THREE.MeshStandardMaterial({
36-
color: "#eeeeee",
37-
metalness: 0.01
38-
});
39-
mat.map = texture as THREE.Texture;
40-
return mat;
36+
return light;
4137
};
42-
public polygonDungeonFactory: MaterialFactory = async (app: Application) => {
43-
const texture = await app.assets.get(
44-
"PolygonDungeon_Tex",
45-
AssetTypes.TEXTURE
46-
);
47-
48-
if (!texture) {
49-
throw new Error("Could not find 'PolygonDungeon_Tex' texture");
50-
}
5138

52-
const mat = new THREE.MeshStandardMaterial({
53-
color: "#eeeeee",
54-
metalness: 0.01
55-
});
56-
mat.map = texture as THREE.Texture;
57-
return mat;
39+
public cameraFactory: CameraFactory = async () => {
40+
const viewAngle = 60;
41+
const nearClipping = 0.1;
42+
const farClipping = 1000;
43+
return new THREE.PerspectiveCamera(
44+
viewAngle,
45+
window.innerWidth / window.innerHeight,
46+
nearClipping,
47+
farClipping
48+
);
5849
};
5950

60-
public lightFactory: LightFactory | null = null;
61-
public cameraFactory: CameraFactory | null = null;
62-
6351
public canvas: HTMLCanvasElement | null = null;
64-
public canvas2: HTMLCanvasElement | null = null;
6552

6653
public scene1 = {
67-
name: "scene1",
6854
camera: {
6955
position: {
7056
x: 0,
@@ -79,17 +65,12 @@ export default class About extends Vue {
7965
},
8066
fields: new Array()
8167
};
82-
public scene2 = {
83-
name: "scene2"
84-
};
8568

8669
public isLoading = true;
8770
public loadingAmount = 0;
8871
public loadingTotal = 0;
8972

90-
public activeScene = this.scene1.name;
91-
92-
public scenes = [this.scene1, this.scene2];
73+
public activeScene = "scene1";
9374

9475
public startLoading() {
9576
this.isLoading = true;
@@ -105,18 +86,11 @@ export default class About extends Vue {
10586
console.log("loading progress", `${amount} / ${total}`);
10687
}
10788

108-
public changeScene(pScene: any) {
109-
this.activeScene = pScene.name;
110-
// this.scenes.forEach(scene => {
111-
// scene.active = false;
112-
// });
113-
// pScene.active = true;
114-
console.log("about scene change", this.scenes);
89+
public changeScene(pName: string) {
90+
this.activeScene = pName;
11591
}
11692

11793
public created() {
118-
console.log("scene", this.scene1);
119-
12094
let idx = 0;
12195
for (let x = 0; x < 5; ++x) {
12296
for (let z = 0; z < 5; ++z) {
@@ -129,88 +103,9 @@ export default class About extends Vue {
129103
++idx;
130104
}
131105
}
132-
133-
this.cubeFactory = async (app: Application) => {
134-
// await new Promise(r => setTimeout(r, 2000));
135-
// return new THREE.CylinderBufferGeometry(1, 1, 1, 6, 6);
136-
137-
return new THREE.BoxBufferGeometry(1, 1, 1);
138-
};
139-
this.planeFactory = async () => {
140-
// await new Promise(r => setTimeout(r, 3000));
141-
return new THREE.PlaneBufferGeometry(100, 100);
142-
};
143-
144-
this.cubeMaterialFactory = async (app: Application) => {
145-
const texture = await app.assets.get("crateTex", AssetTypes.TEXTURE);
146-
147-
if (!texture) {
148-
throw new Error("Could not find 'crateTex' texture");
149-
}
150-
151-
const mat = new THREE.MeshPhysicalMaterial({
152-
color: "#eeeeee",
153-
metalness: 0.01
154-
});
155-
mat.map = texture as THREE.Texture;
156-
// mat.color = new THREE.Color("#dddddd");
157-
return mat;
158-
};
159-
this.waterMaterialFactory = async () => {
160-
const mat = new THREE.MeshPhysicalMaterial({
161-
color: "#9c9cff",
162-
metalness: 0.01,
163-
fog: true
164-
});
165-
// mat.color = new THREE.Color("#dddddd");
166-
return mat;
167-
};
168-
169-
this.lightFactory = async () => {
170-
const light = new THREE.PointLight(0xffffff, 1, 100);
171-
172-
light.shadow.mapSize.width = 512; // default
173-
light.shadow.mapSize.height = 512; // default
174-
light.shadow.camera.near = 0.3; // default
175-
light.shadow.camera.far = 500; // default
176-
177-
return light;
178-
};
179-
180-
this.cameraFactory = async () => {
181-
const viewAngle = 60;
182-
const nearClipping = 0.1;
183-
const farClipping = 1000;
184-
return new THREE.PerspectiveCamera(
185-
viewAngle,
186-
window.innerWidth / window.innerHeight,
187-
nearClipping,
188-
farClipping
189-
);
190-
};
191106
}
192107

193108
public mounted() {
194109
this.canvas = this.$refs.canvas as HTMLCanvasElement;
195-
this.canvas2 = this.$refs.canvas2 as HTMLCanvasElement;
196110
}
197111
}
198-
199-
// <!-- Asset management update ideas: allow to split up and depend on asset bundles (that can be either preloaded or loaded during runtime) -->
200-
// <!-- <assets-bundle name="PolygonMini" preload>
201-
// <texture name="PolygonMini_Tex" src="/assets/textures/PolygonMinis_Texture_01.png"/>
202-
// <material name="PolygonMini_Mat" :factory="polygonMaterialFactory"/>
203-
204-
// <model name="grassModel" src="/assets/models/SM_Env_Grass_01.fbx" materials="PolygonMini_Mat"/>
205-
// <model name="PM_column" src="/assets/models/SM_Tile_Hex_Column_02.fbx" materials="PolygonMini_Mat"/>
206-
// <model name="PM_flat" src="/assets/models/SM_Tile_Hex_Flat_01.fbx" materials="PolygonMini_Mat"/>
207-
// </assets-bundle>
208-
209-
// <assets-bundle name="crate" preload>
210-
// <texture name="crateTex" src="/assets/textures/crate.jpg"/>
211-
// </assets-bundle>
212-
213-
// <assets-bundle name="Scene1" dependencies="crate" preload>
214-
// <geometry name="cube" :factory="cubeFactory"/>
215-
// <material name="cubeMat" :factory="cubeMaterialFactory"/>
216-
// </assets-bundle> -->

samples/views/Demo.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<div class="about">
55
<h1>This is an about page</h1>
66
<div>
7-
<button @click="changeScene(scene1)">Scene 1</button>
8-
<button @click="changeScene(scene2)">Scene 2</button>
7+
<button @click="changeScene('scene1')">Scene 1</button>
8+
<button @click="changeScene('scene2')">Scene 2</button>
99
</div>
1010

1111
<div>
@@ -27,7 +27,7 @@
2727
<asset-bundle name="PolygonMini" preload>
2828
<texture name="PolygonMini_Tex" src="/assets/textures/PolygonMinis_Texture_01.png"/>
2929

30-
<material name="PolygonMini_Mat" :factory="polygonMaterialFactory"/>
30+
<standard-material name="PolygonMini_Mat" map="PolygonMini_Tex"/>
3131

3232
<model name="grassModel" src="/assets/models/SM_Env_Grass_01.fbx" materials="PolygonMini_Mat"/>
3333
<model name="PM_column" src="/assets/models/SM_Tile_Hex_Column_02.fbx" materials="PolygonMini_Mat"/>
@@ -37,23 +37,25 @@
3737
<asset-bundle name="PolygonDungeon" preload>
3838
<texture name="PolygonDungeon_Tex" src="/assets/textures/Dungeons_Texture_01.png"/>
3939

40-
<material name="PolygonDungeon_Mat" :factory="polygonDungeonFactory"/>
40+
<standard-material name="PolygonDungeon_Mat" map="PolygonDungeon_Tex"/>
4141

4242
<model name="PD_dandelion1" src="/assets/models/SM_Env_Tree_Dandelion_01.fbx" materials="PolygonDungeon_Mat"/>
4343
<model name="PD_dandelion2" src="/assets/models/SM_Env_Tree_Dandelion_02.fbx" materials="PolygonDungeon_Mat"/>
4444
<model name="PD_dandelion3" src="/assets/models/SM_Env_Tree_Dandelion_03.fbx" materials="PolygonDungeon_Mat"/>
4545
</asset-bundle>
4646

47+
48+
4749
<asset-bundle name="Crate" preload>
4850
<texture name="crateTex" src="/assets/textures/crate.jpg"/>
49-
<material name="cubeMat" :factory="cubeMaterialFactory"/>
51+
<standard-material name="cubeMat" map="crateTex"/>
5052
<geometry name="cube" :factory="cubeFactory"/>
5153
</asset-bundle>
5254

5355
<asset-bundle dependencies="Crate" name="Scene1" preload>
5456

5557
<geometry name="plane" :factory="planeFactory"/>
56-
<material name="waterMat" :factory="waterMaterialFactory"/>
58+
<standard-material name="waterMat" color="#9c9cff"/>
5759

5860
</asset-bundle>
5961

@@ -97,25 +99,25 @@
9799
<mesh model="grassModel" name="grass">
98100
<position :value="{ x: 10, y: 3, z: 10 }"/>
99101
<scale :value="{ x: 0.05, y: 0.05, z: 0.05 }"/>
100-
<shadows cast receive recursive/>
102+
<shadows cast receive deep/>
101103
</mesh>
102104

103105
<mesh model="PD_dandelion1">
104106
<position :value="{ x: -10, y: 3, z: 10 }"/>
105107
<!-- <scale :value="{ x: 0.05, y: 0.05, z: 0.05 }"/> -->
106-
<shadows cast receive recursive/>
108+
<shadows cast receive deep/>
107109
</mesh>
108110

109111
<group>
110112
<position :value="{ x: 10, y: 3, z: 10 }"/>
111113
<scale :value="{ x: 0.01, y: 0.01, z: 0.01 }"/>
112-
<shadows cast receive recursive/>
114+
<shadows cast receive/>
113115

114116
<mesh model="PM_column" name="column">
115-
<shadows cast receive recursive/>
117+
<shadows cast receive deep/>
116118
</mesh>
117119
<mesh model="PM_flat" name="flat_grass">
118-
<shadows cast receive recursive/>
120+
<shadows cast receive deep/>
119121
</mesh>
120122
</group>
121123

samples/views/HoverBehaviour.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Component, Mixins, Prop } from "vue-property-decorator";
22

3-
import { Behaviour } from "../../src";
3+
import { BehaviourComponent } from "../../src";
44

55
@Component
6-
export class HoverBehaviour extends Mixins(Behaviour) {
6+
export class HoverBehaviour extends Mixins(BehaviourComponent) {
77
@Prop({ required: true, type: Object })
88
public position!: { y: number };
99

samples/views/MyBehaviour.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as THREE from "three";
22
import { Component, Mixins, Prop } from "vue-property-decorator";
33

4-
import { Behaviour } from "../../src";
4+
import { BehaviourComponent } from "../../src";
55
import { OrbitControls } from "./OrbitControls";
66

77
interface Vec3 {
@@ -11,7 +11,7 @@ interface Vec3 {
1111
}
1212

1313
@Component
14-
export class MyBehaviour extends Mixins(Behaviour) {
14+
export class MyBehaviour extends Mixins(BehaviourComponent) {
1515
@Prop()
1616
public data!: {
1717
position: Vec3;

samples/views/StandardMaterial.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { MeshStandardMaterial, Texture } from "three";
2+
import { Component, Prop, Vue } from "vue-property-decorator";
3+
4+
import { Application, components, MaterialFactory } from "../../src";
5+
6+
const { Material } = components;
7+
8+
@Component({
9+
components: {
10+
Material
11+
}
12+
})
13+
export default class StandardMaterial extends Vue {
14+
@Prop({ required: true, type: String })
15+
public name!: string;
16+
17+
@Prop({ type: String })
18+
public map!: string;
19+
20+
@Prop({ type: String, default: "#ffffff" })
21+
public color!: string;
22+
23+
@Prop({ type: Number, default: 0.01 })
24+
public metalness!: number;
25+
26+
public factory: MaterialFactory | null = null;
27+
28+
public created() {
29+
this.factory = async (app: Application) => {
30+
let texture;
31+
if (this.map) {
32+
texture = await app.assets.textures.get(this.map);
33+
}
34+
35+
const mat = new MeshStandardMaterial({
36+
color: this.color,
37+
metalness: this.metalness
38+
});
39+
mat.map = texture as Texture;
40+
return mat;
41+
};
42+
}
43+
}

samples/views/StandardMaterial.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts" src="./StandardMaterial.ts"></script>
2+
3+
<template>
4+
<material :factory="factory" :name="name"/>
5+
</template>

0 commit comments

Comments
 (0)