Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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
使用QML中的obj文件,3D对象不显示原始颜色_Qml_Qt3d - Fatal编程技术网

使用QML中的obj文件,3D对象不显示原始颜色

使用QML中的obj文件,3D对象不显示原始颜色,qml,qt3d,Qml,Qt3d,我尝试使用以下QML显示简单的3D汽车: import QtQuick 2.2 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 import Qt3D.Extras 2.0 Entity { id: sceneRoot Camera { id: camera projectionType: CameraLens.PerspectiveProject

我尝试使用以下QML显示简单的3D汽车:

import QtQuick 2.2 as QQ2
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0

Entity {
    id: sceneRoot

    Camera {
        id: camera
        projectionType: CameraLens.PerspectiveProjection
        fieldOfView: 45
        aspectRatio: 16/9
        nearPlane : 0.1
        farPlane : 500.0
        position: Qt.vector3d( 0.0, 0.0, -40.0 )
        upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
        viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
    }

    OrbitCameraController {
        camera: camera
    }

    components: [
        RenderSettings {
            activeFrameGraph: ForwardRenderer {
                clearColor: Qt.rgba(0, 0.5, 1, 1)
                camera: camera
            }
        },
        // Event Source will be set by the Qt3DQuickWindow
        InputSettings { }
    ]
    Mesh{
        id: sphereMesh
        source: "qrc:/../../../../../Desktop/Qt-3d/assets/55z27frcahz4P911GT/Porsche_911_GT2.obj"
    }

    PhongMaterial {
        id : spherematerial
        shininess: 1
    }

    Transform {
        id: sphereTransform
        property real userAngle: 0.0
        scale: sceneRoot.scale
         rotation: fromAxisAndAngle(Qt.vector3d(0, 1, 0), 45)
        matrix: {
            var m = Qt.matrix4x4();
            m.rotate(userAngle, Qt.vector3d(0, 1, 0));
//            m.translate(Qt.vector3d(0, 0, 20));
            return m;
        }
    }

    QQ2.NumberAnimation {
        target: sphereTransform
        property: "userAngle"
        duration: 10000
        from: 0
        to: 360

        loops: QQ2.Animation.Infinite
        running: true
    }

    Entity {
        id: sphereEntity
        
        components: [ sphereMesh, spherematerial, sphereTransform ]
    }
}
然而,当执行此代码时,我可以看到3D汽车旋转。但它不包含来自3D对象的原始颜色。它显示3D汽车的默认颜色。我怎样才能得到原色

  • 我需要在材质上使用纹理吗?如果是,怎么做
  • 我需要在QML中使用mtl文件吗?如果是,怎么做
  • 请注意

  • 出于某些原因,我不想使用Qt Quick 3D模块
  • 另外,我不想使用Qt3DStudio

  • 使用
    Qt3D::QMesh
    加载网格仅加载顶点数据(顶点、法线、纹理坐标),而不加载纹理,并且不会添加任何
    Qt3DRender::QMaterial
    s。您正在添加一个简单的
    Qt3DExtras::QPhongMaterial
    ,它只将一种颜色应用于整个对象

    如果对象提供逐顶点颜色信息,则可以尝试
    Qt3DExtras::qServerTexColorMaterial

    如果不起作用,请尝试
    Qt3DRender::QSceneLoader
    :在那里,您将URL设置为模型,它会自动加载所有内容,并尝试应用正确的材质。创建它以代替
    QMesh
    ,并将其作为组件添加