oops, diff'ing after a commit does not produce an interesting patch.
Attached one that is not empty ;)

        Sorry about that,
                Carsten

On Tue, 2007-08-28 at 10:22 -0500, Carsten Neumann wrote:
>       Hi Johan,
>       
> On Mon, 2007-08-27 at 17:12 +0200, Johan Robben wrote:
> > >> in general the loader sets the name on everything it can.
> > >> However, MaterialChunks are Attachments and those can not have
> > attachments themselves. Therefore the VRML loader can not add a name
> > attachment to the MaterialChunk.
> > >> If you are in control of the VRML files you load (and therefore know
> > their contents), you might get around this by looking for the Appearance's
> > name instead.
> > 
> > >> Hope it helps,
> > It definitely helps to understand OpenSG.
> > 
> > Is there a way to modify the VRML loader to put the name of the
> > MaterialChunk on the MaterialGroup ? (I am not in control of the VRML files)
> 
> sort of ;) The attached patch adds an option to the loader (use
> SceneFileHandler::the()->setOptions("pushNames=true") to enable it),
> that puts the name of a VRML Material (OpenSG MaterialChunk) on the VRML
> Appearance (OpenSG ChunkMaterial) unless that has a name of its own.
> The patch itself is a horrible hack, but the only way Dirk and I could
> come up with that did not involve even greater surgery ;)
> 
>       Hope it helps,
>               Carsten
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________ Opensg-users mailing list 
> [email protected] 
> https://lists.sourceforge.net/lists/listinfo/opensg-users
Index: Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.cpp	29 Aug 2006 10:58:35 -0000	1.17
+++ Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.cpp	28 Aug 2007 15:15:07 -0000	1.18
@@ -68,7 +68,8 @@
     _szReferenceHeader(NULL  ),
     _pLexer           (new OSGScanParseLexer),
     _image            (NullFC),
-    _imageDataPtr     (0     )
+    _imageDataPtr     (0     ),
+    _options          (0     )
 {
 }
 
@@ -526,6 +527,27 @@
 }
 
 /*-------------------------------------------------------------------------*/
+/*                              Options                                    */
+
+void
+ScanParseSkel::addOptions(UInt32 options)
+{
+    _options |= options;
+}
+
+void
+ScanParseSkel::subOptions(UInt32 options)
+{
+    _options &= ~options;
+}
+
+UInt32
+ScanParseSkel::getOptions(void) const
+{
+    return _options;
+}
+
+/*-------------------------------------------------------------------------*/
 /*                               Set                                       */
 
 void ScanParseSkel::reset(void)
Index: Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.h
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.h	29 Aug 2006 10:58:35 -0000	1.17
+++ Source/System/FileIO/ScanParseSkel/OSGScanParseSkel.h	28 Aug 2007 15:15:07 -0000	1.18
@@ -352,6 +352,15 @@
     OSGScanParseLexer *getLexer(void);
 
     /*! \}                                                                 */
+    /*---------------------------------------------------------------------*/
+    /*! \name                     Options                                  */
+    /*! \{                                                                 */
+    
+    void   addOptions(UInt32 options);
+    void   subOptions(UInt32 options);
+    UInt32 getOptions(void          ) const;
+    
+    /*! \}                                                                 */
     /*=========================  PROTECTED  ===============================*/
   protected:
 
@@ -391,9 +400,9 @@
 
     void endImage();
 
-    ImagePtr _image;
-
-    UInt8 *_imageDataPtr;
+    ImagePtr  _image;
+    UInt8    *_imageDataPtr;
+    UInt32    _options;
 };
 
 //---------------------------------------------------------------------------
Index: Source/System/FileIO/WRL/OSGVRMLFile.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/WRL/OSGVRMLFile.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Source/System/FileIO/WRL/OSGVRMLFile.cpp	26 Jun 2007 16:21:28 -0000	1.21
+++ Source/System/FileIO/WRL/OSGVRMLFile.cpp	28 Aug 2007 15:15:08 -0000	1.22
@@ -86,6 +86,16 @@
 /*! \class osg::VRMLFile
  */
 
+/*! \var osg::VRMLFile::PushNames
+    Option to push the name attachments for entities that can not have a
+    NameAttachment in OpenSG to their respective parent.
+    
+    This is currently only implemented for MaterialChunks and only sets the
+    name on the containing ChunkMaterial if that does not have a name of its
+    own.
+ */
+ 
+ 
 #ifndef __sgi
 template OSG_SYSTEMLIB_DLLMAPPING
 class ScanParseFieldTypeMapper<ScanParseSkel>;
