I was working on an explosion effect for which i needed the object’s faces to be separate so that they will fall apart. I wrote this small script.
import Blender
from Blender.NMesh import *
import math
#*******************************************************
# Global Variables
# 'g_dirOfDisp' specifies the direction the split face will be displaced
g_dirOfDisp = 0.1
#*******************************************************
so = Blender.Object.GetSelected()
if len(so) and so[0].getType() == 'Mesh':
vtxFaceHash = { }
me = so[0].getData()
#Create the vertex-face hash table
for face in me.faces:
for vtx in face.v:
if me.verts.index(vtx) not in vtxFaceHash.keys():
vtxFaceHash[me.verts.index(vtx)] = [me.faces.index(face)]
else:
vtxFaceHash[me.verts.index(vtx)].append(me.faces.index(face))
# Start splitting the faces
currVtx = newVtx = 0
changeWhere = -1
for pair in vtxFaceHash.items():
if len(pair[1]) > 1:
currVtx = me.verts[pair[0]]
for faceIndex in pair[1][1:]:
newVtx = Vert(currVtx.co[0], currVtx.co[1], currVtx.co[2])
me.verts.append(newVtx)
for vtx in me.faces[faceIndex].v:
changeWhere += 1
if vtx == currVtx:
me.faces[faceIndex].v[changeWhere] = newVtx
changeWhere = -1
del vtxFaceHash
me.update()
# Explode the object
for face in me.faces:
nml = face.normal
for vtx in face.v:
vtx.co[0] += nml[0]*g_dirOfDisp
vtx.co[1] += nml[1]*g_dirOfDisp
vtx.co[2] += nml[2]*g_dirOfDisp
me.update()
else:
print "No MESH Object Selected"
I hope this script is useful. If you find any bugs, please post here. I will add a GUI and some more control parameters asap.
you are right, there is a problem .
in fact, its work is just to disconnect one
or several vertices not complete faces.
to split faces, i use thetesselate script
It can work with minor improvements i.
If I change these lines:
...
if result<4:
for v in me.verts:
if v.sel==1:
lebon=v
...
for :
...if result<4:
vSelection=[]
for v in me.verts:
if v.sel==1:
vSelection.append(v)
for v in vSelection:
lebon=v
...
Heres an idea, can one of you two create a script that seperates the faces from a mesh and then makes them their own objects with the object centers in the face center?
thinking about something to work with my BlODEd module.
hum… seems to be a good idea but
an object mesh like suzane has 1970 faces,
do you really think that blender can manage
as much object at the same time ?
Heres an idea, can one of you two create a script that seperates the faces from a mesh and then makes them their own objects with the object centers in the face center?
some time ago I was thinking about doing something along this lines, but as matter of fact I didn’t really got into it.
my method was tinkered to be:
a) split chunks of mesh with random selection of faces(for f in m.faces: [f.flag=1 if random()>0.5]) , then copy selectedfacesdata to new meshobj, then remove these faces from initial object and iterate this until done. this would to some extent solve huge mesh problems, because there would be less of new objects generated.
b) build a list of new expl_mesh.00x objects, and move them in f.normal of initial object and add random plus rotation plus some sort of gravity
c) do something about lifespan
d) I had some rig to do kabooms with ipos back then and it included a negative lamp in it to cater for craters and such so I wanted to implement this and particles, too
but I didn’t even got close to really writing it down
Hey this is a great thread, I was wondering, with this explode script, would it be possible to have explosion patterns, maybe a vortex explode, Like when a small building is hit by a tornado and all the debris is taken up in a vortex, also is it posible to add random directions to the exploded parts.