Exemple #1
0
def ExportObjects(bus, exportNodes=True, exportMeshes=None):
    o      = bus['output']
    scene  = bus['scene']
    camera = bus['camera']

    VRayScene    = scene.vray
    VRayExporter = VRayScene.Exporter

    # Setup object to skip, this is mainly from "Effect" gizmos
    skipObjects = [ob.as_pointer() for ob in bus['skipObjects']]
    _vray_for_blender.setSkipObjects(bus['exporter'], skipObjects)

    # Setup "Hide From View"
    hideFromView = BlenderUtils.GetCameraHideLists(camera)
    _vray_for_blender.setHideFromView(bus['exporter'], hideFromView)

    # In DR we export to a single file so we must force mesh re-export
    if VRayScene.VRayDR.on:
        exportMeshes = True

    # Finally export stuff
    exportGeometry = exportMeshes if exportMeshes is not None else VRayExporter.auto_meshes

    _vray_for_blender.exportScene(
        bus['exporter'],
        exportNodes,
        exportGeometry
    )

    # Clean current frame name cache
    bus['cache']['plugins'] = set()
    _vray_for_blender.clearCache()
    o.resetNamesCache()
Exemple #2
0
def ExportObjects(bus, exportNodes=True, exportMeshes=None):
    o = bus['output']
    scene = bus['scene']
    camera = bus['camera']

    VRayScene = scene.vray
    VRayExporter = VRayScene.Exporter

    # Setup object to skip, this is mainly from "Effect" gizmos
    skipObjects = [ob.as_pointer() for ob in bus['skipObjects']]
    _vray_for_blender.setSkipObjects(bus['exporter'], skipObjects)

    # Setup "Hide From View"
    hideFromView = BlenderUtils.GetCameraHideLists(camera)
    _vray_for_blender.setHideFromView(bus['exporter'], hideFromView)

    # In DR we export to a single file so we must force mesh re-export
    if VRayScene.VRayDR.on:
        exportMeshes = True

    # Finally export stuff
    exportGeometry = exportMeshes if exportMeshes is not None else VRayExporter.auto_meshes

    _vray_for_blender.exportScene(bus['exporter'], exportNodes, exportGeometry)

    # Clean current frame name cache
    bus['cache']['plugins'] = set()
    _vray_for_blender.clearCache()
    o.resetNamesCache()
def ExportObjects(objects,
                  filepath,
                  animation='NONE',
                  frameStart=1,
                  frameEnd=10):
    scene = bpy.context.scene

    vrsceneFile = open(filepath, 'w')

    o = VRayStream.VRaySimplePluginExporter(outputFile=vrsceneFile)

    exporter = _vray_for_blender.init(
        engine=0,
        context=bpy.context.as_pointer(),
        scene=scene.as_pointer(),
        data=bpy.data.as_pointer(),
        mainFile=o.output,
        objectFile=o.output,
        envFile=o.output,
        geometryFile=o.output,
        lightsFile=o.output,
        materialFile=o.output,
        textureFile=o.output,
        drSharePath="",
    )

    def _export_objects(objects):
        # Init stuff for dupli / particles / etc
        _vray_for_blender.exportObjectsPre(exporter)
        for ob in objects:
            print(ob.name)
            _vray_for_blender.exportObject(ob.as_pointer(),
                                           bpy.data.as_pointer(), exporter)
        # Write dupli / particles / etc
        _vray_for_blender.exportObjectsPost(exporter)

    # NOTE: Have to do it before export pre init
    if animation not in {'NONE'}:
        _vray_for_blender.initAnimation(True, frameStart, frameEnd)

    if animation not in {'NONE'}:
        while frameStart <= frameEnd:
            print(frameStart)

            scene.frame_set(frameStart)
            _vray_for_blender.setFrame(frameStart)

            _export_objects(objects)

            frameStart += scene.frame_step
    else:
        _export_objects(objects)

    o.done()
    vrsceneFile.close()
    _vray_for_blender.clearFrames()
    _vray_for_blender.clearCache()
    _vray_for_blender.exit(exporter)
