-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGhostTrails.cpp
2661 lines (2115 loc) · 85.8 KB
/
GhostTrails.cpp
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
*<
FILE: GhostTrails.cpp
DESCRIPTION: Appwizard generated plugin
CREATED BY:
$Id: GhostTrails.cpp,v 1.36 2007/07/09 09:39:24 andrew Exp $
*> Copyright (c) 1997, All Rights Reserved.
**********************************************************************/
// Disable deprecated warnings for strcpy etc.
#pragma warning(disable : 4996)
#include <time.h>
#include <wchar.h>
#include "GhostTrails.h"
#include "TrailSource.h"
#include "DlgProgress.h"
#include "IProgress.h"
#include "MaxProgress.h"
#include "MaxUtils.h"
#include "ParticleStateBuilder.h"
#include "ScopeLock.h"
#include <decomp.h>
#include <modstack.h>
#include <plugapi.h>
#include <splshape.h>
#include <texutil.h>
#include <CUSTCONT.H>
#include <STDMAT.H>
#include "Logging.h"
#define A_RENDER (A_PLUGIN1)
#define PBLOCK_REF 0
// ----------------------------------------------------------------------------
// The material channel ID of the particle age mapping channel.
static const int AGE_CHAN = 2;
HWND GhostTrails::rollupHandles[NUM_ROLLUPS];
// ----------------------------------------------------------------------------
void GhostTrailsDlgProc::DeleteThis() {
LOGIT;
DebugPrint(_T("GhostTrailsDlgProc::DeleteThis() \n"));
// rollupHandles[rollup_id] = 0;
delete this;
LOGIT;
}
// ----------------------------------------------------------------------------
BOOL GhostTrails::debugLogging = FALSE;
// ----------------------------------------------------------------------------
class GhostTrailsClassDesc : public ClassDesc2 {
public:
DWORD _dwCookie;
GhostTrailsClassDesc() {
_dwCookie = NULL;
}
int IsPublic() { return 1; }
void* Create(BOOL loading = FALSE) {
return new GhostTrails();
}
const TCHAR* ClassName() { return GetString(IDS_CLASS_NAME); }
#ifdef MAX2022
const TCHAR* NonLocalizedClassName() { return _T("GhostTrails"); }
#endif
SClass_ID SuperClassID() { return OSM_CLASS_ID; }
Class_ID ClassID() { return GHOSTTRAILS_CLASS_ID; }
const TCHAR* Category() { return GetString(IDS_CATEGORY); }
const TCHAR* InternalName() {
return _T("GhostTrails");
} // returns fixed parsable name (scripter-visible name)
HINSTANCE HInstance() { return hInstance; } // returns owning module handle
~GhostTrailsClassDesc() {}
};
// ----------------------------------------------------------------------------
static GhostTrailsClassDesc GhostTrailsDesc;
ClassDesc2* GetGhostTrailsDesc() { return &GhostTrailsDesc; }
// --------------------------------------------------------------------------------------------------------
// -------------------------------------------
// parameter validator - class declaration
// -------------------------------------------
class ParticlePickerPBValidator : public PBValidator {
// this validator picks only particle system objects
BOOL Validate(PB2Value& v) {
if (!v.r) return FALSE;
static Object* ob;
INode* node = (INode*)v.r;
if (node->GetObjectRef() && GetParticleInterface(node->GetObjectRef()))
return TRUE;
else
return FALSE;
}
};
// global instance
static ParticlePickerPBValidator particleValidator;
// ----------------------------------------------------------------------------
#ifndef MAX2013
#define p_end end
#endif
// clang-format off
ParamBlockDesc2 ghosttrails_param_blk ( GhostTrails::ghosttrails_params, _T("main"), 0, &GhostTrailsDesc,
P_AUTO_CONSTRUCT + P_AUTO_UI + P_MULTIMAP, PBLOCK_REF,
// map rollups
4,
GhostTrails::ghosttrails_map_main, IDD_PANEL_MAIN, IDS_PARAMS1, 0, 0, NULL,
GhostTrails::ghosttrails_map_meshparams, IDD_PANEL_MESHPARAMS, IDS_PARAMS2, 0, 0, NULL,
GhostTrails::ghosttrails_map_apply, IDD_PANEL_APPLY, IDS_PARAMS3, 0, 0, NULL,
GhostTrails::ghosttrails_particle, IDD_PANEL_PARTICLE, IDS_PARAMS4, 0, 0, NULL,
//ghosttrails_map_wizards, IDD_PANEL_WIZARDS, IDS_PARAMS3, 0, 0, NULL,
// START: Original Parameters
// Cannot change these!
GhostTrails::pb_frames, _T("old_frames"), TYPE_INT, P_ANIMATABLE, IDS_OLDFRAMES_SPIN,
p_default, 3,
p_range, 0, 100000,
p_ui, GhostTrails::ghosttrails_map_main, TYPE_SPINNER, EDITTYPE_INT, IDC_MAIN_FRAMES_EDIT, IDC_MAIN_FRAMES_SPIN, SPIN_AUTOSCALE,
p_end,
GhostTrails::pb_segments, _T("segments"), TYPE_INT, 0, IDS_SEGMENTS_SPIN,
p_default, 3,
p_range, 1, 10000,
//p_ui, ghosttrails_map_meshparams, TYPE_SPINNER, EDITTYPE_INT, IDC_SEGMENTS_EDIT, IDC_SEGMENTS_SPIN, SPIN_AUTOSCALE,
p_end,
GhostTrails::pb_flipnormals, _T("flipNormals"), TYPE_BOOL, 0, IDS_FLIPNORMALS,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SINGLECHEKBOX, IDC_FLIPNORMALS,
p_end,
GhostTrails::pb_splinesteps, _T("spline steps"), TYPE_INT, 0, IDS_SPLINESTEPS_SPIN,
p_default, 6,
p_range, 0, 10000,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SPINNER, EDITTYPE_INT, IDC_SPLINESTEPS_EDIT, IDC_SPLINESTEPS_SPIN, SPIN_AUTOSCALE,
p_end,
// END: Original Parameters.
// Parameters
GhostTrails::pb_type, _T("moving or still"), TYPE_INT, 0, IDS_MOVINGORANCHORED,
p_default, 0,
p_ui, GhostTrails::ghosttrails_map_main, TYPE_RADIO, 2, IDC_MAIN_TYPE_MOVING, IDC_MAIN_TYPE_ANCHORED,
p_end,
GhostTrails::pb_userange, _T("pb_userange"), TYPE_BOOL, 0, IDS_USERANGE,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_map_main, TYPE_SINGLECHEKBOX, IDC_MAIN_USERANGE,
p_end,
GhostTrails::pb_startframe, _T("start frame"), TYPE_INT, 0, IDS_STARTFRAME_SPIN,
p_default, 0,
p_range, 0, 100000000,
p_ui, GhostTrails::ghosttrails_map_main, TYPE_SPINNER, EDITTYPE_TIME, IDC_MAIN_STARTFRAME_EDIT, IDC_MAIN_STARTFRAME_SPIN, SPIN_AUTOSCALE,
p_end,
GhostTrails::pb_endframe, _T("end frame"), TYPE_INT, 0, IDS_ENDFRAME_SPIN,
p_default, GetTicksPerFrame(),
p_range, 0, 100000000,
p_ui, GhostTrails::ghosttrails_map_main, TYPE_SPINNER, EDITTYPE_TIME, IDC_MAIN_ENDFRAME_EDIT, IDC_MAIN_ENDFRAME_SPIN, SPIN_AUTOSCALE,
p_end,
//Mesh Parameters
GhostTrails::pb_segsperframe, _T("segments per frame"), TYPE_FLOAT, 0, IDS_SEGSPERFRAME_SPIN,
p_default, 1.0,
p_range, .0001, 10000.0,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SPINNER, EDITTYPE_POS_FLOAT, IDC_SEGSPERFRAME_EDIT, IDC_SEGSPERFRAME_SPIN, 0.1f,
p_end,
GhostTrails::pb_urepeat, _T("pb_urepeat"), TYPE_FLOAT, 0, IDS_UREPEAT_SPIN,
p_default, 1.0,
p_range, .0001, 10000.0,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_UREPEAT_EDIT, IDC_UREPEAT_SPIN, 0.1f,
p_end,
//Apply_Tex Parameters
GhostTrails::pb_apply_tex_b, _T("pb_apply_tex_b"), TYPE_BOOL, P_TRANSIENT, IDS_APPLY_TEX_B,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_map_apply, TYPE_SINGLECHEKBOX, IDC_APPLY_TEX_B,
p_end,
GhostTrails::pb_apply_tex_vrepeat,_T("pb_apply_tex_vrepeat"), TYPE_FLOAT, P_TRANSIENT, IDS_APPLY_TEX_VREPEAT,
p_default, 1.0,
p_range, .0001, 10000.0,
p_ui, GhostTrails::ghosttrails_map_apply, TYPE_SPINNER, EDITTYPE_FLOAT, IDC_APPLY_TEX_VREPEAT_EDIT, IDC_APPLY_TEX_VREPEAT_SPIN, 1.0f,
p_end,
//Apply_Fade Parameters
GhostTrails::pb_apply_fade_b, _T("pb_apply_fade_b"), TYPE_BOOL, P_TRANSIENT, IDS_APPLY_FADE_B,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_map_apply, TYPE_SINGLECHEKBOX, IDC_APPLY_FADE_B,
p_end,
GhostTrails::pb_apply_fade_mp, _T("pb_apply_fade_mp"), TYPE_FLOAT, P_TRANSIENT, IDS_APPLY_FADE_MP,
p_default, .8,
p_range, .0001, 1.0,
p_ui, GhostTrails::ghosttrails_map_apply, TYPE_SPINNER, EDITTYPE_POS_FLOAT, IDC_APPLY_FADE_MP_EDIT, IDC_APPLY_FADE_MP_SPIN, 0.1f,
p_end,
// Particle Trails On/Off
GhostTrails::pb_particle_trails_b, _T("pb_particle_trails_b"), TYPE_BOOL, 0, IDS_PARTICLE_B,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_particle, TYPE_SINGLECHEKBOX, IDC_PARTICLE_ENABLE,
p_end,
// Particle Node reference
GhostTrails::pb_particle_node, _T("pb_particle_node"), TYPE_INODE, 0, IDS_PARTICLE_NODE, // not animatable
p_ui, GhostTrails::ghosttrails_particle, TYPE_PICKNODEBUTTON, IDC_PARTICLE_CHOOSE,
p_validator, &particleValidator,
p_prompt, IDS_PARTICLE_NODE_PROMPT,
p_end,
GhostTrails::pb_generate_map, _T("generateMap"), TYPE_BOOL, 0, IDS_GENERATE_MAP,
p_default, TRUE,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SINGLECHEKBOX, IDC_GENERATE_MAP,
p_end,
GhostTrails::pb_generate_age_map, _T("generateAgeMap"), TYPE_BOOL, 0, IDS_GENERATE_AGE_MAP,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_particle, TYPE_SINGLECHEKBOX, IDC_GENERATE_AGE_MAP,
p_end,
// PFlow event filtering
GhostTrails::pb_useallpf, _T("useAllPFEvents"), TYPE_BOOL, 0, IDS_USEALLPFEVENTS,
p_default, TRUE,
p_ui, GhostTrails::ghosttrails_particle, TYPE_SINGLECHEKBOX, IDC_USEALLPF,
p_end,
GhostTrails::pb_pfeventlist, _T("pfEventList"), TYPE_INODE_TAB, 0, P_AUTO_UI|P_VARIABLE_SIZE, IDS_PFEVENTLIST,
p_ui, GhostTrails::ghosttrails_particle, TYPE_NODELISTBOX, IDC_PFLIST,0,0,IDC_PFREMOVE,
p_end,
GhostTrails::pb_skippart, _T("pb_skippart"), TYPE_INT, 0, IDS_SKIPPART,
p_default, 1,
p_range, 1, 1000,
p_ui, GhostTrails::ghosttrails_particle, TYPE_SPINNER, EDITTYPE_INT, IDC_PARTICLE_SKIPPARTS_EDIT, IDC_PARTICLE_SKIPPARTS_SPIN, SPIN_AUTOSCALE,
p_end,
GhostTrails::pb_startpart, _T("pb_startpart"), TYPE_INT, 0, IDS_STARTPART,
p_default, 1,
p_range, 1, 1000,
p_ui, GhostTrails::ghosttrails_particle, TYPE_SPINNER, EDITTYPE_INT, IDC_PARTICLE_STARTPART_EDIT, IDC_PARTICLE_STARTPART_SPIN, SPIN_AUTOSCALE,
p_end,
// String or Stretch mapping option.
GhostTrails::pb_maptype, _T("maptype"), TYPE_INT, 0, IDS_MAPTYPE,
p_default, 0,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_RADIO, 2, IDC_MAPTYPE_STRING, IDC_MAPTYPE_STRETCH,
p_end,
GhostTrails::pb_nummtls, _T("pb_nummtls"), TYPE_INT, 0, IDS_NUMMTLS,
p_default, 1,
p_range, 1, 1000,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SPINNER, EDITTYPE_INT, IDC_NUMMTLS_EDIT, IDC_NUMMTLS_SPIN, SPIN_AUTOSCALE,
p_end,
// Render params for segs per frame and spline steps. Added for v 3.61
GhostTrails::pb_segsperframe_render, _T("segments per frame render"), TYPE_FLOAT, 0, IDS_SEGSPERFRAME_RENDER,
p_default, 1.0,
p_range, .0001, 10000.0,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SPINNER, EDITTYPE_POS_FLOAT, IDC_SEGSPERFRAME_RENDER_EDIT, IDC_SEGSPERFRAME_RENDER_SPIN, 0.1f,
p_end,
GhostTrails::pb_segsperframe_render_on, _T("segments_render_on"), TYPE_BOOL, 0, IDS_SEGSPERFRAME_USE_RENDER,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SINGLECHEKBOX, IDC_SEGMENT_IS_RENDER,
p_end,
GhostTrails::pb_splinesteps_render, _T("spline steps render"), TYPE_INT, 0, IDS_SPLINESTEPS_RENDER,
p_default, 6,
p_range, 0, 10000,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SPINNER, EDITTYPE_INT, IDC_SPLINESTEPS_RENDER_EDIT, IDC_SPLINESTEPS_RENDER_SPIN, SPIN_AUTOSCALE,
p_end,
GhostTrails::pb_splinesteps_render_on, _T("splinesteps_render_on"), TYPE_BOOL, 0, IDS_SPLINESTEPS_USE_RENDER,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_map_meshparams, TYPE_SINGLECHEKBOX, IDC_SPLINESTEPS_IS_RENDER,
p_end,
GhostTrails::pb_use_pflow_mtlids, _T("usePFlowMtlIDs"), TYPE_BOOL, 0, IDS_USE_PFLOW_MTLIDS,
p_default, FALSE,
p_ui, GhostTrails::ghosttrails_particle, TYPE_SINGLECHEKBOX, IDC_USE_PFLOW_MTLIDS,
p_end,
p_end
);
// clang-format on
// ----------------------------------------------------------------------------
void SetAllDataDefault(IParamBlock2* pblock) {
TimeValue t(0);
// NOTE: Design decision. Do NOT corrupt the original GT1.0 data
LOGIT;
/*
pb_type,
pb_userange,
pb_startframe,
pb_endframe,
pb_segsperframe,
pb_urepeat,
*/
// Non animatable.
pblock->SetValue(GhostTrails::pb_userange, t, FALSE);
pblock->SetValue(GhostTrails::pb_startframe, t, 1);
pblock->SetValue(GhostTrails::pb_endframe, t, 100 * GetTicksPerFrame());
pblock->SetValue(GhostTrails::pb_segsperframe, t, 1.0f);
pblock->SetValue(GhostTrails::pb_segsperframe_render, t, 1.0f);
pblock->SetValue(GhostTrails::pb_splinesteps_render, t, 1);
pblock->SetValue(GhostTrails::pb_type, t, 0);
pblock->SetValue(GhostTrails::pb_urepeat, t, 1.0f);
pblock->SetValue(GhostTrails::pb_generate_map, t, TRUE);
pblock->SetValue(GhostTrails::pb_generate_age_map, t, TRUE);
pblock->SetValue(GhostTrails::pb_segsperframe_render_on, t, FALSE);
pblock->SetValue(GhostTrails::pb_splinesteps_render_on, t, FALSE);
LOGIT;
}
// ----------------------------------------------------------------------------
void EnableRollup_Main(HWND hWnd, IParamBlock2* pblock) {
LOGIT;
if (hWnd == 0) return;
BOOL bIsAnchored = FALSE;
pblock->GetValue(GhostTrails::pb_type, TimeValue(0), bIsAnchored, FOREVER);
if (!bIsAnchored) {
pblock->SetValue(GhostTrails::pb_userange, TimeValue(0), false);
}
BOOL bShowRange /*, bShowLag*/;
pblock->GetValue(GhostTrails::pb_userange, TimeValue(0), bShowRange, FOREVER);
// pblock->GetValue(GhostTrails::pb_type, TimeValue(0), bShowLag, FOREVER);
// bShowLag = !bShowLag;
{
// Start Frame.
EnableWindow(GetDlgItem(hWnd, IDC_MAIN_TEXT1), bShowRange);
ISpinnerControl* ISpin =
GetISpinner(GetDlgItem(hWnd, IDC_MAIN_STARTFRAME_SPIN));
if (ISpin) ISpin->Enable(bShowRange);
}
{
// End Frame.
EnableWindow(GetDlgItem(hWnd, IDC_MAIN_TEXT2), bShowRange);
ISpinnerControl* ISpin2 =
GetISpinner(GetDlgItem(hWnd, IDC_MAIN_ENDFRAME_SPIN));
if (ISpin2) ISpin2->Enable(bShowRange);
}
{
// Frames to lag.
EnableWindow(GetDlgItem(hWnd, IDC_MAIN_TEXT3), !bIsAnchored);
ISpinnerControl* ISpin2 =
GetISpinner(GetDlgItem(hWnd, IDC_MAIN_FRAMES_SPIN));
if (ISpin2) ISpin2->Enable(!bIsAnchored);
}
{ // The things that are only greyed out no bIsRegd
// Anchored Radio.
EnableWindow(GetDlgItem(hWnd, IDC_MAIN_TYPE_ANCHORED), TRUE);
// Range Check Box
EnableWindow(GetDlgItem(hWnd, IDC_MAIN_USERANGE), bIsAnchored);
}
LOGIT;
}
// ----------------------------------------------------------------------------
void EnableRollup_MeshParams(HWND hWnd, IParamBlock2* pblock) {
LOGIT;
if (hWnd == 0) return;
// enable because we're registered (always true now in free version).
BOOL bEnable = TRUE;
// Segs Per Frames.
BOOL bUseRenderSegs = FALSE;
pblock->GetValue(GhostTrails::pb_segsperframe_render_on, 0, bUseRenderSegs,
FOREVER);
EnableWindow(GetDlgItem(hWnd, IDC_SEGSPERFRAME_VIEWPORT_LABEL), bEnable);
EnableWindow(GetDlgItem(hWnd, IDC_SEGSPERFRAME_RENDER_LABEL),
bEnable && bUseRenderSegs);
EnableWindow(GetDlgItem(hWnd, IDC_SEGMENT_IS_RENDER), bEnable);
ISpinnerControl* ISpin = GetISpinner(GetDlgItem(hWnd, IDC_SEGSPERFRAME_SPIN));
if (ISpin) ISpin->Enable(bEnable);
ISpinnerControl* ISpinRender =
GetISpinner(GetDlgItem(hWnd, IDC_SEGSPERFRAME_RENDER_SPIN));
if (ISpinRender) ISpinRender->Enable(bEnable && bUseRenderSegs);
BOOL bUseRenderSplineSteps = FALSE;
pblock->GetValue(GhostTrails::pb_splinesteps_render_on, 0,
bUseRenderSplineSteps, FOREVER);
EnableWindow(GetDlgItem(hWnd, IDC_SPLINESTEPS_RENDER_LABEL),
bUseRenderSplineSteps);
ISpinRender = GetISpinner(GetDlgItem(hWnd, IDC_SPLINESTEPS_RENDER_SPIN));
if (ISpinRender) ISpinRender->Enable(bUseRenderSplineSteps);
// URepeat
EnableWindow(GetDlgItem(hWnd, IDC_MESHPARAMS_TEXT3), bEnable);
ISpinnerControl* ISpinURepeat =
GetISpinner(GetDlgItem(hWnd, IDC_UREPEAT_SPIN));
if (ISpinURepeat) ISpinURepeat->Enable(bEnable);
LOGIT;
}
// ----------------------------------------------------------------------------
void EnableRollup_Apply(HWND hWnd, IParamBlock2* pblock) {
LOGIT;
if (hWnd == 0) return;
TCHAR pchEditContents[200];
BOOL bShowTex, bShowFade, bShowButton;
pblock->GetValue(GhostTrails::pb_apply_tex_b, TimeValue(0), bShowTex,
FOREVER);
pblock->GetValue(GhostTrails::pb_apply_fade_b, TimeValue(0), bShowFade,
FOREVER);
GetWindowText(GetDlgItem(hWnd, IDC_APPLY_TEX_EDIT), pchEditContents, 199);
bShowButton = bShowFade || (bShowTex && *pchEditContents);
{
// Button.
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_APPLY), bShowButton);
}
{
// Tex.
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_TEX_EDIT), bShowTex);
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_TEX_TEXT), bShowTex);
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_TEX_TEXT2), bShowTex);
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_TEX_BROWSE), bShowTex);
ISpinnerControl* ISpin =
GetISpinner(GetDlgItem(hWnd, IDC_APPLY_TEX_VREPEAT_SPIN));
if (ISpin) ISpin->Enable(bShowTex);
}
{
// Fade.
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_FADE_TEXT1), bShowFade);
ISpinnerControl* ISpin2 =
GetISpinner(GetDlgItem(hWnd, IDC_APPLY_FADE_MP_SPIN));
if (ISpin2) ISpin2->Enable(bShowFade);
}
{ // The things that are only greyed out no bIsRegd (always TRUE now).
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_TEX_B), TRUE);
EnableWindow(GetDlgItem(hWnd, IDC_APPLY_FADE_B), TRUE);
}
LOGIT;
}
// ----------------------------------------------------------------------------
IObjParam* GhostTrails::ip = NULL;
//--- GhostTrails -------------------------------------------------------
// ----------------------------------------------------------------------------
GhostTrails::GhostTrails() {
debugLogging = FALSE;
LOGIT;
pblock = pblockBAD = 0;
inRenderMode = FALSE;
InitializeCriticalSection(&critSec);
isRebuildingTrails = FALSE;
*_pchApplyTexFilename = 0;
GhostTrailsDesc.MakeAutoParamBlocks(this);
LOGIT;
}
// ----------------------------------------------------------------------------
GhostTrails::~GhostTrails() {
LOGIT;
DeleteAllRefsFromMe();
DeleteCriticalSection(&critSec);
LOGIT;
}
// ----------------------------------------------------------------------------
Interval GhostTrails::LocalValidity(TimeValue t) {
LOGIT;
// if being edited, return NEVER forces a cache to be built
// after previous modifier.
if (TestAFlag(A_MOD_BEING_EDITED)) return NEVER;
// TODO: Return the validity interval of the modifier
LOGIT;
return Interval(t, t);
// return NEVER;
}
// ----------------------------------------------------------------------------
RefTargetHandle GhostTrails::Clone(RemapDir& remap) {
ScopeLock scopeLock(&critSec);
LOGIT;
GhostTrails* newmod = new GhostTrails();
// TODO: Add the cloning code here
LOGIT;
newmod->ReplaceReference(0, pblock->Clone(remap));
LOGIT;
return (newmod);
}
// ----------------------------------------------------------------------------
class CModifyException {};
// ----------------------------------------------------------------------------
//
// Calculate and return the following values from the GT parameters
//
// pStart -
//
//
// Returns TRUE is all values could be calculated successfully, FALSE otherwise
//
BOOL gGetStartAndEndTimes(IParamBlock2* pBlock, Interval& curTime,
TimeValue* pStart, TimeValue* pEnd, double* pLevels,
double* pTicksPerLevel, BOOL inRenderMode) {
// LOGIT;
if (!pBlock) return FALSE;
// Get start/end frame usage
BOOL bShowRange;
pBlock->GetValue(GhostTrails::pb_userange, TimeValue(0), bShowRange, FOREVER);
// Get frame values for start and end
int iStartFrame = curTime.Start();
int iEndFrame = curTime.End();
if (bShowRange) {
pBlock->GetValue(GhostTrails::pb_startframe, TimeValue(0), iStartFrame,
FOREVER);
pBlock->GetValue(GhostTrails::pb_endframe, TimeValue(0), iEndFrame,
FOREVER);
// Not saved as frames anymore (as of v3.06)
// iStartFrame *= GetTicksPerFrame();
// iEndFrame *= GetTicksPerFrame();
}
// Get ticks values for start and end
if (iStartFrame > iEndFrame) return FALSE;
int ticksStartFrame = iStartFrame; //* GetTicksPerFrame();
int ticksEndFrame = iEndFrame; //* GetTicksPerFrame();
// Get levels per frame
BOOL bUseRenderSegs = FALSE;
pBlock->GetValue(GhostTrails::pb_segsperframe_render_on, 0, bUseRenderSegs,
FOREVER);
float fLevelsPerFrame = 0.0;
if (bUseRenderSegs && inRenderMode)
pBlock->GetValue(GhostTrails::pb_segsperframe_render, 0, fLevelsPerFrame,
FOREVER);
else
pBlock->GetValue(GhostTrails::pb_segsperframe, 0, fLevelsPerFrame, FOREVER);
// Calculate fTicksPerLevel
if (fLevelsPerFrame == 0.0) return FALSE;
double fTicksPerLevel = (1.0 / fLevelsPerFrame) * GetTicksPerFrame();
// Crop the end frames against the given time interval.
if (curTime.End() < ticksStartFrame) return FALSE;
if (curTime.End() < ticksEndFrame) ticksEndFrame = curTime.End();
// Calculate how many levels.
if (fTicksPerLevel == 0.0) return FALSE;
double fLevels = (ticksEndFrame - ticksStartFrame) / fTicksPerLevel;
if (pStart) *pStart = ticksStartFrame;
if (pEnd) *pEnd = ticksEndFrame;
if (pTicksPerLevel) *pTicksPerLevel = fTicksPerLevel;
if (pLevels) *pLevels = fLevels;
// LOGIT;
return TRUE;
}
// ----------------------------------------------------------------------------
//
// GTWorkingValues is a holding pen for all the calculations, data structures
// and intermediate values involved in building the mesh in
// GhostTrails::ModifyObject(). The idea is to make it easy to pass the state
// of the calculation at any point to another method.
//
class GTWorkingValues {
public:
GTWorkingValues() {}
BOOL texturing; // Should UVs be generated for the mesh.
BOOL ageTexturing; // Should the Age UV channel (2) be generated
BOOL usePFlowMtlIDs; // Should we take material IDs from PFlow.
GhostTrails::GTMapType mapType; // Stretch or String Mapping
BOOL bIsPathAnchored; // Trailing or anchored path.
BOOL flipNormals; // Are normal to be flipped.
int nSplineSegments; // Number of spline segments in the trail.
float fURepeat; // number of times the texture repeats in U
float fVRepeat; // number of times the texture repeats in V
int iNumMtlIDs; // Number of material IDs to apply to trails.
BOOL bEasyFade; // ??
std::vector<TimeValue>
caLevelTimes; // The time (ticks) of each segment in the trail.
int nMotionlessLevels; // Number of levels at the end of the trail that are
// in the same location. This value used by stretch
// mapping to correct UVs
double fOverlapPercentage;
double fLevelsIfShowAll;
TimeValue ticksStartTime;
TimeValue ticksEndTime;
TimeValue minTrailTime; // minimum time at which we will generate a trail for
// this frame.
BOOL bUsingCache; // ???
TriObject* tri; // The TriObject for the trail mesh.
PolyShape pShape; // The shape object to use for trail construction.
int polys; // total number of polygons per trail level.
int levelVerts; // Vertexes per trail level.
int levelFaces; // Faces per trail level
int levelTVerts; // UV verts per trail level.
int verts; // Total number of verts in the mesh
int faces; // Total number of faces in the mesh.
int tVerts; // Total number of UV verts in the mesh.
TimeValue t; // The time (ticks) of mesh generation.
ITrailSource*
trailSource; // The source of the trails (spline animation or particles)
int numActiveTrails; // The number of active (ie not stationary) trails
INode* theNode;
int skipParticle; // every n'th particle...
int startParticle; // starting at particle m
private:
// don't allow object copies
GTWorkingValues(const GTWorkingValues&);
GTWorkingValues& operator=(const GTWorkingValues&);
};
// ----------------------------------------------------------------------------
class GhostTrailsLocalModData : public LocalModData {
public:
GhostTrailsLocalModData();
virtual ~GhostTrailsLocalModData() {}
virtual LocalModData* Clone();
// used to store the node pointer for a modifier.
INode* pNode;
};
// ----------------------------------------------------------------------------
GhostTrailsLocalModData::GhostTrailsLocalModData() { pNode = NULL; }
//
// Clone the object
//
LocalModData* GhostTrailsLocalModData::Clone() {
GhostTrailsLocalModData* pClone = new GhostTrailsLocalModData();
// force recalculation of node (as the copied modifer will probably be
// assigned to a newly created one).
pClone->pNode = NULL;
return pClone;
}
// ----------------------------------------------------------------------------
Interval GhostTrails::GetValidity(TimeValue t) {
LOGIT;
Interval valid;
valid.SetInstant(t);
LOGIT;
return valid;
}
// ----------------------------------------------------------------------------
void GhostTrails::ModifyObject(TimeValue t, ModContext& mc, ObjectState* os,
INode* node) {
LOGITM("Entering ModifyObject()");
// LOGIT;
ScopeLock scopeLock(&critSec);
// to hold the working values for the mesh calculation.
GTWorkingValues wv;
wv.t = t;
Interval valid;
valid.SetInstant(t);
// DebugPrint("In ModifyObject - time %d os = %x\n", t, os);
try {
if (isRebuildingTrails) {
// We don't want to redraw while the trails are rebuilding
DebugPrint(_T("GhostTrails::ModifyObject called during trail rebuild\n"));
LOGITM("GhostTrails::ModifyObject called during trail rebuild");
throw CModifyException();
}
if (!mc.localData) {
LOGITM("Making a new GhostTrailsLocalModData");
mc.localData = new GhostTrailsLocalModData; // 3dsmax is responsible for
// deleting mc.localData.
}
GhostTrailsLocalModData* gtLocalData =
(GhostTrailsLocalModData*)mc.localData;
if (!gtLocalData->pNode) {
LOGIT;
gtLocalData->pNode = MaxUtils::FindNodeReference(this, &mc);
LOGIT;
}
if (!gtLocalData->pNode)
throw CModifyException(); // Can't find the node for some reason (should
// never happen).
wv.theNode = gtLocalData->pNode;
// DebugPrint(" In ModifyObject - Node is %s [%x]\n",
// wv.theNode->GetName(), wv.theNode);
if (os->obj->SuperClassID() != SHAPE_CLASS_ID) throw CModifyException();
LOGIT;
initializeWorkingValues(wv);
LOGIT;
calculateTrailTimes(wv);
// Get Mesh object to set points and faces.
Mesh& mesh = wv.tri->GetMesh();
// Get Shape at Time.
for (int poly = 0; poly < wv.polys; ++poly) {
PolyLine& line = wv.pShape.lines[poly];
if (line.numPts <= 0) continue;
if (line.IsClosed()) {
wv.levelTVerts++;
}
wv.levelVerts += line.numPts;
wv.levelTVerts += line.numPts;
wv.levelFaces += (line.Segments() * 2);
}
LOGIT;
// work out how many of the trails need to have a mesh generated for them
wv.numActiveTrails = 0;
for (int nTrail = 0; nTrail < wv.trailSource->numTrails(); nTrail++) {
if (!isSkippedTrail(nTrail, wv)) {
wv.numActiveTrails++;
}
}
LOGIT;
// DebugPrint("Num Active Trails at %d = %d (of %d)\n", wv.t /
// GetTicksPerFrame(), wv.numActiveTrails, wv.trailSource->numTrails());
wv.verts = wv.numActiveTrails * wv.levelVerts * (wv.caLevelTimes.size());
wv.tVerts = wv.numActiveTrails * wv.caLevelTimes.size() * wv.levelTVerts;
wv.faces =
wv.numActiveTrails * wv.levelFaces * (wv.caLevelTimes.size() - 1);
mesh.setNumVerts(wv.verts);
mesh.setNumFaces(wv.faces);
if (wv.texturing) {
mesh.setNumTVerts(wv.tVerts);
mesh.setNumTVFaces(wv.faces);
}
LOGIT;
buildMeshUVVertices(wv);
LOGIT;
buildMeshUVAgeVertices(wv);
LOGIT;
buildMeshVertices(wv);
LOGIT;
buildMeshFaces(wv);
LOGIT;
mesh.InvalidateGeomCache();
mesh.InvalidateTopologyCache();
LOGIT;
// wv.tri->SetChannelValidity(ALL_CHANNELS, valid);
wv.tri->SetChannelValidity(TOPO_CHAN_NUM, valid);
wv.tri->SetChannelValidity(GEOM_CHAN_NUM, valid);
wv.tri->SetChannelValidity(TEXMAP_CHAN_NUM, valid);
wv.tri->SetChannelValidity(MTL_CHAN_NUM, valid);
wv.tri->SetChannelValidity(SELECT_CHAN_NUM, valid);
wv.tri->SetChannelValidity(SUBSEL_TYPE_CHAN_NUM, valid);
wv.tri->SetChannelValidity(DISP_ATTRIB_CHAN_NUM, valid);
wv.tri->SetChannelValidity(VERT_COLOR_CHAN_NUM, valid);
os->obj = wv.tri;
// VV os->obj->UpdateValidity(OBJ_CHANNELS, valid);
// const Mesh& m = static_cast<TriObject*>(os->obj)->GetMesh();
// DebugPrint(" In ModifyObject - MeshStats %d:%d:%d\n", m.getNumVerts(),
// m.getNumFaces(), m.getNumTVerts());
LOGIT;
os->obj->UnlockObject();
LOGIT;
} catch (...) {
// something went wrong - just invalidate the object and return.
LOGIT;
TriObject* tri = CreateNewTriObject();
if (!tri) return;
LOGIT;
// Go to the effort of creating real geometry to minimise the chance that
// 3dsmax will decide it never needs to evaluate the object again.
tri->mesh.setNumVerts(3);
tri->mesh.setNumFaces(1);
tri->mesh.verts[0].x = 0.0f;
tri->mesh.verts[0].y = 0.0f;
tri->mesh.verts[0].z = 0.0f;
tri->mesh.verts[1].x = 1.0f;
tri->mesh.verts[1].y = 0.0f;
tri->mesh.verts[1].z = 0.0f;
tri->mesh.verts[2].x = 0.0f;
tri->mesh.verts[2].y = 1.0f;
tri->mesh.verts[2].z = 0.0f;
tri->mesh.faces[0].v[0] = 0;
tri->mesh.faces[0].v[1] = 1;
tri->mesh.faces[0].v[2] = 2;
tri->mesh.InvalidateGeomCache();
tri->mesh.InvalidateTopologyCache();
// Set the valididty to just this instant because the mesh generation
// might work next frame.
// wv.tri->SetChannelValidity(ALL_CHANNELS, valid);
tri->SetChannelValidity(TOPO_CHAN_NUM, valid);
tri->SetChannelValidity(GEOM_CHAN_NUM, valid);
tri->SetChannelValidity(TEXMAP_CHAN_NUM, valid);
tri->SetChannelValidity(MTL_CHAN_NUM, valid);
tri->SetChannelValidity(SELECT_CHAN_NUM, valid);
tri->SetChannelValidity(SUBSEL_TYPE_CHAN_NUM, valid);
tri->SetChannelValidity(DISP_ATTRIB_CHAN_NUM, valid);
tri->SetChannelValidity(VERT_COLOR_CHAN_NUM, valid);
os->obj = tri;
// os->obj->UpdateValidity(OBJ_CHANNELS, valid);
LOGIT;
os->obj->UnlockObject();
LOGIT;
}
LOGITM("Leaving ModifyObject()");
}
// ----------------------------------------------------------------------------
// Return TRUE is this particle should be skipped for trail generation
//
BOOL GhostTrails::isSkippedTrail(int nTrail, GTWorkingValues& wv) {
int startPart = wv.startParticle - 1;
if (nTrail < startPart) return TRUE;
if (((nTrail - startPart) % wv.skipParticle) != 0) return TRUE;
if (wv.trailSource->isTrailStationary(nTrail, wv.minTrailTime, wv.t,
GetTicksPerFrame(), wv.caLevelTimes))
return TRUE;
return FALSE;
}
// ----------------------------------------------------------------------------
void GhostTrails::initializeWorkingValues(GTWorkingValues& wv) {
//
// Initialize the GTWorkingValues object in preparation
// for the trail generation calculations
//
LOGITM("Entering initializeWorkingValues()");
LOGIT;
pblock->GetValue(pb_generate_map, wv.t, wv.texturing, FOREVER);
pblock->GetValue(pb_generate_age_map, wv.t, wv.ageTexturing, FOREVER);
pblock->GetValue(pb_use_pflow_mtlids, wv.t, wv.usePFlowMtlIDs, FOREVER);
LOGIT;
// 0. Get Map Type
wv.mapType = eString;
int mt;
pblock->GetValue(pb_maptype, wv.t, mt, FOREVER);
switch (mt) {
case 0:
wv.mapType = eString;
break;
case 1:
wv.mapType = eStretch;
break;
}
LOGIT;
// 1. Get Type Moving or Still?
wv.bIsPathAnchored = FALSE;
pblock->GetValue(pb_type, wv.t, wv.bIsPathAnchored, FOREVER);
LOGIT;
// 3. Get FlipNormal
wv.flipNormals = FALSE;
pblock->GetValue(pb_flipnormals, wv.t, wv.flipNormals, FOREVER);
LOGIT;
// 4. Get nSplineSegments
wv.nSplineSegments = 6;
BOOL bUseRenderSteps = FALSE;
pblock->GetValue(GhostTrails::pb_splinesteps_render_on, 0, bUseRenderSteps,
FOREVER);
if (bUseRenderSteps && inRenderMode)
pblock->GetValue(pb_splinesteps_render, wv.t, wv.nSplineSegments, FOREVER);
else
pblock->GetValue(pb_splinesteps, wv.t, wv.nSplineSegments, FOREVER);
LOGIT;
// 5. Get fURepeat
wv.fURepeat = 1.0;
pblock->GetValue(pb_urepeat, wv.t, wv.fURepeat, FOREVER);
LOGIT;
// 5.5. Get iNumMtlIDs
wv.iNumMtlIDs = 1;
pblock->GetValue(pb_nummtls, wv.t, wv.iNumMtlIDs, FOREVER);
LOGIT;
// 6. Get fVRepeat
wv.fVRepeat = 1.0;
// pblock->GetValue(pb_vrepeat, wv.t, fVRepeat, FOREVER);