2
$\begingroup$

I'm looking for a Script or Add-on for Blender 2.79 that creates verts and a lines where two objects intersect.

Practical example:

I need loops where the mountains intersect with the grass and where the grass intersects with the water for many purposes:

  • Hitboxes around everything preventing player from leaving level (Extrude loops upward)
  • AI boundaries where Ranged AI should not walk (Water)
  • AI boundaries where Melee AI should not walk into / see player
  • Boundaries for generating Vegetation using the Particle System

Image below is a part of the scene.

Some people recommended boolean and knife tools. It doesn't work out of the box, but I figured out a way and put it in a seperate answer below.

enter image description here

$\endgroup$
6
  • $\begingroup$ This is very similar to other question. $\endgroup$
    – batFINGER
    Jan 28 '20 at 14:49
  • $\begingroup$ welder addon seems to work only for 2.8x. I didn't learn python or scripting for blender. Can't anyone just test/repair the existing script? $\endgroup$
    – AzulShiva
    Jan 30 '20 at 22:14
  • $\begingroup$ @vklidu Seriously the other answer has 31 upvotes and I used to work with the script. Why doesn't it work anymore? What's going on? $\endgroup$
    – AzulShiva
    Jan 30 '20 at 22:23
  • $\begingroup$ @vklidu I tried learning a bit of python and analyzing the script and yeah you're spot on. I just realised myself it's the wrong script. No idea where the right script went, I've looked online, my harddisk, back-ups, everywhere. Either I'll get lucky with the bounty here or I have to script this thing myself :\ $\endgroup$
    – AzulShiva
    Jan 31 '20 at 8:40
  • $\begingroup$ @vklidu This question is an absolute mess already. Right now it's literally: "I've lost my script guys pls give me a new one" $\endgroup$
    – AzulShiva
    Jan 31 '20 at 8:44
4
+100
$\begingroup$

Script of Witold Jaworski generates intersection of two selected meshes.

  • Select two objects
  • Press W (in 2.79), for 2.8x search Intersection
  • Press P (Separate) > Selected

enter image description here enter image description here enter image description here

For more detailed instructions visit his site.

For future broken links – blend with script for version 2.79

For complex mesh like terrain is better select roughly vertices in intersected area to get script calcutlat faster, and I did quick cleaning of result (not perfect):

  • in Edit mode select one of the longer edge than ussual
  • search SimilarLenght > Greater, Delete X
  • than Select all and Search Remove Doubles (in 2.8x Merge by Distance)

(In tool properties you can increase minimum distance limit, it depence on how precise final intersection has to be. Higher value clean it better but in cost of preciseness (detail). Three gaps I had to connect manually. Pink line is the intersection object, converted into curve just to be visible in the image better.)

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks this is precisely what I am looking for. However I will leave the bounty open as there are some issues with it: 1) It's extremely slow (However it is possible to calculate the speed: Roughly 2 seconds for 1024x1024, 8 seconds for 2048x2048, 100 seconds for 50k x 1024, time will increase if the two objects's tri count deviates drastically) 2) Only works accurately with tris, so Ctr+T the mesh before Intersecting 3) It creates gaps and holes if two intersecting vertices are on the same spot. It can intersect two lines or two faces but not two verts. $\endgroup$
    – AzulShiva
    Jan 31 '20 at 13:37
  • 1
    $\begingroup$ If you preselect vertices in area of intersection, calculation is much faster. See blend. $\endgroup$
    – vklidu
    Jan 31 '20 at 13:53
  • $\begingroup$ If noone posts a better script the bounty goes to you. Thanks a lot. I also managed to get it working using standard boolean modifier, see my answer below. $\endgroup$
    – AzulShiva
    Jan 31 '20 at 18:02
6
$\begingroup$

Bmesh bisect plane.

Here is a script that bisects one mesh with a plane and creates a new mesh object with the intersecting edges.

enter image description here

In test example

  • Grid is a 100 x 100 grid displaced with a cloud texture via a modifier (not applied).
  • Plane is a single face default plane, named "Plane".
  • Move plane to desired location and run script.

  • New object "Bisect" has the edges of the bisection only.

enter image description here Still of result, since I hit stop on gif to quickly

