Skip to content

Commit 857e29f

Browse files
author
Sascha Braun
committed
add grid and axes helper components
increment package version
1 parent ed88f87 commit 857e29f

File tree

6 files changed

+126
-7
lines changed

6 files changed

+126
-7
lines changed

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
},
1212
snapshotSerializers: ["jest-serializer-vue"],
1313
testMatch: [
14-
"**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
14+
"**/tests/unit/**/*.spec.(ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
1515
],
1616
testURL: "http://localhost/"
1717
};

package.json

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

samples/views/Demo.vue

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@
2626

2727
<fog exp2/>
2828

29-
<camera name="mainCamera" :factory="cameraFactory">
29+
<camera :factory="cameraFactory">
3030
<position :value="scene1.camera.position"/>
3131
<rotation :value="scene1.camera.rotation" rad/>
3232

3333
<my-behaviour :data="scene1.camera"/>
3434
</camera>
3535

36-
<light name="light" :factory="lightFactory">
36+
<light name="sun" :factory="lightFactory">
3737
<position :value="{x: 0, y: 10, z: 0}"/>
3838
<shadows cast/>
3939
</light>
4040

41-
<group name="group">
42-
<position :value="{ x: 0, y: 0, z: 0 }"/>
41+
<grid/>
42+
<axes/>
43+
44+
<group>
45+
<position :value="{ x: 0, y: -1, z: 0 }"/>
4346

4447
<mesh name="waterPlane" geometry="plane" material="waterMat">
4548
<rotation :value="{ x: -90, y: 0, z: 0 }"/>
@@ -48,7 +51,6 @@
4851

4952
<mesh v-for="field in scene1.fields"
5053
:key="field.id"
51-
:name="'field-'+field.id"
5254
geometry="cube"
5355
material="cubeMat"
5456
>

src/components/Axes.tsx

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as THREE from "three";
2+
import { Component, Mixins, Prop, Provide } from "vue-property-decorator";
3+
4+
import { AssetTypes, GeometryType, MaterialType } from "../types";
5+
import { ThreeComponent, ThreeObjectComponent, ThreeSceneComponent } from "./base";
6+
7+
@Component
8+
export class Axes extends Mixins(
9+
ThreeComponent,
10+
ThreeSceneComponent,
11+
ThreeObjectComponent
12+
) {
13+
@Prop({ type: String, default: "" })
14+
private name!: string;
15+
16+
@Prop({ type: Number, default: 1 })
17+
private size!: number;
18+
19+
@Provide("object")
20+
private provideObject = this.getObject;
21+
22+
private m_axes!: THREE.AxesHelper;
23+
private m_created = false;
24+
25+
public getObject(): THREE.Object3D {
26+
return this.m_axes;
27+
}
28+
29+
public async created() {
30+
if (!this.scene && !this.object) {
31+
throw new Error(
32+
"Grid component can only be added as child to an object or mesh component"
33+
);
34+
}
35+
36+
this.m_axes = new THREE.AxesHelper(this.size);
37+
this.m_axes.name = this.name;
38+
39+
const parent = this.object ? this.object() : this.scene();
40+
parent.add(this.m_axes);
41+
42+
this.m_created = true;
43+
}
44+
45+
public beforeDestroy() {
46+
const parent = this.object ? this.object() : this.scene();
47+
parent.remove(this.m_axes);
48+
}
49+
50+
public render(h: any) {
51+
if (!this.m_created) {
52+
return null;
53+
}
54+
return <div>{this.$slots.default}</div>;
55+
}
56+
}

src/components/Grid.tsx

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as THREE from "three";
2+
import { Component, Mixins, Prop, Provide } from "vue-property-decorator";
3+
4+
import { AssetTypes, GeometryType, MaterialType } from "../types";
5+
import { ThreeComponent, ThreeObjectComponent, ThreeSceneComponent } from "./base";
6+
7+
@Component
8+
export class Grid extends Mixins(
9+
ThreeComponent,
10+
ThreeSceneComponent,
11+
ThreeObjectComponent
12+
) {
13+
@Prop({ type: String, default: "" })
14+
private name!: string;
15+
16+
@Prop({ type: Number, default: 10 })
17+
private size!: number;
18+
19+
@Prop({ type: Number, default: 10 })
20+
private divisions!: number;
21+
22+
@Provide("object")
23+
private provideObject = this.getObject;
24+
25+
private m_grid!: THREE.GridHelper;
26+
private m_created = false;
27+
28+
public getObject(): THREE.Object3D {
29+
return this.m_grid;
30+
}
31+
32+
public async created() {
33+
if (!this.scene && !this.object) {
34+
throw new Error(
35+
"Grid component can only be added as child to an object or mesh component"
36+
);
37+
}
38+
39+
this.m_grid = new THREE.GridHelper(this.size, this.divisions);
40+
this.m_grid.name = this.name;
41+
42+
const parent = this.object ? this.object() : this.scene();
43+
parent.add(this.m_grid);
44+
45+
this.m_created = true;
46+
}
47+
48+
public beforeDestroy() {
49+
const parent = this.object ? this.object() : this.scene();
50+
parent.remove(this.m_grid);
51+
}
52+
53+
public render(h: any) {
54+
if (!this.m_created) {
55+
return null;
56+
}
57+
return <div>{this.$slots.default}</div>;
58+
}
59+
}

src/components/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ export * from "./Camera";
88
export * from "./Light";
99
export * from "./Fog";
1010
export * from "./Group";
11+
export * from "./Grid";
12+
export * from "./Axes";
1113

1214
export * from "./properties";

0 commit comments

Comments
 (0)