Revision: 58950
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58950
Author:   campbellbarton
Date:     2013-08-06 02:16:29 +0000 (Tue, 06 Aug 2013)
Log Message:
-----------
fix [#36363] ray_cast face index with n_gons

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_object_api.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_object_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object_api.c       
2013-08-06 02:05:32 UTC (rev 58949)
+++ trunk/blender/source/blender/makesrna/intern/rna_object_api.c       
2013-08-06 02:16:29 UTC (rev 58950)
@@ -259,6 +259,21 @@
 }
 #endif
 
+/* don't call inside a loop */
+static int dm_tessface_to_poly_index(DerivedMesh *dm, int tessface_index)
+{
+       if (tessface_index != ORIGINDEX_NONE) {
+               /* double lookup */
+               const int *index_mf_to_mpoly;
+               if ((index_mf_to_mpoly = dm->getTessFaceDataArray(dm, 
CD_ORIGINDEX))) {
+                       const int *index_mp_to_orig = dm->getPolyDataArray(dm, 
CD_ORIGINDEX);
+                       return DM_origindex_mface_mpoly(index_mf_to_mpoly, 
index_mp_to_orig, tessface_index);
+               }
+       }
+
+       return ORIGINDEX_NONE;
+}
+
 /* BMESH_TODO, return polygon index, not tessface */
 static void rna_Object_ray_cast(Object *ob, ReportList *reports, float 
ray_start[3], float ray_end[3],
                                 float r_location[3], float r_normal[3], int 
*index)
@@ -291,7 +306,7 @@
                        if (hit.dist <= dist) {
                                copy_v3_v3(r_location, hit.co);
                                copy_v3_v3(r_normal, hit.no);
-                               *index = hit.index;
+                               *index = 
dm_tessface_to_poly_index(ob->derivedFinal, hit.index);
                                return;
                        }
                }
@@ -330,7 +345,7 @@
                if (BLI_bvhtree_find_nearest(treeData.tree, point_co, &nearest, 
treeData.nearest_callback, &treeData) != -1) {
                        copy_v3_v3(n_location, nearest.co);
                        copy_v3_v3(n_normal, nearest.no);
-                       *index = nearest.index;
+                       *index = dm_tessface_to_poly_index(ob->derivedFinal, 
nearest.index);
                        return;
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to