1、修复Collada材质加载问题。

2、新增Collada模型动画。
This commit is contained in:
liteng 2018-12-01 10:55:05 +08:00
parent fa46a0b5ff
commit a398b46dbd
5 changed files with 3926 additions and 1598 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@ THREE.TGALoader.prototype = {
var loader = new THREE.FileLoader( this.manager );
loader.setResponseType( 'arraybuffer' );
loader.setPath( this.path );
loader.load( url, function ( buffer ) {
@ -535,6 +536,13 @@ THREE.TGALoader.prototype = {
return canvas;
},
setPath: function ( value ) {
this.path = value;
return this;
}
};

View File

@ -110,7 +110,7 @@
<script src="assets/js/loaders/BabylonLoader.js"></script>
<script src="assets/js/loaders/BinaryLoader.js"></script>
<script src="assets/js/loaders/BVHLoader.js"></script>
<script src="assets/js/loaders/ColladaLoader2.js"></script>
<script src="assets/js/loaders/ColladaLoader.js"></script>
<script src="assets/js/loaders/FBXLoader.js"></script>
<script src="assets/js/loaders/DRACOLoader.js"></script>
<script src="assets/js/loaders/GLTFLoader.js"></script>

View File

@ -22,17 +22,34 @@ ColladaLoader.prototype.load = function (url, options) {
if (child instanceof THREE.Mesh) {
child.material.flatShading = true;
}
if (child.isSkinnedMesh) {
child.frustumCulled = false;
}
});
dae.scale.x = dae.scale.y = dae.scale.z = 10.0;
dae.updateMatrix();
if (isNaN(dae.scale.x) || isNaN(dae.scale.y) || isNaN(dae.scale.z)) {
dae.scale.x = dae.scale.y = dae.scale.z = 10.0;
dae.updateMatrix();
}
Object.assign(dae.userData, {
obj: collada,
root: dae
});
if (collada.animations && collada.animations.length > 0) {
Object.assign(dae.userData, {
animNames: collada.animations.map(n => n.name),
scripts: [{
id: null,
name: `${options.Name}动画`,
type: 'javascript',
source: this.createScripts(options.Name),
uuid: THREE.Math.generateUUID()
}]
});
}
resolve(dae);
}, undefined, () => {
resolve(null);
@ -40,4 +57,13 @@ ColladaLoader.prototype.load = function (url, options) {
});
};
ColladaLoader.prototype.createScripts = function (name) {
return `var mesh = this.getObjectByName('${name}');\n\n` +
`var obj = mesh.userData.obj;\n\n` +
`var root = mesh.userData.root;\n\n` +
`var mixer = new THREE.AnimationMixer(root);\n\n` +
`mixer.clipAction(obj.animations[0]).play();\n\n` +
`function update(clock, deltaTime) { \n mixer.update(deltaTime); \n}`;
};
export default ColladaLoader;