Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How do I use the QML 3D Model type?
Forum Updated to NodeBB v4.3 + New Features

How do I use the QML 3D Model type?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 251 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AI_Messiah
    wrote on last edited by
    #1

    This is something that I really want to use, but how do I define the model itself. I mean how do I create an instance of the 3D Model. I tried to use this code that I copied

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick3D 1.15
    import QtQuick3D.Materials 1.15
    import QtQuick3D.Effects 1.15
    import QtQuick3D.Helpers 1.15
    
    Window {
      id: window
      visible: true
      width: 1280
      height: 720
    
      // Viewport for 3D content
      View3D {
        id: view
    
        anchors.fill: parent
        // Scene to view
        Node {
          id: scene
    
          Light {
    
            id: directionalLight
    
          }
          Camera {
                  id: camera
                  // It's important that your camera is not inside
                  // your model so move it back along the z axis
                  // The Camera is implicitly facing up the z axis,
                  // so we should be looking towards (0, 0, 0)
                  z: -600
                }
    
                Model {
                  id: cubeModel
                  // #Cube is one of the "built-in" primitive meshes
                  // Other Options are:
                  // #Cone, #Sphere, #Cylinder, #Rectangle
                  source: "#Cube"
    
                  // When using a Model, it is not enough to have a
                  // mesh source (ie "#Cube")
                  // You also need to define what material to shade
                  // the mesh with. A Model can be built up of
                  // multiple sub-meshes, so each mesh needs its own
                  materials: [
    
                            DefaultMaterial {
    
                              // We are using the DefaultMaterial which
                              // dynamically generates a shader based on what
                              // properties are set. This means you don't
                              // need to write any shader code yourself.
                              // In this case we just want the cube to have
                              // a red diffuse color.
                              id: cubeMaterial
                              diffuseColor: "red"
                            }
                          ]
                        }
                      }
                    }
                  }
    
    

    When I run it I get the error: QQmlApplicationEngine failed to load component
    <Unknown File>:20:7: Light is Abstract

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved