-
Notifications
You must be signed in to change notification settings - Fork 0
/
ivcon.c
16715 lines (13727 loc) · 397 KB
/
ivcon.c
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
/* ivcon.c 24 May 2001 */
/*
http://orion.math.iastate.edu/burkardt/g_src/ivcon/ivcon.html
The program can be used in command line form, as in:
ivcon input.iv output.stl
or can be used in an interactive mode, in which input and output files can be read or converted in any order.
Graphics file formats are poorly documented; hence this program was written primarily by examining typical files and struggling to interpret them. Particularly in the case of Inventor and DXF files, the program is not able to handle all the subtleties of the file format, and may mangle data, or even crash.
Helpful corrections to the 3DS reader were supplied by John F Flanagan. The GMOD reader and writer were written and supplied by Zik Saleeba. Improvements to the DXF routines to handle polygon oriented files were supplied by Zik Saleeba. The 3DS reader is based on a program by Martin van Velsen, with the help of Gert van der Spoel.
IVCON is a C version of the FORTRAN IVREAD program.
*/
/*
Purpose:
IVCON converts various 3D graphics files.
Acknowledgements:
Coding, comments, and advice were supplied by a number of collaborators.
John F Flanagan made some corrections to the 3D Studio Max routines.
Zik Saleeba ([email protected]) enhanced the DXF routines, and added the
Golgotha GMOD routines.
Thanks to Susan M. Fisher, University of North Carolina,
Department of Computer Science, for pointing out a coding error
in FACE_NULL_DELETE that was overwriting all the data!
Modified:
04 July 2000
Author:
John Burkardt
*/
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FALSE 0
#define TRUE 1
#define ERROR 1
#define G1_SECTION_MODEL_QUADS 18
#define G1_SECTION_MODEL_TEXTURE_NAMES 19
#define G1_SECTION_MODEL_VERT_ANIMATION 20
#define GMOD_MAX_SECTIONS 32
#define GMOD_UNUSED_VERTEX 65535
#define PI 3.141592653589793238462643
#define SUCCESS 0
#define DEG_TO_RAD ( PI / 180.0 )
#define RAD_TO_DEG ( 180.0 / PI )
/******************************************************************************/
/* GLOBAL DATA */
/******************************************************************************/
/*
BACKGROUND_RGB[3], the background color.
BYTE_SWAP, byte swapping option.
COR3[3][COR3_MAX], the coordinates of nodes.
COR3_MATERIAL[COR3_MAX], the index of the material of each node.
COR3_MAX, the maximum number of points.
COR3_NORMAL[3][COR3_MAX], normal vectors associated with nodes.
COR3_NUM, the number of points.
COR3_RGB[3][COR3_MAX], RGB colors associated with nodes.
COR3_TEX_UV[2][COR3_MAX], texture coordinates associated with nodes.
FACE[ORDER_MAX][FACE_MAX] contains the index of the I-th node making up face J.
FACE_AREA(FACE_MAX), the area of each face.
FACE_MATERIAL[FACE_MAX]; the material of each face.
FACE_MAX, the maximum number of faces.
FACE_NORMAL[3][FACE_MAX], the face normal vectors.
FACE_NUM, the number of faces.
FACE_ORDER[FACE_MAX], the number of vertices per face.
FACE_TEX_UV[2][FACE_MAX], texture coordinates associated with faces.
LINE_DEX[LINES_MAX], node indices, denoting polylines, each terminated by -1.
LINE_MATERIAL[LINES_MAX], index into RGBCOLOR for line color.
LINES_MAX, the maximum number of line definition items.
LINE_NUM, the number of line definition items.
LINE_PRUNE, pruning option ( 0 = no pruning, nonzero = pruning).
MATERIAL_MAX, the maximum number of materials.
MATERIAL_NUM, the number of materials.
ORDER_MAX, the maximum number of vertices per face.
TEXTURE_MAX, the maximum number of textures.
TEXTURE_NAME[TEXTURE_MAX][LINE_MAX_LEN], ...
TEXTURE_NUM, the number of textures.
TRANSFORM_MATRIX[4][4], the current transformation matrix.
VERTEX_MATERIAL[ORDER_MAX][FACE_MAX]; the material of vertices of faces.
VERTEX_NORMAL[3][ORDER_MAX][FACE_MAX], normals at vertices of faces.
VERTEX_RGB[3][ORDER_MAX][FACE_MAX], colors of vertices of faces.
VERTEX_TEX_UV[2][ORDER_MAX][FACE_MAX], texture coordinates of vertices of faces.
*/
#define COLOR_MAX 1000
#define COR3_MAX 200000
#define FACE_MAX 200000
#define LINE_MAX_LEN 256
#define LEVEL_MAX 10
#define LINES_MAX 100000
#define MATERIAL_MAX 100
#define ORDER_MAX 10
#define TEXTURE_MAX 100
char anim_name[LINE_MAX_LEN];
float background_rgb[3];
int bad_num;
int byte_swap;
int bytes_num;
int color_num;
int comment_num;
float cor3[3][COR3_MAX];
int cor3_material[COR3_MAX];
float cor3_normal[3][COR3_MAX];
int cor3_num;
float cor3_tex_uv[3][COR3_MAX];
int debug;
int dup_num;
int face[ORDER_MAX][FACE_MAX];
float face_area[FACE_MAX];
int face_flags[FACE_MAX];
int face_material[FACE_MAX];
float face_normal[3][FACE_MAX];
int face_num;
int face_object[FACE_MAX];
int face_order[FACE_MAX];
int face_smooth[FACE_MAX];
float face_tex_uv[2][FACE_MAX];
char filein_name[81];
char fileout_name[81];
int group_num;
int i;
char input[LINE_MAX_LEN];
int k;
char level_name[LEVEL_MAX][LINE_MAX_LEN];
int line_dex[LINES_MAX];
int line_material[LINES_MAX];
int line_num;
int line_prune;
int list[COR3_MAX];
char material_binding[80];
char material_name[MATERIAL_MAX][LINE_MAX_LEN];
int material_num;
float material_rgba[4][MATERIAL_MAX];
char mat_name[81];
int max_order2;
char normal_binding[80];
float normal_temp[3][ORDER_MAX*FACE_MAX];
char object_name[81];
int object_num;
float origin[3];
float pivot[3];
float rgbcolor[3][COLOR_MAX];
char temp_name[81];
int text_num;
char texture_binding[80];
char texture_name[TEXTURE_MAX][LINE_MAX_LEN];
int texture_num;
float texture_temp[2][ORDER_MAX*FACE_MAX];
float transform_matrix[4][4];
int vertex_material[ORDER_MAX][FACE_MAX];
float vertex_normal[3][ORDER_MAX][FACE_MAX];
float vertex_rgb[3][ORDER_MAX][FACE_MAX];
float vertex_tex_uv[2][ORDER_MAX][FACE_MAX];
/******************************************************************************/
/* FUNCTION PROTOTYPES */
/******************************************************************************/
int main ( int argc, char **argv );
int ase_read ( FILE *filein );
int ase_write ( FILE *fileout );
int byu_read ( FILE *filein );
int byu_write ( FILE *fileout );
int char_index_last ( char* string, char c );
int char_pad ( int *char_index, int *null_index, char *string,
int STRING_MAX );
char char_read ( FILE *filein );
int char_write ( FILE *fileout, char c );
int command_line ( char **argv );
void cor3_normal_set ( void );
void cor3_range ( void );
void data_check ( void );
void data_init ( void );
int data_read ( void );
void data_report ( void );
int data_write ( void );
int dxf_read ( FILE *filein );
int dxf_write ( FILE *fileout );
void edge_null_delete ( void );
void face_area_set ( void );
void face_normal_ave ( void );
void face_null_delete ( void );
int face_print ( int iface );
void face_reverse_order ( void );
int face_subset ( void );
void face_to_line ( void );
void face_to_vertex_material ( void );
char *file_ext ( char *file_name );
float float_read ( FILE *filein );
float float_reverse_bytes ( float x );
int float_write ( FILE *fileout, float float_val );
int gmod_arch_check ( void );
int gmod_read ( FILE *filein );
float gmod_read_float ( FILE *filein );
unsigned short gmod_read_w16 ( FILE *filein );
unsigned long gmod_read_w32 ( FILE *filein );
int gmod_write ( FILE *fileout );
void gmod_write_float ( float Val, FILE *fileout );
void gmod_write_w16 ( unsigned short Val, FILE *fileout );
void gmod_write_w32 ( unsigned long Val, FILE *fileout );
void hello ( void );
void help ( void );
int hrc_read ( FILE *filein );
int hrc_write ( FILE *fileout );
void init_program_data ( void );
int interact ( void );
int iv_read ( FILE *filein );
int iv_write ( FILE *fileout );
int ivec_max ( int n, int *a );
int leqi ( char* string1, char* string2 );
long int long_int_read ( FILE *filein );
int long_int_write ( FILE *fileout, long int int_val );
void news ( void );
void node_to_vertex_material ( void );
int obj_read ( FILE *filein );
int obj_write ( FILE *fileout );
int pov_write ( FILE *fileout );
int rcol_find ( float a[][COR3_MAX], int m, int n, float r[] );
float rgb_to_hue ( float r, float g, float b );
short int short_int_read ( FILE *filein );
int short_int_write ( FILE *fileout, short int int_val );
int smf_read ( FILE *filein );
int smf_write ( FILE *fileout );
int stla_read ( FILE *filein );
int stla_write ( FILE *fileout );
int stlb_read ( FILE *filein );
int stlb_write ( FILE *fileout );
void tds_pre_process ( void );
int tds_read ( FILE *filein );
unsigned long int tds_read_ambient_section ( FILE *filein );
unsigned long int tds_read_background_section ( FILE *filein );
unsigned long int tds_read_boolean ( unsigned char *boolean, FILE *filein );
unsigned long int tds_read_camera_section ( FILE *filein );
unsigned long int tds_read_edit_section ( FILE *filein, int *views_read );
unsigned long int tds_read_keyframe_section ( FILE *filein, int *views_read );
unsigned long int tds_read_keyframe_objdes_section ( FILE *filein );
unsigned long int tds_read_light_section ( FILE *filein );
unsigned long int tds_read_u_long_int ( FILE *filein );
int tds_read_long_name ( FILE *filein );
unsigned long int tds_read_matdef_section ( FILE *filein );
unsigned long int tds_read_material_section ( FILE *filein );
int tds_read_name ( FILE *filein );
unsigned long int tds_read_obj_section ( FILE *filein );
unsigned long int tds_read_object_section ( FILE *filein );
unsigned long int tds_read_tex_verts_section ( FILE *filein );
unsigned long int tds_read_texmap_section ( FILE *filein );
unsigned short int tds_read_u_short_int ( FILE *filein );
unsigned long int tds_read_spot_section ( FILE *filein );
unsigned long int tds_read_unknown_section ( FILE *filein );
unsigned long int tds_read_view_section ( FILE *filein, int *views_read );
unsigned long int tds_read_vp_section ( FILE *filein, int *views_read );
int tds_write ( FILE *fileout );
int tds_write_string ( FILE *fileout, char *string );
int tds_write_u_short_int ( FILE *fileout,
unsigned short int int_val );
int tec_write ( FILE *fileout );
void tmat_init ( float a[4][4] );
void tmat_mxm ( float a[4][4], float b[4][4], float c[4][4] );
void tmat_mxp ( float a[4][4], float x[4], float y[4] );
void tmat_mxp2 ( float a[4][4], float x[][3], float y[][3], int n );
void tmat_mxv ( float a[4][4], float x[4], float y[4] );
void tmat_rot_axis ( float a[4][4], float b[4][4], float angle,
char axis );
void tmat_rot_vector ( float a[4][4], float b[4][4], float angle,
float v1, float v2, float v3 );
void tmat_scale ( float a[4][4], float b[4][4], float sx, float sy,
float sz );
void tmat_shear ( float a[4][4], float b[4][4], char *axis,
float s );
void tmat_trans ( float a[4][4], float b[4][4], float x, float y,
float z );
int tria_read ( FILE *filein );
int tria_write ( FILE *fileout );
int trib_read ( FILE *filein );
int trib_write ( FILE *fileout );
int txt_write ( FILE *fileout );
int ucd_write ( FILE *fileout );
void vertex_normal_set ( void );
void vertex_to_face_material ( void );
void vertex_to_node_material ( void );
int vla_read ( FILE *filein );
int vla_write ( FILE *fileout );
int wrl_write ( FILE *filout );
int xgl_write ( FILE *fileout );
/******************************************************************************/
int main ( int argc, char **argv )
/******************************************************************************/
/*
Purpose:
MAIN is the main program for converting graphics files.
Modified:
26 May 1999
Author:
John Burkardt
*/
{
int result;
/*
Initialize the program data.
*/
init_program_data ( );
/*
If there are at least two command line arguments, call COMMAND_LINE.
Otherwise call INTERACT and get information from the user.
*/
if ( argc >= 2 ) {
result = command_line ( argv );
}
else {
result = interact ( );
}
return result;
}
/******************************************************************************/
int ase_read ( FILE *filein )
/******************************************************************************/
/*
Purpose:
ASE_READ reads an AutoCAD ASE file.
Modified:
22 May 1999
Author:
John Burkardt
*/
{
float bval;
int count;
float gval;
int i;
int iface;
int ivert;
int iword;
int level;
char *next;
int nlbrack;
int nrbrack;
int cor3_num_old;
int face_num_old;
float rval;
float temp;
int width;
char word[LINE_MAX_LEN];
char word1[LINE_MAX_LEN];
char word2[LINE_MAX_LEN];
char wordm1[LINE_MAX_LEN];
float x;
float y;
float z;
level = 0;
strcpy ( level_name[0], "Top" );
cor3_num_old = cor3_num;
face_num_old = face_num;
nlbrack = 0;
nrbrack = 0;
strcpy ( word, " " );
strcpy ( wordm1, " " );
/*
Read a line of text from the file.
*/
for ( ;; ) {
if ( fgets ( input, LINE_MAX_LEN, filein ) == NULL ) {
break;
}
text_num = text_num + 1;
next = input;
iword = 0;
/*
Read the next word from the line.
*/
for ( ;; ) {
strcpy ( wordm1, word );
strcpy ( word, " " );
count = sscanf ( next, "%s%n", word, &width );
next = next + width;
if ( count <= 0 ) {
break;
}
iword = iword + 1;
if ( iword == 1 ) {
strcpy ( word1, word );
}
/*
In case the new word is a bracket, update the bracket count.
*/
if ( strcmp ( word, "{" ) == 0 ) {
nlbrack = nlbrack + 1;
level = nlbrack - nrbrack;
strcpy ( level_name[level], wordm1 );
}
else if ( strcmp ( word, "}" ) == 0 ) {
nrbrack = nrbrack + 1;
if ( nlbrack < nrbrack ) {
printf ( "\n" );
printf ( "ASE_READ - Fatal error!\n" );
printf ( " Extraneous right bracket on line %d\n", text_num );
printf ( " Currently processing field:\n" );
printf ( "%s\n", level_name[level] );
return ERROR;
}
}
/*
*3DSMAX_ASCIIEXPORT 200
*/
if ( strcmp ( word1, "*3DSMAX_ASCIIEXPORT" ) == 0 ) {
break;
}
/*
*COMMENT
*/
else if ( strcmp ( word1, "*COMMENT" ) == 0 ) {
break;
}
/*
*GEOMOBJECT
*/
else if ( strcmp ( level_name[level], "*GEOMOBJECT" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
/*
Why don't you read and save this name?
*/
else if ( strcmp ( word, "*NODE_NAME" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*NODE_TM" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*MESH" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*PROP_CASTSHADOW" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*PROP_MOTIONBLUR" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*PROP_RECVSHADOW" ) == 0 ) {
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in GEOMOBJECT, line %d\n", text_num );
break;
}
}
/*
*MESH
*/
else if ( strcmp ( level_name[level], "*MESH" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word, "*MESH_CFACELIST" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*MESH_CVERTLIST" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*MESH_FACE_LIST" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*MESH_NORMALS" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*MESH_NUMCVERTEX" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*MESH_NUMCVFACES" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*MESH_NUMFACES" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*MESH_NUMTVERTEX" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*MESH_NUMTVFACES" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*MESH_NUMVERTEX" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*MESH_TFACELIST" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*MESH_TVERTLIST" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*MESH_VERTEX_LIST" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "*TIMEVALUE" ) == 0 ) {
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in MESH, line %d\n", text_num );
break;
}
}
/*
*MESH_CFACELIST
*/
else if ( strcmp ( level_name[level], "*MESH_CFACELIST" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word, "*MESH_CFACE" ) == 0 ) {
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in MESH_CFACE, line %d\n", text_num );
break;
}
}
/*
*MESH_CVERTLIST
Mesh vertex indices must be incremented by COR3_NUM_OLD before being stored
in the internal array.
*/
else if ( strcmp ( level_name[level], "*MESH_CVERTLIST" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word, "*MESH_VERTCOL" ) == 0 ) {
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
i = i + cor3_num_old;
count = sscanf ( next, "%f%n", &rval, &width );
next = next + width;
count = sscanf ( next, "%f%n", &gval, &width );
next = next + width;
count = sscanf ( next, "%f%n", &bval, &width );
next = next + width;
if ( material_num < MATERIAL_MAX ) {
material_rgba[0][material_num] = rval;
material_rgba[1][material_num] = gval;
material_rgba[2][material_num] = bval;
material_rgba[3][material_num] = 1.0;
}
material_num = material_num + 1;
cor3_material[i] = material_num;
}
else {
bad_num = bad_num + 1;
printf ( "\n" );
printf ( "ASE_READ - Warning!\n" );
printf ( " Bad data in MESH_CVERTLIST, line %d\n", text_num );
break;
}
}
/*
*MESH_FACE_LIST
This coding assumes a face is always triangular or quadrilateral.
*/
else if ( strcmp ( level_name[level], "*MESH_FACE_LIST" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word, "*MESH_FACE" ) == 0 ) {
if ( face_num < FACE_MAX ) {
face_material[face_num] = 0;
face_order[face_num] = 0;
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
count = sscanf ( next, "%s%n", word2, &width );
next = next + width;
count = sscanf ( next, "%s%n", word2, &width );
next = next + width;
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
face[0][face_num] = i + cor3_num_old;
face_order[face_num] = face_order[face_num] + 1;
count = sscanf ( next, "%s%n", word2, &width );
next = next + width;
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
face[1][face_num] = i + cor3_num_old;
face_order[face_num] = face_order[face_num] + 1;
count = sscanf ( next, "%s%n", word2, &width );
next = next + width;
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
face[2][face_num] = i + cor3_num_old;
face_order[face_num] = face_order[face_num] + 1;
count = sscanf ( next, "%s%n", word2, &width );
next = next + width;
if ( strcmp ( word2, "D:" ) == 0 ) {
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
face[3][face_num] = i + cor3_num_old;
face_order[face_num] = face_order[face_num] + 1;
}
}
face_num = face_num + 1;
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in MESH_FACE_LIST, line %d\n", text_num );
break;
}
}
/*
*MESH_NORMALS
*/
else if ( strcmp ( level_name[level], "*MESH_NORMALS" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word, "*MESH_FACENORMAL" ) == 0 ) {
count = sscanf ( next, "%d%n", &iface, &width );
next = next + width;
count = sscanf ( next, "%f%n", &x, &width );
next = next + width;
count = sscanf ( next, "%f%n", &y, &width );
next = next + width;
count = sscanf ( next, "%f%n", &z, &width );
next = next + width;
iface = iface + face_num_old;
ivert = 0;
face_normal[0][iface] = x;
face_normal[1][iface] = y;
face_normal[2][iface] = z;
break;
}
else if ( strcmp ( word, "*MESH_VERTEXNORMAL" ) == 0 ) {
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
count = sscanf ( next, "%f%n", &x, &width );
next = next + width;
count = sscanf ( next, "%f%n", &y, &width );
next = next + width;
count = sscanf ( next, "%f%n", &z, &width );
next = next + width;
vertex_normal[0][ivert][iface] = x;
vertex_normal[1][ivert][iface] = y;
vertex_normal[2][ivert][iface] = z;
ivert = ivert + 1;
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in MESH_NORMALS, line %d\n", text_num );
break;
}
}
/*
*MESH_TFACELIST
*/
else if ( strcmp ( level_name[level], "*MESH_TFACELIST" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word1, "*MESH_TFACE" ) == 0 ) {
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in MESH_TFACE_LIST, line %d\n", text_num );
break;
}
}
/*
*MESH_TVERTLIST
*/
else if ( strcmp ( level_name[level], "*MESH_TVERTLIST" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word1, "*MESH_TVERT" ) == 0 ) {
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in MESH_TVERTLIST, line %d\n", text_num );
break;
}
}
/*
*MESH_VERTEX_LIST
*/
else if ( strcmp ( level_name[level], "*MESH_VERTEX_LIST" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
cor3_num_old = cor3_num;
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word1, "*MESH_VERTEX" ) == 0 ) {
count = sscanf ( next, "%d%n", &i, &width );
next = next + width;
count = sscanf ( next, "%f%n", &x, &width );
next = next + width;
count = sscanf ( next, "%f%n", &y, &width );
next = next + width;
count = sscanf ( next, "%f%n", &z, &width );
next = next + width;
i = i + cor3_num_old;
if ( cor3_num < i + 1 ) {
cor3_num = i + 1;
}
if ( i < COR3_MAX ) {
cor3[0][i] =
transform_matrix[0][0] * x
+ transform_matrix[0][1] * y
+ transform_matrix[0][2] * z
+ transform_matrix[0][3];
cor3[1][i] =
transform_matrix[1][0] * x
+ transform_matrix[1][1] * y
+ transform_matrix[1][2] * z
+ transform_matrix[1][3];
cor3[2][i] =
transform_matrix[2][0] * x
+ transform_matrix[2][1] * y
+ transform_matrix[2][2] * z
+ transform_matrix[2][3];
}
break;
}
else {
bad_num = bad_num + 1;
printf ( "Bad data in MESH_VERTEX_LIST, line %d\n", text_num );
break;
}
}
/*
*NODE_TM
Each node should start out with a default transformation matrix.
*/
else if ( strcmp ( level_name[level], "*NODE_TM" ) == 0 ) {
if ( strcmp ( word, "{" ) == 0 ) {
tmat_init ( transform_matrix );
continue;
}
else if ( strcmp ( word, "}" ) == 0 ) {
level = nlbrack - nrbrack;
continue;
}
else if ( strcmp ( word, "*INHERIT_POS" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*INHERIT_ROT" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*INHERIT_SCL" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*NODE_NAME" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*TM_POS" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*TM_ROTANGLE" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*TM_ROTAXIS" ) == 0 ) {
break;
}
else if ( strcmp ( word, "*TM_ROW0" ) == 0 ) {
count = sscanf ( next, "%f%n", &temp, &width );
next = next + width;
transform_matrix[0][0] = temp;
count = sscanf ( next, "%f%n", &temp, &width );
next = next + width;
transform_matrix[1][0] = temp;
count = sscanf ( next, "%f%n", &temp, &width );
next = next + width;
transform_matrix[2][0] = temp;
break;
}
else if ( strcmp ( word, "*TM_ROW1" ) == 0 ) {
count = sscanf ( next, "%f%n", &temp, &width );
next = next + width;
transform_matrix[0][1] = temp;
count = sscanf ( next, "%f%n", &temp, &width );
next = next + width;
transform_matrix[1][1] = temp;
count = sscanf ( next, "%f%n", &temp, &width );
next = next + width;
transform_matrix[2][1] = temp;
break;
}
else if ( strcmp ( word, "*TM_ROW2" ) == 0 ) {
count = sscanf ( next, "%f%n", &temp, &width );