[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26586] trunk/blender/source/blender/ blenlib/intern/math_geom.c: avoid nan tangents which happen with cubes that have generated UVs
Campbell Barton
ideasman42 at gmail.com
Wed Feb 3 20:16:18 CET 2010
Revision: 26586
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26586
Author: campbellbarton
Date: 2010-02-03 20:16:18 +0100 (Wed, 03 Feb 2010)
Log Message:
-----------
avoid nan tangents which happen with cubes that have generated UVs
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/math_geom.c
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2010-02-03 17:48:39 UTC (rev 26585)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2010-02-03 19:16:18 UTC (rev 26586)
@@ -1848,28 +1848,33 @@
void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2, float *co3, float *n, float *tang)
{
- float tangv[3], ct[3], e1[3], e2[3], s1, t1, s2, t2, det;
+ float s1= uv2[0] - uv1[0];
+ float s2= uv3[0] - uv1[0];
+ float t1= uv2[1] - uv1[1];
+ float t2= uv3[1] - uv1[1];
- s1= uv2[0] - uv1[0];
- s2= uv3[0] - uv1[0];
- t1= uv2[1] - uv1[1];
- t2= uv3[1] - uv1[1];
- det= 1.0f / (s1 * t2 - s2 * t1);
+ if(s1 && s2 && t1 && t2) { /* otherwise 'tang' becomes nan */
+ float tangv[3], ct[3], e1[3], e2[3], det;
+ det= 1.0f / (s1 * t2 - s2 * t1);
+
+ /* normals in render are inversed... */
+ sub_v3_v3v3(e1, co1, co2);
+ sub_v3_v3v3(e2, co1, co3);
+ tang[0] = (t2*e1[0] - t1*e2[0])*det;
+ tang[1] = (t2*e1[1] - t1*e2[1])*det;
+ tang[2] = (t2*e1[2] - t1*e2[2])*det;
+ tangv[0] = (s1*e2[0] - s2*e1[0])*det;
+ tangv[1] = (s1*e2[1] - s2*e1[1])*det;
+ tangv[2] = (s1*e2[2] - s2*e1[2])*det;
+ cross_v3_v3v3(ct, tang, tangv);
- /* normals in render are inversed... */
- sub_v3_v3v3(e1, co1, co2);
- sub_v3_v3v3(e2, co1, co3);
- tang[0] = (t2*e1[0] - t1*e2[0])*det;
- tang[1] = (t2*e1[1] - t1*e2[1])*det;
- tang[2] = (t2*e1[2] - t1*e2[2])*det;
- tangv[0] = (s1*e2[0] - s2*e1[0])*det;
- tangv[1] = (s1*e2[1] - s2*e1[1])*det;
- tangv[2] = (s1*e2[2] - s2*e1[2])*det;
- cross_v3_v3v3(ct, tang, tangv);
-
- /* check flip */
- if ((ct[0]*n[0] + ct[1]*n[1] + ct[2]*n[2]) < 0.0f)
- negate_v3(tang);
+ /* check flip */
+ if ((ct[0]*n[0] + ct[1]*n[1] + ct[2]*n[2]) < 0.0f)
+ negate_v3(tang);
+ }
+ else {
+ tang[0]= tang[1]= tang[0]= 0.0;
+ }
}
/********************************************************/
More information about the Bf-blender-cvs
mailing list