MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / writePRT

Function writePRT

extern/partio/src/lib/io/PRT.cpp:347–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347bool writePRT(const char* filename,const ParticlesData& p,const bool /*compressed*/,std::ostream* errorStream)
348{
349 /// Krakatoa pukes on 0 particle files for some reason so don't export at all....
350 int numParts = p.numParticles();
351 if (numParts)
352 {
353 std::unique_ptr<std::ostream> output(
354 new std::ofstream(filename,std::ios::out|std::ios::binary));
355
356 if (!*output) {
357 if(errorStream) *errorStream <<"Partio Unable to open file "<<filename<<std::endl;
358 return false;
359 }
360
361 FileHeadder header;
362 memcpy(header.magic, magic, sizeof(magic));
363 memcpy(header.signature, signature, sizeof(signature));
364 header.headersize = 0x38;
365 header.version = 1;
366 header.numParticles = p.numParticles();
367 int reserve = 4;
368 output->write((char*)&header,sizeof(FileHeadder));
369 write<LITEND>(*output, reserve);
370 write<LITEND>(*output, (int)p.numAttributes());
371 reserve = 0x2c;
372 write<LITEND>(*output, reserve);
373
374 std::vector<ParticleAttribute> attrs;
375 int offset = 0;
376 for (int i=0;i<p.numAttributes();i++) {
377 ParticleAttribute attr;
378 p.attributeInfo(i,attr);
379 Channel ch;
380 memset(&ch, 0, sizeof(Channel));
381 memcpy((char*)ch.name, attr.name.c_str(), attr.name.size());
382 ch.offset = offset;
383 switch (attr.type) {
384 case FLOAT: ch.type=4; ch.arity=attr.count; offset += sizeof(float)*attr.count; break;
385 case INT: ch.type=1; ch.arity=attr.count; offset += sizeof(int)*attr.count; break;
386 case VECTOR: ch.type=4; ch.arity=attr.count; offset += sizeof(float)*attr.count; break;
387 case INDEXEDSTR:; break;
388 case NONE:;break;
389 }
390 if (ch.arity) {
391 #ifdef AUTO_CASES
392 if (ch.name[0] >= 'a' && ch.name[0] <= 'z') {
393 ch.name[0] -= 0x20;
394 }
395 #endif
396 output->write((char*)&ch,sizeof(Channel));
397 attrs.push_back(attr);
398 }
399 }
400
401 z_stream z;
402 z.zalloc = Z_NULL;z.zfree = Z_NULL;z.opaque = Z_NULL;
403 if (deflateInit( &z, Z_DEFAULT_COMPRESSION ) != Z_OK) {
404 if(errorStream) *errorStream<<"Zlib deflateInit error"<<std::endl;

Callers

nothing calls this directly

Calls 7

write_bufferFunction · 0.85
deflateEndFunction · 0.85
numParticlesMethod · 0.80
writeMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected