forked from bartvdbraak/blender
added list2MeshWeight and meshWeight2List - faster then the dict equivilents and better in some cases.
Speedup for bpymesh_redux (poly reducer) with reducing vertex weights. use list2MeshWeight and meshWeight2List. renamed vertex gradient files Removed reload()'s - 3ds_import.py - mesh_cleanup.py - mesh_poly_reduce.py - vertexpaint_selfshadow_ao.py
This commit is contained in:
parent
b4e787cb5c
commit
9a168d8285
@ -109,7 +109,6 @@ import Blender
|
||||
from Blender import Mesh, Scene, Object, Material, Image, Texture, Lamp, Mathutils
|
||||
from Blender.Mathutils import Vector
|
||||
import BPyImage
|
||||
reload( BPyImage )
|
||||
|
||||
import struct
|
||||
from struct import calcsize, unpack
|
||||
|
@ -1,8 +1,5 @@
|
||||
import Blender
|
||||
# from BPyMesh_redux import redux # seperated because of its size.
|
||||
import BPyMesh_redux
|
||||
reload(BPyMesh_redux)
|
||||
redux= BPyMesh_redux.redux
|
||||
from BPyMesh_redux import redux # seperated because of its size.
|
||||
|
||||
# python 2.3 has no reversed() iterator. this will only work on lists and tuples
|
||||
try:
|
||||
@ -20,7 +17,72 @@ except:
|
||||
except:
|
||||
set= None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def meshWeight2List(me):
|
||||
''' Takes a mesh and return its group names and a list of lists, one list per vertex.
|
||||
aligning the each vert list with the group names, each list contains float value for the weight.
|
||||
These 2 lists can be modified and then used with list2MeshWeight to apply the changes.
|
||||
'''
|
||||
|
||||
# Clear the vert group.
|
||||
groupNames= me.getVertGroupNames()
|
||||
len_groupNames= len(groupNames)
|
||||
|
||||
if not len_groupNames:
|
||||
# no verts? return a vert aligned empty list
|
||||
return [[] for i in xrange(len(me.verts))]
|
||||
|
||||
else:
|
||||
vWeightList= [[0.0]*len_groupNames for i in xrange(len(me.verts))]
|
||||
|
||||
for group_index, group in enumerate(groupNames):
|
||||
for vert_index, weight in me.getVertsFromGroup(group, 1): # (i,w) tuples.
|
||||
vWeightList[vert_index][group_index]= weight
|
||||
|
||||
# removed this because me may be copying teh vertex groups.
|
||||
#for group in groupNames:
|
||||
# me.removeVertGroup(group)
|
||||
|
||||
return groupNames, vWeightList
|
||||
|
||||
|
||||
def list2MeshWeight(me, groupNames, vWeightList):
|
||||
''' Takes a list of groups and a list of vertex Weight lists as created by meshWeight2List
|
||||
and applys it to the mesh.'''
|
||||
|
||||
if len(vWeightList) != len(me.verts):
|
||||
raise 'Error, Lists Differ in size, do not modify your mesh.verts before updating the weights'
|
||||
|
||||
# Clear the vert group.
|
||||
currentGroupNames= me.getVertGroupNames()
|
||||
for group in currentGroupNames:
|
||||
me.removeVertGroup(group) # messes up the active group.
|
||||
|
||||
# Add clean unused vert groupNames back
|
||||
currentGroupNames= me.getVertGroupNames()
|
||||
for group in groupNames:
|
||||
me.addVertGroup(group)
|
||||
|
||||
add_ = Blender.Mesh.AssignModes.ADD
|
||||
|
||||
vertList= [None]
|
||||
for i, v in enumerate(me.verts):
|
||||
vertList[0]= i
|
||||
for group_index, weight in enumerate(vWeightList[i]):
|
||||
if weight:
|
||||
try:
|
||||
me.assignVertsToGroup(groupNames[group_index], vertList, min(1, max(0, weight)), add_)
|
||||
except:
|
||||
pass # vert group is not used anymore.
|
||||
|
||||
me.update()
|
||||
|
||||
|
||||
|
||||
|
||||
def meshWeight2Dict(me):
|
||||
''' Takes a mesh and return its group names and a list of dicts, one dict per vertex.
|
||||
using the group as a key and a float value for the weight.
|
||||
@ -33,8 +95,8 @@ def meshWeight2Dict(me):
|
||||
groupNames= me.getVertGroupNames()
|
||||
|
||||
for group in groupNames:
|
||||
for index, weight in me.getVertsFromGroup(group, 1): # (i,w) tuples.
|
||||
vWeightDict[index][group]= weight
|
||||
for vert_index, weight in me.getVertsFromGroup(group, 1): # (i,w) tuples.
|
||||
vWeightDict[vert_index][group]= weight
|
||||
|
||||
# removed this because me may be copying teh vertex groups.
|
||||
#for group in groupNames:
|
||||
|
@ -102,7 +102,16 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI
|
||||
if (VGROUP_INF_REDUX!= None and VGROUP_INF_REDUX not in vgroups) or\
|
||||
VGROUP_INF_WEIGHT==0.0:
|
||||
VGROUP_INF_REDUX= None
|
||||
del vgroups
|
||||
|
||||
try:
|
||||
VGROUP_INF_REDUX_INDEX= vgroups.index(VGROUP_INF_REDUX)
|
||||
except:
|
||||
VGROUP_INF_REDUX_INDEX= -1
|
||||
|
||||
# del vgroups
|
||||
len_vgroups= len(vgroups)
|
||||
|
||||
|
||||
|
||||
OLD_MESH_MODE= Blender.Mesh.Mode()
|
||||
Blender.Mesh.Mode(Blender.Mesh.SelectModes.VERTEX)
|
||||
@ -182,7 +191,8 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI
|
||||
BPyMesh.meshCalcNormals(me, reuse_vertNormals)
|
||||
|
||||
if DO_WEIGHTS:
|
||||
groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
|
||||
#groupNames, vWeightDict= BPyMesh.meshWeight2Dict(me)
|
||||
groupNames, vWeightList= BPyMesh.meshWeight2List(me)
|
||||
|
||||
# THIS CRASHES? Not anymore.
|
||||
verts= list(me.verts)
|
||||
@ -276,11 +286,16 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI
|
||||
|
||||
# Use a vertex group as a weighting.
|
||||
if VGROUP_INF_REDUX!=None:
|
||||
vert_weights_map= [1.0] * len(verts)
|
||||
|
||||
# Get Weights from a vgroup.
|
||||
"""
|
||||
vert_weights_map= [1.0] * len(verts)
|
||||
for i, wd in enumerate(vWeightDict):
|
||||
try: vert_weights_map[i]= 1+(wd[VGROUP_INF_REDUX] * VGROUP_INF_WEIGHT)
|
||||
except: pass
|
||||
"""
|
||||
vert_weights_map= [1+(wl[VGROUP_INF_REDUX_INDEX]*VGROUP_INF_WEIGHT) for wl in vWeightList ]
|
||||
|
||||
|
||||
# BOUNDRY CHECKING AND WEIGHT EDGES. CAN REMOVE
|
||||
# Now we know how many faces link to an edge. lets get all the boundry verts
|
||||
@ -520,8 +535,9 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI
|
||||
|
||||
|
||||
# add verts vgroups to eachother
|
||||
'''
|
||||
wd1= vWeightDict[i1] # v1 weight dict
|
||||
wd2= vWeightDict[i2] # v1 weight dict
|
||||
wd2= vWeightDict[i2] # v2 weight dict
|
||||
|
||||
# Make sure vert groups on both verts exist.
|
||||
for wd_from, wd_to in ((wd1, wd2), (wd2, wd1)):
|
||||
@ -532,6 +548,12 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI
|
||||
# Mix the weights for vert groups
|
||||
for group_key in wd_from.iterkeys():
|
||||
wd1[group_key]= wd2[group_key]= (wd1[group_key]*w1) + (wd2[group_key]*w2)
|
||||
'''
|
||||
|
||||
wl1= vWeightList[i1] # v1 weight dict
|
||||
wl2= vWeightList[i2] # v2 weight dict
|
||||
for group_index in xrange(len_vgroups):
|
||||
wl1[group_index]= wl2[group_index]= (wl1[group_index]*w1) + (wl2[group_index]*w2)
|
||||
|
||||
|
||||
if DO_UV or DO_VCOL:
|
||||
@ -593,7 +615,8 @@ def redux(ob, REDUX=0.5, BOUNDRY_WEIGHT=2.0, REMOVE_DOUBLES=False, FACE_AREA_WEI
|
||||
|
||||
# Copy weights back to the mesh before we remove doubles.
|
||||
if DO_WEIGHTS:
|
||||
BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
|
||||
#BPyMesh.dict2MeshWeight(me, groupNames, vWeightDict)
|
||||
BPyMesh.list2MeshWeight(me, groupNames, vWeightList)
|
||||
|
||||
doubles= me.remDoubles(0.0001)
|
||||
current_face_count= len(me.faces)
|
||||
|
@ -1,21 +1,10 @@
|
||||
#!BPY
|
||||
"""
|
||||
Name: 'Weight Gradient...'
|
||||
Blender: 241
|
||||
Group: 'VertPaint'
|
||||
Tooltip: 'Grad.'
|
||||
"""
|
||||
# This is not to be used directly, vertexGradientPick can be used externaly
|
||||
|
||||
__author__ = ["Campbell Barton"]
|
||||
__url__ = ("blender", "elysiun", "http://members.iinet.net.au/~cpbarton/ideasman/")
|
||||
__version__ = "0.1"
|
||||
import Blender
|
||||
import BPyMesh
|
||||
import BPyWindow
|
||||
|
||||
|
||||
reload(BPyWindow)
|
||||
reload(BPyMesh)
|
||||
mouseViewRay= BPyWindow.mouseViewRay
|
||||
from Blender import Mathutils, Window, Scene, Draw, sys
|
||||
from Blender.Mathutils import CrossVecs, Vector, Intersect, LineIntersect, AngleBetweenVecs
|
@ -10,7 +10,6 @@ from Blender.Mathutils import TriangleArea
|
||||
|
||||
import Blender
|
||||
import BPyMesh
|
||||
reload(BPyMesh)
|
||||
dict2MeshWeight= BPyMesh.dict2MeshWeight
|
||||
meshWeight2Dict= BPyMesh.meshWeight2Dict
|
||||
|
||||
|
@ -8,7 +8,6 @@ Tooltip: 'Removed polygons from a mesh while maintaining the shape, textures and
|
||||
|
||||
from Blender import Draw, Window, Scene, Mesh, Mathutils, sys, Object
|
||||
import BPyMesh
|
||||
reload(BPyMesh)
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -10,8 +10,7 @@ __author__ = ["Campbell Barton"]
|
||||
__url__ = ("blender", "elysiun", "http://members.iinet.net.au/~cpbarton/ideasman/")
|
||||
__version__ = "0.1"
|
||||
|
||||
import __vertex_gradient__
|
||||
reload(__vertex_gradient__)
|
||||
import mesh_gradient
|
||||
import Blender
|
||||
|
||||
def main():
|
||||
@ -22,7 +21,7 @@ def main():
|
||||
Blender.Draw.PupMenu('Error, no active mesh object, aborting.')
|
||||
return
|
||||
|
||||
__vertex_gradient__.vertexGradientPick(ob, 1)
|
||||
mesh_gradient.vertexGradientPick(ob, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
@ -40,7 +40,6 @@ It removes very low weighted verts from the current group with a weight option.
|
||||
|
||||
from Blender import *
|
||||
import BPyMesh
|
||||
# reload(BPyMesh)
|
||||
|
||||
|
||||
def vertexFakeAO(me, PREF_BLUR_ITERATIONS, PREF_BLUR_RADIUS, PREF_MIN_EDLEN, PREF_CLAMP_CONCAVE, PREF_CLAMP_CONVEX, PREF_SHADOW_ONLY, PREF_SEL_ONLY):
|
||||
|
@ -20,8 +20,7 @@ Note:
|
||||
Holding Shift or clicking outside the mesh on the second click will blend the first colour to nothing.
|
||||
'''
|
||||
|
||||
import __vertex_gradient__
|
||||
reload(__vertex_gradient__)
|
||||
import mesh_gradient
|
||||
import Blender
|
||||
|
||||
def main():
|
||||
@ -34,7 +33,7 @@ def main():
|
||||
# MODE 0 == VCOL
|
||||
# MODE 1 == WEIGHT
|
||||
MODE= 0
|
||||
__vertex_gradient__.vertexGradientPick(ob, MODE)
|
||||
mesh_gradient.vertexGradientPick(ob, MODE)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
Loading…
Reference in New Issue
Block a user