| 1 |
// Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import Qt3D.Core 2.0 |
| 5 |
import Qt3D.Render 2.0 |
| 6 |
import Qt3D.Input 2.0 |
| 7 |
import Qt3D.Extras 2.0 |
| 8 |
|
| 9 |
Entity { |
| 10 |
id: root |
| 11 |
|
| 12 |
property vector3d origin |
| 13 |
property vector3d direction |
| 14 |
property real length: 1 |
| 15 |
|
| 16 |
components: [ mesh, material ] |
| 17 |
|
| 18 |
function buildVertexBufferData(o, d, l) { |
| 19 |
// Vertices |
| 20 |
var v0 = o |
| 21 |
var v1 = o.plus(d.times(l)) |
| 22 |
|
| 23 |
var vertices = [ v1, v0 ] |
| 24 |
|
| 25 |
var vertexArray = new Float32Array(vertices.length * 3); |
| 26 |
var i = 0; |
| 27 |
|
| 28 |
vertices.forEach(function(vec3) { |
| 29 |
vertexArray[i++] = vec3.x; |
| 30 |
vertexArray[i++] = vec3.y; |
| 31 |
vertexArray[i++] = vec3.z; |
| 32 |
}); |
| 33 |
|
| 34 |
return vertexArray; |
| 35 |
} |
| 36 |
|
| 37 |
Buffer { |
| 38 |
id: vertexBuffer |
| 39 |
data: buildVertexBufferData(root.origin, root.direction, root.length) |
| 40 |
} |
| 41 |
|
| 42 |
GeometryRenderer { |
| 43 |
id: mesh |
| 44 |
instanceCount: 1 |
| 45 |
indexOffset: 0 |
| 46 |
firstInstance: 0 |
| 47 |
primitiveType: GeometryRenderer.Lines |
| 48 |
|
| 49 |
geometry: Geometry { |
| 50 |
Attribute { |
| 51 |
attributeType: Attribute.VertexAttribute |
| 52 |
vertexBaseType: Attribute.Float |
| 53 |
vertexSize: 3 |
| 54 |
byteOffset: 0 |
| 55 |
count: 2 |
| 56 |
name: defaultPositionAttributeName |
| 57 |
buffer: vertexBuffer |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
LineMaterial { |
| 63 |
id: material |
| 64 |
maincolor: "white" |
| 65 |
} |
| 66 |
} |