Skip to content

Commit f2a1dfb

Browse files
committed
stateCycle() without arguments now cycles between all states
1 parent 08c8877 commit f2a1dfb

File tree

4 files changed

+71
-35
lines changed

4 files changed

+71
-35
lines changed

debug/app.coffee

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88
Light
99
} = require '../form.coffee'
1010

11-
scene = new Studio
11+
scene = new Scene
1212
width: Screen.width
1313
height: Screen.height
1414

1515

1616
new Model
1717
path: './models/flamingo/flamingo.json'
1818
parent: scene
19-
y: 80
2019
rotationY: -40
21-
material: new MeshPhongMaterial
22-
color: 0xffffff
23-
specular: 0xffffff
24-
shininess: 20
25-
vertexColors: THREE.FaceColors
20+
material: new MeshNormalMaterial
2621
morphTargets: true
2722
flatShading: true
2823
onLoad: (model) ->
2924

30-
model.animate
31-
x: 100
32-
options:
33-
time: 2.2
34-
delay: 2
35-
curve: 'easeInOutQuart'
36-
37-
scene.on Events.Pan, (e) ->
38-
model.rotationY += e.deltaX * .3
25+
model.states =
26+
test:
27+
x: 50
28+
rotationZ: 180
29+
z: 0
30+
rotationY: 0
31+
testX:
32+
x: 0
33+
rotationZ: 0
34+
z: 300
35+
rotationY: 84
36+
37+
scene.onClick ->
38+
model.stateCycle()

form/Light.coffee

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,26 @@ class exports.Light extends BaseClass
106106
@[pk] = @states.current[pk]
107107

108108
stateCycle: (stateA, stateB) ->
109-
# Check if stateA or stateB already is the current state on model
110-
if @states.current == @states[stateA] || @states.current == @states[stateB]
111-
if @states.current == @states[stateA] then @animate stateB
112-
else if @states.current == @states[stateB] then @animate stateA
109+
if arguments.length
110+
# Check if stateA or stateB already is the current state on model
111+
if @states.current == @states[stateA] || @states.current == @states[stateB]
112+
if @states.current == @states[stateA] then @animate stateB
113+
else if @states.current == @states[stateB] then @animate stateA
114+
else
115+
# If neither are current, animate to stateA
116+
@animate stateA
113117
else
114-
# If neither are current, animate to stateA
115-
@animate stateA
118+
states = Object.keys(@states)
119+
states.splice(1, 1)
120+
121+
for s, i in states
122+
if _.isEqual @states[s], @states.current
123+
if i == (states.length - 1)
124+
nextState = 0
125+
else
126+
nextState = i + 1
127+
128+
@animate states[nextState]
116129

117130

118131
# GENERIC OBJECT3D PROPERTIES

form/Model.coffee

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,26 @@ class exports.Model extends BaseClass
207207
@[pk] = @states.current[pk]
208208

209209
stateCycle: (stateA, stateB) ->
210-
# Check if stateA or stateB already is the current state on model
211-
if @states.current == @states[stateA] || @states.current == @states[stateB]
212-
if @states.current == @states[stateA] then @animate stateB
213-
else if @states.current == @states[stateB] then @animate stateA
210+
if arguments.length
211+
# Check if stateA or stateB already is the current state on model
212+
if @states.current == @states[stateA] || @states.current == @states[stateB]
213+
if @states.current == @states[stateA] then @animate stateB
214+
else if @states.current == @states[stateB] then @animate stateA
215+
else
216+
# If neither are current, animate to stateA
217+
@animate stateA
214218
else
215-
# If neither are current, animate to stateA
216-
@animate stateA
217-
219+
states = Object.keys(@states)
220+
states.splice(1, 1)
218221

222+
for s, i in states
223+
if _.isEqual @states[s], @states.current
224+
if i == (states.length - 1)
225+
nextState = 0
226+
else
227+
nextState = i + 1
219228

229+
@animate states[nextState]
220230

221231
@define 'scale',
222232
get: -> @pivot.scale.x,

form/_Camera.coffee

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,26 @@ class exports.Camera extends BaseClass
100100
@[pk] = @states.current[pk]
101101

102102
stateCycle: (stateA, stateB) ->
103-
# Check if stateA or stateB already is the current state on model
104-
if @states.current == @states[stateA] || @states.current == @states[stateB]
105-
if @states.current == @states[stateA] then @animate stateB
106-
else if @states.current == @states[stateB] then @animate stateA
103+
if arguments.length
104+
# Check if stateA or stateB already is the current state on model
105+
if @states.current == @states[stateA] || @states.current == @states[stateB]
106+
if @states.current == @states[stateA] then @animate stateB
107+
else if @states.current == @states[stateB] then @animate stateA
108+
else
109+
# If neither are current, animate to stateA
110+
@animate stateA
107111
else
108-
# If neither are current, animate to stateA
109-
@animate stateA
112+
states = Object.keys(@states)
113+
states.splice(1, 1)
114+
115+
for s, i in states
116+
if _.isEqual @states[s], @states.current
117+
if i == (states.length - 1)
118+
nextState = 0
119+
else
120+
nextState = i + 1
121+
122+
@animate states[nextState]
110123

111124
@define 'position',
112125
get: -> @nativeCamera.position

0 commit comments

Comments
 (0)