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

improve geometries ts

This commit is contained in:
Kevin Levron 2021-04-26 18:36:37 +02:00
parent 0a8f1ee88f
commit f70bbaebef
17 changed files with 23 additions and 23 deletions

View File

@ -9,7 +9,7 @@ export const props = {
widthSegments: { type: Number, default: 1 }, widthSegments: { type: Number, default: 1 },
heightSegments: { type: Number, default: 1 }, heightSegments: { type: Number, default: 1 },
depthSegments: { type: Number, default: 1 }, depthSegments: { type: Number, default: 1 },
} } as const
export function createGeometry(comp: any): BoxGeometry { export function createGeometry(comp: any): BoxGeometry {
if (comp.size) { if (comp.size) {

View File

@ -6,7 +6,7 @@ export const props = {
segments: { type: Number, default: 8 }, segments: { type: Number, default: 8 },
thetaStart: { type: Number, default: 0 }, thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 }, thetaLength: { type: Number, default: Math.PI * 2 },
} } as const
export function createGeometry(comp: any): CircleGeometry { export function createGeometry(comp: any): CircleGeometry {
return new CircleGeometry(comp.radius, comp.segments, comp.thetaStart, comp.thetaLength) return new CircleGeometry(comp.radius, comp.segments, comp.thetaStart, comp.thetaLength)

View File

@ -9,7 +9,7 @@ export const props = {
openEnded: { type: Boolean, default: false }, openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 }, thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 }, thetaLength: { type: Number, default: Math.PI * 2 },
} } as const
export function createGeometry(comp: any): ConeGeometry { export function createGeometry(comp: any): ConeGeometry {
return new ConeGeometry(comp.radius, comp.height, comp.radialSegments, comp.heightSegments, comp.openEnded, comp.thetaStart, comp.thetaLength) return new ConeGeometry(comp.radius, comp.height, comp.radialSegments, comp.heightSegments, comp.openEnded, comp.thetaStart, comp.thetaLength)

View File

@ -10,7 +10,7 @@ export const props = {
openEnded: { type: Boolean, default: false }, openEnded: { type: Boolean, default: false },
thetaStart: { type: Number, default: 0 }, thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 }, thetaLength: { type: Number, default: Math.PI * 2 },
} } as const
export function createGeometry(comp: any): CylinderGeometry { export function createGeometry(comp: any): CylinderGeometry {
return new CylinderGeometry(comp.radiusTop, comp.radiusBottom, comp.height, comp.radialSegments, comp.heightSegments, comp.openEnded, comp.thetaStart, comp.thetaLength) return new CylinderGeometry(comp.radiusTop, comp.radiusBottom, comp.height, comp.radialSegments, comp.heightSegments, comp.openEnded, comp.thetaStart, comp.thetaLength)

View File

@ -4,7 +4,7 @@ import { DodecahedronGeometry } from 'three'
export const props = { export const props = {
radius: { type: Number, default: 1 }, radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 }, detail: { type: Number, default: 0 },
} } as const
export function createGeometry(comp: any): DodecahedronGeometry { export function createGeometry(comp: any): DodecahedronGeometry {
return new DodecahedronGeometry(comp.radius, comp.detail) return new DodecahedronGeometry(comp.radius, comp.detail)

View File

@ -1,5 +1,5 @@
import { ComponentPropsOptions, defineComponent, watch } from 'vue'
import { BufferGeometry } from 'three' import { BufferGeometry } from 'three'
import { defineComponent, inject, watch } from 'vue'
import { MeshInjectionKey, MeshInterface } from '../meshes/Mesh' import { MeshInjectionKey, MeshInterface } from '../meshes/Mesh'
export interface GeometrySetupInterface { export interface GeometrySetupInterface {
@ -66,20 +66,20 @@ const Geometry = defineComponent({
export default Geometry export default Geometry
// @ts-ignore // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function geometryComponent(name, props, createGeometry) { export function geometryComponent<P extends Readonly<ComponentPropsOptions>>(
name: string,
props: P,
createGeometry: {(c: any): BufferGeometry}
) {
return defineComponent({ return defineComponent({
name, name,
extends: Geometry, extends: Geometry,
props, props,
setup(): GeometrySetupInterface {
return {}
},
methods: { methods: {
createGeometry() { createGeometry() {
this.geometry = createGeometry(this) this.geometry = createGeometry(this)
}, },
}, },
// __hmrId: name,
}) })
} }

View File

@ -4,7 +4,7 @@ import { IcosahedronGeometry } from 'three'
export const props = { export const props = {
radius: { type: Number, default: 1 }, radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 }, detail: { type: Number, default: 0 },
} } as const
export function createGeometry(comp: any): IcosahedronGeometry { export function createGeometry(comp: any): IcosahedronGeometry {
return new IcosahedronGeometry(comp.radius, comp.detail) return new IcosahedronGeometry(comp.radius, comp.detail)

View File

@ -6,7 +6,7 @@ export const props = {
segments: { type: Number, default: 12 }, segments: { type: Number, default: 12 },
phiStart: { type: Number, default: 0 }, phiStart: { type: Number, default: 0 },
phiLength: { type: Number, default: Math.PI * 2 }, phiLength: { type: Number, default: Math.PI * 2 },
} } as const
export function createGeometry(comp: any): LatheGeometry { export function createGeometry(comp: any): LatheGeometry {
return new LatheGeometry(comp.points, comp.segments, comp.phiStart, comp.phiLength) return new LatheGeometry(comp.points, comp.segments, comp.phiStart, comp.phiLength)

View File

@ -4,7 +4,7 @@ import { OctahedronGeometry } from 'three'
export const props = { export const props = {
radius: { type: Number, default: 1 }, radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 }, detail: { type: Number, default: 0 },
} } as const
export function createGeometry(comp: any): OctahedronGeometry { export function createGeometry(comp: any): OctahedronGeometry {
return new OctahedronGeometry(comp.radius, comp.detail) return new OctahedronGeometry(comp.radius, comp.detail)

View File

@ -6,7 +6,7 @@ export const props = {
height: { type: Number, default: 1 }, height: { type: Number, default: 1 },
widthSegments: { type: Number, default: 1 }, widthSegments: { type: Number, default: 1 },
heightSegments: { type: Number, default: 1 }, heightSegments: { type: Number, default: 1 },
} } as const
export function createGeometry(comp: any): PlaneGeometry { export function createGeometry(comp: any): PlaneGeometry {
return new PlaneGeometry(comp.width, comp.height, comp.widthSegments, comp.heightSegments) return new PlaneGeometry(comp.width, comp.height, comp.widthSegments, comp.heightSegments)

View File

@ -6,7 +6,7 @@ export const props = {
indices: Array, indices: Array,
radius: { type: Number, default: 1 }, radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 }, detail: { type: Number, default: 0 },
} } as const
export function createGeometry(comp: any): PolyhedronGeometry { export function createGeometry(comp: any): PolyhedronGeometry {
return new PolyhedronGeometry(comp.vertices, comp.indices, comp.radius, comp.detail) return new PolyhedronGeometry(comp.vertices, comp.indices, comp.radius, comp.detail)

View File

@ -8,7 +8,7 @@ export const props = {
phiSegments: { type: Number, default: 1 }, phiSegments: { type: Number, default: 1 },
thetaStart: { type: Number, default: 0 }, thetaStart: { type: Number, default: 0 },
thetaLength: { type: Number, default: Math.PI * 2 }, thetaLength: { type: Number, default: Math.PI * 2 },
} } as const
export function createGeometry(comp: any): RingGeometry { export function createGeometry(comp: any): RingGeometry {
return new RingGeometry(comp.innerRadius, comp.outerRadius, comp.thetaSegments, comp.phiSegments, comp.thetaStart, comp.thetaLength) return new RingGeometry(comp.innerRadius, comp.outerRadius, comp.thetaSegments, comp.phiSegments, comp.thetaStart, comp.thetaLength)

View File

@ -5,7 +5,7 @@ export const props = {
radius: { type: Number, default: 1 }, radius: { type: Number, default: 1 },
widthSegments: { type: Number, default: 12 }, widthSegments: { type: Number, default: 12 },
heightSegments: { type: Number, default: 12 }, heightSegments: { type: Number, default: 12 },
} } as const
export function createGeometry(comp: any): SphereGeometry { export function createGeometry(comp: any): SphereGeometry {
return new SphereGeometry(comp.radius, comp.widthSegments, comp.heightSegments) return new SphereGeometry(comp.radius, comp.widthSegments, comp.heightSegments)

View File

@ -4,7 +4,7 @@ import { TetrahedronGeometry } from 'three'
export const props = { export const props = {
radius: { type: Number, default: 1 }, radius: { type: Number, default: 1 },
detail: { type: Number, default: 0 }, detail: { type: Number, default: 0 },
} } as const
export function createGeometry(comp: any): TetrahedronGeometry { export function createGeometry(comp: any): TetrahedronGeometry {
return new TetrahedronGeometry(comp.radius, comp.detail) return new TetrahedronGeometry(comp.radius, comp.detail)

View File

@ -7,7 +7,7 @@ export const props = {
radialSegments: { type: Number, default: 8 }, radialSegments: { type: Number, default: 8 },
tubularSegments: { type: Number, default: 6 }, tubularSegments: { type: Number, default: 6 },
arc: { type: Number, default: Math.PI * 2 }, arc: { type: Number, default: Math.PI * 2 },
} } as const
export function createGeometry(comp: any): TorusGeometry { export function createGeometry(comp: any): TorusGeometry {
return new TorusGeometry(comp.radius, comp.tube, comp.radialSegments, comp.tubularSegments, comp.arc) return new TorusGeometry(comp.radius, comp.tube, comp.radialSegments, comp.tubularSegments, comp.arc)

View File

@ -8,7 +8,7 @@ export const props = {
radialSegments: { type: Number, default: 8 }, radialSegments: { type: Number, default: 8 },
p: { type: Number, default: 2 }, p: { type: Number, default: 2 },
q: { type: Number, default: 3 }, q: { type: Number, default: 3 },
} } as const
export function createGeometry(comp: any): TorusKnotGeometry { export function createGeometry(comp: any): TorusKnotGeometry {
return new TorusKnotGeometry(comp.radius, comp.tube, comp.tubularSegments, comp.radialSegments, comp.p, comp.q) return new TorusKnotGeometry(comp.radius, comp.tube, comp.tubularSegments, comp.radialSegments, comp.p, comp.q)

View File

@ -9,7 +9,7 @@ export const props = {
radius: { type: Number, default: 1 }, radius: { type: Number, default: 1 },
radialSegments: { type: Number, default: 8 }, radialSegments: { type: Number, default: 8 },
closed: { type: Boolean, default: false }, closed: { type: Boolean, default: false },
} } as const
export function createGeometry(comp: any): TubeGeometry { export function createGeometry(comp: any): TubeGeometry {
let curve let curve