Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt3D骨骼动画_C++_Qt_Qt3d - Fatal编程技术网

C++ Qt3D骨骼动画

C++ Qt3D骨骼动画,c++,qt,qt3d,C++,Qt,Qt3d,我尝试将KDAB QT3D QML示例转换为C++。我真的很难过,因为文档基本上没有用处 以下是我到目前为止编写的程序: #include <QApplication> #include <Qt3DCore> #include <Qt3DRender> #include <Qt3DExtras> #include <Qt3DAnimation> #include <QSkeletonLoader> #include <

我尝试将KDAB QT3D QML示例转换为C++。我真的很难过,因为文档基本上没有用处

以下是我到目前为止编写的程序:

#include <QApplication>

#include <Qt3DCore>
#include <Qt3DRender>
#include <Qt3DExtras>
#include <Qt3DAnimation>
#include <QSkeletonLoader>
#include <QSkeletonMapping>
#include <QDebug>

Qt3DCore::QEntity *createScene()
{
    Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;

    Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh(rootEntity);
    mesh->setSource(QUrl::fromLocalFile("D:/Robot/robot.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);

    auto* animator = new Qt3DAnimation::QClipAnimator(meshEntity);
    auto* clip = new Qt3DAnimation::QAnimationClipLoader(QUrl::fromLocalFile("D:/Robot/robot.gltf"), animator);
    animator->setClip(clip);

    Qt3DCore::QSkeletonLoader* skeletonLoader = new Qt3DCore::QSkeletonLoader(meshEntity);
    skeletonLoader->setSource(QUrl::fromLocalFile("D:/Robot/robot.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();
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
Qt3DCore::QEntity*createScene()
{
Qt3DCore::QEntity*rootEntity=新的Qt3DCore::QEntity;
Qt3DRender::QMesh*mesh=新的Qt3DRender::QMesh(rootEntity);
mesh->setSource(QUrl::fromLocalFile(“D:/Robot/Robot.gltf”);
Qt3DExtras::QPhongMaterial*meshMaterial=新的Qt3DExtras::QPhongMaterial(rootEntity);
meshMaterial->setDiffuse(QColor(QRgb(0xa69929));
Qt3DCore::QEntity*meshEntity=新的Qt3DCore::QEntity(rootEntity);
Qt3DCore::QTransform*meshTransform=新的Qt3DCore::QTransform(rootEntity);
网格实体->添加组件(网格);
meshEntity->addComponent(meshTransform);
网格实体->添加组件(网格材质);
auto*animator=新的Qt3DAnimation::QCLIPANITOR(网格实体);
auto*clip=new Qt3DAnimation::QAnimationClipLoader(QUrl::fromLocalFile(“D:/Robot/Robot.gltf”),animator);
动画师->设置剪辑(剪辑);
Qt3DCore::QSkeletonLoader*skeletonLoader=新的Qt3DCore::QSkeletonLoader(meshEntity);
skeletonLoader->setSource(QUrl::fromLocalFile(“D:/Robot/Robot.gltf”);
skeletonLoader->SetCreateJointEnabled(true);
Qt3DCore::QArmature*meshaket=新的Qt3DCore::QArmature;
Mesh电枢->setSkeleton(骨架装载机);
网格实体->添加组件(网格电枢);
Qt3DAnimation::QSkeletonMapping*skeletonMapping=新的Qt3DAnimation::QSkeletonMapping(meshEntity);
骨架贴图->设置骨架(骨架装载机);
Qt3DAnimation::QChannelMapper*m_channelMapper=新的Qt3DAnimation::QChannelMapper;
m_channelMapper->addMapping(skeletonMapping);
animator->setLoopCount(Qt3DAnimation::QAbstractClipAnimator::Infinite);
animator->setChannelMapper(m_channelMapper);
animator->setRunning(真);
返回根实体;
}
int main(int argc,char*argv[])
{
QGUI应用程序应用程序(argc、argv);
Qt3DExtras::Qt3DWindow视图;
Qt3DCore::QEntity*scene=createScene();
Qt3DRender::QCamera*camera=view.camera();
摄像头->镜头()->设置透视投影(45.0f、16.0f/9.0f、0.1f、1000.0f);
摄像头->设置位置(QVector3D(0,0,40.0f));
摄像头->设置视图中心(QVector3D(0,0,0));
qt3detras::QOrbitCameraController*camController=新的qt3detras::QOrbitCameraController(场景);
凸轮控制器->设定线速度(50.0f);
camController->setLookSpeed(180.0f);
摄像机控制器->设置摄像机(摄像机);
Qt3DCore::QEntity*lightetity=新的Qt3DCore::QEntity(场景);
Qt3DRender::QPointLight*light=新的Qt3DRender::QPointLight(亮度);
灯光->设置颜色(“白色”);
光照->设置强度(1);
亮度->添加组件(灯光);
Qt3DCore::QTransform*lightTransform=新的Qt3DCore::QTransform(亮度);
lightTransform->setTranslation(摄影机->位置());
Lightetity->addComponent(lightTransform);
Qt3DCore::QEntity*lightetty2=新的Qt3DCore::QEntity(场景);
Qt3DRender::QPointLight*light2=新的Qt3DRender::QPointLight(lighttity2);
light2->setColor(“黄色”);
light2->setIntensity(1);
LightTity2->添加组件(light2);
Qt3DCore::QTransform*lightTransform2=新的Qt3DCore::QTransform(lighttity2);
lightTransform2->setTranslation(QVector3D(5.0f,5.0f,-3.0f));
LightTity2->添加组件(lightTransform2);
view.setRootEntity(场景);
view.defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4f));
view.registerAspect(新的Qt3DAnimation::QAnimationAspect());
view.show();
返回app.exec();
}
它不会抛出任何运行时错误,并显示机器人网格,但不会设置动画!网格渲染时手臂张开,对我来说,看起来电枢没有应用到网格上,但我不知道我可能做错了什么。。。。。顺便说一句,QML示例正在运行。是否有人发现可能导致问题的原始QML存在差异

编辑:文件robot.gltf是示例中的原始文件