Explorar el Código

updated C4D importer to use the Cineware SDK

Maxon’s Melange SDK has been renamed Cineware SDK as of 21.004, and with it all namespaces and types. This commit
- makes CMake use contrib/Cineware instead of contrib/Melange;
- renames Assimp’s namespace melange to namespace cineware;
- removes useless functions and formatter references from class C4DImporter;
- removes duplicate conversion of cineware::String to aiString in the importer;
- updates comments accordingly;
- updates copyright info.
Krishty hace 4 años
padre
commit
65a2b98b86
Se han modificado 3 ficheros con 46 adiciones y 72 borrados
  1. 8 7
      CMakeLists.txt
  2. 23 41
      code/AssetLib/C4D/C4DImporter.cpp
  3. 15 24
      code/AssetLib/C4D/C4DImporter.h

+ 8 - 7
CMakeLists.txt

@@ -527,12 +527,12 @@ ENDIF()
 MARK_AS_ADVANCED ( ASSIMP_BUILD_ARCHITECTURE ASSIMP_BUILD_COMPILER )
 
 SET ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER OFF CACHE BOOL
-  "Build the C4D importer, which relies on the non-free Melange SDK."
+  "Build the C4D importer, which relies on the non-free Cineware SDK."
 )
 
 IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
   IF ( MSVC )
-    SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Melange/includes")
+    SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/includes")
 
     # pick the correct prebuilt library
     IF(MSVC15)
@@ -551,22 +551,23 @@ IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
       )
     ENDIF()
 
