BlenderVR / source

Blender Virtual Reality Main Code
52 stars 21 forks source link

[NOT A BUG] Modal timing / watching inside Blender while running in VR #44

Open ptabriz opened 8 years ago

ptabriz commented 8 years ago

Hello all, I am very new to Github so and I am not sure if this is the right place to post a question. if this the case,please advise me where to post this,

I have written a script in blender using modal timer that constantly watches a folder to a import .ply and a Georaster as they get updated in GRASS GIS via Kinect. The code also watches for new GIS shapefiles that define a camera path or spot.

I am looking for a recommendations on how to use this blender file in BlenderVR. Can I load the blender file in VR and write the processor file as such that read and run the script inside the blender file ?

Below is part of the code inside blender.

pointPath= "C:/Users/ptabriz/Desktop/Blender_raster/Test_1/new.ply" scratchPointPath= "C:/Users/ptabriz/Desktop/Blender_raster/Test_1/scratch.ply"

class ModalTimerOperator(bpy.types.Operator): """Operator which runs its self from a timer""" bl_idname = "wm.modal_timer_operator" bl_label = "Modal Timer Operator"

_timer = 2

def modal(self, context, event):
    if event.type in {'RIGHTMOUSE', 'ESC'}:
        self.cancel(context)
        return {'CANCELLED'}

    if event.type == 'TIMER':
        if os.path.exists(pointPath):

            #bpy.context.selected_objects
            bpy.ops.import_mesh.ply(filepath=pointPath,directory="C:/Users/ptabriz/Desktop/Blender_raster/",filter_glob="1.ply")
            os.rename(pointPath,scratchPointPath)
            bpy.data.objects["new"].select = True
            bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')
            bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')   
    return {'PASS_THROUGH'}

def execute(self, context):
    wm = context.window_manager
    self._timer = wm.event_timer_add(0.1, context.window)
    wm.modal_handler_add(self)
    return {'RUNNING_MODAL'}

def cancel(self, context):
    wm = context.window_manager
    wm.event_timer_remove(self._timer)

def register(): bpy.utils.register_class(ModalTimerOperator)

def unregister(): bpy.utils.unregister_class(ModalTimerOperator)

if name == "main": register()

# test call
bpy.ops.wm.modal_timer_operator()

def unregister(): bpy.utils.unregister_class(ModalTimerOperator)

if name == "main": register()

# test call
bpy.ops.wm.modal_timer_operator()
PyrApple commented 8 years ago

Dear ptarbiz,

The issue section is usually reserved to issues / bugs noticed while using the code or potential side-devs that may interest the community and be integrated in the main code later.

For individual questions, please use the mailing list blendervr@limsi.fr.

Meanwhile, your code is bpy / addon oriented (blender animation, mesh edit, etc.) while BlenderVR is bge (blender game engine), hence it'll not run as is in BlenderVR. That being said, would you mind giving us some details about what you're trying to achieve, if somehow we may be of any help there?

ptabriz commented 8 years ago

Thank you very much for the instructions. I am trying to update a blender file using modal timer function. The blender file is constantly watching a particular folder for new pointcloud files to import . As soon the new shape is imported , the existing one gets deleted and all the objects would get aligned to the new geometry. In this way as soon as we manupulate any landscape's sand model (by hand ), the kinect collects the new info, and writes the .ply to the folder and blender updates the terrain info. Currently everything works perfectly when i submit run script button in blender. My ultimate goal is to project all these in DK2 thats why i am trying to find a way to translate this code for VR.

PyrApple commented 8 years ago

To project that in DK2, you'll have two solutions: 1) stick to your .ply write / blender-bpy-based framework and use Dalai's Virtual Reality Viewport implementation, or 2) send kinect data to Python for real-time mesh modification in the Blender Game Engine (I'm working on such thing, based on libfreenect2.

ptabriz commented 8 years ago

Thank you,

I have tried the first option but it did not work in Win 64 as indicated in their descriptions. The second is not an applicable one for us since the point files and rasters are generated by GRASS GIS. We need that connection because GRASS is in charge of all the geospatial analysis. Alternatively, Is it possible to :

1) Save the .blend file for each update and re-initiate the blender VR within blender game engine. 2) Or write the VR porcessor file as such that replaces the .blend file as soon as a change is observed (ex. modification time), then If the blender engine overwrite the .blend after each update , the VR reinitiate based on the new .blend.

Thank you,

On Sat, Feb 27, 2016 at 5:05 PM, David Poirier-Quinot < notifications@github.com> wrote:

To project that in DK2, you'll have two solutions: 1) stick to your .ply write / blender-bpy-based framework and use Dalai's https://github.com/dfelinto/virtual_reality_viewport http://Virtual%20Reality%20Viewport implementation 2) send kinect data to Python for real-time mesh modification in the Blender Game Engine (I'm working on such thing, based on https://github.com/OpenKinect/libfreenect2 http://libfreenect2.

— Reply to this email directly or view it on GitHub https://github.com/BlenderVR/source/issues/44#issuecomment-189737754.

Payam Tabrizian http://www4.ncsu.edu/~jwsmit12 PhD student, College of Design Research assistant, College of Natural Resources Center for Geo-spatial analytics North Carolina State University Campus Box 7701 50 Pullen Rd., Raleigh, NC 27696 Raleigh, NC 27695 US (919) 349 5701