// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. // PT: this file is a loader for "raw" binary files. It should NOT create SDK objects directly. #include #include "foundation/PxPreprocessor.h" #include "RawLoader.h" #include "RendererColor.h" #include "RendererMemoryMacros.h" #include "SampleAllocatorSDKClasses.h" #include "PxTkFile.h" using namespace SampleRenderer; RAWObject::RAWObject() : mName(NULL) { mTransform = PxTransform(PxIdentity); } RAWTexture::RAWTexture() : mID (0xffffffff), mWidth (0), mHeight (0), mHasAlpha (false), mPixels (NULL) { } RAWMesh::RAWMesh() : mNbVerts (0), mNbFaces (0), mMaterialID (0xffffffff), mVerts (NULL), mVertexNormals (NULL), mVertexColors (NULL), mUVs (NULL), mIndices (NULL) { } RAWShape::RAWShape() : mNbVerts (0), mVerts (NULL) { } RAWHelper::RAWHelper() { } RAWMaterial::RAWMaterial() : mID (0xffffffff), mDiffuseID (0xffffffff), mOpacity (1.0f), mDoubleSided (false) { mAmbientColor = PxVec3(0); mDiffuseColor = PxVec3(0); mSpecularColor = PxVec3(0); } #if PX_INTEL_FAMILY static const bool gFlip = false; #elif PX_PPC static const bool gFlip = true; #elif PX_ARM_FAMILY static const bool gFlip = false; #else #error Unknown platform! #endif PX_INLINE void Flip(PxU32& v) { PxU8* b = (PxU8*)&v; PxU8 temp = b[0]; b[0] = b[3]; b[3] = temp; temp = b[1]; b[1] = b[2]; b[2] = temp; } PX_INLINE void Flip(PxI32& v) { Flip((PxU32&)v); } PX_INLINE void Flip(PxF32& v) { Flip((PxU32&)v); } static PxU8 read8(File* fp) { PxU8 data; size_t numRead = fread(&data, 1, 1, fp); if(numRead != 1) { return 0; } return data; } static PxU32 read32(File* fp) { PxU32 data; size_t numRead = fread(&data, 1, 4, fp); if(numRead != 4) { return 0; } if(gFlip) Flip(data); return data; } static PxF32 readFloat(File* fp) { PxF32 data; size_t numRead = fread(&data, 1, 4, fp); if(numRead != 4) { return 0; } if(gFlip) Flip(data); return data; } static PxTransform readTransform(File* fp, PxReal scale) { PxTransform tr; tr.p.x = scale * readFloat(fp); tr.p.y = scale * readFloat(fp); tr.p.z = scale * readFloat(fp); tr.q.x = readFloat(fp); tr.q.y = readFloat(fp); tr.q.z = readFloat(fp); tr.q.w = readFloat(fp); PX_ASSERT(tr.isValid()); return tr; } static void readVertexArray(File* fp, PxVec3* verts, PxU32 nbVerts) { const size_t size = 4*3*nbVerts; size_t numRead = fread(verts, 1, size, fp); if(numRead != size) { return; } if(gFlip) { for(PxU32 j=0;j