3
$\begingroup$

I am using blender to triangulate a mesh that I want to use for a physics simulation (outside blender). For that, I want to randomly remesh it. The triangulate modifier is not enough, as there is a preferent edge direction, which I want to avoid. enter image description here

Ideally, adding random vertices inside the quad and force a remeshing algorithm to use this points would work, but I have no idea how to do it or if it is even possible in blender.

$\endgroup$
5
$\begingroup$
  1. Create a new shapekey for your plane. Enter edit mode on that shapekey.

  2. Use transform->randomize operation.

  3. Use a triangulate faces operation. In operator panel, specify "shortest diagonal."

  4. Leave edit mode and delete your shapekey.

$\endgroup$
2
  • $\begingroup$ I forgot to mention that the boundary needs to be the same (can be refined, but I still need to have a square) $\endgroup$
    – jjcasmar
    Jan 26 '21 at 20:13
  • 1
    $\begingroup$ @jjcasmar the boundary will be the same. The reason you're using a shapekey is so that your randomization won't affect the original shape. You're using it only to randomize what the shortest diagonal for each quad is. $\endgroup$
    – Nathan
    Jan 26 '21 at 21:01
5
$\begingroup$

bmesh Script.

enter image description here

Runs thru every quad in the mesh and makes it into two triangles via a random choice of making edge connecting either face verts 0 to 2, or 1 to 3.

Test script. Randomly triangulates the active object in OBJECT mode.

import bpy
import bmesh
from random import choice

context = bpy.context

ob = context.object
me = ob.data
bm = bmesh.new()
bm.from_mesh(me)

quads = [f for f in bm.faces if len(f.verts) == 4]

for q in quads:
    i = choice(range(2))
    bmesh.ops.connect_verts(
            bm,
            verts=[q.verts[i], q.verts[i + 2]],
            )

bm.to_mesh(me)
$\endgroup$
2
  • 1
    $\begingroup$ How long have you been using Python? And how long did it take you to learn it? $\endgroup$ Mar 13 '21 at 19:34
  • $\begingroup$ Since circa the mid naughties. Had coded in other languages, bit like a musical instrument, once you learn one you pick up another reasonably quickly. Still learning tho. Ironically I'm not sure how much sites like this help. Had to nut things out in the old days. $\endgroup$
    – batFINGER
    Mar 13 '21 at 19:41

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.