-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathScene.vue
97 lines (89 loc) · 2.4 KB
/
Scene.vue
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<template>
<div id="three-container"></div>
</template>
<script>
import Environment from '@/three/environment'
import { Colors } from '@/three/colors'
import threeEncoder from '@/three/encoders'
import RhinoService from '@/rhinoService'
export default {
name: 'Scene',
props: [
'fileUrl'
],
data () {
return {
rhinoService: null
}
},
watch: {
fileUrl (fileUrl) {
this.loadModel(fileUrl)
}
},
created () {
this.$emit('isLoading', true)
document.addEventListener('mousedown', this.handleObjectClick, false)
},
destroyed () {
document.removeEventListener('mousedown', this.handleObjectClick)
},
async mounted () {
const sceneSize = 500
let options = {
background: Colors.white,
sceneSize: sceneSize,
grid: {
show: true,
size: 2000,
cellSize: 10,
major: 5,
}
}
this.environment = new Environment(options)
this.$emit('emitMessage', 'Loading Rhino Depedencies')
this.rhinoService = new RhinoService()
await this.rhinoService.init()
this.$emit('isLoading', false)
},
methods: {
async loadModel (fileUrl) {
this.environment.clear()
this.$emit('isLoading', true)
this.$emit('emitMessage', 'Loading Model')
let doc
try {
doc = await this.rhinoService.loadFileFromUrl(fileUrl)
} catch (e) {
this.$emit('emitMessage', 'Request Failed')
setTimeout(() => { this.$emit('isLoading', false) }, 1000)
return
}
this.$emit('emitMessage', 'Encoding Objects')
for (let obj of doc.objects) {
let rhinoObjects
try {
rhinoObjects = await obj.toRenderable()
} catch (e) {
this.$emit('emitMessage', 'Compute Request Failed')
setTimeout(() => { this.$emit('isLoading', false) }, 1000)
return
}
let threeObjects = rhinoObjects
.filter(o => o !== null) // Filter objects with no renderable rep
.map(o => threeEncoder(o))
.filter(o => o !== null) // Filter objects with no three js encoder
this.environment.scene.add(...threeObjects)
}
this.$emit('isLoading', false)
},
handleObjectClick () {
// let intersects = this.environment.raycaster
// .intersectObjects(this.environment.scene.children)
// console.log(intersects)
}
}
}
</script>
<style scoped>
</style>