forked from qt-creator/qt-creator
QmlDesigner: Fix textures created from assets can have invalid source
When creating a texture from an image in the asset library, the "source" for the texture was wrong for images outside of the "content/images" directory of the project. Task-number: QDS-8535 Change-Id: I30a28a7cb63748ce0fb81396ca59c7ccc9e83340 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -65,19 +65,27 @@ ModelNode CreateTexture::createTextureFromImage(const QString &assetPath, AddTex
|
|||||||
|
|
||||||
NodeMetaInfo metaInfo = m_view->model()->qtQuick3DTextureMetaInfo();
|
NodeMetaInfo metaInfo = m_view->model()->qtQuick3DTextureMetaInfo();
|
||||||
|
|
||||||
Utils::FilePath imagePath = ModelNodeOperations::getImagesDefaultDirectory()
|
Utils::FilePath currentDocumentPath = QmlDesigner::DocumentManager::currentFilePath();
|
||||||
.pathAppended(Utils::FilePath::fromString(assetPath).fileName());
|
Utils::FilePath imageTargetPath;
|
||||||
QString sourceVal = imagePath.relativePathFrom(
|
if (m_importFile) {
|
||||||
QmlDesigner::DocumentManager::currentFilePath()).toString();
|
QString assetName = Utils::FilePath::fromString(assetPath).fileName();
|
||||||
|
// if the asset had to be imported from somewhere else, then assetPath is the source where
|
||||||
|
// the asset was taken from, and we have to compute where it was placed in the project.
|
||||||
|
imageTargetPath = ModelNodeOperations::getImagesDefaultDirectory().pathAppended(assetName);
|
||||||
|
} else {
|
||||||
|
imageTargetPath = Utils::FilePath::fromString(assetPath);
|
||||||
|
}
|
||||||
|
|
||||||
ModelNode newTexNode = m_view->getTextureDefaultInstance(sourceVal);
|
QString textureSource = imageTargetPath.relativePathFrom(currentDocumentPath).toString();
|
||||||
|
|
||||||
|
ModelNode newTexNode = m_view->getTextureDefaultInstance(textureSource);
|
||||||
if (!newTexNode.isValid()) {
|
if (!newTexNode.isValid()) {
|
||||||
newTexNode = m_view->createModelNode("QtQuick3D.Texture",
|
newTexNode = m_view->createModelNode("QtQuick3D.Texture",
|
||||||
metaInfo.majorVersion(),
|
metaInfo.majorVersion(),
|
||||||
metaInfo.minorVersion());
|
metaInfo.minorVersion());
|
||||||
newTexNode.validId();
|
newTexNode.validId();
|
||||||
VariantProperty sourceProp = newTexNode.variantProperty("source");
|
VariantProperty sourceProp = newTexNode.variantProperty("source");
|
||||||
sourceProp.setValue(sourceVal);
|
sourceProp.setValue(textureSource);
|
||||||
matLib.defaultNodeListProperty().reparentHere(newTexNode);
|
matLib.defaultNodeListProperty().reparentHere(newTexNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user