From 3fd911023370879a89f6ca9e493cce5e0db294ac Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 25 Aug 2020 12:34:00 +0300 Subject: [PATCH] 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 Reviewed-by: Thomas Hartmann --- .../components/navigator/navigatortreemodel.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp index cf51c1a0220..e543537211f 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatortreemodel.cpp @@ -606,7 +606,7 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i 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 m_view->executeInTransaction("QmlItemNode::createQmlItemNode", [&] { // create a texture item lib @@ -623,9 +623,12 @@ void NavigatorTreeModel::handleItemLibraryImageDrop(const QMimeData *mimeData, i // create a texture newModelNode = QmlItemNode::createQmlObjectNode(m_view, itemLibraryEntry, {}, targetProperty, false); - // set the texture to parent material's diffuseMap property - // TODO: allow the user to choose which map property to set the texture for - targetNode.bindingProperty("diffuseMap").setExpression(newModelNode.validId()); + // Automatically set the texture to default property + // 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()); + else if (targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial")) + targetNode.bindingProperty("baseColorMap").setExpression(newModelNode.validId()); }); } else if (targetNode.isSubclassOf("QtQuick3D.Texture")) { // if dropping an image on a texture, set the texture source