-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
2683 lines (2045 loc) · 61.7 KB
/
index.js
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
/*
##### Class to parse a .3ds file into a js object.
*/
var binary3DSParser = function(file, options){
this.fs = require('fs');
this.err = false;
this.errMsg = '';
this.file = '';
this.fileName = '';
this.filePath = '';
this.logPath = '';
this.dirs = {
log: "log/",
json: "json/",
edit: "edit/",
keyF: "keyframer/",
mat: "material/",
map: "map/",
mask: "mask/",
obj: "objects/",
view: "viewports/",
mesh: "mesh/",
camera: "camera/",
light: "light/"
};
this.setFileAndPath(file);
//Options
this.saveJson = false;
this.save_options = {
path: this.filePath + this.fileName,
jsonPerItem: false,
unparsedToFile: false
};
this.logging = false;
this.log_options = {
read: true,
parsing: true,
unparsed: true,
unknown: true,
jumping: false,
file: true
};
this.verbose = false;
this.verbose_options = {
onlyStats: false
};
this.trackUnparsed = false;
this.setOptions(options);
this.numOfBytes = [];
this.numOfBytes['id'] = 2, // 16 bits
this.numOfBytes['length'] = 4, // 32 bits
this.numOfBytes['header'] = 6, // 6 bytes for chunk info
this.numOfBytes['file'] = 0, // total bytes in file
this.numOfBytes['read'] = 0 // bytes read from file
this.numOfBytes['written'] = 0; // bytes written to the log file
if(this.logging){
this.fdLog = null;
this.initLogFile();
this.writeHeadingToLog();
}
if(this.isFileValid(file)){
this.fd = null;
this.fstats = null;
this.unparsed = null;
this.curPos = 0; // current position in the file
this.curChunkInfo = null; // holds the most recent header chunk information pulled from the file.
this.completed = false; // after everything needed is parsed set this flag to true.
this.eof = false; // gets set to true when we reached the end of the file.
this.headerCt = 0;
this.matCt = 0;
this.meshCt = 0;
this.unparsedCt = 0;
this.level = []; // ["Main", "Edit | KeyFramer", etc...]
}
}
binary3DSParser.prototype = {
isFileValid: function(file){
if(!file){
this.err = true;
this.errMsg = "No file or path provided.";
this.writeToLog(this.errMsg);
this.verboseToConsole(this.errMsg);
return false;
}
if(typeof file != "string"){
this.err = true;
this.errMsg = 'File value must be a path to a file of type string.';
this.writeToLog(this.errMsg);
this.verboseToConsole(this.errMsg);
return false;
}
if(file.indexOf('.3ds') < 1&&file.indexOf('.3DS') < 1){ //a.3ds is a vaild file name
this.err = true;
this.errMsg = 'Not a vaild .3ds file: ' + file;
this.writeToLog(this.errMsg);
this.verboseToConsole(this.errMsg);
return false;
}
if(!this.fs.existsSync(file)){
this.err = true;
this.errMsg = "File doesn't exist: " + file;
this.writeToLog(this.errMsg);
this.verboseToConsole(this.errMsg);
return false;
}
return true;
},
setFileAndPath: function(file){
if(file){
var items = this.getFileInfo(file);
if(items !== null){
this.filePath = items.path;
this.fileName = items.name;
this.file = items.file;
}
}
},
getFileInfo: function(f){
if(f){
var file = '';
var filePath = '';
var fileName = '';
if(f.indexOf('/') > -1){
var parts = f.split('/');
var last = parts[parts.length - 1];
if(last && last.indexOf('.') > -1){
file = last;
filePath = f.replace(file, '') ;
}
else{
filePath = f;
if(f.charAt(f.length - 1) != '/'){
filePath += '/';
}
}
}
else{
file = f;
}
fileName = file.split('.')[0];
return {file: file, name: fileName, path: filePath};
}
return null;
},
setOptions: function(options){
if(!options || options === null || typeof options != "object"){return;}
if(options.saveJson === true){
this.saveJson = true;
}
var savePath = this.save_options.path;
if(options.saveOptions && typeof options.saveOptions == "object"){
var ops = options.saveOptions;
if(ops.path && ops.path != ' ' && ops.path != "undefined" && ops.path != undefined && typeof ops.path == "string"){
var fileInfo = this.getFileInfo(ops.path);
if(fileInfo !== null){
savePath = fileInfo.path;
this.mkDir(savePath);
savePath += this.fileName;
}
}
if(ops.jsonPerItem === true){
this.save_options.jsonPerItem = true;
}
if(ops.unparsedToFile === true){
this.save_options.unparsedToFile = true;
}
}
//need to create the directory default or what was passed in.
if(savePath.charAt(savePath.length - 1) != '/'){
savePath += '/';
}
this.mkDir(savePath);
this.save_options.path = savePath;
if(options.logging === true){
this.logging = true;
}
if(options.logOptions && typeof options.logOptions == "object"){
var ops = options.logOptions;
if(ops.read === false){
this.log_options.read = false;
}
if(ops.parsing === false){
this.log_options.parsing = false;
}
if(ops.unknowns === false){
this.log_options.unknown = false;
}
if(ops.jumping === true){
this.log_options.jumping = true;
}
if(ops.file === false){
this.log_options.file = false;
}
}
if(options.verbose === true){
this.verbose = true;
}
if(options.verboseOptions && typeof options.verboseOptions == "object"){
var ops = options.verboseOptions;
if(ops.onlyStats === true){
this.verbose_options.onlyStats = true;
}
}
if(options.trackUnparsed === true){
this.trackUnparsed = true;
}
},
initFile: function(){
this.writeToLog("Opening File: " + this.filePath + this.file);
var fileData = this.openFile(this.filePath + this.file, 'r');
if(fileData !== null && fileData != undefined){
this.fstats = this.fs.fstatSync(fileData);
if(this.fstats !== null && this.fstats != undefined){
this.numOfBytes.file = this.fstats.size;
this.writeToLog("File Size: " + this.fstats.size + " bytes.");
return fileData;
}
else{
this.err = true;
this.errMsg = 'A file error has occured.';
this.writeToLog(this.errMsg);
this.verboseToConsole(this.errMsg);
this.closeFile(fileData);
}
}
else{
this.err = true;
this.errMsg = "Error opening file.";
this.writeToLog(this.errMsg);
this.verboseToConsole(this.errMsg);
}
return null;
},
initLogFile: function(){
if(this.logging){
var logPath = this.save_options.path + this.dirs.log;
var logFile = logPath + this.fileName + '.log';
this.mkDir(logPath);
this.fdLog = this.openFile(logFile, 'w');
this.logPath = logPath;
}
},
openFile: function(file, flag){
if(file && flag){
return this.fs.openSync(file, flag);
}
return null;
},
closeFile: function(fileData){
if(fileData){
this.fs.closeSync(fileData);
}
},
writeToLog: function(str){
if(this.logging === true && str != undefined){
var buffer = new Buffer(str + '\r\n');
this.numOfBytes.written += this.fs.writeSync(this.fdLog, buffer, 0, buffer.length, this.numOfBytes.written);
}
},
writeHeadingToLog: function(){
var hdMsg = "3dsTojs - .3ds to JS Parser. Log of Parsing file: " + this.filePath + this.file;
var msgLen = hdMsg.length;
var lgBrdr = Array(msgLen + 1).join('=');
var smBrdr = Array(msgLen + 1).join('-');
this.writeToLog(lgBrdr);
this.writeToLog(hdMsg);
this.writeToLog(lgBrdr);
this.writeToLog("Logging:");
for(var key in this.log_options){
this.writeToLog((key.charAt(0).toUpperCase() + key.slice(1)) + ": " + this.log_options[key]);
}
this.writeToLog(smBrdr + "\r\n");
},
writeChunkToLog: function(type, supplementText){
if(this.logging === true){
var chunk = this.curChunkInfo;
switch(type){
case 0: //Read
if(this.log_options.read === false){ return;}
type = "Read";
break;
case 1: //Parsed
if(this.log_options.parsing === false){return;}
type = "Parsed";
break;
case 2: //Error
type = ">>> Error";
break;
case 3: // Not Parsed
if(this.log_options.unparsed === false){return;}
type = ">>> Not Parsed";
break;
case 4: //Unknown
if(this.log_options.unknown === false){return;}
type = ">>> Unknown";
break;
default:
type = "####";
break;
}
if(supplementText && supplementText != undefined){
supplementText = " :: " + supplementText;
} else{
supplementText = '';
}
this.writeToLog(type + " Chunk: Id: " + this.formatHex(chunk.id) + ", Length: " + chunk.length + ", position in file: " + chunk.found_pos + " | Bytes Read: " + this.numOfBytes.read + supplementText);
}
},
writeFileToLog: function(type, fileName, path){
if(this.logging === true && this.log_options.file === true){
this.writeToLog("Saved: JSON | " + type + " | " + fileName + " | " + path);
}
},
readChunkFromFile: function(len){
if(this.fd !== null && len > 0){
var buffer = new Buffer(len);
this.numOfBytes.read += this.fs.readSync(this.fd, buffer, 0, len, this.curPos);
if(this.numOfBytes.read >= this.fstats.size){
this.eof = true;
}
this.jump(len);
return buffer;
}
return null;
},
jump: function(howMany){
this.curPos += howMany;
var msg = "Jumping: " + howMany + " positions to position " + this.curPos + " in file.";
if(this.log_options.jumping){
this.writeToLog(msg);
}
},
setLevel: function(lvl, lbl){
if(this.level){
var len = this.level.length;
var lPos = len > 0 ? len - 1 : 0;
if(lvl < lPos){
this.level = this.level.slice(0, lvl);
}
}
else{
this.level = [];
}
this.level[lvl] = lbl;
},
handleUnparsedChunk: function(type){ // type = 0: unparse due to lack of info to parse, 1: unknown
var id = this.curChunkInfo.id.toString(16);
var levelLbl = this.level.length > 1 ? this.level.join('>') : this.level[0];
if(this.trackUnparsed === true){
if(this.unparsed === null){
this.unparsed = {};
}
if(!this.unparsed[levelLbl]){
this.unparsed[levelLbl] = {};
}
if(!this.parsed[levelLbl][id]){
this.unparsed[levelLbl][id] = [];
}
this.unparsed[levelLbl][id].push(this.curChunkInfo);
}
if(this.save_options.unparsedToFile === true){
this.jump(this.numOfBytes.header * -1); // jump back to the start of the header chunk. Want to include that in the data chunk.
var buffer = this.readChunkFromFile(this.curChunkInfo.length); // now pull that full data chunk from file.
var file = this.logPath + this.fileName + "_unparsed_" + this.curChunkInfo.id.toString(16) + "_" + this.curPos + ".log";
this.fs.writeFileSync(file, buffer); // write the binary data chunk to a log file.
}
else{
this.jump(this.curChunkInfo.data_length);
}
this.unparsedCt++;
if(type == 0){
this.writeChunkToLog(3, "Not enough info to parse. Level: " + levelLbl);
this.verboseToConsole("Not enough info to parse. Id: " + id + ", Data Length: " + this.curChunkInfo.data_length + ", Level: " + levelLbl);
}
else{
this.writeChunkToLog(4, "Chunk was not parsed. Level: " + levelLbl);
this.verboseToConsole("Found Unknown Chunk. Id: " + id + ", Data Length: " + this.curChunkInfo.data_length + ", Level: " + levelLbl);
}
},
nextChunkInfo: function(){
var chunk = this.readChunkFromFile(this.numOfBytes.header);
if(chunk !== null){
this.prevChunkInfo = this.curChunkInfo;
var id = chunk.readUInt16LE(0, true);
var len = chunk.readUInt32LE(this.numOfBytes.id, true);
var dataLen = len - this.numOfBytes.header;
this.curChunkInfo = {
id: id,
length: len,
found_pos: this.curPos - this.numOfBytes.header,
data_start_pos: this.curPos,
data_length: dataLen,
poitionOfNextChunk: this.curPos + dataLen
};
this.headerCt++;
this.writeChunkToLog(0);
}
},
getString: function(len){
if(len === null){
var str = '';
var buffer = this.readChunkFromFile(1);
while(buffer[0] !== 0x00){
str += String.fromCharCode(buffer[0]);
buffer = this.readChunkFromFile(1);
}
return str;
}
else{
var buffer = this.readChunkFromFile(len);
if(buffer !== null){
return buffer.toString();
}
}
return '';
},
getShort: function(){
var buffer = this.readChunkFromFile(2);
if(buffer !== null){
return buffer.readUInt16LE(0, true);
}
},
getInt: function(){
var buffer = this.readChunkFromFile(4);
if(buffer !== null){
return buffer.readUInt32LE(0, true);
}
return 0;
},
getFloat: function(){
var buffer = this.readChunkFromFile(4);
if(buffer !== null){
return buffer.readFloatLE(0, true);
}
return null;
},
getIntPct: function(){
var buffer = this.readChunkFromFile(2);
if(buffer !== null){
return buffer.readUInt16LE(0, true);
}
return null;
},
getFloatPct: function(){
var buffer = this.readChunkFromFile(4);
if(buffer !== null){
return buffer.readFloatLE(0, true);
}
return null;
},
getPercent: function(){
this.nextChunkInfo();
switch(this.curChunkInfo.id){
case 0x0030:
return this.getIntPct();
case 0x0013:
return this.getFloatPct();
default:
this.jump(this.numOfBytes.header * -1);
return null;
}
},
getColor_24: function(){ //BYTE R,G,B
var buffer = this.readChunkFromFile(3);
if(buffer !== null){
return [
buffer.readUInt8(0), // r
buffer.readUInt8(1), // g
buffer.readUInt8(2) // b
];
}
return null;
},
getColorFloat: function(){ //FLOAT R,G,B
var buffer = this.readChunkFromFile(12);
if(buffer !== null){
return [
buffer.readFloatLE(0, true), // r
buffer.readFloatLE(4, true), // g
buffer.readFloatLE(8, true) // b
];
}
return null;
},
getColor: function(){
var eod = this.curPos + this.curChunkInfo.data_length;
var end = false;
var obj = {};
while(this.curPos < eod || !end){
this.nextChunkInfo();
switch(this.curChunkInfo.id){
case 0x0011:
this.writeChunkToLog(1);
this.verboseToConsole("Parsing Color 24...");
obj.color_24 = this.getColor_24();
break;
case 0x0012:
this.writeChunkToLog(1);
this.verboseToConsole("Parsing Lin Color 24...");
obj.lin_color_24 = this.getColor_24();
break;
case 0x0010:
this.writeChunkToLog(1);
this.verboseToConsole("Parsing Color F...");
obj.color_f = this.getColorFloat();
break;
case 0x0013:
this.writeChunkToLog(1);
this.verboseToConsole("Parsing Lin Color F...");
obj.lin_color_f = this.getColorFloat();
break;
default:
this.jump(this.numOfBytes.header * -1); // Reached the end of color chunks.
end = true;
break;
}
}
return obj;
},
parse: function(){
var data = null;
if(!this.err){
this.fd = this.initFile();
if(this.fd !== null){
this.writeToLog("Parsing Start...");
this.verboseToConsole("Parsing Start...");
var time = process.hrtime();
data = this.parseMain();
var diff = process.hrtime(time); // Parse time, diff = [seconds, nanosecoonds];
this.writeToLog("Parsing Complete.");
this.writeToLog("Closing File.");
this.verboseToConsole("Parsing Complete...");
this.verboseToConsole("Closing File...");
this.closeFile(this.fd);
this.saveToJson(data);
if(this.verbose){
this.displayStats(diff);
}
this.writeToLog(this.getStatsString(diff));
}
}
this.closeFile(this.fdLog);
var returnObj = {
err: this.err,
errMsg: this.errMsg,
data: data
};
if(this.trackUnparsed){
returnObj.unparsed = this.unparsed;
}
//console.log(returnObj.data.edit.objects[0].mesh[0].local_coords);
return returnObj;
},
parseMain: function(){
var obj = null;
this.nextChunkInfo();
if(this.curChunkInfo !== null && this.curChunkInfo.id === 0x4d4d){
obj = {};
var eod = this.curChunkInfo.data_start_pos + this.curChunkInfo.data_length;
this.setLevel(0, "4d4d(Main)");
this.writeChunkToLog(1);
this.verboseToConsole("Parsing M3D version...");
while((!this.eof || !this.completed) && this.curPos < eod){
this.nextChunkInfo();
switch(this.curChunkInfo.id){
case 0x0002: // m3d version
this.setLevel(1, "0002(M3D Version)");
this.writeChunkToLog(1);
this.verboseToConsole(". Parsing M3D version...");
obj.m3d_version = this.getInt();
break;
case 0x3d3d: // edit data chunk
this.setLevel(1, "3d3d(Edit)");
this.writeChunkToLog(1);
this.verboseToConsole(". Parsing Edit Data...");
obj.edit = this.parseEdit();
break;
case 0xB000: // key framer data chunk
this.setLevel(1, "b000(Key Framer)");
this.writeChunkToLog(1);
this.verboseToConsole(". Parsing Key Framer Data...");
obj.keyFramer = this.parseKeyFramer();
break;
default:
this.handleUnparsedChunk(1);
break;
}
}
}
else{
this.err = true;
this.errMsg = "Error parsing file: Not a valid 3ds file.";
this.writeToLog(this.errMsg);
this.verboseToConsole(this.errMsg);
}
return obj;
},
parseEdit: function(){
var editObj = {};
var mats = null;
var objs = null;
var vports = null;
var editChunk = this.curChunkInfo;
var eod = editChunk.data_start_pos + editChunk.data_length; //eod(end of data)
while(this.curPos < eod){
this.nextChunkInfo();
switch(this.curChunkInfo.id){
case 0x3d3e:
this.setLevel(2, "3d3e(Mesh Version)");
this.verboseToConsole(".. Paring Mesh Version...");
this.writeChunkToLog(1);
if(editObj === null){editObj = {};}
editObj.mesh_version = this.getInt();
break;
case 0xafff:
this.setLevel(2, "afff(Materials)");
this.verboseToConsole(".. Parsing Material Data...");
this.writeChunkToLog(1);
if(!mats || mats === null){
mats = [];
}
mats.push(this.parseMaterials());
this.matCt++;
break;
case 0x0100:
this.setLevel(2, "0100(Master Scale)");
this.verboseToConsole(".. Parsing Scale...");
this.writeChunkToLog(1);
if(editObj === null){editObj = {};}
editObj.master_scale = this.getFloat();
break;
case 0x1200:
this.setLevel(2, "1200(Solid BGND)");
this.verboseToConsole("..Parsing Solid BGND...");
this.writeChunkToLog(1);
editObj.solid_bgnd = this.getColor();
break;
case 0x1201:
this.setLevel(2, "1201(Use Solid BGND)");
this.writeChunkToLog(this.curChunkInfo.data_length > this.numOfBytes.header ? 3 : 1); // If there is data, not sure how to parse. Mostly been empty data chunks.
this.verboseToConsole(".. Parsing Use Solid BGND...");
editObj.use_solid_bgnd = null; // always seems to be an empty chunk
break;
case 0x2100:
this.setLevel(2, "2100(Ambient Light)");
this.verboseToConsole(".. Parsing Ambient Light...");
this.writeChunkToLog(1);
editObj.ambient_light = this.getColor();
break;
case 0x4000:
this.setLevel(2, "4000(Object)");
this.verboseToConsole(".. Parsing Object Data...")
this.writeChunkToLog(1);
if(!objs || objs === null){
objs = [];
}
objs.push(this.parseObjects());
break;
case 0x7001:
this.setLevel(2, "7001(Viewport)");
this.writeChunkToLog(1);
this.verboseToConsole(".. Parsing Viewport Data...");
if(!vports || vports === null){
vports = [];
}
vports.push(this.parseViewport());
break;
default:
this.handleUnparsedChunk(1);
break;
}
}
if(mats !== null){
editObj.materials = mats;
}
if(objs !== null){
editObj.objects = objs;
}
if(vports !== null){
editObj.view_ports = vports;
}
return editObj;
},
parseMaterials: function(){ //Chunk 0xafff, Child of 0x4d4d
var matObj = {};
var matChunkInfo = this.curChunkInfo;
var eod = matChunkInfo.data_start_pos + matChunkInfo.data_length;
while(this.curPos < eod){
this.nextChunkInfo();
switch(this.curChunkInfo.id){
case 0xA000: //Material Name
this.setLevel(3, "A000(Name)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Material Name...");
matObj.name = this.getString(null);
break;
case 0xA010:
this.setLevel(3, "A010(Ambient Color)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Ambient Color...");
matObj.ambient = this.getColor();
break;
case 0xA020:
this.setLevel(3, "A020(Diffuse Color)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Diffuse Color...");
matObj.diffuse = this.getColor();
break;
case 0xA030:
this.setLevel(3, "A030(Specular Color)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Specular Color...");
matObj.specular = this.getColor();
break;
case 0xA040:
this.setLevel(3, "A040(Shininess)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Shininess...");
matObj.shininess = this.getPercent();
break;
case 0xA041:
this.setLevel(3, "A041(Shininess Strength 1)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Shininess Strength 1...");
matObj.shin_strg1 = this.getPercent();
break;
case 0xA042:
this.setLevel(3, "A042(Shininess Strength 2)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Shiniess Strength 2...");
matObj.shin_strg2 = this.getPercent();
break;
case 0xA050:
this.setLevel(3, "A050(Transparency)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Transparency...");
matObj.transparency = this.getPercent();
break;
case 0xA052:
this.setLevel(3, "A052(Transparency Fall Off)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Transparency Fall Off...");
matObj.trans_fall_off = this.getPercent();
break;
case 0xA053:
this.setLevel(3, "a053(Reflect Blur)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Reflect Blur...");
matObj.reflect_blur = this.getPercent();
break;
case 0xA100:
this.setLevel(3, "a100(Type)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Type...");
matObj.type = this.getShort(); //material type, 1=flat 2=gour. 3=phong 4=metal
break;
case 0xa084:
this.setLevel(3, "a084(Self Illum)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Self Illum...");
matObj.self_illum = this.getPercent();
break;
case 0xa08a:
this.setLevel(3, "a08a(Transparency Fall Off In)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Transpare...")
matObj.trans_falloff_in = null; //so far everyone I have seen has a length of 0
break;
case 0xA087:
this.setLevel(3, "A087(Wire Size)");
this.writeChunkToLog(1);
this.verboseToConsole("... Parsing Wire Size...");
matObj.wire_size = this.getFloat();
break;
case 0xA081:
this.setLevel(3, "A081(Two Sided)");