I have come up with a kludge (not a proper fix) for the lack of
smoothing in AC3D models in PLIB.  The AC3D loader is the only one
that actually uses ssgStripify; I believe that's the wrong place to
calculate normals, because you've already lost the information in the
AC3D file about what surfaces should be smoothed what what vertices
are actually shared (rather than just coincident).  Still, for now,
I've just kludged a short loop into makeNormals in ssgOptimiser.cxx so
that all vertices with the same location get treated as identical (and
all are smoothed).

Here is a before picture of the DC-3 model in FlightGear:

  http://www.megginson.com/flightsim/dc3-unsmoothed.png

Here is a shot from after my patch was applied:

  http://www.megginson.com/flightsim/dc3-smoothed.png

Since the patch is tiny, I'm attaching it to this message.  It is also
available online at

  http://www.megginson.com/flightsim/plib-smoothing.dif

A proper solution to this problem will involve modifying the AC3D
loader, probably to avoid ssgStripify (since it blows away the
normals) and to take advantage of the information that's in the AC3D
file, like the other loaders do for their formats.  In the meantime,
FlightGear users (and others) can apply this patch to their recent CVS
plib source trees and get smoothed AC3D models again.

Here's the patch:

--- ../plib.SAFE/src/ssg/ssgOptimiser.cxx       Fri Mar 29 14:16:58 2002
+++ src/ssg/ssgOptimiser.cxx    Fri Mar 29 14:21:48 2002
@@ -303,16 +303,22 @@
   for ( i = 0 ; i < tnum ; i++ )
   {
     sgVec3 tmp ;
+    short j ;
     
     sgMakeNormal ( tmp, vlist [ tlist [ i*3+ 0 ] ] -> vertex,
       vlist [ tlist [ i*3+ 1 ] ] -> vertex,
       vlist [ tlist [ i*3+ 2 ] ] -> vertex ) ;
-    
-    sgAddVec3 ( vlist [ tlist [ i*3+ 0 ] ] -> normal, tmp ) ;
-    sgAddVec3 ( vlist [ tlist [ i*3+ 1 ] ] -> normal, tmp ) ;
-    sgAddVec3 ( vlist [ tlist [ i*3+ 2 ] ] -> normal, tmp ) ;
+
+    for ( j = 0; j < vnum; j++ ) {
+      if (sgEqualVec3(vlist[j]->vertex, vlist[tlist[i*3+0]]->vertex))
+       sgAddVec3(vlist[j]->normal, tmp);
+      if (sgEqualVec3(vlist[j]->vertex, vlist[tlist[i*3+1]]->vertex))
+       sgAddVec3(vlist[j]->normal, tmp);
+      if (sgEqualVec3(vlist[j]->vertex, vlist[tlist[i*3+2]]->vertex))
+       sgAddVec3(vlist[j]->normal, tmp);
+    }
   }
-  
+
   for ( i = 0 ; i < vnum ; i++ )
     if ( sgScalarProductVec2 ( vlist[i]->normal, vlist[i]->normal ) < 0.001 )
       sgSetVec3 ( vlist[i]->normal, 0.0f, 0.0f, 1.0f ) ;


  
All the best,


David

-- 
David Megginson
[EMAIL PROTECTED]


_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to