-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add control to play specific sequence-variations. #15
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ | |
{ | ||
"imports": { | ||
"three": "https://unpkg.com/[email protected]/build/three.module.js", | ||
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/" | ||
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/", | ||
"lil-gui": "https://unpkg.com/[email protected]/dist/lil-gui.esm.js" | ||
} | ||
} | ||
</script> | ||
|
@@ -27,13 +28,14 @@ | |
import * as THREE from 'three'; | ||
|
||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; | ||
import { GUI } from 'three/addons/libs/lil-gui.module.min.js'; | ||
import { GUI } from 'lil-gui'; | ||
|
||
import { M2Loader } from '../M2Loader.js'; | ||
|
||
const params = { | ||
asset: 'cat/druidcat2.m2', | ||
sequences: 0, | ||
sequence: 0, | ||
variation: 0, | ||
playGlobalSequences: true | ||
}; | ||
|
||
|
@@ -51,7 +53,7 @@ | |
|
||
let camera, scene, renderer, controls, loader, clock; | ||
|
||
let gui, animationFolder; | ||
let gui, animationFolder, variationCtrl; | ||
|
||
let m2Scene, m2SequenceManager; | ||
|
||
|
@@ -115,20 +117,17 @@ | |
|
||
// animations | ||
|
||
animationFolder = gui.addFolder( 'Animations' ); | ||
|
||
m2SequenceManager = m2.userData.sequenceManager; | ||
|
||
// the list() methods provide arrays with all available sequences (animations) | ||
// the list() method provide arrays with all available sequences (animations) | ||
|
||
const sequences = m2SequenceManager.listSequences(); | ||
|
||
animationFolder = gui.addFolder( 'Animations' ); | ||
|
||
if ( sequences.length > 0 ) { | ||
|
||
const sequence = sequences[ 0 ]; // pick first sequence | ||
m2SequenceManager.playSequence( sequence.id ); | ||
|
||
// make all sequences selectable via the UI | ||
// make all sequences and variations selectable via the UI | ||
|
||
const uiSequences = {}; | ||
|
||
|
@@ -139,15 +138,21 @@ | |
|
||
} | ||
|
||
animationFolder.add( params, 'sequences', uiSequences ).onChange( onSequenceChange ); | ||
animationFolder.add( params, 'sequence', uiSequences ).onChange( onSequenceChange ); | ||
variationCtrl = animationFolder.add( params, 'variation', [] ).onChange( onVariationChange ); | ||
|
||
// play first sequence | ||
|
||
const sequence = sequences[ 0 ]; | ||
onSequenceChange( sequence.id ); | ||
|
||
} | ||
|
||
if ( m2SequenceManager.hasGlobalSequences() ) { | ||
|
||
m2SequenceManager.playGlobalSequences(); | ||
|
||
animationFolder.add( params, 'playGlobalSequences' ).onChange( onPlayGlobalSequencesChange ); | ||
|
||
m2SequenceManager.playGlobalSequences(); | ||
|
||
} | ||
|
||
|
@@ -203,7 +208,8 @@ | |
m2SequenceManager.stopSequence(); | ||
m2SequenceManager.stopGlobalSequences(); | ||
|
||
params.sequences = 0; | ||
params.sequence = 0; | ||
params.variation = 0; | ||
params.playGlobalSequences = true; | ||
|
||
animationFolder.destroy(); | ||
|
@@ -217,6 +223,22 @@ | |
m2SequenceManager.stopSequence(); | ||
m2SequenceManager.playSequence( id ); | ||
|
||
// | ||
|
||
params.variation = 0; | ||
|
||
const variations = m2SequenceManager.listVariations( id ); | ||
variationCtrl.options( variations ); | ||
|
||
( variations.length > 1 ) ? variationCtrl.enable() : variationCtrl.disable(); | ||
|
||
} | ||
|
||
function onVariationChange( variationIndex ) { | ||
|
||
m2SequenceManager.stopSequence(); | ||
m2SequenceManager.playSequence( m2SequenceManager.currentSequenceId, variationIndex ); | ||
|
||
} | ||
|
||
function onPlayGlobalSequencesChange( value ) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For simplicity, I have moved the
M2_SEQUENCE_EMBEDDED_DATA
check toplaySequence()
. Meaning the manager now reports all sequences and variations again but warns the users if animation data are not available.