// This code contains NVIDIA Confidential Information and is disclosed to you // under a form of NVIDIA software license agreement provided separately to you. // // Notice // NVIDIA Corporation and its licensors retain all intellectual property and // proprietary rights in and to this software and related documentation and // any modifications thereto. Any use, reproduction, disclosure, or // distribution of this software and related documentation without an express // license agreement from NVIDIA Corporation is strictly prohibited. // // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. // // Information and code furnished is believed to be accurate and reliable. // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such // information or for any infringement of patents or other rights of third parties that may // result from its use. No license is granted by implication or otherwise under any patent // or patent rights of NVIDIA Corporation. Details are subject to change without notice. // This code supersedes and replaces all information previously supplied. // NVIDIA Corporation products are not authorized for use as critical // components in life support devices or systems without express written approval of // NVIDIA Corporation. // // Copyright (c) 2008-2017 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