mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
代码优化。
This commit is contained in:
parent
d8773392d0
commit
56e636fee3
@ -13,7 +13,7 @@ function BaseLoader() {
|
||||
this.require = this.packageManager.require.bind(this.packageManager);
|
||||
}
|
||||
|
||||
BaseLoader.prototype.load = function (url, options) {
|
||||
BaseLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
resolve(null);
|
||||
});
|
||||
|
||||
@ -11,7 +11,7 @@ function GCodeLoader() {
|
||||
GCodeLoader.prototype = Object.create(BaseLoader.prototype);
|
||||
GCodeLoader.prototype.constructor = GCodeLoader;
|
||||
|
||||
GCodeLoader.prototype.load = function (url, options) {
|
||||
GCodeLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
this.require('GCodeLoader').then(() => {
|
||||
var loader = new THREE.GCodeLoader();
|
||||
|
||||
@ -85,7 +85,7 @@ MMDLoader.prototype.loadCameraAnimation = function (url, options, environment, l
|
||||
});
|
||||
};
|
||||
|
||||
MMDLoader.prototype.loadAudio = function (url, options, environment, loader) {
|
||||
MMDLoader.prototype.loadAudio = function (url, options, environment, loader) { // eslint-disable-line
|
||||
if (!options.Audio || !options.Audio.Url) {
|
||||
return new Promise(resolve => {
|
||||
resolve(null);
|
||||
|
||||
@ -11,11 +11,11 @@ function NRRDLoader() {
|
||||
NRRDLoader.prototype = Object.create(BaseLoader.prototype);
|
||||
NRRDLoader.prototype.constructor = NRRDLoader;
|
||||
|
||||
NRRDLoader.prototype.load = function (url, options) {
|
||||
NRRDLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
this.require('NRRDLoader').then(() => {
|
||||
var loader = new THREE.NRRDLoader();
|
||||
loader.load(url, result => {
|
||||
loader.load(url, result => { // eslint-disable-line
|
||||
var loader = new THREE.NRRDLoader();
|
||||
loader.load(url, volume => {
|
||||
var obj = new THREE.Object3D();
|
||||
|
||||
@ -11,7 +11,7 @@ function PCDLoader() {
|
||||
PCDLoader.prototype = Object.create(BaseLoader.prototype);
|
||||
PCDLoader.prototype.constructor = PCDLoader;
|
||||
|
||||
PCDLoader.prototype.load = function (url, options) {
|
||||
PCDLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
this.require('PCDLoader').then(() => {
|
||||
var loader = new THREE.PCDLoader();
|
||||
|
||||
@ -11,7 +11,7 @@ function PDBLoader() {
|
||||
PDBLoader.prototype = Object.create(BaseLoader.prototype);
|
||||
PDBLoader.prototype.constructor = PDBLoader;
|
||||
|
||||
PDBLoader.prototype.load = function (url, options) {
|
||||
PDBLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
this.require('PDBLoader').then(() => {
|
||||
var loader = new THREE.PDBLoader();
|
||||
@ -21,7 +21,7 @@ PDBLoader.prototype.load = function (url, options) {
|
||||
loader.load(url, pdb => {
|
||||
var geometryAtoms = pdb.geometryAtoms;
|
||||
var geometryBonds = pdb.geometryBonds;
|
||||
var json = pdb.json;
|
||||
// var json = pdb.json;
|
||||
|
||||
var root = new THREE.Group();
|
||||
|
||||
@ -40,7 +40,9 @@ PDBLoader.prototype.load = function (url, options) {
|
||||
var position = new THREE.Vector3();
|
||||
var color = new THREE.Color();
|
||||
|
||||
for (var i = 0; i < positions.count; i++) {
|
||||
var i, object;
|
||||
|
||||
for (i = 0; i < positions.count; i++) {
|
||||
position.x = positions.getX(i);
|
||||
position.y = positions.getY(i);
|
||||
position.z = positions.getZ(i);
|
||||
@ -51,7 +53,7 @@ PDBLoader.prototype.load = function (url, options) {
|
||||
|
||||
var material = new THREE.MeshPhongMaterial({ color: color });
|
||||
|
||||
var object = new THREE.Mesh(sphereGeometry, material);
|
||||
object = new THREE.Mesh(sphereGeometry, material);
|
||||
object.position.copy(position);
|
||||
object.position.multiplyScalar(75);
|
||||
object.scale.multiplyScalar(25);
|
||||
@ -63,7 +65,7 @@ PDBLoader.prototype.load = function (url, options) {
|
||||
var start = new THREE.Vector3();
|
||||
var end = new THREE.Vector3();
|
||||
|
||||
for (var i = 0; i < positions.count; i += 2) {
|
||||
for (i = 0; i < positions.count; i += 2) {
|
||||
|
||||
start.x = positions.getX(i);
|
||||
start.y = positions.getY(i);
|
||||
@ -76,7 +78,7 @@ PDBLoader.prototype.load = function (url, options) {
|
||||
start.multiplyScalar(75);
|
||||
end.multiplyScalar(75);
|
||||
|
||||
var object = new THREE.Mesh(boxGeometry, new THREE.MeshPhongMaterial(0xffffff));
|
||||
object = new THREE.Mesh(boxGeometry, new THREE.MeshPhongMaterial(0xffffff));
|
||||
object.position.copy(start);
|
||||
object.position.lerp(end, 0.5);
|
||||
object.scale.set(5, 5, start.distanceTo(end));
|
||||
|
||||
@ -42,7 +42,7 @@ SEA3DLoader.prototype.load = function (url, options) {
|
||||
});
|
||||
};
|
||||
|
||||
SEA3DLoader.prototype.createScripts = function (name) {
|
||||
SEA3DLoader.prototype.createScripts = function (name) { // eslint-disable-line
|
||||
return `function update(clock, deltaTime) { \n THREE.SEA3D.AnimationHandler.update(deltaTime); \n}`;
|
||||
};
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ function VRMLLoader() {
|
||||
VRMLLoader.prototype = Object.create(BaseLoader.prototype);
|
||||
VRMLLoader.prototype.constructor = VRMLLoader;
|
||||
|
||||
VRMLLoader.prototype.load = function (url, options) {
|
||||
VRMLLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
this.require(['chevrotain', 'VRMLLoader']).then(() => {
|
||||
var loader = new THREE.VRMLLoader();
|
||||
|
||||
@ -11,7 +11,7 @@ function VRMLoader() {
|
||||
VRMLoader.prototype = Object.create(BaseLoader.prototype);
|
||||
VRMLoader.prototype.constructor = VRMLoader;
|
||||
|
||||
VRMLoader.prototype.load = function (url, options) {
|
||||
VRMLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
this.require([
|
||||
'GLTFLoader',
|
||||
@ -19,13 +19,14 @@ VRMLoader.prototype.load = function (url, options) {
|
||||
]).then(() => {
|
||||
var loader = new THREE.VRMLoader();
|
||||
loader.load(url, vrm => {
|
||||
var material;
|
||||
// VRMLoader doesn't support VRM Unlit extension yet so
|
||||
// converting all materials to MeshBasicMaterial here as workaround so far.
|
||||
vrm.scene.traverse(function (object) {
|
||||
if (object.material) {
|
||||
if (Array.isArray(object.material)) {
|
||||
for (var i = 0, il = object.material.length; i < il; i++) {
|
||||
var material = new THREE.MeshBasicMaterial();
|
||||
material = new THREE.MeshBasicMaterial();
|
||||
THREE.Material.prototype.copy.call(material, object.material[i]);
|
||||
material.color.copy(object.material[i].color);
|
||||
material.map = object.material[i].map;
|
||||
@ -36,7 +37,7 @@ VRMLoader.prototype.load = function (url, options) {
|
||||
object.material[i] = material;
|
||||
}
|
||||
} else {
|
||||
var material = new THREE.MeshBasicMaterial();
|
||||
material = new THREE.MeshBasicMaterial();
|
||||
THREE.Material.prototype.copy.call(material, object.material);
|
||||
material.color.copy(object.material.color);
|
||||
material.map = object.material.map;
|
||||
|
||||
@ -11,7 +11,7 @@ function XLoader() {
|
||||
XLoader.prototype = Object.create(BaseLoader.prototype);
|
||||
XLoader.prototype.constructor = XLoader;
|
||||
|
||||
XLoader.prototype.load = function (url, options) {
|
||||
XLoader.prototype.load = function (url, options) { // eslint-disable-line
|
||||
return new Promise(resolve => {
|
||||
this.require('XLoader').then(() => {
|
||||
var loader = new THREE.XLoader();
|
||||
|
||||
@ -3,6 +3,9 @@ import AnimationBone from './AnimationBone';
|
||||
/**
|
||||
* @author lolking / http://www.lolking.net/models
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {Model} model 模型
|
||||
* @param {DataView2} r 数据视图
|
||||
* @param {Number} version 版本
|
||||
*/
|
||||
function Animation(model, r, version) {
|
||||
var self = this,
|
||||
@ -16,13 +19,13 @@ function Animation(model, r, version) {
|
||||
self.lookup = {};
|
||||
for (i = 0; i < numBones; ++i) {
|
||||
self.bones[i] = new AnimationBone(model, self, r, version);
|
||||
self.lookup[self.bones[i].bone] = i
|
||||
self.lookup[self.bones[i].bone] = i;
|
||||
}
|
||||
if (numBones == 0 || self.fps <= 1) {
|
||||
self.duration = 1e3
|
||||
if (numBones === 0 || self.fps <= 1) {
|
||||
self.duration = 1e3;
|
||||
} else {
|
||||
self.duration = Math.floor(1e3 * (self.bones[0].frames.length / self.fps))
|
||||
self.duration = Math.floor(1e3 * (self.bones[0].frames.length / self.fps));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Animation;
|
||||
@ -1,6 +1,10 @@
|
||||
/**
|
||||
* @author lolking / http://www.lolking.net/models
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {Model} model 模型
|
||||
* @param {Animation} anim 动画
|
||||
* @param {DataView2} r 数据视图
|
||||
* @param {Number} version 版本
|
||||
*/
|
||||
function AnimationBone(model, anim, r, version) {
|
||||
var self = this;
|
||||
@ -19,15 +23,15 @@ function AnimationBone(model, anim, r, version) {
|
||||
pos: pos,
|
||||
rot: rot,
|
||||
scale: scale
|
||||
}
|
||||
};
|
||||
}
|
||||
self.matrix = mat4.create();
|
||||
self.tmpMat = mat4.create();
|
||||
self.tmpMat2 = mat4.create();
|
||||
self.tmpPos = vec3.create();
|
||||
self.tmpRot = quat.create();
|
||||
self.tmpScale = vec3.create()
|
||||
};
|
||||
self.tmpScale = vec3.create();
|
||||
}
|
||||
|
||||
AnimationBone.prototype.update = function (boneId, frame, r) {
|
||||
var self = this;
|
||||
@ -41,10 +45,10 @@ AnimationBone.prototype.update = function (boneId, frame, r) {
|
||||
self.translation(self.tmpMat2, self.tmpPos);
|
||||
self.rotationQuat(self.tmpMat, self.tmpRot);
|
||||
self.mulSlimDX(self.matrix, self.tmpMat, self.tmpMat2);
|
||||
if (parent != -1) {
|
||||
self.mulSlimDX(self.matrix, self.matrix, self.model.transforms[parent])
|
||||
if (parent !== -1) {
|
||||
self.mulSlimDX(self.matrix, self.matrix, self.model.transforms[parent]);
|
||||
}
|
||||
mat4.copy(self.model.transforms[boneId], self.matrix)
|
||||
mat4.copy(self.model.transforms[boneId], self.matrix);
|
||||
};
|
||||
|
||||
AnimationBone.prototype.translation = function (out, vec) {
|
||||
@ -52,7 +56,7 @@ AnimationBone.prototype.translation = function (out, vec) {
|
||||
out[12] = vec[0];
|
||||
out[13] = vec[1];
|
||||
out[14] = vec[2];
|
||||
return out
|
||||
return out;
|
||||
};
|
||||
|
||||
AnimationBone.prototype.rotationQuat = function (out, q) {
|
||||
@ -75,7 +79,7 @@ AnimationBone.prototype.rotationQuat = function (out, q) {
|
||||
out[8] = 2 * (zx + yw);
|
||||
out[9] = 2 * (yz - xw);
|
||||
out[10] = 1 - 2 * (yy + xx);
|
||||
return out
|
||||
return out;
|
||||
};
|
||||
|
||||
AnimationBone.prototype.mulSlimDX = function (out, l, r) {
|
||||
@ -131,7 +135,7 @@ AnimationBone.prototype.mulSlimDX = function (out, l, r) {
|
||||
out[13] = left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42;
|
||||
out[14] = left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43;
|
||||
out[15] = left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44;
|
||||
return out
|
||||
return out;
|
||||
};
|
||||
|
||||
export default AnimationBone;
|
||||
@ -1,6 +1,9 @@
|
||||
/**
|
||||
* @author lolking / http://www.lolking.net/models
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {Model} model 模型
|
||||
* @param {Number} index 索引
|
||||
* @param {DataView2} r 数据视图
|
||||
*/
|
||||
function Bone(model, index, r) {
|
||||
var self = this,
|
||||
@ -19,10 +22,10 @@ function Bone(model, index, r) {
|
||||
self.incrMatrix = mat4.create();
|
||||
if (model.version >= 2) {
|
||||
for (i = 0; i < 16; ++i) self.incrMatrix[i] = r.getFloat();
|
||||
mat4.transpose(self.incrMatrix, self.incrMatrix)
|
||||
mat4.transpose(self.incrMatrix, self.incrMatrix);
|
||||
} else {
|
||||
mat4.identity(self.incrMatrix)
|
||||
mat4.identity(self.incrMatrix);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Bone;
|
||||
@ -1,107 +1,108 @@
|
||||
/**
|
||||
* @author lolking / http://www.lolking.net/models
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {ArrayBuffer} buffer 缓冲区
|
||||
*/
|
||||
function DataView2(buffer) {
|
||||
this.buffer = new DataView(buffer);
|
||||
this.position = 0
|
||||
};
|
||||
this.position = 0;
|
||||
}
|
||||
|
||||
DataView2.prototype.getBool = function () {
|
||||
var v = this.buffer.getUint8(this.position) != 0;
|
||||
var v = this.buffer.getUint8(this.position) !== 0;
|
||||
this.position += 1;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getUint8 = function () {
|
||||
var v = this.buffer.getUint8(this.position);
|
||||
this.position += 1;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getInt8 = function () {
|
||||
var v = this.buffer.getInt8(this.position);
|
||||
this.position += 1;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getUint16 = function () {
|
||||
var v = this.buffer.getUint16(this.position, true);
|
||||
this.position += 2;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getInt16 = function () {
|
||||
var v = this.buffer.getInt16(this.position, true);
|
||||
this.position += 2;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getUint32 = function () {
|
||||
var v = this.buffer.getUint32(this.position, true);
|
||||
this.position += 4;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getInt32 = function () {
|
||||
var v = this.buffer.getInt32(this.position, true);
|
||||
this.position += 4;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getFloat = function () {
|
||||
var v = this.buffer.getFloat32(this.position, true);
|
||||
this.position += 4;
|
||||
return v
|
||||
return v;
|
||||
};
|
||||
|
||||
DataView2.prototype.getString = function (len) {
|
||||
if (len === undefined) len = this.getUint16();
|
||||
var str = "";
|
||||
for (var i = 0; i < len; ++i) {
|
||||
str += String.fromCharCode(this.getUint8())
|
||||
str += String.fromCharCode(this.getUint8());
|
||||
}
|
||||
return str
|
||||
return str;
|
||||
};
|
||||
|
||||
DataView2.prototype.setBool = function (v) {
|
||||
this.buffer.setUint8(this.position, v ? 1 : 0);
|
||||
this.position += 1
|
||||
this.position += 1;
|
||||
};
|
||||
|
||||
DataView2.prototype.setUint8 = function (v) {
|
||||
this.buffer.setUint8(this.position, v);
|
||||
this.position += 1
|
||||
this.position += 1;
|
||||
};
|
||||
|
||||
DataView2.prototype.setInt8 = function (v) {
|
||||
this.buffer.setInt8(this.position, v);
|
||||
this.position += 1
|
||||
this.position += 1;
|
||||
};
|
||||
|
||||
DataView2.prototype.setUint16 = function (v) {
|
||||
this.buffer.setUint16(this.position, v, true);
|
||||
this.position += 2
|
||||
this.position += 2;
|
||||
};
|
||||
|
||||
DataView2.prototype.setInt16 = function (v) {
|
||||
this.buffer.setInt16(this.position, v, true);
|
||||
this.position += 2
|
||||
this.position += 2;
|
||||
};
|
||||
|
||||
DataView2.prototype.setUint32 = function (v) {
|
||||
this.buffer.setUint32(this.position, v, true);
|
||||
this.position += 4
|
||||
this.position += 4;
|
||||
};
|
||||
|
||||
DataView2.prototype.setInt32 = function (v) {
|
||||
this.buffer.setInt32(this.position, v, true);
|
||||
this.position += 4
|
||||
this.position += 4;
|
||||
};
|
||||
|
||||
DataView2.prototype.setFloat = function (v) {
|
||||
this.buffer.setFloat32(this.position, v, true);
|
||||
this.position += 4
|
||||
this.position += 4;
|
||||
};
|
||||
|
||||
export default DataView2;
|
||||
@ -12,6 +12,7 @@ import AnimationBone from './AnimationBone';
|
||||
/**
|
||||
* @author lolking / http://www.lolking.net/models
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {Object} options 参数
|
||||
*/
|
||||
function Model(options) {
|
||||
var self = this;
|
||||
@ -45,7 +46,7 @@ function Model(options) {
|
||||
var hiddenBones = HiddenBones;
|
||||
if (hiddenBones[self.champion] !== undefined) {
|
||||
if (hiddenBones[self.champion][self.skin] !== undefined) {
|
||||
self.hiddenBones = hiddenBones[self.champion][self.skin]
|
||||
self.hiddenBones = hiddenBones[self.champion][self.skin];
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +82,7 @@ function Model(options) {
|
||||
Promise.all([promise1, promise2, promise3]).then(() => {
|
||||
self.dispatch.call('load');
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Model.prototype.getAnimations = function () {
|
||||
if (!this.animations) {
|
||||
@ -98,27 +99,27 @@ Model.prototype.getAnimation = function (name) {
|
||||
var self = this,
|
||||
i, animIndex = -1;
|
||||
if (!self.animations) {
|
||||
return animIndex
|
||||
};
|
||||
return animIndex;
|
||||
}
|
||||
name = name.toLowerCase();
|
||||
if (name == "idle" || name == "attack") {
|
||||
if (name === "idle" || name === "attack") {
|
||||
var anims = [],
|
||||
re = new RegExp(name + "[0-9]*");
|
||||
for (i = 0; i < self.animations.length; ++i) {
|
||||
if (self.animations[i].name.search(re) == 0) anims.push(i)
|
||||
if (self.animations[i].name.search(re) === 0) anims.push(i);
|
||||
}
|
||||
if (anims.length > 0) {
|
||||
animIndex = anims[0];
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < self.animations.length; ++i) {
|
||||
if (self.animations[i].name == name) {
|
||||
if (self.animations[i].name === name) {
|
||||
animIndex = i;
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return animIndex
|
||||
return animIndex;
|
||||
};
|
||||
|
||||
Model.prototype.setAnimation = function (name) {
|
||||
@ -131,16 +132,16 @@ Model.prototype.update = function (time) {
|
||||
var self = this,
|
||||
i, j;
|
||||
|
||||
if (self.animTime == 0) {
|
||||
if (self.animTime === 0) {
|
||||
self.animTime = time;
|
||||
}
|
||||
|
||||
if (!self.loaded || !self.vertices || !self.animations || self.animations.length == 0) {
|
||||
if (!self.loaded || !self.vertices || !self.animations || self.animations.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.animIndex = self.getAnimation(self.animName);
|
||||
if (self.animIndex == -1) {
|
||||
if (self.animIndex === -1) {
|
||||
self.animIndex = 0;
|
||||
self.animName = "idle";
|
||||
}
|
||||
@ -169,7 +170,7 @@ Model.prototype.update = function (time) {
|
||||
|
||||
if (deltaTime >= anim.duration) {
|
||||
self.animTime = time;
|
||||
deltaTime = 0
|
||||
deltaTime = 0;
|
||||
}
|
||||
|
||||
if (self.ANIMATED) {
|
||||
@ -191,16 +192,16 @@ Model.prototype.update = function (time) {
|
||||
if (hiddenBones[b.name]) {
|
||||
mat4.identity(self.tmpMat);
|
||||
mat4.scale(self.tmpMat, self.tmpMat, vec3.set(self.tmpVec, 0, 0, 0));
|
||||
mat4.copy(self.transforms[i], self.tmpMat)
|
||||
mat4.copy(self.transforms[i], self.tmpMat);
|
||||
} else if (anim.lookup[b.name] !== undefined) {
|
||||
anim.bones[anim.lookup[b.name]].update(i, frame, r)
|
||||
anim.bones[anim.lookup[b.name]].update(i, frame, r);
|
||||
} else if (self.baseAnim && self.baseAnim.lookup[b.name] !== undefined) {
|
||||
self.baseAnim.bones[self.baseAnim.lookup[b.name]].update(i, frame, r)
|
||||
self.baseAnim.bones[self.baseAnim.lookup[b.name]].update(i, frame, r);
|
||||
} else {
|
||||
if (b.parent != -1) {
|
||||
AnimationBone.prototype.mulSlimDX(self.transforms[i], b.incrMatrix, self.transforms[b.parent])
|
||||
if (b.parent !== -1) {
|
||||
AnimationBone.prototype.mulSlimDX(self.transforms[i], b.incrMatrix, self.transforms[b.parent]);
|
||||
} else {
|
||||
mat4.copy(self.transforms[i], b.incrMatrix)
|
||||
mat4.copy(self.transforms[i], b.incrMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,20 +209,20 @@ Model.prototype.update = function (time) {
|
||||
for (i = 0; i < anim.bones.length; ++i) {
|
||||
b = anim.bones[i];
|
||||
if (self.boneLookup[b.bone] !== undefined) {
|
||||
b.update(self.boneLookup[b.bone], frame, r)
|
||||
b.update(self.boneLookup[b.bone], frame, r);
|
||||
} else {
|
||||
var parentBone = anim.bones[i - 1];
|
||||
if (!parentBone) continue;
|
||||
if (parentBone.index + 1 < self.transforms.length) {
|
||||
mat4.copy(self.transforms[parentBone.index + 1], self.transforms[parentBone.index])
|
||||
mat4.copy(self.transforms[parentBone.index + 1], self.transforms[parentBone.index]);
|
||||
}
|
||||
b.index = parentBone.index + 1
|
||||
b.index = parentBone.index + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
var numBones = Math.min(self.transforms.length, self.bones.length);
|
||||
for (i = 0; i < numBones; ++i) {
|
||||
AnimationBone.prototype.mulSlimDX(self.transforms[i], self.bones[i].baseMatrix, self.transforms[i])
|
||||
AnimationBone.prototype.mulSlimDX(self.transforms[i], self.bones[i].baseMatrix, self.transforms[i]);
|
||||
}
|
||||
mat4.identity(self.tmpMat);
|
||||
var numVerts = self.vertices.length,
|
||||
@ -237,7 +238,7 @@ Model.prototype.update = function (time) {
|
||||
for (j = 0; j < 4; ++j) {
|
||||
if (v.weights[j] > 0) {
|
||||
w = v.weights[j];
|
||||
m = anim.fps == 1 ? self.tmpMat : self.transforms[v.bones[j]];
|
||||
m = anim.fps === 1 ? self.tmpMat : self.transforms[v.bones[j]];
|
||||
vec3.transformMat4(vec, v.position, m);
|
||||
position[idx] += vec[0] * w;
|
||||
position[idx + 1] += vec[1] * w;
|
||||
@ -245,7 +246,7 @@ Model.prototype.update = function (time) {
|
||||
vec4.transformMat4(vec, v.normal, m);
|
||||
normal[idx] += vec[0] * w;
|
||||
normal[idx + 1] += vec[1] * w;
|
||||
normal[idx + 2] += vec[2] * w
|
||||
normal[idx + 2] += vec[2] * w;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -253,7 +254,7 @@ Model.prototype.update = function (time) {
|
||||
self.geometry.attributes.normal.needsUpdate = true;
|
||||
}
|
||||
if (self.newAnimation) {
|
||||
self.newAnimation = false
|
||||
self.newAnimation = false;
|
||||
}
|
||||
};
|
||||
|
||||
@ -269,7 +270,7 @@ Model.prototype.load = function () {
|
||||
Model.prototype.loadMesh = function (buffer) {
|
||||
if (!buffer) {
|
||||
console.error("Bad buffer for DataView");
|
||||
return
|
||||
return;
|
||||
}
|
||||
var self = this,
|
||||
r = new DataView(buffer),
|
||||
@ -278,14 +279,14 @@ Model.prototype.loadMesh = function (buffer) {
|
||||
idx;
|
||||
try {
|
||||
var magic = r.getUint32();
|
||||
if (magic != 604210091) {
|
||||
if (magic !== 604210091) {
|
||||
console.log("Bad magic value");
|
||||
return
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
alert("Model currently isn't loading! We're sorry and hope to have this fixed soon.");
|
||||
console.log(err);
|
||||
return
|
||||
return;
|
||||
}
|
||||
self.version = r.getUint32();
|
||||
var animFile = r.getString();
|
||||
@ -294,12 +295,12 @@ Model.prototype.loadMesh = function (buffer) {
|
||||
var loader = new THREE.FileLoader();
|
||||
loader.setResponseType('arraybuffer');
|
||||
loader.load(self.animUrl, function (buffer) {
|
||||
self.loadAnim(buffer)
|
||||
self.loadAnim(buffer);
|
||||
self.dispatch.call('loadAnim');
|
||||
});
|
||||
}
|
||||
if (textureFile && textureFile.length > 0) {
|
||||
self.texture = new Texture(self, self.textureUrl)
|
||||
self.texture = new Texture(self, self.textureUrl);
|
||||
}
|
||||
var numMeshes = r.getUint32();
|
||||
if (numMeshes > 0) {
|
||||
@ -316,7 +317,7 @@ Model.prototype.loadMesh = function (buffer) {
|
||||
vCount: vCount,
|
||||
iStart: iStart,
|
||||
iCount: iCount
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
var numVerts = r.getUint32();
|
||||
@ -336,7 +337,7 @@ Model.prototype.loadMesh = function (buffer) {
|
||||
self.vbData[idx + 4] = v.normal[1];
|
||||
self.vbData[idx + 5] = v.normal[2];
|
||||
self.vbData[idx + 6] = v.u;
|
||||
self.vbData[idx + 7] = v.v
|
||||
self.vbData[idx + 7] = v.v;
|
||||
|
||||
position.push(v.position[0], v.position[1], v.position[2]);
|
||||
normal.push(v.normal[0], v.normal[1], v.normal[2]);
|
||||
@ -353,7 +354,7 @@ Model.prototype.loadMesh = function (buffer) {
|
||||
if (numIndices > 0) {
|
||||
self.indices = new Array(numIndices);
|
||||
for (i = 0; i < numIndices; ++i) {
|
||||
self.indices[i] = r.getUint16()
|
||||
self.indices[i] = r.getUint16();
|
||||
}
|
||||
self.geometry.setIndex(new THREE.BufferAttribute(new Uint16Array(self.indices), 1));
|
||||
}
|
||||
@ -364,10 +365,10 @@ Model.prototype.loadMesh = function (buffer) {
|
||||
for (i = 0; i < numBones; ++i) {
|
||||
self.bones[i] = new Bone(self, i, r);
|
||||
if (self.boneLookup[self.bones[i].name] !== undefined) {
|
||||
self.bones[i].name = self.bones[i].name + "2"
|
||||
self.bones[i].name = self.bones[i].name + "2";
|
||||
}
|
||||
self.boneLookup[self.bones[i].name] = i;
|
||||
self.transforms[i] = new mat4.create
|
||||
self.transforms[i] = new mat4.create;
|
||||
}
|
||||
}
|
||||
self.loaded = true;
|
||||
@ -377,36 +378,36 @@ Model.prototype.loadMesh = function (buffer) {
|
||||
Model.prototype.loadAnim = function (buffer) {
|
||||
if (!buffer) {
|
||||
console.error("Bad buffer for DataView");
|
||||
return
|
||||
return;
|
||||
}
|
||||
var self = this,
|
||||
r = new DataView(buffer),
|
||||
i;
|
||||
var magic = r.getUint32();
|
||||
if (magic != 604210092) {
|
||||
if (magic !== 604210092) {
|
||||
console.log("Bad magic value");
|
||||
return
|
||||
return;
|
||||
}
|
||||
var version = r.getUint32();
|
||||
if (version >= 2) {
|
||||
var compressedData = new Uint8Array(buffer, r.position);
|
||||
var data = null;
|
||||
try {
|
||||
data = pako.inflate(compressedData)
|
||||
data = pako.inflate(compressedData);
|
||||
} catch (err) {
|
||||
console.log("Decompression error: " + err);
|
||||
return
|
||||
return;
|
||||
}
|
||||
r = new DataView(data.buffer)
|
||||
r = new DataView(data.buffer);
|
||||
}
|
||||
var numAnims = r.getUint32();
|
||||
if (numAnims > 0) {
|
||||
self.animations = new Array(numAnims);
|
||||
for (i = 0; i < numAnims; ++i) {
|
||||
self.animations[i] = new Animation(self, r, version)
|
||||
self.animations[i] = new Animation(self, r, version);
|
||||
}
|
||||
}
|
||||
self.animsLoaded = true
|
||||
self.animsLoaded = true;
|
||||
};
|
||||
|
||||
Model.prototype.on = function (eventName, callback) {
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
/**
|
||||
* @author lolking / http://www.lolking.net/models
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {Model} model 模型
|
||||
* @param {String} url 地址
|
||||
*/
|
||||
function Texture(model, url) {
|
||||
var self = this;
|
||||
self.model = model;
|
||||
self.url = url;
|
||||
self.texture = null;
|
||||
self.load()
|
||||
};
|
||||
self.load();
|
||||
}
|
||||
|
||||
Texture.prototype.load = function () {
|
||||
var self = this;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @author lolking / http://www.lolking.net/models
|
||||
* @author tengge / https://github.com/tengge1
|
||||
* @param {DataView2} r 数据视图
|
||||
*/
|
||||
function Vertex(r) {
|
||||
var self = this,
|
||||
@ -17,6 +18,6 @@ function Vertex(r) {
|
||||
for (i = 0; i < 4; ++i) {
|
||||
self.weights[i] = r.getFloat();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Vertex;
|
||||
Loading…
x
Reference in New Issue
Block a user