-
Notifications
You must be signed in to change notification settings - Fork 115
/
obje-exp.html
148 lines (124 loc) · 5.33 KB
/
obje-exp.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
<!doctype html>
<html lang=en >
<head>
<title>obj exp</title>
<meta charset=utf-8 >
<meta name=viewport content=width=device-width,user-scalable=no,minimum-scale=1.0,maximum-scale=1.0 >
</head>
<body>
<script src=http://mrdoob.github.io/three.js/build/three.min.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/controls/TrackballControls.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/libs/stats.min.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/exporters/BufferGeometryExporter.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/exporters/MaterialExporter.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/exporters/GeometryExporter.js ></script>
<script src=http://mrdoob.github.io/three.js/examples/js/exporters/ObjectExporter.js ></script>
<script>
var info, stats, renderer, scene, camera, controls;
var obj;
init();
animate();
function init() {
var geometry, material, mesh;
document.body.style.cssText = 'font: 600 12pt monospace; margin: 0; overflow: hidden' ;
info = document.body.appendChild( document.createElement( 'div' ) );
info.style.cssText = 'left: 20px; position: absolute; top: 0px; width: 100% ';
info.innerHTML = '<h1>' + document.title + '<h1>' +
'<div id=msg></div>';
stats = new Stats();
stats.domElement.style.cssText = 'position: absolute; right: 0; top: 0; zIndex: 100; ';
document.body.appendChild( stats.domElement );
renderer = new THREE.WebGLRenderer( { alpha: 1, antialias: true, clearColor: 0xffffff } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set( 100, 100, 100 );
controls = new THREE.TrackballControls( camera, renderer.domElement );
// axes
function v( x, y, z ){ return new THREE.Vector3( x, y, z ); }
scene.add( new THREE.ArrowHelper( v(1, 0, 0), v(0, 0, 0), 30, 0xcc0000) );
scene.add( new THREE.ArrowHelper( v(0, 1, 0), v(0, 0, 0), 30, 0x00cc00) );
scene.add( new THREE.ArrowHelper( v(0, 0, 1), v(0, 0, 0), 30, 0x0000cc) );
// ground box
geometry = new THREE.BoxGeometry( 200, 1, 100 );
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, -10, 0 );
scene.add( mesh );
//loadJS ( './scene.Monkey.js' );
// Grab whatever is needed from
// http://stemkoski.github.io/Three.js/Textures.html
// and then:
// create an array with six textures for a cool cube
var materialArray = [];
materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/Dice-Blue-1.png' ) }));
materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/Dice-Blue-6.png' ) }));
materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/Dice-Blue-2.png' ) }));
materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/Dice-Blue-5.png' ) }));
materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/Dice-Blue-3.png' ) }));
materialArray.push(new THREE.MeshBasicMaterial( { map: THREE.ImageUtils.loadTexture( 'images/Dice-Blue-4.png' ) }));
var DiceBlueMaterial = new THREE.MeshFaceMaterial(materialArray);
geometry = new THREE.BoxGeometry( 85, 85, 85, 1, 1, 1 );
// mesh = new THREE.Mesh( DiceBlueGeom, DiceBlueMaterial );
mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materialArray ) );
mesh.position.set(60, 50, -100);
scene.add( mesh );
exporter = new THREE.ObjectExporter();
sce = exporter.parse( mesh );
console.log( JSON.stringify( sce ) );
}
function loadJS ( fname ) {
if ( obj ) scene.remove( obj );
obj = new THREE.Object3D();
loader = new THREE.JSONLoader();
loader.load(fname, function( geometry){
mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial( ) );
scene.add(mesh);
exporter = new THREE.ObjectExporter();
sce = exporter.parse( mesh );
console.log( JSON.stringify( sce ) );
// console.log( mesh );
});
//loader.load( fname, function ( geometry, materials) {
// mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
// for (var i = 0, len = materials.length; i < len; i++) {
// materials[i].side = 2;
// }
//mesh.position.set( -3, 0, 0 );
// mesh.scale.set( 20, 20, 20 );
// obj.add( mesh );
//} );
// scene.add( obj );
}
/*
function loadJS ( fname ) {
if ( obj ) scene.remove( obj );
obj = new THREE.Object3D();
// loader = new THREE.ObjectLoader();
loader = new THREE.JSONLoader();
loader.load(fname, function(obj){
scene.add(obj);
console.log( obj );
});
//loader.load( fname, function ( geometry, materials) {
// mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
// for (var i = 0, len = materials.length; i < len; i++) {
// materials[i].side = 2;
// }
//mesh.position.set( -3, 0, 0 );
// mesh.scale.set( 20, 20, 20 );
// obj.add( mesh );
//} );
// scene.add( obj );
}
*/
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
controls.update();
stats.update();
}
</script>
</body>
</html>