Qt Quick 3D - 动态纹理范例

演示如何将 2D 层用作 3D 纹理。

DynamicTexture demonstrates how to render 3D objects with 2D item. The 2D item used in this example is a fancy corkboard and it is textured to a simple double door.

Drawing a 3D View

A wall and two doors

The two doors share the same texture, which is identified by the sourceItem 特性。

DefaultMaterial {
    id: material_001_material
    diffuseMap: Texture {
        sourceItem: object2d
    }
}
materials: [
    material_001_material
]
					
Defining a new state

Each door will open when clicked on it and its state is set to opened .

states: State {
    name: "opened"
    PropertyChanges {
        target: door1
        eulerRotation.y: 90
    }
}
transitions: Transition {
    to: "opened"
    reversible: true
    SequentialAnimation {
        PropertyAnimation { property: "eulerRotation.y"; duration: 2000 }
    }
}
					

Drawing a 2D layer

The corkboards example is used as the content for this example.

Rectangle {
    id: object2d
    width: 500
    height: 700
    anchors.top: parent.top
    anchors.left: parent.left
    anchors.margins: 10
    CorkBoards { }
    layer.enabled: true
}
					

文件:

图像: