PDA

View Full Version : Show the same models in two Scene3Ds



kheaactua
22nd November 2016, 14:28
Hi,

I've been having trouble showing the same Entity (say a Mesh) in two Scene3Ds. I think the problem I don't know how to get around is that an Entity's parent has to be the Entity that that is being shown by the Scene3D. This is different than in the Multi Viewport QML Example (http://doc.qt.io/qt-5/qt3d-multiviewport-example.html) where all the viewports are in one Scene3D.

For example, in the code below, how can I show the SphereMesh torusMesh2 in both Scene3Ds?
Right now I'm setting its parent to insert it into scene3dRight, but I can't seem to set multiple parents on an object, and I'm not sure how to manipulate scene3dLeft's and scene3dRight data/children



import QtQuick 2.0
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.3
import QtQuick.Scene3D 2.0

import Qt3D.Extras 2.0

Item {

SphereMesh {
id: torusMesh2; radius: 5
parent: scene3DRightEntity
}
PhongMaterial {
id: material2; parent: scene3DRightEntity
}
Transform {
id: torusTransform2; scale3D: Qt.vector3d(1.5, 1, 0.5); rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45); parent: scene3DRightEntity
}


Rectangle {
id: topRect
anchors.fill: parent; anchors.margins: 50

color: 'green'

SplitView {
anchors.fill: parent; orientation: Qt.Horizontal

Rectangle {
id: scene
anchors.margins: 50; width: 200; Layout.minimumWidth: 100; Layout.maximumWidth: 500
color: "darkRed"

Text { text: "View 1"; anchors.centerIn: parent }

Scene3D {
id: scene3dLeft
anchors.fill: parent; anchors.margins: 10; focus: true
aspects: ["input", "logic"]
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio

Entity {

SimpleCamera {
id: camera1; fieldOfView: 45; position: Qt.vector3d( 0.0, 0.0, 40.0 )
}

components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
camera: camera1.camera
clearColor: "transparent"
}
}
, InputSettings { }
]

TorusMesh {
id: torusMesh1; radius: 5; minorRadius: 1; rings: 100; slices: 20
}
PhongMaterial { id: material1 }
Transform { id: torusTransform1; scale3D: Qt.vector3d(1.5, 1, 0.5); rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) }

Entity {
id: torusEntity1
components: [ torusMesh1, material1, torusTransform1 ]
}
}

}
}


Rectangle {
id: scene2
Layout.fillWidth: true; Layout.minimumWidth: 50; Layout.maximumWidth: 400; height: 300
color: "darkBlue"

Scene3D {
id: scene3dRight
anchors.fill: parent; anchors.margins: 50; focus: true;
aspects: ["input", "logic"]
cameraAspectRatioMode: Scene3D.AutomaticAspectRatio

Entity {
id: scene3DRightEntity
SimpleCamera {
id: camera2
position: Qt.vector3d( 0.0, 0.0, 40.0 )
}

components: [
RenderSettings {
activeFrameGraph: ForwardRenderer {
camera: camera2.camera
clearColor: "transparent"
}
}
, InputSettings { }
]

Entity {
id: torusEntity2
components: [ torusMesh2, material2, torusTransform2 ]
}
}

}
}
}
}

} // Item


(sorry it's not shorter..)

Also fully open to the idea that I'm going about this the wrong way. I suppose ultimately I would just like to know how to have my data only defined once, but shown anywhere/multiple times.

Thanks!