1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Date;
class MultiMotion extends TriggeredSwitchableBehavior implements FrameHandler, Persister, MouseDownHandler, BumpHandler {
protected int motionNumber = 0;
protected int motionNumberCount = 0;
protected int motionNumberMax = 100;
long startMultiMotionTime;
long totalMultiMotionTime = 0L;
protected String cycleTime;
protected float[] cycleTimeArray;
protected int cycles;
protected Transform MultiMotionTransform;
protected String startPoint;
protected String endPoint;
protected String deltaPoint;
protected String startScale;
protected String endScale;
protected String deltaScale;
protected String startSpin;
protected String endSpin;
protected Point3[] startPointArray;
protected Point3[] endPointArray;
protected Point3[] deltaPointArray;
protected Point3[] startScaleArray;
protected Point3[] endScaleArray;
protected Point3[] deltaScaleArray;
protected Point3[] startSpinArray;
protected Point3[] endSpinArray;
protected String startRotation;
protected String endRotation;
protected float[] startRotationArray;
protected float[] endRotationArray;
protected boolean MultiMotionTransformInitialized;
protected boolean variableInitialized;
protected boolean multiMotionEnd = true;
public MultiMotion() {
this.cycleTime = new String("1000");
this.cycleTimeArray = new float[this.motionNumberMax];
this.cycleTimeArray[0] = 1000.0F;
this.trigger = new String("none");
this.externalTriggerTag = new String("");
this.cycles = 0;
this.MultiMotionTransformInitialized = false;
this.variableInitialized = false;
this.startPointArray = new Point3[this.motionNumberMax];
this.endPointArray = new Point3[this.motionNumberMax];
this.deltaPointArray = new Point3[this.motionNumberMax];
this.startScaleArray = new Point3[this.motionNumberMax];
this.endScaleArray = new Point3[this.motionNumberMax];
this.deltaScaleArray = new Point3[this.motionNumberMax];
this.startSpinArray = new Point3[this.motionNumberMax];
this.endSpinArray = new Point3[this.motionNumberMax];
for (int i = 0; i < this.motionNumberMax; i++) {
this.startPointArray[i] = new Point3();
this.endPointArray[i] = new Point3();
this.deltaPointArray[i] = new Point3();
this.startScaleArray[i] = new Point3();
this.endScaleArray[i] = new Point3();
this.deltaScaleArray[i] = new Point3();
this.startSpinArray[i] = new Point3();
this.endSpinArray[i] = new Point3();
}
this.startRotationArray = new float[this.motionNumberMax];
this.endRotationArray = new float[this.motionNumberMax];
this.startMultiMotion();
}
@Override
public void ExternalTrigger(Trigger trigger_source, int sequence_no, int event_no) {
this.trigger_source = trigger_source;
this.sequence_no = sequence_no;
this.event_no = event_no;
this.startMultiMotion();
}
public void startMultiMotion() {
Date timer = new Date();
this.startMultiMotionTime = timer.getTime();
this.motionNumber = 0;
this.multiMotionEnd = false;
}
public void setTotalMultiMotionTime() {
this.totalMultiMotionTime = 0L;
for (int i = 0; i < this.motionNumberCount; i++) {
this.totalMultiMotionTime = this.totalMultiMotionTime + (int)this.cycleTimeArray[i];
}
}
public void parseFloatString(String floatList, float[] floatArray) {
int currentIndex = 0;
int currentSeparator = 0;
int nextSeparator = 0;
int lastSeparator = floatList.lastIndexOf(" ");
if (lastSeparator != -1 || floatList.length() != 0) {
if (lastSeparator == -1) {
floatArray[currentIndex] = Float.valueOf(floatList);
} else {
nextSeparator = floatList.indexOf(" ");
floatArray[currentIndex] = Float.valueOf(floatList.substring(0, nextSeparator));
currentIndex++;
while (nextSeparator != lastSeparator) {
currentSeparator = nextSeparator;
nextSeparator = floatList.indexOf(" ", nextSeparator + 1);
floatArray[currentIndex] = Float.valueOf(floatList.substring(currentSeparator + 1, nextSeparator));
currentIndex++;
}
floatArray[currentIndex] = Float.valueOf(floatList.substring(nextSeparator + 1));
}
}
}
public Point3 StringToPoint3(String Point3String) {
Point3 newPoint3 = new Point3();
int currentIndex = 0;
newPoint3.x = Float.valueOf(Point3String.substring(currentIndex, Point3String.indexOf(",", currentIndex)));
currentIndex = Point3String.indexOf(",", currentIndex) + 1;
newPoint3.y = Float.valueOf(Point3String.substring(currentIndex, Point3String.indexOf(",", currentIndex)));
currentIndex = Point3String.indexOf(",", currentIndex) + 1;
newPoint3.z = Float.valueOf(Point3String.substring(currentIndex, Point3String.length()));
return newPoint3;
}
public void parsePoint3String(String Point3List, Point3[] Point3Array) {
int currentIndex = 0;
int currentSeparator = 0;
int nextSeparator = 0;
int lastSeparator = Point3List.lastIndexOf(" ");
if (lastSeparator != -1 || Point3List.length() != 0) {
if (lastSeparator == -1) {
Point3Array[currentIndex] = this.StringToPoint3(Point3List);
} else {
nextSeparator = Point3List.indexOf(" ");
Point3Array[currentIndex] = this.StringToPoint3(Point3List.substring(0, nextSeparator));
currentIndex++;
while (nextSeparator != lastSeparator) {
currentSeparator = nextSeparator;
nextSeparator = Point3List.indexOf(" ", nextSeparator + 1);
Point3Array[currentIndex] = this.StringToPoint3(Point3List.substring(currentSeparator + 1, nextSeparator));
currentIndex++;
}
Point3Array[currentIndex] = this.StringToPoint3(Point3List.substring(nextSeparator + 1));
}
}
}
@Override
public boolean handle(FrameEvent e) {
if (!this.MultiMotionTransformInitialized) {
this.MultiMotionTransform = e.target;
this.MultiMotionTransformInitialized = true;
}
if (!this.variableInitialized) {
this.startPoint = this.MultiMotionTransform.getPosition().toString();
this.startPointArray[0].copy(this.MultiMotionTransform.getPosition());
this.endPoint = new String(this.startPoint);
this.endPointArray[0].copy(this.startPointArray[0]);
this.startScaleArray[0].x = this.MultiMotionTransform.getTotalScale();
this.startScaleArray[0].y = this.MultiMotionTransform.getTotalScale();
this.startScaleArray[0].z = this.MultiMotionTransform.getTotalScale();
this.startScale = this.startScaleArray[0].toString();
this.endScaleArray[0].copy(this.startScaleArray[0]);
this.endScale = this.endScaleArray[0].toString();
this.startRotation = new Float(this.MultiMotionTransform.getSpin(this.startSpinArray[0])).toString();
this.startRotationArray[0] = Float.valueOf(this.startRotation);
this.startSpin = this.startSpinArray[0].toString();
this.endRotation = new String("0.0");
this.endRotationArray[0] = Float.valueOf(this.endRotation);
this.endSpinArray[0] = new Point3();
this.endSpin = this.endSpinArray[0].toString();
this.variableInitialized = true;
}
if (this.enabled) {
Date timer = new Date();
long currentTime = timer.getTime();
int cycleNo = 0;
if (this.totalMultiMotionTime > 0L) {
cycleNo = (int)((-this.startMultiMotionTime + currentTime) / this.totalMultiMotionTime);
}
if (this.totalMultiMotionTime > 0L && (cycleNo < this.cycles || this.cycles == 0)) {
long totalTime = 0L;
int currentCycleTime = (int)((currentTime - this.startMultiMotionTime) % this.totalMultiMotionTime);
int currentMotionTime = 0;
for (this.motionNumber = 0; this.motionNumber < this.motionNumberCount && totalTime <= currentCycleTime; this.motionNumber++) {
currentMotionTime = (int)this.cycleTimeArray[this.motionNumber];
totalTime += currentMotionTime;
}
this.motionNumber--;
if (totalTime < currentCycleTime) {
System.out.print("Error in totalMultiMotionTime computation.\n");
}
currentMotionTime = (int)(currentMotionTime - (totalTime - currentCycleTime));
float frameLoc = currentMotionTime % this.cycleTimeArray[this.motionNumber] / this.cycleTimeArray[this.motionNumber];
e.receiver.makeIdentity();
e.receiver
.scale(
this.startScaleArray[this.motionNumber].x + (this.endScaleArray[this.motionNumber].x - this.startScaleArray[this.motionNumber].x) * frameLoc,
this.startScaleArray[this.motionNumber].x + (this.endScaleArray[this.motionNumber].x - this.startScaleArray[this.motionNumber].x) * frameLoc,
this.startScaleArray[this.motionNumber].x + (this.endScaleArray[this.motionNumber].x - this.startScaleArray[this.motionNumber].x) * frameLoc
);
e.receiver
.moveTo(
this.startPointArray[this.motionNumber].x + (this.endPointArray[this.motionNumber].x - this.startPointArray[this.motionNumber].x) * frameLoc,
this.startPointArray[this.motionNumber].y + (this.endPointArray[this.motionNumber].y - this.startPointArray[this.motionNumber].y) * frameLoc,
this.startPointArray[this.motionNumber].z + (this.endPointArray[this.motionNumber].z - this.startPointArray[this.motionNumber].z) * frameLoc
);
e.receiver.spin(this.startSpinArray[this.motionNumber], this.startRotationArray[this.motionNumber]);
e.receiver.spin(this.endSpinArray[this.motionNumber], this.endRotationArray[this.motionNumber] * frameLoc);
} else if (cycleNo >= this.cycles && this.cycles != 0 && !this.multiMotionEnd) {
this.multiMotionEnd = true;
if (this.trigger_source != null) {
this.trigger_source.registerFinishedTriggerTag(this.sequence_no, this.event_no);
}
}
}
return true;
}
@Override
public boolean handle(MouseDownEvent e) {
if (this.enabled && this.trigger.equals("click")) {
this.startMultiMotion();
}
return true;
}
@Override
public boolean handle(BumpEventTemp e) {
if (this.enabled && this.trigger.equals("bump")) {
this.startMultiMotion();
}
return true;
}
public void startTransform() {
if (this.MultiMotionTransform != null) {
this.MultiMotionTransform.makeIdentity();
this.MultiMotionTransform
.scale(this.startScaleArray[this.motionNumber].x, this.startScaleArray[this.motionNumber].x, this.startScaleArray[this.motionNumber].x);
this.MultiMotionTransform
.moveTo(this.startPointArray[this.motionNumber].x, this.startPointArray[this.motionNumber].y, this.startPointArray[this.motionNumber].z);
this.MultiMotionTransform.spin(this.startSpinArray[this.motionNumber], this.startRotationArray[this.motionNumber]);
}
}
public void endTransform() {
if (this.MultiMotionTransform != null) {
this.MultiMotionTransform.makeIdentity();
this.MultiMotionTransform
.scale(this.endScaleArray[this.motionNumber].x, this.endScaleArray[this.motionNumber].x, this.endScaleArray[this.motionNumber].x);
this.MultiMotionTransform
.moveTo(this.endPointArray[this.motionNumber].x, this.endPointArray[this.motionNumber].y, this.endPointArray[this.motionNumber].z);
this.MultiMotionTransform.spin(this.startSpinArray[this.motionNumber], this.startRotationArray[this.motionNumber]);
this.MultiMotionTransform.spin(this.endSpinArray[this.motionNumber], this.endRotationArray[this.motionNumber]);
}
}
@Override
public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
Object ret = null;
switch (index - offset) {
case 0:
if (mode == 0) {
ret = new ClassProperty(this, index, "MultiMotion");
}
break;
case 1:
if (mode == 0) {
ret = IntegerPropertyEditor.make(new Property(this, index, "Number of Motions"));
} else if (mode == 1) {
ret = new Integer(this.motionNumberCount);
} else if (mode == 2) {
this.motionNumberCount = (Integer)value;
this.setTotalMultiMotionTime();
}
break;
case 2:
if (mode == 0) {
ret = IntegerPropertyEditor.make(new Property(this, index, "Cycles"));
} else if (mode == 1) {
ret = new Integer(this.cycles);
} else if (mode == 2) {
this.cycles = (Integer)value;
}
break;
case 3:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "Trigger"));
} else if (mode == 1) {
ret = new String(this.trigger);
} else if (mode == 2) {
this.trigger = ((String)value).toString().trim();
if (this.trigger.equals("external")) {
Trigger.TriggeredSwitchableBehaviorList[Trigger.TriggeredSwitchableBehaviorListCount] = this;
Trigger.TriggeredSwitchableBehaviorListCount++;
}
}
break;
case 4:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "External Trigger Tag"));
} else if (mode == 1) {
ret = new String(this.externalTriggerTag);
} else if (mode == 2) {
this.externalTriggerTag = ((String)value).toString().trim();
}
break;
case 5:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "Cycle Time"));
} else if (mode == 1) {
ret = new String(this.cycleTime);
} else if (mode == 2) {
this.cycleTime = (String)value;
this.parseFloatString(this.cycleTime, this.cycleTimeArray);
this.setTotalMultiMotionTime();
}
break;
case 6:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "End Point"));
} else if (mode == 1) {
ret = new String(this.endPoint);
this.endTransform();
} else if (mode == 2) {
this.endPoint = (String)value;
this.parsePoint3String(this.endPoint, this.endPointArray);
this.endTransform();
}
break;
case 7:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "Start Point"));
} else if (mode == 1) {
ret = new String(this.startPoint);
this.startTransform();
} else if (mode == 2) {
this.startPoint = (String)value;
this.parsePoint3String(this.startPoint, this.startPointArray);
this.startTransform();
}
break;
case 8:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "End Scale"));
} else if (mode == 1) {
ret = new String(this.endScale);
this.endTransform();
} else if (mode == 2) {
this.endScale = (String)value;
this.parsePoint3String(this.endScale, this.endScaleArray);
this.endTransform();
}
break;
case 9:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "Start Scale"));
} else if (mode == 1) {
ret = new String(this.startScale);
this.startTransform();
} else if (mode == 2) {
this.startScale = (String)value;
this.parsePoint3String(this.startScale, this.startScaleArray);
this.startTransform();
}
break;
case 10:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "End Spin (Relative)"));
} else if (mode == 1) {
ret = new String(this.endSpin);
this.endTransform();
} else if (mode == 2) {
this.endSpin = (String)value;
this.parsePoint3String(this.endSpin, this.endSpinArray);
this.endTransform();
}
break;
case 11:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "Start Spin"));
} else if (mode == 1) {
ret = new String(this.startSpin);
this.startTransform();
} else if (mode == 2) {
this.startSpin = (String)value;
this.parsePoint3String(this.startSpin, this.startSpinArray);
this.startTransform();
}
break;
case 12:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "End Rotation (Relative)"));
} else if (mode == 1) {
ret = new String(this.endRotation);
this.endTransform();
} else if (mode == 2) {
this.endRotation = (String)value;
this.parseFloatString(this.endRotation, this.endRotationArray);
this.endTransform();
}
break;
case 13:
if (mode == 0) {
ret = StringPropertyEditor.make(new Property(this, index, "Start Rotation"));
} else if (mode == 1) {
ret = new String(this.startRotation);
this.startTransform();
} else if (mode == 2) {
this.startRotation = (String)value;
this.parseFloatString(this.startRotation, this.startRotationArray);
this.startTransform();
}
break;
default:
ret = super.properties(index, offset + 14, mode, value);
}
if (mode == 2 && this.trigger.equals("none")) {
this.startMultiMotion();
}
return ret;
}
@Override
public String toString() {
return "Multimotion: cycleTime "
+ this.cycleTime
+ ", cycles "
+ this.cycles
+ ", enabled "
+ this.enabled
+ ", trigger "
+ this.trigger
+ ", externalTriggerTag "
+ this.externalTriggerTag;
}
@Override
public void saveState(Saver s) throws IOException {
s.saveInt(this.motionNumberCount);
s.saveInt(this.cycles);
s.saveString(this.trigger);
s.saveString(this.externalTriggerTag);
s.saveString(this.cycleTime);
s.saveString(this.endPoint);
s.saveString(this.startPoint);
s.saveString(this.endScale);
s.saveString(this.startScale);
s.saveString(this.endSpin);
s.saveString(this.startSpin);
s.saveString(this.endRotation);
s.saveString(this.startRotation);
}
@Override
public void restoreState(Restorer r) throws IOException {
this.motionNumberCount = r.restoreInt();
this.cycles = r.restoreInt();
this.trigger = r.restoreString();
if (this.trigger.equals("external")) {
Trigger.TriggeredSwitchableBehaviorList[Trigger.TriggeredSwitchableBehaviorListCount] = this;
Trigger.TriggeredSwitchableBehaviorListCount++;
}
this.externalTriggerTag = r.restoreString();
this.cycleTime = r.restoreString();
this.parseFloatString(this.cycleTime, this.cycleTimeArray);
this.endPoint = r.restoreString();
this.parsePoint3String(this.endPoint, this.endPointArray);
this.setTotalMultiMotionTime();
this.startPoint = r.restoreString();
this.parsePoint3String(this.startPoint, this.startPointArray);
this.endScale = r.restoreString();
this.parsePoint3String(this.endScale, this.endScaleArray);
this.startScale = r.restoreString();
this.parsePoint3String(this.startScale, this.startScaleArray);
this.endSpin = r.restoreString();
this.parsePoint3String(this.endSpin, this.endSpinArray);
this.startSpin = r.restoreString();
this.parsePoint3String(this.startSpin, this.startSpinArray);
this.endRotation = r.restoreString();
this.parseFloatString(this.endRotation, this.endRotationArray);
this.startRotation = r.restoreString();
this.parseFloatString(this.startRotation, this.startRotationArray);
this.variableInitialized = true;
if (!this.trigger.equals("none")) {
this.startMultiMotionTime = (int)(-(this.cycles * this.cycleTimeArray[this.motionNumber]));
} else {
this.startMultiMotion();
}
}
@Override
public void postRestore(int version) {
String name = this.getName();
String arg1 = name == null ? "<null>" : name;
SuperRoot owner = this.getOwner();
String oname = "";
if (owner != null) {
oname = owner.getName();
}
String arg2 = oname == null ? "<null>" : oname;
Object[] arguments = new Object[]{new String(arg1), new String(arg2)};
Console.println(MessageFormat.format(Console.message("MultiMotion-obs"), arguments));
}
}
|