@@ -239,7 +249,7 @@
     if(szNodename != NULL)
     {
         if(pNewNode != NullFC)
-        {
+        {        
             if(pNewNode->getType().isNode() == true)
             {
 #ifdef OSG_DEBUG_VRML
Index: Source/System/FileIO/WRL/OSGVRMLFile.h
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/WRL/OSGVRMLFile.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Source/System/FileIO/WRL/OSGVRMLFile.h	5 Feb 2006 18:16:12 -0000	1.10
+++ Source/System/FileIO/WRL/OSGVRMLFile.h	28 Aug 2007 15:15:08 -0000	1.11
@@ -105,8 +105,9 @@
         StripeGeometry      = CreateNormals         << 1,
         LogProtoGeneration  = StripeGeometry        << 1,
         LogObjectGeneration = LogProtoGeneration    << 1,
-
-        LastOption          = LogObjectGeneration
+        PushNames           = LogObjectGeneration   << 1,
+        
+        LastOption          = PushNames
     };
 
     /*---------------------------------------------------------------------*/
Index: Source/System/FileIO/WRL/OSGVRMLNodeDescs.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/WRL/OSGVRMLNodeDescs.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- Source/System/FileIO/WRL/OSGVRMLNodeDescs.cpp	24 Jan 2007 12:55:26 -0000	1.38
+++ Source/System/FileIO/WRL/OSGVRMLNodeDescs.cpp	28 Aug 2007 15:15:08 -0000	1.39
@@ -51,6 +51,7 @@
 
 #include <OSGNode.h>
 #include <OSGNodeCore.h>
+#include <OSGSimpleAttachments.h>
 #include <OSGGroup.h>
 #include <OSGComponentTransform.h>
 #include <OSGGeometry.h>
@@ -76,20 +77,9 @@
 
 //#define OSG_DEBUG_VRML
 
-#ifndef OSG_DO_DOC
-#    ifdef OSG_DEBUG_VRML
-#        define OSG_VRML_ARG(ARG) ARG
-#    else
-#        define OSG_VRML_ARG(ARG)
-#    endif
-#else
-#    define OSG_VRML_ARG(ARG) ARG
-#endif
-
 OSG_USING_NAMESPACE
 
 
-
 /*! \defgroup GrpSystemFileIOVRML VRML-specific File Input/Output
     \ingroup GrpSystemFileIO
 
@@ -2811,6 +2801,60 @@
                 endEditCP  (pChunkMat, ChunkMaterial::ChunksFieldMask);
             }
         }
+        
+        // This works around the problem that MaterialChunks can not have
+        // NameAttachments on them (they are attachments themselves).
+        //
+        // If the ChunkMaterial (which corresponds to the VRML Appearance Node)
+        // has no name of its own, the material's name is set instead.
+        
+        // BEGIN Material name hack
+                
+        AttachmentContainerPtr attCon    = AttachmentContainerPtr::dcast(pFC);
+        bool                   pushNames = false;
+        std::string            optionStr =
+            SceneFileHandler::the().getOptions("wrl");
+        
+        if(optionStr.find("pushNames=true") != std::string::npos)
+            pushNames = true;
+        
+        if((attCon != NullFC) && (pushNames == true))
+        {        
+            FieldContainerPtr att = attCon->findAttachment(
+                Name::getClassType().getGroupId());
+            
+            if(att != NullFC)
+            {
+                // ChunkMaterial (Appearance) already has a NameAttachment
+                NamePtr nameAtt = NamePtr::dcast(att);
+                
+                if(nameAtt != NullFC)
+                {
+                    if(nameAtt->getFieldPtr()->getValue().empty())
+                    {
+                        beginEditCP(nameAtt);
+                            nameAtt->getFieldPtr()->getValue().assign(
+                                _pMaterialDesc->getName());
+                        endEditCP  (nameAtt);
+                    }
+                }
+            }
+            else
+            {
+                // ChunkMaterial (Appearance) has no NameAttachment                
+                NamePtr nameAtt = Name::create();
+                
+                beginEditCP(nameAtt);
+                beginEditCP(pFC, AttachmentContainer::AttachmentsFieldMask);
+                    nameAtt->getFieldPtr()->getValue().assign(
+                        _pMaterialDesc->getName());
+                    attCon ->addAttachment(nameAtt);
+                endEditCP  (pFC, AttachmentContainer::AttachmentsFieldMask);
+                endEditCP  (nameAtt);
+            }
+        }
+        
+        // END Material name hack
     }
 
 #if 0
@@ -2924,7 +2968,9 @@
     _transparency           (),
 
     _pDefMat                (NullFC),
-    _pMat                   (NullFC)
+    _pMat                   (NullFC),
+    
+    _szName                 ()
 {
 }
 
@@ -2957,6 +3003,8 @@
     _shininess       .setValue(_defaultShininess);
     _specularColor   .setValue(_defaultSpecularColor);
     _transparency    .setValue(_defaultTransparency);
+    
+    _szName          .erase   ();
 }
 
 MaterialPtr VRMLMaterialDesc::getDefaultMaterial(void)
@@ -3111,13 +3159,14 @@
 
 FieldContainerPtr VRMLMaterialDesc::beginNode(
     const Char8       *,
-    const Char8       *,
-    FieldContainerPtr  )
+    const Char8       *szName,
+    FieldContainerPtr   )
 {
     reset();
 
-    _pMat = MaterialChunk::create();
-
+    _pMat   = MaterialChunk::create();
+    _szName = szName;
+    
     return _pMat;
 }
 
@@ -3164,6 +3213,15 @@
 }
 
 /*-------------------------------------------------------------------------*/
+/*                            Type Specific                                */
+
+const std::string &
+VRMLMaterialDesc::getName(void) const
+{
+    return _szName;
+}
+
+/*-------------------------------------------------------------------------*/
 /*                                Dump                                     */
 
 void VRMLMaterialDesc::dump(const Char8 *)
Index: Source/System/FileIO/WRL/OSGVRMLNodeDescs.h
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/WRL/OSGVRMLNodeDescs.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Source/System/FileIO/WRL/OSGVRMLNodeDescs.h	16 Jun 2005 15:18:15 -0000	1.12
+++ Source/System/FileIO/WRL/OSGVRMLNodeDescs.h	28 Aug 2007 15:15:08 -0000	1.13
@@ -964,6 +964,13 @@
 
     /*! \}                                                                 */
     /*---------------------------------------------------------------------*/
+    /*! \name                   Type Specific                              */
+    /*! \{                                                                 */
+    
+    const std::string &getName(void) const;
+    
+    /*! \}                                                                 */
+    /*---------------------------------------------------------------------*/
     /*! \name                        Dump                                  */
     /*! \{                                                                 */
 
@@ -994,6 +1001,8 @@
     ChunkMaterialPtr _pDefMat;
     MaterialChunkPtr _pMat;
 
+    std::string      _szName;
+    
     /*! \}                                                                 */
     /*==========================  PRIVATE  ================================*/
   private:
Index: Source/System/FileIO/WRL/OSGVRMLSceneFileType.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/WRL/OSGVRMLSceneFileType.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Source/System/FileIO/WRL/OSGVRMLSceneFileType.cpp	12 Jan 2007 16:59:05 -0000	1.15
+++ Source/System/FileIO/WRL/OSGVRMLSceneFileType.cpp	28 Aug 2007 15:15:08 -0000	1.16
@@ -90,9 +90,18 @@
 
 NodePtr VRMLSceneFileType::read(std::istream &is, const Char8 *) const
 {
+    SINFO << "Source/System/FileIO/WRL/VRMLSceneFileType::read" << std::endl;
+
     NodePtr root = NullFC;
 
     VRMLFile *loader = new VRMLFile();
+    
+    // parse options
+    if(_options.find("pushNames=true") != std::string::npos)
+        loader->addOptions(VRMLFile::PushNames);
+    else if(_options.find("pushNames=false") != std::string::npos)
+        loader->subOptions(VRMLFile::PushNames);
+    
     loader->createStandardPrototypes();
     loader->scanStream(is);
     root = loader->getRoot();
Index: Source/System/FileIO/WRL/testVRML.cpp
===================================================================
RCS file: /cvsroot/opensg/OpenSG/Source/System/FileIO/WRL/testVRML.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Source/System/FileIO/WRL/testVRML.cpp	23 Sep 2002 12:42:12 -0000	1.1
+++ Source/System/FileIO/WRL/testVRML.cpp	28 Aug 2007 15:15:08 -0000	1.2
@@ -14,6 +14,11 @@
 
     OSG::Node::create();
 
+    if((argc > 2) && (OSG::stringcmp(argv[2], "pushNames") == 0))
+    {    
+        OSG::SceneFileHandler::the().setOptions("wrl", "pushNames=true");
+    }
+    
     pRoot = OSG::SceneFileHandler::the().read(argv[1]);
 
     std::cerr << "Tree : " << std::endl;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to