Index: experimental/distortionNG/ReaderWriterDist.cpp
===================================================================
--- experimental/distortionNG/ReaderWriterDist.cpp	(revision 365)
+++ experimental/distortionNG/ReaderWriterDist.cpp	(revision 366)
@@ -5,42 +5,95 @@
 {
 	supportsExtension( "dist", "distortion set loader");
+	extensionToAdd = ".dist";
 
+	// Configure Compression and instantiate read/write-options
+	bool asAscii = true;
+	bool compressionEnabled = false;
 
-	extensionToAdd = ".dist";
+	std::string readOptionString = "";
+	std::string writeOptionString = "";
+	if(asAscii)
+	{
+		readOptionString = "Ascii";
+		writeOptionString = "Ascii";
+	}
+	if (compressionEnabled)
+		writeOptionString+=" Compressor=zlib";
+	readOptions = new osgDB::Options( readOptionString.c_str() );
+	writeOptions = new osgDB::Options( writeOptionString.c_str() );
+
+	// Get ReaderWriter
+	rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgt");	
+
 }
 
 ReaderWriterDist::ReadResult ReaderWriterDist::readNode( const std::string& file, const osgDB::ReaderWriter::Options* options) const
 {
-	// Check if its a valid file for this pseudo loader
 	std::string ext = osgDB::getLowerCaseFileExtension( file );
 	if( !acceptsExtension(ext) )
 		return ReadResult::FILE_NOT_HANDLED;
 
-	// Strip the pseudo-loader extension
-    std::string realName = osgDB::getNameLessExtension( file );
-
-	// check if stripped file exists
-	std::string fileName = osgDB::findDataFile( realName, options );
+	// check if file exists
+	std::string fileName = osgDB::findDataFile( file, options );
 	if( fileName.empty() )
 		return ReadResult::FILE_NOT_FOUND;
 
-	// If options are available: Save it'S original KdTree Hint.
-	Options::BuildKdTreesHint originalHint = Options::NO_PREFERENCE;
-	if(options)
+	std::ifstream stream( fileName.c_str(), std::ios::in );
+	if (!stream)	return ReadResult::ERROR_IN_READING_FILE;
+	return readNode( stream, options );
+}
+
+ReaderWriterDist::ReadResult ReaderWriterDist:: readNode( std::istream& fin, const osgDB::ReaderWriter::Options* options ) const
+{
+	if ( rw )
 	{
-		originalHint = options->getBuildKdTreesHint();
-		const_cast<osgDB::ReaderWriter::Options*>(options)->setBuildKdTreesHint(Options::DO_NOT_BUILD_KDTREES);
+		osgDB::ReaderWriter::ReadResult rr = rw->readObject( fin, readOptions );
+		if (rr.success())
+		{
+			return( rr.takeObject() );
+		}
+		else
+			OSG_NOTIFY( osg::WARN ) << "ERROR: Unable to convert stream to node" << std::endl;
 	}
+	else
+		OSG_NOTIFY( osg::WARN ) << "ERROR: Unable to get ReaderWriter for internally used extension" << std::endl;
+}
 
-	// Load real file
-	osg::Node *node = osgDB::readNodeFile( fileName, options );
-    if( !node )
-    {
-        // propagate the read failure upwards
-        OSG_WARN << "Subfile \"" << fileName << "\" could not be loaded" << std::endl;
-        return ReadResult::FILE_NOT_HANDLED;
-    }
+ReaderWriterDist::WriteResult writeNode( const osg::Node& node, const std::string& fileName, const Options* options ) const
+{
+	std::string ext = osgDB::getLowerCaseFileExtension( file );
+	if( !acceptsExtension(ext) )
+		return WriteResult::FILE_NOT_HANDLED;
 
-	return node;
+	std::ifstream stream( fileName.c_str(), std::ios::in );
+	if (!stream)	return ReadResult::ERROR_IN_READING_FILE;
+	return readNode( stream, options );
+// ------------------
+    WriteResult result = WriteResult::FILE_SAVED;
+    std::ios::openmode mode = std::ios::out;
+    osg::ref_ptr<Options> local_opt = prepareWriting( result, fileName, mode, options );
+    if ( !result.success() ) return result;
+
+    osgDB::ofstream fout( fileName.c_str(), mode );
+    if ( !fout ) return WriteResult::ERROR_IN_WRITING_FILE;
+
+    result = writeNode( node, fout, local_opt.get() );
+    fout.close();
+    return result;
+}
+
+ReaderWriterDist::WriteResult writeNode( const osg::Node& node, std::ostream& fout, const Options* options ) const
+{
+	if ( rw )
+	{
+		osgDB::ReaderWriter::WriteResult wr = rw->writeObject( node, fout, writeOptions );
+		if (wr.success() )			
+		{
+			OSG_NOTIFY( osg::WARN ) << "schreiben geschafft!"<< std::endl;
+		}
+		else OSG_NOTIFY( osg::WARN ) << "ERROR: Save failed: " << wr.message() << std::endl;
+		return(wr);
+	}
+	OSG_NOTIFY( osg::WARN ) << "ERROR: Unable to get ReaderWriter for internally used extension" << std::endl;
 }
 
