QmlDesigner: Allow image drag to create Texture on all materials

Dragging image asset to any 3D material type now creates a Texture out
of the image. Default materials assign the created Texture to
a diffuse map and principled materials assign it to base color map.
Custom material just creates the Texture without any assignments.

Task-number: QDS-2657
Change-Id: I065f98cbc4d8c3293fbacea9ef8649d0a2edfb0a
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Miikka Heikkinen
2020-08-25 12:34:00 +03:00
parent 8702f58a03
commit 3fd9110233

View File

@@ -606,7 +606,7 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
ModelNode newModelNode; ModelNode newModelNode;
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial")) { if (targetNode.isSubclassOf("QtQuick3D.Material")) {
// if dropping an image on a default material, create a texture instead of image // if dropping an image on a default material, create a texture instead of image
m_view->executeInTransaction("QmlItemNode::createQmlItemNode", [&] { m_view->executeInTransaction("QmlItemNode::createQmlItemNode", [&] {
// create a texture item lib // create a texture item lib
@@ -623,9 +623,12 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i
// create a texture // create a texture
newModelNode = QmlItemNode::createQmlObjectNode(m_view, itemLibraryEntry, {}, targetProperty, false); newModelNode = QmlItemNode::createQmlObjectNode(m_view, itemLibraryEntry, {}, targetProperty, false);
// set the texture to parent material's diffuseMap property // Automatically set the texture to default property
// TODO: allow the user to choose which map property to set the texture for // TODO: allow the user to choose which map property to set the texture for (QDS-2326)
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial"))
targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId()); targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId());
else if (targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial"))
targetNode.bindingProperty("baseColorMap").setExpression(newModelNode.validId());
}); });
} else if (targetNode.isSubclassOf("QtQuick3D.Texture")) { } else if (targetNode.isSubclassOf("QtQuick3D.Texture")) {
// if dropping an image on a texture, set the texture source // if dropping an image on a texture, set the texture source