Page MenuHome

implicitskeleton_248.py

implicitskeleton_248.py

#!BPY
"""
Name: '_implicit skeleton_248'
Blender: 248
Group: 'Add'
Tip: 'Create skel mesh.'
"""
__author__ = ["Andy Houston "]
__url__ = ("http://wiki.blender.org/index.php/Extensions:Py/Scripts/Manual/Add/Implicit_Skeleton")
__version__ = "248 - 2008-10"
__bpydoc__ = """\
This script creates something like triangular metaballs.
If you create a low poly model in Blender
select it and run the script.
it will create a mesh based on the faces of the original mesh.
hence "implicit skeleton".
Be careful using this script, as it is slow & may cause crashes.
The script is not limited to the default meshes, use any mesh you like. .
.\n\
"""
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2008, Andy Houston (serendipiti)
#
# 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 *****
## Implicit skeleton script by Andy Houston (serendipiti)
##
## The marchingtetra.py file that this script uses is
## based on J M Soler's polygonize.py script. I have
## converted it to a class and added in an option for
## greater accuracy, so that the mesh is as close to the
## surface as possible with this polygonisation technique.
## This accuracy makes it slower, obviously.
##
## Create a low poly count, flat object like the swan
## thing in the 3D window. Select it, run the script,
## press the "Convert" button and wait.
## After what seems like far too long a blobby, metaball
## like mesh will appear.
##
## Set the bounding box slider values to about 25% bigger
## than your low poly object. It can be quite fiddly getting
## the settings right, so do experiment.
## Use low resolution and approximate accuracy to get
## everything centred, then high and exact for a
## better finish (and a long wait).
## This doesn't do much yet, but hopefully, after I have
## written a better polygoniser, this will develop into
## a useful modelling tool with nice mesh output.
##
## Hit alt-p to start script
##
import Blender
from Blender import NMesh,Draw,BGL
from implicit_vefm import mesh,face,finalfill,importmesh
import implicit_goo
import implicit_implicit
import implicit_marchingtetra
background=[.7,.7,.7,.0]
bxmin=Draw.Create(-2.0)
bxmax=Draw.Create(2.0)
bymin=Draw.Create(-2.0)
bymax=Draw.Create(2.0)
bzmin=Draw.Create(-2.0)
bzmax=Draw.Create(2.0)
bxres=Draw.Create(10)
byres=Draw.Create(10)
bzres=Draw.Create(10)
strength=Draw.Create(7.0)
accuracy=Draw.Create(0)
approx=Draw.Create(1)
exact=Draw.Create(0)
threshold=Draw.Create(0.5)
def drawgui():
global bxmin,bxmax,bymin,bymax,bzmin,bzmax,bxres,byres,bzres
global strength,approx,exact,threshold,accuracy
gs=implicit_goo.guispace(background)
pan=implicit_goo.panel(5,5,gs.width-5, 250,[.9,.9,.9],[.1,.1,.1])
lp=implicit_goo.scaffold(pan.left+5, pan.base+5, pan.width-10, pan.height-10, 9,5,5)
bxmin=Draw.Slider("x min: ", 2,lp.col3[0],lp.row[0],lp.third,lp.bheight[0], bxmin.val, -10, 0.0,0,"Bounding box x minimum")
bymin=Draw.Slider("y min: ", 2,lp.col3[0],lp.row[1],lp.third,lp.bheight[0], bymin.val, -10, 0.0,0,"Bounding box y minimum")
bzmin=Draw.Slider("z min: ", 2,lp.col3[0],lp.row[2],lp.third,lp.bheight[0], bzmin.val, -10, 0.0,0,"Bounding box z minimum")
bxmax=Draw.Slider("x max: ", 2,lp.col3[1],lp.row[0],lp.third,lp.bheight[0], bxmax.val, 0.0, 10.0,0,"Bounding box x maximum")
bymax=Draw.Slider("y max: ", 2,lp.col3[1],lp.row[1],lp.third,lp.bheight[0], bymax.val, 0.0, 10.0,0,"Bounding box y maximum")
bzmax=Draw.Slider("z max: ", 2,lp.col3[1],lp.row[2],lp.third,lp.bheight[0], bzmax.val, 0.0, 10.0,0,"Bounding box z maximum")
bxres=Draw.Slider("x res: ", 2,lp.col3[2],lp.row[0],lp.third,lp.bheight[0], bxres.val, 5, 25,0,"Bounding box x resolution, lower is quicker")
byres=Draw.Slider("y res: ", 2,lp.col3[2],lp.row[1],lp.third,lp.bheight[0], byres.val, 5, 25,0,"Bounding box y resolution, lower is quicker")
bzres=Draw.Slider("z res: ", 2,lp.col3[2],lp.row[2],lp.third,lp.bheight[0], bzres.val, 5, 25,0,"Bounding box z resolution, lower is quicker")
threshold=Draw.Slider("threshold: ", 2,lp.col1[0],lp.row[3],lp.threequarter,lp.bheight[0], threshold.val, 0.01, 1.0,0,"Blobbyness level, lower is blobbier")
strength=Draw.Slider("strength: ", 2,lp.col1[0],lp.row[4],lp.threequarter,lp.bheight[0], strength.val, 0.01, 10.0,0,"Higher values are closer to the underlying triangle")
approx=Draw.Toggle("Approximate",4,lp.col2[0],lp.row[5],lp.half,lp.bheight[0],approx.val,"Quicker conversion, low quality surface")
exact=Draw.Toggle("Exact",5,lp.col2[1],lp.row[5],lp.half,lp.bheight[0],exact.val,"Slower (much) conversion, higher quality surface. Not perfect")
Draw.Button("Convert", 3, lp.col3[0], lp.row[8],lp.half,lp.bheight[0]*2,"Turn flat triangles into blobby triangles. Check console for progress")
Draw.Button("EXIT", 1, lp.col3[2], lp.row[8],lp.third,lp.bheight[0],"Exit script")
def buttonevents(evt):
if (evt== 1):
Draw.Exit()
elif (evt== 3):
march()
Draw.Redraw()
elif (evt==4):
accuracy.val=0
approx.val=1
exact.val=0
Draw.Redraw()
elif (evt==5):
accuracy.val=1
approx.val=0
exact.val=1
Draw.Redraw()
def otherevents(evt, val):
global mousex,mousey
if (evt== Draw.ESCKEY and not val):
Draw.Exit()
if (evt== Draw.QKEY and not val):
Draw.Exit()
def march():
testy=mesh()
obsel=Blender.Object.GetSelected()
selecto=obsel[0].getName()
impy=importmesh(selecto,1)
cuberez=[bxres.val,byres.val,bzres.val,]
if strength.val>1.0:
streng=strength.val**2
else:
streng=strength.val
cube=implicit_marchingtetra.marchingtetra([bxmin.val,bxmax.val,bymin.val,bymax.val,bzmin.val,bzmax.val,],cuberez,threshold.val,testy,accuracy.val,0.001)
for tri in impy.faces:
imptri=implicit_implicit.cauchytriangle(tri,streng,1.0)
cube.implist.append(imptri)
cube.samplegrid()
basemesh=NMesh.GetRaw()
finalfill(testy,basemesh)
NMesh.PutRaw(basemesh,"test",1)
print "done"
Draw.Register(drawgui, otherevents, buttonevents)

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
65/a3/55edd4696f822bb0f304fd64172f

Event Timeline