Hello Olivier,

Olivier Tournaire wrote:
2009/3/6 Dirk Reiners <[email protected] <mailto:[email protected]>>

    Marcus Lindblom wrote:
     >
     > Not automatically, AFAIK. If your gemoetry is discrete triangles,
    just
     > swap two indices in each. If it's tristips/fans, it might be
    trickier,

    Or, if you only care about lighting and not culling you can just
    invert the
    elements of the NormalProperty. Yeah, it's ugly, but it's quick. ;)


This is exactly what I want ! How can I do that ?

attached is a patch that adds a flipNormals function. It compiles for me, but it's untested, so if you like I'd appreciate if you could give it a try and let me know if it works.

        Cheers,
                Carsten
Index: Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoFunctions.h
===================================================================
--- Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoFunctions.h	(revision 1799)
+++ Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoFunctions.h	(working copy)
@@ -57,6 +57,10 @@
 OSG_DRAWABLE_DLLMAPPING 
 void    calcFaceNormals          (Geometry   *geo        );
 
+OSG_DRAWABLE_DLLMAPPING
+void    flipNormals              (Geometry   *geo,
+                                  UInt16      normProp = Geometry::NormalsIndex);
+
 OSG_DRAWABLE_DLLMAPPING 
 void    calcVertexTangentsProp   (Geometry   *geo,
                                   UInt32      srcTexProp,
Index: Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoFunctions.cpp
===================================================================
--- Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoFunctions.cpp	(revision 1799)
+++ Source/System/NodeCores/Drawables/Geometry/Util/OSGGeoFunctions.cpp	(working copy)
@@ -524,7 +524,29 @@
     FFATAL(("calcFaceNormals:: NYI!\n"));
 }
 
+/*! Inverts all normals (but does not change face orientation) of \a geo.
+    The second parameter \a normProp selects which property of \a geo holds
+    the normals.
+ */
+void flipNormals(Geometry *geo, UInt16 normProp)
+{
+    GeoVectorProperty *normP = geo->getProperty(normProp);
+    
+    if(normP == NULL)
+    {
+        FWARNING(("flipNormals: No normals in property [%u].\n", normProp));
+        return;
+    }
 
+    UInt32 normCount = normP->size();
+    
+    for(UInt32 i = 0; i < normCount; ++i)
+    {
+        normP->setValue(- normP->getValue<Vec4d>(i), i);
+    }
+}
+
+
 void calcVertexTangentsProp(Geometry *geo,
                             UInt32    srcTexProp,
                             UInt32    srcNormalProp,
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to