Exemple #4
0
def ExportObjects(objects, filepath, animation='NONE', frameStart=1, frameEnd=10):
    scene = bpy.context.scene

    vrsceneFile = open(filepath, 'w')

    o = VRayStream.VRaySimplePluginExporter(outputFile=vrsceneFile)

    exporter = _vray_for_blender.init(
        engine  = 0,
        context = bpy.context.as_pointer(),
        scene   = scene.as_pointer(),
        data    = bpy.data.as_pointer(),

        mainFile     = o.output,
        objectFile   = o.output,
        envFile      = o.output,
        geometryFile = o.output,
        lightsFile   = o.output,
        materialFile = o.output,
        textureFile  = o.output,

        drSharePath = "",
    )

    def _export_objects(objects):
        # Init stuff for dupli / particles / etc
        _vray_for_blender.exportObjectsPre(exporter)
        for ob in objects:
            print(ob.name)
            _vray_for_blender.exportObject(ob.as_pointer(), bpy.data.as_pointer(), exporter)
        # Write dupli / particles / etc
        _vray_for_blender.exportObjectsPost(exporter)

    # NOTE: Have to do it before export pre init
    if animation not in {'NONE'}:
        _vray_for_blender.initAnimation(True,
            frameStart,
            frameEnd
        )

    if animation not in {'NONE'}:
        while frameStart <= frameEnd:
            print(frameStart)

            scene.frame_set(frameStart)
            _vray_for_blender.setFrame(frameStart)

            _export_objects(objects)

            frameStart += scene.frame_step
    else:
        _export_objects(objects)

    o.done()
    vrsceneFile.close()
    _vray_for_blender.clearFrames()
    _vray_for_blender.clearCache()
    _vray_for_blender.exit(exporter)
