<a href="http://pasteall.org/3494/diff">http://pasteall.org/3494/diff</a><br><br>This is part of the code developed during GSoC 2008,<br><div class="gmail_quote"><br>Shrinkwrap was imported to trunk in parts, first only BVHTree,<br>
then Shrinkwrap Modifier, then SimpleDeform modifier and now Shrinkwrap Constraint!<br><br>The other GSoC code merged nicely and without any modifications on remaining code,<br>
thought the case is slightly different with this constraint:<br><br>Constraints suffer an evaluation (_get_tarmat) every time the interface is draw,<br>this might be OK for simple constraints, but shrinkwrap needs to build a BVHTree of a target mesh.<br>

And its just not possible to build a BVH tree every interface draw, since it just slow.<br>The work arround was to create a BVH cache.<br><br>The cache was chosen to be implemented at DerivedMesh level (since vertex and face data is on there),<br>

Each object&#39;s derived mesh is already destroyed and rebuild each time the vertex and face data changes,<br>so there is no need for additional control mechanisms.<br><br>Using BVHTree cache is very simple..<br>A BVHTree is build using bvhtree_from_mesh_tri/faces (as it was already done before) and its freed when the respective DerivedMesh is released.<br>

<br> Other code that builds BVH&#39;s from DerivedMesh can also benefit with this cache (being that another of the reasons to implement cache at derivedmesh level)<br>(example is for example having 1000 shrinkwrap constraints applied with the same target).<br>

<br>Its implementation was also very simple:<br>An attribute &quot;BVHCache&quot; was added to the DerivedMesh struct (source/blender/blenkernel/BKE_DerivedMesh.h)<br>And calls to bvhcache_init/free were added on DerivedMesh creation and release (source/blender/blenkernel/intern/DerivedMesh.c)<br>

<br><br>There are the files that are modified by the patch:<br>source/blender/blenkernel/BKE_shrinkwrap.h<br>source/blender/blenkernel/intern/shrinkwrap.c<br>source/blender/blenkernel/BKE_bvhutils.h<br>source/blender/blenkernel/intern/bvhutils.c<br>

&nbsp;Shrinkwrap and BVH code<br><br><br>source/blender/blenkernel/intern/constraint.c<br>source/blender/makesdna/DNA_constraint_types.h<br>source/blender/src/buttons_object.c<br>source/blender/blenloader/intern/readfile.c<br>

&nbsp; Shrinkwrap constraint code<br><br>source/blender/blenkernel/intern/DerivedMesh.c<br>source/blender/blenkernel/BKE_DerivedMesh.h<br>&nbsp; Link of BVHCache and DerivedMesh<br><br><br><br>
If everything is alright..and Aligorith positively reviews the patch I will commit it to trunk.<br>Besides vacations are coming, so I will have time if any problems show up :)<br><br>---<br>AndrĂ© Susano Pinto (jaguarandi)<br>


<br>
<br>
</div><br>