Paraview -> Blender python pipeline

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Reynolds
Posts: 19
Joined: Tue Mar 27, 2012 7:54 pm

Postby Reynolds » Thu May 31, 2012 1:05 pm

gl1w07 wrote:Hi Reynolds,

Many thanks for posting the code.
That's very generous of you.

G




No problem, I'm just trying to give back to the community. blender is such a great tool, so I really like to contribute a tiny bit.

I'm currently working on having multiple cameras in the scene, so I can shoot from different directions / angles in one run.

In addition, I'd really like to rewrite the script for cycles, but can't seem to find a good reference / starting point to do it.

So if there's anybody out there who would want to clean up my code, add functionality or take a look at the cycles portation, please feel free to do so, but please post back and share!

Thanks and all the best
Reynolds

Klaus@RZG
Posts: 4
Joined: Thu May 10, 2012 4:28 pm

Postby Klaus@RZG » Thu May 31, 2012 4:51 pm

Hi Reynolds,

thanks much for posting your code!
Nice turbulence in your movie :)

Best regards,
Klaus

Reynolds
Posts: 19
Joined: Tue Mar 27, 2012 7:54 pm

Postby Reynolds » Thu May 31, 2012 5:32 pm

Klaus@RZG wrote:Hi Reynolds,

thanks much for posting your code!
Nice turbulence in your movie :)

Best regards,
Klaus


Thanks a lot Klaus, the resolution is still way to low to fully resolve the turbulence, but its a start. Hopefully I'll get a fully resolved version with some nice blender shaders and fancy lighting soon :)

Reynolds
Posts: 19
Joined: Tue Mar 27, 2012 7:54 pm

Postby Reynolds » Thu May 31, 2012 5:33 pm

Reynolds wrote:
Klaus@RZG wrote:Hi Reynolds,

thanks much for posting your code!
Nice turbulence in your movie :)

Best regards,
Klaus


Thanks a lot Klaus, the resolution is still way to low to fully resolve the turbulence, but its a start. Hopefully I'll get a fully resolved version with some nice blender shaders and fancy lighting soon :)


BTW: does the G stand for Garching?

Klaus@RZG
Posts: 4
Joined: Thu May 10, 2012 4:28 pm

Postby Klaus@RZG » Thu May 31, 2012 5:44 pm

Reynolds wrote:BTW: does the G stand for Garching?


Yep. Are we neighbours?

Reynolds
Posts: 19
Joined: Tue Mar 27, 2012 7:54 pm

Postby Reynolds » Thu May 31, 2012 5:49 pm

Klaus@RZG wrote:
Reynolds wrote:BTW: does the G stand for Garching?


Yep. Are we neighbours?


Well, on a european scale certainly. Just up the A8 for about 200km, then Ausfahrt Uni Stuttgart ;)

Viele Grüße!

Reynolds
Posts: 19
Joined: Tue Mar 27, 2012 7:54 pm

Postby Reynolds » Sat Aug 04, 2012 7:40 pm

Has anybody ever added to my work? Done anything useful with it?

SH_P
Posts: 4
Joined: Mon Aug 27, 2012 11:26 pm

Postby SH_P » Mon Sep 03, 2012 10:02 pm

Reynolds wrote:Has anybody ever added to my work? Done anything useful with it?

I've just made your code a little cleaner. Now I am trying to set a multi-camera. Do you have any idea how to use cycle? It seems that the "Vertex color paint" option is only available in Blender engine. I think we should find a way to copy the texture in Blender mode and use it in a material in cycle mode.

Code: Select all

import bpy
#---------------------------------Definitions---------------------------------------#
path_tox3d='C:/Users/*****/Desktop/Test_blend/'
path_toimage='C:/Users/*****/Desktop/Test_blend/'
filename_ofx3d='file_'
filename_ofimage='newimage_'
startframe_ofx3d=0
endframe_ofx3d=5
#-----------------------------------------------------------------------------------#

bpy.ops.object.add()
bpy.data.objects['Empty'].select=True
bpy.data.objects['Empty'].name="Aux_Empty"
bpy.context.active_object.location =(0.0, 0.0, 0.0)
bpy.data.objects['Aux_Empty'].select=False
 

for currentframe in range(startframe_ofx3d,(endframe_ofx3d+1)):   
    bpy.context.scene.frame_set(currentframe)
    bpy.data.objects['Aux_Empty'].select=True
    bpy.context.scene.objects.active = bpy.data.objects['Aux_Empty']
    obj = bpy.context.object
    obj.location[2] = 0.0
    obj.keyframe_insert(data_path='location')
    bpy.data.objects['Aux_Empty'].select=False
    #---------------------------Import the x3d file--------------------------------#
    bpy.ops.import_scene.x3d(filepath=path_tox3d+filename_ofx3d+str(currentframe)+'.x3d', filter_glob="*.x3d;*.wrl", axis_forward='Z', axis_up='Y')
    #-------------------------------------------------------------------------------#
   
    #------------rename the geometry to "imported geometry"----------------#
    #--Change the "ShapeIndexedFaceSet.002" according to your geometry--#
    bpy.data.objects['ShapeIndexedFaceSet.002'].name="imported_geometry"
    bpy.data.objects['imported_geometry'].select=True
    bpy.context.scene.objects.active = bpy.data.objects['imported_geometry']
    bpy.context.active_object.material_slots[0].material.use_vertex_color_paint=True
    bpy.data.objects['imported_geometry'].select=False
   
    #Delete all of the imported objects except for the"imported_geometry"----#
    bpy.ops.object.delete()

   #-----------------------Set the rendering options-----------------------------#
    bpy.data.scenes['Scene'].render.resolution_percentage=100

    bpy.ops.render.render(write_still=True)

    bpy.data.images['Render Result'].file_format='PNG'
    bpy.data.images['Render Result'].save_render(filepath=path_toimage+filename_ofimage+str(currentframe)+'.png')
    bpy.data.objects['imported_geometry'].select=True
    bpy.ops.object.delete()
   #--------------------------------End of the loop------------------------------#
