bugfix: recursive animation works
This commit is contained in:
parent
7162621efe
commit
0bbf3ae5e4
Binary file not shown.
|
@ -4,6 +4,7 @@ xrf.frag.t = function(v, opts){
|
|||
if( !model.animations || model.animations[0] == undefined ) return console.warn('no animation in scene')
|
||||
|
||||
xrf.mixers.map ( (mixer) => {
|
||||
|
||||
mixer.t = v
|
||||
|
||||
// update speed
|
||||
|
@ -27,22 +28,26 @@ xrf.addEventListener('parseModel', (opts) => {
|
|||
let {model} = opts
|
||||
let mixer = model.mixer = new xrf.THREE.AnimationMixer(model.scene)
|
||||
mixer.model = model
|
||||
mixer.loop = {}
|
||||
mixer.loop = {timeStart:0,timeStop:0}
|
||||
mixer.i = xrf.mixers.length
|
||||
mixer.actions = []
|
||||
|
||||
model.animations.map( (anim) => {
|
||||
anim.action = mixer.clipAction( anim, model.scene )
|
||||
anim.optimize()
|
||||
mixer.actions.push( mixer.clipAction( anim, model.scene ) )
|
||||
})
|
||||
|
||||
|
||||
mixer.checkZombies = (animations) => {
|
||||
if( mixer.zombieCheck ) return // fire only once
|
||||
animations.map( (anim) => {
|
||||
// collect zombie animations and warn user
|
||||
let zombies = anim.tracks.map( (t) => {
|
||||
let name = t.name.replace(/\..*/,'')
|
||||
return !model.scene.getObjectByName(name) ? {anim:anim.name,obj:t.name} : undefined
|
||||
let obj = model.scene.getObjectByName(name)
|
||||
return !model.scene.getObjectByName(name) ? {anim:anim.name,obj:name} : undefined
|
||||
})
|
||||
if( zombies.length > 0 ){
|
||||
if( zombies.length > 0 && mixer.i == 0 ){ // only warn for zombies in main scene (because src-scenes might be filtered anyways)
|
||||
zombies
|
||||
.filter( (z) => z ) // filter out undefined
|
||||
.map( (z) => console.warn(`gltf: object '${z.obj}' not found (anim: '${z.anim}'`) )
|
||||
|
@ -65,15 +70,15 @@ xrf.addEventListener('parseModel', (opts) => {
|
|||
mixer.updateLoop = (t) => {
|
||||
mixer.loop.timeStart = t.y != undefined ? t.y : mixer.loop.timeStart
|
||||
mixer.loop.timeStop = t.z != undefined ? t.z : mixer.loop.timeStop
|
||||
mixer.model.animations.map( (anim) => {
|
||||
mixer.actions.map( (action) => {
|
||||
if( mixer.loop.timeStart != undefined ){
|
||||
//if( anim.action ) delete anim.action
|
||||
//anim.action = mixer.clipAction( anim )
|
||||
anim.action.time = mixer.loop.timeStart
|
||||
anim.action.setLoop( THREE.LoopOnce, )
|
||||
anim.action.timeScale = mixer.timeScale
|
||||
anim.action.enabled = true
|
||||
if( t.x != 0 ) anim.action.play()
|
||||
action.time = mixer.loop.timeStart
|
||||
action.setLoop( THREE.LoopOnce, )
|
||||
action.timeScale = mixer.timeScale
|
||||
action.enabled = true
|
||||
if( t.x != 0 ){
|
||||
action.play()
|
||||
}
|
||||
}
|
||||
})
|
||||
mixer.setTime(mixer.loop.timeStart)
|
||||
|
@ -90,7 +95,7 @@ xrf.addEventListener('parseModel', (opts) => {
|
|||
if( time == 0 ) return update.call(this,time)
|
||||
|
||||
// loop jump
|
||||
if( mixer.loop.speed > 0.0 && mixer.time > mixer.loop.timeStop ){
|
||||
if( mixer.loop.speed > 0.0 && (mixer.loop.timeStop > 0 && mixer.time > mixer.loop.timeStop) ){
|
||||
setTimeout( (time,anims) => mixer.updateLoop(time), 0, mixer.loop.timeStart ) // prevent recursion
|
||||
}
|
||||
return update.call( this, time )
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// test the XR Fragments parser-filters with THREEjs scenes
|
||||
// test the XR Fragments parser-filters with THREEjs scns
|
||||
THREE = AFRAME.THREE
|
||||
|
||||
createScene = (noadd) => {
|
||||
|
@ -6,6 +6,7 @@ createScene = (noadd) => {
|
|||
for ( let i in obj ){
|
||||
obj[i] = new THREE.Object3D()
|
||||
obj[i].name = i
|
||||
obj[i].material = {visible:true, clone: () => ({visible:true}) }
|
||||
}
|
||||
let {a,b,c} = obj
|
||||
let scene = new THREE.Scene()
|
||||
|
@ -15,6 +16,11 @@ createScene = (noadd) => {
|
|||
scene.add(a)
|
||||
}
|
||||
b.userData.score = 2
|
||||
b.userData.tag = "foo bar"
|
||||
c.userData.tag = "flop flap"
|
||||
a.userData.price = 1
|
||||
b.userData.price = 5
|
||||
c.userData.price = 10
|
||||
return {a,b,c,scene}
|
||||
}
|
||||
|
||||
|
@ -22,84 +28,78 @@ filterScene = (URI) => {
|
|||
frag = xrf.URI.parse(URI)
|
||||
var {a,b,c,scene} = createScene()
|
||||
xrf.filter.scene({scene,frag})
|
||||
|
||||
scene.visible = (objname, expected, checkMaterial) => {
|
||||
let o = scene.getObjectByName(objname)
|
||||
if( !o ) return false === expected
|
||||
let is = checkMaterial ? o.material.visible : o.visible
|
||||
if( is !== expected ) console.dir(o)
|
||||
return is === expected
|
||||
}
|
||||
|
||||
return scene
|
||||
}
|
||||
|
||||
scene = filterScene("#b")
|
||||
test = () => !scene.getObjectByName("a") &&
|
||||
scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #b => a = removed b = visible c = removed`})
|
||||
scn = filterScene("#b")
|
||||
test = () => !scn.visible("a") && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`objectname: #b `})
|
||||
|
||||
scene = filterScene("#b*")
|
||||
test = () => !scene.getObjectByName("a") &&
|
||||
scene.getObjectByName("b").visible &&
|
||||
scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #b* => a = removed b = visible c = visible`})
|
||||
scn = filterScene("#-b")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",false) && scn.visible("c",false)
|
||||
console.assert( test(), {scn,reason:`objectname: #-b `})
|
||||
|
||||
scene = filterScene("#-b")
|
||||
test = () => scene.getObjectByName("a").visible &&
|
||||
!scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #-b => a = visible b = invisible c = invisible`})
|
||||
scn = filterScene("#a&-b")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",false) && scn.visible("c",false)
|
||||
console.assert( test(), {scn,reason:`objectname: #a&-b `})
|
||||
|
||||
scene = filterScene("#a&-b")
|
||||
test = () => scene.getObjectByName("a").visible &&
|
||||
!scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #a&-b => a = visible b = invisible c = invisible`})
|
||||
scn = filterScene("#-b&b")
|
||||
test = () => scn.visible("a",false) && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`objectname: #-b&b `})
|
||||
|
||||
scene = filterScene("#-b&b")
|
||||
test = () => !scene.getObjectByName("a") &&
|
||||
scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #-b&b => a = removed b = invisible c = invisible (last duplicate wins)`})
|
||||
scn = filterScene("#-c")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("c",false)
|
||||
console.assert( test(), {scn,reason:`objectname: #-c `})
|
||||
|
||||
scene = filterScene("#-c")
|
||||
test = () => scene.getObjectByName("a").visible &&
|
||||
scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #-b&b => a = visible b = visible c = invisible`})
|
||||
scn = filterScene("#score")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`propertyfilter: #score `})
|
||||
|
||||
scene = filterScene("#-b*")
|
||||
test = () => scene.getObjectByName("a").visible &&
|
||||
!scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #-b&b => a = visible b = visible c = invisible`})
|
||||
scn = filterScene("#score=>1")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`propertyfilter: #score`})
|
||||
|
||||
scene = filterScene("#score")
|
||||
console.dir(scene)
|
||||
test = () => !scene.getObjectByName("a") &&
|
||||
scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #score => a = removed b = visible c = invisible`})
|
||||
scn = filterScene("#score=2")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`propertyfilter: #score`})
|
||||
|
||||
scene = filterScene("#score=>1")
|
||||
test = () => !scene.getObjectByName("a") &&
|
||||
scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #score=>1 => a = removed b = visible c = invisible`})
|
||||
scn = filterScene("#score=>3")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",false) && scn.visible("c",false)
|
||||
console.assert( test(), {scn,reason:`propertyfilter: #score`})
|
||||
|
||||
scene = filterScene("#score=>3")
|
||||
test = () => !scene.getObjectByName("a") &&
|
||||
!scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #score=>3 => a = invisible b = visible c = invisible`})
|
||||
scn = filterScene("#-score=>1")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",false) && scn.visible("c",false)
|
||||
console.assert( test(), {scn,reason:`propertyfilter: #-score`})
|
||||
|
||||
scene = filterScene("#score*=>1")
|
||||
test = () => !scene.getObjectByName("a") &&
|
||||
scene.getObjectByName("b").visible &&
|
||||
scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #score*=>1 => a = invisible b = visible c = visible`})
|
||||
scn = filterScene("#-score=>1&c")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("b",false,true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`propertyfilter: #-score`})
|
||||
|
||||
scene = filterScene("#-score*=>1")
|
||||
test = () => scene.getObjectByName("a").visible &&
|
||||
!scene.getObjectByName("b").visible &&
|
||||
!scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #-score*=>1 => a = visible b = invisible c = invisible`})
|
||||
scn = filterScene("#-foo")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",false) && scn.visible("b",false)
|
||||
console.assert( test(), {scn,reason:`tagfilter: #-foo `})
|
||||
|
||||
scene = filterScene("#-score*=>1&c")
|
||||
test = () => scene.getObjectByName("a").visible &&
|
||||
!scene.getObjectByName("b").visible &&
|
||||
scene.getObjectByName("c").visible
|
||||
console.assert( test(), {scene,reason:`objectname: #-score*=>1 => a = visible b = invisible c = visible`})
|
||||
scn = filterScene("#-c&flop")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`tagfilter: #-c&flop`})
|
||||
|
||||
scn = filterScene("#-b&-foo&bar&flop")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`tagfilter: #-b&-foo&bar&flop`})
|
||||
|
||||
scn = filterScene("#-b&-foo&bar&flop&-bar&flop")
|
||||
test = () => scn.visible("a",true) && scn.visible("b",false,true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`tagfilter: #-b&-foo&bar&flop&-bar&flop"`})
|
||||
|
||||
scn = filterScene("#-price&price=>4")
|
||||
test = () => scn.visible("a",false,true) && scn.visible("b",true) && scn.visible("c",true)
|
||||
console.assert( test(), {scn,reason:`tagfilter: #-price&price=>4"`})
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
console.assert = ((assert) => (a,b) => {
|
||||
console.log('♥ test: '+b.reason)
|
||||
console.log("\x1b[34m♥ \x1b[36;49mtest: "+b.reason+"\x1B[m")
|
||||
assert.call( console, a, b )
|
||||
})(console.assert)
|
||||
|
||||
|
|
Loading…
Reference in New Issue