From f2a1dfbc412da8b634e23b66c5bfb467d9e941c1 Mon Sep 17 00:00:00 2001 From: Emil Widlund Date: Tue, 8 May 2018 13:23:00 +0200 Subject: [PATCH] stateCycle() without arguments now cycles between all states --- debug/app.coffee | 32 ++++++++++++++++---------------- form/Light.coffee | 25 +++++++++++++++++++------ form/Model.coffee | 24 +++++++++++++++++------- form/_Camera.coffee | 25 +++++++++++++++++++------ 4 files changed, 71 insertions(+), 35 deletions(-) diff --git a/debug/app.coffee b/debug/app.coffee index f8d0a9a..d73c018 100644 --- a/debug/app.coffee +++ b/debug/app.coffee @@ -8,7 +8,7 @@ Light } = require '../form.coffee' -scene = new Studio +scene = new Scene width: Screen.width height: Screen.height @@ -16,23 +16,23 @@ scene = new Studio new Model path: './models/flamingo/flamingo.json' parent: scene - y: 80 rotationY: -40 - material: new MeshPhongMaterial - color: 0xffffff - specular: 0xffffff - shininess: 20 - vertexColors: THREE.FaceColors + material: new MeshNormalMaterial morphTargets: true flatShading: true onLoad: (model) -> - model.animate - x: 100 - options: - time: 2.2 - delay: 2 - curve: 'easeInOutQuart' - - scene.on Events.Pan, (e) -> - model.rotationY += e.deltaX * .3 \ No newline at end of file + model.states = + test: + x: 50 + rotationZ: 180 + z: 0 + rotationY: 0 + testX: + x: 0 + rotationZ: 0 + z: 300 + rotationY: 84 + + scene.onClick -> + model.stateCycle() \ No newline at end of file diff --git a/form/Light.coffee b/form/Light.coffee index 38950af..7971086 100644 --- a/form/Light.coffee +++ b/form/Light.coffee @@ -106,13 +106,26 @@ class exports.Light extends BaseClass @[pk] = @states.current[pk] stateCycle: (stateA, stateB) -> - # Check if stateA or stateB already is the current state on model - if @states.current == @states[stateA] || @states.current == @states[stateB] - if @states.current == @states[stateA] then @animate stateB - else if @states.current == @states[stateB] then @animate stateA + if arguments.length + # Check if stateA or stateB already is the current state on model + if @states.current == @states[stateA] || @states.current == @states[stateB] + if @states.current == @states[stateA] then @animate stateB + else if @states.current == @states[stateB] then @animate stateA + else + # If neither are current, animate to stateA + @animate stateA else - # If neither are current, animate to stateA - @animate stateA + states = Object.keys(@states) + states.splice(1, 1) + + for s, i in states + if _.isEqual @states[s], @states.current + if i == (states.length - 1) + nextState = 0 + else + nextState = i + 1 + + @animate states[nextState] # GENERIC OBJECT3D PROPERTIES diff --git a/form/Model.coffee b/form/Model.coffee index 46c5f51..9f979f1 100644 --- a/form/Model.coffee +++ b/form/Model.coffee @@ -207,16 +207,26 @@ class exports.Model extends BaseClass @[pk] = @states.current[pk] stateCycle: (stateA, stateB) -> - # Check if stateA or stateB already is the current state on model - if @states.current == @states[stateA] || @states.current == @states[stateB] - if @states.current == @states[stateA] then @animate stateB - else if @states.current == @states[stateB] then @animate stateA + if arguments.length + # Check if stateA or stateB already is the current state on model + if @states.current == @states[stateA] || @states.current == @states[stateB] + if @states.current == @states[stateA] then @animate stateB + else if @states.current == @states[stateB] then @animate stateA + else + # If neither are current, animate to stateA + @animate stateA else - # If neither are current, animate to stateA - @animate stateA - + states = Object.keys(@states) + states.splice(1, 1) + for s, i in states + if _.isEqual @states[s], @states.current + if i == (states.length - 1) + nextState = 0 + else + nextState = i + 1 + @animate states[nextState] @define 'scale', get: -> @pivot.scale.x, diff --git a/form/_Camera.coffee b/form/_Camera.coffee index dc70c29..3ae5166 100644 --- a/form/_Camera.coffee +++ b/form/_Camera.coffee @@ -100,13 +100,26 @@ class exports.Camera extends BaseClass @[pk] = @states.current[pk] stateCycle: (stateA, stateB) -> - # Check if stateA or stateB already is the current state on model - if @states.current == @states[stateA] || @states.current == @states[stateB] - if @states.current == @states[stateA] then @animate stateB - else if @states.current == @states[stateB] then @animate stateA + if arguments.length + # Check if stateA or stateB already is the current state on model + if @states.current == @states[stateA] || @states.current == @states[stateB] + if @states.current == @states[stateA] then @animate stateB + else if @states.current == @states[stateB] then @animate stateA + else + # If neither are current, animate to stateA + @animate stateA else - # If neither are current, animate to stateA - @animate stateA + states = Object.keys(@states) + states.splice(1, 1) + + for s, i in states + if _.isEqual @states[s], @states.current + if i == (states.length - 1) + nextState = 0 + else + nextState = i + 1 + + @animate states[nextState] @define 'position', get: -> @nativeCamera.position