1// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qcuboidgeometry.h"
5#include "qcuboidgeometry_p.h"
6
7#include <Qt3DCore/qattribute.h>
8#include <Qt3DCore/qbuffer.h>
9#include <Qt3DCore/private/corelogging_p.h>
10
11#include <limits>
12
13
14QT_BEGIN_NAMESPACE
15
16using namespace Qt3DCore;
17
18namespace Qt3DExtras {
19
20namespace {
21
22enum PlaneNormal {
23 PositiveX,
24 NegativeX,
25 PositiveY,
26 NegativeY,
27 PositiveZ,
28 NegativeZ
29};
30
31void createPlaneVertexData(float w, float h, const QSize &resolution,
32 PlaneNormal normal, float planeDistance,
33 float *vertices)
34{
35 const float a0 = -w / 2.0f;
36 const float b0 = -h / 2.0f;
37 const float da = w / (resolution.width() - 1);
38 const float db = h / (resolution.height() - 1);
39 const float du = 1.0f / (resolution.width() - 1);
40 const float dv = 1.0f / (resolution.height() - 1);
41
42 switch (normal) {
43 case NegativeX:
44 // Iterate over z
45 for (int j = resolution.height() - 1; j >= 0; --j) {
46 const float b = b0 + static_cast<float>(j) * db;
47 const float v = static_cast<float>(j) * dv;
48
49 // Iterate over y
50 for (int i = 0; i < resolution.width(); ++i) {
51 const float a = a0 + static_cast<float>(i) * da;
52 const float u = static_cast<float>(i) * du;
53
54 // position
55 *vertices++ = planeDistance;
56 *vertices++ = a;
57 *vertices++ = b;
58
59 // texture coordinates
60 *vertices++ = v;
61 *vertices++ = u;
62
63 // normal
64 *vertices++ = -1.0f;
65 *vertices++ = 0.0f;
66 *vertices++ = 0.0f;
67
68 // tangent
69 *vertices++ = 0.0f;
70 *vertices++ = 0.0f;
71 *vertices++ = 1.0f;
72 *vertices++ = 1.0f;
73 }
74 }
75 break;
76
77 case PositiveX: {
78 // Iterate over z
79 for (int j = 0; j < resolution.height(); ++j) {
80 const float b = b0 + static_cast<float>(j) * db;
81 const float v = static_cast<float>(j) * dv;
82
83 // Iterate over y
84 for (int i = 0; i < resolution.width(); ++i) {
85 const float a = a0 + static_cast<float>(i) * da;
86 const float u = static_cast<float>(i) * du;
87
88 // position
89 *vertices++ = planeDistance;
90 *vertices++ = a;
91 *vertices++ = b;
92
93 // texture coordinates
94 *vertices++ = 1.0f - v;
95 *vertices++ = u;
96
97 // normal
98 *vertices++ = 1.0f;
99 *vertices++ = 0.0f;
100 *vertices++ = 0.0f;
101
102 // tangent
103 *vertices++ = 0.0f;
104 *vertices++ = 0.0f;
105 *vertices++ = -1.0f;
106 *vertices++ = 1.0f;
107 }
108 }
109 break;
110 }
111
112 case NegativeY:
113 // Iterate over z
114 for (int j = 0; j < resolution.height(); ++j) {
115 const float b = b0 + static_cast<float>(j) * db;
116 const float v = static_cast<float>(j) * dv;
117
118 // Iterate over x
119 // This iterates in the opposite sense to the other directions
120 // so that the winding order is correct
121 for (int i = 0; i < resolution.width(); ++i) {
122 const float a = a0 + static_cast<float>(i) * da;
123 const float u = static_cast<float>(i) * du;
124
125 // position
126 *vertices++ = a;
127 *vertices++ = planeDistance;
128 *vertices++ = b;
129
130 // texture coordinates
131 *vertices++ = u;
132 *vertices++ = v;
133
134 // normal
135 *vertices++ = 0.0f;
136 *vertices++ = -1.0f;
137 *vertices++ = 0.0f;
138
139 // tangent
140 *vertices++ = 1.0f;
141 *vertices++ = 0.0f;
142 *vertices++ = 0.0f;
143 *vertices++ = 1.0f;
144 }
145 }
146 break;
147
148 case PositiveY: {
149 // Iterate over z
150 for (int j = resolution.height() - 1; j >= 0; --j) {
151 const float b = b0 + static_cast<float>(j) * db;
152 const float v = static_cast<float>(j) * dv;
153
154 // Iterate over x
155 // This iterates in the opposite sense to the other directions
156 // so that the winding order is correct
157 for (int i = 0; i < resolution.width(); ++i) {
158 const float a = a0 + static_cast<float>(i) * da;
159 const float u = static_cast<float>(i) * du;
160
161 // position
162 *vertices++ = a;
163 *vertices++ = planeDistance;
164 *vertices++ = b;
165
166 // texture coordinates
167 *vertices++ = u;
168 *vertices++ = 1.0f - v;
169
170 // normal
171 *vertices++ = 0.0f;
172 *vertices++ = 1.0f;
173 *vertices++ = 0.0f;
174
175 // tangent
176 *vertices++ = 1.0f;
177 *vertices++ = 0.0f;
178 *vertices++ = 0.0f;
179 *vertices++ = 1.0f;
180 }
181 }
182 break;
183 }
184
185 case NegativeZ:
186 // Iterate over y
187 for (int j = 0; j < resolution.height(); ++j) {
188 const float b = b0 + static_cast<float>(j) * db;
189 const float v = static_cast<float>(j) * dv;
190
191 // Iterate over x
192 for (int i = resolution.width() - 1; i >= 0; --i) {
193 const float a = a0 + static_cast<float>(i) * da;
194 const float u = static_cast<float>(i) * du;
195
196 // position
197 *vertices++ = a;
198 *vertices++ = b;
199 *vertices++ = planeDistance;
200
201 // texture coordinates
202 *vertices++ = 1.0f - u;
203 *vertices++ = v;
204
205 // normal
206 *vertices++ = 0.0f;
207 *vertices++ = 0.0f;
208 *vertices++ = -1.0f;
209
210 // tangent
211 *vertices++ = -1.0f;
212 *vertices++ = 0.0f;
213 *vertices++ = 0.0f;
214 *vertices++ = 1.0f;
215 }
216 }
217 break;
218
219 case PositiveZ: {
220 // Iterate over y
221 for (int j = 0; j < resolution.height(); ++j) {
222 const float b = b0 + static_cast<float>(j) * db;
223 const float v = static_cast<float>(j) * dv;
224
225 // Iterate over x
226 for (int i = 0; i < resolution.width(); ++i) {
227 const float a = a0 + static_cast<float>(i) * da;
228 const float u = static_cast<float>(i) * du;
229
230 // position
231 *vertices++ = a;
232 *vertices++ = b;
233 *vertices++ = planeDistance;
234
235 // texture coordinates
236 *vertices++ = u;
237 *vertices++ = v;
238
239 // normal
240 *vertices++ = 0.0f;
241 *vertices++ = 0.0f;
242 *vertices++ = 1.0f;
243
244 // tangent
245 *vertices++ = 1.0f;
246 *vertices++ = 0.0f;
247 *vertices++ = 0.0f;
248 *vertices++ = 1.0f;
249 }
250 }
251 break;
252 }
253 } // switch (normal)
254}
255
256void createPlaneIndexData(const QSize &resolution, quint16 *indices, quint16 &baseVertex)
257{
258 // Populate indices taking care to get correct CCW winding on all faces
259 // Iterate over v direction (rows)
260 for (int j = 0; j < resolution.height() - 1; ++j) {
261 const int rowStartIndex = j * resolution.width() + baseVertex;
262 const int nextRowStartIndex = (j + 1) * resolution.width() + baseVertex;
263
264 // Iterate over u direction (columns)
265 for (int i = 0; i < resolution.width() - 1; ++i) {
266 // Split quad into two triangles
267 *indices++ = rowStartIndex + i;
268 *indices++ = rowStartIndex + i + 1;
269 *indices++ = nextRowStartIndex + i;
270
271 *indices++ = nextRowStartIndex + i;
272 *indices++ = rowStartIndex + i + 1;
273 *indices++ = nextRowStartIndex + i + 1;
274 }
275 }
276 baseVertex += resolution.width() * resolution.height();
277}
278
279QByteArray createCuboidVertexData(float xExtent,
280 float yExtent,
281 float zExtent,
282 const QSize &yzResolution,
283 const QSize &xzResolution,
284 const QSize &xyResolution)
285{
286 Q_ASSERT(xExtent > 0.0f && yExtent > 0.0f && zExtent > 0.0);
287 Q_ASSERT(yzResolution.width() >= 2 && yzResolution.height() >=2);
288 Q_ASSERT(xzResolution.width() >= 2 && xzResolution.height() >=2);
289 Q_ASSERT(xyResolution.width() >= 2 && xyResolution.height() >=2);
290
291 const int yzVerts = yzResolution.width() * yzResolution.height();
292 const int xzVerts = xzResolution.width() * xzResolution.height();
293 const int xyVerts = xyResolution.width() * xyResolution.height();
294 const int nVerts = 2 * (yzVerts + xzVerts + xyVerts);
295
296 const quint32 elementSize = 3 + 3 + 2 + 4;
297 const quint32 stride = elementSize * sizeof(float);
298 QByteArray vertexBytes;
299 vertexBytes.resize(size: stride * nVerts);
300 float* vertices = reinterpret_cast<float*>(vertexBytes.data());
301
302 createPlaneVertexData(w: yExtent, h: zExtent, resolution: yzResolution, normal: PositiveX, planeDistance: xExtent * 0.5f, vertices);
303 vertices += yzVerts * elementSize;
304 createPlaneVertexData(w: yExtent, h: zExtent, resolution: yzResolution, normal: NegativeX, planeDistance: -xExtent * 0.5f, vertices);
305 vertices += yzVerts * elementSize;
306 createPlaneVertexData(w: xExtent, h: zExtent, resolution: xzResolution, normal: PositiveY, planeDistance: yExtent * 0.5f, vertices);
307 vertices += xzVerts * elementSize;
308 createPlaneVertexData(w: xExtent, h: zExtent, resolution: xzResolution, normal: NegativeY, planeDistance: -yExtent * 0.5f, vertices);
309 vertices += xzVerts * elementSize;
310 createPlaneVertexData(w: xExtent, h: yExtent, resolution: xyResolution, normal: PositiveZ, planeDistance: zExtent * 0.5f, vertices);
311 vertices += xyVerts * elementSize;
312 createPlaneVertexData(w: xExtent, h: yExtent, resolution: xyResolution, normal: NegativeZ, planeDistance: -zExtent * 0.5f, vertices);
313
314 return vertexBytes;
315}
316
317QByteArray createCuboidIndexData(const QSize &yzResolution,
318 const QSize &xzResolution,
319 const QSize &xyResolution)
320{
321 Q_ASSERT(yzResolution.width() >= 2 && yzResolution.height() >= 2);
322 Q_ASSERT(xzResolution.width() >= 2 && xzResolution.height() >= 2);
323 Q_ASSERT(xyResolution.width() >= 2 && xyResolution.height() >= 2);
324
325 const int yzIndices = 2 * 3 * (yzResolution.width() - 1) * (yzResolution.height() - 1);
326 const int xzIndices = 2 * 3 * (xzResolution.width() - 1) * (xzResolution.height() - 1);
327 const int xyIndices = 2 * 3 * (xyResolution.width() - 1) * (xyResolution.height() - 1);
328 const qsizetype indexCount = 2 * (yzIndices + xzIndices + xyIndices);
329
330 QByteArray indexData;
331 indexData.resize(size: indexCount * sizeof(quint16));
332 quint16 *indices = reinterpret_cast<quint16 *>(indexData.data());
333 quint16 baseIndex = 0;
334
335 createPlaneIndexData(resolution: yzResolution, indices, baseVertex&: baseIndex);
336 indices += yzIndices;
337 createPlaneIndexData(resolution: yzResolution, indices, baseVertex&: baseIndex);
338 indices += yzIndices;
339 createPlaneIndexData(resolution: xzResolution, indices, baseVertex&: baseIndex);
340 indices += xzIndices;
341 createPlaneIndexData(resolution: xzResolution, indices, baseVertex&: baseIndex);
342 indices += xzIndices;
343 createPlaneIndexData(resolution: xyResolution, indices, baseVertex&: baseIndex);
344 indices += xyIndices;
345 createPlaneIndexData(resolution: xyResolution, indices, baseVertex&: baseIndex);
346
347 return indexData;
348}
349
350} // anonymous
351
352QCuboidGeometryPrivate::QCuboidGeometryPrivate()
353 : QGeometryPrivate()
354 , m_xExtent(1.0f)
355 , m_yExtent(1.0f)
356 , m_zExtent(1.0f)
357 , m_yzFaceResolution(2, 2)
358 , m_xzFaceResolution(2, 2)
359 , m_xyFaceResolution(2, 2)
360 , m_positionAttribute(nullptr)
361 , m_normalAttribute(nullptr)
362 , m_texCoordAttribute(nullptr)
363 , m_tangentAttribute(nullptr)
364 , m_indexAttribute(nullptr)
365 , m_vertexBuffer(nullptr)
366 , m_indexBuffer(nullptr)
367{
368}
369
370void QCuboidGeometryPrivate::init()
371{
372 Q_Q(QCuboidGeometry);
373 m_positionAttribute = new Qt3DCore::QAttribute(q);
374 m_normalAttribute = new Qt3DCore::QAttribute(q);
375 m_texCoordAttribute = new Qt3DCore::QAttribute(q);
376 m_tangentAttribute = new Qt3DCore::QAttribute(q);
377 m_indexAttribute = new Qt3DCore::QAttribute(q);
378 m_vertexBuffer = new Qt3DCore::QBuffer(q);
379 m_indexBuffer = new Qt3DCore::QBuffer(q);
380
381 // vec3 pos vec2 tex vec3 normal vec4 tangent
382 const quint32 stride = (3 + 2 + 3 + 4) * sizeof(float);
383 const int yzIndices = 2 * 3 * (m_yzFaceResolution.width() - 1) * (m_yzFaceResolution.height() - 1);
384 const int xzIndices = 2 * 3 * (m_xzFaceResolution.width() - 1) * (m_xzFaceResolution.height() - 1);
385 const int xyIndices = 2 * 3 * (m_xyFaceResolution.width() - 1) * (m_xyFaceResolution.height() - 1);
386 const int yzVerts = m_yzFaceResolution.width() * m_yzFaceResolution.height();
387 const int xzVerts = m_xzFaceResolution.width() * m_xzFaceResolution.height();
388 const int xyVerts = m_xyFaceResolution.width() * m_xyFaceResolution.height();
389
390 const int nVerts = 2 * (yzVerts + xzVerts + xyVerts);
391 const int indexCount = 2 * (yzIndices + xzIndices + xyIndices);
392
393 m_positionAttribute->setName(QAttribute::defaultPositionAttributeName());
394 m_positionAttribute->setVertexBaseType(QAttribute::Float);
395 m_positionAttribute->setVertexSize(3);
396 m_positionAttribute->setAttributeType(QAttribute::VertexAttribute);
397 m_positionAttribute->setBuffer(m_vertexBuffer);
398 m_positionAttribute->setByteStride(stride);
399 m_positionAttribute->setCount(nVerts);
400
401 m_texCoordAttribute->setName(QAttribute::defaultTextureCoordinateAttributeName());
402 m_texCoordAttribute->setVertexBaseType(QAttribute::Float);
403 m_texCoordAttribute->setVertexSize(2);
404 m_texCoordAttribute->setAttributeType(QAttribute::VertexAttribute);
405 m_texCoordAttribute->setBuffer(m_vertexBuffer);
406 m_texCoordAttribute->setByteStride(stride);
407 m_texCoordAttribute->setByteOffset(3 * sizeof(float));
408 m_texCoordAttribute->setCount(nVerts);
409
410 m_normalAttribute->setName(QAttribute::defaultNormalAttributeName());
411 m_normalAttribute->setVertexBaseType(QAttribute::Float);
412 m_normalAttribute->setVertexSize(3);
413 m_normalAttribute->setAttributeType(QAttribute::VertexAttribute);
414 m_normalAttribute->setBuffer(m_vertexBuffer);
415 m_normalAttribute->setByteStride(stride);
416 m_normalAttribute->setByteOffset(5 * sizeof(float));
417 m_normalAttribute->setCount(nVerts);
418
419 m_tangentAttribute->setName(QAttribute::defaultTangentAttributeName());
420 m_tangentAttribute->setVertexBaseType(QAttribute::Float);
421 m_tangentAttribute->setVertexSize(4);
422 m_tangentAttribute->setAttributeType(QAttribute::VertexAttribute);
423 m_tangentAttribute->setBuffer(m_vertexBuffer);
424 m_tangentAttribute->setByteStride(stride);
425 m_tangentAttribute->setByteOffset(8 * sizeof(float));
426 m_tangentAttribute->setCount(nVerts);
427
428 m_indexAttribute->setAttributeType(QAttribute::IndexAttribute);
429 m_indexAttribute->setVertexBaseType(QAttribute::UnsignedShort);
430 m_indexAttribute->setBuffer(m_indexBuffer);
431
432 m_indexAttribute->setCount(indexCount);
433
434 m_vertexBuffer->setData(generateVertexData());
435 m_indexBuffer->setData(generateIndexData());
436
437 q->addAttribute(attribute: m_positionAttribute);
438 q->addAttribute(attribute: m_texCoordAttribute);
439 q->addAttribute(attribute: m_normalAttribute);
440 q->addAttribute(attribute: m_tangentAttribute);
441 q->addAttribute(attribute: m_indexAttribute);
442}
443
444QByteArray QCuboidGeometryPrivate::generateVertexData() const
445{
446 return createCuboidVertexData(xExtent: m_xExtent, yExtent: m_yExtent, zExtent: m_zExtent,
447 yzResolution: m_yzFaceResolution, xzResolution: m_xzFaceResolution, xyResolution: m_xyFaceResolution);
448}
449
450QByteArray QCuboidGeometryPrivate::generateIndexData() const
451{
452 return createCuboidIndexData(yzResolution: m_yzFaceResolution, xzResolution: m_xzFaceResolution, xyResolution: m_xyFaceResolution);
453}
454
455/*!
456 * \qmltype CuboidGeometry
457 * \instantiates Qt3DExtras::QCuboidGeometry
458 * \inqmlmodule Qt3D.Extras
459 * \brief CuboidGeometry allows creation of a cuboid in 3D space.
460 *
461 * The CuboidGeometry type is most commonly used internally by the CuboidMesh type
462 * but can also be used in custom GeometryRenderer types.
463 */
464
465/*!
466 * \qmlproperty real CuboidGeometry::xExtent
467 *
468 * Holds the x extent of the geometry.
469 */
470
471/*!
472 * \qmlproperty real CuboidGeometry::yExtent
473 *
474 * Holds the y extent of the geometry.
475 */
476
477/*!
478 * \qmlproperty real CuboidGeometry::zExtent
479 *
480 * Holds the z extent of the geometry.
481 */
482
483/*!
484 * \qmlproperty size CuboidGeometry::yzMeshResolution
485 *
486 * Holds the y-z resolution.
487 * The width and height values of this property specify the number of vertices generated for
488 * the y-z faces of the mesh.
489 */
490
491/*!
492 * \qmlproperty size CuboidGeometry::xzMeshResolution
493 *
494 * Holds the x-z resolution.
495 * The width and height values of this property specify the number of vertices generated for
496 * the x-z faces of the mesh.
497 */
498
499/*!
500 * \qmlproperty size CuboidGeometry::xyMeshResolution
501 *
502 * Holds the x-y resolution.
503 * The width and height values of this property specify the number of vertices generated for
504 * the x-y faces of the mesh.
505 */
506
507/*!
508 * \qmlproperty Attribute CuboidGeometry::positionAttribute
509 *
510 * Holds the geometry position attribute.
511 */
512
513/*!
514 * \qmlproperty Attribute CuboidGeometry::normalAttribute
515 *
516 * Holds the geometry normal attribute.
517 */
518
519/*!
520 * \qmlproperty Attribute CuboidGeometry::texCoordAttribute
521 *
522 * Holds the geometry texture coordinate attribute.
523 */
524
525/*!
526 * \qmlproperty Attribute CuboidGeometry::tangentAttribute
527 *
528 * Holds the geometry tangent attribute.
529 */
530
531/*!
532 * \qmlproperty Attribute CuboidGeometry::indexAttribute
533 *
534 * Holds the geometry index attribute.
535 */
536
537/*!
538 * \class Qt3DExtras::QCuboidGeometry
539 * \ingroup qt3d-extras-geometries
540 * \inheaderfile Qt3DExtras/QCuboidGeometry
541 * \inmodule Qt3DExtras
542 * \brief The QCuboidGeometry class allows creation of a cuboid in 3D space.
543 * \since 5.7
544 * \ingroup geometries
545 * \inherits Qt3DCore::QGeometry
546 *
547 * The QCuboidGeometry class is most commonly used internally by the QCuboidMesh
548 * but can also be used in custom Qt3DRender::QGeometryRenderer subclasses.
549 */
550
551/*!
552 * Constructs a new QCuboidGeometry with \a parent.
553 */
554QCuboidGeometry::QCuboidGeometry(QNode *parent)
555 : QGeometry(*new QCuboidGeometryPrivate(), parent)
556{
557 Q_D(QCuboidGeometry);
558 d->init();
559}
560
561/*!
562 * \internal
563 */
564QCuboidGeometry::QCuboidGeometry(QCuboidGeometryPrivate &dd, QNode *parent)
565 : QGeometry(dd, parent)
566{
567 Q_D(QCuboidGeometry);
568 d->init();
569}
570
571/*!
572 * \internal
573 */
574QCuboidGeometry::~QCuboidGeometry()
575{
576}
577
578/*!
579 * Updates indices based on mesh resolutions.
580 */
581void QCuboidGeometry::updateIndices()
582{
583 Q_D(QCuboidGeometry);
584 const int yzIndices = 2 * 3 * (d->m_yzFaceResolution.width() - 1) * (d->m_yzFaceResolution.height() - 1);
585 const int xzIndices = 2 * 3 * (d->m_xzFaceResolution.width() - 1) * (d->m_xzFaceResolution.height() - 1);
586 const int xyIndices = 2 * 3 * (d->m_xyFaceResolution.width() - 1) * (d->m_xyFaceResolution.height() - 1);
587 const int indexCount = 2 * (yzIndices + xzIndices + xyIndices);
588
589 d->m_indexAttribute->setCount(indexCount);
590 d->m_indexBuffer->setData(d->generateIndexData());
591}
592
593/*!
594 * Updates vertices based on mesh resolutions.
595 */
596void QCuboidGeometry::updateVertices()
597{
598 Q_D(QCuboidGeometry);
599 const int yzVerts = d->m_yzFaceResolution.width() * d->m_yzFaceResolution.height();
600 const int xzVerts = d->m_xzFaceResolution.width() * d->m_xzFaceResolution.height();
601 const int xyVerts = d->m_xyFaceResolution.width() * d->m_xyFaceResolution.height();
602 const int nVerts = 2 * (yzVerts + xzVerts + xyVerts);
603
604 d->m_positionAttribute->setCount(nVerts);
605 d->m_normalAttribute->setCount(nVerts);
606 d->m_texCoordAttribute->setCount(nVerts);
607 d->m_tangentAttribute->setCount(nVerts);
608
609 d->m_vertexBuffer->setData(d->generateVertexData());
610}
611
612void QCuboidGeometry::setXExtent(float xExtent)
613{
614 Q_D(QCuboidGeometry);
615 if (d->m_xExtent != xExtent) {
616 d->m_xExtent = xExtent;
617 updateVertices();
618 emit xExtentChanged(xExtent);
619 }
620}
621
622void QCuboidGeometry::setYExtent(float yExtent)
623{
624 Q_D(QCuboidGeometry);
625 if (d->m_yExtent != yExtent) {
626 d->m_yExtent = yExtent;
627 updateVertices();
628 emit yExtentChanged(yExtent);
629 }
630}
631
632void QCuboidGeometry::setZExtent(float zExtent)
633{
634 Q_D(QCuboidGeometry);
635 if (d->m_zExtent != zExtent) {
636 d->m_zExtent = zExtent;
637 updateVertices();
638 emit zExtentChanged(zExtent);
639 }
640}
641
642void QCuboidGeometry::setYZMeshResolution(const QSize &resolution)
643{
644 Q_D(QCuboidGeometry);
645 if (d->m_yzFaceResolution != resolution) {
646 d->m_yzFaceResolution = resolution;
647 updateVertices();
648 updateIndices();
649 emit yzMeshResolutionChanged(yzMeshResolution: resolution);
650 }
651}
652
653void QCuboidGeometry::setXZMeshResolution(const QSize &resolution)
654{
655 Q_D(QCuboidGeometry);
656 if (d->m_xzFaceResolution != resolution) {
657 d->m_xzFaceResolution = resolution;
658 updateVertices();
659 updateIndices();
660 emit xzMeshResolutionChanged(xzMeshResolution: resolution);
661 }
662}
663
664void QCuboidGeometry::setXYMeshResolution(const QSize &resolution)
665{
666 Q_D(QCuboidGeometry);
667 if (d->m_xyFaceResolution != resolution) {
668 d->m_xyFaceResolution = resolution;
669 updateVertices();
670 updateIndices();
671 emit xyMeshResolutionChanged(xyMeshResolution: resolution);
672 }
673}
674
675/*!
676 * \property QCuboidGeometry::xExtent
677 *
678 * Holds the x extent of the geometry.
679 */
680float QCuboidGeometry::xExtent() const
681{
682 Q_D(const QCuboidGeometry);
683 return d->m_xExtent;
684}
685
686/*!
687 * \property QCuboidGeometry::yExtent
688 *
689 * Holds the y extent of the geometry.
690 */
691float QCuboidGeometry::yExtent() const
692{
693 Q_D(const QCuboidGeometry);
694 return d->m_yExtent;
695}
696
697/*!
698 * \property QCuboidGeometry::zExtent
699 *
700 * Holds the z extent of the geometry.
701 */
702float QCuboidGeometry::zExtent() const
703{
704 Q_D(const QCuboidGeometry);
705 return d->m_zExtent;
706}
707
708/*!
709 * \property QCuboidGeometry::yzMeshResolution
710 *
711 * Holds the y-z resolution.
712 * The width and height values of this property specify the number of vertices generated for
713 * the y-z faces of the mesh.
714 */
715QSize QCuboidGeometry::yzMeshResolution() const
716{
717 Q_D(const QCuboidGeometry);
718 return d->m_yzFaceResolution;
719}
720
721/*!
722 * \property QCuboidGeometry::xzMeshResolution
723 *
724 * Holds the x-z resolution.
725 * The width and height values of this property specify the number of vertices generated for
726 * the x-z faces of the mesh.
727 */
728QSize QCuboidGeometry::xyMeshResolution() const
729{
730 Q_D(const QCuboidGeometry);
731 return d->m_xyFaceResolution;
732}
733
734/*!
735 * \property QCuboidGeometry::xyMeshResolution
736 *
737 * Holds the x-y resolution.
738 * The width and height values of this property specify the number of vertices generated for
739 * the x-y faces of the mesh.
740 */
741QSize QCuboidGeometry::xzMeshResolution() const
742{
743 Q_D(const QCuboidGeometry);
744 return d->m_xzFaceResolution;
745}
746
747/*!
748 * \property QCuboidGeometry::positionAttribute
749 *
750 * Holds the geometry position attribute.
751 */
752QAttribute *QCuboidGeometry::positionAttribute() const
753{
754 Q_D(const QCuboidGeometry);
755 return d->m_positionAttribute;
756}
757
758/*!
759 * \property QCuboidGeometry::normalAttribute
760 *
761 * Holds the geometry normal attribute.
762 */
763QAttribute *QCuboidGeometry::normalAttribute() const
764{
765 Q_D(const QCuboidGeometry);
766 return d->m_normalAttribute;
767}
768
769/*!
770 * \property QCuboidGeometry::texCoordAttribute
771 *
772 * Holds the geometry texture coordinate attribute.
773 */
774QAttribute *QCuboidGeometry::texCoordAttribute() const
775{
776 Q_D(const QCuboidGeometry);
777 return d->m_texCoordAttribute;
778}
779
780/*!
781 * \property QCuboidGeometry::tangentAttribute
782 *
783 * Holds the geometry tangent attribute.
784 */
785QAttribute *QCuboidGeometry::tangentAttribute() const
786{
787 Q_D(const QCuboidGeometry);
788 return d->m_tangentAttribute;
789}
790
791/*!
792 * \property QCuboidGeometry::indexAttribute
793 *
794 * Holds the geometry index attribute.
795 */
796QAttribute *QCuboidGeometry::indexAttribute() const
797{
798 Q_D(const QCuboidGeometry);
799 return d->m_indexAttribute;
800}
801
802} // Qt3DExtras
803
804QT_END_NAMESPACE
805
806#include "moc_qcuboidgeometry.cpp"
807

source code of qt3d/src/extras/geometries/qcuboidgeometry.cpp