1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

add geometries (generated code)

This commit is contained in:
Kevin Levron 2020-09-28 15:36:22 +02:00
parent 9c9c39a6fe
commit 15ba30e058
18 changed files with 245 additions and 46 deletions

View File

@ -4,23 +4,12 @@ import Geometry from './Geometry.js';
export default { export default {
extends: Geometry, extends: Geometry,
props: { props: {
size: { size: { type: Number },
type: Number, width: { type: Number, default: 1 },
height: { type: Number, default: 1 },
depth: { type: Number, default: 1 },
}, },
width: { created() {
type: Number,
default: 1,
},
height: {
type: Number,
default: 1,
},
depth: {
type: Number,
default: 1,
},
},
mounted() {
if (this.size) { if (this.size) {
this.parent.geometry = new BoxBufferGeometry(this.size, this.size, this.size); this.parent.geometry = new BoxBufferGeometry(this.size, this.size, this.size);
} else { } else {

View File

@ -0,0 +1,15 @@
import { CircleBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
segments: { type: Number, default: 8 },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
created() {
this.parent.geometry = new CircleBufferGeometry(this.radius, this.segments, this.thetaStart, this.thetaLength);
},
};

View File

@ -0,0 +1,18 @@
import { ConeBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
heightSegments: { type: Number, default: 1 },
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
created() {
this.parent.geometry = new ConeBufferGeometry(this.radius, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
},
};

View File

@ -0,0 +1,19 @@
import { CylinderBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radiusTop: { type: Number, default: 1 },
radiusBottom: { type: Number, default: 1 },
height: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 },
heightSegments: { type: Number, default: 1 },
openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
created() {
this.parent.geometry = new CylinderBufferGeometry(this.radiusTop, this.radiusBottom, this.height, this.radialSegments, this.heightSegments, this.openEnded, this.thetaStart, this.thetaLength);
},
};

View File

@ -0,0 +1,13 @@
import { DodecahedronBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created() {
this.parent.geometry = new DodecahedronBufferGeometry(this.radius, this.detail);
},
};

View File

@ -0,0 +1,13 @@
import { IcosahedronBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created() {
this.parent.geometry = new IcosahedronBufferGeometry(this.radius, this.detail);
},
};

View File

@ -0,0 +1,15 @@
import { LatheBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
points: Array,
segments: { type: Number, default: 12 },
phiStart: { type: Number, default: 0 },
phiLength: { type: Number, default: Math.PI * 2 },
},
created() {
this.parent.geometry = new LatheBufferGeometry(this.points, this.segments, this.phiStart, this.phiLength);
},
};

View File

@ -0,0 +1,13 @@
import { OctahedronBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created() {
this.parent.geometry = new OctahedronBufferGeometry(this.radius, this.detail);
},
};

View File

@ -0,0 +1,13 @@
import { PolyhedronBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created() {
this.parent.geometry = new PolyhedronBufferGeometry(this.radius, this.detail);
},
};

View File

@ -0,0 +1,17 @@
import { RingBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
innerRadius: { type: Number, default: 0.5 },
outerRadius: { type: Number, default: 1 },
thetaSegments: { type: Number, default: 8 },
phiSegments: { type: Number, default: 1 },
thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 },
},
created() {
this.parent.geometry = new RingBufferGeometry(this.innerRadius, this.outerRadius, this.thetaSegments, this.phiSegments, this.thetaStart, this.thetaLength);
},
};

View File

@ -5,16 +5,10 @@ export default {
extends: Geometry, extends: Geometry,
props: { props: {
radius: Number, radius: Number,
widthSegments: { widthSegments: { type: Number, default: 12 },
type: Number, heightSegments: { type: Number, default: 12 },
default: 12,
}, },
heightSegments: { created() {
type: Number,
default: 12,
},
},
mounted() {
this.parent.geometry = new SphereBufferGeometry(this.radius, this.widthSegments, this.heightSegments); this.parent.geometry = new SphereBufferGeometry(this.radius, this.widthSegments, this.heightSegments);
}, },
}; };

View File

@ -0,0 +1,13 @@
import { TetrahedronBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 },
},
created() {
this.parent.geometry = new TetrahedronBufferGeometry(this.radius, this.detail);
},
};

View File

