#c #qt #qt6
Вопрос:
Я рад, что ошибка с загрузкой файлов COLLADA DAE была исправлена в Qt 6. Но у меня странная проблема: модель COLLADA DAE темнее, чем OBJ.
Я создал этот куб в блендере 2.93:
С OBJ это прекрасно работает:
Но когда я экспортирую в DAE, я вижу, что модель темнее:
This is my .pro file:
QT = 3dcore 3dlogic 3dextras 3dinput
This is the main.cpp file:
#ifdef _WIN32 #include lt;windows.hgt; extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; #endif #include lt;QtCore/QDebuggt; #include lt;QtGui/QGuiApplicationgt; #include lt;Qt3DExtras/Qt3DWindowgt; #include lt;Qt3DExtras/QCuboidMeshgt; #include lt;Qt3DExtras/QPhongMaterialgt; #include lt;Qt3DExtras/QOrbitCameraControllergt; #include lt;Qt3DCore/QEntitygt; #include lt;Qt3DCore/QTransformgt; #include lt;Qt3DRender/QCameragt; #include lt;Qt3DRender/QPointLightgt; #include lt;Qt3DRender/QSceneLoadergt; class Window : public Qt3DExtras::Qt3DWindow { public: Window() { setTitle("COLLADA DAE 3D model"); resize(400, 400); Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); // Lighting Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity); Qt3DRender::QPointLight *pointLight = new Qt3DRender::QPointLight(lightEntity); Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity); lightTransform-gt;setTranslation(QVector3D(20.f, 25.f, 30.f)); lightEntity-gt;addComponent(pointLight); lightEntity-gt;addComponent(lightTransform); // 3D Model Qt3DCore::QEntity *objectEntity = new Qt3DCore::QEntity(rootEntity); Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(objectEntity); // sceneLoader-gt;setSource(QUrl("qrc:/Models/Cube.obj")); sceneLoader-gt;setSource(QUrl("qrc:/Models/Cube.dae")); objectEntity-gt;addComponent(sceneLoader); Qt3DCore::QTransform *objectTransform = new Qt3DCore::QTransform(objectEntity); objectTransform-gt;setScale(10.f); objectEntity-gt;addComponent(objectTransform); // Camera Qt3DRender::QCamera *camera = this-gt;camera(); camera-gt;lens()-gt;setPerspectiveProjection( 60.f, (float) this-gt;width() / this-gt;height(), 0.1f, 500.0f); camera-gt;setPosition(QVector3D(30.0f, 30.0f, 30.f)); camera-gt;setViewCenter(QVector3D(0.f, 0.f, 0.f)); Qt3DExtras::QOrbitCameraController *cameraController = new Qt3DExtras::QOrbitCameraController(rootEntity); cameraController-gt;setCamera(camera); cameraController-gt;setLookSpeed(180.f); cameraController-gt;setLinearSpeed(50.f); this-gt;setRootEntity(rootEntity); } }; int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); Window w; w.show(); return app.exec(); }
This is a model of Cube:
Cube.dae
lt;?xml version="1.0" encoding="utf-8"?gt; lt;COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1"gt; lt;assetgt; lt;contributorgt; lt;authorgt;Blender Userlt;/authorgt; lt;authoring_toolgt;Blender 2.76.0 commit date:2015-10-11, commit time:06:55, hash:48f7dd6lt;/authoring_toolgt; lt;/contributorgt; lt;createdgt;2020-12-10T01:55:11lt;/createdgt; lt;modifiedgt;2020-12-10T01:55:11lt;/modifiedgt; lt;unit name="meter" meter="1"/gt; lt;up_axisgt;Z_UPlt;/up_axisgt; lt;/assetgt; lt;library_images/gt; lt;library_effectsgt; lt;effect id="BackgoundMaterial-effect"gt; lt;profile_COMMONgt; lt;technique sid="common"gt; lt;phonggt; lt;emissiongt; lt;color sid="emission"gt;0 0 0 1lt;/colorgt; lt;/emissiongt; lt;ambientgt; lt;color sid="ambient"gt;0 0 0 1lt;/colorgt; lt;/ambientgt; lt;diffusegt; lt;color sid="diffuse"gt;0.07052612 0.64 0.02013014 1lt;/colorgt; lt;/diffusegt; lt;speculargt; lt;color sid="specular"gt;0.5 0.5 0.5 1lt;/colorgt; lt;/speculargt; lt;shininessgt; lt;float sid="shininess"gt;50lt;/floatgt; lt;/shininessgt; lt;index_of_refractiongt; lt;float sid="index_of_refraction"gt;1lt;/floatgt; lt;/index_of_refractiongt; lt;/phonggt; lt;/techniquegt; lt;/profile_COMMONgt; lt;/effectgt; lt;effect id="SideMaterial-effect"gt; lt;profile_COMMONgt; lt;technique sid="common"gt; lt;phonggt; lt;emissiongt; lt;color sid="emission"gt;0 0 0 1lt;/colorgt; lt;/emissiongt; lt;ambientgt; lt;color sid="ambient"gt;0 0 0 1lt;/colorgt; lt;/ambientgt; lt;diffusegt; lt;color sid="diffuse"gt;0.64 0.06314375 0.129652 1lt;/colorgt; lt;/diffusegt; lt;speculargt; lt;color sid="specular"gt;0.5 0.5 0.5 1lt;/colorgt; lt;/speculargt; lt;shininessgt; lt;float sid="shininess"gt;50lt;/floatgt; lt;/shininessgt; lt;index_of_refractiongt; lt;float sid="index_of_refraction"gt;1lt;/floatgt; lt;/index_of_refractiongt; lt;/phonggt; lt;/techniquegt; lt;/profile_COMMONgt; lt;/effectgt; lt;/library_effectsgt; lt;library_materialsgt; lt;material id="BackgoundMaterial-material" name="BackgoundMaterial"gt; lt;instance_effect url="#BackgoundMaterial-effect"/gt; lt;/materialgt; lt;material id="SideMaterial-material" name="SideMaterial"gt; lt;instance_effect url="#SideMaterial-effect"/gt; lt;/materialgt; lt;/library_materialsgt; lt;library_geometriesgt; lt;geometry id="Cube-mesh" name="Cube"gt; lt;meshgt; lt;source id="Cube-mesh-positions"gt; lt;float_array id="Cube-mesh-positions-array" count="24"gt;1 1 -1 1 -1 -1 -1 -0.9999998 -1 -0.9999997 1 -1 1 0.9999995 1 0.9999994 -1.000001 1 -1 -0.9999997 1 -1 1 1lt;/float_arraygt; lt;technique_commongt; lt;accessor source="#Cube-mesh-positions-array" count="8" stride="3"gt; lt;param name="X" type="float"/gt; lt;param name="Y" type="float"/gt; lt;param name="Z" type="float"/gt; lt;/accessorgt; lt;/technique_commongt; lt;/sourcegt; lt;source id="Cube-mesh-normals"gt; lt;float_array id="Cube-mesh-normals-array" count="36"gt;0 0 -1 0 0 1 1 -5.96046e-7 3.27825e-7 -4.76837e-7 -1 0 -1 2.38419e-7 -1.19209e-7 2.08616e-7 1 0 0 0 -1 0 0 1 1 0 -2.38419e-7 0 -1 -4.76837e-7 -1 2.38419e-7 -1.49012e-7 2.68221e-7 1 2.38419e-7lt;/float_arraygt; lt;technique_commongt; lt;accessor source="#Cube-mesh-normals-array" count="12" stride="3"gt; lt;param name="X" type="float"/gt; lt;param name="Y" type="float"/gt; lt;param name="Z" type="float"/gt; lt;/accessorgt; lt;/technique_commongt; lt;/sourcegt; lt;vertices id="Cube-mesh-vertices"gt; lt;input semantic="POSITION" source="#Cube-mesh-positions"/gt; lt;/verticesgt; lt;polylist material="BackgoundMaterial-material" count="10"gt; lt;input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/gt; lt;input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/gt; lt;vcountgt;3 3 3 3 3 3 3 3 3 3 lt;/vcountgt; lt;pgt;0 0 1 0 2 0 7 1 6 1 5 1 5 3 6 3 2 3 2 4 6 4 7 4 0 5 3 5 7 5 3 6 0 6 2 6 4 7 7 7 5 7 1 9 5 9 2 9 3 10 2 10 7 10 4 11 0 11 7 11lt;/pgt; lt;/polylistgt; lt;polylist material="SideMaterial-material" count="2"gt; lt;input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/gt; lt;input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/gt; lt;vcountgt;3 3 lt;/vcountgt; lt;pgt;4 2 5 2 1 2 0 8 4 8 1 8lt;/pgt; lt;/polylistgt; lt;/meshgt; lt;/geometrygt; lt;/library_geometriesgt; lt;library_controllers/gt; lt;library_visual_scenesgt; lt;visual_scene id="Scene" name="Scene"gt; lt;node id="Cube" name="Cube" type="NODE"gt; lt;matrix sid="transform"gt;1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1lt;/matrixgt; lt;instance_geometry url="#Cube-mesh" name="Cube"gt; lt;bind_materialgt; lt;technique_commongt; lt;instance_material symbol="BackgoundMaterial-material" target="#BackgoundMaterial-material"/gt; lt;instance_material symbol="SideMaterial-material" target="#SideMaterial-material"/gt; lt;/technique_commongt; lt;/bind_materialgt; lt;/instance_geometrygt; lt;/nodegt; lt;/visual_scenegt; lt;/library_visual_scenesgt; lt;scenegt; lt;instance_visual_scene url="#Scene"/gt; lt;/scenegt; lt;/COLLADAgt;
Cube.obj
# Blender v2.93.5 OBJ File: '' # www.blender.org mtllib Cube.mtl o Cube_Cube.001 v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 -1.000000 -1.000000 v 1.000000 1.000000 -1.000000 v 0.999999 1.000000 1.000001 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 vn 0.0000 -1.0000 0.0000 vn 0.0000 1.0000 0.0000 vn -0.0000 0.0000 1.0000 vn -1.0000 -0.0000 0.0000 vn 0.0000 0.0000 -1.0000 vn 1.0000 0.0000 0.0000 usemtl BackgoundMaterial s off f 1//1 2//1 3//1 f 8//2 7//2 6//2 f 6//3 7//3 3//3 f 3//4 7//4 8//4 f 1//5 4//5 8//5 f 4//1 1//1 3//1 f 5//2 8//2 6//2 f 2//3 6//3 3//3 f 4//4 3//4 8//4 f 5//5 1//5 8//5 usemtl SideMaterial f 5//6 6//6 2//6 f 1//6 5//6 2//6
Cube.mtl
# Blender MTL File: 'None' # Material Count: 2 newmtl BackgoundMaterial Ns 225.000000 Ka 1.000000 1.000000 1.000000 Kd 0.070526 0.640000 0.020130 Ks 0.500000 0.500000 0.500000 Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2 newmtl SideMaterial Ns 225.000000 Ka 1.000000 1.000000 1.000000 Kd 0.640000 0.063144 0.129652 Ks 0.500000 0.500000 0.500000 Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2