mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 11:33:30 +02:00
fix missing models
This commit is contained in:
parent
abbe263142
commit
9f12d3a365
8 changed files with 66 additions and 21 deletions
libraries
entities-renderer/src
EntityTreeRenderer.cppRenderableEntityItem.cppRenderableEntityItem.hRenderableModelEntityItem.cppRenderableModelEntityItem.h
model-networking/src/model-networking
render-utils/src
|
@ -222,6 +222,14 @@ void EntityTreeRenderer::updateChangedEntities(const render::ScenePointer& scene
|
|||
_renderablesToUpdate.insert({ entityId, renderable });
|
||||
}
|
||||
|
||||
if (!_entitiesInScene.empty()) {
|
||||
for (const auto& entry : _entitiesInScene) {
|
||||
const auto& renderable = entry.second;
|
||||
if (renderable) {
|
||||
renderable->update(scene, transaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!_renderablesToUpdate.empty()) {
|
||||
for (const auto& entry : _renderablesToUpdate) {
|
||||
const auto& renderable = entry.second;
|
||||
|
|
|
@ -291,6 +291,18 @@ void EntityRenderer::updateInScene(const ScenePointer& scene, Transaction& trans
|
|||
});
|
||||
}
|
||||
|
||||
void EntityRenderer::update(const ScenePointer& scene, Transaction& transaction) {
|
||||
if (!isValidRenderItem()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!needsUpdate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
doUpdate(scene, transaction, _entity);
|
||||
}
|
||||
|
||||
//
|
||||
// Internal methods
|
||||
//
|
||||
|
@ -304,6 +316,11 @@ bool EntityRenderer::needsRenderUpdate() const {
|
|||
return needsRenderUpdateFromEntity(_entity);
|
||||
}
|
||||
|
||||
// Returns true if the item needs to have update called
|
||||
bool EntityRenderer::needsUpdate() const {
|
||||
return needsUpdateFromEntity(_entity);
|
||||
}
|
||||
|
||||
// Returns true if the item in question needs to have updateInScene called because of changes in the entity
|
||||
bool EntityRenderer::needsRenderUpdateFromEntity(const EntityItemPointer& entity) const {
|
||||
bool success = false;
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
virtual bool addToScene(const ScenePointer& scene, Transaction& transaction) final;
|
||||
virtual void removeFromScene(const ScenePointer& scene, Transaction& transaction);
|
||||
|
||||
virtual void update(const ScenePointer& scene, Transaction& transaction);
|
||||
|
||||
protected:
|
||||
virtual bool needsRenderUpdateFromEntity() const final { return needsRenderUpdateFromEntity(_entity); }
|
||||
virtual void onAddToScene(const EntityItemPointer& entity);
|
||||
|
@ -71,6 +73,12 @@ protected:
|
|||
// Returns true if the item in question needs to have updateInScene called because of changes in the entity
|
||||
virtual bool needsRenderUpdateFromEntity(const EntityItemPointer& entity) const;
|
||||
|
||||
// Returns true if the item in question needs to have update called
|
||||
virtual bool needsUpdate() const;
|
||||
|
||||
// Returns true if the item in question needs to have update called because of changes in the entity
|
||||
virtual bool needsUpdateFromEntity(const EntityItemPointer& entity) const { return false; }
|
||||
|
||||
// Will be called on the main thread from updateInScene. This can be used to fetch things like
|
||||
// network textures or model geometry from resource caches
|
||||
virtual void doRenderUpdateSynchronous(const ScenePointer& scene, Transaction& transaction, const EntityItemPointer& entity) { }
|
||||
|
@ -80,6 +88,8 @@ protected:
|
|||
// data in this method if using multi-threaded rendering
|
||||
virtual void doRenderUpdateAsynchronous(const EntityItemPointer& entity);
|
||||
|
||||
virtual void doUpdate(const ScenePointer& scene, Transaction& transaction, const EntityItemPointer& entity) { }
|
||||
|
||||
// Called by the `render` method after `needsRenderUpdate`
|
||||
virtual void doRender(RenderArgs* args) = 0;
|
||||
|
||||
|
@ -148,6 +158,15 @@ protected:
|
|||
onRemoveFromSceneTyped(_typedEntity);
|
||||
}
|
||||
|
||||
using Parent::needsUpdateFromEntity;
|
||||
// Returns true if the item in question needs to have update called because of changes in the entity
|
||||
virtual bool needsUpdateFromEntity(const EntityItemPointer& entity) const override final {
|
||||
if (Parent::needsUpdateFromEntity(entity)) {
|
||||
return true;
|
||||
}
|
||||
return needsUpdateFromTypedEntity(_typedEntity);
|
||||
}
|
||||
|
||||
using Parent::needsRenderUpdateFromEntity;
|
||||
// Returns true if the item in question needs to have updateInScene called because of changes in the entity
|
||||
virtual bool needsRenderUpdateFromEntity(const EntityItemPointer& entity) const override final {
|
||||
|
@ -162,6 +181,11 @@ protected:
|
|||
doRenderUpdateSynchronousTyped(scene, transaction, _typedEntity);
|
||||
}
|
||||
|
||||
virtual void doUpdate(const ScenePointer& scene, Transaction& transaction, const EntityItemPointer& entity) override final {
|
||||
Parent::doUpdate(scene, transaction, entity);
|
||||
doUpdateTyped(scene, transaction, _typedEntity);
|
||||
}
|
||||
|
||||
virtual void doRenderUpdateAsynchronous(const EntityItemPointer& entity) override final {
|
||||
Parent::doRenderUpdateAsynchronous(entity);
|
||||
doRenderUpdateAsynchronousTyped(_typedEntity);
|
||||
|
@ -170,6 +194,8 @@ protected:
|
|||
virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { return false; }
|
||||
virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { }
|
||||
virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) { }
|
||||
virtual bool needsUpdateFromTypedEntity(const TypedEntityPointer& entity) const { return false; }
|
||||
virtual void doUpdateTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { }
|
||||
virtual void onAddToSceneTyped(const TypedEntityPointer& entity) { }
|
||||
virtual void onRemoveFromSceneTyped(const TypedEntityPointer& entity) { }
|
||||
|
||||
|
|
|
@ -904,7 +904,7 @@ using namespace render;
|
|||
using namespace render::entities;
|
||||
|
||||
ItemKey ModelEntityRenderer::getKey() {
|
||||
return ItemKey::Builder::opaqueShape().withTypeMeta();
|
||||
return ItemKey::Builder().withTypeMeta();
|
||||
}
|
||||
|
||||
uint32_t ModelEntityRenderer::metaFetchMetaSubItems(ItemIDs& subItems) {
|
||||
|
@ -1026,7 +1026,7 @@ void ModelEntityRenderer::animate(const TypedEntityPointer& entity) {
|
|||
entity->copyAnimationJointDataToModel();
|
||||
}
|
||||
|
||||
bool ModelEntityRenderer::needsRenderUpdate() const {
|
||||
bool ModelEntityRenderer::needsUpdate() const {
|
||||
ModelPointer model;
|
||||
withReadLock([&] {
|
||||
model = _model;
|
||||
|
@ -1057,10 +1057,10 @@ bool ModelEntityRenderer::needsRenderUpdate() const {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
return Parent::needsRenderUpdate();
|
||||
return Parent::needsUpdate();
|
||||
}
|
||||
|
||||
bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const {
|
||||
bool ModelEntityRenderer::needsUpdateFromTypedEntity(const TypedEntityPointer& entity) const {
|
||||
if (resultWithReadLock<bool>([&] {
|
||||
if (entity->hasModel() != _hasModel) {
|
||||
return true;
|
||||
|
@ -1122,7 +1122,7 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin
|
|||
return false;
|
||||
}
|
||||
|
||||
void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) {
|
||||
void ModelEntityRenderer::doUpdateTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) {
|
||||
if (_hasModel != entity->hasModel()) {
|
||||
_hasModel = entity->hasModel();
|
||||
}
|
||||
|
@ -1175,8 +1175,8 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
|||
properties.setLastEdited(usecTimestampNow()); // we must set the edit time since we're editing it
|
||||
auto extents = model->getMeshExtents();
|
||||
properties.setDimensions(extents.maximum - extents.minimum);
|
||||
qCDebug(entitiesrenderer) << "Autoresizing"
|
||||
<< (!entity->getName().isEmpty() ? entity->getName() : entity->getModelURL())
|
||||
qCDebug(entitiesrenderer) << "Autoresizing"
|
||||
<< (!entity->getName().isEmpty() ? entity->getName() : entity->getModelURL())
|
||||
<< "from mesh extents";
|
||||
|
||||
QMetaObject::invokeMethod(DependencyManager::get<EntityScriptingInterface>().data(), "editEntity",
|
||||
|
@ -1203,7 +1203,6 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
|||
entity->updateModelBounds();
|
||||
}
|
||||
|
||||
|
||||
if (model->isVisible() != _visible) {
|
||||
// FIXME: this seems like it could be optimized if we tracked our last known visible state in
|
||||
// the renderable item. As it stands now the model checks it's visible/invisible state
|
||||
|
@ -1234,7 +1233,6 @@ void ModelEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& sce
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
if (_animating) {
|
||||
if (!jointsMapped()) {
|
||||
mapJoints(entity, model->getJointNames());
|
||||
|
|
|
@ -138,10 +138,10 @@ protected:
|
|||
virtual ItemKey getKey() override;
|
||||
virtual uint32_t metaFetchMetaSubItems(ItemIDs& subItems) override;
|
||||
|
||||
virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override;
|
||||
virtual bool needsRenderUpdate() const override;
|
||||
virtual bool needsUpdateFromTypedEntity(const TypedEntityPointer& entity) const override;
|
||||
virtual bool needsUpdate() const override;
|
||||
virtual void doRender(RenderArgs* args) override;
|
||||
virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;
|
||||
virtual void doUpdateTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override;
|
||||
|
||||
private:
|
||||
void animate(const TypedEntityPointer& entity);
|
||||
|
|
|
@ -464,7 +464,7 @@ void GeometryResourceWatcher::setResource(GeometryResource::Pointer resource) {
|
|||
_resource = resource;
|
||||
if (_resource) {
|
||||
if (_resource->isLoaded()) {
|
||||
_geometryRef = std::make_shared<Geometry>(*_resource);
|
||||
resourceFinished(true);
|
||||
} else {
|
||||
startWatching();
|
||||
}
|
||||
|
|
|
@ -321,8 +321,8 @@ template <> void payloadRender(const ModelMeshPartPayload::Pointer& payload, Ren
|
|||
|
||||
}
|
||||
|
||||
ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int _meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform) :
|
||||
_meshIndex(_meshIndex),
|
||||
ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, int partIndex, int shapeIndex, const Transform& transform, const Transform& offsetTransform) :
|
||||
_meshIndex(meshIndex),
|
||||
_shapeID(shapeIndex) {
|
||||
|
||||
assert(model && model->isLoaded());
|
||||
|
|
|
@ -209,11 +209,6 @@ void Model::updateRenderItems() {
|
|||
return;
|
||||
}
|
||||
|
||||
glm::vec3 scale = getScale();
|
||||
if (_collisionGeometry) {
|
||||
// _collisionGeometry is already scaled
|
||||
scale = glm::vec3(1.0f);
|
||||
}
|
||||
_needsUpdateClusterMatrices = true;
|
||||
_renderItemsNeedUpdate = false;
|
||||
|
||||
|
@ -221,7 +216,7 @@ void Model::updateRenderItems() {
|
|||
// the application will ensure only the last lambda is actually invoked.
|
||||
void* key = (void*)this;
|
||||
std::weak_ptr<Model> weakSelf = shared_from_this();
|
||||
AbstractViewStateInterface::instance()->pushPostUpdateLambda(key, [weakSelf, scale]() {
|
||||
AbstractViewStateInterface::instance()->pushPostUpdateLambda(key, [weakSelf]() {
|
||||
|
||||
// do nothing, if the model has already been destroyed.
|
||||
auto self = weakSelf.lock();
|
||||
|
@ -1219,6 +1214,7 @@ const render::ItemIDs& Model::fetchRenderItemIDs() const {
|
|||
}
|
||||
|
||||
void Model::createRenderItemSet() {
|
||||
updateClusterMatrices();
|
||||
if (_collisionGeometry) {
|
||||
if (_collisionRenderItems.empty()) {
|
||||
createCollisionRenderItemSet();
|
||||
|
|
Loading…
Reference in a new issue