forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
176 lines (118 loc) · 4.76 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js gui</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 14px;
margin: 0;
overflow: hidden;
}
hr {
border: 0px;
border-top: 1px solid #ccc;
}
</style>
</head>
<body>
<script type="text/javascript" src="../build/Three.js"></script>
<script type="text/javascript" src="../examples/js/loaders/ColladaLoader.js"></script>
<script type="text/javascript" src="../examples/js/loaders/OBJLoader.js"></script>
<script type="text/javascript" src="../examples/js/loaders/UTF8Loader.js"></script>
<script type="text/javascript" src="../examples/js/loaders/VTKLoader.js"></script>
<script type="text/javascript" src="js/libs/signals.min.js"></script>
<script type="text/javascript" src="js/UI.js"></script>
<script type="text/javascript" src="js/ui/Menubar.js"></script>
<script type="text/javascript" src="js/ui/Viewport.js"></script>
<script type="text/javascript" src="js/ui/Sidebar.js"></script>
<script type="text/javascript" src="js/ui/Sidebar.Outliner.js"></script>
<script type="text/javascript" src="js/ui/Sidebar.Properties.js"></script>
<script type="text/javascript" src="js/ui/Sidebar.Properties.Object3D.js"></script>
<script type="text/javascript" src="js/ui/Sidebar.Properties.Geometry.js"></script>
<script type="text/javascript" src="js/ui/Sidebar.Properties.Material.js"></script>
<script>
window.URL = window.URL || window.webkitURL;
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
var SIGNALS = signals;
var signals = {
objectAdded: new SIGNALS.Signal(),
objectSelected: new SIGNALS.Signal(),
objectChanged: new SIGNALS.Signal(),
materialChanged: new SIGNALS.Signal(),
windowResize: new SIGNALS.Signal()
};
//
var menubar = new Menubar( signals );
menubar.setWidth( '100%' );
menubar.setHeight( '32px' );
document.body.appendChild( menubar.dom );
var viewport = new Viewport( signals );
viewport.setTop( '32px' );
viewport.setWidth( '-webkit-calc(100% - 300px)', '-moz-calc(100% - 300px)', 'calc(100% - 300px)' );
viewport.setHeight( '-webkit-calc(100% - 32px)', '-moz-calc(100% - 32px)', 'calc(100% - 32px)' );
document.body.appendChild( viewport.dom );
var sidebar = new Sidebar( signals );
sidebar.setLeft( '-webkit-calc(100% - 300px)', '-moz-calc(100% - 300px)', 'calc(100% - 300px)' );
sidebar.setTop( '32px' );
sidebar.setHeight( '-webkit-calc(100% - 32px)', '-moz-calc(100% - 32px)', 'calc(100% - 32px)' );
document.body.appendChild( sidebar.dom );
document.addEventListener( 'drop', function ( event ) {
event.preventDefault();
var file = event.dataTransfer.files[ 0 ];
var extension = file.name.split( '.' )[1].toLowerCase();
var reader = new FileReader();
reader.onload = function ( event ) {
var contents = event.target.result;
switch ( extension ) {
case 'dae':
var parser = new DOMParser();
var xml = parser.parseFromString( contents, 'text/xml' );
// TODO: Update ColladaLoader
var loader = new THREE.ColladaLoader();
loader.parse( xml, function ( collada ) {
signals.objectAdded.dispatch( collada.scene );
signals.objectSelected.dispatch( collada.scene );
} );
break;
case 'js':
var geometry = new THREE.GeometryLoader().parse( JSON.parse( contents ) );
var material = new THREE.MeshLambertMaterial( { color: 0xffffff } );
var mesh = new THREE.Mesh( geometry, material );
signals.objectAdded.dispatch( mesh );
signals.objectSelected.dispatch( mesh );
break;
case 'obj':
var object = new THREE.OBJLoader().parse( contents );
signals.objectAdded.dispatch( object );
signals.objectSelected.dispatch( object );
break;
case 'utf8':
// TODO
break;
case 'vtk':
var geometry = new THREE.VTKLoader().parse( contents );
var material = new THREE.MeshLambertMaterial( { color: 0xffffff } );
var mesh = new THREE.Mesh( geometry, material );
signals.objectAdded.dispatch( mesh );
signals.objectSelected.dispatch( mesh );
break;
}
};
reader.readAsText( file );
}, false );
//
var geometry = new THREE.SphereGeometry( 75, 25, 15 );
var material = new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } );
var mesh = new THREE.Mesh( geometry, material );
signals.objectAdded.dispatch( mesh );
signals.objectSelected.dispatch( mesh );
//
var onWindowResize = function ( event ) {
signals.windowResize.dispatch();
};
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
</script>
</body>
</html>