Add priority loading for model entities

This commit is contained in:
Ryan Huffman 2016-07-25 10:52:31 -07:00
parent 6585be036c
commit c594dcdf9f
5 changed files with 16 additions and 4 deletions

View file

@ -529,7 +529,7 @@ void EntityTreeRenderer::processEraseMessage(ReceivedMessage& message, const Sha
std::static_pointer_cast<EntityTree>(_tree)->processEraseMessage(message, sourceNode);
}
ModelPointer EntityTreeRenderer::allocateModel(const QString& url, const QString& collisionUrl) {
ModelPointer EntityTreeRenderer::allocateModel(const QString& url, const QString& collisionUrl, float priority) {
ModelPointer model = nullptr;
// Only create and delete models on the thread that owns the EntityTreeRenderer
@ -543,6 +543,7 @@ ModelPointer EntityTreeRenderer::allocateModel(const QString& url, const QString
}
model = std::make_shared<Model>(std::make_shared<Rig>());
model->priority = priority;
model->init();
model->setURL(QUrl(url));
model->setCollisionModelURL(QUrl(collisionUrl));

View file

@ -46,6 +46,8 @@ public:
virtual PacketType getExpectedPacketType() const { return PacketType::EntityData; }
virtual void setTree(OctreePointer newTree);
glm::vec3 cameraPosition {};
void shutdown();
void update();
@ -66,7 +68,7 @@ public:
void reloadEntityScripts();
/// if a renderable entity item needs a model, we will allocate it for them
Q_INVOKABLE ModelPointer allocateModel(const QString& url, const QString& collisionUrl);
Q_INVOKABLE ModelPointer allocateModel(const QString& url, const QString& collisionUrl, float priority = 0);
/// if a renderable entity item needs to update the URL of a model, we will handle that for the entity
Q_INVOKABLE ModelPointer updateModel(ModelPointer original, const QString& newUrl, const QString& collisionUrl);

View file

@ -484,7 +484,11 @@ ModelPointer RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) {
if (!getModelURL().isEmpty()) {
// If we don't have a model, allocate one *immediately*
if (!_model) {
_model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL());
auto dims = this->getDimensions();
auto maxSize = glm::max(dims.x, dims.y, dims.z);
auto distance = glm::distance(renderer->cameraPosition, getPosition());
float priority = atan2(maxSize / 2, distance);
_model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL(), priority);
_needsInitialSimulation = true;
// If we need to change URLs, update it *after rendering* (to avoid access violations)
} else if ((QUrl(getModelURL()) != _model->getURL() || QUrl(getCompoundShapeURL()) != _model->getCollisionURL())) {

View file

@ -826,7 +826,10 @@ void Model::setURL(const QUrl& url) {
invalidCalculatedMeshBoxes();
deleteGeometry();
_renderWatcher.setResource(DependencyManager::get<ModelCache>()->getGeometryResource(url));
auto resource = DependencyManager::get<ModelCache>()->getGeometryResource(url);
resource->setLoadPriority(this, priority);
qDebug() << "Setting priority to: " << priority;
_renderWatcher.setResource(resource);
onInvalidate();
}

View file

@ -238,6 +238,8 @@ public:
// returns 'true' if needs fullUpdate after geometry change
bool updateGeometry();
float priority { 0 };
public slots:
void loadURLFinished(bool success);
void loadCollisionModelURLFinished(bool success);