Esempio n. 1
0
int vertex_insert(float v[])
{
  int i;

  i=vertex_find(v);
  if(i!=-1) return i;

  for(i=0; 
      i<VERTEX_MAX && 
	vertex_used[i]>0;
      i++) ;

  if(i>=VERTEX_MAX)
    {
      printf("too many vertices !!!\n");
      return -1;
    }

  vectorcpy(vertex[i], v);

   /*  vertex_used[i]++; */
  return i;
}
Esempio n. 2
0
//to global verts and faces  (not shorts)
//ALSO, COMBINES EACH DAE OBJECT
void dae_geo_to_polys_and_verts( dae_geo_t dg )
{
	//mtrl string , count
	materials.insert( materials.end(),
					  dg.materials.begin(),dg.materials.end());
	material_counts.insert( material_counts.end(),
							dg.material_counts.begin(),
							dg.material_counts.end());

	printf("_\t_\tDAE -> VERTEX / INDICES\t_\t_\t_\t_\t_\n");
	int II = 0, pi,ui,ni,ci;
	poly_t p={};
	for ( int f = 0; f < dg.poly_count; ++f)
	{
		//vertices / indices
		for ( int j = 0; j < 3; ++j )
		{
			vertex_t v={};
			//get indices, p,normal,
			pi = dg.poly[II++];
			ni = dg.poly[II++];
			ui = dg.poly[II++];
			ci = dg.poly[II++];

			//
			v.pos.x = dg.pos[ pi*3 + 0 ];
			v.pos.y = dg.pos[ pi*3 + 1 ];
			v.pos.z = dg.pos[ pi*3 + 2 ];
			
			v.normal.x = dg.normal[ ni*3 + 0 ];
			v.normal.y = dg.normal[ ni*3 + 1 ];
			v.normal.z = dg.normal[ ni*3 + 2 ];

			v.uv.x = dg.uv[ ui*2 + 0 ];
			v.uv.y = dg.uv[ ui*2 + 1 ];
		
			//vertex hand painted color
			//vset(v.init_rgb,.1,.1,.1);
			v.color.x = dg.rgb[ ci*3 + 0 ];
			v.color.y = dg.rgb[ ci*3 + 1 ];
			v.color.z = dg.rgb[ ci*3 + 2 ];

			int index = vertex_find( v );
			if ( index == (int)verts.size() ){
				verts.push_back( v );
				//debug ( "dupe found\n" );
			}

			 p.index[ j ]=index;
		}

		const vec3 basis[3]={
			{ -.40824829046, -.70710678118,  .57735026919 },//blue
			{ -.40824829046, .70710678118,   .57735026919 },//green
			{ .81649658092,  0.,			 .57735026919 }//red
		};

		//tangent, basis and inset,,, and direction of vertex color light
		for ( int j=0;j<3;++j )
		{
			vertex_t& a = verts[p.index[j]];
			const vertex_t& b =  verts[p.index[(j+1)%3]];
			const vertex_t& c =  verts[p.index[(j+2)%3]];

			//inset ( lighting sample point ) //BAD FOR SMOOTH!!
			a.inset = a.pos + (b.pos-a.pos)*.005f + (c.pos-a.pos)*.005f;

			//tangent
			a.tangent = uv_tangent(
				vnormal(b.pos-a.pos),
				vnormal(c.pos-a.pos), 
				vnormal(b.uv - a.uv),
				vnormal(c.uv - a.uv) 
				);

			//MUST BE CORRECTED FOR SMOOTH SURFACES
			
			// if( vdot ( vnormal( a.normal ), vnormal ( vcross( b.pos-a.pos, c.pos-a.pos ) ) ) < .9 )
			// {
			// 	printf( "SHOULD BE CORRECTED\n");
			 vec3 right = vcross( a.tangent, a.normal );
			 a.tangent = vnormal( vcross( a.normal, right ) );

			// }

			//basis

			//we have normal
			vec3 N = a.normal;//vnormal( vcross(b.pos-a.pos, c.pos-a.pos) );
			vec3 T = a.tangent;
			vec3 B = vcross( T, N );
			
			//rotate basis axes by TBN 
			for( int k=0; k<3;++k)
				a.basis[k] = //exactly like mmulv
					T*vec3f(basis[k].x,basis[k].x,basis[k].x)+
					B*vec3f(basis[k].y,basis[k].y,basis[k].y)+
					N*vec3f(basis[k].z,basis[k].z,basis[k].z)
					;

			//vertex color.. FOR NOW JUST ALL
			// for( int k=0; k<3;++k)
			//  	a.basis_color[k]=a.color;

		}

		polys.push_back(p);
	}
	printf ( "VERTS : %d\n", verts.size() );
	printf ( "POLYS : %d\n", polys.size() );
	printf ( "\n" );
}