diff --git a/package.json b/package.json index 181ab7e..b25df1b 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,15 @@ { - "name": "trois", - "version": "0.0.1", + "name": "troisjs", + "version": "0.0.5", "scripts": { "dev": "vite", - "build": "vite build" + "build": "vite build", + "rollup": "rollup -c" }, "dependencies": { - "three": "^0.119", - "vue": "^3.0.0-rc.10", - "vuex": "^4.0.0-beta.4" + "three": "^0.119" }, "devDependencies": { - "@vue/compiler-sfc": "^3.0.0-rc.10", "eslint": "^7.7.0", "eslint-config-airbnb-base": "^14.2.0", "eslint-config-standard": "^14.1.1", @@ -21,9 +19,11 @@ "eslint-plugin-standard": "^4.0.1", "eslint-plugin-vue": "^6.2.2", "sass": "^1.26.10", - "vite": "^1.0.0-rc.4" + "vite": "^1.0.0-rc.4", + "vue": "^3.0.0-rc.10" }, - "main": "src/index.js", + "main": "dist/trois.js", + "module": "dist/trois.module.js", "repository": { "type": "git", "url": "git+https://github.com/troisjs/trois.git" diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..e6edb5a --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,65 @@ +import commonjs from '@rollup/plugin-commonjs'; +import vue from 'rollup-plugin-vue'; +import buble from '@rollup/plugin-buble'; +import { terser } from "rollup-plugin-terser"; + +const input = 'src/index.js'; +const external = ['three', 'three/examples/jsm/controls/OrbitControls.js', 'vue']; +const plugins = [ + commonjs(), + vue(), + buble({ + transforms: { forOf: false }, + }), +]; + +export default [ + { + input, + external, + output: { + format: 'es', + exports: 'named', + file: 'build/trois.module.js', + sourcemap: true, + }, + plugins, + }, + { + input, + external, + output: { + format: 'es', + exports: 'named', + file: 'build/trois.module.min.js', + sourcemap: true, + }, + plugins: [ + ...plugins, + terser(), + ], + }, + { + input, + external, + output: { + format: 'cjs', + file: 'dist/trois.js', + sourcemap: true, + }, + plugins, + }, + { + input, + external, + output: { + format: 'cjs', + file: 'dist/trois.min.js', + sourcemap: true, + }, + plugins: [ + ...plugins, + terser(), + ], + }, +]; diff --git a/src/core/Renderer.vue b/src/core/Renderer.js similarity index 91% rename from src/core/Renderer.vue rename to src/core/Renderer.js index 44a7479..b39ed1b 100644 --- a/src/core/Renderer.vue +++ b/src/core/Renderer.js @@ -1,10 +1,4 @@ - - - - - diff --git a/src/core/Scene.js b/src/core/Scene.js index 455d7cf..c239cbb 100644 --- a/src/core/Scene.js +++ b/src/core/Scene.js @@ -17,7 +17,9 @@ export default { }; }, mounted() { - this.three.scene = this.scene; + if (!this.three.scene) { + this.three.scene = this.scene; + } }, render() { if (this.$slots.default) { diff --git a/src/core/index.js b/src/core/index.js index 7231343..1574d00 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,4 +1,4 @@ -export { default as Renderer } from './Renderer.vue'; +export { default as Renderer } from './Renderer.js'; export { default as PerspectiveCamera } from './PerspectiveCamera.js'; export { default as Camera } from './PerspectiveCamera.js'; export { default as Scene } from './Scene.js'; diff --git a/src/index.js b/src/index.js index 16e7623..814c7be 100644 --- a/src/index.js +++ b/src/index.js @@ -3,3 +3,4 @@ export * from './geometries/index.js'; export * from './lights/index.js'; export * from './materials/index.js'; export * from './meshes/index.js'; +export * from './tools.js'; diff --git a/src/tools.js b/src/tools.js index e25ca1e..bd4b719 100644 --- a/src/tools.js +++ b/src/tools.js @@ -5,3 +5,9 @@ export function setFromProp(o, prop) { } } }; + +export function lerp(value1, value2, amount) { + amount = amount < 0 ? 0 : amount; + amount = amount > 1 ? 1 : amount; + return value1 + (value2 - value1) * amount; +};