Import x3d files automatic

Hi

I got some(500) x3d-files exported form Paraview and I want to import them with blender in order to animate and render them. Every file represents a single timestep, so it should be added to its own frame. The import of single files workes fine, but I have no idea how I can loop the importskript. I used the forums search but all I found, was that I have to use python for this issue and I never found a usefull howto.
Thanks for your help.
harwen

This is possible! It would be VERY helpful if the .x3d were named something useful like file001.x3d, file002.x3d, file003.x3d and so on. A script could be written to import the script that loads .x3d files and then every time you change the frame it will load up the appropriate .x3d file. This is HIGHLY inefficient but it would be the easiest way. The other option would be to load up all the files at once and then make only the one needed for that frame unhidden. This wouldn’t be too hard either. Depending on the number of frames and the size of the object you are wanting to import, one of these ways will be better suited than the other. So a few questions…

  1. How many frames are you looking at using? About 500 you said
  2. Is each object big? (ie memory) cuz there might be 500 of them stored in memory
  3. Once you import them, are you immediately going to render and be done? or are you going to be doing alot of work after you import them before rendering?

Thanks

Thank you for your quick response.
@1 Usually I got 500-1000 files as results.
@2 It depends, if I use paraview export the size is about 400-500kb. If I use my own writer I got files at a size of 50-100kb.
@3 I want to do some postproduction stuff like adding materials, but structure of the imported files should not be changed.

I would prefer an easy solution. Like your first suggestion. Actually I am new to python. But should this look like this example?


for i in range(5): 
   file = open("filename00"+i) 
   //start importer
   //insert grid                             
   file.close()
//change frame

For this I got some questions:

  1. how can I access the python script for the importer?
  2. How can I change the frame?
    I tried to find some answers in the API Documentation. But I wasn’t that helpful to me.

Thanks

Well, the good thing you can do with blender is have it run a script every time the frame is changed. So when you change the frame in blender, ie playing animation, or arrow keys. You could run a script like this…


import Blender
import import_web3d

#delete old mesh from last frame

frame = Blender.Get("curframe")

obj = import_web3d.load_web3d("file" + str(frame) + ".x3d")

#setmaterial on obj, not for sure how right now
obj.setMaterial(mat)

# change location or whatever is needed


As you can see i imported the script that handles the x3d files. And using this script, the script would not need to change the frame.

Is there any way you could zip up all the files, or several of them and send them to me( Filehosting, email…) so i could test some stuff out?

Thank you for you quick help. I can set up a small test case, zip the files and sent them to you via Email.
Of course I got an other question about your skript.

Where do i have to put the x3d files in order to import them. Realiv to the blend-file?
You save the imported object in obj. What will happen if there are two oder more objects in the x3d file?

Sorry, i had a very busy weekend. To answer your questions, i don’t know. I would have to do some testing to find out. You can email the zip of the files to dail8859 at yahoo dot com. I’ll see what i can figure out with them.

So finally I found the time to do some documentation. I rode a small script for looping the import of x3d files. It works like this:

  • In the Main Scene first you do the setup (Camera position etc.).
  • After that you have to set up the script parameters (filenames, materials, resize).
  • Then execute the script.

The script copies the Main Scene to the Render Scene and imports in there the time step of the 3xd file, renders and deletes it.

It is a quite simple script and it works only with one object for each x3d file, Blender 2.48a.


import Blender 
import bpy
import import_web3d
from Blender import Types, Object, Mesh, Camera, Lamp, Scene, Window, Material, NMesh
from Blender.Scene import Render

#http://www.futura-designs.de/

print '+++start import+++'
print"   __       "
print"    _) _|   "
print")( __)(_|  "
                       
#Parameter
frameS = 45  #Startframe
frameE = 46     #Endframe
name = "step_" #Filename
input ="C:/Users/"
output ="C:/render/"

for frame in range(frameS,frameE):
    #NEW Scene
    scn=Scene.GetCurrent()
    scn2=scn.copy(2)
    scn2.setName('renderScene')
    scn2.makeCurrent()
    
    #Import
    frame_n = frame*100
    tmp=input+name+str(frame_n)+".x3d"
    print tmp
    import_web3d.load_web3d(tmp) 
    
    
    #Editing add parameters
    water = bpy.data.materials['blue']
    
    for me in bpy.data.meshes:
        me.materials = [water]
    for me in bpy.data.objects:
        me.setSize(0.2,2,0.2)
    
    #Rendering
    scn2=Scene.GetCurrent()
    context = scn2.getRenderingContext()
    context.renderPath = output
    context.getRenderPath()
    context.render()
    context.saveRenderedImage(name+str(frame_n), 0)
    #Render.CloseRenderWindow()
    Window.RedrawAll() 
    scn=Scene.Get('Scene')
    scn.makeCurrent()
    Scene.Unlink(scn2)
    
print '+++end import+++'