summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2014-05-19 10:16:11 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2014-05-19 10:17:15 +0300
commit806fd8ab43dd59da89d04651b22c5c0440032b94 (patch)
tree41ff37fcebbe02d6c22209935b758ba7ddd59fd9
parent92ee7767f81f7a15b8773ed97356f01ecac68d0c (diff)
Added property for disabling shadows on custom items
Task-number: QTRD-3093 Change-Id: Ia24a1bc657af1bb1a528581e1f65fb50277e6874 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r--examples/datavisualization/customitems/customitemgraph.cpp17
-rw-r--r--examples/datavisualization/customitems/customitems.qrc1
-rw-r--r--examples/datavisualization/customitems/pipe.obj330
-rw-r--r--src/datavisualization/data/customrenderitem_p.h3
-rw-r--r--src/datavisualization/data/qcustom3ditem.cpp58
-rw-r--r--src/datavisualization/data/qcustom3ditem.h15
-rw-r--r--src/datavisualization/data/qcustom3ditem_p.h5
-rw-r--r--src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc4
-rw-r--r--src/datavisualization/engine/abstract3drenderer.cpp7
-rw-r--r--src/datavisualization/engine/qabstract3dgraph.cpp5
-rw-r--r--tests/qmlcamera/qml/qmlcamera/main.qml1
11 files changed, 431 insertions, 15 deletions
diff --git a/examples/datavisualization/customitems/customitemgraph.cpp b/examples/datavisualization/customitems/customitemgraph.cpp
index aeae61e9..be51f1f0 100644
--- a/examples/datavisualization/customitems/customitemgraph.cpp
+++ b/examples/datavisualization/customitems/customitemgraph.cpp
@@ -109,6 +109,7 @@ void CustomItemGraph::toggleItemOne(bool show)
//! [1]
QVector3D positionOne = QVector3D(39.0f, 77.0f, 19.2f);
//! [1]
+ QVector3D positionOnePipe = QVector3D(39.0f, 45.0f, 19.2f);
if (show) {
//! [0]
QImage color = QImage(2, 2, QImage::Format_RGB32);
@@ -123,17 +124,25 @@ void CustomItemGraph::toggleItemOne(bool show)
//! [3]
m_graph->addCustomItem(item);
//! [3]
+ item = new QCustom3DItem(":/items/pipe.obj", positionOnePipe,
+ QVector3D(0.005f, 0.5f, 0.005f),
+ QQuaternion(),
+ color);
+ item->setShadowCasting(false);
+ m_graph->addCustomItem(item);
} else {
resetSelection();
//! [4]
m_graph->removeCustomItemAt(positionOne);
//! [4]
+ m_graph->removeCustomItemAt(positionOnePipe);
}
}
void CustomItemGraph::toggleItemTwo(bool show)
{
QVector3D positionTwo = QVector3D(34.5f, 77.0f, 23.4f);
+ QVector3D positionTwoPipe = QVector3D(34.5f, 45.0f, 23.4f);
if (show) {
QImage color = QImage(2, 2, QImage::Format_RGB32);
color.fill(Qt::red);
@@ -144,9 +153,16 @@ void CustomItemGraph::toggleItemTwo(bool show)
item->setRotation(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 25.0f));
item->setTextureImage(color);
m_graph->addCustomItem(item);
+ item = new QCustom3DItem(":/items/pipe.obj", positionTwoPipe,
+ QVector3D(0.005f, 0.5f, 0.005f),
+ QQuaternion(),
+ color);
+ item->setShadowCasting(false);
+ m_graph->addCustomItem(item);
} else {
resetSelection();
m_graph->removeCustomItemAt(positionTwo);
+ m_graph->removeCustomItemAt(positionTwoPipe);
}
}
@@ -221,6 +237,7 @@ void CustomItemGraph::handleElementSelected(QAbstract3DGraph::ElementType type)
m_selectionAnimation->setStartValue(item->scaling());
m_selectionAnimation->setEndValue(item->scaling() * 1.5f);
m_selectionAnimation->start();
+ item->setShadowCasting(false);
} else if (type == QAbstract3DGraph::ElementSeries) {
QString text = "Surface (";
QSurface3DSeries *series = m_graph->selectedSeries();
diff --git a/examples/datavisualization/customitems/customitems.qrc b/examples/datavisualization/customitems/customitems.qrc
index af91d645..1337c9fc 100644
--- a/examples/datavisualization/customitems/customitems.qrc
+++ b/examples/datavisualization/customitems/customitems.qrc
@@ -7,5 +7,6 @@
<qresource prefix="/items">
<file>refinery.obj</file>
<file>oilrig.obj</file>
+ <file>pipe.obj</file>
</qresource>
</RCC>
diff --git a/examples/datavisualization/customitems/pipe.obj b/examples/datavisualization/customitems/pipe.obj
new file mode 100644
index 00000000..6ccbb286
--- /dev/null
+++ b/examples/datavisualization/customitems/pipe.obj
@@ -0,0 +1,330 @@
+# Blender v2.66 (sub 0) OBJ File: 'cylinder.blend'
+# www.blender.org
+o Cylinder
+v 0.000000 -1.000000 -1.000000
+v 0.000000 1.000000 -1.000000
+v 0.195090 -1.000000 -0.980785
+v 0.195090 1.000000 -0.980785
+v 0.382683 -1.000000 -0.923880
+v 0.382683 1.000000 -0.923880
+v 0.555570 -1.000000 -0.831470
+v 0.555570 1.000000 -0.831470
+v 0.707107 -1.000000 -0.707107
+v 0.707107 1.000000 -0.707107
+v 0.831470 -1.000000 -0.555570
+v 0.831470 1.000000 -0.555570
+v 0.923880 -1.000000 -0.382683
+v 0.923880 1.000000 -0.382683
+v 0.980785 -1.000000 -0.195090
+v 0.980785 1.000000 -0.195090
+v 1.000000 -1.000000 -0.000000
+v 1.000000 1.000000 -0.000000
+v 0.980785 -1.000000 0.195090
+v 0.980785 1.000000 0.195090
+v 0.923880 -1.000000 0.382683
+v 0.923880 1.000000 0.382683
+v 0.831470 -1.000000 0.555570
+v 0.831470 1.000000 0.555570
+v 0.707107 -1.000000 0.707107
+v 0.707107 1.000000 0.707107
+v 0.555570 -1.000000 0.831470
+v 0.555570 1.000000 0.831470
+v 0.382683 -1.000000 0.923880
+v 0.382683 1.000000 0.923880
+v 0.195090 -1.000000 0.980785
+v 0.195090 1.000000 0.980785
+v -0.000000 -1.000000 1.000000
+v -0.000000 1.000000 1.000000
+v -0.195091 -1.000000 0.980785
+v -0.195091 1.000000 0.980785
+v -0.382684 -1.000000 0.923879
+v -0.382684 1.000000 0.923879
+v -0.555571 -1.000000 0.831469
+v -0.555571 1.000000 0.831469
+v -0.707107 -1.000000 0.707106
+v -0.707107 1.000000 0.707106
+v -0.831470 -1.000000 0.555570
+v -0.831470 1.000000 0.555570
+v -0.923880 -1.000000 0.382683
+v -0.923880 1.000000 0.382683
+v -0.980785 -1.000000 0.195089
+v -0.980785 1.000000 0.195089
+v -1.000000 -1.000000 -0.000001
+v -1.000000 1.000000 -0.000001
+v -0.980785 -1.000000 -0.195091
+v -0.980785 1.000000 -0.195091
+v -0.923879 -1.000000 -0.382684
+v -0.923879 1.000000 -0.382684
+v -0.831469 -1.000000 -0.555571
+v -0.831469 1.000000 -0.555571
+v -0.707106 -1.000000 -0.707108
+v -0.707106 1.000000 -0.707108
+v -0.555569 -1.000000 -0.831470
+v -0.555569 1.000000 -0.831470
+v -0.382682 -1.000000 -0.923880
+v -0.382682 1.000000 -0.923880
+v -0.195089 -1.000000 -0.980786
+v -0.195089 1.000000 -0.980786
+vt 0.289718 0.879351
+vt 0.288367 0.438844
+vt 0.330714 0.438714
+vt 0.332066 0.879221
+vt 0.370605 0.438592
+vt 0.371956 0.879099
+vt 0.406505 0.438482
+vt 0.407857 0.878988
+vt 0.437036 0.438388
+vt 0.778904 0.000000
+vt 0.780256 0.440507
+vt 0.749725 0.440601
+vt 0.748373 0.000094
+vt 0.713824 0.440711
+vt 0.712473 0.000204
+vt 0.673934 0.440833
+vt 0.672582 0.000326
+vt 0.631586 0.440963
+vt 0.630235 0.000456
+vt 0.588409 0.441095
+vt 0.587057 0.000588
+vt 0.546061 0.441225
+vt 0.544710 0.000718
+vt 0.506171 0.441348
+vt 0.504819 0.000841
+vt 0.470270 0.441458
+vt 0.468919 0.000951
+vt 0.439739 0.441552
+vt 0.720545 0.882916
+vt 0.719194 0.442409
+vt 0.755094 0.442299
+vt 0.756446 0.882806
+vt 0.794985 0.442176
+vt 0.796336 0.882683
+vt 0.837333 0.442046
+vt 0.838684 0.882553
+vt 0.881861 0.882421
+vt 0.880510 0.441914
+vt 0.924209 0.882291
+vt 0.922857 0.441784
+vt 0.964099 0.882168
+vt 0.962748 0.441662
+vt 1.000000 0.882058
+vt 0.717842 0.441552
+vt 0.719194 0.882058
+vt 0.681942 0.441662
+vt 0.683293 0.882169
+vt 0.642051 0.441784
+vt 0.643403 0.882291
+vt 0.599704 0.441914
+vt 0.601055 0.882421
+vt 0.556526 0.442046
+vt 0.557878 0.882553
+vt 0.514179 0.442176
+vt 0.515530 0.882683
+vt 0.474288 0.442299
+vt 0.475640 0.882806
+vt 0.438388 0.442409
+vt 0.097872 0.879939
+vt 0.096520 0.439433
+vt 0.128403 0.879846
+vt 0.127051 0.439339
+vt 0.164303 0.879735
+vt 0.162952 0.439229
+vt 0.204194 0.879613
+vt 0.000000 0.197605
+vt 0.008423 0.155257
+vt 0.000000 0.240783
+vt 0.246541 0.879483
+vt 0.245190 0.438976
+vt 0.202842 0.439106
+vt 0.438388 0.878895
+vt 0.438388 0.001045
+vt 0.998649 0.441552
+vt 0.439739 0.882916
+vt 0.024947 0.115367
+vt 0.048935 0.079466
+vt 0.079466 0.048935
+vt 0.115366 0.024947
+vt 0.155257 0.008424
+vt 0.197605 0.000000
+vt 0.240782 0.000000
+vt 0.283130 0.008423
+vt 0.323021 0.024947
+vt 0.358922 0.048935
+vt 0.389453 0.079466
+vt 0.413441 0.115367
+vt 0.429964 0.155257
+vt 0.438388 0.197605
+vt 0.438388 0.240783
+vt 0.429964 0.283130
+vt 0.413441 0.323021
+vt 0.389453 0.358922
+vt 0.358922 0.389453
+vt 0.323021 0.413441
+vt 0.283130 0.429964
+vt 0.240783 0.438388
+vt 0.197605 0.438388
+vt 0.155257 0.429964
+vt 0.115367 0.413441
+vt 0.079466 0.389453
+vt 0.048935 0.358922
+vt 0.024947 0.323021
+vt 0.008423 0.283130
+vn 0.000000 0.000000 -1.000000
+vn 0.000000 0.685690 -0.727866
+vn 0.142003 0.685690 -0.713889
+vn 0.195074 0.000000 -0.980773
+vn 0.278542 0.685690 -0.672475
+vn 0.382672 0.000000 -0.923856
+vn 0.404370 0.685690 -0.605213
+vn 0.555559 0.000000 -0.831446
+vn 0.514664 0.685690 -0.514664
+vn 0.707083 0.000000 -0.707083
+vn 0.605213 0.685690 -0.404370
+vn 0.831446 0.000000 -0.555559
+vn 0.672475 0.685690 -0.278542
+vn 0.923856 0.000000 -0.382672
+vn 0.713889 0.685690 -0.142003
+vn 0.980773 0.000000 -0.195074
+vn 0.727866 0.685690 0.000000
+vn 1.000000 0.000000 0.000000
+vn 0.713889 0.685690 0.142003
+vn 0.980773 0.000000 0.195074
+vn 0.672475 0.685690 0.278542
+vn 0.923856 0.000000 0.382672
+vn 0.605213 0.685690 0.404370
+vn 0.831446 0.000000 0.555559
+vn 0.514664 0.685690 0.514664
+vn 0.707083 0.000000 0.707083
+vn 0.404370 0.685690 0.605213
+vn 0.555559 0.000000 0.831446
+vn 0.278542 0.685690 0.672475
+vn 0.382672 0.000000 0.923856
+vn 0.142003 0.685690 0.713889
+vn 0.195074 0.000000 0.980773
+vn 0.000000 0.685690 0.727866
+vn 0.000000 0.000000 0.999969
+vn -0.195074 0.000000 0.980773
+vn -0.142003 0.685690 0.713889
+vn -0.382672 0.000000 0.923856
+vn -0.278542 0.685690 0.672475
+vn -0.555559 0.000000 0.831446
+vn -0.404370 0.685690 0.605213
+vn -0.707083 0.000000 0.707083
+vn -0.514664 0.685690 0.514664
+vn -0.831446 0.000000 0.555559
+vn -0.605213 0.685690 0.404370
+vn -0.923856 0.000000 0.382672
+vn -0.672475 0.685690 0.278542
+vn -0.980773 0.000000 0.195074
+vn -0.713889 0.685690 0.142003
+vn -1.000000 0.000000 0.000000
+vn -0.727866 0.685690 0.000000
+vn -0.980773 0.000000 -0.195074
+vn -0.713889 0.685690 -0.142003
+vn -0.923856 0.000000 -0.382672
+vn -0.672475 0.685690 -0.278542
+vn -0.831446 0.000000 -0.555559
+vn -0.605213 0.685690 -0.404370
+vn -0.707083 0.000000 -0.707083
+vn -0.514664 0.685690 -0.514695
+vn -0.555559 0.000000 -0.831446
+vn -0.404370 0.685690 -0.605213
+vn -0.382672 0.000000 -0.923856
+vn -0.195074 0.000000 -0.980773
+vn -0.142003 0.685690 -0.713889
+vn -0.278542 0.685690 -0.672475
+s 1
+f 1/1/1 2/2/2 4/3/3
+f 3/4/4 4/3/3 6/5/5
+f 5/6/6 6/5/5 8/7/7
+f 7/8/8 8/7/7 10/9/9
+f 9/10/10 10/11/9 12/12/11
+f 11/13/12 12/12/11 14/14/13
+f 13/15/14 14/14/13 16/16/15
+f 15/17/16 16/16/15 18/18/17
+f 17/19/18 18/18/17 20/20/19
+f 19/21/20 20/20/19 22/22/21
+f 21/23/22 22/22/21 24/24/23
+f 23/25/24 24/24/23 26/26/25
+f 25/27/26 26/26/25 28/28/27
+f 27/29/28 28/30/27 30/31/29
+f 29/32/30 30/31/29 32/33/31
+f 31/34/32 32/33/31 34/35/33
+f 33/36/34 34/35/33 35/37/35
+f 35/37/35 36/38/36 37/39/37
+f 37/39/37 38/40/38 39/41/39
+f 39/41/39 40/42/40 41/43/41
+f 41/44/41 42/45/42 43/46/43
+f 43/46/43 44/47/44 45/48/45
+f 45/48/45 46/49/46 47/50/47
+f 47/50/47 48/51/48 49/52/49
+f 49/52/49 50/53/50 51/54/51
+f 51/54/51 52/55/52 53/56/53
+f 53/56/53 54/57/54 55/58/55
+f 55/59/55 56/60/56 57/61/57
+f 57/61/57 58/62/58 59/63/59
+f 59/63/59 60/64/60 61/65/61
+f 4/66/3 2/67/2 6/68/5
+f 63/69/62 64/70/63 1/1/1
+f 61/65/61 62/71/64 63/69/62
+f 3/4/4 1/1/1 4/3/3
+f 5/6/6 3/4/4 6/5/5
+f 7/8/8 5/6/6 8/7/7
+f 9/72/10 7/8/8 10/9/9
+f 11/13/12 9/10/10 12/12/11
+f 13/15/14 11/13/12 14/14/13
+f 15/17/16 13/15/14 16/16/15
+f 17/19/18 15/17/16 18/18/17
+f 19/21/20 17/19/18 20/20/19
+f 21/23/22 19/21/20 22/22/21
+f 23/25/24 21/23/22 24/24/23
+f 25/27/26 23/25/24 26/26/25
+f 27/73/28 25/27/26 28/28/27
+f 29/32/30 27/29/28 30/31/29
+f 31/34/32 29/32/30 32/33/31
+f 33/36/34 31/34/32 34/35/33
+f 34/35/33 36/38/36 35/37/35
+f 36/38/36 38/40/38 37/39/37
+f 38/40/38 40/42/40 39/41/39
+f 40/42/40 42/74/42 41/43/41
+f 42/45/42 44/47/44 43/46/43
+f 44/47/44 46/49/46 45/48/45
+f 46/49/46 48/51/48 47/50/47
+f 48/51/48 50/53/50 49/52/49
+f 50/53/50 52/55/52 51/54/51
+f 52/55/52 54/57/54 53/56/53
+f 54/57/54 56/75/56 55/58/55
+f 56/60/56 58/62/58 57/61/57
+f 58/62/58 60/64/60 59/63/59
+f 60/64/60 62/71/64 61/65/61
+f 2/67/2 64/76/63 6/68/5
+f 64/76/63 62/77/64 6/68/5
+f 62/77/64 60/78/60 6/68/5
+f 60/78/60 58/79/58 6/68/5
+f 58/79/58 56/80/56 6/68/5
+f 56/80/56 54/81/54 6/68/5
+f 54/81/54 52/82/52 6/68/5
+f 52/82/52 50/83/50 6/68/5
+f 50/83/50 48/84/48 6/68/5
+f 48/84/48 46/85/46 6/68/5
+f 46/85/46 44/86/44 6/68/5
+f 44/86/44 42/87/42 6/68/5
+f 42/87/42 40/88/40 6/68/5
+f 40/88/40 38/89/38 6/68/5
+f 38/89/38 36/90/36 6/68/5
+f 36/90/36 34/91/33 6/68/5
+f 34/91/33 32/92/31 6/68/5
+f 32/92/31 30/93/29 6/68/5
+f 30/93/29 28/94/27 6/68/5
+f 28/94/27 26/95/25 6/68/5
+f 26/95/25 24/96/23 6/68/5
+f 24/96/23 22/97/21 6/68/5
+f 22/97/21 20/98/19 6/68/5
+f 20/98/19 18/99/17 6/68/5
+f 18/99/17 16/100/15 6/68/5
+f 16/100/15 14/101/13 6/68/5
+f 14/101/13 12/102/11 6/68/5
+f 12/102/11 10/103/9 8/104/7
+f 6/68/5 12/102/11 8/104/7
+f 64/70/63 2/2/2 1/1/1
+f 62/71/64 64/70/63 63/69/62
diff --git a/src/datavisualization/data/customrenderitem_p.h b/src/datavisualization/data/customrenderitem_p.h
index 1722163b..1dce62e5 100644
--- a/src/datavisualization/data/customrenderitem_p.h
+++ b/src/datavisualization/data/customrenderitem_p.h
@@ -59,6 +59,8 @@ public:
inline bool isValid() const { return m_valid; }
inline void setIndex(int index) { m_index = index; }
inline int index() const { return m_index; }
+ inline void setShadowCasting(bool shadowCasting) { m_shadowCasting = shadowCasting; }
+ inline bool isShadowCasting() const { return m_shadowCasting; }
private:
GLuint m_texture;
@@ -68,6 +70,7 @@ private:
bool m_visible;
bool m_valid;
int m_index;
+ bool m_shadowCasting;
QCustom3DItem *m_item;
};
typedef QHash<QCustom3DItem *, CustomRenderItem *> CustomRenderItemArray;
diff --git a/src/datavisualization/data/qcustom3ditem.cpp b/src/datavisualization/data/qcustom3ditem.cpp
index bb6c96eb..0428d59b 100644
--- a/src/datavisualization/data/qcustom3ditem.cpp
+++ b/src/datavisualization/data/qcustom3ditem.cpp
@@ -56,6 +56,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
*
* Holds the texture file name for the item. If left unset, a solid gray texture will be
* used.
+ *
+ * \note To conserve memory the Image loaded from the file is cleared after a texture is created.
*/
// TODO: Position check in task QTRD-3057
@@ -78,6 +80,18 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
* Holds the item \a rotation as a quaternion. Defaults to \c {quaternion(0.0, 0.0, 0.0, 0.0)}.
*/
+/*! \qmlproperty bool Custom3DItem::visible
+ *
+ * Sets the item \a visible. Defaults to \c{true}.
+ */
+
+/*! \qmlproperty bool Custom3DItem::shadowCasting
+ *
+ * Sets shadow casting for the item to \a enabled. Defaults to \c{true}.
+ * If set \c{false}, the item does not cast shadows regardless of
+ * \l{QAbstract3DGraph::ShadowQuality}{ShadowQuality}.
+ */
+
/*!
* \qmlmethod void Custom3DItem::setRotationAxisAndAngle(vector3d axis, real angle)
*
@@ -129,7 +143,7 @@ void QCustom3DItem::setMeshFile(const QString &meshFile)
}
}
-QString QCustom3DItem::meshFile()
+QString QCustom3DItem::meshFile() const
{
return d_ptr->m_meshFile;
}
@@ -152,7 +166,7 @@ void QCustom3DItem::setPosition(const QVector3D &position)
}
}
-QVector3D QCustom3DItem::position()
+QVector3D QCustom3DItem::position() const
{
return d_ptr->m_position;
}
@@ -171,7 +185,7 @@ void QCustom3DItem::setScaling(const QVector3D &scaling)
}
}
-QVector3D QCustom3DItem::scaling()
+QVector3D QCustom3DItem::scaling() const
{
return d_ptr->m_scaling;
}
@@ -209,11 +223,32 @@ void QCustom3DItem::setVisible(bool visible)
}
}
-bool QCustom3DItem::isVisible()
+bool QCustom3DItem::isVisible() const
{
return d_ptr->m_visible;
}
+
+/*! \property QCustom3DItem::shadowCasting
+ *
+ * Sets shadow casting for the item to \a enabled. Defaults to \c{true}.
+ * If set \c{false}, the item does not cast shadows regardless of QAbstract3DGraph::ShadowQuality.
+ */
+void QCustom3DItem::setShadowCasting(bool enabled)
+{
+ if (d_ptr->m_shadowCasting != enabled) {
+ d_ptr->m_shadowCasting = enabled;
+ d_ptr->m_dirtyBits.shadowCastingDirty = true;
+ emit shadowCastingChanged(enabled);
+ emit d_ptr->needUpdate();
+ }
+}
+
+bool QCustom3DItem::isShadowCasting() const
+{
+ return d_ptr->m_shadowCasting;
+}
+
/*!
* A convenience function to construct rotation quaternion from \a axis and \a angle.
*
@@ -226,6 +261,8 @@ void QCustom3DItem::setRotationAxisAndAngle(const QVector3D &axis, float angle)
/*!
* Set the \a textureImage as a QImage for the item. Texture defaults to solid gray.
+ *
+ * \note To conserve memory the given QImage is cleared after a texture is created.
*/
void QCustom3DItem::setTextureImage(const QImage &textureImage)
{
@@ -249,8 +286,10 @@ void QCustom3DItem::setTextureImage(const QImage &textureImage)
/*! \property QCustom3DItem::textureFile
*
- * Holds the texture file name for the item. If both this and textureImage are unset, a solid
+ * Holds the texture file name for the item. If both this and texture image are unset, a solid
* gray texture will be used.
+ *
+ * \note To conserve memory the QImage loaded from the file is cleared after a texture is created.
*/
void QCustom3DItem::setTextureFile(const QString &textureFile)
{
@@ -268,7 +307,7 @@ void QCustom3DItem::setTextureFile(const QString &textureFile)
}
}
-QString QCustom3DItem::textureFile()
+QString QCustom3DItem::textureFile() const
{
return d_ptr->m_textureFile;
}
@@ -279,7 +318,8 @@ QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, QObject *parent) :
m_position(QVector3D(0.0f, 0.0f, 0.0f)),
m_scaling(QVector3D(0.1f, 0.1f, 0.1f)),
m_rotation(QQuaternion(0.0f, 0.0f, 0.0f, 0.0f)),
- m_visible(true)
+ m_visible(true),
+ m_shadowCasting(true)
{
}
@@ -292,7 +332,8 @@ QCustom3DItemPrivate::QCustom3DItemPrivate(QCustom3DItem *q, const QString &mesh
m_position(position),
m_scaling(scaling),
m_rotation(rotation),
- m_visible(true)
+ m_visible(true),
+ m_shadowCasting(true)
{
}
@@ -318,6 +359,7 @@ void QCustom3DItemPrivate::resetDirtyBits()
m_dirtyBits.scalingDirty = false;
m_dirtyBits.rotationDirty = false;
m_dirtyBits.visibleDirty = false;
+ m_dirtyBits.shadowCastingDirty = false;
}
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/data/qcustom3ditem.h b/src/datavisualization/data/qcustom3ditem.h
index 77e33404..72aad604 100644
--- a/src/datavisualization/data/qcustom3ditem.h
+++ b/src/datavisualization/data/qcustom3ditem.h
@@ -37,6 +37,7 @@ class QT_DATAVISUALIZATION_EXPORT QCustom3DItem : public QObject
Q_PROPERTY(QVector3D scaling READ scaling WRITE setScaling NOTIFY scalingChanged)
Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
+ Q_PROPERTY(bool shadowCasting READ isShadowCasting WRITE setShadowCasting NOTIFY shadowCastingChanged)
public:
explicit QCustom3DItem(QObject *parent = 0);
@@ -46,22 +47,25 @@ public:
virtual ~QCustom3DItem();
void setMeshFile(const QString &meshFile);
- QString meshFile();
+ QString meshFile() const;
void setTextureFile(const QString &textureFile);
- QString textureFile();
+ QString textureFile() const;
void setPosition(const QVector3D &position);
- QVector3D position();
+ QVector3D position() const;
void setScaling(const QVector3D &scaling);
- QVector3D scaling();
+ QVector3D scaling() const;
void setRotation(const QQuaternion &rotation);
QQuaternion rotation();
void setVisible(bool visible);
- bool isVisible();
+ bool isVisible() const;
+
+ void setShadowCasting(bool enabled);
+ bool isShadowCasting() const;
Q_INVOKABLE void setRotationAxisAndAngle(const QVector3D &axis, float angle);
@@ -74,6 +78,7 @@ signals:
void scalingChanged(const QVector3D &scaling);
void rotationChanged(const QQuaternion &rotation);
void visibleChanged(bool visible);
+ void shadowCastingChanged(bool shadowCasting);
protected:
QScopedPointer<QCustom3DItemPrivate> d_ptr;
diff --git a/src/datavisualization/data/qcustom3ditem_p.h b/src/datavisualization/data/qcustom3ditem_p.h
index 007c9fc4..2523abd4 100644
--- a/src/datavisualization/data/qcustom3ditem_p.h
+++ b/src/datavisualization/data/qcustom3ditem_p.h
@@ -40,6 +40,7 @@ struct QCustomItemDirtyBitField {
bool scalingDirty : 1;
bool rotationDirty : 1;
bool visibleDirty : 1;
+ bool shadowCastingDirty : 1;
QCustomItemDirtyBitField()
: textureDirty(false),
@@ -47,7 +48,8 @@ struct QCustomItemDirtyBitField {
positionDirty(false),
scalingDirty(false),
rotationDirty(false),
- visibleDirty(false)
+ visibleDirty(false),
+ shadowCastingDirty(false)
{
}
};
@@ -74,6 +76,7 @@ public:
QVector3D m_scaling;
QQuaternion m_rotation;
bool m_visible;
+ bool m_shadowCasting;
QCustomItemDirtyBitField m_dirtyBits;
diff --git a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
index 4fac937b..a71bd28b 100644
--- a/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
+++ b/src/datavisualization/doc/src/qtdatavisualization-qml-abstractdeclarative.qdoc
@@ -192,6 +192,10 @@
* Gets ownership of \a item back and removes the \a item from the graph.
*
* \since Qt Data Visualization 1.1
+ *
+ * \note If the same item is added back to the graph, the texture file needs to be re-set.
+ *
+ * \sa Custom3DItem::textureFile
*/
/*!
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp
index a2181271..82952a26 100644
--- a/src/datavisualization/engine/abstract3drenderer.cpp
+++ b/src/datavisualization/engine/abstract3drenderer.cpp
@@ -582,6 +582,7 @@ CustomRenderItem *Abstract3DRenderer::addCustomItem(QCustom3DItem *item)
QVector3D translation = convertPositionToTranslation(item->position());
newItem->setTranslation(translation);
newItem->setVisible(item->isVisible());
+ newItem->setShadowCasting(item->isShadowCasting());
m_customRenderCache.insert(item, newItem);
return newItem;
}
@@ -620,6 +621,10 @@ void Abstract3DRenderer::updateCustomItem(CustomRenderItem *renderItem)
renderItem->setVisible(item->isVisible());
item->d_ptr->m_dirtyBits.visibleDirty = false;
}
+ if (item->d_ptr->m_dirtyBits.shadowCastingDirty) {
+ renderItem->setShadowCasting(item->isShadowCasting());
+ item->d_ptr->m_dirtyBits.shadowCastingDirty = false;
+ }
}
void Abstract3DRenderer::drawCustomItems(RenderingState state,
@@ -700,7 +705,7 @@ void Abstract3DRenderer::drawCustomItems(RenderingState state,
itemColor /= 255.0f;
shader->setUniformValue(shader->color(), itemColor);
m_drawer->drawObject(shader, item->mesh());
- } else {
+ } else if (item->isShadowCasting()) {
// Depth render
shader->setUniformValue(shader->MVP(), depthProjectionViewMatrix * modelMatrix);
m_drawer->drawObject(shader, item->mesh());
diff --git a/src/datavisualization/engine/qabstract3dgraph.cpp b/src/datavisualization/engine/qabstract3dgraph.cpp
index 9818d176..196460da 100644
--- a/src/datavisualization/engine/qabstract3dgraph.cpp
+++ b/src/datavisualization/engine/qabstract3dgraph.cpp
@@ -430,6 +430,11 @@ void QAbstract3DGraph::removeCustomItemAt(const QVector3D &position)
* Gets ownership of given \a item back and removes the \a item from the graph.
*
* \since Qt Data Visualization 1.1
+ *
+ * \note If the same item is added back to the graph, the texture or the texture file needs to be
+ * re-set.
+ *
+ * \sa QCustom3DItem::setTextureImage(), QCustom3DItem::setTextureFile()
*/
void QAbstract3DGraph::releaseCustomItem(QCustom3DItem *item)
{
diff --git a/tests/qmlcamera/qml/qmlcamera/main.qml b/tests/qmlcamera/qml/qmlcamera/main.qml
index 6b83bde2..d32140e7 100644
--- a/tests/qmlcamera/qml/qmlcamera/main.qml
+++ b/tests/qmlcamera/qml/qmlcamera/main.qml
@@ -182,6 +182,7 @@ Rectangle {
property bool addObject: false
onClicked: {
if (addObject === true) {
+ shuttleItem.textureFile(":/items/shuttle.png")
testChart.addCustomItem(shuttleItem)
text = "Remove Shuttle"
addObject = false