pull/933/head
Kim Kulling 2016-07-04 20:19:37 +02:00
commit ebb209a0d6
10 changed files with 127 additions and 43 deletions

View File

@ -1,6 +1,6 @@
# Open Asset Import Library (assimp)
# ----------------------------------------------------------------------
#
#
# Copyright (c) 2006-2016, assimp team
# All rights reserved.
#
@ -81,7 +81,8 @@ IF(NOT GIT_COMMIT_HASH)
ENDIF(NOT GIT_COMMIT_HASH)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/revision.h.in
${CMAKE_CURRENT_LIST_DIR}/revision.h.in
# ${CMAKE_CURRENT_SOURCE_DIR}/revision.h.in
${CMAKE_CURRENT_BINARY_DIR}/revision.h
)
@ -175,7 +176,15 @@ ENDIF( CMAKE_COMPILER_IS_GNUCXX )
# Search for external dependencies, and build them from source if not found
# Search for zlib
find_package(ZLIB)
OPTION(ASSIMP_BUILD_ZLIB
"Build your own zlib"
OFF
)
IF ( NOT ASSIMP_BUILD_ZLIB )
find_package(ZLIB)
ENDIF(ASSIMP_BUILD_ZLIB)
IF( NOT ZLIB_FOUND )
message(STATUS "compiling zlib from souces")
include(CheckIncludeFile)
@ -228,31 +237,33 @@ SET ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER OFF CACHE BOOL
IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
IF ( MSVC )
SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Melange/_melange/includes")
SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Melange/includes")
# pick the correct prebuilt library
IF(MSVC11)
SET(C4D_LIB_POSTFIX "_2012md")
IF(MSVC14)
SET(C4D_LIB_POSTFIX "_2015")
ELSEIF(MSVC12)
SET(C4D_LIB_POSTFIX "_2013")
ELSEIF(MSVC11)
SET(C4D_LIB_POSTFIX "_2012")
ELSEIF(MSVC10)
SET(C4D_LIB_POSTFIX "_2010md")
ELSEIF(MSVC90)
SET(C4D_LIB_POSTFIX "_2008md")
SET(C4D_LIB_POSTFIX "_2010")
ELSE()
MESSAGE( FATAL_ERROR
"C4D is currently only supported with MSVC 9, 10, 11"
"C4D is currently only supported with MSVC 10, 11, 12, 14"
)
ENDIF()
IF(CMAKE_CL_64)
SET(C4D_LIB_ARCH_POSTFIX "_x64")
ELSE()
SET(C4D_LIB_ARCH_POSTFIX "")
ENDIF()
SET(C4D_LIB_BASE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Melange/libraries/win")
SET(C4D_LIB_BASE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Melange/_melange/lib/WIN")
SET(C4D_DEBUG_LIBRARY "${C4D_LIB_BASE_PATH}/debug/_melange_lib${C4D_LIB_ARCH_POSTFIX}${C4D_LIB_POSTFIX}.lib")
SET(C4D_RELEASE_LIBRARY "${C4D_LIB_BASE_PATH}/release/_melange_lib${C4D_LIB_ARCH_POSTFIX}${C4D_LIB_POSTFIX}.lib")
SET(C4D_DEBUG_LIBRARIES
"${C4D_LIB_BASE_PATH}/melangelib${C4D_LIB_POSTFIX}/melangelib_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}/jpeglib${C4D_LIB_POSTFIX}/jpeglib_release.lib"
)
# winsock and winmm are necessary dependencies of melange (this is undocumented, but true.)
SET(C4D_EXTRA_LIBRARIES WSock32.lib Winmm.lib)
@ -278,7 +289,7 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
ADD_SUBDIRECTORY( tools/assimp_view/ )
ENDIF ( ASSIMP_BUILD_ASSIMP_VIEW )
ENDIF ( WIN32 )
ADD_SUBDIRECTORY( tools/assimp_cmd/ )
ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS )

View File

@ -52,6 +52,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "C4DImporter.h"
#include "TinyFormatter.h"
#include <memory>
#include <assimp/IOSystem.hpp>
#include <assimp/scene.h>
#include <assimp/ai_assert.h>
#if defined(_M_X64) || defined(__amd64__)
# define __C4D_64BIT
@ -61,10 +65,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "c4d_file.h"
#include "default_alien_overloads.h"
using namespace _melange_;
using namespace melange;
// overload this function and fill in your own unique data
void GetWriterInfo(LONG &id, String &appname)
void GetWriterInfo(int &id, String &appname)
{
id = 2424226;
appname = "Open Asset Import Library";
@ -197,7 +201,7 @@ void C4DImporter::InternReadFile( const std::string& pFile,
// ------------------------------------------------------------------------------------------------
bool C4DImporter::ReadShader(aiMaterial* out, _melange_::BaseShader* shader)
bool C4DImporter::ReadShader(aiMaterial* out, melange::BaseShader* shader)
{
// based on Melange sample code (C4DImportExport.cpp)
while(shader) {
@ -263,7 +267,7 @@ bool C4DImporter::ReadShader(aiMaterial* out, _melange_::BaseShader* shader)
// ------------------------------------------------------------------------------------------------
void C4DImporter::ReadMaterials(_melange_::BaseMaterial* mat)
void C4DImporter::ReadMaterials(melange::BaseMaterial* mat)
{
// based on Melange sample code
while (mat)
@ -288,7 +292,7 @@ void C4DImporter::ReadMaterials(_melange_::BaseMaterial* mat)
mat->GetParameter(MATERIAL_COLOR_COLOR, data);
Vector color = data.GetVector();
mat->GetParameter(MATERIAL_COLOR_BRIGHTNESS, data);
const Real brightness = data.GetReal();
const Float brightness = data.GetFloat();
color *= brightness;
@ -507,11 +511,13 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object)
// copy normals
if (normals_src) {
if(i >= normals_src->GetNormalCount()) {
if(i >= normals_src->GetDataCount()) {
LogError("unexpected number of normals, ignoring");
}
else {
const NormalStruct& nor = normals_src->GetNormals(i);
ConstNormalHandle normal_handle = normals_src->GetDataAddressR();
NormalStruct nor;
NormalTag::Get(normal_handle, i, nor);
normals->x = nor.a.x;
normals->y = nor.a.y;
normals->z = nor.a.z;

View File

@ -54,7 +54,7 @@ struct aiMaterial;
struct aiImporterDesc;
namespace _melange_ {
namespace melange {
class BaseObject; // c4d_file.h
class PolygonObject;
class BaseMaterial;
@ -103,17 +103,17 @@ protected:
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(melange::BaseMaterial* mat);
void RecurseHierarchy(melange::BaseObject* object, aiNode* parent);
aiMesh* ReadMesh(melange::BaseObject* object);
unsigned int ResolveMaterial(melange::PolygonObject* obj);
bool ReadShader(aiMaterial* out, _melange_::BaseShader* shader);
bool ReadShader(aiMaterial* out, melange::BaseShader* shader);
std::vector<aiMesh*> meshes;
std::vector<aiMaterial*> materials;
typedef std::map<_melange_::BaseMaterial*, unsigned int> MaterialMap;
typedef std::map<melange::BaseMaterial*, unsigned int> MaterialMap;
MaterialMap material_mapping;
}; // !class C4DImporter

View File

@ -775,8 +775,8 @@ if(ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM)
endif(ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM)
IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
TARGET_LINK_LIBRARIES(assimp optimized ${C4D_RELEASE_LIBRARY})
TARGET_LINK_LIBRARIES(assimp debug ${C4D_DEBUG_LIBRARY})
TARGET_LINK_LIBRARIES(assimp optimized ${C4D_RELEASE_LIBRARIES})
TARGET_LINK_LIBRARIES(assimp debug ${C4D_DEBUG_LIBRARIES})
TARGET_LINK_LIBRARIES(assimp ${C4D_EXTRA_LIBRARIES})
ENDIF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)

View File

@ -240,6 +240,8 @@ struct Mesh {
unsigned int m_uiMaterialIndex;
/// True, if normals are stored.
bool m_hasNormals;
/// True, if vertex colors are stored.
bool m_hasVertexColors;
/// Constructor
explicit Mesh( const std::string &name )
@ -289,6 +291,8 @@ struct Model
std::vector<aiVector3D> m_Vertices;
//! vector with all generated normals
std::vector<aiVector3D> m_Normals;
//! vector with all vertex colors
std::vector<aiVector3D> m_VertexColors;
//! Group map
GroupMap m_Groups;
//! Group to face id assignment

View File

@ -416,6 +416,10 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
if ( !pModel->m_Normals.empty() && pObjMesh->m_hasNormals )
pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ];
// Allocate buffer for vertex-color vectors
if ( !pModel->m_VertexColors.empty() )
pMesh->mColors[0] = new aiColor4D[ pMesh->mNumVertices ];
// Allocate buffer for texture coordinates
if ( !pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0] )
{
@ -449,6 +453,13 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
pMesh->mNormals[ newIndex ] = pModel->m_Normals[ normal ];
}
// Copy all vertex colors
if ( !pModel->m_VertexColors.empty())
{
const aiVector3D color = pModel->m_VertexColors[ vertex ];
pMesh->mColors[0][ newIndex ] = aiColor4D(color.x, color.y, color.z, 1.0);
}
// Copy all texture coordinates
if ( !pModel->m_TextureCoord.empty() && vertexIndex < pSourceFace->m_pTexturCoords->size())
{

View File

@ -136,8 +136,14 @@ void ObjFileParser::parseFile()
{
++m_DataIt;
if (*m_DataIt == ' ' || *m_DataIt == '\t') {
// read in vertex definition
getVector3(m_pModel->m_Vertices);
size_t numComponents = getNumComponentsInLine();
if (numComponents == 3) {
// read in vertex definition
getVector3(m_pModel->m_Vertices);
} else if (numComponents == 6) {
// read vertex and vertex-color
getTwoVectors3(m_pModel->m_Vertices, m_pModel->m_VertexColors);
}
} else if (*m_DataIt == 't') {
// read in texture coordinate ( 2D or 3D )
++m_DataIt;
@ -257,8 +263,7 @@ void ObjFileParser::copyNextLine(char *pBuffer, size_t length)
pBuffer[ index ] = '\0';
}
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
size_t ObjFileParser::getNumComponentsInLine() {
size_t numComponents( 0 );
const char* tmp( &m_DataIt[0] );
while( !IsLineEnd( *tmp ) ) {
@ -268,6 +273,12 @@ void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
SkipToken( tmp );
++numComponents;
}
return numComponents;
}
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
size_t numComponents = getNumComponentsInLine();
float x, y, z;
if( 2 == numComponents ) {
copyNextWord( m_buffer, Buffersize );
@ -309,6 +320,35 @@ void ObjFileParser::getVector3( std::vector<aiVector3D> &point3d_array ) {
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
// -------------------------------------------------------------------
// Get values for two 3D vectors on the same line
void ObjFileParser::getTwoVectors3( std::vector<aiVector3D> &point3d_array_a, std::vector<aiVector3D> &point3d_array_b ) {
float x, y, z;
copyNextWord(m_buffer, Buffersize);
x = (float) fast_atof(m_buffer);
copyNextWord(m_buffer, Buffersize);
y = (float) fast_atof(m_buffer);
copyNextWord( m_buffer, Buffersize );
z = ( float ) fast_atof( m_buffer );
point3d_array_a.push_back( aiVector3D( x, y, z ) );
copyNextWord(m_buffer, Buffersize);
x = (float) fast_atof(m_buffer);
copyNextWord(m_buffer, Buffersize);
y = (float) fast_atof(m_buffer);
copyNextWord( m_buffer, Buffersize );
z = ( float ) fast_atof( m_buffer );
point3d_array_b.push_back( aiVector3D( x, y, z ) );
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
// -------------------------------------------------------------------
// Get values for a new 2D vector instance
void ObjFileParser::getVector2( std::vector<aiVector2D> &point2d_array ) {

View File

@ -89,6 +89,8 @@ private:
void getVector( std::vector<aiVector3D> &point3d_array );
/// Stores the following 3d vector.
void getVector3( std::vector<aiVector3D> &point3d_array );
/// Stores the following two 3d vectors on the line.
void getTwoVectors3( std::vector<aiVector3D> &point3d_array_a, std::vector<aiVector3D> &point3d_array_b );
/// Stores the following 3d vector.
void getVector2(std::vector<aiVector2D> &point2d_array);
/// Stores the following face.
@ -119,6 +121,8 @@ private:
bool needsNewMesh( const std::string &rMaterialName );
/// Error report in token
void reportErrorTokenInFace();
/// Get the number of components in a line.
size_t getNumComponentsInLine();
private:
// Copy and assignment constructor should be private

View File

@ -557,7 +557,7 @@ public:
flags_ |= kIntFlag;
}
#if !defined(__x86_64__)
#if !defined(__x86_64__) && !defined(__arm64__)
//! Constructor for size_t value.
explicit GenericValue( size_t u ) RAPIDJSON_NOEXCEPT : data_(), flags_( kNumberUintFlag ) {
data_.n.u64 = u;

View File

@ -22,6 +22,8 @@ CPP_DEV_TARGET_LIST=(miphoneos-version-min mios-simulator-version-min)
CPP_DEV_TARGET=
CPP_STD_LIB_LIST=(libc++ libstdc++)
CPP_STD_LIB=
CPP_STD_LIST=(c++03 c++11 c++14)
CPP_STD=
function join { local IFS="$1"; shift; echo "$*"; }
@ -46,7 +48,7 @@ build_arch()
export CFLAGS="-arch $1 -pipe -no-cpp-precomp -stdlib=$CPP_STD_LIB -isysroot $SDKROOT -$CPP_DEV_TARGET=$IOS_SDK_TARGET -I$SDKROOT/usr/include/"
export LDFLAGS="-L$SDKROOT/usr/lib/"
export CPPFLAGS=$CFLAGS
export CXXFLAGS=$CFLAGS
export CXXFLAGS="$CFLAGS -std=$CPP_STD"
rm CMakeCache.txt
@ -65,11 +67,16 @@ build_arch()
echo "[!] $0 - assimp iOS build script"
CPP_STD_LIB=${CPP_STD_LIB_LIST[0]}
CPP_STD=${CPP_STD_LIST[0]}
DEPLOY_ARCHS=${BUILD_ARCHS_ALL[*]}
DEPLOY_FAT=1
for i in "$@"; do
case $i in
-s=*|--std=*)
CPP_STD=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
echo "[!] Selecting c++ standard: $CPP_STD"
;;
-l=*|--stdlib=*)
CPP_STD_LIB=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
echo "[!] Selecting c++ std lib: $CPP_STD_LIB"
@ -85,7 +92,8 @@ for i in "$@"; do
-h|--help)
echo " - don't build fat library (--no-fat)."
echo " - supported architectures (--archs): $(echo $(join , ${BUILD_ARCHS_ALL[*]}) | sed 's/,/, /g')"
echo " - supported C++ STD libs. (--stdlib): $(echo $(join , ${CPP_STD_LIB_LIST[*]}) | sed 's/,/, /g')"
echo " - supported C++ STD libs (--stdlib): $(echo $(join , ${CPP_STD_LIB_LIST[*]}) | sed 's/,/, /g')"
echo " - supported C++ standards (--std): $(echo $(join , ${CPP_STD_LIST[*]}) | sed 's/,/, /g')"
exit
;;
*)