Archived

This topic is now archived and is closed to further replies.

obj file problem

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

/*reposted from the general programming forum*/ I''m having some problems with my obj loader heres the source
      
extern int loadmodel(int texindex,model* obj,char* str){
	int vers,texs,nors,poly,index,index2,vertex_index=0,texture_index=0,normal_index=0,poly_index;
	float *pver,*ptex,*pnor;
	int *ppoly;
	char str2[100],str3[100],str_a[100],str_b[100],str_c[100];
	FILE *file;
	
	if((file=fopen(str,"r"))==NULL){
		return(2);
	}
	
	
	while(!feof(file)){
		fgets(str2,100,file);
		if(str2[0]==''v'' && str2[1]=='' ''){
			vers++;
		}
		if(str2[0]==''v'' && str2[1]==''t''){
			texs++;
		}
		if(str2[0]==''v'' && str2[1]==''n''){
			nors++;
		}
		if(str2[0]==''f'' && str2[1]=='' ''){
			poly++;
		}
	
	}

	pver=(float *)malloc(sizeof(float)*vers*3);
	if(pver==NULL){
		return(3);
	}
	
	ptex=(float *)malloc(sizeof(float)*texs*2);
	if(ptex==NULL){
		return(4);
	}
	
	pnor=(float *)malloc(sizeof(float)*nors*3);
	if(pnor==NULL){
		return(5);
	}
	
	ppoly=(int *)malloc(sizeof(int)*poly*9);
	if(ppoly==NULL){
		return(6);
	}

	rewind(file);

	
	
	while(!feof(file)){
		
		fgets(str2,100,file);
		
		if(str2[0]==''v'' && str2[1]=='' ''){//load vertecies

			index=2;
			index2=0;
			
			while(str2[index]!='' ''){
				str_a[index2]=str2[index];
				index++;
				index2++;
			}
			index++;
			
			while(str2[index]!='' ''){
				str_b[index2]=str2[index];
				index++;
				index2++;
			}
			index++;
			
			while(str2[index]!=0){
				str_c[index2]=str2[index];
				index++;
				index2++;
			}
			
			*(pver+vertex_index)=(float)atof(str_a);
			*(pver+vertex_index+1)=(float)atof(str_b);
			*(pver+vertex_index+2)=(float)atof(str_c);
			vertex_index+=3;
		}
		
		if(str2[0]==''v'' && str2[1]==''t''){//load texture cords

			index=2;
			index2=0;
			
			while(str2[index]!='' ''){
				str_a[index2]=str2[index];
				index++;
				index2++;
			}
			index++;
			
			while(str2[index]!=0){
				str_b[index2]=str2[index];
				index++;
				index2++;
			}
						
			*(pver+texture_index)=(float)atof(str_a);
			*(pver+texture_index+1)=(float)atof(str_b);
			vertex_index+=2;				
		}
		
		if(str2[0]==''v'' && str2[1]==''n''){//load normals

			index=2;
			index2=0;
			
			while(str2[index]!='' ''){
				str_a[index2]=str2[index];
				index++;
				index2++;
			}
			index++;
			
			while(str2[index]!='' ''){
				str_b[index2]=str2[index];
				index++;
				index2++;
			}
			index++;
			
			while(str2[index]!=0){
				str_c[index2]=str2[index];
				index++;
				index2++;
			}
			
			*(pnor+normal_index)=(float)atof(str_a);
			*(pnor+normal_index+1)=(float)atof(str_b);
			*(pnor+normal_index+2)=(float)atof(str_c);
			vertex_index+=3;				
		}
		
		if(str2[0]==''f'' && str2[1]=='' ''){//load polys

			index=2;
			index2=0;
			for(int x2=0;x2<9;x2++){
				while(isdigit(str2[index])){
					str3[index2]=str2[index];
					index++;
					index2++;
				}//end while

				index++;
				*(ppoly+poly_index++)=atoi(str3);
					
				index2=0;
			}//end for


			
		}//end if

	
	}//end while !feof


	fclose(file);
	
	obj->tex=texindex;
	obj->nump=poly;
	obj->vers=pver;
	obj->texcords=ptex;
	obj->normals=pnor;
	obj->polys=ppoly;
		
	return(0);
}
      
It dies on the dynamic allocation although I dont know if thats the only problem

Share this post


