1
$\begingroup$

I have some x3d files made by ParaView. I need to write a script to import these objects sequentially to Blender and make an animation. When each object is imported to 3D View Editor, a keyframe should be created. Then this object is deleted and the next object needs to be imported to make the next keyframe. After doing the same for all objects, the made animation will be played. There are some scripts to make jpeg files as each frame of animation and save it as mpeg or avi format. But,I need to export the above made animation as an Alembic file and import it to Unity. I would be grateful if anybody can help. Thank you so much.

$\endgroup$
2
  • $\begingroup$ Method suggested looks unsound. Please add more detail, eg are imported objects different or could they be considered shapekeys of each other. ... are you mixing keyframe with shapekey above? $\endgroup$
    – batFINGER
    Jul 17 '20 at 11:23
  • $\begingroup$ The imported objects are the time dependent CFD simulation results. They are velocity vectors at different time steps which have been post processed using ParaView and exported as x3d files to Blender. They are different and cannot be shapekeys of each other. $\endgroup$
    – Sima
    Jul 23 '20 at 3:48
0
$\begingroup$

I have the same problem. I somehow managed importing the .x3d files. However I couldn't animate it. Here is my detail information: I have 11 .x3d files representing a simulation at time of 0 second, 10 seconds up to 100 seconds. I want to set frame 0 to the file at 0 seconds, frame 1 for the file at 10 seconds and so on. I hope the importing scripts will help. My importing script is:

    import bpy
    import os
    import sys
    from mathutils import Vector

    importFolder = "./x3d" #the relative path of the folder containing the files
   # Fixed parameters
    geoName = "imported_geometry1"
    blenderVersion = bpy.app.version
    if blenderVersion[1] >= 79:
      x3dImportString = 'Shape_IndexedFaceSet'
   else:
       x3dImportString = 'ShapeIndexedFaceSet'
      #--------------------------------------------------------------------------#

      # Turn relative into absolute paths
      importFolder=os.path.join(os.getcwd(), importFolder)
       # Get a list of all files in this directory - these are going to be the files we 
       #import and visualize
      importFiles = os.listdir(importFolder)
      importFiles.sort()
      # Start the rendering loop over all import files
      for frame in range(len(importFiles)):
    importFile = os.path.join(importFolder,importFiles[frame])
    print("Processing frame ",frame+1," importing ",importFile)

    bpy.context.scene.frame_set(frame+1)

    # Import the current object, either supplied as a .ply or a .x3d file
    # The geometry will always be renamed so it can be easily used later on
    bpy.ops.import_scene.x3d(filepath=importFile, filter_glob="*.x3d;*.wrl", axis_forward='Y', axis_up='Z')
     # check for geometries / meshes, lamps and cameras
    imported_geo_exists = [item.name for item in bpy.data.objects if x3dImportString in item.name]
    nImportedGeo = len(imported_geo_exists)
    imported_lights_exists = [item.name for item in bpy.data.objects if ("TODO" in item.name or "DirectLight" in item.name)]
    imported_cameras_exists = [item.name for item in bpy.data.objects if "Viewpoint" in item.name]
    # rename geometry
    if imported_geo_exists:
        for i in range(0,nImportedGeo):
              bpy.data.objects[imported_geo_exists[i]].name=geoName+str(i)
        bpy.ops.object.select_all(action='DESELECT')
        # delete lights and cameras that blender creates after import
        if imported_lights_exists:
            #bpy.ops.object.mode_set(mode='OBJECT')
            bpy.ops.object.select_pattern(pattern="TODO*")
            bpy.ops.object.delete(use_global=False)
            bpy.ops.object.select_pattern(pattern="DirectLight*")
            bpy.ops.object.delete(use_global=False)
        if imported_cameras_exists:
            #bpy.ops.object.mode_set(mode='OBJECT')
            bpy.ops.object.select_pattern(pattern="Viewpoint*")
            bpy.ops.object.delete(use_global=False)

```
$\endgroup$
1
  • $\begingroup$ Thank you for the script, but I had imported the files but I still have the animation problem. $\endgroup$
    – Sima
    Nov 4 '20 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.