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

wip: geometries

This commit is contained in:
Kevin Levron 2021-04-18 22:25:24 +02:00
parent 216c44deaf
commit 5df3223bd6
18 changed files with 51 additions and 26 deletions

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { BoxGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { CircleGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { ConeGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { CylinderGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { DodecahedronGeometry } from 'three'
export const props = {

View File

@ -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({
inject: ['mesh'],
props: {
rotateX: Number,
rotateY: Number,
rotateZ: Number,
},
setup() {
return defaultSetup()
},
created() {
if (!this.mesh) {
console.error('Missing parent Mesh')
return
}
this.watchProps = []
Object.entries(this.$props).forEach(e => this.watchProps.push(e[0]))
this.createGeometry()
this.rotateGeometry()
this.mesh.setGeometry(this.geometry)
if (this.geometry) this.mesh.setGeometry(this.geometry)
this.addWatchers()
},
unmounted() {
this.geometry.dispose()
this.geometry?.dispose()
},
methods: {
createGeometry() {},
addWatchers() {
this.watchProps.forEach(prop => {
// @ts-ignore
watch(() => this[prop], () => {
this.refreshGeometry()
})
})
},
rotateGeometry() {
if (this.rotateX) this.geometry.rotateX(this.rotateX)
if (this.rotateY) this.geometry.rotateY(this.rotateY)
if (this.rotateZ) this.geometry.rotateZ(this.rotateZ)
if (this.rotateX) this.geometry?.rotateX(this.rotateX)
if (this.rotateY) this.geometry?.rotateY(this.rotateY)
if (this.rotateZ) this.geometry?.rotateZ(this.rotateZ)
},
refreshGeometry() {
const oldGeo = this.geometry
this.createGeometry()
this.rotateGeometry()
this.mesh.setGeometry(this.geometry)
oldGeo.dispose()
if (this.geometry) this.mesh?.setGeometry(this.geometry)
oldGeo?.dispose()
},
},
render() { return []; },
@ -55,10 +76,14 @@ export function geometryComponent(name, props, createGeometry) {
name,
extends: Geometry,
props,
setup() {
return defaultSetup()
},
methods: {
createGeometry() {
this.geometry = createGeometry(this)
},
},
// __hmrId: name,
})
}

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { IcosahedronGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { LatheGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { OctahedronGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { PlaneGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { PolyhedronGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { RingGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { SphereGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { TetrahedronGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { TorusGeometry } from 'three'
export const props = {

View File

@ -1,4 +1,4 @@
import { geometryComponent } from './Geometry.js'
import { geometryComponent } from './Geometry'
import { TorusKnotGeometry } from 'three'
export const props = {

View File

@ -1,6 +1,6 @@
import { defineComponent } from 'vue'
import { CatmullRomCurve3, Curve, TubeGeometry, Vector3 } from 'three'
import Geometry from './Geometry.js'
import Geometry from './Geometry'
export const props = {
points: Array,