char HTriangleMesh::save(ATriangleMesh * tri) { int nv = tri->numPoints(); if(!hasNamedAttr(".nv")) addIntAttr(".nv"); writeIntAttr(".nv", &nv); int nt = tri->numTriangles(); if(!hasNamedAttr(".ntri")) addIntAttr(".ntri"); writeIntAttr(".ntri", &nt); if(!hasNamedData(".p")) addVector3Data(".p", nv); writeVector3Data(".p", nv, (Vector3F *)tri->points()); if(!hasNamedData(".a")) addIntData(".a", nv); writeIntData(".a", nv, (int *)tri->anchors()); if(!hasNamedData(".v")) addIntData(".v", nt * 3); writeIntData(".v", nt * 3, (int *)tri->indices()); return 1; }
char HPolygonalUV::save(APolygonalUV * poly) { int nuv = poly->numCoords(); if(!hasNamedAttr(".nuv")) addIntAttr(".nuv"); writeIntAttr(".nuv", &nuv); int nind = poly->numIndices(); if(!hasNamedAttr(".nind")) addIntAttr(".nind"); writeIntAttr(".nind", &nind); if(!hasNamedData(".ucoord")) addFloatData(".ucoord", nuv); writeFloatData(".ucoord", nuv, (float *)poly->ucoord()); if(!hasNamedData(".vcoord")) addFloatData(".vcoord", nuv); writeFloatData(".vcoord", nuv, (float *)poly->vcoord()); if(!hasNamedData(".uvid")) addIntData(".uvid", nind); writeIntData(".uvid", nind, (int *)poly->indices()); return 1; }
char HBaseNTree::verifyType() { if(!hasNamedAttr(".nrope") ) return 0; if(!hasNamedData(".rope") ) return 0; if(!hasNamedAttr(".nind") ) return 0; if(!hasNamedData(".ind") ) return 0; if(!hasNamedAttr(".nleaf") ) return 0; if(!hasNamedData(".leaf") ) return 0; if(!hasNamedAttr(".nnode") ) return 0; if(!hasNamedData(".node") ) return 0; if(!hasNamedAttr(".bbx") ) return 0; return 1; }
char HNumericBundle::save(const ABundleAttribute * d) { if(!hasNamedAttr(".longname")) addStringAttr(".longname", d->longName().size()); writeStringAttr(".longname", d->longName()); int sz = d->size(); if(!hasNamedAttr(".bundle_sz")) addIntAttr(".bundle_sz"); writeIntAttr(".bundle_sz", &sz); int nt = d->numericType(); if(!hasNamedAttr(".bundle_num_typ")) addIntAttr(".bundle_num_typ"); writeIntAttr(".bundle_num_typ", &nt); int l = d->dataLength(); if(!hasNamedData(".raw")) addCharData(".raw", l); writeCharData(".raw", l, (char *)d->value()); return 1; }
char HMesh::saveFaceTag(BaseMesh * mesh, const std::string & tagName, const std::string & dataName) { if(!hasNamedData(dataName.c_str())) addCharData(dataName.c_str(), mesh->getNumFaces()); std::cout<<"write face tag"<<tagName; writeCharData(dataName.c_str(), mesh->getNumFaces(), mesh->perFaceTag(tagName)); return 1; }
char HTriangleMeshGroup::save(ATriangleMeshGroup * tri) { if(!hasNamedAttr(".npart")) addIntAttr(".npart"); int np = tri->numStripes(); writeIntAttr(".npart", &np); if(!hasNamedData(".pntdrift")) addIntData(".pntdrift", np); writeIntData(".pntdrift", np, (int *)tri->pointDrifts()); if(!hasNamedData(".inddrift")) addIntData(".inddrift", np); writeIntData(".inddrift", np, (int *)tri->indexDrifts()); return HTriangleMesh::save(tri); }
char HMesh::loadFaceTag(BaseMesh * mesh, const std::string & tagName, const std::string & dataName) { char * g = mesh->perFaceTag(tagName); if(hasNamedData(dataName.c_str())) { readCharData(dataName.c_str(), mesh->getNumFaces(), g); } else { std::cout<<"WARNING: reset face tag "<<tagName; for(unsigned i =0; i < mesh->getNumFaces(); i++) g[i] = 1; } return 1; }
void HAnimationCurve::saveKeys(AAnimationCurve * curve, int n) { if(n<1) return; AAnimationKey * data = new AAnimationKey[n]; int i = 0; for(;i<n;i++) data[i] = curve->key(i); if(!hasNamedData(".key_data")) addCharData(".key_data", n * sizeof(AAnimationKey)); writeCharData(".key_data", n * sizeof(AAnimationKey), (char *)data); delete[] data; }
char HAdaptiveField::save(AdaptiveField * fld) { int nc = fld->numCells(); std::cout<<"\n hadaptivefield save n cells "<<nc; if(!hasNamedAttr(".ncells")) addIntAttr(".ncells"); writeIntAttr(".ncells", &nc); if(!hasNamedAttr(".origin_span")) addFloatAttr(".origin_span", 4); float originSpan[4]; originSpan[0] = fld->origin().x; originSpan[1] = fld->origin().y; originSpan[2] = fld->origin().z; originSpan[3] = fld->span(); writeFloatAttr(".origin_span", originSpan); if(!hasNamedAttr(".max_level")) addIntAttr(".max_level"); int ml = fld->maxLevel(); writeIntAttr(".max_level", &ml); BaseBuffer dhash; dhash.create(nc * 16); IOCellHash * dst = (IOCellHash *)dhash.data(); sdb::CellHash * c = fld->cells(); c->begin(); while(!c->end()) { dst->code = c->key(); dst->level = c->value()->level; dst->visited = c->value()->visited; dst->index = c->value()->index; dst++; c->next(); } if(!hasNamedData(".cellHash")) addCharData(".cellHash", nc*16); writeCharData(".cellHash", nc*16, dhash.data()); return HField::save(fld); }
char HMesh::save(BaseMesh * mesh) { mesh->verbose(); int nv = mesh->getNumVertices(); if(!hasNamedAttr(".nv")) addIntAttr(".nv"); writeIntAttr(".nv", &nv); int nf = mesh->getNumPolygons(); if(!hasNamedAttr(".nf")) addIntAttr(".nf"); writeIntAttr(".nf", &nf); int nfv = mesh->getNumPolygonFaceVertices(); if(!hasNamedAttr(".nfv")) addIntAttr(".nfv"); writeIntAttr(".nfv", &nfv); int nuv = mesh->getNumUVs(); if(!hasNamedAttr(".nuv")) addIntAttr(".nuv"); writeIntAttr(".nuv", &nuv); int nuvid = mesh->getNumUVIds(); if(!hasNamedAttr(".nuvid")) addIntAttr(".nuvid"); writeIntAttr(".nuvid", &nuvid); if(!hasNamedData(".p")) addVector3Data(".p", nv); writeVector3Data(".p", nv, mesh->getVertices()); if(!hasNamedData(".polyc")) addIntData(".polyc", nf); writeIntData(".polyc", nf, (int *)mesh->getPolygonCounts()); if(!hasNamedData(".polyv")) addIntData(".polyv", nfv); std::cout<<" polyv[0]"<<mesh->getPolygonIndices()[0]<<"\n"; std::cout<<" polyv["<<nfv<<"-1]"<<mesh->getPolygonIndices()[nfv - 1]<<"\n"; writeIntData(".polyv", nfv, (int *)mesh->getPolygonIndices()); if(!hasNamedData(".us")) addFloatData(".us", nuv); writeFloatData(".us", nuv, mesh->getUs()); if(!hasNamedData(".vs")) addFloatData(".vs", nuv); writeFloatData(".vs", nuv, mesh->getVs()); if(!hasNamedData(".uvids")) addIntData(".uvids", nuvid); writeIntData(".uvids", nuvid, (int *)mesh->getUvIds()); return 1; }