Skip to content

Commit

Permalink
stateCycle() without arguments now cycles between all states
Browse files Browse the repository at this point in the history
  • Loading branch information
emilwidlund committed May 8, 2018
1 parent 08c8877 commit f2a1dfb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 35 deletions.
32 changes: 16 additions & 16 deletions debug/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@
Light
} = require '../form.coffee'

scene = new Studio
scene = new Scene
width: Screen.width
height: Screen.height


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
model.states =
test:
x: 50
rotationZ: 180
z: 0
rotationY: 0
testX:
x: 0
rotationZ: 0
z: 300
rotationY: 84

scene.onClick ->
model.stateCycle()
25 changes: 19 additions & 6 deletions form/Light.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 17 additions & 7 deletions form/Model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 19 additions & 6 deletions form/_Camera.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f2a1dfb

Please sign in to comment.