-
Notifications
You must be signed in to change notification settings - Fork 16
/
app_shadow.html
235 lines (164 loc) · 6.7 KB
/
app_shadow.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang="en">
<head>
<title>Three.js MMDLoader app Shadow</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #fff;
color: #000;
margin: 0px;
overflow: hidden;
}
#info {
color: #000;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - MMDLoader app Shadow<br />
<a href="https://github.com/takahirox/MMDLoader-app#readme" target="_blank">MMD Assets license</a><br />
Copyright
<a href="http://www.geocities.jp/higuchuu4/index_e.htm" target="_blank">Model Data</a>
<a href="http://www.nicovideo.jp/watch/sm13147122" target="_blank">Dance Data</a>
<a href="http://www.nicovideo.jp/watch/sm11938255" target="_blank">Audio Data</a><br />
<a href="http://www.nicovideo.jp/watch/sm19168559" target="_blank">Original Camera Data(I've customized this)</a>
</div>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/build/three.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/libs/mmdparser.min.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/libs/ammo.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/loaders/TGALoader.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/loaders/MMDLoader.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/effects/OutlineEffect.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/animation/CCDIKSolver.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/animation/MMDPhysics.js"></script>
<script src="https://rawcdn.githack.com/mrdoob/three.js/r87/examples/js/Detector.js"></script>
<script>
var container;
var mesh, camera, scene, renderer, effect;
var helper;
var ready = false;
var mouseX = 0, mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var clock = new THREE.Clock();
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
// scene
scene = new THREE.Scene();
var ground = new THREE.Mesh(
new THREE.PlaneBufferGeometry( 100, 100 ),
new THREE.MeshPhongMaterial( { color: 0xdddddd } )
);
ground.rotation.x = -90 * Math.PI / 180;
ground.receiveShadow = true;
scene.add( ground );
var ambient = new THREE.AmbientLight( 0x666666 );
scene.add( ambient );
var directionalLight = new THREE.DirectionalLight( 0x887766 );
directionalLight.position.set( -15, 15, 15 );
scene.add( directionalLight );
//
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( new THREE.Color( 0xffffff ) );
container.appendChild( renderer.domElement );
effect = new THREE.OutlineEffect( renderer );
// Shadow parameters
renderer.shadowMap.enabled = true;
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.x = 1024;
directionalLight.shadow.mapSize.y = 1024;
directionalLight.shadow.camera.right = 20;
directionalLight.shadow.camera.top = 20;
directionalLight.shadow.camera.left = -20;
directionalLight.shadow.camera.bottom = -20;
// Model specific Shadow parameters
renderer.shadowMap.renderSingleSided = false;
renderer.shadowMap.renderReverseSided = false;
directionalLight.shadow.bias = -0.001;
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round(percentComplete, 2) + '% downloaded' );
}
};
var onError = function ( xhr ) {
};
// see the license https://github.com/takahirox/MMDLoader-app#readme for these assets
var modelFile = 'https://rawcdn.githack.com/mrdoob/three.js/r87/examples/models/mmd/miku/miku_v2.pmd';
var vmdFiles = [ 'https://rawcdn.githack.com/mrdoob/three.js/r87/examples/models/mmd/vmds/wavefile_v2.vmd' ];
var cameraFiles = [ 'https://rawcdn.githack.com/mrdoob/three.js/r87/examples/models/mmd/vmds/wavefile_camera.vmd' ];
var audioFile = 'https://rawcdn.githack.com/mrdoob/three.js/r87/examples/models/mmd/audios/wavefile_short.mp3';
var audioParams = { delayTime: 160 * 1 / 30 };
helper = new THREE.MMDHelper();
var loader = new THREE.MMDLoader();
loader.load( modelFile, vmdFiles, function ( object ) {
mesh = object;
mesh.castShadow = true;
mesh.receiveShadow = true;
helper.add( mesh );
helper.setAnimation( mesh );
helper.setPhysics( mesh );
loader.loadVmds( cameraFiles, function ( vmd ) {
helper.setCamera( camera );
loader.pourVmdIntoCamera( camera, vmd );
helper.setCameraAnimation( camera );
loader.loadAudio( audioFile, function ( audio, listener ) {
listener.position.z = 1;
helper.setAudio( audio, listener, audioParams );
/*
* Note: call this method after you set all animations
* including camera and audio.
*/
helper.unifyAnimationDuration();
scene.add( audio );
scene.add( listener );
scene.add( mesh );
ready = true;
}, onProgress, onError );
}, onProgress, onError );
}, onProgress, onError );
document.addEventListener( 'mousemove', onDocumentMouseMove, false );
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
effect.setSize( window.innerWidth, window.innerHeight );
}
function onDocumentMouseMove( event ) {
mouseX = ( event.clientX - windowHalfX ) / 2;
mouseY = ( event.clientY - windowHalfY ) / 2;
}
//
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
if ( ready ) {
helper.animate( clock.getDelta() );
}
effect.render( scene, camera );
}
</script>
</body>
</html>