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