@ -0,0 +1,16 @@
import { TorusBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
tube: { type: Number, default: 0.4 },
radialSegments: { type: Number, default: 8 },
tubularSegments: { type: Number, default: 6 },
arc: { type: Number, default: Math.PI * 2 },
},
created() {
this.parent.geometry = new TorusBufferGeometry(this.radius, this.tube, this.radialSegments, this.tubularSegments, this.arc);
},
};

View File

@ -0,0 +1,17 @@
import { TorusKnotBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
radius: { type: Number, default: 1 },
tube: { type: Number, default: 0.4 },
radialSegments: { type: Number, default: 64 },
tubularSegments: { type: Number, default: 8 },
p: { type: Number, default: 2 },
q: { type: Number, default: 3 },
},
created() {
this.parent.geometry = new TorusKnotBufferGeometry(this.radius, this.tube, this.radialSegments, this.tubularSegments, this.p, this.q);
},
};

View File

@ -0,0 +1,16 @@
import { Curve, TubeBufferGeometry } from 'three';
import Geometry from './Geometry.js';
export default {
extends: Geometry,
props: {
path: Curve,
tubularSegments: { type: Number, default: 64 },
radius: { type: Number, default: 1 },
radiusSegments: { type: Number, default: 8 },
closed: { type: Boolean, default: false },
},
created() {
this.parent.geometry = new TubeBufferGeometry(this.path, this.tubularSegments, this.radius, this.radiusSegments, this.closed);
},
};

View File

@ -1,2 +1,14 @@
export { default as BoxGeometry } from './BoxGeometry.js'; export { default as BoxGeometry } from './BoxGeometry.js';
export { default as CircleGeometry } from './CircleGeometry.js';
export { default as CylinderGeometry } from './CylinderGeometry.js';
export { default as DodecahedronGeometry } from './DodecahedronGeometry.js';
export { default as IcosahedronGeometry } from './IcosahedronGeometry.js';
export { default as LatheGeometry } from './LatheGeometry.js';
export { default as OctahedronGeometry } from './OctahedronGeometry.js';
export { default as PolyhedronGeometry } from './PolyhedronGeometry.js';
export { default as RingGeometry } from './RingGeometry.js';
export { default as SphereGeometry } from './SphereGeometry.js'; export { default as SphereGeometry } from './SphereGeometry.js';
export { default as TetrahedronGeometry } from './TetrahedronGeometry.js';
export { default as TorusGeometry } from './TorusGeometry.js';
export { default as TorusKnotGeometry } from './TorusKnotGeometry.js';
export { default as TubeGeometry } from './TubeGeometry.js';

View File

@ -1,33 +1,26 @@
import { BoxBufferGeometry } from 'three'; import { BoxBufferGeometry } from 'three';
import { watch } from 'vue';
import Mesh from './Mesh.js'; import Mesh from './Mesh.js';
export default { export default {
extends: Mesh, extends: Mesh,
props: { props: {
size: { size: { type: Number },
type: Number, width: { type: Number, default: 1 },
}, height: { type: Number, default: 1 },
width: { depth: { type: Number, default: 1 },
type: Number, widthSegments: { type: Number, default: 1 },
default: 1, heightSegments: { type: Number, default: 1 },
}, depthSegments: { type: Number, default: 1 },
height: {
type: Number,
default: 1,
},
depth: {
type: Number,
default: 1,
},
},
watch: {
size() { this.refreshGeometry(); },
width() { this.refreshGeometry(); },
height() { this.refreshGeometry(); },
depth() { this.refreshGeometry(); },
}, },
created() { created() {
this.createGeometry(); this.createGeometry();
['size', 'width', 'height', 'depth', 'widthSegments', 'heightSegments', 'depthSegments'].forEach(prop => {
watch(() => this[prop], () => {
this.refreshGeometry();
});
});
}, },
methods: { methods: {
createGeometry() { createGeometry() {

View File

@ -9,7 +9,20 @@ export const TroisJSVuePlugin = {
'Scene', 'Scene',
'BoxGeometry', 'BoxGeometry',
'CircleGeometry',
'ConeGeometry',
'CylinderGeometry',
'DodecahedronGeometry',
'IcosahedronGeometry',
'LatheGeometry',
'OctahedronGeometry',
'PolyhedronGeometry',
'RingGeometry',
'SphereGeometry', 'SphereGeometry',
'TetrahedronGeometry',
'TorusGeometry',
'TorusKnotGeometry',
'TubeGeometry',
'AmbientLight', 'AmbientLight',
'DirectionalLight', 'DirectionalLight',