forked from coldemo/gallery.code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvue-threejs.js
More file actions
58 lines (54 loc) · 1.58 KB
/
vue-threejs.js
File metadata and controls
58 lines (54 loc) · 1.58 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
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)
// Creating a scene - Three.js Documentation
// https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene
let App = {
template: `
<div class="container">
<renderer :size="bg.size">
<scene>
<camera :position="{ z: 5 }"></camera>
<mesh name="Cube" :rotation="ui.rotation">
<geometry type="Box" :args="[1, 1, 1]"></geometry>
<material type="MeshBasic" :color="0x00ff00"></material>
</mesh>
<animation :fn="animate"></animation>
</scene>
</renderer>
</div>
`,
data() {
return {
bg: {
sysKey: 0,
// size: { w: window.innerWidth, h: window.innerHeight },
size: { w: mountNode.clientWidth, h: mountNode.clientHeight },
},
ui: {
rotation: { x: 0, y: 0, z: 0 },
}
}
},
mounted() {
mountNode.addEventListener('resize', this.handleResize)
},
beforeDestroy() {
mountNode.removeEventListener('resize', this.handleResize)
},
methods: {
animate() {
this.ui.rotation.x += 0.01
this.ui.rotation.y += 0.01
},
handleResize: _.debounce(triggerPreview, 2000)
}
}