# some kind of dynamic and localized subdivision surface modifier - type algorithm?

In a previous, excellent answer it was proposed that it might be helpful to subdivide some triangles in my mesh at certain times during the animation to prevent them from overlapping adjacent faces when the mesh is very highly distorted. It's best to look at the question and answer there now.

OK you're back. The trajectory of the ~10,000 vertices of the original icosphere mesh are pre-calculated and stored in a NumPy array. A "badness" detector could search for highly stretched edges, but then what? If it inserted real vertices, I think it might be tricky to try to remove them later, and keep the rest lined up with NumPy. I could try to figure out a way to script that, but I wonder if there might be other ways, or possibly something existing in Blender already?

I am re-linking @TLousky 's image here:

• you warp this mesh so much that the points that where previously beside each-other are no longer neighbours, so while the topology is still valid.. it produces that wacky result. I think you might investigate how to triangulate this mesh using something like: n-e-r-v-o-u-s.com/blog/?p=3093 "Ball-Pivot algorithm" Commented Sep 6, 2015 at 14:30
• That's a good point @zeffii , and link. The original task (section 8.1 here ) is supposed to be challenging to visualize, and it sure is. Ultimately need to keep the icosphere's original vertices in their correct place, but adding vertices is fine. I think Blender is incredibly useful and flexible, and can do just about anything, so long as StackExchange is here too! :)
– uhoh
Commented Sep 7, 2015 at 3:35
• These videos are not exactly what we're talking about here @zeffii but roughly this kind of thing.
– uhoh
Commented Sep 7, 2015 at 4:16
• It seems the paper suggests to do the deformation first, then make a heat map of the faces relative deformation (edge, surface area), then on a fresh icoshphere apply a new subdivision with relative weights according to the heat map produced, then deform that one. might be possible. see blender.stackexchange.com/questions/29106/tesselate-a-plane Commented Sep 7, 2015 at 7:18
• "decimation" .. not subdivision. Commented Sep 7, 2015 at 7:36

Well, as I originally suggested in the previous question, you can always try using the Remesh modifier. It dynamically generates a clean mesh with ~equal size quads out of the volume of your mesh.

I'd recommend using the smooth mode and an octtree depth of 7 or more to get accurate reconstruction of your mesh.

ADDED: It also helps to add a smooth modifier on top of the remesh modifier, because the mesh generated by the remesh modifier is still a but funky due to the issues with the original mesh.

myObject.select = True # Replace myObject with a reference to your actual mesh object
bpy.context.scene.objects.active = myObject

m = bpy.context.object.modifiers['Remesh']
m.mode         = 'SMOOTH'
m.octree_depth = 7

m = bpy.context.object.modifiers['Smooth']
m.iterations = 26


It's not exactly what you asked for, but might do the job nontheless.

ADDED: You only need to add this modifier once, of course (it will adapt to changes in your mesh), but it will slow down your script considerably, since the remesh modifier takes quite a bit of time to calculate, especially in the higher octtree_depth levels.

• This is interesting! I'm putting it just before the i_frame loop near line 100, but so far I get an error about context (I'm just using one of the two objects) I'll check to see if it works with the key_blocking or one of the other keyfaming methods in the three answers to this question. stay tuned.....
– uhoh
Commented Sep 6, 2015 at 13:03
• Generally, the modifier add operator (bpy.ops.object.modifier_add), like many other object operators, needs an active object to work. Make sure to select and set one of your objects as active before running this code, and it will solve your context issue. To select use: myObject.select = True To activate use: bpy.context.scene.objects.active = myObject (with myObject being a general name for which you'll replace with your actual object reference, of course) Commented Sep 6, 2015 at 15:35
• OK a comment is no place to put code samples, so I just updated the code block above to include the required amendment (just make sure to actually use your own object there) Commented Sep 6, 2015 at 15:39
• Thanks! It's not 100% perfect yet, but it is a great start. It looks like I now have three parameters to play with, initial icosphere subdivisions, octree depth, and smooth iterations. Thank you @TLousky for taking the time to dig in to the script.
– uhoh
Commented Sep 7, 2015 at 3:28