-    SET(C4D_LIB_BASE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Melange/libraries/win")
+    SET(C4D_LIB_BASE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/libraries/win")
 
     SET(C4D_DEBUG_LIBRARIES
-      "${C4D_LIB_BASE_PATH}/melangelib${C4D_LIB_POSTFIX}/melangelib_debug.lib"
+      "${C4D_LIB_BASE_PATH}/cinewarelib${C4D_LIB_POSTFIX}/cinewarelib_debug.lib"
       "${C4D_LIB_BASE_PATH}/jpeglib${C4D_LIB_POSTFIX}/jpeglib_debug.lib"
     )
     SET(C4D_RELEASE_LIBRARIES
-      "${C4D_LIB_BASE_PATH}/melangelib${C4D_LIB_POSTFIX}/melangelib_release.lib"
+      "${C4D_LIB_BASE_PATH}/cinewarelib${C4D_LIB_POSTFIX}/cinewarelib_release.lib"
       "${C4D_LIB_BASE_PATH}/jpeglib${C4D_LIB_POSTFIX}/jpeglib_release.lib"
     )
 
-    # winsock and winmm are necessary dependencies of melange (this is undocumented, but true.)
+    # winsock and winmm are necessary (and undocumented) dependencies of Cineware SDK because
+    # it can be used to communicate with a running Cinema 4D instance
     SET(C4D_EXTRA_LIBRARIES WSock32.lib Winmm.lib)
   ELSE ()
     MESSAGE( FATAL_ERROR
-      "C4D is currently only available on Windows with melange SDK installed in contrib/Melange"
+      "C4D is currently only available on Windows with Cineware SDK installed in contrib/Cineware"
     )
   ENDIF ()
 ELSE ()

+ 23 - 41
code/AssetLib/C4D/C4DImporter.cpp

@@ -2,7 +2,7 @@
 Open Asset Import Library (assimp)
 ----------------------------------------------------------------------
 
-Copyright (c) 2006-2020, assimp team
+Copyright (c) 2006-2021, assimp team
 All rights reserved.
 
 Redistribution and use of this software in source and binary forms,
@@ -51,7 +51,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #endif
 
 #include "C4DImporter.h"
-#include <assimp/TinyFormatter.h>
 #include <memory>
 #include <assimp/IOSystem.hpp>
 #include <assimp/scene.h>
@@ -65,7 +64,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "c4d_file.h"
 #include "default_alien_overloads.h"
 
-using namespace melange;
+namespace {
+
+aiString aiStringFrom(cineware::String const & cinestring) {
+    aiString result;
+    cinestring.GetCString(result.data, MAXLEN-1);
+    result.length = static_cast<ai_uint32>(cinestring.GetLength());
+    return result;
+}
+
+}
+
+using namespace Assimp;
+using namespace cineware;
 
 // overload this function and fill in your own unique data
 void GetWriterInfo(int &id, String &appname) {
@@ -73,9 +84,6 @@ void GetWriterInfo(int &id, String &appname) {
     appname = "Open Asset Import Library";
 }
 
-using namespace Assimp;
-using namespace Assimp::Formatter;
-
 namespace Assimp {
     template<> const char* LogFunctions<C4DImporter>::Prefix() {
         static auto prefix = "C4D: ";
@@ -97,17 +105,6 @@ static const aiImporterDesc desc = {
 };
 
 
-// ------------------------------------------------------------------------------------------------
-C4DImporter::C4DImporter()
-: BaseImporter() {
-    // empty
-}
-
-// ------------------------------------------------------------------------------------------------
-C4DImporter::~C4DImporter() {
-    // empty
-}
-
 // ------------------------------------------------------------------------------------------------
 bool C4DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
     const std::string& extension = GetExtension(pFile);
@@ -125,11 +122,6 @@ const aiImporterDesc* C4DImporter::GetInfo () const {
     return &desc;
 }
 
-// ------------------------------------------------------------------------------------------------
-void C4DImporter::SetupProperties(const Importer* /*pImp*/) {
-    // nothing to be done for the moment
-}
-
 
 // ------------------------------------------------------------------------------------------------
 // Imports the given file into the given scene structure.
@@ -199,8 +191,8 @@ void C4DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
 
 
 // ------------------------------------------------------------------------------------------------
-bool C4DImporter::ReadShader(aiMaterial* out, melange::BaseShader* shader) {
-    // based on Melange sample code (C4DImportExport.cpp)
+bool C4DImporter::ReadShader(aiMaterial* out, BaseShader* shader) {
+    // based on Cineware sample code (C4DImportExport.cpp)
     while(shader) {
         if(shader->GetType() == Xlayer) {
             BaseContainer* container = shader->GetDataInstance();
@@ -242,9 +234,7 @@ bool C4DImporter::ReadShader(aiMaterial* out, melange::BaseShader* shader) {
                 lsl = lsl->GetNext();
             }
         } else if ( shader->GetType() == Xbitmap ) {
-            aiString path;
-            shader->GetFileName().GetString().GetCString(path.data, MAXLEN-1);
-            path.length = ::strlen(path.data);
+            auto const path = aiStringFrom(shader->GetFileName().GetString());
             out->AddProperty(&path, AI_MATKEY_TEXTURE_DIFFUSE(0));
             return true;
         } else {
@@ -257,18 +247,15 @@ bool C4DImporter::ReadShader(aiMaterial* out, melange::BaseShader* shader) {
 }
 
 // ------------------------------------------------------------------------------------------------
-void C4DImporter::ReadMaterials(melange::BaseMaterial* mat) {
-    // based on Melange sample code
+void C4DImporter::ReadMaterials(BaseMaterial* mat) {
+    // based on Cineware sample code
     while (mat) {
-        const String& name = mat->GetName();
         if (mat->GetType() == Mmaterial) {
             aiMaterial* out = new aiMaterial();
             material_mapping[mat] = static_cast<unsigned int>(materials.size());
             materials.push_back(out);
 
-            aiString ai_name;
-            name.GetCString(ai_name.data, MAXLEN-1);
-            ai_name.length = ::strlen(ai_name.data);
+            auto const ai_name = aiStringFrom(mat->GetName());
             out->AddProperty(&ai_name, AI_MATKEY_NAME);
 
             Material& m = dynamic_cast<Material&>(*mat);
@@ -305,19 +292,15 @@ void C4DImporter::RecurseHierarchy(BaseObject* object, aiNode* parent) {
     ai_assert(parent != nullptr );
     std::vector<aiNode*> nodes;
 
-    // based on Melange sample code
+    // based on Cineware sample code
     while (object) {
-        const String& name = object->GetName();
         const LONG type = object->GetType();
         const Matrix& ml = object->GetMl();
 
-        aiString string;
-        name.GetCString(string.data, MAXLEN-1);
-        string.length = ::strlen(string.data);
         aiNode* const nd = new aiNode();
 
         nd->mParent = parent;
-        nd->mName = string;
+        nd->mName = aiStringFrom(object->GetName());
 
         nd->mTransformation.a1 = ml.v1.x;
         nd->mTransformation.b1 = ml.v1.y;
@@ -370,7 +353,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) {
     ai_assert(object != nullptr);
     ai_assert( object->GetType() == Opolygon );
 
-    // based on Melange sample code
+    // based on Cineware sample code
     PolygonObject* const polyObject = dynamic_cast<PolygonObject*>(object);
     ai_assert(polyObject != nullptr);
 
@@ -618,4 +601,3 @@ unsigned int C4DImporter::ResolveMaterial(PolygonObject* obj) {
 }
 
 #endif // ASSIMP_BUILD_NO_C4D_IMPORTER
-

+ 15 - 24
code/AssetLib/C4D/C4DImporter.h

@@ -2,7 +2,7 @@
 Open Asset Import Library (assimp)
 ----------------------------------------------------------------------
 
-Copyright (c) 2006-2020, assimp team
+Copyright (c) 2006-2021, assimp team
 All rights reserved.
 
 Redistribution and use of this software in source and binary forms,
@@ -56,8 +56,8 @@ struct aiMaterial;
 
 struct aiImporterDesc;
 
-namespace melange {
-    class BaseObject; // c4d_file.h
+namespace cineware {
+    class BaseObject;
     class PolygonObject;
     class BaseMaterial;
     class BaseShader;
@@ -71,43 +71,34 @@ namespace Assimp  {
     }
 
 // -------------------------------------------------------------------------------------------
-/** Importer class to load Cinema4D files using the Melange library to be obtained from
- *  www.plugincafe.com
+/** Importer class to load Cinema4D files using the Cineware library to be obtained from
+ *  https://developers.maxon.net
  *
- *  Note that Melange is not free software. */
+ *  Note that Cineware is not free software. */
 // -------------------------------------------------------------------------------------------
 class C4DImporter : public BaseImporter, public LogFunctions<C4DImporter> {
 public:
-    C4DImporter();
-    ~C4DImporter();
-    bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
-        bool checkSig) const;
+    bool CanRead( const std::string& pFile, IOSystem*, bool checkSig) const override;
 
 protected:
 
-    // --------------------
-    const aiImporterDesc* GetInfo () const;
+    const aiImporterDesc* GetInfo () const override;
 
-    // --------------------
-    void SetupProperties(const Importer* pImp);
-
-    // --------------------
-    void InternReadFile( const std::string& pFile, aiScene* pScene,
-        IOSystem* pIOHandler);
+    void InternReadFile( const std::string& pFile, aiScene*, IOSystem* ) override;
 
 private:
 
-    void ReadMaterials(melange::BaseMaterial* mat);
-    void RecurseHierarchy(melange::BaseObject* object, aiNode* parent);
-    aiMesh* ReadMesh(melange::BaseObject* object);
-    unsigned int ResolveMaterial(melange::PolygonObject* obj);
+    void ReadMaterials(cineware::BaseMaterial* mat);
+    void RecurseHierarchy(cineware::BaseObject* object, aiNode* parent);
+    aiMesh* ReadMesh(cineware::BaseObject* object);
+    unsigned int ResolveMaterial(cineware::PolygonObject* obj);
 
-    bool ReadShader(aiMaterial* out, melange::BaseShader* shader);
+    bool ReadShader(aiMaterial* out, cineware::BaseShader* shader);
 
     std::vector<aiMesh*> meshes;
     std::vector<aiMaterial*> materials;
 
-    typedef std::map<melange::BaseMaterial*, unsigned int> MaterialMap;
+    typedef std::map<cineware::BaseMaterial*, unsigned int> MaterialMap;
     MaterialMap material_mapping;
 
 }; // !class C4DImporter