Re: [Interest] Drawing a dashed line with Qt Quick 3D
Aswering my question about lineWith, there's a lineWith property in DefaultMaterial, but that may not always work according the docs "none of the following can be expected to support wide lines: Direct3D, Metal, OpenGL with core profile contexts." It worked or me in linux, but failed on mac, and windows. So I did a workaround by creating a line with 4 points with a TriangleStrip primitive, now it works for all the plataforms. It's solved !!! CheersJoão Em sexta-feira, 28 de maio de 2021 21:28:33 GMT+1, joao morgado via Interest escreveu: It works, thank you very much :) Two more questions: 1) If I want to make color1 fully transparent, I guess using the color alpha channel wont work, so maybe I have to make a custom shader to discard color1 pixels? Or do you have any other sugestions ? 2) Is there a equivalent to OpenGL glLineWidth(...) to make the lines thicker ? And something like glGetFloatv(GL_LINE_WIDTH, ...); ? Best regardsJoão Em sexta-feira, 28 de maio de 2021 19:59:19 GMT+1, Laszlo Agocs escreveu: #yiv4610245498 P {margin-top:0;margin-bottom:0;}Hi, The custom geometry lacks UV coordinates in your example application, and so it samples with texture coordinates (0, 0) for any fragment, hence getting a line with color0 instead of the expected color0-color1-color0-... Add two floats per vertex and register an attribute for TexCoord0: m_vertexData.resize(m_count * 5 * sizeof(float)); ... *p++ = 0.0f; // U *p++ = 0.0f; // V ... *p++ = 1.0f; // U *p++ = 0.0f; // V ... setStride(5 * sizeof(float)); addAttribute(QQuick3DGeometry::Attribute::PositionSemantic, 0, Attribute::F32Type); addAttribute(QQuick3DGeometry::Attribute::TexCoord0Semantic, 3 * sizeof(float), Attribute::F32Type); Best regards,Laszlo From: Interest on behalf of joao morgado via Interest Sent: Friday, May 28, 2021 6:07 PM To: interest@qt-project.org Subject: [Interest] Drawing a dashed line with Qt Quick 3D I'm trying to make a dashed line in quick3d. I made the line with QQuick3DGeometry, and exposed it to qml, all good.Then I tried to apply a custom texture with QQuick3DTextureData, using a texture made with 2 colors with size of 2x1 pixels, but I only get to see the first color. I sucessfully did in the past a dashed line example with raw OpenGL see here: Bitbucket | | | | Bitbucket | | | Here is the small qt quick 3d example that is failling: LineDashed.zip | | | | LineDashed.zip | | | Any help is welcome. The relevant code is: // main.qmlView3D { id: view3D visible: true anchors.fill: parent .. importScene: sceneRoot Node { id: sceneRoot .. // solid line, all good Line { p0: Qt.vector3d(-55, 55, 0) p1: Qt.vector3d(55, -55, 0) baseColor: "red" //visible: false } // dashed line, error: only the first color is show Line_dashed { p0: Qt.vector3d(-80, -40, 0) p1: Qt.vector3d(80, 80, 0) color1: "orange" color2: "yellow" //visible: false } }//Node: sceneRoot }//View3D} // Line_dashed.qml import QtQuick 2.12import QtQuick3D 1.15import Entity_Line 1.0import LineTexture 1.0 Node { property alias p0: line.p0 property alias p1: line.p1 property alias color1: lineTex.color1 property alias color2: lineTex.color2 Model { geometry: EntityLine { id: line p0: Qt.vector3d(-55, -55, 50) p1: Qt.vector3d(55, 55, 50) } materials: DefaultMaterial { id: material lighting: DefaultMaterial.NoLighting diffuseMap: Texture { textureData: LineTexture { id: lineTex //color1: "blue" //color2: "white" } magFilter: Texture.Nearest minFilter: Texture.Nearest mappingMode: Texture.UV scaleU: 2 scaleV: 1 } } pickable: true property bool isPicked: false }} // custom texture void LineTexture::generateTextureData(){ m_textureData.resize(2 * 4 * sizeof (float)); //QByteArray float *p = reinterpret_cast(m_textureData.data()); *p++ = m_color1.redF(); *p++ = m_color1.greenF(); *p++ = m_color1.blueF(); *p++ = m_color1.alphaF(); *p++ = m_color2.redF(); *p++ = m_color2.greenF(); *p++ = m_color2.blueF(); *p++ = m_color2.alphaF(); setTextureData(m_textureData); setSize(QSize(2,1)); //setFormat(QQuick3DTextureData::Format::RGBA8); setFormat(QQuick3DTextureData::Format::RGBA32F); setHasTransparency(true);} CheersJoão
Re: [Interest] Drawing a dashed line with Qt Quick 3D
It works, thank you very much :) Two more questions: 1) If I want to make color1 fully transparent, I guess using the color alpha channel wont work, so maybe I have to make a custom shader to discard color1 pixels? Or do you have any other sugestions ? 2) Is there a equivalent to OpenGL glLineWidth(...) to make the lines thicker ? And something like glGetFloatv(GL_LINE_WIDTH, ...); ? Best regardsJoão Em sexta-feira, 28 de maio de 2021 19:59:19 GMT+1, Laszlo Agocs escreveu: #yiv1622565661 P {margin-top:0;margin-bottom:0;}Hi, The custom geometry lacks UV coordinates in your example application, and so it samples with texture coordinates (0, 0) for any fragment, hence getting a line with color0 instead of the expected color0-color1-color0-... Add two floats per vertex and register an attribute for TexCoord0: m_vertexData.resize(m_count * 5 * sizeof(float)); ... *p++ = 0.0f; // U *p++ = 0.0f; // V ... *p++ = 1.0f; // U *p++ = 0.0f; // V ... setStride(5 * sizeof(float)); addAttribute(QQuick3DGeometry::Attribute::PositionSemantic, 0, Attribute::F32Type); addAttribute(QQuick3DGeometry::Attribute::TexCoord0Semantic, 3 * sizeof(float), Attribute::F32Type); Best regards,Laszlo From: Interest on behalf of joao morgado via Interest Sent: Friday, May 28, 2021 6:07 PM To: interest@qt-project.org Subject: [Interest] Drawing a dashed line with Qt Quick 3D I'm trying to make a dashed line in quick3d. I made the line with QQuick3DGeometry, and exposed it to qml, all good.Then I tried to apply a custom texture with QQuick3DTextureData, using a texture made with 2 colors with size of 2x1 pixels, but I only get to see the first color. I sucessfully did in the past a dashed line example with raw OpenGL see here: Bitbucket | | | | Bitbucket | | | Here is the small qt quick 3d example that is failling: LineDashed.zip | | | | LineDashed.zip | | | Any help is welcome. The relevant code is: // main.qmlView3D { id: view3D visible: true anchors.fill: parent .. importScene: sceneRoot Node { id: sceneRoot .. // solid line, all good Line { p0: Qt.vector3d(-55, 55, 0) p1: Qt.vector3d(55, -55, 0) baseColor: "red" //visible: false } // dashed line, error: only the first color is show Line_dashed { p0: Qt.vector3d(-80, -40, 0) p1: Qt.vector3d(80, 80, 0) color1: "orange" color2: "yellow" //visible: false } }//Node: sceneRoot }//View3D} // Line_dashed.qml import QtQuick 2.12import QtQuick3D 1.15import Entity_Line 1.0import LineTexture 1.0 Node { property alias p0: line.p0 property alias p1: line.p1 property alias color1: lineTex.color1 property alias color2: lineTex.color2 Model { geometry: EntityLine { id: line p0: Qt.vector3d(-55, -55, 50) p1: Qt.vector3d(55, 55, 50) } materials: DefaultMaterial { id: material lighting: DefaultMaterial.NoLighting diffuseMap: Texture { textureData: LineTexture { id: lineTex //color1: "blue" //color2: "white" } magFilter: Texture.Nearest minFilter: Texture.Nearest mappingMode: Texture.UV scaleU: 2 scaleV: 1 } } pickable: true property bool isPicked: false }} // custom texture void LineTexture::generateTextureData(){ m_textureData.resize(2 * 4 * sizeof (float)); //QByteArray float *p = reinterpret_cast(m_textureData.data()); *p++ = m_color1.redF(); *p++ = m_color1.greenF(); *p++ = m_color1.blueF(); *p++ = m_color1.alphaF(); *p++ = m_color2.redF(); *p++ = m_color2.greenF(); *p++ = m_color2.blueF(); *p++ = m_color2.alphaF(); setTextureData(m_textureData); setSize(QSize(2,1)); //setFormat(QQuick3DTextureData::Format::RGBA8); setFormat(QQuick3DTextureData::Format::RGBA32F); setHasTransparency(true);} CheersJoão ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
Re: [Interest] Drawing a dashed line with Qt Quick 3D
Hi, The custom geometry lacks UV coordinates in your example application, and so it samples with texture coordinates (0, 0) for any fragment, hence getting a line with color0 instead of the expected color0-color1-color0-... Add two floats per vertex and register an attribute for TexCoord0: m_vertexData.resize(m_count * 5 * sizeof(float)); ... *p++ = 0.0f; // U *p++ = 0.0f; // V ... *p++ = 1.0f; // U *p++ = 0.0f; // V ... setStride(5 * sizeof(float)); addAttribute(QQuick3DGeometry::Attribute::PositionSemantic, 0, Attribute::F32Type); addAttribute(QQuick3DGeometry::Attribute::TexCoord0Semantic, 3 * sizeof(float), Attribute::F32Type); Best regards, Laszlo From: Interest on behalf of joao morgado via Interest Sent: Friday, May 28, 2021 6:07 PM To: interest@qt-project.org Subject: [Interest] Drawing a dashed line with Qt Quick 3D I'm trying to make a dashed line in quick3d. I made the line with QQuick3DGeometry, and exposed it to qml, all good. Then I tried to apply a custom texture with QQuick3DTextureData, using a texture made with 2 colors with size of 2x1 pixels, but I only get to see the first color. I sucessfully did in the past a dashed line example with raw OpenGL see here: Bitbucket<https://bitbucket.org/joaodeusmorgado/opengltutorials/src/master/T07.1_TextureLines/mygl.cpp> <https://bitbucket.org/joaodeusmorgado/opengltutorials/src/master/T07.1_TextureLines/mygl.cpp> Bitbucket Here is the small qt quick 3d example that is failling: LineDashed.zip<https://drive.google.com/file/d/1ND5xsCLCdM2zK35Yt8PbOaC3ycTleKwc/view?usp=sharing> <https://drive.google.com/file/d/1ND5xsCLCdM2zK35Yt8PbOaC3ycTleKwc/view?usp=sharing> [https://s.yimg.com/lb/brands/80x80_google.png] LineDashed.zip Any help is welcome. The relevant code is: // main.qml View3D { id: view3D visible: true anchors.fill: parent .. importScene: sceneRoot Node { id: sceneRoot .. // solid line, all good Line { p0: Qt.vector3d(-55, 55, 0) p1: Qt.vector3d(55, -55, 0) baseColor: "red" //visible: false } // dashed line, error: only the first color is show Line_dashed { p0: Qt.vector3d(-80, -40, 0) p1: Qt.vector3d(80, 80, 0) color1: "orange" color2: "yellow" //visible: false } }//Node: sceneRoot }//View3D } // Line_dashed.qml import QtQuick 2.12 import QtQuick3D 1.15 import Entity_Line 1.0 import LineTexture 1.0 Node { property alias p0: line.p0 property alias p1: line.p1 property alias color1: lineTex.color1 property alias color2: lineTex.color2 Model { geometry: EntityLine { id: line p0: Qt.vector3d(-55, -55, 50) p1: Qt.vector3d(55, 55, 50) } materials: DefaultMaterial { id: material lighting: DefaultMaterial.NoLighting diffuseMap: Texture { textureData: LineTexture { id: lineTex //color1: "blue" //color2: "white" } magFilter: Texture.Nearest minFilter: Texture.Nearest mappingMode: Texture.UV scaleU: 2 scaleV: 1 } } pickable: true property bool isPicked: false } } // custom texture void LineTexture::generateTextureData() { m_textureData.resize(2 * 4 * sizeof (float)); //QByteArray float *p = reinterpret_cast(m_textureData.data()); *p++ = m_color1.redF(); *p++ = m_color1.greenF(); *p++ = m_color1.blueF(); *p++ = m_color1.alphaF(); *p++ = m_color2.redF(); *p++ = m_color2.greenF(); *p++ = m_color2.blueF(); *p++ = m_color2.alphaF(); setTextureData(m_textureData); setSize(QSize(2,1)); //setFormat(QQuick3DTextureData::Format::RGBA8); setFormat(QQuick3DTextureData::Format::RGBA32F); setHasTransparency(true); } Cheers João ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest
[Interest] Drawing a dashed line with Qt Quick 3D
I'm trying to make a dashed line in quick3d. I made the line with QQuick3DGeometry, and exposed it to qml, all good.Then I tried to apply a custom texture with QQuick3DTextureData, using a texture made with 2 colors with size of 2x1 pixels, but I only get to see the first color. I sucessfully did in the past a dashed line example with raw OpenGL see here: Bitbucket | | | | Bitbucket | | | Here is the small qt quick 3d example that is failling: LineDashed.zip | | | | LineDashed.zip | | | Any help is welcome. The relevant code is: // main.qmlView3D { id: view3D visible: true anchors.fill: parent .. importScene: sceneRoot Node { id: sceneRoot .. // solid line, all good Line { p0: Qt.vector3d(-55, 55, 0) p1: Qt.vector3d(55, -55, 0) baseColor: "red" //visible: false } // dashed line, error: only the first color is show Line_dashed { p0: Qt.vector3d(-80, -40, 0) p1: Qt.vector3d(80, 80, 0) color1: "orange" color2: "yellow" //visible: false } }//Node: sceneRoot }//View3D} // Line_dashed.qml import QtQuick 2.12import QtQuick3D 1.15import Entity_Line 1.0import LineTexture 1.0 Node { property alias p0: line.p0 property alias p1: line.p1 property alias color1: lineTex.color1 property alias color2: lineTex.color2 Model { geometry: EntityLine { id: line p0: Qt.vector3d(-55, -55, 50) p1: Qt.vector3d(55, 55, 50) } materials: DefaultMaterial { id: material lighting: DefaultMaterial.NoLighting diffuseMap: Texture { textureData: LineTexture { id: lineTex //color1: "blue" //color2: "white" } magFilter: Texture.Nearest minFilter: Texture.Nearest mappingMode: Texture.UV scaleU: 2 scaleV: 1 } } pickable: true property bool isPicked: false }} // custom texture void LineTexture::generateTextureData(){ m_textureData.resize(2 * 4 * sizeof (float)); //QByteArray float *p = reinterpret_cast(m_textureData.data()); *p++ = m_color1.redF(); *p++ = m_color1.greenF(); *p++ = m_color1.blueF(); *p++ = m_color1.alphaF(); *p++ = m_color2.redF(); *p++ = m_color2.greenF(); *p++ = m_color2.blueF(); *p++ = m_color2.alphaF(); setTextureData(m_textureData); setSize(QSize(2,1)); //setFormat(QQuick3DTextureData::Format::RGBA8); setFormat(QQuick3DTextureData::Format::RGBA32F); setHasTransparency(true);} CheersJoão ___ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest