Re: csv>python>blender

Posté par Cdric le 18/3/2021 11:15:03
j'y suis finalement parvenu
apparemment, le type de fichier devait Ítre "AVI_RAW"
ce qui donne :

import bpy
import csv
from math import pi #useful for text and camera rotation_euler
#create material
material_basic = bpy.data.materials.new(name= "Basic")
material_basic.use_nodes = True
principled_node = material_basic.node_tree.nodes.get('Principled BSDF')
principled_node.inputs[17].default_value = (1,1,1,1)


def event_text(event):
    bpy.ops.object.text_add()
    ob = bpy.context.object      
    curve = ob.data
    curve.body = "%s"%event
    bpy.context.active_object.location=(float(x),float(y),float(z))
    bpy.context.active_object.rotation_euler=(pi*90/180,0,0)
    bpy.context.active_object.data.materials.append(material_basic)
#define scene
scn = bpy.context.scene
# create the first camera
cam1 = bpy.data.cameras.new("Camera 1")
cam1.lens = 18
# create the first camera object
cam_obj1 = bpy.data.objects.new("Camera 1", cam1)
cam_obj1.rotation_euler = (pi*90/180, 0, 0)
scn.collection.objects.link(cam_obj1)
scn.camera = cam_obj1


#extract datas from csv file :
file = '\\Users\essai.csv'
#make the loop 
with open( file, 'r' ) as f:
    reader = csv.reader(f, delimiter=',')
    for row in reader:
        x, y, z, event = row[0], row[1], row[2], row[3]
        cam_obj1.location = (float(x),float(y)-3,float(z))
        cam_obj1.keyframe_insert(data_path=("location"), frame=((reader.line_num)-1)*120)
        cam_obj1.keyframe_insert(data_path=("location"), frame=((reader.line_num)-1)*120+120)
        print (reader.line_num)
        #creer les blocs textes 
        event_text(event)
        #render
bpy.context.scene.render.filepath = '\\Users\essai'
bpy.context.scene.render.image_settings.file_format = "AVI_RAW"
bpy.ops.render.render(animation = True)

Cette contribution était de : http://blenderclan.tuxfamily.org/html/newbb/viewtopic.php?forum=1&topic_id=50579&post_id=588297