| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
import Qt3D.Render 2.0 |
| 5 |
|
| 6 |
// TODO: Once support for meshes from arrays is implemented, replace ring.obj with that |
| 7 |
Mesh { |
| 8 |
property real innerRadius |
| 9 |
property real outerRadius |
| 10 |
/* |
| 11 |
property real ringSegments |
| 12 |
|
| 13 |
property var vertices: [] |
| 14 |
property var faces: [] |
| 15 |
property var faceVertexUvs: [] |
| 16 |
*/ |
| 17 |
|
| 18 |
source: "qrc:/meshes/ring.obj" |
| 19 |
|
| 20 |
// Converted from the _RingGeometry() method in the threex.planets.js extension. |
| 21 |
/* |
| 22 |
function makeRing() { |
| 23 |
innerRadius = innerRadius || 0 |
| 24 |
outerRadius = outerRadius || 50 |
| 25 |
var thetaSegments = ringSegments || 8 |
| 26 |
console.log(innerRadius + "," + outerRadius + "," + thetaSegments) |
| 27 |
|
| 28 |
var normal = Qt.vector3d(0, 0, 1) |
| 29 |
|
| 30 |
for (var i = 0; i < thetaSegments; i++) { |
| 31 |
var angleLo = (i / thetaSegments) * Math.PI * 2 |
| 32 |
var angleHi = ((i + 1) / thetaSegments) * Math.PI * 2 |
| 33 |
|
| 34 |
var vertex1 = Qt.vector3d(innerRadius * Math.cos(angleLo), |
| 35 |
innerRadius * Math.sin(angleLo), |
| 36 |
0) |
| 37 |
var vertex2 = Qt.vector3d(outerRadius * Math.cos(angleLo), |
| 38 |
outerRadius * Math.sin(angleLo), |
| 39 |
0) |
| 40 |
var vertex3 = Qt.vector3d(innerRadius * Math.cos(angleHi), |
| 41 |
innerRadius * Math.sin(angleHi), |
| 42 |
0) |
| 43 |
var vertex4 = Qt.vector3d(outerRadius * Math.cos(angleHi), |
| 44 |
outerRadius * Math.sin(angleHi), |
| 45 |
0) |
| 46 |
|
| 47 |
vertices.push(vertex1) |
| 48 |
vertices.push(vertex2) |
| 49 |
vertices.push(vertex3) |
| 50 |
vertices.push(vertex4) |
| 51 |
|
| 52 |
var vertexIdx = i * 4 |
| 53 |
|
| 54 |
// Create the first triangle |
| 55 |
var face = Qt.vector4d(vertexIdx + 0, vertexIdx + 1, vertexIdx + 2, normal) |
| 56 |
var uvs = [] |
| 57 |
|
| 58 |
var uv = Qt.vector2d(0, 0) |
| 59 |
uvs.push(uv) |
| 60 |
uv = Qt.vector2d(1, 0) |
| 61 |
uvs.push(uv) |
| 62 |
uv = Qt.vector2d(0, 1) |
| 63 |
uvs.push(uv) |
| 64 |
|
| 65 |
faces.push(face) |
| 66 |
//faceVertexUvs[0].push(uvs) |
| 67 |
faceVertexUvs.push(uvs) |
| 68 |
|
| 69 |
// Create the second triangle |
| 70 |
face = Qt.vector4d(vertexIdx + 2, vertexIdx + 1, vertexIdx + 3, normal) |
| 71 |
uvs = [] |
| 72 |
|
| 73 |
uv = Qt.vector2d(0, 1) |
| 74 |
uvs.push(uv) |
| 75 |
uv = Qt.vector2d(1, 0) |
| 76 |
uvs.push(uv) |
| 77 |
uv = Qt.vector2d(1, 1) |
| 78 |
uvs.push(uv) |
| 79 |
|
| 80 |
faces.push(face) |
| 81 |
//faceVertexUvs[0].push(uvs) |
| 82 |
faceVertexUvs.push(uvs) |
| 83 |
} |
| 84 |
|
| 85 |
computeFaceNormals() |
| 86 |
} |
| 87 |
|
| 88 |
// Converted from the computeFaceNormals() method in the three.js extension. |
| 89 |
function computeFaceNormals() { |
| 90 |
var cb = Qt.vector3d(0, 0, 0) |
| 91 |
var ab = Qt.vector3d(0, 0, 0) |
| 92 |
|
| 93 |
for (var f = 0, fl = faces.length; f < fl; f ++) { |
| 94 |
var face = faces[f] |
| 95 |
|
| 96 |
var vA = vertices[face.x] |
| 97 |
var vB = vertices[face.y] |
| 98 |
var vC = vertices[face.z] |
| 99 |
|
| 100 |
cb = vC.minus(vB) |
| 101 |
ab = vA.minus(vB) |
| 102 |
cb = cb.crossProduct(ab) |
| 103 |
|
| 104 |
cb = cb.normalized() |
| 105 |
|
| 106 |
face.w = cb |
| 107 |
} |
| 108 |
} |
| 109 |
*/ |
| 110 |
} |
| 111 |
|
| 112 |
|