bpy.data.objects['Aux_Empty'].select=True
bpy.ops.object.delete()

SH_P
Posts: 4
Joined: Mon Aug 27, 2012 11:26 pm

Postby SH_P » Sun Sep 09, 2012 2:45 pm

Finally found a way to use Cycle engine :wink:

The easy way:
1. Create a material in your scene while Cycle is selected as the render engine
2. Add an 'Attribute' node to color of Diffuse BSDF as shown in the picture.
Image

Change the name to Col or whatever appears in 'Vertex Color' under Object data.
Image

3. Add the following command in your code to change the material for all of the objects with vertex color to the newly created material:

Code: Select all

bpy.context.active_base.object.active_material= bpy.data.materials['Cycle_Mat']


Now your objects are rendered based on their color map that were exported with.

Complete way!
If you want to have more control over changing materials and manipulating nodes the following code fits you! It does what explained above but in python :

Code: Select all

bpy.context.active_object.material_slots['Mat_name'].material.node_tree.nodes.new('ATTRIBUTE')

Att = bpy.context.active_object.material_slots['Mat_name'].material.node_tree.nodes['Attribute']
Diff = bpy.context.active_object.material_slots['Mat_name'].material.node_tree.nodes['Diffuse BSDF']

bpy.data.objects['Obj_name'].material_slots['Mat_name'].material.node_tree.nodes['Attribute'].attribute_name='Col'
bpy.context.active_object.material_slots['Mat_name'].material.node_tree.links.new(Att.outputs[0],Diff.inputs[0])


Enjoy the full power of Blender for post-processing !! :)

werty_TSS
Posts: 4
Joined: Thu Dec 20, 2012 7:45 am
Location: Austin, TX

Postby werty_TSS » Thu Dec 20, 2012 8:00 am

Hi guys,
I encounter pretty much the same situation described here. I've a time varying file in paraview that i would put into Blender to work on the rendering. So I export the different x3d files, I do my stuff as explained here.

Though, I was wondering: is there a way to interpolate between each time steps in Blender in order to get something smoother ? I don't really want to write something myself which is gonna create temp files with the interpolated values, it's gonna be extremely time consuming as I work with meshes with several million nodes...

So simple question: can Blender do that? if yes, how?

SH_P
Posts: 4
Joined: Mon Aug 27, 2012 11:26 pm

Postby SH_P » Thu Dec 20, 2012 9:59 am

werty_TSS wrote:Hi guys,
I encounter pretty much the same situation described here. I've a time varying file in paraview that i would put into Blender to work on the rendering. So I export the different x3d files, I do my stuff as explained here.

Though, I was wondering: is there a way to interpolate between each time steps in Blender in order to get something smoother ? I don't really want to write something myself which is gonna create temp files with the interpolated values, it's gonna be extremely time consuming as I work with meshes with several million nodes...

So simple question: can Blender do that? if yes, how?


Well, Let's say you have your CFD results in Paraview and you import them into Blender. Now are you expecting Blender to interpolate you CFD data?!! I don't think it would be possible. Try increasing your time steps when obtaining results in your solver and your results should be smoother (Very obvious of course! :D)

werty_TSS
Posts: 4
Joined: Thu Dec 20, 2012 7:45 am
Location: Austin, TX

Postby werty_TSS » Thu Dec 20, 2012 10:04 am

SH_P wrote:Well, Let's say you have your CFD results in Paraview and you import them into Blender. Now are you expecting Blender to interpolate you CFD data?!! I don't think it would be possible. Try increasing your time steps when obtaining results in your solver and your results should be smoother (Very obvious of course! :D)


Yes, well that's what I'm trying to avoid.. I export x3d files from paraview, they just give RGB values to each nodes of my mesh. So I hoped Blender could interpolate between those RGB values for the different time steps, which is different than changing the timestep in my numerical scheme when I solve the equations at the beginning.

SH_P
Posts: 4
Joined: Mon Aug 27, 2012 11:26 pm

Postby SH_P » Thu Dec 20, 2012 10:12 am

So your geometry is the same in every time-steps. You should alter the code in a way to change the color map instead of changing the whole geometry. This way you may be able to find a function with the out put of RGB values at each node in your geometry. If there exists such a function, it would be straightforward to interpolate the values.
Look under the material and texture section of Python guide to see if there is function suitable for you...

Lindstroem
Posts: 1
Joined: Fri Jul 12, 2013 6:33 pm

generating the set of x3d-files

Postby Lindstroem » Fri Jul 12, 2013 6:37 pm

Hi!

It has been a while since the last post, but anyhow, I'd like to pose my question here. How did you generate the set of x3d-files in paraview? Certainly not manually for each timestep.. And how did you generate the set of camera viewpoints? Actually I would only need one camera viewpoint, that would be enough..

Thanks for any hints in advance!

Lindstroem


Return to “Python”

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests