Updated: Drop To Ground

Today I wrote the first version of a script that will drop any number of objects onto a “ground” object. Useful for: putting trees, rocks, etc, onto an irregular ground plane. Or sitting things on a table. Or whatever.

Usage: The object upon which all else will fall should be called “Ground”. Select the objects that you want to have sitting on that ground, and hit alt-p to run the script. Note that this isn’t phsyics - you’re objects will not tumble or stack up, etc. It’ll just drop them to the ground mesh.

A blend file with suitable Ground object and stuff to drop:
http://harkyman.home.comcast.net/Drop2Ground.blend
and a .py file for incorporation in the new script menus:
http://harkyman.home.comcast.net/Drop2Ground.py

Notes:

  1. Make sure you Cntrl-A your ground object before running the script, as it does not take scaling or rotation into effect.
  2. The script will place your objects based on their Object Center, so if it’s a tree, put your OC just above the bottom of the trunk.

updates:

  • Objects are now dropped to the actual mesh surface properly, not just to the average height of the face.
  • The script recognizes and compensates for a translated ground object, i.e. the ground object no longer has to have it’s object center at 0,0,0
  • Works for meshes with both tri and quad faces
  • Ignores objects who are not over the bounding box of the Ground object.
  • Added script menu headers, and a separate .py file for menu inclusion

Hey, nice going. This could have alot of uses.

Nice :slight_smile:

I’ll try it for rocks and trees :slight_smile:

quick qestions without yet having downloaded it :stuck_out_tongue:

1 - The ‘dropping’ objects stops when their center hits the ‘Ground’ or when their lower vertex does? first option would be more flexible :slight_smile:

2 - What happens to objects which would fall ‘outside’ ?

Stefano

Ok, got both answers by trying it :wink:

Stefano

Happy Happy joy… it works mighty fine.

Your still going for the bones not going through the floor? and would it be possible to move an object from left to right and it would follow the ground?

Greets and good luck in furter develloping this!

Very nice script indeed. Thankyou.
If you’re looking to extend this further how about…

1 - add the option to use the face normal of the face that the object ‘drops’ to to determine rotation of the falling object (handy for aligning objects to sloped sides of a mountain etc).

2 - instead of selecting all the objects that you wish to drop, chose one and the required number of duplicates and randomly scatter your object over the ground.

2 is somewhat easier to implement than 1 i think.

ps8: still working on the locking bones to the floor thing. Having trouble getting bone to follow my orders from Python.

Also, today I’m working on another version of this script that can be linked via frame-change or redraw links so that an object will follow the contours of a ground object as you move it around.

I probably won’t be adding randomized object creation to this script - that’s what Beast is for. This one is strictly for sticking already existing things to the ground. As for rotating of placed objects being influenced by the face normal - I’ve thought about it and I’m not sure I want to learn quite that much math. Calculating the z-value for x and y on an arbitrary triangle for this script was almost too much for me as it was!

Hi i tried your script, it register in the menu but when i click
on the menu it reply
“Version mismatch script was written for 232, it may fails with your 2.31”
and when i leave from the pop up message blender crash
===Drop to Ground - Start===
Traceback (most recent call last):
File “<string>”, line 61, in ?
AttributeError: Unknown object specified.
Segmentation fault

i compiled the last CVS on linux , python 2.2.2

i changed the line to match the version but when i
select the object to ground and start the script
i have this error

===Drop to Ground - Start===
===Drop to Ground - Done===
Memoryblock free: pointer not in memlist
Segmentation fault

mybe is just my compile

ciao
kino

Kino - I have not tested this with the current cvs script menus. I simply followed their instructions regarding headers. If it’s giving you a version incompatability, that’s because I put Blender: 232 in the header. Changing it to 231 would most likely fix that. If someone else has a problem with running through the menus, I’ll remove the link to the straight .py file until I can test it.

Also, another version of the script is now available. This one is for use with object script links, so you can animate or move an object around in real-time and have it stick to the contour of your terrain. It’s fun!

FollowTerrain:
http://harkyman.home.comcast.net/FollowTerrain.blend
with its own thread here:
https://blenderartists.org/forum/viewtopic.php?t=20183

i tried the blend file you provided without using the menu and all go well :slight_smile:

even if i change the version it dont work from the menu

Also, another version of the script is now available. This one is for use with object script links, so you can animate or move an object around in real-time and have it stick to the contour of your terrain. It’s fun!

FollowTerrain:
http://harkyman.home.comcast.net/FollowTerrain.blend
with its own thread here:
https://blenderartists.org/forum/viewtopic.php?t=20183

Yes also this one work really fine
great !
thanks
kino

Nice code.

I am attempting to use your program to drop a mesh i.e. vertices on to the ground.

I noticed that on quad faces you are converting the vertices to world coordinates

	#check for quad faces
	[x1,y1,z1] = InverseTranslate(GroundVerts[0].co,InvVec)
	[x2,y2,z2] = InverseTranslate(GroundVerts[1].co,InvVec)

where as on the tri face you are using relative coordinates.

	#check for tri faces
	[x1,y1,z1] = GroundVerts[0].co
	[x2,y2,z2] = GroundVerts[1].co

Can you please explain why ?

also

Erm… probably because I don’t use a whole lot of tri-meshes and didn’t notice the discrepancy. Thanks for pointing that out. I’ll change them to both use world coords.

Hello Roland

I am still working on my program that is modelled after yours.
It is a little difficult, as although I have programmed before I am completely new to Blender.

As it seemed I was having problems with tri faces. I rewrote the code to find if a point was inside or outside a face for both tri and quad faces. I got that to work. However now it seems that the code you have for determining the Z may be incorrect for tri faces (I am not sure).
I have spent a lot of time debugging and looking for an algorithm on math forums on how to calculate a point on a face. No luck, so I thought I should go to the source and see if you can help.

I’ll look at my code. It’s been a while since I’ve delved into it. One thing to think about, though, is that my code is optimized for the special case of moving in the Z direction given x and y coords. If you’re trying for full 3D motion, the math will be more complex.

Also, if you look at the code to check if a point is inside a quad, it is really just two calls to the tri-check function, once for each tri in the quad.

My house guests are leaving tonight, so I’ll look into the code tomorrow.