UNPKG

whs-cube-spheres

Version:

This plugin has a container with multiple spheres.

58 lines (46 loc) 1.19 kB
import { Mesh, TetrahedronBufferGeometry, TetrahedronGeometry } from 'three'; import {MeshComponent} from '../../core/MeshComponent'; class Tetrahedron extends MeshComponent { static defaults = { ...MeshComponent.defaults, geometry: { radius: 1, detail: 0 }, physics: { create: false } }; static instructions = { ...MeshComponent.instructions, geometry: ['radius', 'detail'] }; constructor(params = {}) { super(params, Tetrahedron.defaults, Tetrahedron.instructions); if (params.build) { this.build(params); super.wrap(); } } build(params = this.params) { const {geometry, material} = this.applyBridge({ geometry: this.buildGeometry(params), material: params.material }); return this.applyBridge({mesh: new Mesh(geometry, material)}).mesh; } buildGeometry(params = {}) { const GConstruct = params.buffer && !params.softbody ? TetrahedronBufferGeometry : TetrahedronGeometry; return new GConstruct( params.geometry.radius, params.geometry.detail ); } } export { Tetrahedron };