-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.html
104 lines (104 loc) · 3.2 KB
/
index.html
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
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head>
<title>Vuejs Aframe 3d.io demo</title>
<meta name="description" content="Vuejs Aframe 3d.io demo">
<!-- aframe -->
<script src="https://aframe.io/releases/0.6.1/aframe.min.js"></script>
<!-- vue.js -->
<script src="https://unpkg.com/vue"></script>
<!-- 3d.io -->
<script src="https://dist.3d.io/3dio-js/1.2.x/3dio.min.js"></script>
<!-- lodash -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<style>
#app {
width: 100%; height: 100%;
}
input {
position: absolute; top:10px; left:10px; width:300px; font-size:16px; outline: none; font-weight: bold; padding: 5px 10px; z-index:1000;
}
</style>
</head>
<body>
<div id="app">
<input class="input" v-model="searchStr" @input="findFurniture">
<a-scene>
<a-camera position="0 2 0" rotation="-41 0 0"></a-camera>
<!-- vue js component that wraps our aframe entity -->
<vue-furniture v-for="(uuid, i) in ids"
:key="uuid.id"
:furniture-id="'id:' + uuid"
:index="i">
</vue-furniture>
</a-scene>
</div>
<script>
Vue.config.ignoredElements = [
'a-scene',
'a-entity',
'a-camera',
'a-box'
]
Vue.component('vue-furniture', {
props: ['furnitureId', 'index'],
template: `
<a-entity :io3d-furniture="furnitureId" :position="pos">
<a-box height="0.04" :color="rndColor" :width="stepSize" :depth="stepSize" position="0 -0.02 0"></a-box>
</a-entity>`,
data () {
return {
stepSize: 3
}
},
computed: {
rndColor: function(){
// magic pastel color formula
var hue = Math.floor(Math.random() * 290) - 40
var saturation = Math.floor(Math.random() * 20) + 20
var lightness = Math.floor(Math.random() * 20) + 70
return `hsl(${hue < 0 ? hue + 360 : hue}, ${saturation}%, ${lightness}%)`
},
pos: function() {
// we want rows of 5
var xPos = this.index % 5 * this.stepSize - this.stepSize * 2
var zPos = Math.floor(this.index / 5) * -this.stepSize -2
return `${xPos} 0 ${zPos}`
}
}
})
new Vue({
el: '#app',
data: {
ids: [],
searchStr: 'chair',
placement: null
},
methods: {
findFurniture: _.debounce(function() {
// check out 3d.io furniture documentation here: https://3d.io/docs/api/1/furniture.html
io3d.furniture.search(this.searchStr, {limit: 300})
.then(result => {
if (result && result.length) {
result = result.map(item => item.id)
this.ids = []
const placement = io3d.utils.uuid.generate()
this.placement = placement
// populate array with delay
result.forEach((el, i) => {
_.delay(() => {
if (placement === this.placement) this.ids.push(el)
}, 25 * i)
})
}
})
.catch(console.error)
}, 300)
},
created: function() {
this.findFurniture()
}
})
</script>
</body>
</html>