英文:
Qt5.12 C++ How to dynamically load QPIxmap as texture in QML 3DScene
问题
以下是您要翻译的内容:
有一个应用程序在2D(QGraphicScene)和3D(QML 3D场景)中显示地图。我们需要在3D场景上使用2D场景的QML代码动态显示地图。加载使用QQuickImageProvider进行,该方法在QML中的图像上成功运行,但TextureLoader无法识别。是否有更简单的方法,如果没有,如何解决这个问题?
id: scene3d
Entity {
Entity {
id: floor
components: [
PlaneMesh {
width: 10
height: 10
mirrored: true
},
TexturedMetalRoughMaterial {
id: material
baseColor: TextureLoader {
id: textureLoader
source: "image://colors/yellow.png"
format: Texture.SRGB8_Alpha8
generateMipMaps: true
请提供一个解决方案。
英文:
There is an application that displays a map in 2D (QGraphicScene) and 3D (QML 3D Scene) We need a map on 3DScene to dynamically display a map with a 2D Scene QML code, Loading occurs using QQuickImageProvider, which successfully works with Image in QML, but TextureLoader does not perceives.() Is there any simpler way, if not, how to solve this problem?
id: scene3d
Entity {
Entity {
id: floor
components: [
PlaneMesh {
width: 10
height: 10
mirrored: true
},
TexturedMetalRoughMaterial {
id: material
baseColor: TextureLoader {
id: textureLoader
source: "image://colors/yellow.png"
format: Texture.SRGB8_Alpha8
generateMipMaps: true
Please suggest a solution
答案1
得分: 1
如果您使用QtQuick3D,可以通过将其设置为Texture.sourceItem
来使用QtQuick 2D组件,例如:
Model {
source: "#Cube"
materials: [
DefaultMaterial {
diffuseMap: Texture {
sourceItem: Rectangle {
width: 256
height: 256
color: "#78a"
Image {
anchors.centerIn: parent
width: 224
height: 224
source: "https://stephenquan.github.io/images/qt/madewithqt.png"
}
}
}
}
]
}
您可以通过访问 https://stephenquan.github.io/qmlonline/ 查看此示例。
英文:
If you use QtQuick3D you can use QtQuick 2D components such as Image by setting it to Texture.sourceItem
, for instance:
Model {
source: "#Cube"
materials: [
DefaultMaterial {
diffuseMap: Texture {
sourceItem: Rectangle {
width: 256
height: 256
color: "#78a"
Image {
anchors.centerIn: parent
width: 224
height: 224
source: "https://stephenquan.github.io/images/qt/madewithqt.png"
}
}
}
}
]
}
You can see a sample of this by visiting https://stephenquan.github.io/qmlonline/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论