[Interest] Drawing a dashed line with Qt Quick 3D

joao morgado joaodeusmorgado at yahoo.com
Sun May 30 14:57:39 CEST 2021


 
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 <interest at qt-project.org> 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 <laszlo.agocs at qt.io> 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 <interest-bounces at qt-project.org> on behalf of joao morgado via Interest <interest at qt-project.org>
Sent: Friday, May 28, 2021 6:07 PM
To: interest at qt-project.org <interest at 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<float *>(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 at qt-project.org
https://lists.qt-project.org/listinfo/interest
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210530/d4704c87/attachment.html>


More information about the Interest mailing list