Maya Exporter

Vlado,

I’m trying to improve my .vrscene scripts. If you cant share the Maya exporter, can you help me with the ListHex types? Everything made sense until I started looking at the some of the examples and saw “ZIPB8” and “ZIPB4” with some weird values after that which are out of the Hex (0-F) range. I’m assuming this is some kind of Hex compression that Vray understands, but I couldnt find any information on how to use it.

Yes, I’m trying to shrink the size of my .vrscene files. (LOL)

-GB-

Here is the code for producing the zipped strings (the compress() function is from the zlib library):

ErrorCode getStringZip(const uint8 *buf, unsigned bufLen, CharString &str) {
	// First compress the data into a temporary buffer
	uLongf tempLen=bufLen+bufLen/10+12;
	PtrArray<char> temp(tempLen);
	int res=compress((Bytef*) temp.get(), &tempLen, (Bytef*) buf, bufLen);

	if (res==Z_MEM_ERROR) return ErrorCode(__FUNCTION__, -1, "Zlib: not enough memory to compress buffer");
	if (res==Z_BUF_ERROR) return ErrorCode(__FUNCTION__, -2, "Zlib: not enough room in output buffer");

	// Convert the zipped buffer into an ASCII string
	unsigned offset=4+8+8;
	unsigned strLen=(tempLen/2+1)*3+offset;
	str.setLength(strLen);

	tchar *pstr=str.write_ptr();
	ErrorCode res1=hex2str((uint8*) temp.get(), tempLen, &pstr[offset], strLen-offset);
	if (res1.error()) return ErrorCode(res1, __FUNCTION__, -3, "Cannot convert to ASCII string");

	// Add the Zip header
	pstr[0]='Z'; pstr[1]='I'; pstr[2]='P'; pstr[3]='B';

	int2hex(bufLen, &pstr[4]);
	int2hex(tempLen, &pstr[8+4]);

	return ErrorCode();
}

inline void word2str(uint16 w, char *str) {
	int d0=w%41;
	w/=41;
	int d1=w%41;
	w/=41;
	int d2=w%41;
	*str=letr2char(d0);
	str++;
	*str=letr2char(d1);
	str++;
	*str=letr2char(d2);
}

ErrorCode VUtils::hex2str(const uint8 *bytes, unsigned numBytes, char *str, unsigned strMaxLen) {
	if (strMaxLen<numBytes*2/3+1) return ErrorCode(__FUNCTION__, -1, "Buffer too small");

	for (unsigned i=0; i<numBytes/2; i++) {
		word2str(*((uint16*) (bytes+i*2)), str);
		str+=3;
	}
	if (numBytes&1) {
		uint8 b[2]={ bytes[numBytes-1], 0 };
		word2str(*((uint16*) b), str);
		str+=3;
	}
	*str=0;

	return ErrorCode();
}

char int2hexValue(char d) {
	return d<=9? '0'+d : (d-10+'A');
}

void int2hex(uint32 i, char *hex) {
	uint8 f[4];
	*((uint32*)&f)=i;
	for (int i=0; i<4; i++) {
		char val0=int2hexValue((f[i]>>4)&0xF);
		char val1=int2hexValue((f[i])&0xF);
		hex[i*2+0]=val0;
		hex[i*2+1]=val1;
	}
}

Best regards,
Vlado