explosions again, shattering a mesh

Here’s another explosion script

http://www.picard.ups-tlse.fr/~mcshane/myExlplodeBeta.blend.gz

it’s basically the same idea as Soler’s but it
calculate face groups first so that the mesh
shatters not as individual faces but into “chunks”.
Added realism no?

It works fine on smallish meshes - a subdivision of the monkey
is OK but my code calculating the adjacencies for faces is
far from optimal.

It runs by selecting a mesh and then doing ctrl A
(as it’s already scriptlinked)

ouch! it causes blender to crash on my machine(linux, both blender 2.36 and a fairly recent CVS build) with this to say:


Traceback (most recent call last):
  File "explodeMe.py", line 9, in ?
TypeError: unsubscriptable object
*** glibc detected *** free(): invalid pointer: 0x09d42e10 ***
Aborted

woa very nice, the only idea I can think of is if the empty could postion the shatters force. this way it could act like a soda can or something…

The chunk mesh is much better, less like confetti and cleaner. .

sorry if it crashes your Blender.

what version of python 2.* are you running?

This is more of an alpha than a beta version.
I don’t have a Linux machine at home
(OS X, win2k)
I’ll try it at work later and see…

the Blender python api is good (feature rich)
but not very robust in places (update() can kill
anything if you feed it rubbish)

2.3.4. :expressionless:

I accidentally started another thread with my reply.

I’ts a bug when you hand getType() a None.
It gives up. I’ll fix the file and post it later today

is there anyway to add a point and direction of force to this script ???

Here’s an update. The short answer to your question is YES.

http://www.picard.ups-tlse.fr/~mcshane/myExlplodeBeta.blend.gz

explodeMe.py is really an example of client code that uses the class
Explosion defined in the Blender text object explosion.py,
this in turn imports some “standard functions” from tools.py.
The class binds a couple of names
in Blender.dict for persistence which are
used to do the dynamics of the
explosion at the bottom of the file.

The advantage of using a class, sorry if this sounds patronising,
is that I give you an interface to my code and tell you
what you can change. For example:

In the window explodeMe.py lines 34-40
shows how to get an Explosion instance.
I added an attribute expCenter which you can set
to be the center of the explosion, actually this
is a delta relative to the center of the mesh.
(If you need it I can add the 3 lines that
it takes to set this from a named empty.)
There is also a method makeV0,
which you can override i.e. customize, which calculates the
initial velocity of each chunk.

Here’s a dumb example.
If you remove the # line 37 or thereabouts
save and reload the standard makeV0
is overridden by makeV1 (which is defined
at the top of explodeMe.py).

BTW this does work with subsurfaced meshes
and should preserve smoothing.

BTW2 I was working on adding smoke etc. with particles
but the API doesn’t allow you to link an Effect to a Mesh

:frowning:

hm, i got the same error on a windows machine. i have an older version of python though. could be the problem.

Awesome script!!! I can see suzanne exploding!

2 simple questions…

  1. Ctrl-A is asking me if I want to apply size and rotation. If I hit alt-a to animate, I see the explosion… is this what you meant?

  2. I cannot get it to work on any other elements in the scene. If I select another element and hit alt-a, the original still explodes.

  3. Is there a way to link this to happen at a certain frame during an animation?

whoops… 3 ?s… sorry

reaper

Can I use this script in another model I have already built? When dumping the text file out and loading into another blend file and then trying to execute it, I got an error about the average vector not being loaded.

Ahhh man, I just need a full out tut on this awesome piece of work!

I split the code across 2 files.
tools.py contains the code for averageVector
and a couple of functions I use in other projects.
And since it’s a beta I’m still screwing around
so I didn’t paste it into the explosion.py

You should link the tools.py file
as well and everything will work fine again.
Or you can dump it somwhere in your pythonpath.

this would be a great script except for one thing. No Intructons. Please do not give me the “oh just play around with it crap” To me that is one reason blender has not made it as a pro application even as good at it its. People that are working for money and on deadlines do not want to “play around” to get the effect that they want. They want clear instruction on what controls and the interface do so they can make the effect that they want.

I copies all the files out of the blend file. Which btw should have been either a zip, it took a while to undertand that I had do delete the .gz on ther end to get a good blend file back.

But when I try to run them on a simple cube nothing happens. Even though I hav them all loaded into text windows and have pressed ALT-P on all three scripts

select the monkey head

Do the alt-A thing in the 3D window wait till it finishes and voila, no?

RTFDS Hey this is a Python Forum man instructions in python files
come in triple quoted strings ‘’’ ‘’’ which you find at the top of the module
on lines 4,5,6

