-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
93 lines (81 loc) · 3.9 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Prototype Aframe</title>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-animation-component.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-randomizer-components.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-entity-generator-component.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-extras.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.5/dat.gui.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
</head>
<body>
<a-scene stats>
<a-assets>
<a-mixin id='red' material='color:red'></a-mixin>
<a-mixin id="cube" geometry="primitive: box" random-position></a-mixin>
<!-- models from https://sketchfab.com/models/fd528056ad154e62a7b2500337fecc34 -->
<a-asset-item id='avartar' src='assets/avartar/scene.gltf'></a-asset-item>
<!-- <a-asset-item id='blackdragon' src='assets/blackdragon/source/dragon.fbx'></a-asset-item> -->
<a-asset-item id='blackhole' src='assets/blackhole/scene.gltf'></a-asset-item>
<a-mixin id='model' gltf-model='#avartar' animation-mixer='clip: mixamo.com;' scale='0.05 0.05 0.05' random-position='min:-10 -2 -10; max:10 10 5' random-rotation></a-mixin>
<a-mixin id='blackholes' gltf-model='#blackhole' random-position='min:-10 -5 -20;max:10 10 0' scale='0.01 0.01 0.01' random-rotation>
</a-mixin>
</a-assets>
<a-sky color='#808080'></a-sky>
<!-- <a-entity entity-generator='mixin:red cube;num:50'></a-entity> -->
<!-- <a-entity entity-generator='mixin:blackholes;num:10;'></a-entity> -->
<a-entity entity-generator='mixin:model;num:50' id='generator'></a-entity>
<!-- <a-entity gltf-model='#avartar'
animation-mixer='clip: mixamo.com;'
position='-2 0 -5'
scale='0.05 0.05 0.05'> -->
<!-- </a-entity> -->
<!-- <a-entity position='0 0 -2'
scale='0.05 0.05 0.05'
fbx-model='src:url(assets/blackdragon/dragon.fbx)'>
</a-entity> -->
<!-- <a-entity gltf-model='#blackhole'
position='0 -0.1 -10'
scale='0.05 0.05 0.05'>
</a-entity> -->
<!-- <a-entity id="ocean" ocean="density: 20; width: 50; depth: 100; speed: 3"
material="color: #ec913e; opacity: 0.75; metalness: 0; roughness: 1"
rotation="-90 0 0">
</a-entity> -->
<!-- <a-grid id="grid" src="image.jpg" scale="0.1 0.1 0.1"> -->
</a-grid>
</a-scene>
</body>
<script type="text/javascript">
var ModelController = function() {
this.number = 50;
}
window.onload = function() {
var modelController = new ModelController();
var gui = new dat.GUI();
var controller = gui.add(modelController, 'number', 0, 100);
controller.onChange(function(v) {
let numOfChildren = $('#generator').children().length;
let value = Math.floor(v)
console.log(numOfChildren, value)
if (numOfChildren < value) { //Add after the end
var generatorEl = document.querySelector('a-entity#generator');
for (let i=0;i<value-numOfChildren;i+=1){
//the entity to be attached needs to be created everytime.
//Otherwise appendChild just moves the one to the new position.
var entityEl = document.createElement('a-entity')
entityEl.setAttribute('mixin', 'model')
generatorEl.appendChild(entityEl);
}
} else if (numOfChildren>value) { //Remove from index 0
$('#generator').children().slice(0, numOfChildren-Math.floor(value) ).remove()
}
numOfChildren = $('#generator').children().length;
console.log('numOfChildren', numOfChildren)
})
}
</script>
</html