static void _ase_submit_triangles( picoModel_t* model , aseMaterial_t* materials , aseVertex_t* vertices, aseTexCoord_t* texcoords, aseColor_t* colors, aseFace_t* faces, int numFaces ) { aseFacesIter_t i = faces, end = faces + numFaces; for(; i != end; ++i) { /* look up the shader for the material/submaterial pair */ aseSubMaterial_t* subMtl = _ase_get_submaterial_or_default( materials, (*i).materialId, (*i).subMaterialId ); if( subMtl == NULL ) { return; } { picoVec3_t* xyz[3]; picoVec3_t* normal[3]; picoVec2_t* st[3]; picoColor_t* color[3]; picoIndex_t smooth[3]; int j; /* we pull the data from the vertex, color and texcoord arrays using the face index data */ for ( j = 0 ; j < 3 ; j ++ ) { xyz[j] = &vertices[(*i).indices[j]].xyz; normal[j] = &vertices[(*i).indices[j]].normal; st[j] = &texcoords[(*i).indices[j + 3]].texcoord; if( colors != NULL && (*i).indices[j + 6] >= 0 ) { color[j] = &colors[(*i).indices[j + 6]].color; } else { color[j] = &white; } smooth[j] = (vertices[(*i).indices[j]].id * (1 << 16)) + (*i).smoothingGroup; /* don't merge vertices */ } /* submit the triangle to the model */ PicoAddTriangleToModel ( model , xyz , normal , 1 , st , 1 , color , subMtl->shader, smooth ); } } }
static void _ase_submit_triangles( picoModel_t* model , aseMaterial_t* materials , aseVertex_t* vertices, aseTexCoord_t* texcoords, aseColor_t* colors, aseFace_t* faces, int numFaces,int numVerts, int submodel ) { picoVec3_t accum; int index; int counter; faceref_t* faceref; int *normalsC; int fc=0; aseFacesIter_t i = faces, end = faces + numFaces; counter=0; //allocate room for sg optimization faceref=(faceref_t*)malloc(numVerts*sizeof(faceref_t)); memset(faceref,0,numVerts*sizeof(faceref_t)); //rebuild face normals for(i=faces; i != end; ++i) { picoVec3_t a,b,c; picoVec3_t v1,v2,v3; int j; counter++; for (j=0;j<3;j++) { a[j] = vertices[(*i).indices[0]].xyz[j]; b[j] = vertices[(*i).indices[1]].xyz[j]; c[j] = vertices[(*i).indices[2]].xyz[j]; } for (j=0;j<3;j++) { v1[j]=a[j]-b[j]; v2[j]=c[j]-b[j]; } CrossProductTemp(v1,v2,v3); _pico_normalize_vec(v3); (*i).facenormal[0]=v3[0]; (*i).facenormal[1]=v3[1]; (*i).facenormal[2]=v3[2]; //throw this face into the index pools for ( j = 0 ; j < 3 ; j ++ ) { index=(*i).indices[j]; if (faceref[index].count>=MAX_FACEREFS-1) { } else { faceref[index].faces[faceref[index].count++]=i; } } } //if (counter>0) Sys_Printf( "Rebuilding %d Normals\n", counter * 3 ); for(i=faces; i != end; ++i) { /* look up the shader for the material/submaterial pair */ aseSubMaterial_t* subMtl = _ase_get_submaterial_or_default( materials, (*i).materialId, (*i).subMaterialId ); if( subMtl == NULL ) { continue; } { picoVec3_t* xyz[3]; picoVec3_t *a[3]; picoVec3_t* normal[3]; picoVec2_t* st[3]; picoColor_t* color[3]; picoIndex_t smooth[3]; int j,z; /* we pull the data from the vertex, color and texcoord arrays using the face index data */ for ( j = 0 ; j < 3 ; j ++ ) { aseFacesIter_t q = faces; aseFacesIter_t qend = faces + numFaces; xyz[j] = &vertices[(*i).indices[j]].xyz; // Use Face normal normal[j] = &(*i).facenormal; //Oooor we can use the smoothing group //Slow method, but testing //Find All faces that use this vertex, average their facenormals. // skip where smoothgroups both equal 0, or don't have any shared bits (x & y) index=(*i).indices[j]; accum[0]=(*i).facenormal[0]; accum[1]=(*i).facenormal[1]; accum[2]=(*i).facenormal[2]; counter=1; z=0; for (fc=0;fc<faceref[index].count;fc++) { z++; q=faceref[index].faces[fc]; if (q==i) continue; //skip us. // if ( (*q).indices[0]==index || (*q).indices[1]==index || (*q).indices[2]==index) a[0]= &vertices[(*q).indices[0] ].xyz; a[1]= &vertices[(*q).indices[1] ].xyz; a[2]= &vertices[(*q).indices[2] ].xyz; if ( VectorCompareExtn(*a[0],*xyz[j],0.01f)>0 || VectorCompareExtn(*a[1],*xyz[j],0.01f)>0 || VectorCompareExtn(*a[2],*xyz[j],0.01f)>0 ) { if ( (*i).smoothingGroup==0 && (*q).smoothingGroup ==0 ) continue; if ( (*i).smoothingGroup & (*q).smoothingGroup ) { accum[0]+=(*q).facenormal[0]; accum[1]+=(*q).facenormal[1]; accum[2]+=(*q).facenormal[2]; counter++; } } } _pico_normalize_vec(accum); (*i).vertexnormal[j][0]=accum[0]; (*i).vertexnormal[j][1]=accum[1]; (*i).vertexnormal[j][2]=accum[2]; normal[j]=&(*i).vertexnormal[j]; st[j] = &texcoords[(*i).indices[j + 3]].texcoord; if( colors != NULL && (*i).indices[j + 6] >= 0 ) { color[j] = &colors[(*i).indices[j + 6]].color; } else { color[j] = &white; } smooth[j] = 0;// (vertices[(*i).indices[j]].id * (1 << 16)) + (*i).smoothingGroup; /* don't merge vertices */ } /* submit the triangle to the model */ PicoAddTriangleToModel ( model , xyz , normal , 1 , st , 1 , color , subMtl->shader, smooth, submodel ); } } free(faceref); }