Link to post
Share on other sites
...But now my display function doesn''t work

  
extern int displaymodel(float x,float y,float z,model* obj){
glColor3f(1,0,0);
for(int x2=0;x2<obj->nump*9;){
glBegin(GL_TRIANGLES);
glVertex3f(obj->vers[obj->polys[x2]]+x,obj->vers[obj->polys[x2]+1]+y,obj->vers[obj->polys[x2]+2]+z);
x2+=3;
glVertex3f(obj->vers[obj->polys[x2]]+x,obj->vers[obj->polys[x2]+1]+y,obj->vers[obj->polys[x2]+2]+z);
x2+=3;
glVertex3f(obj->vers[obj->polys[x2]]+x,obj->vers[obj->polys[x2]+1]+y,obj->vers[obj->polys[x2]+2]+z);
x2+=3;
glEnd();

}


return(1);
}

it displays nothing but wierd triangle. I think my indecies are wrong, but I can''t figure out how to fix them

Share this post


Link to post
Share on other sites
Well, one large problem would be that you''re assuming that there''s only triangles in the file. I''ve got OBJ files out of Poser 4 with some polys of over 50 vertices. Try looking into the tesselation functions in OpenGL.

Share this post


Link to post
Share on other sites
nope I''m using milkshape all models are triangulated(sp)

  
# Wavefront OBJ exported by MilkShape 3D

v 3.078942 12.721730 -0.085571
v 3.078942 16.044230 -7.099794
v 2.857884 17.794319 -5.349705
v 2.857884 14.471820 1.664518
v 2.839320 24.391068 -18.192051
v -0.715659 25.732157 -16.755615
v 0.328331 19.713190 -3.419155
v -2.857884 17.794319 -5.349705
v -3.141768 23.707361 -18.875757
v -2.857884 14.471820 1.664518
v -3.078942 12.721730 -0.085571
v -3.078942 16.044230 -7.099794
v -1.650000 11.284264 -1.523038
v -1.650000 14.606764 -8.537261
v -1.074862 21.446745 -20.862831
v 0.000000 14.294140 -8.849884
v 0.000000 10.971641 -1.835661
v 1.650000 11.284264 -1.523038
v 1.650000 14.606764 -8.537261
v 2.161693 22.013239 -20.569880
v 5.917666 21.737844 1.726000
v 7.343303 46.353558 -10.613414
v 3.568324 23.155359 4.632337
v 6.415104 47.103981 -9.074776
v 4.913245 46.817352 -9.662467
v -0.232991 22.613926 3.522212
v -1.566324 21.238894 -0.447340
v 4.913245 45.889732 -11.564344
v 6.415104 45.603119 -12.152043
v 5.875000 -24.286974 37.598591
v 4.700000 12.060586 8.541839
v 1.815475 -20.336046 41.549522
v 1.452380 15.221329 11.702582
v -3.802380 14.014032 10.495286
v -4.752975 -21.845167 40.040401
v -4.752975 -26.728785 35.156784
v -3.802380 10.107139 6.588391
v 1.452380 8.293752 4.775005
v 1.815475 -28.237906 33.647663
v -1.867189 30.698256 -25.600677
v -1.867189 33.045208 -28.048203
v -1.731791 32.313213 -28.612675
v -1.731791 29.966263 -26.165173
v -7.325558 48.412167 -33.390675
v -0.142219 31.417944 -29.064320
v 1.769117 32.313213 -28.612675
v 1.769117 29.966263 -26.165173
v 1.904515 30.698256 -25.600677
v 1.904515 33.045208 -28.048203
v 1.029288 31.807690 -25.035404
v 1.029288 34.154640 -27.482922
v 0.018663 34.395924 -27.359993
v 0.018663 32.048969 -24.912462
v -0.991962 31.807690 -25.035404
v -0.991962 34.154640 -27.482922
v -2.063837 28.989666 -29.564255
v 5.507776 29.427912 -48.187714
v -0.624865 27.523333 -29.592411
v 1.703441 28.272484 -29.487137
v 1.703441 30.201818 -29.393898
v 0.000000 50.077560 -19.146240
v 5.910001 48.146145 -11.557972
v 9.799999 53.419144 -11.780207
# 63 vertices

