1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
7 
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
11 
12 * Redistributions of source code must retain the above
13   copyright notice, this list of conditions and the
14   following disclaimer.
15 
16 * Redistributions in binary form must reproduce the above
17   copyright notice, this list of conditions and the
18   following disclaimer in the documentation and/or other
19   materials provided with the distribution.
20 
21 * Neither the name of the assimp team, nor the names of its
22   contributors may be used to endorse or promote products
23   derived from this software without specific prior
24   written permission of the assimp team.
25 
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 
38 ----------------------------------------------------------------------
39 */
40 
41 /** @file  C4DImporter.h
42  *  @brief Declaration of the Cinema4D (*.c4d) importer class.
43  */
44 #ifndef INCLUDED_AI_CINEMA_4D_LOADER_H
45 #define INCLUDED_AI_CINEMA_4D_LOADER_H
46 
47 #include "BaseImporter.h"
48 #include "LogAux.h"
49 
50 #include <map>
51 struct aiNode;
52 struct aiMesh;
53 struct aiMaterial;
54 
55 struct aiImporterDesc;
56 
57 namespace melange {
58     class BaseObject; // c4d_file.h
59     class PolygonObject;
60     class BaseMaterial;
61     class BaseShader;
62 }
63 
64 namespace Assimp    {
65 
66     // TinyFormatter.h
67     namespace Formatter {
68         template <typename T,typename TR, typename A> class basic_formatter;
69         typedef class basic_formatter< char, std::char_traits<char>, std::allocator<char> > format;
70     }
71 
72 // -------------------------------------------------------------------------------------------
73 /** Importer class to load Cinema4D files using the Melange library to be obtained from
74  *  www.plugincafe.com
75  *
76  *  Note that Melange is not free software. */
77 // -------------------------------------------------------------------------------------------
78 class C4DImporter : public BaseImporter, public LogFunctions<C4DImporter>
79 {
80 public:
81 
82     C4DImporter();
83     ~C4DImporter();
84 
85 
86 public:
87 
88     // --------------------
89     bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
90         bool checkSig) const;
91 
92 protected:
93 
94     // --------------------
95     const aiImporterDesc* GetInfo () const;
96 
97     // --------------------
98     void SetupProperties(const Importer* pImp);
99 
100     // --------------------
101     void InternReadFile( const std::string& pFile, aiScene* pScene,
102         IOSystem* pIOHandler);
103 
104 private:
105 
106     void ReadMaterials(melange::BaseMaterial* mat);
107     void RecurseHierarchy(melange::BaseObject* object, aiNode* parent);
108     aiMesh* ReadMesh(melange::BaseObject* object);
109     unsigned int ResolveMaterial(melange::PolygonObject* obj);
110 
111     bool ReadShader(aiMaterial* out, melange::BaseShader* shader);
112 
113     std::vector<aiMesh*> meshes;
114     std::vector<aiMaterial*> materials;
115 
116     typedef std::map<melange::BaseMaterial*, unsigned int> MaterialMap;
117     MaterialMap material_mapping;
118 
119 }; // !class C4DImporter
120 
121 } // end of namespace Assimp
122 #endif // INCLUDED_AI_CINEMA_4D_LOADER_H
123 
124