Qt3d. Draw transparent QSphereMesh over triangles
My mistake was that i did wrong order of creating and deletion of Triangles and Sphere entities.
In pseudo code right order is as follows:
clearTriangles();
clearSphere();
drawTriangles();
drawSphere();
Draw triangle with Qt3D
Your points are set in clockwise order you can reorder them or set a different behaviour via this link: doc.qt.io/qt-5.11/qt3drender-qcullface.html
If you need both i would give a try to Qt3DRender::QCullFace::NoCulling
Draw transparent image over the screen with Qt
I have tried your code and it works fine, apparently it seems to be a problem of the image, I recommend you to use some kind of external application to erase the transparent parts like this.
Here is a test that works with your code:
If you want to do this automatically I recommend you to use opencv.
GeometryRenderer Why render lines, but not Triangles
If I adapt your QML the following way then I can see two triangles:
import QtQuick 2.2
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Extras 2.0
Entity {
id: root
PhongMaterial { id: material; diffuse: Qt.rgba(0.8, 0., 0., 1.0) }
GeometryRenderer {
id: renderer
primitiveType: GeometryRenderer.Triangles
instanceCount: 1
geometry: Geometry {
Attribute {
name: defaultPositionAttributeName
attributeType: Attribute.VertexAttribute
vertexBaseType: Attribute.Float
vertexSize: 3
byteOffset: 0
byteStride: 3 * 4
count: 6
buffer: Buffer {
type: Buffer.VertexBuffer
data: new Float32Array([
// #1 triangle
-0.9, -0.5, 0.0,
-0.0, -0.5, 0.0,
-0.45, 0.5, 0.0,
// #2 triangle
0.0, -0.5, 0.0,
0.9, -0.5, 0.0,
0.45, 0.5, 0.0,
])
}
}
}
}
components: [ renderer, material ]
}
I suppose the error is related to the wrong hierarchy of GeometryRenderer and Entity.
To get correct lighting you need to give the GeometryRenderer the vertexNormals too.
Edit:
As it is a common question whether a GeometryRenderer
always needs an indexBuffer
for primitiveType: Triangles
, TriangleStrip
, and TriangleFan
, I'll come up with a somewhat more detailed answer.
A GeometryRenderer
of primitiveType: Triangles
does not necessarily need an index array (I checked the source code of Qt3D
as I was unsure).
The reason you are not seeing your triangles is: You are defining the vertices in the wrong order! Change the order of the vertices in the vertexBuffer
so that every three consecutive vertices form a triangle when going counterclockwise around the triangle. The triangle normal will then point at you.
Or, have a look onto your Entity from the opposite direction: you'll see the two triangles.
When using huge buffers and you don't want to repeat large amounts of vertices for memory/efficiency reasons you'll definitely should consider using an indexBuffer
.
Related Topics
How to Use Non-Default Delimiters When Reading a Text File with Std::Fstream
How to Call Derived Class Method from Base Class Pointer
Std::Map Default Value for Build-In Type
How to Securely Disconnect an Asio Ssl Socket
"Undefined Symbols" Linker Error with Simple Template Class
What Does "Void *(*)(Void *)" Mean in C++
How to Use Dynamic Name for Variables in C++
What Does "#Define Str(A) #A" Do
Opencv How to Select a Region of Image Irregularly with Mouse Event? C/C++
Sizeof in C++ Showing String Size One Less
What Is _Declspec and When Do I Need to Use It