|
| 1 | +await loadJs([ |
| 2 | + 'https://unpkg.com/[email protected]/dist/vue.min.js', |
| 3 | + // 'https://unpkg.com/[email protected]/build/three.min.js', |
| 4 | + 'https://unpkg.com/[email protected]/build/three.min.js', |
| 5 | +]) |
| 6 | + |
| 7 | +// await loadJs('https://unpkg.com/[email protected]/lib/VueThreejs.umd.min.js') |
| 8 | +await loadJs('https://unpkg.com/[email protected]/lib/VueThreejs.umd.js') |
| 9 | + |
| 10 | +appendCss(` |
| 11 | +#mountNode { overflow:hidden; background-color:black } |
| 12 | +`) |
| 13 | + |
| 14 | +Vue.use(VueThreejs) |
| 15 | + |
| 16 | +let Cube = Vue.extend({ |
| 17 | + props: { size: Number, texture: String }, |
| 18 | + template: ` |
| 19 | + <mesh name="Cube" v-bind="$attrs"> |
| 20 | + <geometry type="Box" :args="[size, size, size]"></geometry> |
| 21 | + <material type="MeshBasic"> |
| 22 | + <texture :url="\`https://fritx.github.io/vue-threejs/static/textures/\${texture}.png\`"></texture> |
| 23 | + </material> |
| 24 | + </mesh> |
| 25 | + `, |
| 26 | +}) |
| 27 | + |
| 28 | +let App = { |
| 29 | + components: { Cube }, |
| 30 | + template: ` |
| 31 | + <div class="container"> |
| 32 | + <renderer :size="bg.size"> |
| 33 | + <scene> |
| 34 | + <orbit-controls :position="{ x: 9, y: 21, z: 20 }" :rotation="{ x: 2, y: 0, z: 3 }"> |
| 35 | + <camera></camera> |
| 36 | + </orbit-controls> |
| 37 | + <light :hex="0xefefff" :intensity="2" :position="{ x: 50, y: 50, z: 50 }"></light> |
| 38 | + <light :hex="0xefefff" :intensity="2" :position="{ x: -50, y: -50, z: -50 }"></light> |
| 39 | + <div :key="ui.sysKey"> |
| 40 | + <movement-system> |
| 41 | + <mass-object :rv0="{ x: 2, y: 2 }" :v0="{ x: 10 }" |
| 42 | + :f="{ x: -3, y: -2 }" :m="1"> |
| 43 | + <cube texture="cobblestone" :size="1"></cube> |
| 44 | + </mass-object> |
| 45 | + <mass-object :rv0="{ x: 2, z: 2 }" :v0="{ z: 20 }" |
| 46 | + :f="{ y: -1, z: -8 }" :m="1.2"> |
| 47 | + <cube texture="diamond" :size="1.2"></cube> |
| 48 | + </mass-object> |
| 49 | + <movement-object :rv0="{ x: 2, z: 2 }" :v0="{ x: 15, z: -20 }" |
| 50 | + :a="{ x: -6, y: .5, z: 6 }"> |
| 51 | + <cube texture="redwool" :size="1.1"></cube> |
| 52 | + </movement-object> |
| 53 | + </movement-system> |
| 54 | + </div> |
| 55 | + </scene> |
| 56 | + </renderer> |
| 57 | + </div> |
| 58 | + `, |
| 59 | + data() { |
| 60 | + return { |
| 61 | + bg: { |
| 62 | + sysKey: 0, |
| 63 | + // size: { w: window.innerWidth, h: window.innerHeight }, |
| 64 | + size: { w: mountNode.clientWidth, h: mountNode.clientHeight }, |
| 65 | + }, |
| 66 | + ui: { sysKey: 0 } |
| 67 | + } |
| 68 | + }, |
| 69 | + mounted() { |
| 70 | + mountNode.addEventListener('resize', this.handleResize) |
| 71 | + this.timerId = setInterval(() => { |
| 72 | + this.ui.sysKey++ |
| 73 | + }, 9000) |
| 74 | + }, |
| 75 | + beforeDestroy() { |
| 76 | + if (this.timerId) clearInterval(this.timerId) |
| 77 | + mountNode.removeEventListener('resize', this.handleResize) |
| 78 | + }, |
| 79 | + methods: { |
| 80 | + handleResize: _.debounce(triggerPreview, 2000) |
| 81 | + } |
| 82 | +} |
0 commit comments