Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormeta-androcto <meta.androcto1@gmail.com>2019-07-03 12:28:22 +0300
committermeta-androcto <meta.androcto1@gmail.com>2019-07-03 12:28:22 +0300
commit2b144940181b60c8a08b91646e167064f286a2ef (patch)
tree9b44478d3eea0af439c210588ba444f9cb13570b /mesh_tissue
parent582119a574effd14e09b76491bb018526757d994 (diff)
mesh_tissue: fix errors, remove read me, clean up: T63477
Diffstat (limited to 'mesh_tissue')
-rw-r--r--mesh_tissue/README.md38
-rw-r--r--mesh_tissue/__init__.py4
-rw-r--r--mesh_tissue/colors_groups_exchanger.py93
-rw-r--r--mesh_tissue/dual_mesh.py13
-rw-r--r--mesh_tissue/lattice.py13
-rw-r--r--mesh_tissue/numba_functions.py44
-rw-r--r--mesh_tissue/tessellate_numpy.py10
-rw-r--r--mesh_tissue/utils.py96
-rw-r--r--mesh_tissue/uv_to_mesh.py50
9 files changed, 187 insertions, 174 deletions
diff --git a/mesh_tissue/README.md b/mesh_tissue/README.md
deleted file mode 100644
index e5511cef..00000000
--- a/mesh_tissue/README.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Tissue
-![cover](http://www.co-de-it.com/wordpress/wp-content/uploads/2015/07/tissue_graphics.jpg)
-Tissue - Blender's add-on for computational design by Co-de-iT
-http://www.co-de-it.com/wordpress/code/blender-tissue
-
-### Blender 2.79
-
-Official version (master): https://github.com/alessandro-zomparelli/tissue/archive/master.zip
-
-Latest development version (dev1): https://github.com/alessandro-zomparelli/tissue/tree/dev1
-(Includes animatable Tessellation)
-
-### Blender 2.80
-
-Latest development version (b280-dev): https://github.com/alessandro-zomparelli/tissue/tree/b280-dev
-(Includes animatable Tessellation and Patch method)
-
-
-
-### Installation:
-
-1. Start Blender. Open User Preferences, the addons tab
-2. Click "install from file" and point Blender at the downloaded zip
-3. Activate Tissue add-on from user preferences
-3. Save user preferences if you want to have it on at startup.
-
-
-### Contribute
-Please help me keeping Tissue stable and updated, report any issue here: https://github.com/alessandro-zomparelli/tissue/issues
-
-Tissue is free and open-source. I really think that this is the power of Blender and I wanted to give my small contribution to it.
-If you like my work and you want to help to continue the development of Tissue, please consider to make a small donation. Any small contribution is really appreciated, thanks! :-D
-
-Alessandro
-
-
-[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ARSDJWXVFZ346)
-
diff --git a/mesh_tissue/__init__.py b/mesh_tissue/__init__.py
index 3be9aefd..26fbd199 100644
--- a/mesh_tissue/__init__.py
+++ b/mesh_tissue/__init__.py
@@ -34,10 +34,10 @@ bl_info = {
"name": "Tissue",
"author": "Alessandro Zomparelli (Co-de-iT)",
"version": (0, 3, 25),
- "blender": (2, 79, 0),
+ "blender": (2, 80, 0),
"location": "",
"description": "Tools for Computational Design",
- "warning": "Work In Progress",
+ "warning": "",
"wiki_url": "https://github.com/alessandro-zomparelli/tissue/wiki",
"tracker_url": "https://github.com/alessandro-zomparelli/tissue/issues",
"category": "Mesh"}
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'
diff --git a/mesh_tissue/dual_mesh.py b/mesh_tissue/dual_mesh.py
index eefd4c07..63735c72 100644
--- a/mesh_tissue/dual_mesh.py
+++ b/mesh_tissue/dual_mesh.py
@@ -29,16 +29,6 @@
# #
# ############################################################################ #
-bl_info = {
- "name": "Dual Mesh",
- "author": "Alessandro Zomparelli (Co-de-iT)",
- "version": (0, 4),
- "blender": (2, 8, 0),
- "location": "",
- "description": "Convert a generic mesh to its dual",
- "warning": "",
- "wiki_url": "",
- "category": "Mesh"}
import bpy
from bpy.types import Operator
@@ -131,9 +121,6 @@ class dual_mesh_tessellated(Operator):
ob.tissue_tessellate.merge = True
ob.tissue_tessellate.bool_dissolve_seams = True
if self.source_faces == 'TRI': ob.tissue_tessellate.fill_mode = 'FAN'
- print(ob1)
- print(ob0)
- print(bpy.context.object)
bpy.ops.object.update_tessellate()
ob.location = ob0.location
ob.matrix_world = ob0.matrix_world
diff --git a/mesh_tissue/lattice.py b/mesh_tissue/lattice.py
index fade7837..4e398332 100644
--- a/mesh_tissue/lattice.py
+++ b/mesh_tissue/lattice.py
@@ -27,18 +27,6 @@
# #
# ############################################################################ #
-bl_info = {
- "name": "Lattice",
- "author": "Alessandro Zomparelli (Co-de-iT)",
- "version": (0, 3),
- "blender": (2, 7, 8),
- "location": "",
- "description": "Generate a Lattice based on a grid mesh",
- "warning": "",
- "wiki_url": "",
- "category": "Mesh"}
-
-
import bpy
import bmesh
from bpy.types import Operator
@@ -372,7 +360,6 @@ class lattice_along_surface(Operator):
first = False
bb = max - min
- print(bb)
lattice_loc = (max + min) / 2
bpy.ops.object.add(type='LATTICE')
lattice = bpy.context.active_object
diff --git a/mesh_tissue/numba_functions.py b/mesh_tissue/numba_functions.py
index 1cb8e6b8..62c7dc22 100644
--- a/mesh_tissue/numba_functions.py
+++ b/mesh_tissue/numba_functions.py
@@ -16,25 +16,31 @@
#
# ##### END GPL LICENSE BLOCK #####
-from numba import jit
import numpy as np
+try:
+ from numba import jit
-@jit
-def numba_reaction_diffusion(n_verts, a, b, diff_a, diff_b, f, k, dt, id0, id1, time_steps):
- for i in range(time_steps):
- lap_a = np.zeros(n_verts)
- lap_b = np.zeros(n_verts)
- lap_a0 = a[id1] - a[id0] # laplacian increment for first vertex of each edge
- lap_b0 = b[id1] - b[id0] # laplacian increment for first vertex of each edge
+ @jit
+ def numba_reaction_diffusion(n_verts, n_edges, edge_verts, a, b, diff_a, diff_b, f, k, dt, time_steps):
+ 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)
+ lap_a0 = a[id1] - a[id0] # laplacian increment for first vertex of each edge
+ lap_b0 = b[id1] - b[id0] # laplacian increment for first vertex of each edge
- for i, j, la0, lb0 in zip(id0,id1,lap_a0,lap_b0):
- lap_a[i] += la0
- lap_b[i] += lb0
- lap_a[j] -= la0
- lap_b[j] -= lb0
- ab2 = a*b**2
- #a += eval("(diff_a*lap_a - ab2 + f*(1-a))*dt")
- #b += eval("(diff_b*lap_b + ab2 - (k+f)*b)*dt")
- a += (diff_a*lap_a - ab2 + f*(1-a))*dt
- b += (diff_b*lap_b + ab2 - (k+f)*b)*dt
- return a, b
+ for i, j, la0, lb0 in zip(id0,id1,lap_a0,lap_b0):
+ lap_a[i] += la0
+ lap_b[i] += lb0
+ lap_a[j] -= la0
+ lap_b[j] -= lb0
+ ab2 = a*b**2
+ #a += eval("(diff_a*lap_a - ab2 + f*(1-a))*dt")
+ #b += eval("(diff_b*lap_b + ab2 - (k+f)*b)*dt")
+ a += (diff_a*lap_a - ab2 + f*(1-a))*dt
+ b += (diff_b*lap_b + ab2 - (k+f)*b)*dt
+ return a, b
+except:
+ pass
diff --git a/mesh_tissue/tessellate_numpy.py b/mesh_tissue/tessellate_numpy.py
index 9526d115..52b50e60 100644
--- a/mesh_tissue/tessellate_numpy.py
+++ b/mesh_tissue/tessellate_numpy.py
@@ -124,7 +124,7 @@ class tissue_tessellate_prop(PropertyGroup):
)
bool_run : BoolProperty(
name="Animatable Tessellation",
- description="Automatically recompute the tessellation when the frame is changed",
+ description="Automatically recompute the tessellation when the frame is changed. Currently is not working during Render Animation",
default = False,
update = set_tessellate_handler
)
@@ -1271,8 +1271,6 @@ def tessellate_original(_ob0, _ob1, offset, zscale, gen_modifiers, com_modifiers
for v in me0.vertices:
try:
_weight.append(vg.weight(v.index))
- #print(vg.weight(v.index))
- #_weight.append(v.groups[0])
except:
_weight.append(0)
weight.append(_weight)
@@ -2361,7 +2359,6 @@ class update_tessellate(Operator):
local_ob1 = []
for area in bpy.context.screen.areas:
for space in area.spaces:
- print(space)
try:
if ob.local_view_get(space):
local_spaces.append(space)
@@ -2684,8 +2681,6 @@ class update_tessellate(Operator):
for space, local0, local1 in zip(local_spaces, local_ob0, local_ob1):
ob0.local_view_set(space, local0)
ob1.local_view_set(space, local1)
- print(local_ob0)
- print(local_ob1)
return {'FINISHED'}
@@ -2761,6 +2756,9 @@ class TISSUE_PT_tessellate_object(Panel):
icon='ERROR')
col = layout.column(align=True)
row = col.row(align=True)
+
+ set_tessellate_handler(self,context)
+ set_animatable_fix_handler(self,context)
row.prop(props, "bool_run", text="Animatable")
row.operator("object.update_tessellate", icon='FILE_REFRESH')
diff --git a/mesh_tissue/utils.py b/mesh_tissue/utils.py
index e9aa894b..f9186120 100644
--- a/mesh_tissue/utils.py
+++ b/mesh_tissue/utils.py
@@ -1,4 +1,82 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
import bpy
+import threading
+import numpy as np
+import multiprocessing
+from multiprocessing import Process, Pool
+
+weight = []
+n_threads = multiprocessing.cpu_count()
+
+class ThreadVertexGroup(threading.Thread):
+ def __init__ ( self, id, vertex_group, n_verts):
+ self.id = id
+ self.vertex_group = vertex_group
+ self.n_verts = n_verts
+ threading.Thread.__init__ ( self )
+
+ def run (self):
+ global weight
+ global n_threads
+ verts = np.arange(int(self.n_verts/8))*8 + self.id
+ for v in verts:
+ try:
+ weight[v] = self.vertex_group.weight(v)
+ except:
+ pass
+
+def thread_read_weight(_weight, vertex_group):
+ global weight
+ global n_threads
+ print(n_threads)
+ weight = _weight
+ n_verts = len(weight)
+ threads = [ThreadVertexGroup(i, vertex_group, n_verts) for i in range(n_threads)]
+ for t in threads: t.start()
+ for t in threads: t.join()
+ return weight
+
+def process_read_weight(id, vertex_group, n_verts):
+ global weight
+ global n_threads
+ verts = np.arange(int(self.n_verts/8))*8 + self.id
+ for v in verts:
+ try:
+ weight[v] = self.vertex_group.weight(v)
+ except:
+ pass
+
+
+def read_weight(_weight, vertex_group):
+ global weight
+ global n_threads
+ print(n_threads)
+ weight = _weight
+ n_verts = len(weight)
+ n_cores = multiprocessing.cpu_count()
+ pool = Pool(processes=n_cores)
+ multiple_results = [pool.apply_async(process_read_weight, (i, vertex_group, n_verts)) for i in range(n_cores)]
+ #processes = [Process(target=process_read_weight, args=(i, vertex_group, n_verts)) for i in range(n_threads)]
+ #for t in processes: t.start()
+ #for t in processes: t.join()
+ return weight
#Recursivly transverse layer_collection for a particular name
def recurLayerCollection(layerColl, collName):
@@ -108,3 +186,21 @@ def simple_to_mesh(ob):
me = bpy.data.meshes.new_from_object(ob_eval, preserve_all_data_layers=True, depsgraph=dg)
me.calc_normals()
return me
+
+# Prevent Blender Crashes with handlers
+def set_animatable_fix_handler(self, context):
+ old_handlers = []
+ blender_handlers = bpy.app.handlers.render_init
+ for h in blender_handlers:
+ if "turn_off_animatable" in str(h):
+ old_handlers.append(h)
+ for h in old_handlers: blender_handlers.remove(h)
+ blender_handlers.append(turn_off_animatable)
+ return
+
+def turn_off_animatable(scene):
+ for o in bpy.data.objects:
+ o.tissue_tessellate.bool_run = False
+ o.reaction_diffusion_settings.run = False
+ #except: pass
+ return
diff --git a/mesh_tissue/uv_to_mesh.py b/mesh_tissue/uv_to_mesh.py
index 87179a92..2e9d6928 100644
--- a/mesh_tissue/uv_to_mesh.py
+++ b/mesh_tissue/uv_to_mesh.py
@@ -28,23 +28,12 @@
# #
# ############################################################################ #
-bl_info = {
- "name": "UV to Mesh",
- "author": "Alessandro Zomparelli (Co-de-iT)",
- "version": (0, 1, 1),
- "blender": (2, 7, 9),
- "location": "",
- "description": "Create a new Mesh based on active UV",
- "warning": "",
- "wiki_url": "",
- "category": "Mesh"}
-
-
import bpy
import math
from bpy.types import Operator
from bpy.props import BoolProperty
from mathutils import Vector
+from .utils import *
class uv_to_mesh(Operator):
@@ -55,12 +44,12 @@ class uv_to_mesh(Operator):
apply_modifiers : BoolProperty(
name="Apply Modifiers",
- default=False,
+ default=True,
description="Apply object's modifiers"
)
vertex_groups : BoolProperty(
name="Keep Vertex Groups",
- default=False,
+ default=True,
description="Transfer all the Vertex Groups"
)
materials : BoolProperty(
@@ -85,7 +74,12 @@ class uv_to_mesh(Operator):
bpy.ops.object.convert(target='MESH')
ob0 = bpy.context.object
- me0 = ob0.to_mesh(bpy.context.depsgraph, apply_modifiers=self.apply_modifiers)
+# me0 = ob0.to_mesh(bpy.context.depsgraph, apply_modifiers=self.apply_modifiers)
+ #if self.apply_modifiers: me0 = simple_to_mesh(ob0)
+ #else: me0 = ob0.data.copy()
+ name0 = ob0.name
+ ob0 = convert_object_to_mesh(ob0, apply_modifiers=self.apply_modifiers, preserve_status=False)
+ me0 = ob0.data
area = 0
verts = []
@@ -111,7 +105,7 @@ class uv_to_mesh(Operator):
return {'CANCELLED'}
- name = ob0.name + 'UV'
+ name = name0 + 'UV'
# Create mesh and object
me = bpy.data.meshes.new(name + 'Mesh')
ob = bpy.data.objects.new(name, me)
@@ -132,20 +126,21 @@ class uv_to_mesh(Operator):
new_area += p.area
if new_area == 0:
self.report({'ERROR'}, "Impossible to generate mesh from UV")
+ bpy.data.objects.remove(ob0)
return {'CANCELLED'}
# VERTEX GROUPS
if self.vertex_groups:
- try:
- for group in ob0.vertex_groups:
- index = group.index
- ob.vertex_groups.new(group.name)
- for p in me0.polygons:
- for vert, loop in zip(p.vertices, p.loop_indices):
- ob.vertex_groups[index].add([loop], group.weight(vert), "ADD")
- except:
- pass
+ for group in ob0.vertex_groups:
+ index = group.index
+ ob.vertex_groups.new(name=group.name)
+ for p in me0.polygons:
+ for vert, loop in zip(p.vertices, p.loop_indices):
+ try:
+ ob.vertex_groups[index].add([loop], group.weight(vert), 'REPLACE')
+ except:
+ pass
ob0.select_set(False)
if self.auto_scale:
@@ -169,7 +164,7 @@ class uv_to_mesh(Operator):
ob.data.polygons[i].material_index = face_materials[i]
except:
pass
-
+ '''
if self.apply_modifiers:
bpy.ops.object.mode_set(mode='OBJECT')
ob.select_set(False)
@@ -177,5 +172,8 @@ class uv_to_mesh(Operator):
bpy.ops.object.delete(use_global=False)
ob.select_set(True)
bpy.context.view_layer.objects.active = ob
+ '''
+ bpy.data.objects.remove(ob0)
+ bpy.data.meshes.remove(me0)
return {'FINISHED'}