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

added loading models for 3D printing: 3MF and STL

This commit is contained in:
wannnwdooo 2023-07-18 16:44:23 +03:00
parent a1b1239809
commit 1831c11536
5 changed files with 41 additions and 0 deletions

View File

@ -15,6 +15,8 @@ const external = [
'three/examples/jsm/loaders/FontLoader.js',
'three/examples/jsm/loaders/FBXLoader.js',
'three/examples/jsm/loaders/GLTFLoader.js',
'three/examples/jsm/loaders/3MFLoader.js',
'three/examples/jsm/loaders/STLLoader.js',
'three/examples/jsm/postprocessing/BokehPass.js',
'three/examples/jsm/postprocessing/EffectComposer.js',
'three/examples/jsm/postprocessing/FilmPass.js',

15
src/models/3MF.ts Normal file
View File

@ -0,0 +1,15 @@
import { defineComponent } from "vue"
import Model from "./Model"
import { ThreeMFLoader } from "three/examples/jsm/loaders/3MFLoader"
export default defineComponent({
extends: Model,
created() {
const loader: ThreeMFLoader = new ThreeMFLoader()
this.$emit('before-load', loader)
loader.load(this.src, (threeMF) => {
this.onLoad(threeMF)
this.initObject3D(threeMF)
}, this.onProgress, this.onError)
},
})

20
src/models/STL.ts Normal file
View File

@ -0,0 +1,20 @@
import { defineComponent } from "vue"
import Model from "./Model"
import { STLLoader } from "three/examples/jsm/loaders/STLLoader"
import { Mesh, MeshLambertMaterial } from "three"
export default defineComponent({
extends: Model,
created() {
const loader: STLLoader = new STLLoader()
this.$emit('before-load', loader)
loader.load(this.src, (geometry) => {
const object3D = new Mesh(geometry, new MeshLambertMaterial())
object3D.userData.component = this
object3D.geometry = geometry
this.onLoad(object3D)
this.initObject3D(object3D)
}, this.onProgress, this.onError)
},
})

View File

@ -1,2 +1,4 @@
export { default as GltfModel } from './GLTF'
export { default as FbxModel } from './FBX'
export { default as ThreeMFModel } from './3MF'
export { default as StlModel } from './STL'

View File

@ -64,6 +64,8 @@ export const TroisJSVuePlugin = {
'FbxModel',
'GltfModel',
'ThreeMFModel',
'StlModel',
'BokehPass',
'EffectComposer',