mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 01:48:59 +02:00
Fixup model on tex load
This commit is contained in:
parent
74633ca8c8
commit
3de5f73a1f
5 changed files with 20 additions and 24 deletions
|
@ -133,10 +133,8 @@ void RenderableModelEntityItem::remapTextures() {
|
|||
return; // nothing to do if the model has not yet loaded
|
||||
}
|
||||
|
||||
auto& geometry = _model->getGeometry()->getGeometry();
|
||||
|
||||
if (!_originalTexturesRead) {
|
||||
_originalTextures = geometry->getTextures();
|
||||
_originalTextures = _model->getTextures();
|
||||
_originalTexturesRead = true;
|
||||
|
||||
// Default to _originalTextures to avoid remapping immediately and lagging on load
|
||||
|
@ -152,7 +150,7 @@ void RenderableModelEntityItem::remapTextures() {
|
|||
auto newTextures = parseTexturesToMap(textures);
|
||||
|
||||
if (newTextures != _currentTextures) {
|
||||
geometry->setTextures(newTextures);
|
||||
_model->setTextures(newTextures);
|
||||
_currentTextures = newTextures;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,6 +270,9 @@ void Geometry::setTextures(const QVariantMap& textureMap) {
|
|||
|
||||
material->setTextures(textureMap);
|
||||
_areTexturesLoaded = false;
|
||||
|
||||
// If we only use cached textures, they should all be loaded
|
||||
areTexturesLoaded();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -279,8 +282,6 @@ void Geometry::setTextures(const QVariantMap& textureMap) {
|
|||
|
||||
bool Geometry::areTexturesLoaded() const {
|
||||
if (!_areTexturesLoaded) {
|
||||
_hasTransparentTextures = false;
|
||||
|
||||
for (auto& material : _materials) {
|
||||
// Check if material textures are loaded
|
||||
if (std::any_of(material->_textures.cbegin(), material->_textures.cend(),
|
||||
|
@ -293,8 +294,6 @@ bool Geometry::areTexturesLoaded() const {
|
|||
const auto albedoTexture = material->_textures[NetworkMaterial::MapChannel::ALBEDO_MAP];
|
||||
if (albedoTexture.texture && albedoTexture.texture->getGPUTexture()) {
|
||||
material->resetOpacityMap();
|
||||
|
||||
_hasTransparentTextures |= material->getKey().isTranslucent();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,9 +74,6 @@ public:
|
|||
void setTextures(const QVariantMap& textureMap);
|
||||
|
||||
virtual bool areTexturesLoaded() const;
|
||||
// Returns true if any albedo texture has a non-masking alpha channel.
|
||||
// This can only be known after areTexturesLoaded().
|
||||
bool hasTransparentTextures() const { return _hasTransparentTextures; }
|
||||
|
||||
protected:
|
||||
friend class GeometryMappingResource;
|
||||
|
@ -91,7 +88,6 @@ protected:
|
|||
|
||||
private:
|
||||
mutable bool _areTexturesLoaded { false };
|
||||
mutable bool _hasTransparentTextures { false };
|
||||
};
|
||||
|
||||
/// A geometry loaded from the network.
|
||||
|
|
|
@ -76,14 +76,9 @@ AbstractViewStateInterface* Model::_viewState = NULL;
|
|||
|
||||
bool Model::needsFixupInScene() const {
|
||||
if (readyToAddToScene()) {
|
||||
// Once textures are loaded, fixup if they are now transparent
|
||||
if (_needsUpdateTransparentTextures && _geometry->getGeometry()->areTexturesLoaded()) {
|
||||
_needsUpdateTransparentTextures = false;
|
||||
bool hasTransparentTextures = _geometry->getGeometry()->hasTransparentTextures();
|
||||
if (_hasTransparentTextures != hasTransparentTextures) {
|
||||
_hasTransparentTextures = hasTransparentTextures;
|
||||
return true;
|
||||
}
|
||||
if (_needsUpdateTextures && _geometry->getGeometry()->areTexturesLoaded()) {
|
||||
_needsUpdateTextures = false;
|
||||
return true;
|
||||
}
|
||||
if (!_readyWhenAdded) {
|
||||
return true;
|
||||
|
@ -791,6 +786,13 @@ int Model::getLastFreeJointIndex(int jointIndex) const {
|
|||
return (isActive() && jointIndex != -1) ? getFBXGeometry().joints.at(jointIndex).freeLineage.last() : -1;
|
||||
}
|
||||
|
||||
void Model::setTextures(const QVariantMap& textures) {
|
||||
if (isLoaded()) {
|
||||
_needsUpdateTextures = true;
|
||||
_geometry->getGeometry()->setTextures(textures);
|
||||
}
|
||||
}
|
||||
|
||||
void Model::setURL(const QUrl& url) {
|
||||
// don't recreate the geometry if it's the same URL
|
||||
if (_url == url && _geometry && _geometry->getURL() == url) {
|
||||
|
@ -807,8 +809,7 @@ void Model::setURL(const QUrl& url) {
|
|||
}
|
||||
|
||||
_needsReload = true;
|
||||
_needsUpdateTransparentTextures = true;
|
||||
_hasTransparentTextures = false;
|
||||
_needsUpdateTextures = true;
|
||||
_meshGroupsKnown = false;
|
||||
invalidCalculatedMeshBoxes();
|
||||
deleteGeometry();
|
||||
|
|
|
@ -129,6 +129,9 @@ public:
|
|||
/// Returns a reference to the shared collision geometry.
|
||||
const NetworkGeometry::Pointer& getCollisionGeometry() const { return _collisionGeometry; }
|
||||
|
||||
const QVariantMap getTextures() const { assert(isLoaded()); return _geometry->getGeometry()->getTextures(); }
|
||||
void setTextures(const QVariantMap& textures);
|
||||
|
||||
/// Provided as a convenience, will crash if !isLoaded()
|
||||
// And so that getGeometry() isn't chained everywhere
|
||||
const FBXGeometry& getFBXGeometry() const { assert(isLoaded()); return getGeometry()->getGeometry()->getGeometry(); }
|
||||
|
@ -385,9 +388,8 @@ protected:
|
|||
bool _readyWhenAdded { false };
|
||||
bool _needsReload { true };
|
||||
bool _needsUpdateClusterMatrices { true };
|
||||
mutable bool _needsUpdateTransparentTextures { true };
|
||||
mutable bool _hasTransparentTextures { false };
|
||||
bool _showCollisionHull { false };
|
||||
mutable bool _needsUpdateTextures { true };
|
||||
|
||||
friend class ModelMeshPartPayload;
|
||||
RigPointer _rig;
|
||||
|
|
Loading…
Reference in a new issue