1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of COLLADASaxFrameworkLoader.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #include "COLLADASaxFWLStableHeaders.h"
12 #include "COLLADASaxFWLAssetLoader.h"
13 #include "COLLADASaxFWLLoader.h"
14 
15 
16 namespace COLLADASaxFWL
17 {
18 
19     //------------------------------
AssetLoader(IFilePartLoader * callingFilePartLoader)20     AssetLoader::AssetLoader ( IFilePartLoader* callingFilePartLoader )
21         : FilePartLoader ( callingFilePartLoader )
22         , mAsset ( new COLLADAFW::FileInfo () )
23 	{
24 		mAsset->setAbsoluteFileUri( callingFilePartLoader->getFileUri() );
25 		// COLLADA always uses degrees as angular units
26 		mAsset->getUnit().setAngularUnit( COLLADAFW::FileInfo::Unit::DEGREES );
27 	}
28 
29     //------------------------------
~AssetLoader()30 	AssetLoader::~AssetLoader()
31 	{
32 	}
33 
34 	//------------------------------
end__asset()35 	bool AssetLoader::end__asset()
36 	{
37 		bool success = true;
38 		if ( (getObjectFlags() & Loader::ASSET_FLAG) != 0 )
39 		{
40 			success = writer()->writeGlobalAsset ( mAsset );
41 		}
42 		delete mAsset;
43 		finish();
44 		return success;
45 	}
46 
47 	//------------------------------
data__author(const ParserChar * data,size_t length)48 	bool AssetLoader::data__author( const ParserChar* data, size_t length )
49 	{
50 		mAsset->appendValuePair ( "author", String ( (char*) data, length ) );
51 		return true;
52 	}
53 
54 	//------------------------------
data__authoring_tool(const ParserChar * data,size_t length)55 	bool AssetLoader::data__authoring_tool( const ParserChar* data, size_t length )
56 	{
57 		mAsset->appendValuePair ( "authoring_tool", String ( (char*) data, length ) );
58 		return true;
59 	}
60 
61 	//------------------------------
data__copyright(const ParserChar * data,size_t length)62 	bool AssetLoader::data__copyright( const ParserChar* data, size_t length )
63 	{
64 		mAsset->appendValuePair ( "copyright", String ( (char*) data, length ) );
65 		return true;
66 	}
67 
68 	//------------------------------
data__comments(const ParserChar * data,size_t length)69 	bool AssetLoader::data__comments( const ParserChar* data, size_t length )
70 	{
71 		mAsset->appendValuePair ( "comments", String ( (char*) data, length ) );
72 		return true;
73 	}
74 
75 	//------------------------------
data__source_data(COLLADABU::URI value)76 	bool AssetLoader::data__source_data( COLLADABU::URI value )
77 	{
78 		mAsset->appendValuePair ( "source", value.getURIString() );
79 		return true;
80 	}
81 
82 	//------------------------------
data__created(const ParserChar * data,size_t length)83 	bool AssetLoader::data__created( const ParserChar* data, size_t length )
84 	{
85 		mAsset->appendValuePair ( "created", String ( (char*) data, length ) );
86 		return true;
87 	}
88 
89 	//------------------------------
data__keywords(const ParserChar * data,size_t length)90 	bool AssetLoader::data__keywords( const ParserChar* data, size_t length )
91 	{
92 		mAsset->appendValuePair ( "keywords", String ( (char*) data, length ) );
93 		return true;
94 	}
95 
96 	//------------------------------
data__modified(const ParserChar * data,size_t length)97 	bool AssetLoader::data__modified( const ParserChar* data, size_t length )
98 	{
99 		mAsset->appendValuePair ( "modified", String ( (char*) data, length ) );
100 		return true;
101 	}
102 
103 	//------------------------------
data__revision(const ParserChar * data,size_t length)104 	bool AssetLoader::data__revision( const ParserChar* data, size_t length )
105 	{
106 		mAsset->appendValuePair ( "revision", String ( (char*) data, length ) );
107 		return true;
108 	}
109 
110 	//------------------------------
data__subject(const ParserChar * data,size_t length)111 	bool AssetLoader::data__subject( const ParserChar* data, size_t length )
112 	{
113 		mAsset->appendValuePair ( "subject", String ( (char*) data, length ) );
114 		return true;
115 	}
116 
117 	//------------------------------
data__title(const ParserChar * data,size_t length)118 	bool AssetLoader::data__title( const ParserChar* data, size_t length )
119 	{
120 		mAsset->appendValuePair ( "title", String ( (char*) data, length ) );
121 		return true;
122 	}
123 
124 	//------------------------------
begin__unit(const unit__AttributeData & attributeData)125 	bool AssetLoader::begin__unit( const unit__AttributeData& attributeData )
126 	{
127 		mAsset->getUnit().setLinearUnitName ( String ( (char*) attributeData.name ) );
128 		mAsset->getUnit().setLinearUnitMeter ( attributeData.meter );
129 		return true;
130 	}
131 
132 	//------------------------------
data__up_axis(const ENUM__UpAxisType val)133 	bool AssetLoader::data__up_axis( const ENUM__UpAxisType val )
134 	{
135 		switch ( val )
136 		{
137 		case COLLADASaxFWL14::ENUM__UpAxisType__X_UP:
138 			mAsset->setUpAxisType ( COLLADAFW::FileInfo::X_UP );
139 			break;
140 		case COLLADASaxFWL14::ENUM__UpAxisType__Y_UP:
141 			mAsset->setUpAxisType ( COLLADAFW::FileInfo::Y_UP );
142 			break;
143 		case COLLADASaxFWL14::ENUM__UpAxisType__Z_UP:
144 			mAsset->setUpAxisType ( COLLADAFW::FileInfo::Z_UP );
145 			break;
146 		default:
147 			mAsset->setUpAxisType ( COLLADAFW::FileInfo::Y_UP);
148 		}
149 		return true;
150 	}
151 } // namespace COLLADASaxFWL
152