vt -2.625912 -0.404122
vt -2.625912 -0.051866
vt -2.517494 -0.051866
vt -2.517494 -0.404122
vt -2.508390 0.610585
vt -0.764803 0.607335
vt -1.276842 -0.052263
vt 0.285878 -0.051866
vt 0.425113 0.610585
vt 0.285878 -0.404122
vt 0.394298 -0.404122
vt 0.394298 -0.051866
vt -0.306544 -0.404122
vt -0.306544 -0.051866
vt -0.588628 0.601263
vt -1.115809 -0.051866
vt -1.115809 -0.404122
vt -1.925070 -0.404122
vt -1.925070 -0.051866
vt -2.176036 0.610585
vt -4.018202 -0.158604
vt -4.717425 1.100761
vt -2.865939 -0.209341
vt -4.262178 1.073900
vt -3.525569 1.084160
vt -1.001534 -0.189961
vt -0.347585 -0.101545
vt -3.525569 1.117361
vt -4.262178 1.127621
vt -3.997274 -2.949523
vt -3.420981 -0.720660
vt -2.006230 -2.949523
vt -1.828145 -0.720660
vt 0.749118 -0.720660
vt 1.215348 -2.949523
vt -0.200021 1.077995
vt -0.200021 1.241383
vt -0.266428 1.235674
vt -0.266428 1.072287
vt 2.477104 1.947123
vt -1.046054 1.220556
vt -1.983493 1.235674
vt -1.983493 1.072287
vt -2.049901 1.077995
vt -2.049901 1.241383
vt -1.620635 1.096539
vt -1.620635 1.259926
vt -1.124960 1.263960
vt -1.124960 1.100572
vt -0.629287 1.096539
vt -0.629287 1.259926
vt -0.103573 1.154841
vt -3.817164 1.804431
vt -0.809334 1.105831
vt -1.951280 1.127773
vt -1.951280 1.190344
vt -1.115809 1.518452
vt -4.014443 1.194038
vt -5.922341 1.381306
# 59 texture coordinates

vn 0.967770 -0.210559 -0.138152
vn 0.948897 -0.278062 -0.149251
vn 0.882787 0.427110 0.195614
vn 0.978375 0.080382 -0.190583
vn 0.947422 0.287337 0.140818
vn -0.184319 0.825972 0.532726
vn -0.056491 0.879671 -0.472216
vn -0.894404 0.400964 0.198165
vn -0.996936 -0.022650 -0.074874
vn -0.971890 0.235049 -0.013487
vn -0.982154 -0.153737 -0.108347
vn -0.923993 -0.335399 -0.183696
vn -0.532379 -0.779505 -0.330069
vn -0.560129 -0.731620 -0.388570
vn -0.342268 -0.785760 -0.515203
vn 0.028621 -0.885192 -0.464344
vn 0.002470 -0.915465 -0.402391
vn 0.554058 -0.754453 -0.351883
vn 0.558838 -0.733782 -0.386348
vn 0.658018 -0.622062 -0.424325
vn 0.967854 -0.159202 -0.194716
vn 0.977376 -0.095994 0.188469
vn 0.413896 0.468734 0.780371
vn 0.067944 0.581076 0.811008
vn -0.721061 0.480839 0.498863
vn -0.617581 0.536979 0.574672
vn -0.945784 0.093982 -0.310902
vn -0.806962 -0.485948 -0.335660
vn 0.279735 -0.336437 -0.899199
vn 0.977734 -0.114470 -0.175875
vn 0.990815 0.057862 0.122216
vn 0.308924 0.613325 0.726910
vn 0.169181 0.639885 0.749616
vn -0.808775 0.417895 0.413819
vn -0.809101 0.386319 0.442847
vn -0.827946 -0.334422 -0.450186
vn -0.904217 -0.327705 -0.273862
vn 0.306862 -0.789664 -0.531288
vn 0.308094 -0.588017 -0.747873
vn -0.967972 0.211063 0.135949
vn -0.921884 0.117358 0.369266
vn -0.880639 -0.341421 -0.328492
vn -0.973501 0.030486 -0.226640
vn -0.075843 0.822657 0.563457
vn -0.177069 0.327444 -0.928131
vn 0.821473 -0.164135 -0.546115
vn 0.978174 -0.011498 -0.207469
vn 0.987266 0.140096 0.075362
vn 0.933190 0.351089 0.076764
vn 0.552047 0.625213 0.551682
vn 0.568916 0.588150 0.574816
vn 0.005529 0.625560 0.780156
vn -0.000438 0.757252 0.653123
vn -0.562998 0.617502 0.549294
vn -0.499963 0.406620 0.764655
vn -0.963473 0.050008 -0.263095
vn 0.788905 -0.311115 -0.529939
vn -0.382085 -0.843585 -0.377327
vn 0.712305 -0.659739 -0.239514
vn 0.879322 0.468178 0.087188
vn -0.883579 -0.407681 -0.230400
vn 0.000000 0.000000 0.000000
vn -0.295862 0.951438 -0.085036
vn 0.861796 0.240599 -0.446564
# 64 normals

g Regroup01
s 1
f 1/1/1 2/2/2 3/3/3
f 1/1/1 3/3/3 4/4/4
f 2/2/2 5/5/5 3/3/3
f 3/3/3 5/5/5 6/6/6
f 3/3/3 6/6/6 7/7/7
f 7/7/7 6/6/6 8/8/8
f 6/6/6 9/9/9 8/8/8
f 10/10/10 8/8/8 11/11/11
f 8/8/8 12/12/12 11/11/11
f 8/8/8 9/9/9 12/12/12
f 11/11/11 12/12/12 13/13/13
f 12/12/12 14/14/14 13/13/13
f 12/12/12 9/9/9 15/15/15
f 12/12/12 15/15/15 14/14/14
f 13/13/13 14/14/14 16/16/16
f 13/13/13 16/16/16 17/17/17
f 14/14/14 15/15/15 16/16/16
f 17/17/17 16/16/16 18/18/18
f 16/16/16 19/19/19 18/18/18
f 16/16/16 15/15/15 20/20/20
f 16/16/16 20/20/20 19/19/19
f 18/18/18 19/19/19 2/2/2
f 18/18/18 2/2/2 1/1/1
f 19/19/19 20/20/20 2/2/2
f 20/20/20 5/5/5 2/2/2
f 21/21/21 22/22/22 23/23/23
f 22/22/22 24/24/24 23/23/23
f 23/23/23 24/24/24 25/25/25
f 23/23/23 25/25/25 26/26/26
f 26/26/26 25/25/25 27/27/27
f 25/25/25 28/28/28 27/27/27
f 27/27/27 28/28/28 29/29/29
f 27/27/27 29/29/29 7/7/7
f 7/7/7 29/29/29 21/21/21
f 29/29/29 22/22/22 21/21/21
f 27/27/27 7/7/7 10/10/10
f 7/7/7 8/8/8 10/10/10
f 30/30/30 31/31/31 32/32/32
f 31/31/31 33/33/33 32/32/32
f 32/32/32 33/33/33 34/34/34
f 32/32/32 34/34/34 35/35/35
f 35/35/35 34/34/34 36/35/36
f 34/34/34 37/34/37 36/35/36
f 36/35/36 37/34/37 38/33/38
f 36/35/36 38/33/38 39/32/39
f 39/32/39 38/33/38 30/30/30
f 38/33/38 31/31/31 30/30/30
f 26/26/26 27/27/27 10/10/10
f 10/10/10 34/34/34 26/26/26
f 34/34/34 10/10/10 37/34/37
f 37/34/37 10/10/10 11/11/11
f 37/34/37 11/11/11 13/13/13
f 37/34/37 13/13/13 38/33/38
f 38/33/38 13/13/13 17/17/17
f 10/10/10 26/26/26 34/34/34
f 34/34/34 33/33/33 26/26/26
f 33/33/33 23/23/23 26/26/26
f 3/3/3 7/7/7 4/4/4
f 4/4/4 7/7/7 21/21/21
f 21/21/21 31/31/31 4/4/4
f 31/31/31 21/21/21 23/23/23
f 31/31/31 23/23/23 33/33/33
f 1/1/1 4/4/4 31/31/31
f 31/31/31 38/33/38 1/1/1
f 38/33/38 18/18/18 1/1/1
f 38/33/38 17/17/17 18/18/18
f 40/36/40 41/37/41 42/38/42
f 40/36/40 42/38/42 43/39/43
f 41/37/41 44/40/44 42/38/42
f 42/38/42 44/40/44 45/41/45
f 45/41/45 44/40/44 46/42/46
f 47/43/47 46/42/46 48/44/48
f 46/42/46 49/45/49 48/44/48
f 46/42/46 44/40/44 49/45/49
f 48/44/48 49/45/49 50/46/50
f 49/45/49 51/47/51 50/46/50
f 49/45/49 44/40/44 51/47/51
f 50/46/50 51/47/51 52/48/52
f 50/46/50 52/48/52 53/49/53
f 51/47/51 44/40/44 52/48/52
f 53/49/53 52/48/52 54/50/54
f 52/48/52 55/51/55 54/50/54
f 52/48/52 44/40/44 55/51/55
f 54/50/54 55/51/55 41/37/41
f 54/50/54 41/37/41 40/36/40
f 55/51/55 44/40/44 41/37/41
f 56/52/56 57/53/57 58/54/58
f 58/54/58 57/53/57 59/55/59
f 59/55/59 57/53/57 60/56/60
f 60/56/60 57/53/57 45/41/45
f 45/41/45 57/53/57 56/52/56
f 60/56/60 45/41/45 47/43/47
f 45/41/45 46/42/46 47/43/47
f 59/55/59 60/56/60 47/43/47
f 47/43/47 20/20/20 59/55/59
f 20/20/20 47/43/47 5/5/5
f 5/5/5 47/43/47 48/44/48
f 5/5/5 48/44/48 50/46/50
f 5/5/5 50/46/50 6/6/6
f 6/6/6 50/46/50 53/49/53
f 47/43/47 59/55/59 20/20/20
f 15/15/15 58/54/58 59/55/59
f 42/38/42 45/41/45 43/39/43
f 43/39/43 45/41/45 56/52/56
f 56/52/56 9/9/9 43/39/43
f 9/9/9 56/52/56 58/54/58
f 40/36/40 43/39/43 9/9/9
f 9/9/9 6/6/6 40/36/40
f 6/6/6 54/50/54 40/36/40
f 6/6/6 53/49/53 54/50/54
f 61/57/61 28/28/28 25/25/25
f 22/22/22 22/22/62 22/22/62
f 29/29/29 28/28/28 61/57/61
f 25/25/25 62/58/63 61/57/61
f 61/57/61 62/58/63 29/29/29
f 25/25/25 24/24/24 62/58/63
f 63/59/64 62/58/63 24/24/24
f 24/24/24 22/22/22 63/59/64
f 22/22/22 29/29/29 63/59/64
f 29/29/29 62/58/63 63/59/64
f 20/20/20 15/15/15 59/55/59
f 15/15/15 9/9/9 58/54/58
# 122 triangles in group

