Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Exporting 3D content for Qt 3D with Blender


Entity {
    components: [
        GeometryRenderer {
            geometry: ...
        },
        Material {}
    ]
}

Entity {
    components: [
        ConeMesh {
            rings: 16
            slices: 16
            topRadius: 0.1
            bottomRadius: 1.0
       },
       Material {...}
    ]
}

Entity {
    components: [
        Mesh {
            source: "path/to/my/file.obj"
        },
        Material {...}
    ]
}

Entity {
    components: [
        SceneLoader {
            source: "path/to/my/scene.obj"
        }
   ]
}

Buffer {
    type: Buffer.VertexBuffer
    data: readBinaryFile("qrc:/assets/binaries/bufferdata.bin")
}

class Qt3DExporter(bpy.types.Operator, ExportHelper, OrientationHelper):
    """Qt3D Exporter"""
    bl_idname = "export_scene.qt3d_exporter";
    bl_label = "Qt3DExporter";
    filename_ext = ""

    # We set up exporter UI here
    use_mesh_modifiers = BoolProperty(
        name="Apply Modifiers",
        description="Apply modifiers (preview resolution)",
        default=True,
    )

    use_selection_only = BoolProperty(
        name="Selection Only",
        description="Only export selected objects",
        default=False,
    )

    def draw(self, context):
        layout = self.layout
        col = layout.box().column(align=True)
        col.label("Nodes", icon="OBJECT_DATA")
        col.prop(self, "use_selection_only")
        col.prop(self, "use_visible_only")

    def execute(self, context):
        # Actual exporting work to be done here

def createBlenderMenu(self, context):
    self.layout.operator(Qt3DExporter.bl_idname, text="Qt3D (.qml)")

# Register against Blender
def register():
    bpy.utils.register_class(Qt3DExporter)
    bpy.types.INFO_MT_file_export.append(createBlenderMenu)

def unregister():
    bpy.utils.unregister_class(Qt3DExporter)
    bpy.types.INFO_MT_file_export.remove(createBlenderMenu)


    def execute(self, context):
        exportSettings = self.as_keywords()
        exportSettings["global_matrix"] = axis_conversion(to_forward=self.axis_forward, to_up=self.axis_up).to_4x4()

        self.binaryDirectoryName = "assets/binaries/"
        self.shadersDirectoryName = "assets/shaders/"
        self.qmlDirectoryName = "qml"

        self.userpath = self.properties.filepath
        if not os.path.isdir(self.userpath):
            self.userpath = os.path.dirname(self.userpath)
            msg = "Selecting directory: " + self.userpath
            self.report({"INFO"}, msg)

        # switch to work dir and create directories
        os.chdir(self.userpath)
        if not os.path.exists(self.binaryDirectoryName):
            os.makedirs(self.binaryDirectoryName)
        if not os.path.exists(self.shadersDirectoryName):
            os.makedirs(self.shadersDirectoryName)
        if not os.path.exists(self.qmlDirectoryName):
            os.makedirs(self.qmlDirectoryName)

        # Save scene into scene
        scene = bpy.context.scene

        exporter = Exporter(scene, exportSettings)
        exporter.export()

        # Create QML Files
        exporter.createQMLNodeTree()

        # Create .qrc file
        exporter.generateQRCFiles()

        # Create main.cpp
        exporter.generateMainCppFile()

        # Create .pro
        exporter.generateProjectFile(self.userpath)


6 Comments

26 - Feb - 2018

xuin

26 - Feb - 2018

Paul Lemire

5 - Mar - 2018

modir

6 - Mar - 2018

Pirngadi

4 - Aug - 2020

hamdi

12 - Aug - 2020

Paul Lemire

PaulLemire

Paul Lemire

Senior Software Engineer