-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmdmesh.js
81 lines (72 loc) · 3.16 KB
/
mmdmesh.js
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
/*
* mmdmesh.js
*/
(function() {
// var tm = require("../../../libs/tmlib");
// var THREE = require("../../../libs/three");
// require("./delegateutil");
// require("./threeelement");
tm.define("tm.hybrid.MMDMesh", {
superClass: "tm.hybrid.ThreeElement",
init: function(mesh) {
if (typeof(mesh) === "string") {
var asset = tm.asset.Manager.get(mesh);
if (asset) {
if (asset instanceof tm.asset.ThreeJSON) {
this.superInit(asset.mesh.clone());
} else if (asset instanceof tm.asset.MQO) {
this.superInit(asset.model.meshes[0]);
for (var i = 1; i < asset.model.meshes.length; i++) {
tm.hybrid.Mesh(asset.model.meshes[i]).addChildTo(this);
}
} else if (asset instanceof tm.asset.PMD) {
var loader = new THREE.MMDLoader();
var mesh = loader.createMesh(asset.data, undefined, asset.pmd.texturePath, function(){}, function(){});
this.superInit(mesh);
} else if (asset instanceof tm.asset.MMD) {
var mesh = asset.mesh.clone();
this.superInit(mesh);
this._animation = new THREE.Animation(mesh, mesh.geometry.animation);
this._animation.play();
this._morphAnimation = new THREE.MorphAnimation2(mesh, mesh.geometry.morphAnimation);
this._morphAnimation.play();
this._ikSolver = new tm.hybrid.mmd.CCDIKSolver(mesh);
var that = this;
this.on('enterframe', function(e) {
that._ikSolver.update();
});
}
} else {
console.error("アセット'{0}'がないよ".format(mesh));
}
} else if (mesh instanceof THREE.Mesh) {
this.superInit(mesh);
} else if (mesh instanceof THREE.Geometry) {
if (arguments.length >= 2) {
this.superInit(new THREE.Mesh(mesh, arguments[1]));
} else {
this.superInit(new THREE.Mesh(mesh));
}
} else {
this.superInit(new THREE.Mesh());
}
},
playAnimation: function(startTime, weight) {
if (this._animation && this._morphAnimation) {
this._animation.play(startTime, weight);
this._morphAnimation.play(startTime);
}
},
stopAnimation: function() {
if (this._animation && this._morphAnimation) {
this._animation.stop();
this._morphAnimation.stop();
}
},
});
var delegater = tm.hybrid.DelegateUtil(tm.hybrid.Mesh);
delegater.property("geometry");
delegater.property("material");
delegater.method("getMorphTargetIndexByName", true);
delegater.method("updateMorphTargets", true);
})();