8#include <QtQml/QQmlFile>
9#include <extensions/PxExtensionsAPI.h>
39 physx::PxTriangleMesh *&triangleMesh, physx::PxConvexMesh *&convexMesh,
46 QFile cacheFile(cacheFilename);
47 QFile meshFile(meshFilename);
48 uchar *cacheData =
nullptr;
49 uchar *meshData =
nullptr;
53 cacheFile.unmap(cacheData);
55 meshFile.unmap(meshData);
56 if (cacheFile.isOpen())
58 if (meshFile.isOpen())
66 qWarning() <<
"Could not open" << meshFilename;
71 if (cacheFile.size() <=
qint64(
sizeof(uint64_t))) {
72 qWarning() <<
"Invalid convex mesh from file" << cacheFilename;
76 cacheData = cacheFile.map(0, cacheFile.size());
78 qWarning() <<
"Could not map" << cacheFilename;
81 uint64_t cacheHash = *
reinterpret_cast<uint64_t *
>(cacheData);
83 meshData = meshFile.map(0, meshFile.size());
85 qWarning() <<
"Could not map" << meshFilename;
90 if (cacheHash != meshHash)
93 physx::PxDefaultMemoryInputData
input(cacheData +
sizeof(uint64_t),
94 physx::PxU32(cacheFile.size() -
sizeof(uint64_t)));
98 triangleMesh = physics.createTriangleMesh(
input);
99 qCDebug(lcQuick3dPhysics) <<
"Read triangle mesh" << triangleMesh <<
"from file"
104 convexMesh = physics.createConvexMesh(
input);
105 qCDebug(lcQuick3dPhysics) <<
"Read convex mesh" << convexMesh <<
"from file"
110 heightField = physics.createHeightField(
input);
111 qCDebug(lcQuick3dPhysics) <<
"Read height field" << heightField <<
"from file"
124 QFile cacheFile(cacheFilename);
125 QFile meshFile(meshFilename);
126 uchar *cacheData =
nullptr;
127 uchar *meshData =
nullptr;
131 cacheFile.unmap(cacheData);
133 meshFile.unmap(meshData);
134 if (cacheFile.isOpen())
136 if (meshFile.isOpen())
141 qCWarning(lcQuick3dPhysics) <<
"Could not open" << cacheFile.fileName() <<
"for writing.";
145 qWarning() <<
"Could not open" << meshFilename;
149 meshData = meshFile.map(0, meshFile.size());
151 qWarning() <<
"Could not map" << meshFilename;
156 cacheFile.write(
reinterpret_cast<char *
>(&meshHash),
sizeof(uint64_t));
157 cacheFile.write(
reinterpret_cast<char *
>(
buf.getData()),
buf.getSize());
160 qCDebug(lcQuick3dPhysics) <<
"Wrote" << cacheFile.size() <<
"bytes to" << cacheFile.fileName();
179 physx::PxTriangleMesh *&triangleMesh, physx::PxConvexMesh *&convexMesh,
193 qWarning() <<
"Could not open" << meshFilename;
199 qWarning() <<
"Could not map" << meshFilename;
207 triangleMesh = physics.createTriangleMesh(
input);
211 convexMesh = physics.createConvexMesh(
input);
215 heightField = physics.createHeightField(
input);
222 physx::PxTriangleMesh *triangleMesh =
nullptr;
223 physx::PxConvexMesh *convexMesh =
nullptr;
224 physx::PxHeightField *heightField =
nullptr;
225 readCachedMesh(filePath, physics, triangleMesh, convexMesh, heightField,
232 physx::PxTriangleMesh *triangleMesh =
nullptr;
233 physx::PxConvexMesh *convexMesh =
nullptr;
234 physx::PxHeightField *heightField =
nullptr;
235 readCachedMesh(filePath, physics, triangleMesh, convexMesh, heightField,
242 physx::PxTriangleMesh *triangleMesh =
nullptr;
243 physx::PxConvexMesh *convexMesh =
nullptr;
244 physx::PxHeightField *heightField =
nullptr;
245 readCachedMesh(filePath, physics, triangleMesh, convexMesh, heightField,
252 physx::PxTriangleMesh *triangleMesh =
nullptr;
253 physx::PxConvexMesh *convexMesh =
nullptr;
254 physx::PxHeightField *heightField =
nullptr;
255 readCookedMesh(filePath, physics, triangleMesh, convexMesh, heightField,
262 physx::PxTriangleMesh *triangleMesh =
nullptr;
263 physx::PxConvexMesh *convexMesh =
nullptr;
264 physx::PxHeightField *heightField =
nullptr;
265 readCookedMesh(filePath, physics, triangleMesh, convexMesh, heightField,
272 physx::PxTriangleMesh *triangleMesh =
nullptr;
273 physx::PxConvexMesh *convexMesh =
nullptr;
274 physx::PxHeightField *heightField =
nullptr;
275 readCookedMesh(filePath, physics, triangleMesh, convexMesh, heightField,
uchar * map(qint64 offset, qint64 size, MemoryMapFlags flags=NoOptions)
Maps size bytes of the file into memory starting at offset.
bool unmap(uchar *address)
Unmaps the memory address.
void close() override
Calls QFileDevice::flush() and closes the file.
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
qint64 size() const override
\reimp
bool isOpen() const
Returns true if the device is open; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static void readCookedMesh(const QString &meshFilename, physx::PxPhysics &physics, physx::PxTriangleMesh *&triangleMesh, physx::PxConvexMesh *&convexMesh, physx::PxHeightField *&heightField, CacheGeometry geom)
void writeCachedConvexMesh(const QString &filePath, physx::PxDefaultMemoryOutputStream &buf)
void writeCachedTriangleMesh(const QString &filePath, physx::PxDefaultMemoryOutputStream &buf)
static void readCachedMesh(const QString &meshFilename, physx::PxPhysics &physics, physx::PxTriangleMesh *&triangleMesh, physx::PxConvexMesh *&convexMesh, physx::PxHeightField *&heightField, CacheGeometry geom)
physx::PxTriangleMesh * readCachedTriangleMesh(const QString &filePath, physx::PxPhysics &physics)
void writeCachedHeightField(const QString &filePath, physx::PxDefaultMemoryOutputStream &buf)
physx::PxConvexMesh * readCookedConvexMesh(const QString &filePath, physx::PxPhysics &physics)
physx::PxTriangleMesh * readCookedTriangleMesh(const QString &filePath, physx::PxPhysics &physics)
physx::PxHeightField * readCookedHeightField(const QString &filePath, physx::PxPhysics &physics)
static QString MESH_CACHE_PATH
static void writeCachedMesh(const QString &meshFilename, physx::PxDefaultMemoryOutputStream &buf, CacheGeometry geom)
static QString getCachedFilename(const QString &filePath, CacheGeometry geom)
physx::PxConvexMesh * readCachedConvexMesh(const QString &filePath, physx::PxPhysics &physics)
physx::PxHeightField * readCachedHeightField(const QString &filePath, physx::PxPhysics &physics)
Combined button and popup list for selecting options.
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLenum GLenum input
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)