Mugen87 / three-m2loader

three.js loader for importing M2 assets from World of Warcraft.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for loading `.anim` files.

Mugen87 opened this issue · comments

Low priority sequences (like emotes) are not embedded in M2 files but located in separate files with .anim extensions. There is such a file for each low priority sequence and it can be identified via the sequence and subsequence id.

Each sequence that does not hold the 0x20 value in its flag is a called external sequence and must be processed in a separate code path.

I think it's best to introduce an option (loadExternalSequences) that can be passed to the load() method. It's default value would be false. When set to true, the loader automatically loads all external .anim files. Their content is stored as array buffers internally and used when parsing tracks.

I have changed my mind. I think we can support lazy loading when SequenceManager.playSequence() is called. But we must ensure to avoid duplicate track parsing logic if possible.

Such an approach should better match to developer's expectations than a loadExternalSequences flag.

const filename = this.filename;
const resourcePath = this.resourcePath;
const sequenceId = id.toString().padStart( 4, '0' );
const subSequenceId = variationIndex.toString().padStart( 2, '0' );

const path = resourcePath + filename + sequenceId + '-' + subSequenceId + '.anim';

fetch( path ).then( ( response ) => {

	if ( response.ok === false ) {

		throw new Error( `Unable to load animation file. HTTP error, response status = ${response.status}` );

	}

	return response.arrayBuffer();

} ).then( ( buffer ) => {

	console.log( buffer );

} );

The above code shows how the path for an external animation file is build and how the loading process looks like. However, I'm not sure yet how to update the existing keyframes with these new track data.

Fixed via 53749a3.