📄 icezcbbreaker.cpp
字号:
ZCBTextureInfo::~ZCBTextureInfo()
{
DELETEARRAY(mBitmap);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBNativeMeshInfo::ZCBNativeMeshInfo()
{
mNbFaces = 0;
mNbVerts = 0;
mNbTVerts = 0;
mNbCVerts = 0;
mFlags = 0;
mFaces = null;
mTFaces = null;
mCFaces = null;
mFaceProperties = null;
mVerts = null;
mTVerts = null;
mCVerts = null;
mVertexAlpha = null;
mParity = false;
mBonesNb = null;
mBonesID = null;
mOffsetVectors = null;
mWeights = null;
mSkeleton = null;
mNbBones = 0;
mNbHullVerts = 0;
mNbHullFaces = 0;
mHullVerts = null;
mHullFaces = null;
mBSCenter.Zero();
mBSRadius = 0.0f;
mCOM.Zero();
mComputedMass = 0.0f;
ZeroMemory(mInertiaTensor, 9*sizeof(float));
ZeroMemory(mCOMInertiaTensor, 9*sizeof(float));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBNativeMeshInfo::~ZCBNativeMeshInfo()
{
DELETEARRAY(mHullFaces);
DELETEARRAY(mHullVerts);
DELETEARRAY(mSkeleton);
DELETEARRAY(mWeights);
DELETEARRAY(mOffsetVectors);
DELETEARRAY(mBonesID);
DELETEARRAY(mBonesNb);
DELETEARRAY(mFaces);
DELETEARRAY(mTFaces);
DELETEARRAY(mCFaces);
DELETEARRAY(mFaceProperties);
DELETEARRAY(mVerts);
DELETEARRAY(mTVerts);
DELETEARRAY(mCVerts);
DELETEARRAY(mVertexAlpha);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBMeshInfo::ZCBMeshInfo()
{
mIsCollapsed = false;
mIsSkeleton = false;
mIsInstance = false;
mIsTarget = false;
mIsConvertible = false;
mIsSkin = false;
mCastShadows = false;
mReceiveShadows = false;
mMotionBlur = false;
mCharID = INVALID_ID;
mCSID = INVALID_ID;
mCleanMesh = null;
mNbColors = 0;
mColors = null;
mPrimParams = null;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBMeshInfo::~ZCBMeshInfo()
{
DELETESINGLE(mPrimParams);
DELETESINGLE(mCleanMesh);
DELETEARRAY(mColors);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBShapeInfo::ZCBShapeInfo() : mType(ZCB_SHAP_UNDEFINED), mNbLines(0), mNbVerts(null), mClosed(null), mVerts(null), mTotalNbVerts(0), mMatID(INVALID_ID)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBShapeInfo::~ZCBShapeInfo()
{
DELETEARRAY(mVerts);
DELETEARRAY(mClosed);
DELETEARRAY(mNbVerts);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBHelperInfo::ZCBHelperInfo() : mIsGroupHead(false)
{
mHelperType = ZCB_HELPER_DUMMY;
mIsGroupHead = false;
mLength = 0.0f;
mWidth = 0.0f;
mHeight = 0.0f;
mRadius = 0.0f;
mHemi = false;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBHelperInfo::~ZCBHelperInfo()
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBControllerInfo::ZCBControllerInfo()
{
mObjectID = INVALID_ID;
mOwnerID = INVALID_ID;
mOwnerType = ZCB_OBJ_UNDEFINED;
mCtrlType = ZCB_CTRL_NONE;
mCtrlMode = ZCB_CTRL_SAMPLES;
mNbSamples = 0;
mSamplingRate = 0;
mSamples = null;
mNbVertices = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBControllerInfo::~ZCBControllerInfo()
{
DELETEARRAY(mSamples);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Constructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBBreaker::ZCBBreaker() : mFileType(ZCB_FILE_FORCE_DWORD), mImportArray(null), mZCBGlobalVersion(0)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Destructor.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ZCBBreaker::~ZCBBreaker()
{
ReleaseRam();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Frees used memory.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ZCBBreaker::ReleaseRam()
{
DELETESINGLE(mImportArray);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Imports a ZCB scene.
* \param filename [in] the scene's filename
* \return true if success.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ZCBBreaker::Import(const String& filename)
{
// Find the file somewhere in registered paths
String FoundFile;
// Check the file exists
if(!FindFile(filename, &FoundFile))
{
ZCBImportError("File not found.", ZCB_ERROR_FILE_NOT_FOUND);
return false;
}
// Release possibly already existing array
DELETESINGLE(mImportArray);
// Create a new array
mImportArray = new CustomArray(FoundFile);
ZCB_CHECKALLOC(mImportArray);
// Parse the array
return Import();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Imports a ZCB scene.
* \return true if success.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool ZCBBreaker::Import()
{
// Check format signature
ubyte b1 = mImportArray->GetByte();
ubyte b2 = mImportArray->GetByte();
ubyte b3 = mImportArray->GetByte();
// The three first bytes must be "ZCB"
if(b1!='Z' || b2!='C' || b3!='B')
{
ZCBImportError("Invalid ZCB file.", ZCB_ERROR_INVALID_FILE);
return false;
}
// The fourth byte can be '!' for normal files and 'P' for packed files.
ubyte b4 = mImportArray->GetByte();
if(b4=='P')
{
// This is a packed ZCB file. ZCB files are packed with ZLib or BZip2 only, so that anyone can read them back.
udword Compression = mImportArray->GetDword(); // Compression scheme
udword OriginalSize = mImportArray->GetDword(); // Size of the forthcoming depacked buffer
udword PackedSize = mImportArray->GetDword(); // Size of the packed buffer
// Get some bytes for the depacked buffer
ubyte* Depacked = new ubyte[OriginalSize];
ZCB_CHECKALLOC(Depacked);
if(Compression==ZCB_COMPRESSION_ZLIB)
{
#ifdef __FLEXINESDK_H__
if(!Decompress(Depacked, OriginalSize, mImportArray->GetAddress(), PackedSize, "ZLIB")) return false;
#else
#ifdef _ZLIB_H
// Use ZLib to depack the file
int ErrorCode = uncompress((Bytef*)Depacked, (uLongf*)&OriginalSize, (Bytef*)mImportArray->GetAddress(), PackedSize);
if(ErrorCode!=Z_OK)
{
ZCBImportError("Depacking failed.", ZCB_ERROR_CANT_DEPACK);
return false;
}
#else
ZCBImportError("ZLIB depacking not available.", ZCB_ERROR_CANT_DEPACK);
return false;
#endif
#endif
}
else if(Compression==ZCB_COMPRESSION_BZIP2)
{
#ifdef __FLEXINESDK_H__
if(!Decompress(Depacked, OriginalSize, mImportArray->GetAddress(), PackedSize, "BZIP2")) return false;
#else
#ifdef _BZLIB_H
// Use BZip2 to depack the file
int ErrorCode = BZ2_bzBuffToBuffDecompress((char*)Depacked, &OriginalSize, (char*)mImportArray->GetAddress(), PackedSize, 0, 0);
if(ErrorCode!=BZ_OK)
{
ZCBImportError("Depacking failed.", ZCB_ERROR_CANT_DEPACK);
return false;
}
#else
ZCBImportError("BZIP2 depacking not available.", ZCB_ERROR_CANT_DEPACK);
return false;
#endif
#endif
}
else
{
ZCBImportError("Depacking failed.", ZCB_ERROR_CANT_DEPACK);
return false;
}
// Release packed buffer
DELETESINGLE(mImportArray);
// Create a new array filled with depacked data
mImportArray = new CustomArray(OriginalSize, Depacked);
ZCB_CHECKALLOC(mImportArray);
mImportArray->Reset();
// Release depacked buffer
DELETEARRAY(Depacked);
// And wrap it up
return Import();
}
else if(b4=='!')
{
// This is a valid ZCB file. Get the type.
udword Data = mImportArray->GetDword();
// Since 1.14 we need to mask out reserved bits & get back the global version
mZCBGlobalVersion = Data>>16;
mFileType = ZCBFile(Data & ZCB_FILE_MASK);
gZCBVersion = mZCBGlobalVersion;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -