diff options
author | meta-androcto <meta.androcto1@gmail.com> | 2019-07-03 12:28:22 +0300 |
---|---|---|
committer | meta-androcto <meta.androcto1@gmail.com> | 2019-07-03 12:28:22 +0300 |
commit | 2b144940181b60c8a08b91646e167064f286a2ef (patch) | |
tree | 9b44478d3eea0af439c210588ba444f9cb13570b /mesh_tissue/colors_groups_exchanger.py | |
parent | 582119a574effd14e09b76491bb018526757d994 (diff) |
mesh_tissue: fix errors, remove read me, clean up: T63477
Diffstat (limited to 'mesh_tissue/colors_groups_exchanger.py')
-rw-r--r-- | mesh_tissue/colors_groups_exchanger.py | 93 |
1 files changed, 36 insertions, 57 deletions
diff --git a/mesh_tissue/colors_groups_exchanger.py b/mesh_tissue/colors_groups_exchanger.py index 0da15e85..00fd3649 100644 --- a/mesh_tissue/colors_groups_exchanger.py +++ b/mesh_tissue/colors_groups_exchanger.py @@ -35,7 +35,7 @@ import bpy, bmesh import numpy as np -import math, timeit +import math, timeit, time from math import *#pi, sin from statistics import mean, stdev from mathutils import Vector @@ -61,19 +61,6 @@ from bpy.props import ( from .utils import * -bl_info = { - "name": "Colors/Groups Exchanger", - "author": "Alessandro Zomparelli (Co-de-iT)", - "version": (0, 3), - "blender": (2, 7, 9), - "location": "", - "description": ("Convert vertex colors channels to vertex groups and vertex" - " groups to colors"), - "warning": "", - "wiki_url": "", - "tracker_url": "", - "category": "Mesh"} - def reaction_diffusion_add_handler(self, context): # remove existing handlers old_handlers = [] @@ -91,7 +78,8 @@ class formula_prop(PropertyGroup): int_var : IntVectorProperty(name="", description="", default=(0, 0, 0, 0, 0), size=5) class reaction_diffusion_prop(PropertyGroup): - run : BoolProperty(default=False, update = reaction_diffusion_add_handler) + run : BoolProperty(default=False, update = reaction_diffusion_add_handler, + description='Compute a new iteration on frame changes. Currently is not working during Render Animation') time_steps : bpy.props.IntProperty( name="Steps", default=10, min=0, soft_max=50, @@ -333,8 +321,6 @@ class weight_formula(bpy.types.Operator): self.report({'ERROR'}, weight) return {'CANCELLED'} - #print("time: " + str(timeit.default_timer() - start_time)) - #start_time = timeit.default_timer() weight = nan_to_num(weight) if type(weight) == int or type(weight) == float: @@ -413,7 +399,6 @@ class _weight_laplacian(bpy.types.Operator): group_id = ob.vertex_groups.active_index input_group = ob.vertex_groups[group_id].name - print(input_group) group_name = "Laplacian" ob.vertex_groups.new(name=group_name) @@ -432,8 +417,6 @@ class _weight_laplacian(bpy.types.Operator): n_verts = len(bm.verts) lap = [0]*n_verts - #print(len(lap)) - #print(len(weight)) for e in bm.edges: if self.mode == 'LENGTH': length = e.calc_length() @@ -596,8 +579,6 @@ class weight_laplacian(bpy.types.Operator): lap_a = zeros((n_verts))#[0]*n_verts lap_b = zeros((n_verts))#[0]*n_verts - #print(len(lap)) - #print(len(weight)) for e in bm.edges: id0 = e.verts[0].index id1 = e.verts[1].index @@ -660,6 +641,7 @@ class reaction_diffusion(bpy.types.Operator): def execute(self, context): #bpy.app.handlers.frame_change_post.remove(reaction_diffusion_def) reaction_diffusion_add_handler(self, context) + set_animatable_fix_handler(self, context) try: ob = context.object except: self.report({'ERROR'}, "Please select an Object") @@ -696,8 +678,6 @@ class reaction_diffusion(bpy.types.Operator): lap_a = zeros((n_verts))#[0]*n_verts lap_b = zeros((n_verts))#[0]*n_verts - #print(len(lap)) - #print(len(weight)) for e in bm.edges: id0 = e.verts[0].index id1 = e.verts[1].index @@ -947,7 +927,6 @@ class edges_bending(bpy.types.Operator): for e in v.link_edges: vdef.append(deformations[e.index]) v_deformations.append(mean(vdef)) - print(v_deformations) if self.bounds == 'MANUAL': min_def = radians(self.min_def) max_def = radians(self.max_def) @@ -1097,7 +1076,6 @@ class weight_contour_displace(bpy.types.Operator): if w_min < iso_val and w_max > iso_val: faces_mask.append(f) break - #print("selected faces:" + str(len(faces_mask))) #link_faces = [[f for f in e.link_faces] for e in bm.edges] @@ -1137,7 +1115,6 @@ class weight_contour_displace(bpy.types.Operator): count += 1 _filtered_edges.append(e) filtered_edges = _filtered_edges - #print("creating faces") splitted_faces = [] switch = False @@ -1180,7 +1157,6 @@ class weight_contour_displace(bpy.types.Operator): splitted_faces.append(build_faces[switch]) #del_faces.append(f.index) - #print("generate new bmesh") # adding new vertices for v in verts: new_vert = bm.verts.new(v) bm.verts.index_update() @@ -1197,7 +1173,6 @@ class weight_contour_displace(bpy.types.Operator): except: missed_faces.append(f) - #print("missed " + str(len(missed_faces)) + " faces") bm.faces.ensure_lookup_table() # updating weight values weight = weight + [iso_val]*len(verts) @@ -1211,7 +1186,6 @@ class weight_contour_displace(bpy.types.Operator): if e not in delete_edges: _filtered_edges.append(e) filtered_edges = _filtered_edges - #print("creating curve") name = ob0.name + '_ContourDisp' me = bpy.data.meshes.new(name) bm.to_mesh(me) @@ -1229,7 +1203,6 @@ class weight_contour_displace(bpy.types.Operator): ob.vertex_groups.new(name=g.name) #ob.vertex_groups.new(name=vertex_group_name) - #print("doing weight") all_weight = weight + [iso_val]*len(verts) #mult = 1/(1-iso_val) for id in range(len(all_weight)): @@ -1253,10 +1226,6 @@ class weight_contour_displace(bpy.types.Operator): if self.bool_flip: w1 = 1-w else: w1 = w ob.vertex_groups[vertex_group_name].add([id], w1, 'REPLACE') - #print("weight done") - #for id in range(len(weight), len(ob.data.vertices)): - # ob.vertex_groups[vertex_group_name].add([id], iso_val*0, 'ADD') - ob.vertex_groups.active_index = group_id @@ -1354,9 +1323,6 @@ class weight_contour_mask(bpy.types.Operator): if w_min < iso_val and w_max > iso_val: faces_mask.append(f) break - #print("selected faces:" + str(len(faces_mask))) - - #link_faces = [[f for f in e.link_faces] for e in bm.edges] filtered_edges = bm.edges# me0.edges faces_todo = [f.select for f in bm.faces] @@ -1388,7 +1354,6 @@ class weight_contour_mask(bpy.types.Operator): edges_id[str(id1)+"_"+str(id0)] = count count += 1 - #print("creating faces") splitted_faces = [] switch = False @@ -1430,7 +1395,6 @@ class weight_contour_mask(bpy.types.Operator): # add last face splitted_faces.append(build_faces[switch]) - #print("generate new bmesh") # adding new vertices for v in verts: bm.verts.new(v) bm.verts.ensure_lookup_table() @@ -1449,7 +1413,6 @@ class weight_contour_mask(bpy.types.Operator): bm.faces.new(face_verts) except: missed_faces.append(f) - #print("missed " + str(len(missed_faces)) + " faces") # Mask geometry if(True): @@ -1460,7 +1423,6 @@ class weight_contour_mask(bpy.types.Operator): else: weight.append(w) # Create mesh and object - #print("creating curve") name = ob0.name + '_ContourMask_{:.3f}'.format(iso_val) me = bpy.data.meshes.new(name) bm.to_mesh(me) @@ -1591,7 +1553,6 @@ class weight_contour_curves(bpy.types.Operator): if iso_val < 0: iso_val = (min_iso + max_iso)/2 except: iso_val = (min_iso + max_iso)/2 - #print(iso_val) faces_mask = [] for f in bm.faces: w_min = 2 @@ -1665,7 +1626,6 @@ class weight_contour_curves(bpy.types.Operator): iso_rad = (self.min_rad + self.max_rad)/2 radius = radius + [iso_rad]*len(verts) - #print("generate new bmesh") bm = bmesh.new() # adding new vertices for v in total_verts: bm.verts.new(v) @@ -1679,7 +1639,6 @@ class weight_contour_curves(bpy.types.Operator): except: pass try: - #print("creating curve") name = ob0.name + '_ContourCurves' me = bpy.data.meshes.new(name) bm.to_mesh(me) @@ -1987,7 +1946,6 @@ class face_area_to_vertex_groups(bpy.types.Operator): for i in range(len(areas)): areas[i] = mean(areas[i]) - print(areas) if self.bounds == 'MANUAL': min_area = self.min_area max_area = self.max_area @@ -2000,8 +1958,6 @@ class face_area_to_vertex_groups(bpy.types.Operator): elif self.bounds == 'TENSION': min_area = 1 max_area = max(areas) - print(min_area) - print(max_area) delta_area = max_area - min_area if delta_area == 0: delta_area = 0.0001 @@ -2144,6 +2100,9 @@ class start_reaction_diffusion(bpy.types.Operator): bl_description = ("Run a Reaction-Diffusion based on existing Vertex Groups: A and B") bl_options = {'REGISTER', 'UNDO'} + run : bpy.props.BoolProperty( + name="Run Reaction-Diffusion", default=True, description="Compute a new iteration on frame changes") + time_steps : bpy.props.IntProperty( name="Steps", default=10, min=0, soft_max=50, description="Number of Steps") @@ -2174,16 +2133,18 @@ class start_reaction_diffusion(bpy.types.Operator): def execute(self, context): reaction_diffusion_add_handler(self, context) + set_animatable_fix_handler(self, context) ob = context.object - ''' + + ob.reaction_diffusion_settings.run = self.run ob.reaction_diffusion_settings.dt = self.dt ob.reaction_diffusion_settings.time_steps = self.time_steps ob.reaction_diffusion_settings.f = self.f ob.reaction_diffusion_settings.k = self.k ob.reaction_diffusion_settings.diff_a = self.diff_a ob.reaction_diffusion_settings.diff_b = self.diff_b - ''' + # check vertex group A try: @@ -2218,6 +2179,7 @@ class reset_reaction_diffusion_weight(bpy.types.Operator): def execute(self, context): reaction_diffusion_add_handler(self, context) + set_animatable_fix_handler(self, context) ob = context.object @@ -2352,8 +2314,6 @@ def reaction_diffusion_def_(scene): for i in range(time_steps): lap_a = zeros((n_verts))#[0]*n_verts lap_b = zeros((n_verts))#[0]*n_verts - #print(len(lap)) - #print(len(weight)) if i == 0: lap_map = [[] for i in range(n_verts)] lap_mult = [] @@ -2397,6 +2357,9 @@ def reaction_diffusion_def_(scene): def reaction_diffusion_def(scene): for ob in scene.objects: if ob.reaction_diffusion_settings.run: + + start = time.time() + me = ob.data n_edges = len(me.edges) n_verts = len(me.vertices) @@ -2404,6 +2367,11 @@ def reaction_diffusion_def(scene): # store weight values a = np.zeros(n_verts) b = np.zeros(n_verts) + #a = thread_read_weight(a, ob.vertex_groups["A"]) + #b = thread_read_weight(b, ob.vertex_groups["B"]) + #a = read_weight(a, ob.vertex_groups["A"]) + #b = read_weight(b, ob.vertex_groups["B"]) + for i in range(n_verts): try: a[i] = ob.vertex_groups["A"].weight(i) except: pass @@ -2421,16 +2389,20 @@ def reaction_diffusion_def(scene): edge_verts = [0]*n_edges*2 me.edges.foreach_get("vertices", edge_verts) - edge_verts = np.array(edge_verts) - arr = np.arange(n_edges)*2 - id0 = edge_verts[arr] # first vertex indices for each edge - id1 = edge_verts[arr+1] # second vertex indices for each edge + timeElapsed = time.time() - start + print('RD - Preparation Time:',timeElapsed) + start = time.time() try: - a, b = numba_reaction_diffusion(n_verts, a, b, diff_a, diff_b, f, k, dt, id0, id1, time_steps) + edge_verts = np.array(edge_verts) + a, b = numba_reaction_diffusion(n_verts, n_edges, edge_verts, a, b, diff_a, diff_b, f, k, dt, time_steps) a = nan_to_num(a) b = nan_to_num(b) except: + edge_verts = np.array(edge_verts) + arr = np.arange(n_edges)*2 + id0 = edge_verts[arr] # first vertex indices for each edge + id1 = edge_verts[arr+1] # second vertex indices for each edge for i in range(time_steps): lap_a = np.zeros(n_verts) lap_b = np.zeros(n_verts) @@ -2451,6 +2423,10 @@ def reaction_diffusion_def(scene): a = nan_to_num(a) b = nan_to_num(b) + timeElapsed = time.time() - start + print('RD - Simulation Time:',timeElapsed) + start = time.time() + for i in range(n_verts): ob.vertex_groups['A'].add([i], a[i], 'REPLACE') ob.vertex_groups['B'].add([i], b[i], 'REPLACE') @@ -2460,6 +2436,9 @@ def reaction_diffusion_def(scene): ps.invert_vertex_group_density = not ps.invert_vertex_group_density ps.invert_vertex_group_density = not ps.invert_vertex_group_density + timeElapsed = time.time() - start + print('RD - Closing Time:',timeElapsed) + class TISSUE_PT_reaction_diffusion(Panel): bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' |