<div dir="ltr">Thank you Mike.<div><br></div><div>Follow up question:</div><div><br></div><div>Given a</div><div><br></div><div>```</div><div>Qt3DRender::QSceneLoader *sceneLoader;<br></div><div>```</div><div><br></div><div>How do we get at this QGeometryRenderer object to be able to call the impliciteMinPoint (), impliciteMaxPoint () properties ?</div><div><br></div><div>Cheers</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 2 Aug 2022 at 05:56, Mike Krus <<a href="mailto:mike.krus@kdab.com">mike.krus@kdab.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi<br>
<br>
if you are using Qt6, then yes.<br>
<br>
For a specific object, QGeometryRenderer derives from QBoundingVolume which has impliciteMinPoint and impliciteMaxPoint properties.<br>
<br>
If you’re interested in the bounding volume of a portion of the scene graph, all a QBoundingVolume component at the root and the<br>
same properties will be updated.<br>
<br>
In Qt5, the QGeometry node associated with each render has similar min/max properties (note that they only valid if the mesh uses all the geometry).<br>
<br>
Hope this helps,<br>
<br>
Mike<br>
<br>
<br>
> On 1 Aug 2022, at 16:05, Nicholas Yue <<a href="mailto:yue.nicholas@gmail.com" target="_blank">yue.nicholas@gmail.com</a>> wrote:<br>
> <br>
> Hi,<br>
> <br>
>   I am diving into the geometry scene via QSceneLoader.<br>
>   <br>
>   Using the following code as a starting point, I wish to place the camera such that it automatically accommodates scenes of different sizes.<br>
>   <br>
>   One way I am thinking of doing is to base on the scene geometry bounding box.<br>
>   <br>
>   Is there a method or API which I can call to query the entire scene geometry bounding box ? Or do I have to walk the entire scene to build that up by querying the bounding box for every geometry in the scene ?<br>
>   <br>
>   Any sample code I can view to get me going ?<br>
>  <br>
> ```<br>
> /****************************************************************************<br>
> **<br>
> ** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).<br>
> ** Contact: <a href="https://www.qt.io/licensing/" rel="noreferrer" target="_blank">https://www.qt.io/licensing/</a><br>
> **<br>
> ** This file is part of the Qt3D module of the Qt Toolkit.<br>
> **<br>
> ** $QT_BEGIN_LICENSE:BSD$<br>
> ** Commercial License Usage<br>
> ** Licensees holding valid commercial Qt licenses may use this file in<br>
> ** accordance with the commercial license agreement provided with the<br>
> ** Software or, alternatively, in accordance with the terms contained in<br>
> ** a written agreement between you and The Qt Company. For licensing terms<br>
> ** and conditions see <a href="https://www.qt.io/terms-conditions" rel="noreferrer" target="_blank">https://www.qt.io/terms-conditions</a>. For further<br>
> ** information use the contact form at <a href="https://www.qt.io/contact-us" rel="noreferrer" target="_blank">https://www.qt.io/contact-us</a>.<br>
> **<br>
> ** BSD License Usage<br>
> ** Alternatively, you may use this file under the terms of the BSD license<br>
> ** as follows:<br>
> **<br>
> ** "Redistribution and use in source and binary forms, with or without<br>
> ** modification, are permitted provided that the following conditions are<br>
> ** met:<br>
> **   * Redistributions of source code must retain the above copyright<br>
> **     notice, this list of conditions and the following disclaimer.<br>
> **   * Redistributions in binary form must reproduce the above copyright<br>
> **     notice, this list of conditions and the following disclaimer in<br>
> **     the documentation and/or other materials provided with the<br>
> **     distribution.<br>
> **   * Neither the name of The Qt Company Ltd nor the names of its<br>
> **     contributors may be used to endorse or promote products derived<br>
> **     from this software without specific prior written permission.<br>
> **<br>
> **<br>
> ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS<br>
> ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br>
> ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR<br>
> ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT<br>
> ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,<br>
> ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT<br>
> ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,<br>
> ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY<br>
> ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT<br>
> ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE<br>
> ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."<br>
> **<br>
> ** $QT_END_LICENSE$<br>
> **<br>
> ****************************************************************************/<br>
> <br>
> #include <QFileDialog><br>
> #include <QApplication><br>
> <br>
> #include <Qt3DRender/QCamera><br>
> #include <Qt3DCore/QEntity><br>
> #include <Qt3DCore/QAspectEngine><br>
> #include <Qt3DInput/QInputAspect><br>
> #include <Qt3DRender/QSceneLoader><br>
> #include <Qt3DRender/QRenderAspect><br>
> #include <Qt3DExtras/QForwardRenderer><br>
> #include <Qt3DExtras/qt3dwindow.h><br>
> // #include <Qt3DExtras/qfirstpersoncameracontroller.h><br>
> #include "MyCameraController.h"<br>
> #include "TrackballCameraController.h"<br>
> <br>
> class SceneWalker : public QObject<br>
> {<br>
> public:<br>
>     SceneWalker(Qt3DRender::QSceneLoader *loader) : m_loader(loader) { }<br>
> <br>
>     void onStatusChanged();<br>
> <br>
> private:<br>
>     void walkEntity(Qt3DCore::QEntity *e, int depth = 0);<br>
> <br>
>     Qt3DRender::QSceneLoader *m_loader;<br>
> };<br>
> <br>
> void SceneWalker::onStatusChanged()<br>
> {<br>
>     qDebug() << "Status changed:" << m_loader->status();<br>
>     if (m_loader->status() != Qt3DRender::QSceneLoader::Ready)<br>
>         return;<br>
> <br>
>     // The QSceneLoader instance is a component of an entity. The loaded scene<br>
>     // tree is added under this entity.<br>
>     QVector<Qt3DCore::QEntity *> entities = m_loader->entities();<br>
> <br>
>     // Technically there could be multiple entities referencing the scene loader<br>
>     // but sharing is discouraged, and in our case there will be one anyhow.<br>
>     if (entities.isEmpty())<br>
>         return;<br>
>     Qt3DCore::QEntity *root = entities[0];<br>
>     // Print the tree.<br>
>     walkEntity(root);<br>
> <br>
>     // To access a given node (like a named mesh in the scene), use QObject::findChild().<br>
>     // The scene structure and names always depend on the asset.<br>
>     Qt3DCore::QEntity *e = root->findChild<Qt3DCore::QEntity *>(QStringLiteral("PlanePropeller_mesh")); // toyplane.obj<br>
>     if (e)<br>
>         qDebug() << "Found propeller node" << e << "with components" << e->components();<br>
> }<br>
> <br>
> void SceneWalker::walkEntity(Qt3DCore::QEntity *e, int depth)<br>
> {<br>
>     Qt3DCore::QNodeVector nodes = e->childNodes();<br>
>     for (int i = 0; i < nodes.count(); ++i) {<br>
>         Qt3DCore::QNode *node = nodes[i];<br>
>         Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>(node);<br>
>         if (entity) {<br>
>             QString indent;<br>
>             indent.fill(' ', depth * 2);<br>
>             qDebug().noquote() << indent << "Entity:" << entity << "Components:" << entity->components();<br>
>             walkEntity(entity, depth + 1);<br>
>         }<br>
>     }<br>
> }<br>
> <br>
> int main(int ac, char **av)<br>
> {<br>
>     QApplication app(ac, av);<br>
>     Qt3DExtras::Qt3DWindow view;<br>
>     view.defaultFrameGraph()->setClearColor(Qt::black);<br>
> <br>
>     // Root entity<br>
>     Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity();<br>
> <br>
>     // Scene Camera<br>
>     Qt3DRender::QCamera *camera = view.camera();<br>
>     camera->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection);<br>
>     camera->setViewCenter(QVector3D(0.0f, 3.5f, 0.0f));<br>
>     camera->setPosition(QVector3D(0.0f, 3.5f, 25.0f));<br>
>     camera->setNearPlane(0.001f);<br>
>     camera->setFarPlane(10000.0f);<br>
> <br>
>     // For camera controls<br>
>     // Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(sceneRoot);<br>
>     TrackballCameraController *camController = new TrackballCameraController(sceneRoot);<br>
>     camController->setWindowSize(QSize(view.width(),view.height())); // <a href="https://github.com/cjmdaixi/Qt3DTrackball/issues/1#issuecomment-544183228" rel="noreferrer" target="_blank">https://github.com/cjmdaixi/Qt3DTrackball/issues/1#issuecomment-544183228</a><br>
>     camController->setCamera(camera);<br>
> <br>
>     // Scene loader<br>
>     Qt3DCore::QEntity *sceneLoaderEntity = new Qt3DCore::QEntity(sceneRoot);<br>
>     Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(sceneLoaderEntity);<br>
>     SceneWalker sceneWalker(sceneLoader);<br>
>     QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, &sceneWalker, &SceneWalker::onStatusChanged);<br>
>     sceneLoaderEntity->addComponent(sceneLoader);<br>
> <br>
>     QStringList args = QCoreApplication::arguments();<br>
>     QUrl sourceFileName;<br>
>     if (args.count() <= 1) {<br>
>         QWidget *container = new QWidget();<br>
>         QFileDialog dialog;<br>
>         dialog.setFileMode(QFileDialog::AnyFile);<br>
>         sourceFileName = dialog.getOpenFileUrl(container, QStringLiteral("Open a scene file"));<br>
>     } else {<br>
>         sourceFileName = QUrl::fromLocalFile(args[1]);<br>
>     }<br>
> <br>
>     if (sourceFileName.isEmpty())<br>
>         return 0;<br>
> <br>
>     sceneLoader->setSource(sourceFileName);<br>
> <br>
>     view.setRootEntity(sceneRoot);<br>
>     view.show();<br>
> <br>
>     return app.exec();<br>
> }<br>
> ```  <br>
> <br>
> Cheers<br>
> --<br>
> Nicholas Yue<br>
> <a href="https://www.linkedin.com/in/nicholasyue/" rel="noreferrer" target="_blank">https://www.linkedin.com/in/nicholasyue/</a><br>
> _______________________________________________<br>
> Interest mailing list<br>
> <a href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a><br>
> <a href="https://lists.qt-project.org/listinfo/interest" rel="noreferrer" target="_blank">https://lists.qt-project.org/listinfo/interest</a><br>
<br>
—<br>
Mike Krus | <a href="mailto:mike.krus@kdab.com" target="_blank">mike.krus@kdab.com</a> | Senior Software Engineer & Teamlead<br>
KDAB (UK) Ltd., a KDAB Group company<br>
Tel: UK Office +44 1625 809908   Mobile +44 7833 491941<br>
KDAB - The Qt Experts, C++, OpenGL Experts<br>
<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Nicholas Yue<br><a href="https://www.linkedin.com/in/nicholasyue/" target="_blank">https://www.linkedin.com/in/nicholasyue/</a><br></div></div>