mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
wip: geometries
This commit is contained in:
parent
216c44deaf
commit
5df3223bd6
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { BoxGeometry } from 'three'
|
import { BoxGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { CircleGeometry } from 'three'
|
import { CircleGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { ConeGeometry } from 'three'
|
import { ConeGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { CylinderGeometry } from 'three'
|
import { CylinderGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { DodecahedronGeometry } from 'three'
|
import { DodecahedronGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,48 +1,69 @@
|
|||||||
import { defineComponent, watch } from 'vue'
|
import { BufferGeometry } from 'three'
|
||||||
|
import { defineComponent, inject, watch } from 'vue'
|
||||||
|
|
||||||
|
interface MeshInterface {
|
||||||
|
setGeometry(geometry: BufferGeometry): void
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GeometryInterface {
|
||||||
|
geometry?: BufferGeometry
|
||||||
|
mesh?: MeshInterface
|
||||||
|
watchProps: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultSetup(): GeometryInterface {
|
||||||
|
const mesh = inject('mesh') as MeshInterface
|
||||||
|
const watchProps: string[] = []
|
||||||
|
return { mesh, watchProps }
|
||||||
|
}
|
||||||
|
|
||||||
const Geometry = defineComponent({
|
const Geometry = defineComponent({
|
||||||
inject: ['mesh'],
|
|
||||||
props: {
|
props: {
|
||||||
rotateX: Number,
|
rotateX: Number,
|
||||||
rotateY: Number,
|
rotateY: Number,
|
||||||
rotateZ: Number,
|
rotateZ: Number,
|
||||||
},
|
},
|
||||||
|
setup() {
|
||||||
|
return defaultSetup()
|
||||||
|
},
|
||||||
created() {
|
created() {
|
||||||
if (!this.mesh) {
|
if (!this.mesh) {
|
||||||
console.error('Missing parent Mesh')
|
console.error('Missing parent Mesh')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.watchProps = []
|
|
||||||
Object.entries(this.$props).forEach(e => this.watchProps.push(e[0]))
|
Object.entries(this.$props).forEach(e => this.watchProps.push(e[0]))
|
||||||
|
|
||||||
this.createGeometry()
|
this.createGeometry()
|
||||||
this.rotateGeometry()
|
this.rotateGeometry()
|
||||||
this.mesh.setGeometry(this.geometry)
|
if (this.geometry) this.mesh.setGeometry(this.geometry)
|
||||||
|
|
||||||
this.addWatchers()
|
this.addWatchers()
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
this.geometry.dispose()
|
this.geometry?.dispose()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
createGeometry() {},
|
||||||
addWatchers() {
|
addWatchers() {
|
||||||
this.watchProps.forEach(prop => {
|
this.watchProps.forEach(prop => {
|
||||||
|
// @ts-ignore
|
||||||
watch(() => this[prop], () => {
|
watch(() => this[prop], () => {
|
||||||
this.refreshGeometry()
|
this.refreshGeometry()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
rotateGeometry() {
|
rotateGeometry() {
|
||||||
if (this.rotateX) this.geometry.rotateX(this.rotateX)
|
if (this.rotateX) this.geometry?.rotateX(this.rotateX)
|
||||||
if (this.rotateY) this.geometry.rotateY(this.rotateY)
|
if (this.rotateY) this.geometry?.rotateY(this.rotateY)
|
||||||
if (this.rotateZ) this.geometry.rotateZ(this.rotateZ)
|
if (this.rotateZ) this.geometry?.rotateZ(this.rotateZ)
|
||||||
},
|
},
|
||||||
refreshGeometry() {
|
refreshGeometry() {
|
||||||
const oldGeo = this.geometry
|
const oldGeo = this.geometry
|
||||||
this.createGeometry()
|
this.createGeometry()
|
||||||
this.rotateGeometry()
|
this.rotateGeometry()
|
||||||
this.mesh.setGeometry(this.geometry)
|
if (this.geometry) this.mesh?.setGeometry(this.geometry)
|
||||||
oldGeo.dispose()
|
oldGeo?.dispose()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render() { return []; },
|
render() { return []; },
|
||||||
@ -55,10 +76,14 @@ export function geometryComponent(name, props, createGeometry) {
|
|||||||
name,
|
name,
|
||||||
extends: Geometry,
|
extends: Geometry,
|
||||||
props,
|
props,
|
||||||
|
setup() {
|
||||||
|
return defaultSetup()
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createGeometry() {
|
createGeometry() {
|
||||||
this.geometry = createGeometry(this)
|
this.geometry = createGeometry(this)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// __hmrId: name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { IcosahedronGeometry } from 'three'
|
import { IcosahedronGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { LatheGeometry } from 'three'
|
import { LatheGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { OctahedronGeometry } from 'three'
|
import { OctahedronGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { PlaneGeometry } from 'three'
|
import { PlaneGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { PolyhedronGeometry } from 'three'
|
import { PolyhedronGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { RingGeometry } from 'three'
|
import { RingGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { SphereGeometry } from 'three'
|
import { SphereGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { TetrahedronGeometry } from 'three'
|
import { TetrahedronGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { TorusGeometry } from 'three'
|
import { TorusGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { geometryComponent } from './Geometry.js'
|
import { geometryComponent } from './Geometry'
|
||||||
import { TorusKnotGeometry } from 'three'
|
import { TorusKnotGeometry } from 'three'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { defineComponent } from 'vue'
|
import { defineComponent } from 'vue'
|
||||||
import { CatmullRomCurve3, Curve, TubeGeometry, Vector3 } from 'three'
|
import { CatmullRomCurve3, Curve, TubeGeometry, Vector3 } from 'three'
|
||||||
import Geometry from './Geometry.js'
|
import Geometry from './Geometry'
|
||||||
|
|
||||||
export const props = {
|
export const props = {
|
||||||
points: Array,
|
points: Array,
|
||||||
|
Loading…
Reference in New Issue
Block a user