/** Overlay constructor * * Operation: * -# Create a surface for the overlay's texture * -# Initialise the mesh base class to hold 4 vertices * -# Initialise the surface to hold 6 indicies (3 for each triangle, 2 triangles for one rectangle) * -# Assign the default vertex data for the rectangle * -# Assign the default normal data for the rectangle * -# Assign the triangle indices * -# Set the surfaces vertex/normal/index data * -# Generate a white material and update the surface with it */ Overlay::Overlay() { IVertexBuffer *v = AddVertexBuffer(); Initialise(4); v->Initialise(GetNumVertex(),6,3,2); int *index = v->GetIndex(); // Assign all the m_position data m_position[0].x = 0; m_position[0].y = 0; m_position[0].z = 0; m_position[1].x = 0; m_position[1].y = 1; m_position[1].z = 0; m_position[2].x = 1; m_position[2].y = 1; m_position[2].z = 0; m_position[3].x = 1; m_position[3].y = 0; m_position[3].z = 0; // Assign all the m_normal data m_normal[0].x = 0; m_normal[0].y = 0; m_normal[0].z = 1; m_normal[1].x = 0; m_normal[1].y = 0; m_normal[1].z = 1; m_normal[2].x = 0; m_normal[2].y = 0; m_normal[2].z = 1; m_normal[3].x = 0; m_normal[3].y = 0; m_normal[3].z = 1; // Assign all the polygon indices index[0] = 0; index[1] = 1; index[2] = 2; index[3] = 0; index[4] = 3; index[5] = 2; v->SetPosition((float *)m_position); v->SetNormal((float *)m_normal); v->SetIndex(index); Material *m = v->GetMaterial(); m->colour.r = 1; m->colour.g = 1; m->colour.b = 1; m->colour.a = 1; v->SetMaterial(m); }
YSRESULT YsShell::SaveMsh(int &nIgnored,const char fn[]) const { FILE *fp; YsShellVertexHandle vtHd; YsShellPolygonHandle plHd; Encache(); nIgnored=0; fp=fopen(fn,"w"); if(fp!=NULL) { int id,nofel2; fprintf(fp,"nofnod %d\n",GetNumVertex()); id=1; vtHd=NULL; while((vtHd=FindNextVertex(vtHd))!=NULL) { YsVec3 pos; GetVertexPosition(pos,vtHd); fprintf(fp,"nod %d %lf %lf %lf\n",id,pos.x(),pos.y(),pos.z()); id++; } nofel2=0; plHd=NULL; while((plHd=FindNextPolygon(plHd))!=NULL) { if(GetNumVertexOfPolygon(plHd)==3 || GetNumVertexOfPolygon(plHd)==4) { nofel2++; } else { nIgnored++; } } fprintf(fp,"nofel2 %d\n",nofel2); id=1; plHd=NULL; while((plHd=FindNextPolygon(plHd))!=NULL) { int i,n; const YsShellVertexHandle *plVtHd; n=GetNumVertexOfPolygon(plHd); plVtHd=GetVertexListOfPolygon(plHd); if(n==3 || n==4) { fprintf(fp,"el2 %d %d",id,n); for(i=0; i<n; i++) { fprintf(fp," %d",GetVertexIdFromHandle(plVtHd[i])+1); } fprintf(fp,"\n"); id++; } } fclose(fp); return YSOK; } return YSERR; }