Showing the changes to interface/src/renderer/GeometryCache.cpp (1 of 4 files). Show all
Unified · Split
| @@ -250,21 +250,37 @@ QSharedPointer<NetworkGeometry> GeometryCache::getGeometry(const QUrl& url) { · 249 unmodified lines | |||
| 250 | return geometry; | 250 | return geometry; |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | NetworkGeometry::NetworkGeometry(const QUrl& url) : _reply(NULL) { | 253 | NetworkGeometry::NetworkGeometry(const QUrl& url) : |
| 254 | _modelReply(NULL), | ||
| 255 | _mappingReply(NULL) | ||
| 256 | { | ||
| 254 | if (!url.isValid()) { | 257 | if (!url.isValid()) { |
| 255 | return; | 258 | return; |
| 256 | } | 259 | } |
| 257 | QNetworkRequest request(url); | 260 | QNetworkRequest modelRequest(url); |
| 258 | request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); | 261 | modelRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); |
| 259 | _reply = Application::getInstance()->getNetworkAccessManager()->get(request); | 262 | _modelReply = Application::getInstance()->getNetworkAccessManager()->get(modelRequest); |
| 260 | 263 | ||
| 261 | connect(_reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(handleDownloadProgress(qint64,qint64))); | 264 | connect(_modelReply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(maybeReadModelWithMapping())); |
| 262 | connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleReplyError())); | 265 | connect(_modelReply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleModelReplyError())); |
| 266 | |||
| 267 | QUrl mappingURL = url; | ||
| 268 | QString path = url.path(); | ||
| 269 | mappingURL.setPath(path.left(path.lastIndexOf('.')) + ".fst"); | ||
| 270 | QNetworkRequest mappingRequest(mappingURL); | ||
| 271 | mappingRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); | ||
| 272 | _mappingReply = Application::getInstance()->getNetworkAccessManager()->get(mappingRequest); | ||
| 273 | |||
| 274 | connect(_mappingReply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(maybeReadModelWithMapping())); | ||
| 275 | connect(_mappingReply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(handleMappingReplyError())); | ||
| 263 | } | 276 | } |
| 264 | 277 | ||
| 265 | NetworkGeometry::~NetworkGeometry() { | 278 | NetworkGeometry::~NetworkGeometry() { |
| 266 | if (_reply != NULL) { | 279 | if (_modelReply != NULL) { |
| 267 | delete _reply; | 280 | delete _modelReply; |
| 281 | } | ||
| 282 | if (_mappingReply != NULL) { | ||
| 283 | delete _mappingReply; | ||
| 268 | } | 284 | } |
| 269 | foreach (const NetworkMesh& mesh, _meshes) { | 285 | foreach (const NetworkMesh& mesh, _meshes) { |
| 270 | glDeleteBuffers(1, &mesh.indexBufferID); | 286 | glDeleteBuffers(1, &mesh.indexBufferID); |
| @@ -272,19 +288,43 @@ NetworkGeometry::~NetworkGeometry() { · 1 unmodified line | |||
| 272 | } | 288 | } |
| 273 | } | 289 | } |
| 274 | 290 | ||
| 275 | void NetworkGeometry::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { | 291 | void NetworkGeometry::handleModelReplyError() { |
| 276 | if (bytesReceived < bytesTotal && !_reply->isFinished()) { | 292 | qDebug() << _modelReply->errorString() << "\n"; |
| 293 | |||
| 294 | _modelReply->disconnect(this); | ||
| 295 | _modelReply->deleteLater(); | ||
| 296 | _modelReply = NULL; | ||
| 297 | } | ||
| 298 | |||
| 299 | void NetworkGeometry::handleMappingReplyError() { | ||
| 300 | _mappingReply->disconnect(this); | ||
| 301 | _mappingReply->deleteLater(); | ||
| 302 | _mappingReply = NULL; | ||
| 303 | |||
| 304 | maybeReadModelWithMapping(); | ||
| 305 | } | ||
| 306 | |||
| 307 | void NetworkGeometry::maybeReadModelWithMapping() { | ||
| 308 | if (_modelReply == NULL || !_modelReply->isFinished() || (_mappingReply != NULL && !_mappingReply->isFinished())) { | ||
| 277 | return; | 309 | return; |
| 278 | } | 310 | } |
| 279 | 311 | ||
| 280 | QUrl url = _reply->url(); | 312 | QUrl url = _modelReply->url(); |
| 281 | QByteArray entirety = _reply->readAll(); | 313 | QByteArray model = _modelReply->readAll(); |
| 282 | _reply->disconnect(this); | 314 | _modelReply->disconnect(this); |
| 283 | _reply->deleteLater(); | 315 | _modelReply->deleteLater(); |
| 284 | _reply = NULL; | 316 | _modelReply = NULL; |
| 317 | |||
| 318 | QByteArray mapping; | ||
| 319 | if (_mappingReply != NULL) { | ||
| 320 | mapping = _mappingReply->readAll(); | ||
| 321 | _mappingReply->disconnect(this); | ||
| 322 | _mappingReply->deleteLater(); | ||
| 323 | _mappingReply = NULL; | ||
| 324 | } | ||
| 285 | 325 | ||
| 286 | try { | 326 | try { |
| 287 | _geometry = extractFBXGeometry(parseFBX(entirety)); | 327 | _geometry = readFBX(model, mapping); |
| 288 | 328 | ||
| 289 | } catch (const QString& error) { | 329 | } catch (const QString& error) { |
| 290 | qDebug() << "Error reading " << url << ": " << error << "\n"; | 330 | qDebug() << "Error reading " << url << ": " << error << "\n"; |
| @@ -338,11 +378,3 @@ void NetworkGeometry::handleDownloadProgress(qint64 bytesReceived, qint64 bytesT · 47 unmodified lines | |||
| 338 | _meshes.append(networkMesh); | 378 | _meshes.append(networkMesh); |
| 339 | } | 379 | } |
| 340 | } | 380 | } |
| 341 | |||
| 342 | void NetworkGeometry::handleReplyError() { | ||
| 343 | qDebug() << _reply->errorString() << "\n"; | ||
| 344 | |||
| 345 | _reply->disconnect(this); | ||
| 346 | _reply->deleteLater(); | ||
| 347 | _reply = NULL; | ||
| 348 | } | ||