bool ITR3DMImport::import(const char* file, ITRGeometry* geometry, Vector<UInt32>* volumeMasks) { TPlaneF::DistancePrecision = distancePrecision; TPlaneF::NormalPrecision = normalPrecision; char buff[256]; // printf("Thred.3DM Import\n"); PolyList polyList; printf(" Importing..."); import(file,&polyList); #if 0 // This is now down by Zed. // Texture mapping printf("Texturing..."); for (int i = 0; i < polyList.size(); i++) boxMap(polyList[i]); #endif // Split polys whose textures are larger than 256x256 printf("Splitting..."); for (int i = 0; i < polyList.size(); i++) { Poly* poly = polyList[i]; if (poly->textureSize.x > splitDist) splitX(poly,&polyList); if (poly->textureSize.y > splitDist) splitY(poly,&polyList); } printf("Material Sorting..."); sortByMaterial(polyList); if (lowDetailInterior == false) { // Insert colinear vertices into polygons printf("SharedVertices..."); insertVertices(polyList); } else { printf("LowDetail (Shared Vertices not inserted)..."); geometry->setFlag(ITRGeometry::LowDetailInterior); } // printf("Export..."); exportToGeometry(polyList, geometry, volumeMasks); geometry->highestMipLevel = maxMipLevel; printf("\n"); // printf(" Vertices: %d\n", geometry->point3List.size()); printf(" Surfaces: %d\n", geometry->surfaceList.size()); printf(" Planes: %d\n", geometry->planeList.size()); return true; }
bool DelPoly() { if (poly_.size() == Settings::MinPolygons) return false; int idx = RangeRand(poly_.size()); PolyIt it = poly_.begin(); std::advance(it, idx); poly_.erase(it); return true; }
bool AddPoly() { if (poly_.size() == Settings::MaxPolygons) return false; int idx = RangeRand(poly_.size()); PolyIt it = poly_.begin(); std::advance(it, idx); poly_.insert(it, DnaPolygon()); return true; }
void dtEndComplexShape() { if (currentComplex->getBase().getPointer() == 0) { Point *ptr = new Point[pointBuf.size()]; copy(pointBuf.begin(), pointBuf.end(), ptr); currentComplex->setBase(ptr, true); pointBuf.erase(pointBuf.begin(), pointBuf.end()); } currentComplex->finish(polyList.size(), &polyList[0]); polyList.erase(polyList.begin(), polyList.end()); complexList.push_back(currentComplex); currentComplex = 0; }
/* -------------------------------------------------------------------------------- ------ FacetComplex class functions ----------------------------------------------- -------------------------------------------------------------------------------- */ FacetComplex::FacetComplex(const PolyRing& /*P*/, const PolyList& PL) { // facet f_tmp; // vector<long> v(NumIndets(P)); for (PolyList::const_iterator it=PL.begin(); it!=PL.end();++it) { // exponents(v,LPP(*it)); // f_tmp=facet(v); // myInsert(f_tmp); myInsert(facet(LPP(*it))); } }//FacetComplex
void MaterialGroup::extract( SMesh* mesh ) { mesh->numMats = (uint)MatIDs.size(); if ( mesh->numMats > 0 ) { mesh->matGrps = (SMatGrp*)calloc( mesh->numMats, sizeof(SMatGrp) );//new SMatGrp[ mesh->numMats ]; for (size_t i = 0; i < mesh->numMats; i++) { SMatGrp* matGrp = &mesh->matGrps[i]; matGrp->materialID = MatIDs[i]; PolyList *list = PolyListList[i]; list->extract( matGrp ); } } }
bool Mutate() { bool dirty = false; if (DoMutate(AddPolyMutation)) dirty |= AddPoly(); if (DoMutate(DelPolyMutation)) dirty |= DelPoly(); if (DoMutate(MovePolyMutation)) dirty |= MovePoly(); for (PolyIt it = poly_.begin(); it != poly_.end(); ++it) dirty |= it->Mutate(); return dirty; }
bool MovePoly() { int origpos = RangeRand(poly_.size()); int newpos = RangeRand(poly_.size()); if (newpos == origpos) return false; PolyIt it = poly_.begin(); std::advance(it, origpos); DnaPolygon p(*it); poly_.erase(it); it = poly_.begin(); std::advance(it, newpos); poly_.insert(it, p); return true; }
// to GOperations void ComputeDynamicGBasis(PolyList& theGB,const PolyList& thePL, int level=0) { clog << "ComputeDynamicGBasis:level= " <<level<<endl; PolyList GB; if (thePL.empty()) { swap(theGB,GB); return; } PolyList NewCandidateBasis; { SparsePolyRing CurrentSPR(AsSparsePolyRing(owner(thePL))); PPMonoidElem BestLPP(PPM(CurrentSPR)); vector<RingElem> BestSolution; bool ArePolyHomogeneous=IsHomog(thePL); GRingInfo GRI(CurrentSPR,ArePolyHomogeneous,NewDivMaskEvenPowers()); clog <<"ComputeDynamicGBasis:ArePolyHomogeneous="<<ArePolyHomogeneous<<endl; GReductor GBR(GRI, thePL, 3); GBR.myReduceUntilWrongLPPFound(BestLPP,BestSolution);// dynamic algorithm if (!GBR.WrongLPPFound()) { GBR.myGBasis(GB); swap(theGB,GB); return; } clog << "ComputeDynamicGBasis:WrongLPPFound " <<endl; SparsePolyRing TmpRing=NewSparsePolyRingA(CurrentSPR,BestSolution); RingHom phi=OrderingChangeRingHom(CurrentSPR,TmpRing); PolyList CandidateBasis; clog << "ComputeDynamicGBasis:Pairs "<<endl; GBR.myStampaPairs(clog); GBR.GetCandidateGBasis(CandidateBasis); clog << "ComputeDynamicGBasis:CandidateBasis " <<CandidateBasis<<endl; NewCandidateBasis=ChangeOrdering(TmpRing,CandidateBasis); clog << "ComputeDynamicGBasis:BestLPP " <<BestLPP<<endl; clog << "ComputeDynamicGBasis:BestSolution " <<BestSolution<<endl; clog << "ComputeDynamicGBasis:TmpRing " <<TmpRing<<endl; clog << "ComputeDynamicGBasis:phi " <<phi<<endl; clog << "ComputeDynamicGBasis:NewCandidateBasis " <<NewCandidateBasis<<endl; GB.clear(); } ComputeDynamicGBasis(GB,NewCandidateBasis,level+1); swap(theGB,GB); clog << "ComputeDynamicGBasis: theGB= " <<theGB<<endl; }//ComputeGBasis
void ITR3DMImport::insertVertices(PolyList& polyList) { ColinearList colinearList; for (int p = 0; p < polyList.size(); p++) { Poly* poly = polyList[p]; // Loop through all the edges. int v1 = poly->vertexList.size() - 1; for (int v2 = 0; v2 < poly->vertexList.size(); v2++) { // For each edge, find colinear points. Point3F &p1 = poly->vertexList[v1].point; Point3F &p2 = poly->vertexList[v2].point; if (findColinear(p1,p2,poly,polyList,&colinearList)) { Point2F tv1 = poly->vertexList[v1].texture; Point2F tv2 = poly->vertexList[v2].texture; tv2 -= tv1; // Insert new vertices in order. for (ColinearList::iterator itr = colinearList.begin(); itr != colinearList.end(); itr++) { poly->vertexList.insert(v2); PolyVertex& vertex = poly->vertexList[v2++]; float time = (*itr).time; vertex.texture.x = tv1.x + (tv2.x * time); vertex.texture.y = tv1.y + (tv2.y * time); vertex.point = (*itr).point; vertex.colinear = true; } } v1 = v2; } // Make sure first three vertices are not colinear. poly->rotate(); // for (int i = 0; i < poly->vertexList.size(); i++) { Point3F& p = poly->vertexList[i].point; float distance = poly->plane.distance(p); if (distance > distancePrecision) { printf("Doh!"); } } } }
void dtVertexIndices(DtPolyType type, DtCount count, const DtIndex *indices) { if (currentComplex) { const Polytope *poly; switch (type) { case DT_SIMPLEX: poly = new Simplex(currentComplex->getBase(), count, indices); break; case DT_POLYGON: poly = new Polygon(currentComplex->getBase(), count, indices); break; case DT_POLYHEDRON: if (currentComplex->getBase().getPointer() == 0) { currentComplex->setBase(&pointBuf[0]); poly = new Polyhedron(currentComplex->getBase(), count, indices); currentComplex->setBase(0); } else poly = new Polyhedron(currentComplex->getBase(), count, indices); break; } polyList.push_back(poly); } }
int Poly() const { return poly_.size(); }
void program() { GlobalManager CoCoAFoundations; cout << endl << "------ building complexes------" << endl; ring myQQ = RingQQ(); SparsePolyRing R=NewPolyRing(myQQ,5); const vector<RingElem>& x = indets(R); cout <<"------ from PolyList------" << endl; PolyList L; L.push_back(x[1]*x[3]); L.push_back(x[0]*x[1]*x[4]); SimplicialComplex SC(L); cout << "PolyList L: " << L << endl; cout << "SC(L): " << SC <<endl; cout << "------ from std::list<face> ------" << endl; DynamicBitset f(LPP(x[1]*x[2])); DynamicBitset f2(LPP(x[0]*x[2]*x[4])); face f3(5); f3.mySet(3,1); f3.mySet(2,1); f3.mySet(4,1); std::list<face> l; l.push_back(f); l.push_back(f2); l.push_back(f3); SimplicialComplex SC2(l); cout << "std::list<face> l: " << l <<endl; cout << "SC2(l): " << SC2 <<endl; cout << "------ the empty SC on n vertices------" << endl; SimplicialComplex emptySC(5); cout << "the empty SC on 5 vertices: " << emptySC <<endl; cout << "is empty? :: " << emptySC.IamEmptySC() <<endl; cout << "is a simplex? : " << emptySC.IamSimplexSC() <<endl; cout << endl << "------ the simplex on n vertices ------" << endl; SimplicialComplex S4=simplexSC(5); cout << "the simplex on 5 vertices, S4: " << S4 <<endl; cout << "is S4 a simplex? : " << S4.IamSimplexSC() <<endl; cout << "is S4 empty? :: " << S4.IamEmptySC() <<endl; //----------------------------------------- cout << endl <<"------ the boundary of the simplex on n vertices ------" << endl; SimplicialComplex bdS4=boundarySimplexSC(5); cout << "the boundary of S4: " << bdS4 <<endl; //------------------------------------------ cout << "------ subcomplexes ------" << endl; std::vector<long> V(0); V.push_back(0); V.push_back(1); V.push_back(2); SimplicialComplex subSC(SC,V); cout << "SC: " << SC <<endl; cout << "vector<long> V: " << V <<endl; cout << "subSC(SC,V): " << subSC << endl; cout << "subSC.myVSet: " << subSC.myGetVSet() <<endl << endl; SimplicialComplex subSC2(SC,f2); cout << "SC: " << SC <<endl; cout << "face f: " << f << endl; cout << "subSC2(SC,f): " << subSC2 << endl; cout << "subSC2.myVSet: " << subSC2.myGetVSet() <<endl << endl; //----------------------------------------- cout << "------myNumIndets, myNumFacets, myDim, myFacetList,myGetVSet------"<< endl << endl; cout << "SC: " << SC <<endl; cout << "SC.myNumIndets(): " << SC.myNumIndets() << endl << endl; cout << "SC.myNumFacets(): " << SC.myNumFacets() << endl << endl; cout << "SC.myDim(): " << SC.myDim() << endl << endl; cout << "SC.myFacetList(): " << SC.myFacetList() << endl << endl; cout << "SC.myGetVSet(): " << SC.myGetVSet() <<endl << endl; //------------------------------------------ cout << "------ complements ------" << endl << endl; std::list<face> L1=SC.myFacetList(); face f1=L1.front(); cout << "SC.myVSet: " << SC.myGetVSet() << endl; cout << "f1: " << f1 << endl; cout << "complement f1: " << SC.myComplF(f1) << endl<< endl; //----------------------------------------- cout << "------ link, star, del, fdel ------"<< endl << endl; face v0(LPP(x[0])); cout << "vertex 0: " << v0 << endl; cout << "boundary of simplex of dim 4, bdS4: " << bdS4 << endl; SimplicialComplex LKv=bdS4.myLinkSC(v0); cout << "link(v0,bdS4): " << LKv << endl; SimplicialComplex STv=bdS4.myStarSC(v0); cout << "star(v0,bdS4): " << STv << endl; SimplicialComplex Delv=bdS4.myDelSC(v0); cout << "del(v0,bdS4): " << Delv << endl; cout << "boundary of simplex of dim 4, bdS4: " << bdS4 << endl; face f0(LPP(x[0]*x[1]*x[2]*x[3])); cout << "f0: " << f0 << endl << endl; SimplicialComplex LKf=bdS4.myLinkSC(f0); cout << "link(f0,bdS4): " << LKf << endl; SimplicialComplex STf=bdS4.myStarSC(f0); cout << "star(f0,bdS4): " << STf << endl; SimplicialComplex Delf=bdS4.myDelSC(f0); cout << "del(f0,bdS4): " << Delf << endl; SimplicialComplex FDelf=bdS4.myFaceDelSC(f0); cout << "faceDel(f0,bdS4): " << FDelf << endl; face g0(LPP(x[0]*x[1]*x[2])); cout << "g0: " << g0 << endl << endl; LKf=bdS4.myLinkSC(g0); cout << "link(g0,bdS4): " << LKf << endl; STf=bdS4.myStarSC(g0); cout << "star(g0,bdS4): " << STf << endl; Delf=bdS4.myDelSC(g0); cout << "del(g0,bdS4): " << Delf << endl; FDelf=bdS4.myFaceDelSC(g0); cout << "faceDel(g0,bdS4): " << FDelf << endl; //----------------------------------------- cout << "------connectivity------"<< endl << endl; cout << "is emptySc connected?: " << emptySC.IamConnected() << endl; cout << "is S4 connected?: " << S4.IamConnected() << endl; cout << "is bdS4? connected?: " << bdS4.IamConnected() << endl; std::vector<long> V1(0); V1.push_back(0); V1.push_back(1); V1.push_back(2); std::vector<long> V2(2); V2[0]=3; V2[1]=4; //cout << V2; SimplicialComplex newSC1(SC,V2); SimplicialComplex newSC2(bdS4,V1); cout << "newSC1: " << newSC1 <<endl; cout << "newSC2: " << newSC2 <<endl; SimplicialComplex newSC=unionSC(newSC1,newSC2); cout << "newSC: " << newSC <<endl; cout << "is newSC connected?: " << newSC.IamConnected() << endl; cout << "connected components of newSC: "; std::list<SimplicialComplex> CC=newSC.myConnCompsSC(); cout << len(CC); for (std::list<SimplicialComplex>::const_iterator it=CC.begin(); it!=CC.end();++it) cout << *it; PolyList NL; NL.push_back(x[2]*x[3]); NL.push_back(x[1]*x[4]); NL.push_back(x[3]*x[4]); NL.push_back(x[0]); SimplicialComplex NSC(NL); cout << endl <<"NSC: " << NSC <<endl; cout << "is NSC connected?: " << NSC.IamConnected() << endl; cout << "connected components of NSC: "; CC=NSC.myConnCompsSC(); cout << len(CC); for (std::list<SimplicialComplex>::const_iterator it=CC.begin(); it!=CC.end();++it) cout << *it; //----------------------------------------- cout << endl << "------membership------" << endl << endl; cout << "is f0 in link(v0,bdS4): " << LKv.IamFace(f0) << endl; cout << "is f0 in link(f0,bdS4): " << LKf.IamFace(f0) << endl; cout << "is v0 in bdS4: " << bdS4.IamFace(v0) << endl; cout << "is v0 a facet in bdS4: " << bdS4.IamFacet(v0) << endl; face F0=bdS4.myFacetList().back(); cout << "F0: " << F0 << endl; cout << "is F0 a facet in bdS4: " << bdS4.IamFacet(F0) << endl; //----------------------------------------- cout << endl << "------purity------" << endl << endl; cout << "is emptySC pure?: " << emptySC.IamPure() << endl; cout << "is S4 pure?: " << S4.IamPure() << endl; cout << "is bdS4 pure?: " << bdS4.IamPure() << endl; cout << "is SC pure?: " << SC.IamPure() << endl; cout << "SC: " << SC <<endl; //----------------------------------------- cout << endl << "------ k-faces ------" << endl << endl; cout << "face: " << f0 << endl; cout << "1-faces: " << ifacesF(1,f0) << endl; //--------------------------------------------------------- cout << endl << "------ k-decomposability ------" << endl << endl; face newf=face(9); newf.mySet(0); newf.mySet(2); newf.mySet(3); newf.mySet(4); // newf.mySet(7); cout << "newf: " << newf << endl; SimplicialComplex S8=simplexSC(9); SimplicialComplex D=S8.myFaceDelSC(newf); cout << "D: " << D << endl; cout << "Is D 8-decomposable?: " << S8.IamKDecomposable(4) << endl; D=simplexSC(5); for(SimplicialComplexConstIter k=l.begin(); k!=l.end(); ++k) D=D.myFaceDelSC(*k); cout << "D: " << D << endl; cout << "Is D 0-decomposable?: " << D.IamKDecomposable(0) << endl; cout << "Is D (dim D)-decomposable?: " << D.IamKDecomposable(2) << endl; cout << "Is D vertex-decomposable?: " << D.IamVertexDecomposable() << endl; SparsePolyRing R7=NewPolyRing(myQQ,7); const vector<RingElem>& y = indets(R7); PolyList L2; RingElem vL2[]={y[0]*y[1]*y[2]*y[6],y[0]*y[1]*y[3]*y[6],y[0]*y[2]*y[5]*y[6],y[0]*y[3]*y[5]*y[6],y[1]*y[2]*y[4]*y[6],y[1]*y[3]*y[4]*y[6],y[2]*y[4]*y[5]*y[6],y[0]*y[1]*y[3]*y[4],y[0]*y[2]*y[3]*y[5],y[1]*y[2]*y[4]*y[5]}; for (long i=0; i<10; ++i) L2.push_back(vL2[i]); SimplicialComplex nVD(L2); cout << "Is nVD 0-decomposable?: " << nVD.IamKDecomposable(0) << endl << endl; //--------------------------------------------------------- cout << endl << "------ Stanley-Reisner Ideal ------" << endl; //cout << endl << "emptySC: " << emptySC <<endl; // cout << emptySC.myStanleyReisnerIdeal(R) << endl; // cout << endl << "S4: " << S4 <<endl; //cout << S4.myStanleyReisnerIdeal(R) << endl; cout << endl << "bdS4: " << bdS4 <<endl; cout << bdS4.myStanleyReisnerIdeal(R) << endl; cout << endl << "NSC: " << NSC <<endl; //std::list<PPMonoidElem> SRI= NSC.myStanleyReisnerIdeal(); cout << NSC.myStanleyReisnerIdeal(R) << endl; //RingElem(SRI.front()); ????? //----------------------------------------- cout << endl << "------ boundaries of faces------"<< endl << endl; cout << "f2: " << f2 << endl; cout << "bound of f2: " << boundaryF(f2) << endl; //----------------------------------------- cout << endl << "------vertices------"<< endl << endl; cout << "f2: " << f2 << endl; cout << "vertices of f2: " << vertices(f2) << endl; //----------------------------------------- cout << endl << "------unions------" << endl; cout << "SC: " << SC <<endl; cout << "SC2: " << SC2 << endl; SimplicialComplex U=SC|SC2; cout << "SC union SC2 :" << U << endl; //----------------------------------------- cout << "------ intersections ------" << endl; cout << "SC: " << SC <<endl; cout << "SC2: " << SC2 << endl; SimplicialComplex I=intersectSC(SC,SC2); cout << "SC intersection SC2 :" << I << endl; //----------------------------------------- cout << "------ anticycle ideals ------" << endl << endl; // SparsePolyRing S=NewPolyRing(myQQ,8); // ideal I=antiCycleIdeal(NumIndets(S),S); ideal AC=antiCycleIdeal(NumIndets(R),R); cout <<"anty-cycle of length :" << NumIndets(R) << endl << AC << endl; //--------------------------------------------------------- cout << endl << "------ polarization of ideals ------" << endl << endl; ideal AC2=AC*AC; // cout << AC2 << endl; SparsePolyRing S=NewPolyRing(myQQ,4); ideal AC4=antiCycleIdeal(NumIndets(R)-1,R); // cout << AC4 << endl; ideal J=AC2*AC4; cout << J << endl; cout << endl << "polarized ideal :" << endl << polarization(J) << endl; //------------------------------------------------------- cout << endl << "------ ADPAC ------" << endl << endl; //ideal JJ=ADPAC(6,3); SimplicialComplex Delta=ADPAC(5,3); cout << Delta << endl; // cout << ADPAC(6,3) << endl; //-------------------------------------------- // ideal SRI(NSC.myStanleyReisnerIdeal()); //cout << "ideal: "<< SRI << endl; // cout << "------iterators------" << endl; // for (PolyList::const_iterator k=NL.begin(); k!=NL.end(); ++k) // { // for(PolyList::const_iterator j=k; j!=NL.end(); ++j) // { // std::cout<< *j <<endl; // } // } // cout << "------lists------" << endl; // std::list<face> LL; // LL=SC.myFacetList(); // cout << "L1: " << LL << endl; // SimplicialComplexConstIter it1=LL.begin(); //it1=LL.remove(it1); //cout << "L1: " << LL << endl; //cout << "*it1: " << *it1 << endl; //--it1; //++it1; //cout << "*it1: " << *it1 << endl; // f=f & f2; // cout << "f: " << f << endl; // cout << "count f: " << count(f) << endl; // std::list<face> L1,L2; // L1=SC.myFacetList(); // SimplicialComplexConstIter it1=L1.begin(); // L2=SC2.myFacetList(); // SimplicialComplexConstIter it2=L2.begin(); // cout << IsSubset(*it1,*it2) << endl; // cout << len(*it1) << endl; // cout << len(*it2) << endl; // bool menor; // menor=*it1 < *it1; // cout << "is <: " << menor << endl; // SC.myUnion(SC2); //SC.mySort(); //cout << "SC union SC2 sorted:" << SC <<endl; }
void Render(Image &dest) const { dest.Clear(); for (PolyList::const_iterator it = poly_.begin(); it != poly_.end(); ++it) it->Render(dest); }
bool ITR3DMImport::findColinear(const Point3F& v1,const Point3F& v2, Poly* spoly,PolyList& polyList,ColinearList* colinearList) { colinearList->clear(); Point3F vec1 = v2; vec1 -= v1; float len = vec1.len(); if (!len || len < distancePrecision) return false; float timeScale = 1.0f / len; vec1 *= timeScale; float maxDistance = len - distancePrecision; float dist2Precision = distancePrecision * distancePrecision; for (PolyList::iterator ptr = polyList.begin(); ptr != polyList.end(); ptr++) { Poly* poly = *ptr; if (poly == spoly) continue; for (Poly::VertexList::iterator itr = poly->vertexList.begin(); itr != poly->vertexList.end(); itr++) { if ((*itr).colinear) // Skip points that were inserted, we should end up testing // the original point. continue; // Is it within the bounds of the line seg? Point3F vec2,&v3 = (*itr).point; vec2.x = v3.x - v1.x; vec2.y = v3.y - v1.y; vec2.z = v3.z - v1.z; float d = m_dot(vec1,vec2); if (d > distancePrecision && d < maxDistance) { // Now lets see if it's on the line Point3F dp; dp.x = v3.x - (v1.x + vec1.x * d); dp.y = v3.y - (v1.y + vec1.y * d); dp.z = v3.z - (v1.z + vec1.z * d); float dist2 = dp.x * dp.x + dp.y * dp.y + dp.z * dp.z; if (dist2 < dist2Precision) { // Sanity check here, make sure the point is // on the plane. if (spoly->plane.whichSide((*itr).point) == TPlaneF::OnPlane) { colinearList->increment(); colinearList->last().time = d * timeScale; colinearList->last().point = (*itr).point; } } } } } // Sort by increasing time value. float precision = distancePrecision / len; if (colinearList->size()) { qsort(colinearList->address(),colinearList->size(),sizeof(Colinear), Colinear::compare); // Remove duplicates for (int i = 1; i < colinearList->size(); i++) { float delta = (*colinearList)[i].time - (*colinearList)[i-1].time; if (fabs(delta) < precision) colinearList->erase(i--); } return true; } return false; }
void ITR3DMImport::exportToGeometry(PolyList& polyList, ITRGeometry* geometry, Vector<UInt32>* volumeMasks) { AssertFatal(polyList.size() < ITRGeometry::MaxIndex, "ITR3DMImport:export: Too many polygons"); geometry->surfaceList.reserve(polyList.size()); for (int i = 0; i < polyList.size(); i++) { Poly* poly = polyList[i]; ITRBitVector bv; // Build surface geometry->surfaceList.push_back(ITRGeometry::Surface()); ITRGeometry::Surface& surface = geometry->surfaceList.last(); surface.type = ITRGeometry::Surface::Material; surface.material = (poly->material == -1)? ITRGeometry::Surface::NullMaterial: poly->material; surface.textureOffset.x = poly->textureOffset.x; surface.textureOffset.y = poly->textureOffset.y; surface.textureScaleShift = ( poly->textureScaleShift & ( ( 1 << ITRGeometry::Surface::textureScaleBits ) - 1 ) ); surface.applyAmbient = poly->applyAmbient; // Default is _not_ visible to the outside... surface.visibleToOutside = 0; volumeMasks->push_back(poly->volumeMask); // Size is 1->256 stored in UInt8 Point2I pSize; pSize.x = poly->textureSize.x >> maxMipLevel; pSize.y = poly->textureSize.y >> maxMipLevel; surface.textureSize.x = (pSize.x == 0)? 1: pSize.x - 1; surface.textureSize.y = (pSize.y == 0)? 1: pSize.y - 1; // Build poly AssertFatal(poly->vertexList.size() < 256, "ITR3DMImport::export: Vertex count on poly too large") surface.vertexCount = poly->vertexList.size(); surface.vertexIndex = geometry->vertexList.size(); geometry->vertexList.setSize(geometry->vertexList.size() + surface.vertexCount); ITRGeometry::Vertex* vp = &geometry->vertexList[surface.vertexIndex]; for (int i = 0; i < surface.vertexCount; i++) { vp[i].pointIndex = geometry->point3List.add(poly->vertexList[i].point); AssertFatal(geometry->point3List.size() < ITRGeometry::MaxIndex, "ITR3DMImport:export: Too many poly vertices"); // Texture coordinates normalized to texture size Point2F tx = poly->vertexList[i].texture; tx.x *= (1.0 / poly->textureSize.x); tx.y *= (1.0 / poly->textureSize.y); // Make sure it's not out of bounds (Zed bug?). bool clamp = false; if (tx.x < 0.0f) tx.x = 0.0f, clamp = true; if (tx.x > 1.0f) tx.x = 1.0f, clamp = true; if (tx.y < 0.0f) tx.y = 0.0f, clamp = true; if (tx.y > 1.0f) tx.y = 1.0f, clamp = true; if (clamp) printf(" Warning: Texture coordinate clamped\n"); // vp[i].textureIndex = geometry->point2List.add(tx); AssertFatal(geometry->point2List.size() < ITRGeometry::MaxIndex, "ITR3DMImport:export: Too many texture vertices"); bv.set(vp[i].pointIndex); } // Add plane to list. ITRVector<TPlaneF>::iterator itr = ::find(geometry->planeList.begin(),geometry->planeList.end(), poly->plane); if (itr == geometry->planeList.end()) { // Try too match inverted plane. poly->plane.neg(); itr = ::find(geometry->planeList.begin(), geometry->planeList.end(),poly->plane); if (itr == geometry->planeList.end()) { // No inverted either, so add original plane // to the list. surface.planeIndex = geometry->planeList.size(); surface.planeFront = true; poly->plane.neg(); geometry->planeList.push_back(poly->plane); } else { surface.planeIndex = itr - geometry->planeList.begin(); surface.planeFront = false; } } else { surface.planeIndex = itr - geometry->planeList.begin(); surface.planeFront = true; } // Build bitvec of points used by the surface surface.pointIndex = geometry->bitList.size(); int pcount = bv.compress(&geometry->bitList); AssertFatal(pcount < 256, "ITR3DMImport::export: Point bitvector too large"); surface.pointCount = pcount; } }
DnaDrawing() { for (int i = 0; i < Settings::MinPolygons; ++i) poly_.push_back(DnaPolygon()); }
void ITR3DMImport::sortByMaterial(PolyList& polyList) { qsort(polyList.address(), polyList.size(), sizeof(PolyList::value_type), materialCmp); }