2.8 version

import bpy
import bmesh

context = bpy.context
dg = context.evaluated_depsgraph_get()
scene = context.scene 
ob = context.object
plane = scene.objects.get("Plane")

if plane and ob:
    pmw = plane.matrix_world
    face = plane.data.polygons[0]
    plane_co = pmw @ face.center
    plane_no = pmw @ (face.center + face.normal) - plane_co 
    bm = bmesh.new()
    bm.from_object(ob, dg)
    bmesh.ops.transform(bm,
            verts=bm.verts,
            matrix=ob.matrix_world)

    x = bmesh.ops.bisect_plane(bm,
            geom=bm.faces[:] + bm.edges[:] + bm.verts[:],
            clear_inner=True,
            clear_outer=True,
            plane_co=plane_co,
            plane_no=plane_no,
            )
    # new object
    me = bpy.data.meshes.new("Bisect")
    bm.to_mesh(me)
    ob = bpy.data.objects.new("Bisect", me)
    context.collection.objects.link(ob)

2.7x version

enter image description here Result of running in 2.79 on modified grid, using a one face plane object named "Plane"

import bpy
import bmesh

context = bpy.context

scene = context.scene 
ob = context.object
plane = scene.objects.get("Plane")

if plane and ob:
    pmw = plane.matrix_world
    plane_co = pmw.translation
    face = plane.data.polygons[0]
    plane_no = pmw * (face.center + face.normal) - pmw * face.center 
    bm = bmesh.new()
    bm.from_object(ob, scene)
    bmesh.ops.transform(bm, verts=bm.verts, matrix=ob.matrix_world)
    x = bmesh.ops.bisect_plane(bm,
            geom=bm.faces[:] + bm.edges[:] + bm.verts[:],
            clear_inner=True,
            clear_outer=True,
            plane_co=plane_co,
            plane_no=plane_no,
            )
    # new object
    me = bpy.data.meshes.new("Bisect")
    bm.to_mesh(me)
    ob = bpy.data.objects.new("Bisect", me)
    scene.objects.link(ob)
$\endgroup$
9
  • $\begingroup$ I get "Python script fail, look in the console for now..." Can you give precise info on which object to select? I'm using 2.79 $\endgroup$
    – AzulShiva
    Jan 28 '20 at 16:31
  • $\begingroup$ Traceback (most recent call last): File "C:\Users\AzulShiva\Documents\Unity\Blender Files\blend_Levels\Level6.2_Terrain.blend_Intersect.txt", line 5, in <module> AttributeError: 'Context' object has no attribute 'evaluated_depsgraph_get' Error: Python script fail, look in the console for now... $\endgroup$
    – AzulShiva
    Jan 28 '20 at 16:33
  • $\begingroup$ Clearly was for 2.8. See edit for 2.7x $\endgroup$
    – batFINGER
    Jan 28 '20 at 16:38
  • $\begingroup$ No error message this time, the script did something. Not what I wanted though: bilder-upload.eu/upload/00c1a2-1580229796.jpg $\endgroup$
    – AzulShiva
    Jan 28 '20 at 16:43
  • 1
    $\begingroup$ @AzulShiva might have issue with transform space, will fix later it's late. $\endgroup$
    – batFINGER
    Jan 28 '20 at 17:09
0
$\begingroup$

Just a reminder of Bisect tool in Blender 2.8x (as native tool) that can do similar kind of job (cut by plane).

  • Duplicate your object
  • Search Bisect
  • Enable Clear Inner and Clear Outer in tool properties in left-down corner
  • Adjust cut position (can be set numerically in properties too)

Done

enter image description here For horizontal cut set Plane Normal values to 0/0/1 and move only Z axis of Plane Point parametr.

enter image description here

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks but I don't need to cut by plane, I need to intersect two objects with each other. And I'm using 2.79 $\endgroup$
    – AzulShiva
    Jan 30 '20 at 21:38
  • $\begingroup$ Sorry my fault, batFinger's script also works as a plane cut so I felt in mistake you are OK with that kind since I thought water surface is cutter. BTW 2.79 has the same tool I see. $\endgroup$
    – vklidu
    Jan 30 '20 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.