Back in the old days the only python script that worked/ was bundled was
the doc string browser…

You might think that works… but now select the box and try again. It still explodes the monkey head in mine.

So what you are saying is that this only works with that one mesh and in the one blend file that you included in the link.

RAISON D’ETRE:

let’s be clear.

the download you took was a demo for a class in the module explosion.py
a class is not a script as you understand it. This is not intended to be
used as a script and as I said I was screwing about with the limits
of the API as such persistence etc (see criticism below).
The Blender guys give you this stoopid module Registry
that you don’t need, they give you a few hints and
then leave you up s*** creek…to figure out what best practice is.

So the intended audience is other developpers whoever they
might be (do they exist ) and I want to figure out what best
practice is for keeping the mesh deformation data.

ANSWER to your question:

Sure you can add a mesh, select it, save Blender, quit, reload
then alt-A will explode your mesh. Don’t complain – I still
to ctrl-W before I edit a mesh because I haven’t got used
to having an undo yet.

on the other hand there is an unzipped .blend at the same URL
merely selecting another mesh and doing alt-A does what you
want (unfortunately I didn’t have the time to write the clean up
code so every time you do this this adds essentially 2 copies
of the selected mesh).

The effect is still quite unnatural tell me what you like and
I might make a proper end user script. For example

a) I don’t think square faces are natural and in any case should
be smaller/more random

b) maybe the big pieces should be extruded at the edges.

c) maybe the big pieces should be individual objects with IPOs

d) I thought about adding clouds and a flash but the
API won’t let me access the texture mappings so…

BTW I disagree with you about this being the worst example
of open source. I wrote minimal demo code
because I didn’t want all those nested if’s that you have to do
to check the user hasn’t done something incredibly stoopid.
I was sure this would p*** some people off

What p***es me off is that I have been hanging
about this forum for over a year and in all that time.

1/ the API is flakier than ever (see my other posts on
Effects, Scenes, and key IPOs over on blender.org)
You can’t even access texture mappings.

The doc is wrong/largely incomplete in places e.g.
http://www.blender.org/modules/documentation/236PythonDoc/Object.Object-class.html#copyAllPropertiesTo

what does this do?

2/ I use Python a lot (mySQL, PIL, webcrawling, google,CGI)
and have a collection of useful modules and ‘stolen code’
from other people. As yet I have not stolen a single
line (well actually I stole 4 from JMS) on this forum

3/ at Blender.org the code snippets consists of 5 functions
one of which I rewrote cutting it from >250 lines to <110.

This all really hurts if you have a deadline and want
to modify something to order (I know form experience).
When I did ActionScript a quick google search and
usually you found something close enough.
It was often written as a class, which you subclassed,
overrode/added methods etc, like in the explodeMe.py

the script seems to be working for me now. very nice. one suggestion for an improvement: in the old script the pieces actually travelled in an arc, then scattered on the ground. I have no idea how jms accomplished this, and I’m sure it was very complicated, but it would be very cool.

sure this can be done.

It just means adding gravity in the equation in the loop at the bottom
of explodeMe.py. I think JMS had a flag that he set and the bits bounced
this is more difficult and when objects bounce they pick up
angular momentum (rotation see below). In any case
I’ve been watching reruns of Star Wars on TV with my kid
and in general they show <1 sec of an explosion so over
that kind of timescale you don’t really see gravity at work.

Of course real explosions like you see in Iraq
are puffs of smoke with vapour trails but as I say the API won’t
let you access texture mappings or create usable
particle systems :x (You can get chunks, when Chernoby
went up there were some great chunks)

Then again I could link these in with Library from another .blend
but the Blender guys haven’t given us a model for distributing
scripts that use Libraries like this. I agree with SHABA1 my
way of distributing/packing this script, sorry class, sucks but
thinking up solutions all the time is tiring and I have a
day job, two kids and a cat…if only there was an O’Reilley
“Blender Hacks”

Finally, like I said I’m screwing about trying to see what’s
the best way of doing persistence in the API as the
Blender “Crew” have more or less given us an API
and told us to get on with it. As far as I see Registry
dupicates things you could already do. You can
save numerical data as points in a mesh, yes
even vectors but then you have to hide it so
the user doesn’t delete it accidentally.

I think the big chunks should be individual objects
with IPO’s then I can add rotation to the motion – which you do
see over the 1 sec timescale and this would give the (end)user
the possibility of tweaking the explosion if he needed to.

But I don’t see how to clear all the points of an IPO curve
with the API