()
| 107 | |
| 108 | |
| 109 | def main(): |
| 110 | print("main") |
| 111 | |
| 112 | parser = argparse.ArgumentParser() |
| 113 | parser.add_argument('--input_npz', required=True) #npz file to read and create a alembic from |
| 114 | parser.add_argument('--out_path', required=True) #output path for the blender file and the alembic |
| 115 | parser.add_argument('--export_alembic', action='store_true') #set it to true to also export an alembic file |
| 116 | parser.add_argument('-ss', '--strands_subsample', type=float, default=1.0) # perentage of strands we keep (1.0=keep all, 0.5=keep half, 0.25=keep quarter) |
| 117 | parser.add_argument('-vs', '--vertex_subsample', type=float, default=1.0) # perentage of vertices per strand to keep (1.0=keep all, 0.5=keep half, 0.25=keep quarter) |
| 118 | parser.add_argument('-ar', '--alembic_resolution', type=int, default=7) #the resolution of the alembic, higher number means more points per strand (default=7 which is probably 2^7=128 points per strands) |
| 119 | parser.add_argument('-sh', '--shrinkwrap', action='store_true') #set it to true to perform a shrinkwrap of the hair so that it avoids penetrating through the body |
| 120 | args = parser.parse_args(sys.argv[sys.argv.index("--") + 1:]) |
| 121 | print("strands_subsample", args.strands_subsample) |
| 122 | print("vertex_subsample", args.vertex_subsample) |
| 123 | print("alembic_resolution", args.alembic_resolution) |
| 124 | print("shrinkwrap", args.shrinkwrap) |
| 125 | |
| 126 | |
| 127 | #read npz |
| 128 | path_hair=args.input_npz |
| 129 | do_export_alembic=args.export_alembic |
| 130 | |
| 131 | |
| 132 | hair_geom=np.load(path_hair) |
| 133 | points=hair_geom["positions"] #nr_strands x nr_points_per_strand x 3 |
| 134 | |
| 135 | |
| 136 | subsample_nr_strands=False |
| 137 | #removes randomly x amount of strands or X nr of vertices |
| 138 | if args.strands_subsample!=1.0 or args.vertex_subsample!=1.0: |
| 139 | subsample_nr_strands=True |
| 140 | if subsample_nr_strands: |
| 141 | print("before ramoving random curves, points is ", points.shape) #nr_strands x nr_verts x3 |
| 142 | num_strands_to_keep = int(points.shape[0] * args.strands_subsample) |
| 143 | strands_to_keep = np.random.choice(points.shape[0], num_strands_to_keep, replace=False) |
| 144 | points = points[strands_to_keep, :, :].copy() |
| 145 | print("after removing random curves, points is ", points.shape) |
| 146 | |
| 147 | #removing verts now |
| 148 | nr_verts_to_skip=int(np.floor(1.0/args.vertex_subsample)) |
| 149 | print("nr_verts_to_skip",nr_verts_to_skip) |
| 150 | points = points[:, ::nr_verts_to_skip, :].copy() |
| 151 | print("after removing consecurive vertices, points is ", points.shape) |
| 152 | print("final points", points.shape) |
| 153 | |
| 154 | #open the blender file |
| 155 | # path_in_blend=os.path.join(path_cur_script,"./assets/blender_vis_base_v24.blend") |
| 156 | # path_in_blend=os.path.join(path_cur_script,"./assets/blender_vis_base_v25_with_shrinkwrap.blend") |
| 157 | # if args.shrinkwrap: |
| 158 | # path_in_blend=os.path.join(path_cur_script,"./assets/blender_vis_base_v26_with_shrinkwrap_full_base.blend") |
| 159 | # else: |
| 160 | # path_in_blend=os.path.join(path_cur_script,"./assets/blender_vis_base_v24.blend") |
| 161 | # path_in_blend=os.path.join(path_cur_script,"./assets/blender_vis_base_v27_blender36.blend") |
| 162 | path_in_blend=os.path.join(path_cur_script,"./assets/blender_vis_base_v26_with_shrinkwrap_full_base.blend") |
| 163 | bpy.ops.wm.open_mainfile(filepath=path_in_blend) |
| 164 | |
| 165 | |
| 166 | #write new geometry |
no test coverage detected