Пример #1
0
def ExportFullRange(bus):
    scene = bus['scene']
    o = bus['output']

    err = None

    # Init exporter
    exp_init.InitAnimation(bus, isAnimation=True)

    # Store current frame
    selected_frame = scene.frame_current

    f = o.frameStart
    while (f <= o.frameEnd):
        scene.frame_set(f)
        o.setFrame(f)
        _vray_for_blender.setFrame(f)

        err = exp_scene.ExportScene(bus)
        if err is not None:
            break

        f += o.frameStep

    # Restore selected frame
    scene.frame_set(selected_frame)

    return err
Пример #2
0
def ExportFullRange(bus):
    scene = bus['scene']
    o     = bus['output']

    err = None

    # Init exporter
    exp_init.InitAnimation(bus, isAnimation=True)

    # Store current frame
    selected_frame = scene.frame_current

    f = o.frameStart
    while(f <= o.frameEnd):
        scene.frame_set(f)
        o.setFrame(f)
        _vray_for_blender.setFrame(f)

        err = exp_scene.ExportScene(bus)
        if err is not None:
            break

        f += o.frameStep

    # Restore selected frame
    scene.frame_set(selected_frame)

    return err
Пример #3
0
def ExportSingleFrame(bus):
    o      = bus['output']
    scene  = bus['scene']

    err = None

    VRayScene    = scene.vray
    VRayExporter = VRayScene.Exporter

    if VRayExporter.frames_to_export > 1:
        frameStart = scene.frame_current
        frameEnd   = frameStart + VRayExporter.frames_to_export - 1
        frameStep  = scene.frame_step

        o.setAnimation(True)
        o.setFrameStart(frameStart)
        o.setFrameEnd(frameEnd)
        o.setFrameStep(frameStep)

        err = exp_anim_full.ExportFullRange(bus)

    else:
        _vray_for_blender.setFrame(scene.frame_current)
        err = exp_scene.ExportScene(bus)

    return err
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)
Пример #5
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)
Пример #6
0
def ExportCameraLoop(bus):
    scene  = bus['scene']
    engine = bus['engine']
    camera = bus['camera']
    o      = bus['output']

    VRayScene    = scene.vray
    VRayExporter = VRayScene.Exporter

    cameras = GetLoopCameras(scene)
    if not len(cameras):
        return 'No cameras are selected for "Camera Loop"!'

    cameras = sorted(cameras, key=lambda c: c.name)

    # We will create animated camera from 'cameras'
    o.setAnimation(True)
    o.setFrameStart(1)
    o.setFrameEnd(len(cameras))
    o.setFrameStep(1)

    if IsHideFromViewUsed(cameras):
        debug.Debug('Using "Hide From View"...')

        # Since hide from view affect object properties we have to export in
        # animation mode 
        exp_init.InitAnimation(bus, isAnimation=True)

        for i, camera in enumerate(cameras):
            # Setup camera
            bus['camera'] = camera

            # Setup fake frame
            frame = i+1
            o.setFrame(frame)
            _vray_for_blender.setFrame(frame)

            # Since we are using 'Hide From View' we have to update
            # object's visibilities.
            # Export meshes only for the first frame since
            # 'Hide From View' affects only object level.
            #
            exp_scene.ExportScene(bus, exportNodes=True, exportMeshes=(frame==1))

    else:
        # Export objects as usual
        exp_scene.ExportScene(bus)

        # Export animated camera from 'Camera Loop' cameras
        for i, camera in enumerate(cameras):
            # Setup camera
            bus['camera'] = camera

            # Setup fake frame
            frame = i+1
            o.setFrame(frame)

            exp_camera.ExportCamera(bus)
Пример #7
0
def ExportFullNotMeshes(bus):
    scene = bus['scene']
    o = bus['output']

    exp_init.InitAnimation(bus, isAnimation=True)

    # Store current frame
    selected_frame = scene.frame_current

    # Set frame
    f = o.frameStart

    scene.frame_set(f)
    o.setFrame(f)
    _vray_for_blender.setFrame(f)

    # 1. Export full first frame
    err = exp_scene.ExportScene(bus)
    if err is not None:
        return err

    # 2. Export nodes for rest frames
    f += o.frameStep
    while (f <= o.frameEnd):
        scene.frame_set(f)
        o.setFrame(f)
        _vray_for_blender.setFrame(f)

        err = exp_scene.ExportScene(bus, exportMeshes=False)
        if err is not None:
            break

        f += o.frameStep

    # Restore selected frame
    scene.frame_set(selected_frame)

    return None
Пример #8
0
def ExportFullNotMeshes(bus):
    scene = bus['scene']
    o     = bus['output']

    exp_init.InitAnimation(bus, isAnimation=True)

    # Store current frame
    selected_frame = scene.frame_current

    # Set frame
    f = o.frameStart

    scene.frame_set(f)
    o.setFrame(f)
    _vray_for_blender.setFrame(f)

    # 1. Export full first frame
    err = exp_scene.ExportScene(bus)
    if err is not None:
        return err

    # 2. Export nodes for rest frames
    f += o.frameStep
    while(f <= o.frameEnd):
        scene.frame_set(f)
        o.setFrame(f)
        _vray_for_blender.setFrame(f)

        err = exp_scene.ExportScene(bus, exportMeshes=False)
        if err is not None:
            break

        f += o.frameStep

    # Restore selected frame
    scene.frame_set(selected_frame)

    return None
def ExportSingleFrame(bus):
    o = bus['output']
    scene = bus['scene']

    err = None

    VRayScene = scene.vray
    VRayExporter = VRayScene.Exporter

    mb_duration, mb_interval_center = GetMotionBlurFrames(bus)

    if mb_duration:
        debug.Debug("MB Duration: %.3f sec" % mb_duration)
        debug.Debug("MB Interval Center: %.3f sec" % mb_interval_center)

        if mb_duration < 1.0:
            mb_duration = 1.0

        # We need to export +1 frames data
        mb_duration += 1

        frameStart = scene.frame_current
        frameEnd = frameStart + mb_duration - 1
        frameStep = scene.frame_step

        o.setAnimation(True)
        o.setFrameStart(frameStart)
        o.setFrameEnd(frameEnd)
        o.setFrameStep(frameStep)

        err = exp_anim_full.ExportFullRange(bus)

    else:
        _vray_for_blender.setFrame(scene.frame_current)
        err = exp_scene.ExportScene(bus)

    return err
Пример #10
0
def ExportSingleFrame(bus):
    o      = bus['output']
    scene  = bus['scene']

    err = None

    VRayScene    = scene.vray
    VRayExporter = VRayScene.Exporter

    mb_duration, mb_interval_center = GetMotionBlurFrames(bus)

    if mb_duration:
        debug.Debug("MB Duration: %.3f sec" % mb_duration)
        debug.Debug("MB Interval Center: %.3f sec" % mb_interval_center)

        if mb_duration < 1.0:
            mb_duration = 1.0

        # We need to export +1 frames data
        mb_duration += 1

        frameStart = scene.frame_current
        frameEnd   = frameStart + mb_duration - 1
        frameStep  = scene.frame_step

        o.setAnimation(True)
        o.setFrameStart(frameStart)
        o.setFrameEnd(frameEnd)
        o.setFrameStep(frameStep)

        err = exp_anim_full.ExportFullRange(bus)

    else:
        _vray_for_blender.setFrame(scene.frame_current)
        err = exp_scene.ExportScene(bus)

    return err
Пример #11
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'}
Пример #12
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
        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'}