diff --git a/rollup.config.js b/rollup.config.js index b773ac1..92d614d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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', diff --git a/src/models/3MF.ts b/src/models/3MF.ts new file mode 100644 index 0000000..fe62114 --- /dev/null +++ b/src/models/3MF.ts @@ -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) + }, +}) diff --git a/src/models/STL.ts b/src/models/STL.ts new file mode 100644 index 0000000..922d7c0 --- /dev/null +++ b/src/models/STL.ts @@ -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) + }, +}) diff --git a/src/models/index.ts b/src/models/index.ts index c7a438f..aced1a7 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -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' diff --git a/src/plugin.ts b/src/plugin.ts index 5c3fbac..bfca047 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -64,6 +64,8 @@ export const TroisJSVuePlugin = { 'FbxModel', 'GltfModel', + 'ThreeMFModel', + 'StlModel', 'BokehPass', 'EffectComposer',