Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.qml:
- import QtQuick 2.9
- import QtQuick.Window 2.2
- import QtQuick.Scene3D 2.0
- Window {
- visible: true
- width: 640
- height: 480
- title: qsTr("Czworościan")
- id: mainwindow
- Scene3D {
- id: scene
- anchors.fill: parent
- aspects: ["render", "logic", "input"]
- focus: true
- Scene {
- id: sceneRoot
- }
- }
- }
- // Scene.qml:
- import QtQuick 2.0
- import Qt3D.Core 2.0
- import Qt3D.Render 2.0
- import Qt3D.Input 2.1
- import Qt3D.Extras 2.0
- Entity {
- id: sceneRoot
- components: [
- RenderSettings {
- activeFrameGraph: ForwardRenderer {
- clearColor: Qt.rgba(0.5, 0.5, 0.5, 1.0)
- camera: camera
- }
- },
- InputSettings { }
- ]
- Camera {
- id: camera
- projectionType: CameraLens.PerspectiveProjection
- fieldOfView: 45
- aspectRatio: 16/9
- nearPlane: 0.1
- farPlane: 1000.0
- position: Qt.vector3d(0.0, 0.0, 10.0)
- upVector: Qt.vector3d(0.0, 1.0, 0.0)
- viewCenter: Qt.vector3d(0.0, 0.0, 0.0)
- }
- OrbitCameraController {
- camera: camera
- }
- Entity {
- components: [
- DirectionalLight {
- color: "white"
- intensity: 1.0
- worldDirection: camera.viewCenter.minus(camera.position)
- }
- ]
- }
- Tetrahedron {
- }
- }
- // Tetrahedron.qml:
- import QtQuick 2.0
- import Qt3D.Core 2.0
- import Qt3D.Render 2.0
- import Qt3D.Extras 2.0
- Entity {
- id: root
- property vector3d position: Qt.vector3d(0.0, -1.0, 0.0)
- property real angle: 0.0
- components: [ mesh, material, transform ]
- PhongMaterial {
- id: material
- ambient: "black"
- diffuse: "#002300"
- }
- Transform {
- id: transform
- matrix: {
- var m = Qt.matrix4x4();
- m.rotate(angle, Qt.vector3d(0, 1, 0));
- m.translate(position);
- return m;
- }
- }
- GeometryRenderer {
- id: mesh
- instanceCount: 1
- indexOffset: 0
- firstInstance: 0
- primitiveType: GeometryRenderer.Triangles
- Buffer {
- id: vertexBuffer
- type: Buffer.VertexBuffer
- data: new Float32Array([
- 2.0, 0.0, 0.0, 0.0, 0.0, 1.0,
- -2.0, 0.0, 0.0, 0.0, 0.0, 1.0,
- 0.0, 3.46410161513, 0.0, 0.0, 0.0, 1.0,
- 2.0, 0.0, 0.0, 0.0, -1.0, 0.0,
- -2.0, 0.0, 0.0, 0.0, -1.0, 0.0,
- 0.0, 0.0, -3.46410161513, 0.0, -1.0, 0.0,
- 2.0, 0.0, 0.0, 1.0, 1.0, -1.0,
- 0.0, 0.0, -3.46410161513, 1.0, 1.0, -1.0,
- 0.0, 3.46410161513, 0.0, 1.0, 1.0, -1.0,
- -2.0, 0.0, 0.0, -1.0, 1.0, -1.0,
- 0.0, 3.46410161513, 0.0, -1.0, 1.0, -1.0,
- 0.0, 0.0, -3.46410161513, -1.0, 1.0, -1.0
- ])
- }
- Buffer {
- id: indexBuffer
- type: Buffer.IndexBuffer
- data: new Uint16Array([
- 2, 1, 0,
- 4, 5, 3,
- 6, 7, 8,
- 9, 10, 11
- ])
- }
- geometry: Geometry {
- attributes: [
- Attribute {
- attributeType: Attribute.VertexAttribute
- vertexBaseType: Attribute.Float
- vertexSize: 3
- byteOffset: 0
- byteStride: 6*4
- count: 12
- name: defaultPositionAttributeName
- buffer: vertexBuffer
- },
- Attribute {
- attributeType: Attribute.VertexAttribute
- vertexBaseType: Attribute.Float
- vertexSize: 3
- byteOffset: 3 * 4
- byteStride: 6*4
- count: 12
- name: defaultNormalAttributeName
- buffer: vertexBuffer
- },
- Attribute {
- attributeType: Attribute.IndexAttribute
- vertexBaseType: Attribute.UnsignedShort
- count: 3*4
- buffer: indexBuffer
- }
- ]
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement