#include #include #include #include #include #include #include #include #include Qt3DCore::QEntity *createScene() { Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity; Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh(rootEntity); mesh->setSource(QUrl::fromLocalFile("C:/robot_rexeported.gltf")); Qt3DExtras::QPhongMaterial *meshMaterial = new Qt3DExtras::QPhongMaterial(rootEntity); meshMaterial->setDiffuse(QColor(QRgb(0xa69929))); Qt3DCore::QEntity *meshEntity = new Qt3DCore::QEntity(rootEntity); Qt3DCore::QTransform *meshTransform = new Qt3DCore::QTransform(rootEntity); meshEntity->addComponent(mesh); meshEntity->addComponent(meshTransform); meshEntity->addComponent(meshMaterial); Qt3DCore::QSkeletonLoader* skeletonLoader = new Qt3DCore::QSkeletonLoader(meshEntity); skeletonLoader->setSource(QUrl::fromLocalFile("C:/robot_rexeported.gltf")); skeletonLoader->setCreateJointsEnabled(true); Qt3DCore::QArmature *meshArmature = new Qt3DCore::QArmature; meshArmature->setSkeleton(skeletonLoader); meshEntity->addComponent(meshArmature); Qt3DAnimation::QSkeletonMapping* skeletonMapping = new Qt3DAnimation::QSkeletonMapping(meshEntity); skeletonMapping->setSkeleton(skeletonLoader); Qt3DAnimation::QChannelMapper *m_channelMapper = new Qt3DAnimation::QChannelMapper; m_channelMapper->addMapping(skeletonMapping); animator->setLoopCount(Qt3DAnimation::QAbstractClipAnimator::Infinite); animator->setChannelMapper(m_channelMapper); animator->setRunning(true); return rootEntity; } int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); Qt3DExtras::Qt3DWindow view; Qt3DCore::QEntity *scene = createScene(); Qt3DRender::QCamera *camera = view.camera(); camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); camera->setPosition(QVector3D(0, 0, 40.0f)); camera->setViewCenter(QVector3D(0, 0, 0)); Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(scene); camController->setLinearSpeed( 50.0f ); camController->setLookSpeed( 180.0f ); camController->setCamera(camera); Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(scene); Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity); light->setColor("white"); light->setIntensity(1); lightEntity->addComponent(light); Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity); lightTransform->setTranslation(camera->position()); lightEntity->addComponent(lightTransform); Qt3DCore::QEntity *lightEntity2 = new Qt3DCore::QEntity(scene); Qt3DRender::QPointLight *light2 = new Qt3DRender::QPointLight(lightEntity2); light2->setColor("yellow"); light2->setIntensity(1); lightEntity2->addComponent(light2); Qt3DCore::QTransform *lightTransform2 = new Qt3DCore::QTransform(lightEntity2); lightTransform2->setTranslation(QVector3D(5.0f, 5.0f, -3.0f)); lightEntity2->addComponent(lightTransform2); view.setRootEntity(scene); view.defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f))); view.registerAspect(new Qt3DAnimation::QAnimationAspect()); view.show(); return app.exec(); }