[node] Adding working background and several other feat.

Almost complete version of the node, I added a background that can render with eevee and changed the cubes used as particles by a plane that always follows the camera. The one of the only thing left is the option to change the color of the particle (among other things).
This commit is contained in:
Solal Depardieu 2021-05-17 20:45:23 +02:00 committed by Fabien Castan
parent 5bb026afec
commit 5701f8f578
2 changed files with 65 additions and 14 deletions

View file

@ -47,6 +47,24 @@ class RenderAnimatedCamera(desc.CommandLineNode):
range=(0.01, 0.5, 0.01), range=(0.01, 0.5, 0.01),
uid=[0], uid=[0],
), ),
desc.FloatParam(
name='particleSize',
label='Particle Size',
description='''Scale of every particle used to show the cloud of point''',
value=0.25,
range=(0.01, 1, 0.01),
uid=[0],
),
desc.ChoiceParam(
name='particleColor',
label='Particle Color',
description='''Color of every particle used to show the cloud of point''',
value=['Grey'],
values=['Grey', 'White', 'Red', 'Green', 'Magenta'],
exclusive=True,
uid=[0],
joinChar=',',
),
desc.File( desc.File(
name='undistortedImages', name='undistortedImages',
label='Images Folder', label='Images Folder',

View file

@ -39,6 +39,11 @@ def main():
help="Number of point from the cloud rendered", help="Number of point from the cloud rendered",
) )
parser.add_argument(
"--particleSize", dest="Particle_Size", type=float, required=True,
help="Scale of every particle used to show the cloud of point",
)
parser.add_argument( parser.add_argument(
"--undistortedImages", dest="undisto_images", metavar='FILE', required=True, "--undistortedImages", dest="undisto_images", metavar='FILE', required=True,
help="Save the generated file to the specified path", help="Save the generated file to the specified path",
@ -49,6 +54,11 @@ def main():
help="Render an image to the specified path", help="Render an image to the specified path",
) )
parser.add_argument(
"--particleColor", dest="Particle_Color", metavar=str, required=True,
help="Color of every particle used to show the cloud of point",
)
args = parser.parse_args(argv) args = parser.parse_args(argv)
if not argv: if not argv:
@ -70,11 +80,21 @@ def main():
parser.print_help() parser.print_help()
return return
if not args.Particle_Size:
print("Error: --Particle_Size argument not given, aborting.")
parser.print_help()
return
if not args.output_path: if not args.output_path:
print("Error: --output_path argument not given, aborting.") print("Error: --output_path argument not given, aborting.")
parser.print_help() parser.print_help()
return return
if not args.Particle_Color:
print("Error: --Particle_Color argument not given, aborting.")
parser.print_help()
return
print(args.SFM_cam_path) print(args.SFM_cam_path)
@ -85,17 +105,6 @@ def main():
except: except:
print("Error: While clearing current scene") print("Error: While clearing current scene")
#Place the particle cube
cube = bpy.data.meshes['Cube']
objectsCube = bpy.data.objects.new(name="Cube", object_data=cube)
objectsCube.scale = mathutils.Vector((0.3, 0.3, 0.3))
objectsCube.location = mathutils.Vector((0, -2.0, -1000))
bpy.context.scene.collection.objects.link(objectsCube)
bpy.data.objects['Cube'].hide_set(True)
# import Undistorted Images # import Undistorted Images
undis_imgs = [] undis_imgs = []
@ -116,14 +125,21 @@ def main():
print("Error: while importing the undistorted images.") print("Error: while importing the undistorted images.")
#import abc (Animated Camera) #import abc (Animated Camera)
try: try:
bpy.ops.wm.alembic_import(filepath=args.SFM_cam_path) bpy.ops.wm.alembic_import(filepath=args.SFM_cam_path)
animated_cams = bpy.context.selected_editable_objects[:] animated_cams = bpy.context.selected_editable_objects[:]
cam_scale = mathutils.Vector((0, 0, 0))
cam_location = mathutils.Vector((0, 0, 0))
cam_obj = None
for obj in animated_cams: for obj in animated_cams:
if obj.data and obj.data.type == 'PERSP' and "anim" in obj.data.name: if obj.data and obj.data.type == 'PERSP' and "anim" in obj.data.name:
bpy.context.scene.collection.objects.link(obj) bpy.context.scene.collection.objects.link(obj)
bpy.context.view_layer.objects.active = obj bpy.context.view_layer.objects.active = obj
bpy.context.scene.camera = obj bpy.context.scene.camera = obj
cam_scale = obj.scale
cam_location = obj.location
cam_obj = obj
bpy.ops.image.open(filepath=args.undisto_images + "/" + image_name, directory=args.undisto_images, files=undis_imgs, relative_path=True, show_multiview=False) bpy.ops.image.open(filepath=args.undisto_images + "/" + image_name, directory=args.undisto_images, files=undis_imgs, relative_path=True, show_multiview=False)
bpy.data.cameras[obj.data.name].background_images.new() bpy.data.cameras[obj.data.name].background_images.new()
bpy.data.cameras[obj.data.name].show_background_images = True bpy.data.cameras[obj.data.name].show_background_images = True
@ -136,7 +152,21 @@ def main():
except: except:
print("Error: while importing the alembic file (Animated Camera).") print("Error: while importing the alembic file (Animated Camera).")
#Place the particle plane
try:
plane = bpy.data.meshes.new('Plane')
objectsPlane = bpy.data.objects.new(name="Plane", object_data=plane)
bm = bmesh.new()
bmesh.ops.create_grid(bm, x_segments = 1, y_segments = 1, size = 1.0)
bm.to_mesh(plane)
bm.free()
objectsPlane.scale = mathutils.Vector((args.Particle_Size, args.Particle_Size, args.Particle_Size))
cam_location.y += -2.0
objectsPlane.location = cam_location
bpy.context.scene.collection.objects.link(objectsPlane)
bpy.data.objects['Plane'].parent = cam_obj
except:
print("Error: while setting up the particle model.")
#import abc (Cloud Point) #import abc (Cloud Point)
@ -151,7 +181,7 @@ def main():
particle_system = bpy.data.particles["ParticleSystem"] particle_system = bpy.data.particles["ParticleSystem"]
particle_system.render_type = 'OBJECT' particle_system.render_type = 'OBJECT'
particle_system.instance_object = bpy.data.objects["Cube"] particle_system.instance_object = bpy.data.objects["Plane"]
particle_system.emit_from = 'VERT' particle_system.emit_from = 'VERT'
particle_system.count = int(args.Cloud_Point_Density * len(obj.data.vertices.values())) particle_system.count = int(args.Cloud_Point_Density * len(obj.data.vertices.values()))
@ -159,12 +189,15 @@ def main():
particle_system.use_emit_random = False particle_system.use_emit_random = False
particle_system.particle_size = 0.02 particle_system.particle_size = 0.02
particle_system.physics_type = 'NO' particle_system.physics_type = 'NO'
particle_system.use_rotations = True
particle_system.use_rotation_instance = True
particle_system.rotation_mode = 'GLOB_X'
except: except:
print("Error: while importing the alembic file (Cloud Point).") print("Error: while importing the alembic file (Cloud Point).")
#WE HAVE TO USE THE GRAPH TO MAKE THE BACKGROUND IMAGE VISIBLE (For some reason) All explained in https://www.youtube.com/watch?v=3PoEVlObMv0 #WE HAVE TO USE THE GRAPH TO MAKE THE BACKGROUND IMAGE VISIBLE
try: try:
bpy.context.scene.use_nodes = True bpy.context.scene.use_nodes = True