Andy,
how can i select all verts listed under the bones material ?
thanks
Moderator: pistacja
FEEDBACK: Illusoft Collada 1.4 Plugin v0.3.159 started
[Object "joint0"]
scene.link(ob) deprecated!
use scene.objects.link(ob) instead
FEEDBACK: FINISHED - time elapsed: 16.8#!BPY
"""
Name: 'MakeHuman Fix'
Blender: 246
Group: 'Object'
Tooltip: 'Cleanup import fron MakeHuman as per andyp's tutorial'
"""
__author__ = 'Martin Ellison'
__version__ = '1.0 2008/07/28'
__url__ = []
__email__ = ["Martin Ellison, m.e:acm*org", "scripts"]
__bpydoc__ = """\
this automates part of a makehuman->blender import.
See http://www.makehuman.org/forum/viewtopic.php?f=6&t=167
1. Import human using collada 1.4 importer
2. select mesh
3. run this script
4. continue tutorial, starting with parenting armature to mesh
"""
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) Martin Ellison
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
from Blender import Window, sys, Texture, Image, Material, Draw, Mesh, Scene, Modifier
imageDir = '/home/martin/makehuman/rendering/'
prefix = 'lady3-'
def add_texture(name, fileName, index, materialName, mapTo):
tex = Texture.New(prefix + name)
tex.setType('Image')
imageFile = imageDir + fileName
img = Image.Load(imageFile)
tex.image = img
mat = Material.Get(materialName)
mat.spec = 0
mat.hard = 1
mat.setTexture(index, tex)
mtex = mat.getTextures()[index]
mtex.texco = Texture.TexCo.UV
mtex.mapping = Texture.Mappings.FLAT
mtex.mapto = mapTo
def fix_human(mesh):
try:
print 'fixing mesh...'
add_texture('head-colour', 'head_color.tx', 0, 'head', Texture.MapTo.COL | Texture.MapTo.CSP | Texture.MapTo.CMIR)
add_texture('head-bump', 'head_bump.tx', 1, 'head', Texture.MapTo.NOR)
add_texture('head-specular', 'head_specular.tx', 2, 'head', Texture.MapTo.SPEC)
add_texture('body-colour', 'body_color.tx', 0, 'body', Texture.MapTo.COL | Texture.MapTo.CSP | Texture.MapTo.CMIR)
add_texture('body-bump', 'body_bump.tx', 1, 'body', Texture.MapTo.NOR)
add_texture('body-specular', 'body_specular.tx', 2, 'body', Texture.MapTo.SPEC)
add_texture('eyes-reflection', 'eyes_reflection.tx', 0, 'eye', Texture.MapTo.REF)
add_texture('eyes-colour', 'eyes_color.tx', 1, 'eye', Texture.MapTo.COL | Texture.MapTo.CSP | Texture.MapTo.CMIR)
add_texture('eyebrows-alpha', 'eyebrows_alpha.tx', 0, 'eyebrows', Texture.MapTo.ALPHA)
Material.Get('eyebrows').getTextures()[0].tex.imageFlags = Texture.ImageFlags.CALCALPHA | Texture.ImageFlags.CALCALPHA
add_texture('eyebrows-colour', 'eyebrows_color.tx', 1, 'eyebrows', Texture.MapTo.COL | Texture.MapTo.CSP | Texture.MapTo.CMIR)
Material.Get('eyebrows').mode |= Material.Modes.ZTRANSP | Material.Modes.SHADOWBUF | Material.Modes.TRACEABLE
Material.Get('eyebrows').alpha = 0
add_texture('eyelashes-colour', 'eyelashes_color.tx', 1, 'eyelashes', Texture.MapTo.COL | Texture.MapTo.CSP | Texture.MapTo.CMIR)
Material.Get('eyelashes').mode |= Material.Modes.ZTRANSP | Material.Modes.SHADOWBUF | Material.Modes.TRACEABLE
Material.Get('eyelashes').alpha = 0
bonesMaterialIndex = -1
for matIndex in range(len(mesh.materials)):
if mesh.materials[matIndex].name.startswith('bones'):
bones = []
for face in mesh.faces:
if face.mat == matIndex:
for vert in face.verts:
bones += [vert]
print 'bones material is #%d, deleting %d bones' % (matIndex, len(bones))
mesh.verts.delete(bones)
for face in mesh.faces: face.smooth = True
print 'done'
except:
Draw.PupMenu("There was some problem ")
raise
def main():
print '-----'
Window.WaitCursor(1)
t = sys.time()
# Run the object editing function
scn= Scene.GetCurrent()
sel_object = scn.objects.active
if sel_object == None or sel_object.getType()!='Mesh':
result = Draw.PupMenu("You need to select a mesh")
return
popup = []
global imageDir
global prefix
imageDir = Draw.PupStrInput("Image directory: ", imageDir, 64)
prefix = Draw.PupStrInput("Texture prefix: ", '')
retval = Draw.PupMenu("Continue?%t|No|Yes")
if not retval: return
the_mesh = sel_object.getData(mesh=1)
editmode = Window.EditMode()
if editmode: Window.EditMode(0)
fix_human(the_mesh)
if editmode: Window.EditMode(1)
Window.RedrawAll()
# Timing the script is a good way to be aware on any speed hits when scripting
print 'My Script finished in %.2f seconds' % (sys.time()-t)
Window.WaitCursor(0)
# This lets you can import the script without running it
if __name__ == '__main__':
main()
#!BPY
# """
# Name: 'Re-align Armature'
# Blender: 246
# Group: 'Mesh'
# Tooltip: '(Re)Attach an armature to a mesh and ensure that they have the same object centres.'
# """
import Blender
from Blender import Window, Draw, Scene, Object, Mesh
__author__ = 'Martin Ellison'
__version__ = '1.0 2008/07/30'
__url__ = []
__email__ = ["Martin Ellison, m.e:acm*org", "scripts"]
__bpydoc__ = """\
From the popup, select one armature and one mesh.
"""
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Script copyright (C) Martin Ellison
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
import Blender
from Blender import Window, Scene, Geometry, Mathutils, Object, Armature, Mesh, Draw
from Blender.Mathutils import Vector
def alignArmature(armatureObject, meshObject):
armatureLoc = Vector(armatureObject.loc)
armature = armatureObject.getData()
meshLoc = Vector(meshObject.loc)
diff = armatureLoc - meshLoc
armature.makeEditable()
for bone in armature.bones.values():
bone.head -= diff
bone.tail -= diff
armature.update()
armatureObject.setLocation(meshObject.loc)
def main():
print '-----'
scn = Scene.GetCurrent()
sel_object = scn.objects.active
popup = []
armatures = []
meshes = []
for obj in scn.getChildren():
if obj.type == 'Armature':
tog = Blender.Draw.Create(0)
popup.append((obj.name + ' (arm)', tog))
armatures.append((tog, obj.name))
if obj.type == 'Mesh':
tog = Blender.Draw.Create(0)
popup.append((obj.name + ' (mesh)', tog))
meshes.append((tog, obj.name))
if not Blender.Draw.PupBlock("Attach mesh to armature? ", popup): return
armatureName = ''
for tog, name in armatures:
if tog.val:
if armatureName != '': Draw.PupMenu("Duplicate armature")
armatureName = name
meshName = ''
for tog, name in meshes:
if tog.val:
if meshName != '': Draw.PupMenu("Duplicate mesh")
meshName = name
mesh_object = Object.Get(meshName)
armature_object = Object.Get(armatureName)
if mesh_object.getType()!='Mesh':
result = Draw.PupMenu("You need a mesh")
return
the_mesh = mesh_object.getData(mesh=1)
print 'the mesh is at ', mesh_object.loc
if armature_object.getType()!='Armature':
result = Draw.PupMenu("You need an armature")
return
the_armature = armature_object.getData()
print 'the armature is at ', armature_object.loc
editmode = Window.EditMode()
if editmode: Window.EditMode(0)
Window.WaitCursor(1)
if mesh_object.parent != None: mesh_object.clrParent()
alignArmature(armature_object, mesh_object)
armature_object.makeParentDeform([mesh_object])
if editmode: Window.EditMode(1)
Window.WaitCursor(0)
Window.RedrawAll()
if __name__ == '__main__':
main()
Users browsing this forum: No registered users and 1 guest