1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-23 20:02:32 +08:00

defineComponent for meshes and simplify (#10)

This commit is contained in:
Kevin Levron 2021-04-03 22:54:11 +02:00
parent 885268fede
commit 168289c641
25 changed files with 94 additions and 265 deletions

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/BoxGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Box',
};
export default meshComponent('Box', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/CircleGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Circle',
};
export default meshComponent('Circle', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/ConeGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Cone',
};
export default meshComponent('Cone', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/CylinderGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Cylinder',
};
export default meshComponent('Cylinder', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/DodecahedronGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Dodecahedron',
};
export default meshComponent('Dodecahedron', props, createGeometry);

View File

@ -1,3 +1,4 @@
import { defineComponent } from 'vue';
import {
BackSide,
CubeCamera,
@ -10,7 +11,7 @@ import {
import Mesh from './Mesh.js';
import { bindProp } from '../tools';
export default {
export default defineComponent({
extends: Mesh,
props: {
cubeRTSize: { type: Number, default: 256 },
@ -69,4 +70,4 @@ export default {
},
},
__hmrId: 'Gem',
};
});

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/IcosahedronGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Icosahedron',
};
export default meshComponent('Icosahedron', props, createGeometry);

View File

@ -1,8 +1,8 @@
import { defineComponent, watch } from 'vue';
import { DoubleSide, MeshBasicMaterial, PlaneGeometry, TextureLoader } from 'three';
import { watch } from 'vue';
import Mesh from './Mesh.js';
export default {
export default defineComponent({
emits: ['loaded'],
extends: Mesh,
props: {
@ -66,4 +66,4 @@ export default {
},
},
__hmrId: 'Image',
};
});

View File

@ -1,9 +1,10 @@
import { defineComponent } from 'vue';
import { InstancedMesh } from 'three';
import Object3D from '../core/Object3D';
import { bindProp } from '../tools';
import { pointerProps } from './Mesh';
export default {
export default defineComponent({
extends: Object3D,
props: {
castShadow: Boolean,
@ -60,4 +61,4 @@ export default {
}
},
__hmrId: 'InstancedMesh',
};
});

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/LatheGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Lathe',
};
export default meshComponent('Lathe', props, createGeometry);

View File

@ -1,5 +1,5 @@
import { watch } from 'vue';
import { Mesh } from 'three';
import { defineComponent, watch } from 'vue';
import { Mesh as TMesh } from 'three';
import Object3D from '../core/Object3D.js';
import { bindProp } from '../tools';
@ -13,7 +13,7 @@ export const pointerProps = {
onClick: Function,
};
export default {
const Mesh = defineComponent({
name: 'Mesh',
extends: Object3D,
props: {
@ -33,7 +33,7 @@ export default {
},
methods: {
initMesh() {
this.mesh = new Mesh(this.geometry, this.material);
this.mesh = new TMesh(this.geometry, this.material);
this.mesh.component = this;
bindProp(this, 'castShadow', this.mesh);
@ -81,4 +81,24 @@ export default {
if (this.geometry) this.geometry.dispose();
},
__hmrId: 'Mesh',
});
export default Mesh;
export function meshComponent(name, props, createGeometry) {
return defineComponent({
name,
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: name,
});
};

View File

@ -1,3 +1,4 @@
import { defineComponent } from 'vue';
import {
CubeCamera,
LinearMipmapLinearFilter,
@ -6,7 +7,7 @@ import {
} from 'three';
import Mesh from './Mesh.js';
export default {
export default defineComponent({
extends: Mesh,
props: {
cubeRTSize: { type: Number, default: 256 },
@ -39,4 +40,4 @@ export default {
},
},
__hmrId: 'MirrorMesh',
};
});

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/OctahedronGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Octahedron',
};
export default meshComponent('Octahedron', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/PlaneGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Plane',
};
export default meshComponent('Plane', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/PolyhedronGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Polyhedron',
};
export default meshComponent('Polyhedron', props, createGeometry);

View File

@ -1,3 +1,4 @@
import { defineComponent } from 'vue';
import {
CubeCamera,
CubeRefractionMapping,
@ -8,7 +9,7 @@ import {
import Mesh from './Mesh.js';
import { bindProp } from '../tools';
export default {
export default defineComponent({
extends: Mesh,
props: {
cubeRTSize: { type: Number, default: 256 },
@ -44,4 +45,4 @@ export default {
},
},
__hmrId: 'RefractionMesh',
};
});

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/RingGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Ring',
};
export default meshComponent('Ring', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/SphereGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Sphere',
};
export default meshComponent('Sphere', props, createGeometry);

View File

@ -1,7 +1,8 @@
import { defineComponent } from 'vue';
import { Sprite, SpriteMaterial, TextureLoader } from 'three';
import Object3D from '../core/Object3D.js';
export default {
export default defineComponent({
extends: Object3D,
emits: ['loaded'],
props: {
@ -50,4 +51,4 @@ export default {
},
},
__hmrId: 'Sprite',
};
});

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/TetrahedronGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Tetrahedron',
};
export default meshComponent('Tetrahedron', props, createGeometry);

View File

@ -1,13 +1,25 @@
import { defineComponent, watch } from 'vue';
import { FontLoader, TextGeometry } from 'three';
import { watch } from 'vue';
import Mesh from './Mesh.js';
import TextProps from './TextProps.js';
export default {
const props = {
text: String,
fontSrc: String,
size: { type: Number, default: 80 },
height: { type: Number, default: 5 },
depth: { type: Number, default: 1 },
curveSegments: { type: Number, default: 12 },
bevelEnabled: { type: Boolean, default: false },
bevelThickness: { type: Number, default: 10 },
bevelSize: { type: Number, default: 8 },
bevelOffset: { type: Number, default: 0 },
bevelSegments: { type: Number, default: 5 },
align: { type: [Boolean, String], default: false },
};
export default defineComponent({
extends: Mesh,
props: {
...TextProps,
},
props,
data() {
return {
loading: true,
@ -54,4 +66,4 @@ export default {
}
},
},
};
});

View File

@ -1,14 +0,0 @@
export default {
text: String,
fontSrc: String,
size: { type: Number, default: 80 },
height: { type: Number, default: 5 },
depth: { type: Number, default: 1 },
curveSegments: { type: Number, default: 12 },
bevelEnabled: { type: Boolean, default: false },
bevelThickness: { type: Number, default: 10 },
bevelSize: { type: Number, default: 8 },
bevelOffset: { type: Number, default: 0 },
bevelSegments: { type: Number, default: 5 },
align: { type: [Boolean, String], default: false },
};

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/TorusGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'Torus',
};
export default meshComponent('Torus', props, createGeometry);

View File

@ -1,17 +1,4 @@
import Mesh from './Mesh.js';
import { meshComponent } from './Mesh.js';
import { props, createGeometry } from '../geometries/TorusKnotGeometry.js';
export default {
extends: Mesh,
props,
created() {
this.createGeometry();
this.addGeometryWatchers(props);
},
methods: {
createGeometry() {
this.geometry = createGeometry(this);
},
},
__hmrId: 'TorusKnot',
};
export default meshComponent('TorusKnot', props, createGeometry);

View File

@ -1,7 +1,8 @@
import { defineComponent } from 'vue';
import Mesh from './Mesh.js';
import { props, createGeometry, updateTubeGeometryPoints } from '../geometries/TubeGeometry.js';
export default {
export default defineComponent({
extends: Mesh,
props,
created() {
@ -18,4 +19,4 @@ export default {
},
},
__hmrId: 'Tube',
};
});