2

I need to render some lines and points that hold some data in a 3d scene.

And points need to be picked by mouse, and then get the data in the point.

I first try to define a class inherited from QQuickFramebufferObject, however i find it is difficult to do mouse picking.

I find that it has the ObjectPicker in Qt3D module, so i want to use Qt3D to deal with my work.

My test code below. I defined my GeometryRenderer Object, and set vertices data(just draw two triangles). Like this:

GeometryRenderer {
    id: geometry
    geometry: Geometry {
        boundingVolumePositionAttribute: position
        Attribute {
            id: position
            attributeType: Attribute.VertexAttribute
            vertexBaseType: Attribute.Float
            vertexSize: 3
            count: 4
            byteOffset: 0
            byteStride: 6 * 4
            name: "position"
            buffer: vertexBuffer
        }
        Attribute {
            id: color
            attributeType: Attribute.VertexAttribute
            vertexBaseType: Attribute.Float
            vertexSize: 3
            count: 4
            byteOffset: 3 * 4
            byteStride: 6 * 4
            name: "color"
            buffer: vertexBuffer
        }

        Attribute {
            attributeType: Attribute.IndexAttribute
            vertexBaseType: Attribute.UnsignedShort
            vertexSize: 1
            count: 6
            buffer: indexBuffer
        }
    }
    Buffer {
        id: vertexBuffer
        type: Buffer.VertexBuffer
        data: new Float32Array(...)
    }
    Buffer {
        id: indexBuffer
        type: Buffer.IndexBuffer
        data: new Uint16Array(...)
    }
}

And then define a material object like this:

Material {
    id: material
    effect: Effect {
        techniques: Technique {
            graphicsApiFilter {
                profile: GraphicsApiFilter.CoreProfile
            }
            renderPasses: RenderPass {
                shaderProgram: ShaderProgram {
                    vertexShaderCode: loadSource("qrc:/shader/hellotriangle.vert")
                    fragmentShaderCode: loadSource("qrc:/shader/hellotriangle.frag")
                }
            }
        }
    }
}

And then in my root Entity:


Entity {
    id: root
    components: [
        RenderSettings {
            activeFrameGraph: colorBuffer
            pickingSettings.pickMethod: PickingSettings.TrianglePicking
            pickingSettings.pickResultMode: PickingSettings.NearestPick
        },
        InputSettings { }
    ]
    ClearBuffers {
        id: colorBuffer
        clearColor: Qt.rgba(0.8, 0.8, 0.8, 0.6)
        buffers: ClearBuffers.ColorDepthBuffer
        RenderSurfaceSelector {
            RenderStateSet {
                renderStates: DepthTest {
                    depthFunction: DepthTest.Less
                }
            }
        }
    }
}

It works, rendering two triangle. And I want to add Qt3D Camera and ObjectPicker in my scene, How can i make it?

I find that if i use ForwardRenderer(but i couldn't find a way to render my own lines/points vertices) instead of ClearBuffers, the Camera and ObjectPicker works

Mengyu Chen
  • 137
  • 6

0 Answers0