Hello I am learning Qt 3d in version 6.4.2 using QTCreator and qml and after researching in the official qt documentation and even here in stack overflow I did not find a way to put several images as faces of a cube or one texture image mapped in, I tried using CubeMapTexture but I get an error, I also tried with the material but I couldn't either
here is a minimal code to reproduce
import QtQuick
import QtQuick3D
import QtQuick3D.Effects
import QtQuick3D.Helpers
import QtQuick.Controls
import QtQuick.Layouts
Window {
id: window
width: 1280
height: 720
visible: true
title: "Example"
color: "#848895"
SplitView {
id: splitView
anchors.fill: parent
View3D {
id: viewport
SplitView.fillHeight: true
SplitView.fillWidth: true
SplitView.minimumWidth: splitView.width * 0.5
environment: SceneEnvironment {
property bool enableEffects: false
antialiasingMode: SceneEnvironment.MSAA
antialiasingQuality: SceneEnvironment.High
lightProbe: Texture {
source: "maps/OpenfootageNET_garage-1024.hdr"
}
effects: enableEffects ? [bloom, scurveTonemap] : []
backgroundMode: SceneEnvironment.SkyBox
SCurveTonemap {
id: scurveTonemap
}
HDRBloomTonemap {
id: bloom
}
}
Node {
id: originNode
PerspectiveCamera {
id: cameraNode
z: 600
clipNear: 1
clipFar: 10000
}
}
PrincipledMaterial {
id: basicMaterial
baseColorMap: CubeMapTexture{
source: "maps/side.png"
}
}
Model {
id: cube
source: "#Cube"
materials: basicMaterial
pickable: true
}
OrbitCameraController {
origin: originNode
camera: cameraNode
}
MouseArea {
id: pickController
anchors.fill: parent
onClicked: function(mouse) {
let pickResult = viewport.pick(mouse.x, mouse.y);
if (pickResult.objectHit) {
let pickedObject = pickResult.objectHit;
// Move the camera orbit origin to be the clicked object
originNode.position = pickedObject.position
}
}
}
}
}
}
The error using CubeMapTexture is this "Sampler qt_BaseColorMap_sampler expects a 2D texture but the associated texture is a cube map. This will lead to problems." but in other ways I can't put multiple textures in the cube or just one texture and map it.
For the
Textureconsider usingsourceItem. That will allow you to use traditional 2D components such asImageas your texture. In my example, I've used SVG images so that I can quickly apply a mixture of vector graphics to my textures. For you, you don't have to limit yourself to usingImageas yoursourceItem. You can choose, any 2D component, e.g.Item,Rectangle,Text,Label,Canvas,Shape, etc.If you use "#Cube", the Material(s) you use will be the same on all 6 sides. If you switch to using 6 "#Rectangle"s, you can use a different material for each rectangle. We can use this technique to create a 6-sided dice. Each face of the dice is rendered with its own SVG image:
You can Try it Online!