forked from lo-th/Oimo.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bvh.html
717 lines (596 loc) · 24.6 KB
/
test_bvh.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>BVH labs</title>
<meta name="Description" content="" />
<meta name="Keywords" content="" />
<link rel="icon" href="favicon.ico" />
<style>
html { width:100%; height:100%; }
*{ padding:0; margin:0; -o-user-select:none; -ms-user-select:none; -khtml-user-select:none; -webkit-user-select:none; -moz-user-select: none; text-align: center;}
body { background: #000; font:12px sans-serif; color:#fff; text-shadow:1px 1px 0px #000; overflow:hidden; }
#container { position:absolute; top:0; left:0; }
#guiContener { position:absolute; overflow-x:auto; height:100%; width:215px; top: 0; left: 0;}
#out2 { position:absolute; bottom:30px; right:6px; text-align: right; font-size:10px; pointer-events:none;}
#out1 { position:absolute; bottom:30px; left:6px; text-align: left; font-size:10px; pointer-events:none;}
#debug { position:absolute; top:6px; left:170px; text-align:left; pointer-events:none;}
#topp { position:absolute; top:0px; left:0px; }
#l1 { position:absolute; top:0px; left:0; width:160px; height:100%; background-color:rgba(30,30,40,0.4); pointer-events:none; border-right:1px solid #303040; }
#l2 { position:absolute; top:0px; right:0; width:160px; height:100%; background-color:rgba(30,30,40,0.4); pointer-events:none; border-left:1px solid #303040;}
#b1 { position:absolute; top:10px; left:5px; width:72.5px; height:30px; }
#b2 { position:absolute; top:10px; left:82.5px; width:72.5px; height:30px; }
#b3 { position:absolute; top:10px; right:5px; width:148px; height:30px; }
#dragZone { position:absolute; bottom:60px; left:5px; width:144px; height:45px; background-color:none; border: 3px dashed #ccc; pointer-events:auto; }
#dragZone.hover { border: 3px dashed #333; }
#topfiles { position:absolute; bottom:5px; left:5px; width:144px; height:45px; background-color:none; pointer-events:none; border: 3px solid #ccc;}
#topfiles.hover { background-color:#999999; }
#files { position:absolute; bottom:5px; left:5px; width:150px; height:45px; opacity:0; }
</style>
</head>
<body>
<script src="js/bvh.js"></script>
<script src="js/three.min.js"></script>
<script src="js/navigation.js"></script>
<script src="js/loaders/sea3d.min.js"></script>
<script src="js/slider.js"></script>
<script src="js/loth/Transcode.js"></script>
<script src="build/oimo.min.js"></script>
<div id="viewport"></div>
<div id="l1"></div>
<div id="l2"></div>
<div id="debug"></div>
<input type="file" id="files" />
<input type="submit" value="action" id="b1">
<input type="submit" value="story" id="b2">
<input type="submit" value="show model" id="b3">
<div id="BVHhubs"></div>
<div id="out1"></div>
<div id="out2"></div>
<div id="topp"></div>
<div id="dragZone"><br>Drag File</div>
<div id="topfiles"><br>Load File</div>
<script type="text/javascript">
window.onload = initInterface;
var bodyLink = "models/onkba.sea";
var out1, out2, debug, fileButton, fileSel, holder;
var camera, container, scene, renderer, delta, center, centerLight;
var ToRad = Math.PI / 180;
var ToDeg = 180 / Math.PI;
var SeaStandard = false;
var hero = null;
var topp, s1, s2;
var buffgeoBox;
var bvh;
var BVHset = {ax:"x", ay:"y", az:"z", dx:1, dy:1, dz:1, rx:0, ry:0, rz:0, order:"XYZ"};
var BVHanimConfig = { debug:true, speed:0.5, size:1, px:0, py:0, pz:0, boneSize:0.5 };
var bones = null;
var boneInverses = null;
var isViewModel = false;
var currentNames = null;
var currentDistance = null;
//oimo var
var world = null;
var collisionGroupes = {};
var bodysquel = null;
var meshsquel = null;
var meshs = null;
var bodys = null;
var doc = document;
var isWithSqueleton = false;
function initInterface() {
out1 = doc.getElementById("ou1");
out2 = doc.getElementById("out2");
debug = doc.getElementById("debug");
fileButton = doc.getElementById('files');
fileSel = doc.getElementById('topfiles');
holder = doc.getElementById('dragZone');
container = doc.getElementById("viewport");
topp = doc.getElementById("topp");
holder.ondragover = function () { this.className = 'hover'; return false; };
holder.ondragend = function () { this.className = ''; return false; };
holder.ondrop = function (e) {
this.className = '';
e.preventDefault();
var file = e.dataTransfer.files[0];
var reader = new FileReader();
holder.innerHTML = '<br>'+ file.name;
reader.onload = (function(theFile) { return function(e) { bvh.parseData(e.target.result.split(/\s+/g));}; })(file);
reader.readAsText(file);
return false;
};
fileButton.addEventListener('change', handleFileSelect, false);
fileButton.onmouseover = function () { fileSel.className = 'hover'; return false; };
fileButton.onmouseout = function () { fileSel.className = ''; return false; };
doc.getElementById("b1").addEventListener( 'click', function ( e ) { loadBVH("bvh/action.png"); }, false );
doc.getElementById("b2").addEventListener( 'click', function ( e ) { loadBVH("bvh/story.png"); }, false );
doc.getElementById("b3").addEventListener( 'click', function ( e ) {heroVisibility(); }, false );
s1 = new UI.Slide(topp, "speed", setSpeed, 50, [5,70, 150, 20]);
s2 = new UI.Slide(topp, "bones", setBones, 25, [5,110, 150, 20]);
init3D();
animate();
}
function handleFileSelect(evt) {
var f = evt.target.files[0];
var reader = new FileReader();
reader.onload = (function(theFile) { return function(e) { bvh.parseData(e.target.result.split(/\s+/g));}; })(f);
reader.readAsText(f);
}
function debugTell(s) {
debug.innerHTML = s;
}
function init3D() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
initCamera(120,70,200);
center = new THREE.Vector3(0,40,0);
centerLight = new THREE.Vector3(0,-45,0);
moveCamera();
scene.add( new THREE.AmbientLight( 0x505050 ) );
var light = new THREE.SpotLight( 0xFFFFFF, 1, 0, Math.PI/2, 1 );
light.castShadow = true;
light.onlyShadow = false;
light.shadowCameraNear = 50;
light.shadowCameraFar = 500;
//light.shadowCameraFov = 35;
light.shadowBias = -0.005;
light.shadowMapWidth = light.shadowMapHeight = 1024;
light.shadowDarkness = 0.35;
var lightPos = { horizontal: 135, vertical: 35, distance: 200 };
light.position.copy(Orbit(centerLight, lightPos.horizontal, lightPos.vertical, lightPos.distance));
light.lookAt(centerLight);
scene.add( light );
var buffgeoBack = new THREE.BufferGeometry();
buffgeoBack.fromGeometry( new THREE.IcosahedronGeometry(300,1) );
var back = new THREE.Mesh( buffgeoBack, new THREE.MeshBasicMaterial( { map:gradTexture([[0.75,0.5,0.45, 0.2], ['#808080','#2e3032','#09050e', '#86a4bc']]), side:THREE.BackSide, depthWrite: false } ));
back.geometry.applyMatrix(new THREE.Matrix4().makeRotationZ(5*ToRad));
scene.add( back );
var groundMaterial = new THREE.MeshBasicMaterial( { color: 0xFFFFFF, transparent: true, depthWrite: false } );
groundMaterial.blending = THREE[ "MultiplyBlending" ];
var ground = new THREE.Mesh(new THREE.PlaneBufferGeometry( 1000, 1000, 4, 4 ), groundMaterial);
ground.position.set( 0, 5, 0 );
ground.rotation.x = - Math.PI / 2;
ground.receiveShadow = true;
scene.add( ground );
buffgeoBox = new THREE.BufferGeometry();
buffgeoBox.fromGeometry( new THREE.BoxGeometry( 1, 1, 1 ) );
var helper = new THREE.GridHelper( 100, 50 );
helper.setColors( 0x909090, 0x606060 );
scene.add( helper );
helper.position.y = 5;
renderer = new THREE.WebGLRenderer({precision: "mediump", antialias:true});
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.autoClear = false;
renderer.shadowMapEnabled = true;
//renderer.gammaInput = true;
//renderer.gammaOutput = true;
container.appendChild( renderer.domElement );
initEvents();
initOimoPhysics();
initBVH();
}
function animate() {
requestAnimationFrame( animate );
updateBVH();
renderer.clear();
renderer.render( scene, camera );
}
//----------------------------------
// BVH READER
//----------------------------------
function initBVH() {
bvh = new BVH.Reader();
loadBVH("bvh/story.png");
}
function updateBVH() {
if(bvh !== null) bvh.update();
if(isViewModel) updateSkinBones();
}
function setSpeed(v) {
BVHanimConfig.speed = v/100;;
bvh.speed = BVHanimConfig.speed
}
function setBones(v) {
var s = v/30;
if(s>0)BVHanimConfig.boneSize = s;
else BVHanimConfig.boneSize = 0.1;
bvh.boneSize = BVHanimConfig.boneSize;
}
function loadBVH(file) {
bvh.boneSize = BVHanimConfig.boneSize;
bvh.speed = BVHanimConfig.speed;
bvh.load(file);
bvh.endFunction = createOimoSqueleton;
}
//----------------------------------
// OIMO PHYSICS
//----------------------------------
function initOimoPhysics(){
// The Bit of a collision group
collisionGroupes = {
group1 : 1 << 0, // 00000000 00000000 00000000 00000001
group2 : 1 << 1, // 00000000 00000000 00000000 00000010
group3 : 1 << 2, // 00000000 00000000 00000000 00000100
all : 0xffffffff // 11111111 11111111 11111111 11111111
}
buffgeoSphere = new THREE.BufferGeometry();
buffgeoSphere.fromGeometry( new THREE.SphereGeometry( 1, 20, 10 ) );
buffgeoBox = new THREE.BufferGeometry();
buffgeoBox.fromGeometry( new THREE.BoxGeometry( 1, 1, 1 ) );
matSphere = new THREE.MeshLambertMaterial( { map: basicTexture(0), name:'sph' } );
matBox = new THREE.MeshLambertMaterial( { map: basicTexture(2), name:'box' } );
matSphereSleep = new THREE.MeshLambertMaterial( { map: basicTexture(1), name:'ssph' } );
matBoxSleep = new THREE.MeshLambertMaterial( { map: basicTexture(3), name:'sbox' } );
world = new OIMO.World(1/60, 2, 8, true);
world.gravity = new OIMO.Vec3(0, -1, 0);
populate();
setInterval(updateOimoPhysics, 1000/60);
}
function DistanceTest( p1, p2 ){
var x = p2.x-p1.x;
var y = p2.y-p1.y;
var z = p2.z-p1.z;
var d = Math.sqrt(x*x + y*y + z*z);
if(d<=0)d=0.1;
return d;
}
function createOimoSqueleton() {
if(currentNames!==null)deleteOldSkeleton();
bodysquel = {};
meshsquel = {};
currentNames = [];
currentDistance = [];
var node, name;
var w=6, h = 6;
var distance = 2;
var boneMaterial = new THREE.MeshBasicMaterial( { color: 0xFFFF33, transparent:true, opacity:0.4 } );
var boneHeadMaterial = new THREE.MeshBasicMaterial( { color: 0x33FF33, transparent:true, opacity:0.4 } )
var config = [10,0.4,0.2, collisionGroupes.group1, collisionGroupes.group2];
var i = bvh.nodes.length;
while(i--){
node = bvh.nodes[i];
name = node.name;
if(name!=='Site'){
/*if(bvh.ParentNodes[name] !== null){
var p1 = node.position;//new THREE.Vector3().setFromMatrixPosition( node.matrixWorld )
var p2 = bvh.ParentNodes[name].position;//new THREE.Vector3().setFromMatrixPosition( childNodes[name].matrixWorld );
distance = DistanceTest(p1, p2);
}*/
if(bvh.ChildNodes[name] !== null){
// get distance to child
var p1 = new THREE.Vector3().setFromMatrixPosition( node.matrixWorld );
var p2 = bvh.ChildNodes[name].position;
//var p2 = new THREE.Vector3().setFromMatrixPosition( bvh.ChildNodes[name].matrix );
distance = DistanceTest(p1, p2);
} else {
distance = 2;
}
currentNames.push(name);
currentDistance[i] = distance;
if(name=='Head'){
bodysquel[name] = new OIMO.Body({type:'sphere', name:node.name, size:[w], move:true, noSleep:true, world:world, config:config});
meshsquel[name] = new THREE.Mesh( buffgeoSphere, boneHeadMaterial );
meshsquel[name].scale.set( w, w, w );
} else {
bodysquel[name] = new OIMO.Body({type:'box', name:node.name, size:[w,h,distance], move:true, noSleep:true, world:world, config:config});
meshsquel[name] = new THREE.Mesh( buffgeoBox, boneMaterial );
meshsquel[name].scale.set( w, h, distance );
}
meshsquel[name].castShadow = true;
meshsquel[name].receiveShadow = true;
scene.add( meshsquel[name] );
}
}
isWithSqueleton = true;
}
function deleteOldSkeleton() {
isWithSqueleton = false;
var i = currentNames.length;
var name;
while (i--){
name = currentNames[i];
scene.remove(meshsquel[name]);
bodysquel[name].remove();
}
}
function updateOimoPhysics() {
world.step();
// update squeleton physics object
if(isWithSqueleton){
var mtx = new THREE.Matrix4();
var mtx2 = new THREE.Matrix4();
var mtx3 = new THREE.Matrix4();
var node, name;
var pos = new THREE.Vector3(), quat = new THREE.Quaternion();
var pos_base = new THREE.Vector3();
var pos_target = new THREE.Vector3();
var i = bvh.nodes.length;
while(i--){
node = bvh.nodes[i];
name = node.name;
if(name!=='Site'){
mtx = new THREE.Matrix4();
// get position of node
pos_base.setFromMatrixPosition( node.matrixWorld );
// apply position on matrix
mtx.makeTranslation(pos_base.x, pos_base.y, pos_base.z);
if( bvh.ParentNodes[name] !== null ){
}
if(bvh.ChildNodes[name] !== null){
// get orientation look at child node
pos_target.setFromMatrixPosition( bvh.ChildNodes[name].matrixWorld );
mtx3 = new THREE.Matrix4();
mtx3.lookAt( pos_target, pos_base, new THREE.Vector3(0, 0, 1) );
mtx.multiply( mtx3 );
}
// lock rotationZ
mtx2 = new THREE.Matrix4();
mtx2.makeRotationZ( 0 );
mtx.multiply( mtx2 );
// translate to middle of node
mtx2 = new THREE.Matrix4();
mtx2.makeTranslation( 0,0,currentDistance[i]*0.5);
mtx.multiply( mtx2 );
pos.setFromMatrixPosition( mtx );
quat.setFromRotationMatrix( mtx );
if(bodysquel[name]!==null && bodysquel[name]!==null){
bodysquel[name].setPosition(pos);
bodysquel[name].setQuaternion(quat);
meshsquel[name].position.copy(pos);
meshsquel[name].quaternion.copy(quat);
}
}
}
}
// update dynamique object
var x, y, z;
var i = bodys.length;
var mesh;
var body;
while (i--){
body = bodys[i];
mesh = meshs[i];
if(!body.getSleep()){
mesh.position.copy(body.getPosition());
mesh.quaternion.copy(body.getQuaternion());
// change material
if(mesh.material.name === 'sbox') mesh.material = matBox;
if(mesh.material.name === 'ssph') mesh.material = matSphere;
// reset position
if(mesh.position.y<-100){
x = -100 + Math.random()*200;;
z = -100 + Math.random()*200;
y = 100 + Math.random()*1000;
body.resetPosition(x,y,z);
}
} else {
if(mesh.material.name === 'box') mesh.material = matBoxSleep;
if(mesh.material.name === 'sph') mesh.material = matSphereSleep;
}
}
}
function populate() {
// reset old
bodys = [];
meshs = [];
var config = [0,0.4,0.2, collisionGroupes.group3, collisionGroupes.all & ~ collisionGroupes.group1];
//add ground
var ground = new OIMO.Body({size:[200, 40, 200], pos:[0,-15,0], world:world, config:config});
// wall
var w0 = new OIMO.Body({ type:"box", size:[200,500,50], pos:[0,250,-100], world:world, config:config });
var w1 = new OIMO.Body({ type:"box", size:[200,500,50], pos:[0,250, 100], world:world, config:config });
var w2 = new OIMO.Body({ type:"box", size:[50,500,200], pos:[-100,250,0], world:world, config:config });
var w3 = new OIMO.Body({ type:"box", size:[50,500,200], pos:[100,250,0], world:world, config:config });
config = [1,0.4,0.2, collisionGroupes.group2, collisionGroupes.all];
// now add object
var x, y, z, w, h, d;
var i = 200;
while (i--){
t = 1//Math.floor(Math.random()*2)+1;
x = -100 + Math.random()*200;;
z = -100 + Math.random()*200;
y = 100 + Math.random()*500;
w = 10 + Math.random()*10;
h = 5 + Math.random()*10;
d = 5 + Math.random()*10;
if(t===1){
bodys[i] = new OIMO.Body({type:'sphere', size:[w*0.5], pos:[x,y,z], move:true, world:world, config:config});
meshs[i] = new THREE.Mesh( buffgeoSphere, matSphere );
meshs[i].scale.set( w*0.5, w*0.5, w*0.5 );
} else if(t===2){
bodys[i] = new OIMO.Body({type:'box', size:[w,h,d], pos:[x,y,z], move:true, world:world, config:config});
meshs[i] = new THREE.Mesh( buffgeoBox, matBox );
meshs[i].scale.set( w, h, d );
}
meshs[i].castShadow = true;
meshs[i].receiveShadow = true;
scene.add( meshs[i] );
}
}
//----------------------------------
// TODO SEA3D TEST
//----------------------------------
var origine ={};
function loadSea3dBody(){
var size = 1;
var loader = new THREE.SEA3D( true );
loader.onComplete = function( e ) {
hero = loader.getMesh("onkba");
hero.scale.set(size, size, -size);
hero.material.transparent = true;
hero.material.normalScale={x:-2,y:-2};
hero.material.shininess = 10;
scene.add(hero);
//console.log(hero.skeleton.bones.length);
bones = hero.skeleton.bones;
boneInverses = hero.skeleton.boneInverses;
var i = hero.skeleton.bones.length;
//
while(i--)origine[hero.skeleton.bones[i].name]=hero.skeleton.bones[i].matrix;
hero.visible = true;
isViewModel = true;
doc.getElementById("b3").value = "hide model";
}
loader.load( bodyLink );
}
function heroVisibility() {
if(hero == null){ loadSea3dBody(); return;}
if(isViewModel){isViewModel = false; hero.visible=false; doc.getElementById("b3").value = "show model";}
else{ isViewModel = true; hero.visible=true; doc.getElementById("b3").value = "hide model";}
}
function updateSkinBones() {
//getValue();
var q = new THREE.Quaternion()
q.setFromEuler(new THREE.Euler( 0, -90, -90, 'XYZ' ))
var vector = new THREE.Vector3( );
var nodes = bvh.Nodes;
var parentNodes = bvh.ParentNodes;
var parent;
var i = bones.length;
var mtx = new THREE.Matrix4();
var mtx3 = new THREE.Matrix4();
var mtx_inv = new THREE.Matrix4();
var mtx_base = new THREE.Matrix4();
var bone, node, invBone, name;
var pos = new THREE.Vector3(), quat = new THREE.Quaternion(), scale = new THREE.Vector3(1,1,1);
var pos2 = new THREE.Vector3(), quat2 = new THREE.Quaternion(), scale2 = new THREE.Vector3(1,1,1);
var quat3 = new THREE.Quaternion()
while(i--){
//mtx.identity();
//invmtx.identity();
mtx = new THREE.Matrix4();
mtx2 = new THREE.Matrix4();
mtx3 = new THREE.Matrix4();
mtx_inv = new THREE.Matrix4();
bone = bones[i];
name = bone.name;
if(nodes[name]){
node = nodes[name];
mtx.copy( node.matrixWorld );
mtx.copy( node.matrix);
// console.log(bone.parent)
// mtx_inv.copy(bone.matrixWorld);
//mtx_inv.getInverse( bone.matrixWorld );
//mtx_inv.copy(node.matrixWorld);//= node.matrixWorld.clone();//.getInverse(bone.matrixWorld)
//mtx = new THREE.Matrix4();
// mtx.getInverse( mtx_base );
//mtx.copy( node.matrix );
if( bone.parent ){
mtx2 = bone.matrix.clone()
// mtx_inv.getInverse( bone.matrixWorld.clone() );
// mtx2.multiply( mtx_inv )
}
//mtx.multiply( mtx2);
//if( node.parent ){
if( parentNodes[name] !== null ){
mtx3.getInverse( parentNodes[name].matrixWorld );
mtx3.multiply(node.matrixWorld);
//parent = nodes[parentNodes[name]];//nodes[node.parent.name];
//mtx_inv.copy( parent.matrixWorld );
//mtx.multiplyMatrices( mtx_inv, mtx );
// mtx_inv.getInverse( parent.matrixWorld );
// mtx_inv.getInverse( parentNodes[name].matrix );
//vector = mtx_inv.multiplyVector3( parent.matrixWorld.getPosition() );
// mtx.getInverse( parent.matrixWorld );
// mtx.multiply( node.matrixWorld );
// mtx.getInverse( parent.matrix );
// mtx.multiply( node.matrix );
// mtx.multiplyMatrices( mtx_inv, mtx );
} else {
//mtx.copy( nodes[name].matrixWorld );
// mtx.copy( node.matrixWorld );
// mtx.copy( node.matrix );
//vector = new THREE.Vector3.setFromMatrixPosition( node.matrixWorld )
//node.matrixWorld.getPosition()
//mtx.multiplyMatrices(invmtx, mtx);
//bone.position.setFromMatrixPosition( mtx );
//
}
//mtx.makeRotationAxis(new THREE.Vector3(0,1,0), 90*ToRad);
//mtx.decompose(pos, quat, scale);
//quat.setFromRotationMatrix( mtx );
//quat.inverse();
//
pos.setFromMatrixPosition( mtx );
// quat.setFromRotationMatrix( mtx3 );
quat2.setFromRotationMatrix( mtx2 );
quat3.multiplyQuaternions(quat,quat2)
//quat2.x+= quat.x
//quat3.normalize();
//bone.position.copy(pos);
bone.quaternion.copy(quat3);
// quat.multiplyQuaternions(q, quat)//normalize()
//bone.position.setFromMatrixPosition( mtx );
//bone.quaternion.setFromRotationMatrix( mtx );
//mtx2.getInverse( bone.matrix );
//mtx2.copy(origine[name]);
//mtx2.decompose( pos2, quat2, scale2 );
//mtx.decompose(pos, quat, scale);
//var euler = new THREE.Euler().setFromRotationMatrix(mtx, bone.rotation.order)
//var euler = new THREE.Euler().setFromQuaternion(quat, bvh.order[name], true)
//bone.rotation.order = bvh.order[name];
// var euler = new THREE.Euler().setFromQuaternion(quat)
// bone.rotation.order = bvh.order[name];
//quat.multiplyQuaternions(quat2)
//bone.position.copy(pos)
//bone.quaternion.copy(quat)
//bone.position.set(pos.y, pos.x, pos.z)
//bone.quaternion.set(quat.z, quat.y, quat.x, quat.w)
// bone.position.set(pos[V[0]]*M[0], pos[V[1]]*M[1], pos[V[2]]*M[2])
//bone.quaternion.set(quat[V[3]]*M[3], quat[V[4]]*M[4], quat[V[5]]*M[5], quat[V[6]]*M[6])
//bone.rotation.set(euler[V[3]]*M[3], euler[V[4]]*M[4], euler[V[5]]*M[5])
// bone.setRotationFromEuler(euler);
//bone.lookAt( vector );
//bone.updateMatrixWorld();
}
}
}
//----------------------------------
// AUTO TEXTURE
//----------------------------------
function gradTexture(color) {
var c = doc.createElement("canvas");
var ct = c.getContext("2d");
c.width = 16; c.height = 256;
var gradient = ct.createLinearGradient(0,0,0,256);
var i = color[0].length;
while(i--){ gradient.addColorStop(color[0][i],color[1][i]); }
ct.fillStyle = gradient;
ct.fillRect(0,0,16,256);
var texture = new THREE.Texture(c);
texture.needsUpdate = true;
return texture;
}
function basicTexture(n){
var canvas = doc.createElement( 'canvas' );
canvas.width = canvas.height = 64;
var ctx = canvas.getContext( '2d' );
var colors = [];
if(n===0){ // sphere
colors[0] = "#58AA80";
colors[1] = "#58FFAA";
}
if(n===1){ // sphere sleep
colors[0] = "#383838";
colors[1] = "#38AA80";
}
if(n===2){ // box
colors[0] = "#AA8058";
colors[1] = "#FFAA58";
}
if(n===3){ // box sleep
colors[0] = "#383838";
colors[1] = "#AA8038";
}
ctx.fillStyle = colors[0];
ctx.fillRect(0, 0, 64, 64);
ctx.fillStyle = colors[1];
ctx.fillRect(0, 0, 32, 32);
ctx.fillRect(32, 32, 32, 32);
var tx = new THREE.Texture(canvas);
tx.needsUpdate = true;
return tx;
}
</script>
</body>
</html>