1 /* $Id: polyobj.c,v 1.10 2003-01-03 00:56:33 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
20 static char rcsid[] = "$Id: polyobj.c,v 1.10 2003-01-03 00:56:33 btb Exp $";
27 // -- I hate this warning in make depend! -- #ifdef DRIVE
28 // -- I hate this warning in make depend! -- #include "drive.h"
29 // -- I hate this warning in make depend! -- #else
31 // -- I hate this warning in make depend! -- #endif
59 polymodel Polygon_models[MAX_POLYGON_MODELS]; // = {&bot11,&bot17,&robot_s2,&robot_b2,&bot11,&bot17,&robot_s2,&robot_b2};
61 int N_polygon_models = 0;
63 #define MAX_POLYGON_VECS 1000
64 g3s_point robot_points[MAX_POLYGON_VECS];
66 #define PM_COMPATIBLE_VERSION 6
67 #define PM_OBJFILE_VERSION 8
72 #define MODEL_BUF_SIZE 32768
74 #ifdef WORDS_BIGENDIAN
75 void short_swap(short *s)
82 *f = (fix)SWAPINT((int)*f);
85 void fixang_swap(fixang *f)
87 *f = (fixang)SWAPSHORT((short)*f);
90 void vms_vector_swap(vms_vector *v)
97 void vms_angvec_swap(vms_angvec *v)
105 void _pof_cfseek(int len,int type)
108 case SEEK_SET: Pof_addr = len; break;
109 case SEEK_CUR: Pof_addr += len; break;
111 Assert(len <= 0); // seeking from end, better be moving back.
112 Pof_addr = Pof_file_end + len;
116 if (Pof_addr > MODEL_BUF_SIZE)
120 #define pof_cfseek(_buf,_len,_type) _pof_cfseek((_len),(_type))
122 int pof_read_int(ubyte *bufp)
126 i = *((int *) &bufp[Pof_addr]);
130 // if (cfread(&i,sizeof(i),1,f) != 1)
131 // Error("Unexpected end-of-file while reading object");
136 size_t pof_cfread(void *dst, size_t elsize, size_t nelem, ubyte *bufp)
138 if (Pof_addr + nelem*elsize > Pof_file_end)
141 memcpy(dst, &bufp[Pof_addr], elsize*nelem);
143 Pof_addr += elsize*nelem;
145 if (Pof_addr > MODEL_BUF_SIZE)
151 // #define new_read_int(i,f) cfread(&(i),sizeof(i),1,(f))
152 #define new_pof_read_int(i,f) pof_cfread(&(i),sizeof(i),1,(f))
154 short pof_read_short(ubyte *bufp)
158 s = *((short *) &bufp[Pof_addr]);
160 return INTEL_SHORT(s);
161 // if (cfread(&s,sizeof(s),1,f) != 1)
162 // Error("Unexpected end-of-file while reading object");
167 void pof_read_string(char *buf,int max_char, ubyte *bufp)
171 for (i=0; i<max_char; i++) {
172 if ((*buf++ = bufp[Pof_addr++]) == 0)
176 // while (max_char-- && (*buf=cfgetc(f)) != 0) buf++;
180 void pof_read_vecs(vms_vector *vecs,int n,ubyte *bufp)
182 // cfread(vecs,sizeof(vms_vector),n,f);
184 memcpy(vecs, &bufp[Pof_addr], n*sizeof(*vecs));
185 Pof_addr += n*sizeof(*vecs);
187 #ifdef WORDS_BIGENDIAN
189 vms_vector_swap(&vecs[--n]);
192 if (Pof_addr > MODEL_BUF_SIZE)
196 void pof_read_angs(vms_angvec *angs,int n,ubyte *bufp)
198 memcpy(angs, &bufp[Pof_addr], n*sizeof(*angs));
199 Pof_addr += n*sizeof(*angs);
201 #ifdef WORDS_BIGENDIAN
203 vms_angvec_swap(&angs[--n]);
206 if (Pof_addr > MODEL_BUF_SIZE)
210 #define ID_OHDR 0x5244484f // 'RDHO' //Object header
211 #define ID_SOBJ 0x4a424f53 // 'JBOS' //Subobject header
212 #define ID_GUNS 0x534e5547 // 'SNUG' //List of guns on this object
213 #define ID_ANIM 0x4d494e41 // 'MINA' //Animation data
214 #define ID_IDTA 0x41544449 // 'ATDI' //Interpreter data
215 #define ID_TXTR 0x52545854 // 'RTXT' //Texture filename list
218 #define robot_info void
220 vms_angvec anim_angs[N_ANIM_STATES][MAX_SUBMODELS];
222 //set the animation angles for this robot. Gun fields of robot info must
224 void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES][MAX_SUBMODELS]);
227 #define DEBUG_LEVEL CON_NORMAL
229 //reads a binary file containing a 3d model
230 polymodel *read_model_file(polymodel *pm,char *filename,robot_info *r)
234 int id,len, next_chunk;
238 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
240 Error("Can't allocate space to read model %s\n", filename);
242 if ((ifile=cfopen(filename,"rb"))==NULL)
243 Error("Can't open file <%s>",filename);
245 Assert(ifile->size <= MODEL_BUF_SIZE);
248 Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
251 id = pof_read_int(model_buf);
253 if (id!=0x4f505350) /* 'OPSP' */
254 Error("Bad ID in model file <%s>",filename);
256 version = pof_read_short(model_buf);
258 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
259 Error("Bad version (%d) in model file <%s>",version,filename);
261 if ( FindArg( "-bspgen" ))
262 printf( "bspgen -c1" );
264 while (new_pof_read_int(id,model_buf) == 1) {
266 //id = pof_read_int(model_buf);
267 len = pof_read_int(model_buf);
268 next_chunk = Pof_addr + len;
272 case ID_OHDR: { //Object header
273 vms_vector pmmin,pmmax;
275 //con_printf(DEBUG_LEVEL, "Got chunk OHDR, len=%d\n",len);
277 pm->n_models = pof_read_int(model_buf);
278 pm->rad = pof_read_int(model_buf);
280 Assert(pm->n_models <= MAX_SUBMODELS);
282 pof_read_vecs(&pmmin,1,model_buf);
283 pof_read_vecs(&pmmax,1,model_buf);
285 if ( FindArg( "-bspgen" )) {
289 vm_vec_sub(&v, &pmmax, &pmmin );
291 if ( v.y > l ) l = v.y;
292 if ( v.z > l ) l = v.z;
294 printf( " -l%.3f", f2fl(l) );
300 case ID_SOBJ: { //Subobject header
305 //con_printf(DEBUG_LEVEL, "Got chunk SOBJ, len=%d\n",len);
307 n = pof_read_short(model_buf);
309 Assert(n < MAX_SUBMODELS);
311 pm->submodel_parents[n] = pof_read_short(model_buf);
313 pof_read_vecs(&pm->submodel_norms[n],1,model_buf);
314 pof_read_vecs(&pm->submodel_pnts[n],1,model_buf);
315 pof_read_vecs(&pm->submodel_offsets[n],1,model_buf);
317 pm->submodel_rads[n] = pof_read_int(model_buf); //radius
319 pm->submodel_ptrs[n] = pof_read_int(model_buf); //offset
326 case ID_GUNS: { //List of guns on this object
328 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
333 ubyte gun_used[MAX_GUNS];
335 r->n_guns = pof_read_int(model_buf);
340 Assert(r->n_guns <= MAX_GUNS);
342 for (i=0;i<r->n_guns;i++)
345 for (i=0;i<r->n_guns;i++) {
348 id = pof_read_short(model_buf);
349 Assert(id < r->n_guns);
350 Assert(gun_used[id] == 0);
352 r->gun_submodels[id] = pof_read_short(model_buf);
353 Assert(r->gun_submodels[id] != 0xff);
354 pof_read_vecs(&r->gun_points[id],1,model_buf);
357 pof_read_vecs(&gun_dir,1,model_buf);
361 pof_cfseek(model_buf,len,SEEK_CUR);
366 case ID_ANIM: //Animation data
367 //con_printf(DEBUG_LEVEL, "Got chunk ANIM, len=%d\n",len);
374 n_frames = pof_read_short(model_buf);
376 Assert(n_frames == N_ANIM_STATES);
378 for (m=0;m<pm->n_models;m++)
379 for (f=0;f<n_frames;f++)
380 pof_read_angs(&anim_angs[f][m], 1, model_buf);
383 robot_set_angles(r,pm,anim_angs);
387 pof_cfseek(model_buf,len,SEEK_CUR);
392 case ID_TXTR: { //Texture filename list
396 //con_printf(DEBUG_LEVEL, "Got chunk TXTR, len=%d\n",len);
398 n = pof_read_short(model_buf);
399 //con_printf(DEBUG_LEVEL, " num textures = %d\n",n);
401 pof_read_string(name_buf,128,model_buf);
402 //con_printf(DEBUG_LEVEL, "<%s>\n",name_buf);
408 case ID_IDTA: //Interpreter data
409 //con_printf(DEBUG_LEVEL, "Got chunk IDTA, len=%d\n",len);
411 pm->model_data = d_malloc(len);
412 pm->model_data_size = len;
414 pof_cfread(pm->model_data,1,len,model_buf);
419 //con_printf(DEBUG_LEVEL, "Unknown chunk <%c%c%c%c>, len = %d\n",id,id>>8,id>>16,id>>24,len);
420 pof_cfseek(model_buf,len,SEEK_CUR);
424 if ( version >= 8 ) // Version 8 needs 4-byte alignment!!!
425 pof_cfseek(model_buf,next_chunk,SEEK_SET);
428 // for (i=0;i<pm->n_models;i++)
429 // pm->submodel_ptrs[i] += (int) pm->model_data;
431 if ( FindArg( "-bspgen" )) {
432 char *p = strchr( filename, '.' );
438 printf( " %s.3ds\n", filename );
444 #ifdef WORDS_NEED_ALIGNMENT
445 align_polygon_model_data(pm);
447 #ifdef WORDS_BIGENDIAN
448 swap_polygon_model_data(pm->model_data);
450 //verify(pm->model_data);
455 //reads the gun information for a model
456 //fills in arrays gun_points & gun_dirs, returns the number of guns read
457 int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs, int *gun_submodels)
465 model_buf = (ubyte *)d_malloc( MODEL_BUF_SIZE * sizeof(ubyte) );
467 Error("Can't allocate space to read model %s\n", filename);
469 if ((ifile=cfopen(filename,"rb"))==NULL)
470 Error("Can't open file <%s>",filename);
472 Assert(ifile->size <= MODEL_BUF_SIZE);
475 Pof_file_end = cfread(model_buf, 1, ifile->size, ifile);
478 id = pof_read_int(model_buf);
480 if (id!=0x4f505350) /* 'OPSP' */
481 Error("Bad ID in model file <%s>",filename);
483 version = pof_read_short(model_buf);
485 Assert(version >= 7); //must be 7 or higher for this data
487 if (version < PM_COMPATIBLE_VERSION || version > PM_OBJFILE_VERSION)
488 Error("Bad version (%d) in model file <%s>",version,filename);
490 while (new_pof_read_int(id,model_buf) == 1) {
492 //id = pof_read_int(model_buf);
493 len = pof_read_int(model_buf);
495 if (id == ID_GUNS) { //List of guns on this object
497 //con_printf(DEBUG_LEVEL, "Got chunk GUNS, len=%d\n",len);
501 n_guns = pof_read_int(model_buf);
503 for (i=0;i<n_guns;i++) {
506 id = pof_read_short(model_buf);
507 sm = pof_read_short(model_buf);
509 gun_submodels[id] = sm;
511 Error("Invalid gun submodel in file <%s>",filename);
512 pof_read_vecs(&gun_points[id],1,model_buf);
514 pof_read_vecs(&gun_dirs[id],1,model_buf);
519 pof_cfseek(model_buf,len,SEEK_CUR);
528 //free up a model, getting rid of all its memory
529 void free_model(polymodel *po)
531 d_free(po->model_data);
534 grs_bitmap *texture_list[MAX_POLYOBJ_TEXTURES];
535 bitmap_index texture_list_index[MAX_POLYOBJ_TEXTURES];
537 int Simple_model_threshhold_scale=5; //switch when this times radius far away
540 //draw a polygon model
542 void draw_polygon_model(vms_vector *pos,vms_matrix *orient,vms_angvec *anim_angles,int model_num,int flags,fix light,fix *glow_values,bitmap_index alt_textures[])
546 PA_DFX (int save_light);
548 Assert(model_num < N_polygon_models);
550 po=&Polygon_models[model_num];
552 //check if should use simple model
553 if (po->simpler_model ) //must have a simpler model
554 if (flags==0) //can't switch if this is debris
555 //!!if (!alt_textures) { //alternate textures might not match
556 //alt textures might not match, but in the one case we're using this
557 //for on 11/14/94, they do match. So we leave it in.
562 depth = g3_calc_point_depth(pos); //gets 3d depth
564 while (po->simpler_model && depth > cnt++ * Simple_model_threshhold_scale * po->rad)
565 po = &Polygon_models[po->simpler_model-1];
570 for (i=0;i<po->n_textures;i++) {
571 texture_list_index[i] = alt_textures[i];
572 texture_list[i] = &GameBitmaps[alt_textures[i].index];
575 texture_list[i]->bm_handle = texture_list_index[i].index;
581 for (i=0;i<po->n_textures;i++) {
582 texture_list_index[i] = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
583 texture_list[i] = &GameBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index];
586 texture_list[i]->bm_handle = texture_list_index[i].index;
591 #ifdef PIGGY_USE_PAGING
592 // Make sure the textures for this object are paged in...
593 piggy_page_flushed = 0;
594 for (i=0;i<po->n_textures;i++)
595 PIGGY_PAGE_IN( texture_list_index[i] );
596 // Hmmm... cache got flushed in the middle of paging all these in,
597 // so we need to reread them all in.
598 if (piggy_page_flushed) {
599 piggy_page_flushed = 0;
600 for (i=0;i<po->n_textures;i++)
601 PIGGY_PAGE_IN( texture_list_index[i] );
603 // Make sure that they can all fit in memory.
604 Assert( piggy_page_flushed == 0 );
607 g3_start_instance_matrix(pos,orient);
609 g3_set_interp_points(robot_points);
612 _3dfx_rendering_poly_obj = 1;
614 PA_DFX(save_light = Lighting_on);
615 PA_DFX(Lighting_on = 0);
617 if (flags == 0) //draw entire object
619 g3_draw_polygon_model(po->model_data,texture_list,anim_angles,light,glow_values);
624 for (i=0;flags;flags>>=1,i++)
628 Assert(i < po->n_models);
630 //if submodel, rotate around its center point, not pivot point
632 vm_vec_avg(&ofs,&po->submodel_mins[i],&po->submodel_maxs[i]);
634 g3_start_instance_matrix(&ofs,NULL);
636 g3_draw_polygon_model(&po->model_data[po->submodel_ptrs[i]],texture_list,anim_angles,light,glow_values);
645 _3dfx_rendering_poly_obj = 0;
648 PA_DFX (Lighting_on = save_light);
653 void free_polygon_models()
657 for (i=0;i<N_polygon_models;i++) {
658 free_model(&Polygon_models[i]);
663 void polyobj_find_min_max(polymodel *pm)
669 vms_vector *big_mn,*big_mx;
674 for (m=0;m<pm->n_models;m++) {
675 vms_vector *mn,*mx,*ofs;
677 mn = &pm->submodel_mins[m];
678 mx = &pm->submodel_maxs[m];
679 ofs= &pm->submodel_offsets[m];
681 data = (ushort *)&pm->model_data[pm->submodel_ptrs[m]];
685 Assert(type == 7 || type == 1);
690 data+=2; //skip start & pad
692 vp = (vms_vector *) data;
694 *mn = *mx = *vp++; nverts--;
697 *big_mn = *big_mx = *mn;
700 if (vp->x > mx->x) mx->x = vp->x;
701 if (vp->y > mx->y) mx->y = vp->y;
702 if (vp->z > mx->z) mx->z = vp->z;
704 if (vp->x < mn->x) mn->x = vp->x;
705 if (vp->y < mn->y) mn->y = vp->y;
706 if (vp->z < mn->z) mn->z = vp->z;
708 if (vp->x+ofs->x > big_mx->x) big_mx->x = vp->x+ofs->x;
709 if (vp->y+ofs->y > big_mx->y) big_mx->y = vp->y+ofs->y;
710 if (vp->z+ofs->z > big_mx->z) big_mx->z = vp->z+ofs->z;
712 if (vp->x+ofs->x < big_mn->x) big_mn->x = vp->x+ofs->x;
713 if (vp->y+ofs->y < big_mn->y) big_mn->y = vp->y+ofs->y;
714 if (vp->z+ofs->z < big_mn->z) big_mn->z = vp->z+ofs->z;
719 // printf("Submodel %d: (%8x,%8x) (%8x,%8x) (%8x,%8x)\n",m,mn->x,mx->x,mn->y,mx->y,mn->z,mx->z);
722 // printf("Whole model: (%8x,%8x) (%8x,%8x) (%8x,%8x)\n",big_mn->x,big_mx->x,big_mn->y,big_mx->y,big_mn->z,big_mx->z);
726 extern short highest_texture_num; //from the 3d
728 char Pof_names[MAX_POLYGON_MODELS][FILENAME_LEN];
730 //returns the number of this model
732 int load_polygon_model(char *filename,int n_textures,int first_texture,robot_info *r)
734 int load_polygon_model(char *filename,int n_textures,grs_bitmap ***textures)
741 Assert(N_polygon_models < MAX_POLYGON_MODELS);
742 Assert(n_textures < MAX_POLYOBJ_TEXTURES);
744 // MK was real tired of those useless, slow mprintfs...
745 if (N_polygon_models > MAX_POLYGON_MODELS - 10)
746 mprintf(( 0, "Used %d/%d polygon model slots\n", N_polygon_models+1, MAX_POLYGON_MODELS ));
748 Assert(strlen(filename) <= 12);
749 strcpy(Pof_names[N_polygon_models],filename);
751 read_model_file(&Polygon_models[N_polygon_models],filename,r);
753 polyobj_find_min_max(&Polygon_models[N_polygon_models]);
755 g3_init_polygon_model(Polygon_models[N_polygon_models].model_data);
757 if (highest_texture_num+1 != n_textures)
758 Error("Model <%s> references %d textures but specifies %d.",filename,highest_texture_num+1,n_textures);
760 Polygon_models[N_polygon_models].n_textures = n_textures;
761 Polygon_models[N_polygon_models].first_texture = first_texture;
762 Polygon_models[N_polygon_models].simpler_model = 0;
764 // Assert(polygon_models[N_polygon_models]!=NULL);
768 return N_polygon_models-1;
773 void init_polygon_models()
775 N_polygon_models = 0;
777 atexit((void (*)())free_polygon_models);
781 //compare against this size when figuring how far to place eye for picture
782 #define BASE_MODEL_SIZE 0x28000
784 #define DEFAULT_VIEW_DIST 0x60000
786 //draws the given model in the current canvas. The distance is set to
787 //more-or-less fill the canvas. Note that this routine actually renders
788 //into an off-screen canvas that it creates, then copies to the current
790 void draw_model_picture(int mn,vms_angvec *orient_angles)
792 vms_vector temp_pos=ZERO_VECTOR;
793 vms_matrix temp_orient = IDENTITY_MATRIX;
794 grs_canvas *save_canv = grd_curcanv,*temp_canv;
796 Assert(mn>=0 && mn<N_polygon_models);
798 temp_canv = gr_create_canvas(save_canv->cv_bitmap.bm_w,save_canv->cv_bitmap.bm_h);
799 gr_set_current_canvas(temp_canv);
800 gr_clear_canvas( BM_XRGB(0,0,0) );
803 g3_set_view_matrix(&temp_pos,&temp_orient,0x9000);
805 if (Polygon_models[mn].rad != 0)
806 temp_pos.z = fixmuldiv(DEFAULT_VIEW_DIST,Polygon_models[mn].rad,BASE_MODEL_SIZE);
808 temp_pos.z = DEFAULT_VIEW_DIST;
810 vm_angles_2_matrix(&temp_orient, orient_angles);
812 PA_DFX(save_light = Lighting_on);
813 PA_DFX(Lighting_on = 0);
814 draw_polygon_model(&temp_pos,&temp_orient,NULL,mn,0,f1_0,NULL,NULL);
815 PA_DFX (Lighting_on = save_light);
817 gr_set_current_canvas(save_canv);
819 gr_bitmap(0,0,&temp_canv->cv_bitmap);
821 gr_free_canvas(temp_canv);
826 * reads a polymodel structure from a CFILE
828 extern void polymodel_read(polymodel *pm, CFILE *fp)
832 pm->n_models = cfile_read_int(fp);
833 pm->model_data_size = cfile_read_int(fp);
834 pm->model_data = (ubyte *) cfile_read_int(fp);
835 for (i = 0; i < MAX_SUBMODELS; i++)
836 pm->submodel_ptrs[i] = cfile_read_int(fp);
837 for (i = 0; i < MAX_SUBMODELS; i++)
838 cfile_read_vector(&(pm->submodel_offsets[i]), fp);
839 for (i = 0; i < MAX_SUBMODELS; i++)
840 cfile_read_vector(&(pm->submodel_norms[i]), fp);
841 for (i = 0; i < MAX_SUBMODELS; i++)
842 cfile_read_vector(&(pm->submodel_pnts[i]), fp);
843 for (i = 0; i < MAX_SUBMODELS; i++)
844 pm->submodel_rads[i] = cfile_read_fix(fp);
845 cfread(pm->submodel_parents, MAX_SUBMODELS, 1, fp);
846 for (i = 0; i < MAX_SUBMODELS; i++)
847 cfile_read_vector(&(pm->submodel_mins[i]), fp);
848 for (i = 0; i < MAX_SUBMODELS; i++)
849 cfile_read_vector(&(pm->submodel_maxs[i]), fp);
850 cfile_read_vector(&(pm->mins), fp);
851 cfile_read_vector(&(pm->maxs), fp);
852 pm->rad = cfile_read_fix(fp);
853 pm->n_textures = cfile_read_byte(fp);
854 pm->first_texture = cfile_read_short(fp);
855 pm->simpler_model = cfile_read_byte(fp);
859 * reads n polymodel structs from a CFILE
861 extern int polymodel_read_n(polymodel *pm, int n, CFILE *fp)
865 for (i = 0; i < n; i++) {
866 pm[i].n_models = cfile_read_int(fp);
867 pm[i].model_data_size = cfile_read_int(fp);
868 pm[i].model_data = (ubyte *) cfile_read_int(fp);
869 for (j = 0; j < MAX_SUBMODELS; j++)
870 pm[i].submodel_ptrs[j] = cfile_read_int(fp);
871 for (j = 0; j < MAX_SUBMODELS; j++)
872 cfile_read_vector(&(pm[i].submodel_offsets[j]), fp);
873 for (j = 0; j < MAX_SUBMODELS; j++)
874 cfile_read_vector(&(pm[i].submodel_norms[j]), fp);
875 for (j = 0; j < MAX_SUBMODELS; j++)
876 cfile_read_vector(&(pm[i].submodel_pnts[j]), fp);
877 for (j = 0; j < MAX_SUBMODELS; j++)
878 pm[i].submodel_rads[j] = cfile_read_fix(fp);
879 cfread(pm[i].submodel_parents, MAX_SUBMODELS, 1, fp);
880 for (j = 0; j < MAX_SUBMODELS; j++)
881 cfile_read_vector(&(pm[i].submodel_mins[j]), fp);
882 for (j = 0; j < MAX_SUBMODELS; j++)
883 cfile_read_vector(&(pm[i].submodel_maxs[j]), fp);
884 cfile_read_vector(&(pm[i].mins), fp);
885 cfile_read_vector(&(pm[i].maxs), fp);
886 pm[i].rad = cfile_read_fix(fp);
887 pm[i].n_textures = cfile_read_byte(fp);
888 pm[i].first_texture = cfile_read_short(fp);
889 pm[i].simpler_model = cfile_read_byte(fp);
897 * routine which allocates, reads, and inits a polymodel's model_data
899 void polygon_model_data_read(polymodel *pm, CFILE *fp)
901 pm->model_data = d_malloc(pm->model_data_size);
902 Assert(pm->model_data != NULL);
903 cfread(pm->model_data, sizeof(ubyte), pm->model_data_size, fp );
904 #ifdef WORDS_NEED_ALIGNMENT
905 align_polygon_model_data(pm);
907 #ifdef WORDS_BIGENDIAN
908 swap_polygon_model_data(pm->model_data);
910 //verify(pm->model_data);
911 g3_init_polygon_model(pm->model_data);