Beispiel #1
0
PtexWriter* PtexWriter::edit(const char* path, bool incremental,
			     Ptex::MeshType mt, Ptex::DataType dt,
			     int nchannels, int alphachan, int nfaces,
			     Ptex::String& error, bool genmipmaps)
{
    if (!checkFormat(mt, dt, nchannels, alphachan, error))
	return 0;

    // try to open existing file (it might not exist)
    FILE* fp = fopen(path, "rb+");
    if (!fp && errno != ENOENT) {
	error = fileError("Can't open ptex file for update: ", path).c_str();
    }

    PtexWriterBase* w = 0;
    // use incremental writer iff incremental mode requested and file exists
    if (incremental && fp) {
	w = new PtexIncrWriter(path, fp, mt, dt, nchannels, alphachan, nfaces);
    }
    // otherwise use main writer
    else {
	PtexTexture* tex = 0;
	if (fp) {
	    // got an existing file, close and reopen with PtexReader
	    fclose(fp);

	    // open reader for existing file
	    tex = PtexTexture::open(path, error);
	    if (!tex) return 0;

	    // make sure header matches
	    bool headerMatch = (mt == tex->meshType() &&
				dt == tex->dataType() &&
				nchannels == tex->numChannels() &&
				alphachan == tex->alphaChannel() &&
				nfaces == tex->numFaces());
	    if (!headerMatch) {
		std::stringstream str;
		str << "PtexWriter::edit error: header doesn't match existing file, "
		    << "conversions not currently supported";
		error = str.str().c_str();
		return 0;
	    }
	}
	w = new PtexMainWriter(path, tex, mt, dt, nchannels, alphachan,
			       nfaces, genmipmaps);
    }

    if (!w->ok(error)) {
	w->release();
	return 0;
    }
    return w;
}
Beispiel #2
0
bool PtexWriter::applyEdits(const char* path, Ptex::String& error)
{
    // open reader for existing file
    PtexTexture* tex = PtexTexture::open(path, error);
    if (!tex) return 0;

    // see if we have any edits to apply
    if (tex->hasEdits()) {
	// create non-incremental writer
	PtexWriter* w = new PtexMainWriter(path, tex, tex->meshType(), tex->dataType(),
					   tex->numChannels(), tex->alphaChannel(), tex->numFaces(),
					   tex->hasMipMaps());
	// close to rebuild file
	if (!w->close(error)) return 0;
	w->release();
    }
    return 1;
}