Exemple #5
0
    def execute(self, context):
        sce = context.scene

        # Use current active object UI for initial settings
        ob        = bpy.context.object
        selection = bpy.context.selected_objects
        oneObject = len(selection)

        GeomMeshFile = ob.data.vray.GeomMeshFile

        # Create output path
        outputDirpath = BlenderUtils.GetFullFilepath(GeomMeshFile.dirpath)
        outputDirpath = PathUtils.CreateDirectory(outputDirpath)

        # Create tmp export file
        vrsceneFilepath = os.path.join(tempfile.gettempdir(), "vrmesh.vrscene")
        vrsceneFile = open(vrsceneFilepath, 'w')

        # Settings
        frames = None
        frameStart = 1
        frameStep  = 1
        if GeomMeshFile.animation not in {'NONE'}:
            if GeomMeshFile.animation == 'MANUAL':
                frameStart = GeomMeshFile.frame_start
                frames = (frameStart, GeomMeshFile.frame_end, 1)
            else:
                frameStart = sce.frame_start
                frameStep  = sce.frame_step
                frames = (sce.frame_start, sce.frame_end, sce.frame_step)

        applyTm     = GeomMeshFile.apply_transforms
        useVelocity = GeomMeshFile.add_velocity

        # Export objects meshes and generate nodes name list
        obPluginNames = []
        o = VRayStream.VRaySimplePluginExporter(outputFile=vrsceneFile)

        exporter = _vray_for_blender.init(
            engine  = 0,
            context = bpy.context.as_pointer(),
            scene   = sce.as_pointer(),
            data    = bpy.data.as_pointer(),

            mainFile     = o.output,
            objectFile   = o.output,
            envFile      = o.output,
            geometryFile = o.output,
            lightsFile   = o.output,
            materialFile = o.output,
            textureFile  = o.output,

            drSharePath = "",
        )

        _vray_for_blender.setFrame(frameStart)

        for ob in selection:
            if ob.type in BlenderUtils.NonGeometryTypes:
                continue
            nodeName = None
            if not frames:
                nodeName = ExportMeshSample(o, ob)
            else:
                sce = bpy.context.scene
                frame_current = sce.frame_current
                for f in range(frames[0], frames[1]+frames[2], frames[2]):
                    bpy.context.scene.frame_set(f)
                    _vray_for_blender.setFrame(f)
                    nodeName = ExportMeshSample(o, ob)
                    _vray_for_blender.clearCache()
                sce.frame_set(frame_current)
            obPluginNames.append([ob, nodeName])
        o.done()
        vrsceneFile.close()

        _vray_for_blender.clearFrames()
        _vray_for_blender.exit(exporter)

        # Launch the generator tool
        err = None
        for ob, nodeName in obPluginNames:
            vrmeshName = LibUtils.CleanString(ob.name)
            if oneObject and GeomMeshFile.filename:
                vrmeshName = GeomMeshFile.filename
            vrmeshName += ".vrmesh"
            vrmeshFilepath = os.path.join(outputDirpath, vrmeshName)

            err = LaunchPly2Vrmesh(vrsceneFilepath, vrmeshFilepath, nodeName, frames, applyTm, useVelocity)
            if err is not None:
                break

            if GeomMeshFile.proxy_attach_mode != 'NONE':
                attachOb = ob

                if GeomMeshFile.proxy_attach_mode == 'NEW':
                    newName = '%s@VRayProxy' % ob.name
                    newMesh = bpy.data.meshes.new(newName)
                    attachOb = bpy.data.objects.new(newName, newMesh)

                    context.scene.objects.link(attachOb)

                BlenderUtils.SelectObject(attachOb)

                if GeomMeshFile.proxy_attach_mode == 'NEW':
                    for slot in ob.material_slots:
                        if slot and slot.material:
                            attachOb.data.materials.append(slot.material)
                            attachOb.material_slots[-1].link     = 'OBJECT'
                            attachOb.material_slots[-1].material = slot.material

                if GeomMeshFile.apply_transforms:
                    bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
                else:
                    attachOb.matrix_world = ob.matrix_world

                CreateProxyNodetree(attachOb, vrmeshFilepath)

                if GeomMeshFile.proxy_attach_mode in {'NEW', 'REPLACE'}:
                    LoadProxyPreviewMesh(
                        attachOb,
                        vrmeshFilepath,
                        GeomMeshFile.anim_type,
                        GeomMeshFile.anim_offset,
                        GeomMeshFile.anim_speed,
                        context.scene.frame_current-1
                    )

        # Remove temp export file
        os.remove(vrsceneFilepath)

        if err:
            self.report({'ERROR'}, "Error generating VRayProxy! Check system console!")
            debug.PrintError(err)
            return {'CANCELLED'}

        self.report({'INFO'}, "Done creating proxy!")

        return {'FINISHED'}
    def execute(self, context):
        sce = context.scene

        # Use current active object UI for initial settings
        ob = bpy.context.object
        selection = bpy.context.selected_objects
        oneObject = len(selection)

        GeomMeshFile = ob.data.vray.GeomMeshFile

        # Create output path
        outputIsRelative = BlenderUtils.IsPathRelative(GeomMeshFile.dirpath)

        outputDirpath = BlenderUtils.GetFullFilepath(GeomMeshFile.dirpath)
        outputDirpath = PathUtils.CreateDirectory(outputDirpath)

        # Create tmp export file
        vrsceneFilepath = os.path.join(tempfile.gettempdir(), "vrmesh.vrscene")
        vrsceneFile = open(vrsceneFilepath, 'w')

        # Settings
        frames = None
        frameStart = 1
        frameStep = 1
        if GeomMeshFile.animation not in {'NONE'}:
            if GeomMeshFile.animation == 'MANUAL':
                frameStart = GeomMeshFile.frame_start
                frames = (frameStart, GeomMeshFile.frame_end, 1)
            else:
                frameStart = sce.frame_start
                frameStep = sce.frame_step
                frames = (sce.frame_start, sce.frame_end, sce.frame_step)

        applyTm = GeomMeshFile.apply_transforms
        useVelocity = GeomMeshFile.add_velocity

        # Export objects meshes and generate nodes name list
        obPluginNames = []
        o = VRayStream.VRaySimplePluginExporter(outputFile=vrsceneFile)

        exporter = _vray_for_blender.init(
            engine=0,
            context=bpy.context.as_pointer(),
            scene=sce.as_pointer(),
            data=bpy.data.as_pointer(),
            mainFile=o.output,
            objectFile=o.output,
            envFile=o.output,
            geometryFile=o.output,
            lightsFile=o.output,
            materialFile=o.output,
            textureFile=o.output,
            drSharePath="",
        )

        _vray_for_blender.initAnimation(True, frameStart, 1)

        _vray_for_blender.setFrame(frameStart)

        for ob in selection:
            if ob.type in BlenderUtils.NonGeometryTypes:
                continue
            nodeName = None
            if not frames:
                nodeName = ExportMeshSample(o, ob)
            else:
                sce = bpy.context.scene
                frame_current = sce.frame_current
                for f in range(frames[0], frames[1] + frames[2], frames[2]):
                    bpy.context.scene.frame_set(f)
                    _vray_for_blender.setFrame(f)
                    nodeName = ExportMeshSample(o, ob)
                    _vray_for_blender.clearCache()
                sce.frame_set(frame_current)
            obPluginNames.append([ob, nodeName])
        o.done()
        vrsceneFile.close()

        _vray_for_blender.clearFrames()
        _vray_for_blender.exit(exporter)

        # Launch the generator tool
        err = None
        for ob, nodeName in obPluginNames:
            vrmeshName = LibUtils.CleanString(ob.name)
            if oneObject and GeomMeshFile.filename:
                vrmeshName = GeomMeshFile.filename
            vrmeshName += ".vrmesh"
            vrmeshFilepath = os.path.join(outputDirpath, vrmeshName)

            err = LaunchPly2Vrmesh(vrsceneFilepath, vrmeshFilepath, nodeName,
                                   frames, applyTm, useVelocity)
            if err is not None:
                break

            if GeomMeshFile.proxy_attach_mode != 'NONE':
                attachOb = ob

                if GeomMeshFile.proxy_attach_mode == 'NEW':
                    newName = '%s@VRayProxy' % ob.name
                    newMesh = bpy.data.meshes.new(newName)
                    attachOb = bpy.data.objects.new(newName, newMesh)

                    context.scene.objects.link(attachOb)

                BlenderUtils.SelectObject(attachOb)

                if GeomMeshFile.proxy_attach_mode == 'NEW':
                    for slot in ob.material_slots:
                        if slot and slot.material:
                            attachOb.data.materials.append(slot.material)
                            attachOb.material_slots[-1].link = 'OBJECT'
                            attachOb.material_slots[
                                -1].material = slot.material

                if GeomMeshFile.apply_transforms:
                    bpy.ops.object.transform_apply(location=True,
                                                   rotation=True,
                                                   scale=True)
                else:
                    attachOb.matrix_world = ob.matrix_world

                CreateProxyNodetree(attachOb, vrmeshFilepath, outputIsRelative)

                if GeomMeshFile.proxy_attach_mode in {'NEW', 'REPLACE'}:
                    LoadProxyPreviewMesh(attachOb, vrmeshFilepath,
                                         GeomMeshFile.anim_type,
                                         GeomMeshFile.anim_offset,
                                         GeomMeshFile.anim_speed,
                                         context.scene.frame_current - 1)

        # Remove temp export file
        os.remove(vrsceneFilepath)

        if err:
            self.report({'ERROR'},
                        "Error generating VRayProxy! Check system console!")
            debug.PrintError(err)
            return {'CANCELLED'}

        self.report({'INFO'}, "Done creating proxy!")

        return {'FINISHED'}