# 122 triangles total


see

Share this post


Link to post
Share on other sites
Welp, show us a little more of your code ''n I may post mine when I get back to work Monday. My OBJ loader is certainly not perfect, but I think it should suffice for your purposes. Could compare code...

Share this post


Link to post
Share on other sites
quote:
Original post by neonoblivion
nope I''m using milkshape all models are triangulated(sp)
see


the problem list :

1. When reading in the normals and uv''s, you were incrementing the vertex_index rather than normal_index & uv_index respectively.

2. When reading in the vertices,normals & uv co-ords, the index accessing str_b & str_c was never reset causing the second and third values to be written somewhere in the middle of str_b & str_c respectively. When atof() was then called, the value returned was 0.000000 for all values.

3. You never terminated any of the strings causing a few funny glitches in the data.

4. I changed around the way that you were reading in the index values so that they were a little easier to place in the drawing function.

5. Variables were left unitialised which caused a couple of errors.


As a general tip, when trying to pull some values from a string, you''ll probably find sscanf a lot easier to use


  
float x,y,z;
char *str = "0.1 0.2 0.3";
sscanf(str,"%f%f%f",&x,&y,&z);


With the case of the face indices, you can use sscanf by placing the characters you want to ignore in there, ie


  
int x,y,z;
char *str = "1/2/3";
sscanf(str,"%d/%d/%d",&x,&y,&z);


Anyhow, I sent you a few resources, and here''s the working version :


  

int displaymodel(float x,float y,float z,model* obj)
{
glPushMatrix();

// use the translate command cos it''s a bit better!!!!

//

glTranslatef(x,y,z);

// can place the begin and end around the for loop

glBegin(GL_TRIANGLES);

for(int i=0,j=0;i<obj->nump*3;i++,j+=3)
{
glNormal3f (obj->normals [ 3*obj->polys[j ] ],
obj->normals [ 3*obj->polys[j ] + 1 ],
obj->normals [ 3*obj->polys[j ] + 2 ]);
glTexCoord2f(obj->texcords[ 2*obj->polys[j+1] ],
obj->texcords[ 2*obj->polys[j+1] + 1 ]);
glVertex3f (obj->vers [ 3*obj->polys[j+2] ],
obj->vers [ 3*obj->polys[j+2] + 1 ],
obj->vers [ 3*obj->polys[j+2] + 2 ]);
}

glEnd();

glPopMatrix();
return(1);
}


int loadmodel(int texindex,model* obj,char* str)
{
int vers = 0,
texs = 0,
nors = 0,
poly = 0,
index = 0,
index2 = 0,
vertex_index=0,
texture_index=0,
normal_index=0,
poly_index = 0;
float *pver = NULL,
*ptex = NULL,
*pnor = NULL;
int *ppoly = NULL;
char str2[100],
str3[100],
str_a[100],
str_b[100],
str_c[100];
FILE *file;

if((file=fopen(str,"r"))==NULL)
{
return(2);
}
while(!feof(file))
{
fgets(str2,100,file);
if(str2[0]==''v'' && str2[1]=='' '')
{
vers++;
}
if(str2[0]==''v'' && str2[1]==''t'')
{
texs++;
}
if(str2[0]==''v'' && str2[1]==''n'')
{
nors++;
}
if(str2[0]==''f'' && str2[1]=='' '')
{
poly++;
}
}

pver=(float *)malloc(sizeof(float)*vers*3);
if(pver==NULL)
{
return(3);
}
ptex=(float *)malloc(sizeof(float)*texs*2);
if(ptex==NULL)
{
return(4);
}
pnor=(float *)malloc(sizeof(float)*nors*3);
if(pnor==NULL)
{
return(5);
}
ppoly=(int *)malloc(sizeof(int)*poly*9);
if(ppoly==NULL)
{
return(6);
}
rewind(file);
while(!feof(file))
{
fgets(str2,100,file);
if(str2[0]==''v'' && str2[1]=='' '')
{
//load vertecies

index=2;
index2=0;
while(str2[index]!='' '')
{
str_a[index2]=str2[index];
index++;
index2++;
}
str_a[index2] = NULL;
index2=0;
index++;
while(str2[index]!='' '')
{
str_b[index2]=str2[index];
index++;
index2++;
}
str_b[index2] = NULL;
index2=0;
index++;
while(str2[index]!=0)
{
str_c[index2]=str2[index];
index++;
index2++;
}
str_c[index2] = NULL;
pver[vertex_index ]=(float)atof(str_a);
pver[vertex_index+1]=(float)atof(str_b);
pver[vertex_index+2]=(float)atof(str_c);
vertex_index+=3;
}
if(str2[0]==''v'' && str2[1]==''t'')
{
//load texture cords

index=2;
index2=0;
while(str2[index]!='' '')
{
str_a[index2]=str2[index];
index++;
index2++;
}
str_a[index2] = NULL;
index2=0;
index++;
while(str2[index]!=0)
{
str_b[index2]=str2[index];
index++;
index2++;
}
str_b[index2] = NULL;
ptex[texture_index ]=(float)atof(str_a);
ptex[texture_index+1]=(float)atof(str_b);
texture_index+=2;
}
if(str2[0]==''v'' && str2[1]==''n'')
{
//load normals

index=2;
index2=0;
while(str2[index]!='' '')
{
str_a[index2]=str2[index];
index++;
index2++;
}
str_a[index2] = NULL;
index2=0;
index++;
while(str2[index]!='' '')
{
str_b[index2]=str2[index];
index++;
index2++;
}
str_b[index2] = NULL;
index2=0;
index++;
while(str2[index]!=0)
{
str_c[index2]=str2[index];
index++;
index2++;
}
str_c[index2] = NULL;
pnor[normal_index ]=(float)atof(str_a);
pnor[normal_index+1]=(float)atof(str_b);
pnor[normal_index+2]=(float)atof(str_c);
normal_index+=3;
}
if(str2[0]==''f'' && str2[1]=='' '')
{
/*
//load polys
index=2;
index2=0;
for(int x2=0;x2<9;x2++)
{
while(isdigit(str2[index]))
{
str3[index2]=str2[index];
index++;
index2++;
}//end while
index++;
ppoly[poly_index] = atoi(str3);
--ppoly[poly_index++];
index2=0;
}//end for
*/

//sorry, didn''t like the above

sscanf(&str2[2],"%d/%d/%d %d/%d/%d %d/%d/%d",
&ppoly[poly_index+2],&ppoly[poly_index+1],&ppoly[poly_index ],
&ppoly[poly_index+5],&ppoly[poly_index+4],&ppoly[poly_index+3],
&ppoly[poly_index+8],&ppoly[poly_index+7],&ppoly[poly_index+6]);
for(int i=0;i<9;i++)
{
--ppoly[poly_index++];
}

}//end if

}//end while !feof

fclose(file);
obj->tex=texindex;
obj->nump=poly;
obj->vers=pver;
obj->texcords=ptex;
obj->normals=pnor;
obj->polys=ppoly;
return(0);
}


Share this post


Link to post
Share on other sites