I tried to use the script to drop some objects to a BWF-made mesh but it didn’t work. Does anyone know why?
#!BPY """ Registration info for Blender menus: Name: 'Drop To Ground' Blender: 233 Group: 'Misc' Tooltip: 'Drop objects from current selection on mesh object *Ground*' """ import Blender from Blender import NMesh, Object, Draw from math import * def sideofline(PA, PB, PP): return ((PA-PP)*(PB-PP))-((PB-PP)*(PA-PP)) def InsideQuad(p0, p1, p2, p3, p4): if (sideofline(p1, p3, p0) >= 0): return (sideofline(p1, p4, p0) <= 0) and (sideofline(p4, p3, p0) <= 0) else: return (sideofline(p1, p2, p0) >= 0) and (sideofline(p2, p3, p0) >= 0) def InsideTri(p0, p1, p2, p3): return (sideofline(p1, p2, p0) >= 0) and (sideofline(p2, p3, p0) >= 0) and (sideofline(p3, p1, p0) >= 0) def FindZ(TriangleFace, tx, ty, tz, px, py): [A, B, C]=TriangleFace.no D=-((A*tx)+(B*ty)+(C*tz)) return -((A*px)+(B*py)+D)/C def InverseTranslate(InCoords, DeltaVec): return [InCoords+DeltaVec, InCoords+DeltaVec, InCoords+DeltaVec] try: FloatingObjects = Object.GetSelected() Ground = Object.Get('Ground') GroundMesh = NMesh.GetRawFromObject('Ground') InvVec = Ground.getLocation() GroundBounds = Ground.getBoundBox() GBminX = 0 GBminY = 0 GBmaxX = 0 GBmaxY = 0 name = "OK? %t|drop objects %x1|cancel %x0" result = Draw.PupMenu(name) if result == 1: for [gbx, gby, gbz] in GroundBounds: gbx = gbx + InvVec gby = gby + InvVec gbz = gbz + InvVec if GBminX > gbx: GBminX = gbx else: if GBmaxX < gbx: GBmaxX = gbx if GBminY > gby: GBminY = gby else: if GBmaxY < gby: GBmaxY = gby for DropObject in FloatingObjects: [DropX, DropY, DropZ] = DropObject.getLocation() if ((DropX <= GBmaxX) and (DropX >= GBminX) and (DropY >= GBminY) and (DropY <= GBmaxY)): GroundFaces = GroundMesh.faces for GroundFace in GroundFaces: GroundVerts = GroundFace.v if len(GroundVerts) == 4: [x1, y1, z1] = InverseTranslate(GroundVerts.co, InvVec) [x2, y2, z2] = InverseTranslate(GroundVerts.co, InvVec) [x3, y3, z3] = InverseTranslate(GroundVerts.co, InvVec) [x4, y4, z4] = InverseTranslate(GroundVerts.co, InvVec) p0 = [DropX, DropY, 0] p1 = [x1, y1, 0] p2 = [x2, y2, 0] p3 = [x3, y3, 0] p4 = [x4, y4, 0] if InsideQuad(p0, p1, p2, p3, p4): print 'Moved ', DropObject, ' to a Quad face.' DropObject.setLocation(DropX, DropY, FindZ(GroundFace, x1, y1, z1, DropX, DropY)) else: [x1, y1, z1] = GroundVerts.co [x2, y2, z2] = GroundVerts.co [x3, y3, z3] = GroundVerts.co p0 = [DropX, DropY, 0] p1 = [x1, y1, 0] p2 = [x2, y2, 0] p3 = [x3, y3, 0] if InsideTri(p0, p1, p2, p3): print 'Moved ', DropObject, ' to a Tri face.' DropObject.setLocation(DropX, DropY, FindZ(GroundFace, x1, y1, z1, DropX, DropY)) except: name = "No Ground object in Scene %t|cancel" result = Draw.PupMenu(name) if result: pass Blender.Redraw()
i’ve edited this script to work here fine, but … you never know
however i ain’t the author and i forgot who that noble person was …
aw forgot … the ground object has to be named * Ground * for script ot work as expected
Thanks for writing that error checking code. I hate doing that stuff!
I have tried your rewrite, but it still doesn’t work. I had name the mesh “Ground” too.
ja, known thing - you’ll have to manually unwrap the lines that forum wrapped (some code should be on one line only) - or else I can optionally send you the*.py thing via email.
Ground should have normals pointing outwards
btw - you had selected all to-drop objects?
I tried what you suggested on the normals thing and it works. It seemed the mesh had normals pointing downwards.
sparrow, nice you’ve got it doing what it’s supposed to do
@ harkyman - you are the author?
Yes. Glad people are using it.
harkyman, blender people project looks deadly serious. any chance of a lite version that wouldn’t require mysql?
i have cca 45 py things which i have either edited/upg’ded or just cleaned up comments etc. so i’ve lost track of respective authors.
for some reason ever since 2.3 i think when you add a grid the normals are pointing down. kind of confusing the first couple of times. also don’t forget to do ‘ctrl A’ on all objects.