1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00
This commit is contained in:
Kevin Levron 2021-03-03 22:58:09 +01:00
parent 1c0fb609e9
commit 11eb935b95
3 changed files with 13 additions and 15 deletions

View File

@ -9,13 +9,13 @@
"dependencies": { "dependencies": {
"gsap": "^3.5.1", "gsap": "^3.5.1",
"three": "^0.125", "three": "^0.125",
"vue": "3.0.5" "vue": "^3.0.7"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-buble": "^0.21.3", "@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-replace": "^2.3.3", "@rollup/plugin-replace": "^2.3.3",
"@vitejs/plugin-vue": "^1.1.4", "@vitejs/plugin-vue": "^1.1.4",
"@vue/compiler-sfc": "^3.0.5", "@vue/compiler-sfc": "^3.0.7",
"eslint": "^7.7.0", "eslint": "^7.7.0",
"eslint-config-airbnb-base": "^14.2.0", "eslint-config-airbnb-base": "^14.2.0",
"eslint-config-standard": "^14.1.1", "eslint-config-standard": "^14.1.1",
@ -27,7 +27,7 @@
"rollup-plugin-terser": "^7.0.2", "rollup-plugin-terser": "^7.0.2",
"rollup-plugin-vue": "^6.0.0-beta.10", "rollup-plugin-vue": "^6.0.0-beta.10",
"sass": "^1.26.10", "sass": "^1.26.10",
"vite": "^2.0.1" "vite": "^2.0.5"
}, },
"main": "build/trois.js", "main": "build/trois.js",
"module": "build/trois.module.js", "module": "build/trois.module.js",

View File

@ -1,15 +1,12 @@
import { Color } from 'three'; import { Color } from 'three';
import { inject, watch } from 'vue'; import { watch } from 'vue';
import { setFromProp } from '../tools.js'; import { setFromProp } from '../tools.js';
import useBindProp from '../use/useBindProp.js'; import useBindProp from '../use/useBindProp.js';
export default { export default {
inject: { inject: {
scene: 'scene', scene: 'scene',
parent: { group: { default: null },
from: 'group',
default: () => inject('scene'),
},
}, },
props: { props: {
color: { color: {
@ -29,6 +26,9 @@ export default {
}, },
// can't use setup because it will not be used in sub components // can't use setup because it will not be used in sub components
// setup() {}, // setup() {},
created() {
this.parent = this.group ? this.group : this.scene;
},
mounted() { mounted() {
useBindProp(this, 'position', this.light.position); useBindProp(this, 'position', this.light.position);

View File

@ -1,5 +1,5 @@
import { Mesh } from 'three'; import { Mesh } from 'three';
import { inject, watch } from 'vue'; import { watch } from 'vue';
import useBindProp from '../use/useBindProp.js'; import useBindProp from '../use/useBindProp.js';
export default { export default {
@ -7,10 +7,7 @@ export default {
three: 'three', three: 'three',
scene: 'scene', scene: 'scene',
rendererComponent: 'rendererComponent', rendererComponent: 'rendererComponent',
parent: { group: { default: null },
from: 'group',
default: () => inject('scene'),
},
}, },
emits: ['ready'], emits: ['ready'],
props: { props: {
@ -25,17 +22,18 @@ export default {
}, },
// can't use setup because it will not be used in sub components // can't use setup because it will not be used in sub components
// setup() {}, // setup() {},
created() {
this.parent = this.group ? this.group : this.scene;
},
provide() { provide() {
return { return {
mesh: this, mesh: this,
}; };
}, },
mounted() { mounted() {
// console.log('Mesh mounted');
if (this.geometry && !this.mesh) this.initMesh(); if (this.geometry && !this.mesh) this.initMesh();
}, },
unmounted() { unmounted() {
// console.log('Mesh unmounted');
if (this.mesh) { if (this.mesh) {
this.three.removeIntersectObject(this.mesh); this.three.removeIntersectObject(this.mesh);
this.parent.remove(this.mesh); this.parent.remove(this.mesh);