From c179b9602ecd003c306803b757fd44203e584405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Wed, 6 May 2020 11:02:22 +0300 Subject: Fix editor loading custom material images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add project path to the custom material image path and check if the image path contains ../. Change-Id: Iab436ffa304c94cdc8235dc9fbf06abd9c060e71 Reviewed-by: Miikka Heikkinen Reviewed-by: Tomi Korpipää --- .../graphobjects/Qt3DSRenderDynamicObject.cpp | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp b/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp index 1dd352c..0292428 100644 --- a/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp +++ b/src/runtimerender/graphobjects/Qt3DSRenderDynamicObject.cpp @@ -125,12 +125,25 @@ void SDynamicObject::SetStrPropertyValueT(dynamic::SPropertyDefinition &inDefini if (inProjectDir == NULL) inProjectDir = ""; if (CFileTools::RequiresCombineBaseAndRelative(inValue)) { - QString path = QDir(inProjectDir).cleanPath(inValue); - ioWorkspace.assign(path.toLatin1().constData()); - SetPropertyValueT(inDefinition, inStrTable.RegisterStr(ioWorkspace.c_str())); - // We also adjust the image path in the definition - // I could not find a better place - inDefinition.m_ImagePath = inStrTable.RegisterStr(ioWorkspace.c_str()); + QString value(QDir::cleanPath(inValue)); + QDir projectDir(inProjectDir); + QString path = projectDir.path() + QChar('/') + value; + if (QFileInfo(path).exists()) { + ioWorkspace.assign(path.toLatin1().constData()); + SetPropertyValueT(inDefinition, inStrTable.RegisterStr(ioWorkspace.c_str())); + // We also adjust the image path in the definition + // I could not find a better place + inDefinition.m_ImagePath = inStrTable.RegisterStr(ioWorkspace.c_str()); + } else if (value.startsWith("../")) { + path = projectDir.path() + QChar('/') + value.right(value.size() - 3); + if (QFileInfo(path).exists()) { + ioWorkspace.assign(path.toLatin1().constData()); + SetPropertyValueT(inDefinition, inStrTable.RegisterStr(ioWorkspace.c_str())); + // We also adjust the image path in the definition + // I could not find a better place + inDefinition.m_ImagePath = inStrTable.RegisterStr(ioWorkspace.c_str()); + } + } } else { SetPropertyValueT(inDefinition, inStrTable.RegisterStr(inValue)); // If the image path is not adjusted here, an invalid textures flashes for one frame -- cgit v1.2.3