Merge branch 'master' into master
commit
6e13baf89c
|
@ -589,11 +589,13 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
||||||
ADD_SUBDIRECTORY( tools/assimp_view/ )
|
ADD_SUBDIRECTORY( tools/assimp_view/ )
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
# Te command line tool
|
# The command line tool
|
||||||
ADD_SUBDIRECTORY( tools/assimp_cmd/ )
|
ADD_SUBDIRECTORY( tools/assimp_cmd/ )
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF ( ASSIMP_BUILD_SAMPLES)
|
IF ( ASSIMP_BUILD_SAMPLES)
|
||||||
|
SET( SAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/samples )
|
||||||
|
SET( SAMPLES_SHARED_CODE_DIR ${SAMPLES_DIR}/SharedCode )
|
||||||
IF ( WIN32 )
|
IF ( WIN32 )
|
||||||
ADD_SUBDIRECTORY( samples/SimpleTexturedOpenGL/ )
|
ADD_SUBDIRECTORY( samples/SimpleTexturedOpenGL/ )
|
||||||
ADD_SUBDIRECTORY( samples/SimpleTexturedDirectx11 )
|
ADD_SUBDIRECTORY( samples/SimpleTexturedDirectx11 )
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -43,45 +41,43 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
/** @file Implementation of BaseProcess */
|
/** @file Implementation of BaseProcess */
|
||||||
|
|
||||||
#include <assimp/BaseImporter.h>
|
|
||||||
#include "BaseProcess.h"
|
#include "BaseProcess.h"
|
||||||
#include <assimp/DefaultLogger.hpp>
|
|
||||||
#include <assimp/scene.h>
|
|
||||||
#include "Importer.h"
|
#include "Importer.h"
|
||||||
|
#include <assimp/BaseImporter.h>
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor to be privately used by Importer
|
// Constructor to be privately used by Importer
|
||||||
BaseProcess::BaseProcess() AI_NO_EXCEPT
|
BaseProcess::BaseProcess() AI_NO_EXCEPT
|
||||||
: shared()
|
: shared(),
|
||||||
, progress()
|
progress() {
|
||||||
{
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Destructor, private as well
|
// Destructor, private as well
|
||||||
BaseProcess::~BaseProcess()
|
BaseProcess::~BaseProcess() {
|
||||||
{
|
|
||||||
// nothing to do here
|
// nothing to do here
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void BaseProcess::ExecuteOnScene( Importer* pImp)
|
void BaseProcess::ExecuteOnScene(Importer *pImp) {
|
||||||
{
|
ai_assert( nullptr != pImp );
|
||||||
ai_assert(NULL != pImp && NULL != pImp->Pimpl()->mScene);
|
ai_assert( nullptr != pImp->Pimpl()->mScene);
|
||||||
|
|
||||||
progress = pImp->GetProgressHandler();
|
progress = pImp->GetProgressHandler();
|
||||||
ai_assert(progress);
|
ai_assert(nullptr != progress);
|
||||||
|
|
||||||
SetupProperties( pImp );
|
SetupProperties(pImp);
|
||||||
|
|
||||||
// catch exceptions thrown inside the PostProcess-Step
|
// catch exceptions thrown inside the PostProcess-Step
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
Execute(pImp->Pimpl()->mScene);
|
Execute(pImp->Pimpl()->mScene);
|
||||||
|
|
||||||
} catch( const std::exception& err ) {
|
} catch (const std::exception &err) {
|
||||||
|
|
||||||
// extract error description
|
// extract error description
|
||||||
pImp->Pimpl()->mErrorString = err.what();
|
pImp->Pimpl()->mErrorString = err.what();
|
||||||
|
@ -94,14 +90,11 @@ void BaseProcess::ExecuteOnScene( Importer* pImp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void BaseProcess::SetupProperties(const Importer* /*pImp*/)
|
void BaseProcess::SetupProperties(const Importer * /*pImp*/) {
|
||||||
{
|
|
||||||
// the default implementation does nothing
|
// the default implementation does nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
bool BaseProcess::RequireVerboseFormat() const
|
bool BaseProcess::RequireVerboseFormat() const {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -44,12 +43,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef INCLUDED_AI_BASEPROCESS_H
|
#ifndef INCLUDED_AI_BASEPROCESS_H
|
||||||
#define INCLUDED_AI_BASEPROCESS_H
|
#define INCLUDED_AI_BASEPROCESS_H
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <assimp/GenericProperty.h>
|
#include <assimp/GenericProperty.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
struct aiScene;
|
struct aiScene;
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
class Importer;
|
class Importer;
|
||||||
|
|
||||||
|
@ -60,64 +60,50 @@ class Importer;
|
||||||
* to provide additional information to other steps. This is primarily
|
* to provide additional information to other steps. This is primarily
|
||||||
* intended for cross-step optimizations.
|
* intended for cross-step optimizations.
|
||||||
*/
|
*/
|
||||||
class SharedPostProcessInfo
|
class SharedPostProcessInfo {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
struct Base {
|
||||||
struct Base
|
virtual ~Base() {}
|
||||||
{
|
|
||||||
virtual ~Base()
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Represents data that is allocated on the heap, thus needs to be deleted
|
//! Represents data that is allocated on the heap, thus needs to be deleted
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct THeapData : public Base
|
struct THeapData : public Base {
|
||||||
{
|
explicit THeapData(T *in) :
|
||||||
explicit THeapData(T* in)
|
data(in) {}
|
||||||
: data (in)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~THeapData()
|
~THeapData() {
|
||||||
{
|
|
||||||
delete data;
|
delete data;
|
||||||
}
|
}
|
||||||
T* data;
|
T *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Represents static, by-value data not allocated on the heap
|
//! Represents static, by-value data not allocated on the heap
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TStaticData : public Base
|
struct TStaticData : public Base {
|
||||||
{
|
explicit TStaticData(T in) :
|
||||||
explicit TStaticData(T in)
|
data(in) {}
|
||||||
: data (in)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~TStaticData()
|
~TStaticData() {}
|
||||||
{}
|
|
||||||
|
|
||||||
T data;
|
T data;
|
||||||
};
|
};
|
||||||
|
|
||||||
// some typedefs for cleaner code
|
// some typedefs for cleaner code
|
||||||
typedef unsigned int KeyType;
|
typedef unsigned int KeyType;
|
||||||
typedef std::map<KeyType, Base*> PropertyMap;
|
typedef std::map<KeyType, Base *> PropertyMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
~SharedPostProcessInfo()
|
~SharedPostProcessInfo() {
|
||||||
{
|
|
||||||
Clean();
|
Clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Remove all stored properties from the table
|
//! Remove all stored properties from the table
|
||||||
void Clean()
|
void Clean() {
|
||||||
{
|
|
||||||
// invoke the virtual destructor for all stored properties
|
// invoke the virtual destructor for all stored properties
|
||||||
for (PropertyMap::iterator it = pmap.begin(), end = pmap.end();
|
for (PropertyMap::iterator it = pmap.begin(), end = pmap.end();
|
||||||
it != end; ++it)
|
it != end; ++it) {
|
||||||
{
|
|
||||||
delete (*it).second;
|
delete (*it).second;
|
||||||
}
|
}
|
||||||
pmap.clear();
|
pmap.clear();
|
||||||
|
@ -125,24 +111,21 @@ public:
|
||||||
|
|
||||||
//! Add a heap property to the list
|
//! Add a heap property to the list
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void AddProperty( const char* name, T* in ){
|
void AddProperty(const char *name, T *in) {
|
||||||
AddProperty(name,(Base*)new THeapData<T>(in));
|
AddProperty(name, (Base *)new THeapData<T>(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Add a static by-value property to the list
|
//! Add a static by-value property to the list
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void AddProperty( const char* name, T in ){
|
void AddProperty(const char *name, T in) {
|
||||||
AddProperty(name,(Base*)new TStaticData<T>(in));
|
AddProperty(name, (Base *)new TStaticData<T>(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Get a heap property
|
//! Get a heap property
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool GetProperty( const char* name, T*& out ) const
|
bool GetProperty(const char *name, T *&out) const {
|
||||||
{
|
THeapData<T> *t = (THeapData<T> *)GetPropertyInternal(name);
|
||||||
THeapData<T>* t = (THeapData<T>*)GetPropertyInternal(name);
|
if (!t) {
|
||||||
if(!t)
|
|
||||||
{
|
|
||||||
out = NULL;
|
out = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -152,53 +135,34 @@ public:
|
||||||
|
|
||||||
//! Get a static, by-value property
|
//! Get a static, by-value property
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool GetProperty( const char* name, T& out ) const
|
bool GetProperty(const char *name, T &out) const {
|
||||||
{
|
TStaticData<T> *t = (TStaticData<T> *)GetPropertyInternal(name);
|
||||||
TStaticData<T>* t = (TStaticData<T>*)GetPropertyInternal(name);
|
if ( nullptr == t) {
|
||||||
if(!t)return false;
|
return false;
|
||||||
|
}
|
||||||
out = t->data;
|
out = t->data;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Remove a property of a specific type
|
//! Remove a property of a specific type
|
||||||
void RemoveProperty( const char* name) {
|
void RemoveProperty(const char *name) {
|
||||||
SetGenericPropertyPtr<Base>(pmap,name,NULL);
|
SetGenericPropertyPtr<Base>(pmap, name, nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void AddProperty(const char *name, Base *data) {
|
||||||
void AddProperty( const char* name, Base* data) {
|
SetGenericPropertyPtr<Base>(pmap, name, data);
|
||||||
SetGenericPropertyPtr<Base>(pmap,name,data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Base* GetPropertyInternal( const char* name) const {
|
Base *GetPropertyInternal(const char *name) const {
|
||||||
return GetGenericProperty<Base*>(pmap,name,NULL);
|
return GetGenericProperty<Base *>(pmap, name, nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! Map of all stored properties
|
//! Map of all stored properties
|
||||||
PropertyMap pmap;
|
PropertyMap pmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
/** @brief Represents a dependency table for a postprocessing steps.
|
|
||||||
*
|
|
||||||
* For future use.
|
|
||||||
*/
|
|
||||||
struct PPDependencyTable
|
|
||||||
{
|
|
||||||
unsigned int execute_me_before_these;
|
|
||||||
unsigned int execute_me_after_these;
|
|
||||||
unsigned int only_if_these_are_not_specified;
|
|
||||||
unsigned int mutually_exclusive_with;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define AI_SPP_SPATIAL_SORT "$Spat"
|
#define AI_SPP_SPATIAL_SORT "$Spat"
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@ -228,7 +192,7 @@ public:
|
||||||
* @return true if the process is present in this flag fields,
|
* @return true if the process is present in this flag fields,
|
||||||
* false if not.
|
* false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool IsActive( unsigned int pFlags) const = 0;
|
virtual bool IsActive(unsigned int pFlags) const = 0;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Check whether this step expects its input vertex data to be
|
/** Check whether this step expects its input vertex data to be
|
||||||
|
@ -241,14 +205,14 @@ public:
|
||||||
* the object pointer will be set to NULL).
|
* the object pointer will be set to NULL).
|
||||||
* @param pImp Importer instance (pImp->mScene must be valid)
|
* @param pImp Importer instance (pImp->mScene must be valid)
|
||||||
*/
|
*/
|
||||||
void ExecuteOnScene( Importer* pImp);
|
void ExecuteOnScene(Importer *pImp);
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Called prior to ExecuteOnScene().
|
/** Called prior to ExecuteOnScene().
|
||||||
* The function is a request to the process to update its configuration
|
* The function is a request to the process to update its configuration
|
||||||
* basing on the Importer's configuration property list.
|
* basing on the Importer's configuration property list.
|
||||||
*/
|
*/
|
||||||
virtual void SetupProperties(const Importer* pImp);
|
virtual void SetupProperties(const Importer *pImp);
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Executes the post processing step on the given imported data.
|
/** Executes the post processing step on the given imported data.
|
||||||
|
@ -256,35 +220,32 @@ public:
|
||||||
* This method must be implemented by deriving classes.
|
* This method must be implemented by deriving classes.
|
||||||
* @param pScene The imported data to work at.
|
* @param pScene The imported data to work at.
|
||||||
*/
|
*/
|
||||||
virtual void Execute( aiScene* pScene) = 0;
|
virtual void Execute(aiScene *pScene) = 0;
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Assign a new SharedPostProcessInfo to the step. This object
|
/** Assign a new SharedPostProcessInfo to the step. This object
|
||||||
* allows multiple postprocess steps to share data.
|
* allows multiple postprocess steps to share data.
|
||||||
* @param sh May be NULL
|
* @param sh May be NULL
|
||||||
*/
|
*/
|
||||||
inline void SetSharedData(SharedPostProcessInfo* sh) {
|
inline void SetSharedData(SharedPostProcessInfo *sh) {
|
||||||
shared = sh;
|
shared = sh;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Get the shared data that is assigned to the step.
|
/** Get the shared data that is assigned to the step.
|
||||||
*/
|
*/
|
||||||
inline SharedPostProcessInfo* GetSharedData() {
|
inline SharedPostProcessInfo *GetSharedData() {
|
||||||
return shared;
|
return shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** See the doc of #SharedPostProcessInfo for more details */
|
/** See the doc of #SharedPostProcessInfo for more details */
|
||||||
SharedPostProcessInfo* shared;
|
SharedPostProcessInfo *shared;
|
||||||
|
|
||||||
/** Currently active progress handler */
|
/** Currently active progress handler */
|
||||||
ProgressHandler* progress;
|
ProgressHandler *progress;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
||||||
#endif // AI_BASEPROCESS_H_INC
|
#endif // AI_BASEPROCESS_H_INC
|
||||||
|
|
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
project(zip
|
project(zip
|
||||||
LANGUAGES C
|
LANGUAGES C
|
||||||
VERSION "0.1.15")
|
VERSION "0.1.18")
|
||||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||||
|
|
||||||
option(CMAKE_DISABLE_TESTING "Disable test creation" OFF)
|
option(CMAKE_DISABLE_TESTING "Disable test creation" OFF)
|
||||||
|
@ -16,10 +16,6 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
|
||||||
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
|
||||||
"${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
|
"${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror -pedantic")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror -pedantic")
|
||||||
if(ENABLE_COVERAGE)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
|
|
||||||
endif()
|
|
||||||
endif (MSVC)
|
endif (MSVC)
|
||||||
|
|
||||||
# zip
|
# zip
|
||||||
|
@ -35,7 +31,7 @@ if (NOT CMAKE_DISABLE_TESTING)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
find_package(Sanitizers)
|
find_package(Sanitizers)
|
||||||
add_sanitizers(${PROJECT_NAME} ${test_out} ${test_miniz_out})
|
add_sanitizers(${PROJECT_NAME} ${test_out})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
####
|
####
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
### A portable (OSX/Linux/Windows), simple zip library written in C
|
### A portable (OSX/Linux/Windows), simple zip library written in C
|
||||||
This is done by hacking awesome [miniz](https://code.google.com/p/miniz) library and layering functions on top of the miniz v1.15 API.
|
This is done by hacking awesome [miniz](https://code.google.com/p/miniz) library and layering functions on top of the miniz v1.15 API.
|
||||||
|
|
||||||
[![Windows](https://ci.appveyor.com/api/projects/status/bph8dr3jacgmjv32/branch/master?svg=true&label=windows)](https://ci.appveyor.com/project/kuba--/zip)
|
[![Build](https://github.com/kuba--/zip/workflows/build/badge.svg)](https://github.com/kuba--/zip/actions?query=workflow%3Abuild)
|
||||||
[![Linux](https://travis-ci.org/kuba--/zip.svg?branch=master&label=linux%2fosx)](https://travis-ci.org/kuba--/zip)
|
|
||||||
[![Version](https://badge.fury.io/gh/kuba--%2Fzip.svg)](https://github.com/kuba--/zip/releases)
|
[![Version](https://badge.fury.io/gh/kuba--%2Fzip.svg)](https://github.com/kuba--/zip/releases)
|
||||||
[![Codecov](https://codecov.io/gh/kuba--/zip/branch/master/graph/badge.svg)](https://codecov.io/gh/kuba--/zip)
|
|
||||||
|
|
||||||
|
|
||||||
# The Idea
|
# The Idea
|
||||||
|
@ -213,6 +211,53 @@ func main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Rust (ffi)
|
||||||
|
```rust
|
||||||
|
extern crate libc;
|
||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct Zip {
|
||||||
|
_private: [u8; 0],
|
||||||
|
}
|
||||||
|
|
||||||
|
#[link(name = "zip")]
|
||||||
|
extern "C" {
|
||||||
|
fn zip_open(path: *const libc::c_char, level: libc::c_int, mode: libc::c_char) -> *mut Zip;
|
||||||
|
fn zip_close(zip: *mut Zip) -> libc::c_void;
|
||||||
|
|
||||||
|
fn zip_entry_open(zip: *mut Zip, entryname: *const libc::c_char) -> libc::c_int;
|
||||||
|
fn zip_entry_close(zip: *mut Zip) -> libc::c_int;
|
||||||
|
fn zip_entry_write(
|
||||||
|
zip: *mut Zip,
|
||||||
|
buf: *const libc::c_void,
|
||||||
|
bufsize: libc::size_t,
|
||||||
|
) -> libc::c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let path = CString::new("/tmp/test.zip").unwrap();
|
||||||
|
let mode: libc::c_char = 'w' as libc::c_char;
|
||||||
|
|
||||||
|
let entryname = CString::new("test.txt").unwrap();
|
||||||
|
let content = "test content\0";
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let zip: *mut Zip = zip_open(path.as_ptr(), 5, mode);
|
||||||
|
{
|
||||||
|
zip_entry_open(zip, entryname.as_ptr());
|
||||||
|
{
|
||||||
|
let buf = content.as_ptr() as *const libc::c_void;
|
||||||
|
let bufsize = content.len() as libc::size_t;
|
||||||
|
zip_entry_write(zip, buf, bufsize);
|
||||||
|
}
|
||||||
|
zip_entry_close(zip);
|
||||||
|
}
|
||||||
|
zip_close(zip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Ruby (ffi)
|
### Ruby (ffi)
|
||||||
Install _ffi_ gem.
|
Install _ffi_ gem.
|
||||||
```shell
|
```shell
|
||||||
|
|
|
@ -222,6 +222,20 @@ void zip_close(struct zip_t *zip) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int zip_is64(struct zip_t *zip) {
|
||||||
|
if (!zip) {
|
||||||
|
// zip_t handler is not initialized
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!zip->archive.m_pState) {
|
||||||
|
// zip state is not initialized
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)zip->archive.m_pState->m_zip64;
|
||||||
|
}
|
||||||
|
|
||||||
int zip_entry_open(struct zip_t *zip, const char *entryname) {
|
int zip_entry_open(struct zip_t *zip, const char *entryname) {
|
||||||
size_t entrylen = 0;
|
size_t entrylen = 0;
|
||||||
mz_zip_archive *pzip = NULL;
|
mz_zip_archive *pzip = NULL;
|
||||||
|
@ -794,7 +808,8 @@ int zip_create(const char *zipname, const char *filenames[], size_t len) {
|
||||||
|
|
||||||
if (MZ_FILE_STAT(name, &file_stat) != 0) {
|
if (MZ_FILE_STAT(name, &file_stat) != 0) {
|
||||||
// problem getting information - check errno
|
// problem getting information - check errno
|
||||||
return -1;
|
status = -1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((file_stat.st_mode & 0200) == 0) {
|
if ((file_stat.st_mode & 0200) == 0) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ extern "C" {
|
||||||
|
|
||||||
#if !defined(_SSIZE_T_DEFINED) && !defined(_SSIZE_T_DEFINED_) && \
|
#if !defined(_SSIZE_T_DEFINED) && !defined(_SSIZE_T_DEFINED_) && \
|
||||||
!defined(__DEFINED_ssize_t) && !defined(__ssize_t_defined) && \
|
!defined(__DEFINED_ssize_t) && !defined(__ssize_t_defined) && \
|
||||||
!defined(_SSIZE_T) && !defined(_SSIZE_T_)
|
!defined(_SSIZE_T) && !defined(_SSIZE_T_) && !defined(_SSIZE_T_DECLARED)
|
||||||
|
|
||||||
// 64-bit Windows is the only mainstream platform
|
// 64-bit Windows is the only mainstream platform
|
||||||
// where sizeof(long) != sizeof(void*)
|
// where sizeof(long) != sizeof(void*)
|
||||||
|
@ -37,6 +37,7 @@ typedef long ssize_t; /* byte count or error */
|
||||||
#define __ssize_t_defined
|
#define __ssize_t_defined
|
||||||
#define _SSIZE_T
|
#define _SSIZE_T
|
||||||
#define _SSIZE_T_
|
#define _SSIZE_T_
|
||||||
|
#define _SSIZE_T_DECLARED
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -90,6 +91,16 @@ extern struct zip_t *zip_open(const char *zipname, int level, char mode);
|
||||||
*/
|
*/
|
||||||
extern void zip_close(struct zip_t *zip);
|
extern void zip_close(struct zip_t *zip);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the archive has a zip64 end of central directory headers.
|
||||||
|
*
|
||||||
|
* @param zip zip archive handler.
|
||||||
|
*
|
||||||
|
* @return the return code - 1 (true), 0 (false), negative number (< 0) on
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
extern int zip_is64(struct zip_t *zip);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens an entry by name in the zip archive.
|
* Opens an entry by name in the zip archive.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,15 +2,10 @@ cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
# test
|
# test
|
||||||
set(test_out test.out)
|
set(test_out test.out)
|
||||||
set(test_miniz_out test_miniz.out)
|
|
||||||
|
|
||||||
add_executable(${test_out} test.c)
|
add_executable(${test_out} test.c)
|
||||||
target_link_libraries(${test_out} zip)
|
target_link_libraries(${test_out} zip)
|
||||||
add_executable(${test_miniz_out} test_miniz.c)
|
|
||||||
target_link_libraries(${test_miniz_out} zip)
|
|
||||||
|
|
||||||
add_test(NAME ${test_out} COMMAND ${test_out})
|
add_test(NAME ${test_out} COMMAND ${test_out})
|
||||||
add_test(NAME ${test_miniz_out} COMMAND ${test_miniz_out})
|
|
||||||
|
|
||||||
set(test_out ${test_out} PARENT_SCOPE)
|
set(test_out ${test_out} PARENT_SCOPE)
|
||||||
set(test_miniz_out ${test_miniz_out} PARENT_SCOPE)
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ static void test_write(void) {
|
||||||
assert(CRC32DATA1 == zip_entry_crc32(zip));
|
assert(CRC32DATA1 == zip_entry_crc32(zip));
|
||||||
++total_entries;
|
++total_entries;
|
||||||
assert(0 == zip_entry_close(zip));
|
assert(0 == zip_entry_close(zip));
|
||||||
|
assert(0 == zip_is64(zip));
|
||||||
zip_close(zip);
|
zip_close(zip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ static void test_read(void) {
|
||||||
size_t buftmp;
|
size_t buftmp;
|
||||||
struct zip_t *zip = zip_open(ZIPNAME, 0, 'r');
|
struct zip_t *zip = zip_open(ZIPNAME, 0, 'r');
|
||||||
assert(zip != NULL);
|
assert(zip != NULL);
|
||||||
|
assert(0 == zip_is64(zip));
|
||||||
|
|
||||||
assert(0 == zip_entry_open(zip, "test\\test-1.txt"));
|
assert(0 == zip_entry_open(zip, "test\\test-1.txt"));
|
||||||
assert(strlen(TESTDATA1) == zip_entry_size(zip));
|
assert(strlen(TESTDATA1) == zip_entry_size(zip));
|
||||||
|
@ -310,6 +311,7 @@ static void test_fwrite(void) {
|
||||||
assert(0 == zip_entry_open(zip, WFILE));
|
assert(0 == zip_entry_open(zip, WFILE));
|
||||||
assert(0 == zip_entry_fwrite(zip, WFILE));
|
assert(0 == zip_entry_fwrite(zip, WFILE));
|
||||||
assert(0 == zip_entry_close(zip));
|
assert(0 == zip_entry_close(zip));
|
||||||
|
assert(0 == zip_is64(zip));
|
||||||
|
|
||||||
zip_close(zip);
|
zip_close(zip);
|
||||||
remove(WFILE);
|
remove(WFILE);
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -45,26 +44,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define AI_GENERIC_PROPERTY_H_INCLUDED
|
#define AI_GENERIC_PROPERTY_H_INCLUDED
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
# pragma GCC system_header
|
# pragma GCC system_header
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <assimp/Importer.hpp>
|
|
||||||
#include <assimp/ai_assert.h>
|
|
||||||
#include <assimp/Hash.h>
|
#include <assimp/Hash.h>
|
||||||
|
#include <assimp/ai_assert.h>
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline bool SetGenericProperty(std::map<unsigned int, T> &list,
|
||||||
bool SetGenericProperty(std::map< unsigned int, T >& list,
|
const char *szName, const T &value) {
|
||||||
const char* szName, const T& value) {
|
|
||||||
ai_assert(nullptr != szName);
|
ai_assert(nullptr != szName);
|
||||||
const uint32_t hash = SuperFastHash(szName);
|
const uint32_t hash = SuperFastHash(szName);
|
||||||
|
|
||||||
typename std::map<unsigned int, T>::iterator it = list.find(hash);
|
typename std::map<unsigned int, T>::iterator it = list.find(hash);
|
||||||
if (it == list.end()) {
|
if (it == list.end()) {
|
||||||
list.insert(std::pair<unsigned int, T>( hash, value ));
|
list.insert(std::pair<unsigned int, T>(hash, value));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
(*it).second = value;
|
(*it).second = value;
|
||||||
|
@ -74,9 +72,8 @@ bool SetGenericProperty(std::map< unsigned int, T >& list,
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline const T &GetGenericProperty(const std::map<unsigned int, T> &list,
|
||||||
const T& GetGenericProperty(const std::map< unsigned int, T >& list,
|
const char *szName, const T &errorReturn) {
|
||||||
const char* szName, const T& errorReturn) {
|
|
||||||
ai_assert(nullptr != szName);
|
ai_assert(nullptr != szName);
|
||||||
const uint32_t hash = SuperFastHash(szName);
|
const uint32_t hash = SuperFastHash(szName);
|
||||||
|
|
||||||
|
@ -92,22 +89,21 @@ const T& GetGenericProperty(const std::map< unsigned int, T >& list,
|
||||||
// Special version for pointer types - they will be deleted when replaced with another value
|
// Special version for pointer types - they will be deleted when replaced with another value
|
||||||
// passing NULL removes the whole property
|
// passing NULL removes the whole property
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline void SetGenericPropertyPtr(std::map<unsigned int, T *> &list,
|
||||||
void SetGenericPropertyPtr(std::map< unsigned int, T* >& list,
|
const char *szName, T *value, bool *bWasExisting = nullptr) {
|
||||||
const char* szName, T* value, bool* bWasExisting = nullptr ) {
|
|
||||||
ai_assert(nullptr != szName);
|
ai_assert(nullptr != szName);
|
||||||
const uint32_t hash = SuperFastHash(szName);
|
const uint32_t hash = SuperFastHash(szName);
|
||||||
|
|
||||||
typename std::map<unsigned int, T*>::iterator it = list.find(hash);
|
typename std::map<unsigned int, T *>::iterator it = list.find(hash);
|
||||||
if (it == list.end()) {
|
if (it == list.end()) {
|
||||||
if (bWasExisting) {
|
if (bWasExisting) {
|
||||||
*bWasExisting = false;
|
*bWasExisting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
list.insert(std::pair<unsigned int,T*>( hash, value ));
|
list.insert(std::pair<unsigned int, T *>(hash, value));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((*it).second != value) {
|
if ((*it).second != value) {
|
||||||
delete (*it).second;
|
delete (*it).second;
|
||||||
(*it).second = value;
|
(*it).second = value;
|
||||||
}
|
}
|
||||||
|
@ -121,9 +117,8 @@ void SetGenericPropertyPtr(std::map< unsigned int, T* >& list,
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
template <class T>
|
template <class T>
|
||||||
inline
|
inline bool HasGenericProperty(const std::map<unsigned int, T> &list,
|
||||||
bool HasGenericProperty(const std::map< unsigned int, T >& list,
|
const char *szName) {
|
||||||
const char* szName) {
|
|
||||||
ai_assert(nullptr != szName);
|
ai_assert(nullptr != szName);
|
||||||
const uint32_t hash = SuperFastHash(szName);
|
const uint32_t hash = SuperFastHash(szName);
|
||||||
|
|
||||||
|
|
|
@ -93,10 +93,10 @@ public:
|
||||||
const TReal* operator[] (unsigned int p_iIndex) const;
|
const TReal* operator[] (unsigned int p_iIndex) const;
|
||||||
|
|
||||||
// comparison operators
|
// comparison operators
|
||||||
bool operator== (const aiMatrix4x4t<TReal>& m) const;
|
bool operator== (const aiMatrix3x3t<TReal>& m) const;
|
||||||
bool operator!= (const aiMatrix4x4t<TReal>& m) const;
|
bool operator!= (const aiMatrix3x3t<TReal>& m) const;
|
||||||
|
|
||||||
bool Equal(const aiMatrix4x4t<TReal>& m, TReal epsilon = 1e-6) const;
|
bool Equal(const aiMatrix3x3t<TReal>& m, TReal epsilon = 1e-6) const;
|
||||||
|
|
||||||
template <typename TOther>
|
template <typename TOther>
|
||||||
operator aiMatrix3x3t<TOther> () const;
|
operator aiMatrix3x3t<TOther> () const;
|
||||||
|
|
|
@ -141,7 +141,7 @@ const TReal* aiMatrix3x3t<TReal>::operator[] (unsigned int p_iIndex) const {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
template <typename TReal>
|
template <typename TReal>
|
||||||
AI_FORCE_INLINE
|
AI_FORCE_INLINE
|
||||||
bool aiMatrix3x3t<TReal>::operator== (const aiMatrix4x4t<TReal>& m) const {
|
bool aiMatrix3x3t<TReal>::operator== (const aiMatrix3x3t<TReal>& m) const {
|
||||||
return a1 == m.a1 && a2 == m.a2 && a3 == m.a3 &&
|
return a1 == m.a1 && a2 == m.a2 && a3 == m.a3 &&
|
||||||
b1 == m.b1 && b2 == m.b2 && b3 == m.b3 &&
|
b1 == m.b1 && b2 == m.b2 && b3 == m.b3 &&
|
||||||
c1 == m.c1 && c2 == m.c2 && c3 == m.c3;
|
c1 == m.c1 && c2 == m.c2 && c3 == m.c3;
|
||||||
|
@ -150,14 +150,14 @@ bool aiMatrix3x3t<TReal>::operator== (const aiMatrix4x4t<TReal>& m) const {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
template <typename TReal>
|
template <typename TReal>
|
||||||
AI_FORCE_INLINE
|
AI_FORCE_INLINE
|
||||||
bool aiMatrix3x3t<TReal>::operator!= (const aiMatrix4x4t<TReal>& m) const {
|
bool aiMatrix3x3t<TReal>::operator!= (const aiMatrix3x3t<TReal>& m) const {
|
||||||
return !(*this == m);
|
return !(*this == m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
template<typename TReal>
|
template<typename TReal>
|
||||||
AI_FORCE_INLINE
|
AI_FORCE_INLINE
|
||||||
bool aiMatrix3x3t<TReal>::Equal(const aiMatrix4x4t<TReal>& m, TReal epsilon) const {
|
bool aiMatrix3x3t<TReal>::Equal(const aiMatrix3x3t<TReal>& m, TReal epsilon) const {
|
||||||
return
|
return
|
||||||
std::abs(a1 - m.a1) <= epsilon &&
|
std::abs(a1 - m.a1) <= epsilon &&
|
||||||
std::abs(a2 - m.a2) <= epsilon &&
|
std::abs(a2 - m.a2) <= epsilon &&
|
||||||
|
|
|
@ -138,7 +138,7 @@ def _init(self, target = None, parent = None):
|
||||||
logger.debug(str(self) + ": Added array " + str(getattr(target, name)) + " as self." + name.lower())
|
logger.debug(str(self) + ": Added array " + str(getattr(target, name)) + " as self." + name.lower())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if m.startswith('m'):
|
if m.startswith('m') and len(m) > 1 and m[1].upper() == m[1]:
|
||||||
|
|
||||||
if name == "parent":
|
if name == "parent":
|
||||||
setattr(target, name, parent)
|
setattr(target, name, parent)
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
with or without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the assimp team, nor the names of its
|
||||||
|
contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior
|
||||||
|
written permission of the assimp team.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UTFConverter.h"
|
||||||
|
|
||||||
|
namespace AssimpSamples {
|
||||||
|
namespace SharedCode {
|
||||||
|
|
||||||
|
typename UTFConverter::UTFConverterImpl UTFConverter::impl_;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
with or without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the assimp team, nor the names of its
|
||||||
|
contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior
|
||||||
|
written permission of the assimp team.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ASSIMP_SAMPLES_SHARED_CODE_UTFCONVERTER_H
|
||||||
|
#define ASSIMP_SAMPLES_SHARED_CODE_UTFCONVERTER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <locale>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
|
namespace AssimpSamples {
|
||||||
|
namespace SharedCode {
|
||||||
|
|
||||||
|
// Used to convert between multibyte and unicode strings.
|
||||||
|
class UTFConverter {
|
||||||
|
using UTFConverterImpl = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>;
|
||||||
|
public:
|
||||||
|
UTFConverter(const char* s) :
|
||||||
|
s_(s),
|
||||||
|
ws_(impl_.from_bytes(s)) {
|
||||||
|
}
|
||||||
|
UTFConverter(const wchar_t* s) :
|
||||||
|
s_(impl_.to_bytes(s)),
|
||||||
|
ws_(s) {
|
||||||
|
}
|
||||||
|
UTFConverter(const std::string& s) :
|
||||||
|
s_(s),
|
||||||
|
ws_(impl_.from_bytes(s)) {
|
||||||
|
}
|
||||||
|
UTFConverter(const std::wstring& s) :
|
||||||
|
s_(impl_.to_bytes(s)),
|
||||||
|
ws_(s) {
|
||||||
|
}
|
||||||
|
inline const char* c_str() const {
|
||||||
|
return s_.c_str();
|
||||||
|
}
|
||||||
|
inline const std::string& str() const {
|
||||||
|
return s_;
|
||||||
|
}
|
||||||
|
inline const wchar_t* c_wstr() const {
|
||||||
|
return ws_.c_str();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
static UTFConverterImpl impl_;
|
||||||
|
std::string s_;
|
||||||
|
std::wstring ws_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ASSIMP_SAMPLES_SHARED_CODE_UTFCONVERTER_H
|
|
@ -10,12 +10,12 @@ if ( MSVC )
|
||||||
REMOVE_DEFINITIONS( -DUNICODE -D_UNICODE )
|
REMOVE_DEFINITIONS( -DUNICODE -D_UNICODE )
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
ADD_COMPILE_DEFINITIONS(SHADER_PATH="${CMAKE_CURRENT_SOURCE_DIR}/SimpleTexturedDirectx11/")
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(
|
INCLUDE_DIRECTORIES(
|
||||||
${Assimp_SOURCE_DIR}/include
|
${Assimp_SOURCE_DIR}/include
|
||||||
${Assimp_SOURCE_DIR}/code
|
${Assimp_SOURCE_DIR}/code
|
||||||
${OPENGL_INCLUDE_DIR}
|
${SAMPLES_SHARED_CODE_DIR}
|
||||||
${GLUT_INCLUDE_DIR}
|
|
||||||
${Assimp_SOURCE_DIR}/samples/freeglut/include
|
|
||||||
)
|
)
|
||||||
|
|
||||||
LINK_DIRECTORIES(
|
LINK_DIRECTORIES(
|
||||||
|
@ -32,6 +32,9 @@ ADD_EXECUTABLE( assimp_simpletextureddirectx11 WIN32
|
||||||
SimpleTexturedDirectx11/TextureLoader.h
|
SimpleTexturedDirectx11/TextureLoader.h
|
||||||
#SimpleTexturedDirectx11/VertexShader.hlsl
|
#SimpleTexturedDirectx11/VertexShader.hlsl
|
||||||
SimpleTexturedDirectx11/main.cpp
|
SimpleTexturedDirectx11/main.cpp
|
||||||
|
SimpleTexturedDirectx11/SafeRelease.hpp
|
||||||
|
${SAMPLES_SHARED_CODE_DIR}/UTFConverter.cpp
|
||||||
|
${SAMPLES_SHARED_CODE_DIR}/UTFConverter.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET_PROPERTY(TARGET assimp_simpletextureddirectx11 PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
SET_PROPERTY(TARGET assimp_simpletextureddirectx11 PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||||
|
|
|
@ -6,13 +6,14 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using namespace std;
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <d3d11_1.h>
|
#include <d3d11_1.h>
|
||||||
#include <DirectXMath.h>
|
#include <DirectXMath.h>
|
||||||
|
|
||||||
using namespace DirectX;
|
using namespace DirectX;
|
||||||
|
|
||||||
|
#include "SafeRelease.hpp"
|
||||||
|
|
||||||
struct VERTEX {
|
struct VERTEX {
|
||||||
FLOAT X, Y, Z;
|
FLOAT X, Y, Z;
|
||||||
XMFLOAT2 texcoord;
|
XMFLOAT2 texcoord;
|
||||||
|
@ -22,81 +23,85 @@ struct Texture {
|
||||||
string type;
|
string type;
|
||||||
string path;
|
string path;
|
||||||
ID3D11ShaderResourceView *texture;
|
ID3D11ShaderResourceView *texture;
|
||||||
|
|
||||||
|
void Release() {
|
||||||
|
SafeRelease(texture);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Mesh {
|
class Mesh {
|
||||||
public:
|
public:
|
||||||
vector<VERTEX> vertices;
|
std::vector<VERTEX> vertices;
|
||||||
vector<UINT> indices;
|
std::vector<UINT> indices;
|
||||||
vector<Texture> textures;
|
std::vector<Texture> textures;
|
||||||
ID3D11Device *dev;
|
ID3D11Device *dev;
|
||||||
|
|
||||||
Mesh(ID3D11Device *dev, vector<VERTEX> vertices, vector<UINT> indices, vector<Texture> textures)
|
Mesh(ID3D11Device *dev, const vector<VERTEX>& vertices, const vector<UINT>& indices, const vector<Texture>& textures) :
|
||||||
{
|
vertices(vertices),
|
||||||
this->vertices = vertices;
|
indices(indices),
|
||||||
this->indices = indices;
|
textures(textures),
|
||||||
this->textures = textures;
|
dev(dev),
|
||||||
|
VertexBuffer(nullptr),
|
||||||
|
IndexBuffer(nullptr) {
|
||||||
|
this->setupMesh(this->dev);
|
||||||
|
}
|
||||||
|
|
||||||
this->dev = dev;
|
void Draw(ID3D11DeviceContext *devcon) {
|
||||||
|
UINT stride = sizeof(VERTEX);
|
||||||
|
UINT offset = 0;
|
||||||
|
|
||||||
this->setupMesh(dev);
|
devcon->IASetVertexBuffers(0, 1, &VertexBuffer, &stride, &offset);
|
||||||
}
|
devcon->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
||||||
|
|
||||||
void Draw(ID3D11DeviceContext *devcon)
|
devcon->PSSetShaderResources(0, 1, &textures[0].texture);
|
||||||
{
|
|
||||||
UINT stride = sizeof(VERTEX);
|
|
||||||
UINT offset = 0;
|
|
||||||
|
|
||||||
devcon->IASetVertexBuffers(0, 1, &VertexBuffer, &stride, &offset);
|
devcon->DrawIndexed(static_cast<UINT>(indices.size()), 0, 0);
|
||||||
devcon->IASetIndexBuffer(IndexBuffer, DXGI_FORMAT_R32_UINT, 0);
|
}
|
||||||
|
|
||||||
devcon->PSSetShaderResources(0, 1, &textures[0].texture);
|
void Close() {
|
||||||
|
SafeRelease(VertexBuffer);
|
||||||
devcon->DrawIndexed(indices.size(), 0, 0);
|
SafeRelease(IndexBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Close()
|
|
||||||
{
|
|
||||||
VertexBuffer->Release();
|
|
||||||
IndexBuffer->Release();
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
/* Render data */
|
// Render data
|
||||||
ID3D11Buffer *VertexBuffer, *IndexBuffer;
|
ID3D11Buffer *VertexBuffer, *IndexBuffer;
|
||||||
|
|
||||||
/* Functions */
|
// Functions
|
||||||
// Initializes all the buffer objects/arrays
|
// Initializes all the buffer objects/arrays
|
||||||
bool setupMesh(ID3D11Device *dev)
|
void setupMesh(ID3D11Device *dev) {
|
||||||
{
|
HRESULT hr;
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
D3D11_BUFFER_DESC vbd;
|
D3D11_BUFFER_DESC vbd;
|
||||||
vbd.Usage = D3D11_USAGE_IMMUTABLE;
|
vbd.Usage = D3D11_USAGE_IMMUTABLE;
|
||||||
vbd.ByteWidth = sizeof(VERTEX) * vertices.size();
|
vbd.ByteWidth = static_cast<UINT>(sizeof(VERTEX) * vertices.size());
|
||||||
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||||
vbd.CPUAccessFlags = 0;
|
vbd.CPUAccessFlags = 0;
|
||||||
vbd.MiscFlags = 0;
|
vbd.MiscFlags = 0;
|
||||||
|
|
||||||
D3D11_SUBRESOURCE_DATA initData;
|
D3D11_SUBRESOURCE_DATA initData;
|
||||||
initData.pSysMem = &vertices[0];
|
initData.pSysMem = &vertices[0];
|
||||||
|
|
||||||
hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer);
|
hr = dev->CreateBuffer(&vbd, &initData, &VertexBuffer);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr)) {
|
||||||
return false;
|
Close();
|
||||||
|
throw std::runtime_error("Failed to create vertex buffer.");
|
||||||
|
}
|
||||||
|
|
||||||
D3D11_BUFFER_DESC ibd;
|
D3D11_BUFFER_DESC ibd;
|
||||||
ibd.Usage = D3D11_USAGE_IMMUTABLE;
|
ibd.Usage = D3D11_USAGE_IMMUTABLE;
|
||||||
ibd.ByteWidth = sizeof(UINT) * indices.size();
|
ibd.ByteWidth = static_cast<UINT>(sizeof(UINT) * indices.size());
|
||||||
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||||
ibd.CPUAccessFlags = 0;
|
ibd.CPUAccessFlags = 0;
|
||||||
ibd.MiscFlags = 0;
|
ibd.MiscFlags = 0;
|
||||||
|
|
||||||
initData.pSysMem = &indices[0];
|
initData.pSysMem = &indices[0];
|
||||||
|
|
||||||
hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer);
|
hr = dev->CreateBuffer(&ibd, &initData, &IndexBuffer);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr)) {
|
||||||
return false;
|
Close();
|
||||||
}
|
throw std::runtime_error("Failed to create index buffer.");
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
#include "ModelLoader.h"
|
#include "ModelLoader.h"
|
||||||
|
|
||||||
ModelLoader::ModelLoader()
|
ModelLoader::ModelLoader() :
|
||||||
{
|
dev(nullptr),
|
||||||
|
devcon(nullptr),
|
||||||
|
meshes(),
|
||||||
|
directory(),
|
||||||
|
textures_loaded(),
|
||||||
|
hwnd(nullptr) {
|
||||||
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ModelLoader::~ModelLoader()
|
ModelLoader::~ModelLoader() {
|
||||||
{
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devcon, std::string filename)
|
bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devcon, std::string filename) {
|
||||||
{
|
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
|
|
||||||
const aiScene* pScene = importer.ReadFile(filename,
|
const aiScene* pScene = importer.ReadFile(filename,
|
||||||
|
@ -20,9 +25,10 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc
|
||||||
if (pScene == NULL)
|
if (pScene == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this->directory = filename.substr(0, filename.find_last_of('/'));
|
this->directory = filename.substr(0, filename.find_last_of("/\\"));
|
||||||
|
|
||||||
this->dev = dev;
|
this->dev = dev;
|
||||||
|
this->devcon = devcon;
|
||||||
this->hwnd = hwnd;
|
this->hwnd = hwnd;
|
||||||
|
|
||||||
processNode(pScene->mRootNode, pScene);
|
processNode(pScene->mRootNode, pScene);
|
||||||
|
@ -30,41 +36,37 @@ bool ModelLoader::Load(HWND hwnd, ID3D11Device * dev, ID3D11DeviceContext * devc
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelLoader::Draw(ID3D11DeviceContext * devcon)
|
void ModelLoader::Draw(ID3D11DeviceContext * devcon) {
|
||||||
{
|
for (int i = 0; i < meshes.size(); ++i ) {
|
||||||
for (int i = 0; i < meshes.size(); i++)
|
|
||||||
{
|
|
||||||
meshes[i].Draw(devcon);
|
meshes[i].Draw(devcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string textype;
|
string textype;
|
||||||
|
|
||||||
Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene)
|
Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) {
|
||||||
{
|
|
||||||
// Data to fill
|
// Data to fill
|
||||||
vector<VERTEX> vertices;
|
vector<VERTEX> vertices;
|
||||||
vector<UINT> indices;
|
vector<UINT> indices;
|
||||||
vector<Texture> textures;
|
vector<Texture> textures;
|
||||||
|
|
||||||
if (mesh->mMaterialIndex >= 0)
|
if (mesh->mMaterialIndex >= 0) {
|
||||||
{
|
|
||||||
aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex];
|
aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex];
|
||||||
|
|
||||||
if (textype.empty()) textype = determineTextureType(scene, mat);
|
if (textype.empty()) {
|
||||||
|
textype = determineTextureType(scene, mat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk through each of the mesh's vertices
|
// Walk through each of the mesh's vertices
|
||||||
for (UINT i = 0; i < mesh->mNumVertices; i++)
|
for (UINT i = 0; i < mesh->mNumVertices; i++) {
|
||||||
{
|
|
||||||
VERTEX vertex;
|
VERTEX vertex;
|
||||||
|
|
||||||
vertex.X = mesh->mVertices[i].x;
|
vertex.X = mesh->mVertices[i].x;
|
||||||
vertex.Y = mesh->mVertices[i].y;
|
vertex.Y = mesh->mVertices[i].y;
|
||||||
vertex.Z = mesh->mVertices[i].z;
|
vertex.Z = mesh->mVertices[i].z;
|
||||||
|
|
||||||
if (mesh->mTextureCoords[0])
|
if (mesh->mTextureCoords[0]) {
|
||||||
{
|
|
||||||
vertex.texcoord.x = (float)mesh->mTextureCoords[0][i].x;
|
vertex.texcoord.x = (float)mesh->mTextureCoords[0][i].x;
|
||||||
vertex.texcoord.y = (float)mesh->mTextureCoords[0][i].y;
|
vertex.texcoord.y = (float)mesh->mTextureCoords[0][i].y;
|
||||||
}
|
}
|
||||||
|
@ -72,16 +74,14 @@ Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene)
|
||||||
vertices.push_back(vertex);
|
vertices.push_back(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UINT i = 0; i < mesh->mNumFaces; i++)
|
for (UINT i = 0; i < mesh->mNumFaces; i++) {
|
||||||
{
|
|
||||||
aiFace face = mesh->mFaces[i];
|
aiFace face = mesh->mFaces[i];
|
||||||
|
|
||||||
for (UINT j = 0; j < face.mNumIndices; j++)
|
for (UINT j = 0; j < face.mNumIndices; j++)
|
||||||
indices.push_back(face.mIndices[j]);
|
indices.push_back(face.mIndices[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mesh->mMaterialIndex >= 0)
|
if (mesh->mMaterialIndex >= 0) {
|
||||||
{
|
|
||||||
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
|
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
|
||||||
|
|
||||||
vector<Texture> diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse", scene);
|
vector<Texture> diffuseMaps = this->loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse", scene);
|
||||||
|
@ -91,35 +91,27 @@ Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene)
|
||||||
return Mesh(dev, vertices, indices, textures);
|
return Mesh(dev, vertices, indices, textures);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, string typeName, const aiScene * scene)
|
vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureType type, string typeName, const aiScene * scene) {
|
||||||
{
|
|
||||||
vector<Texture> textures;
|
vector<Texture> textures;
|
||||||
for (UINT i = 0; i < mat->GetTextureCount(type); i++)
|
for (UINT i = 0; i < mat->GetTextureCount(type); i++) {
|
||||||
{
|
|
||||||
aiString str;
|
aiString str;
|
||||||
mat->GetTexture(type, i, &str);
|
mat->GetTexture(type, i, &str);
|
||||||
// Check if texture was loaded before and if so, continue to next iteration: skip loading a new texture
|
// Check if texture was loaded before and if so, continue to next iteration: skip loading a new texture
|
||||||
bool skip = false;
|
bool skip = false;
|
||||||
for (UINT j = 0; j < textures_loaded.size(); j++)
|
for (UINT j = 0; j < textures_loaded.size(); j++) {
|
||||||
{
|
if (std::strcmp(textures_loaded[j].path.c_str(), str.C_Str()) == 0) {
|
||||||
if (std::strcmp(textures_loaded[j].path.c_str(), str.C_Str()) == 0)
|
|
||||||
{
|
|
||||||
textures.push_back(textures_loaded[j]);
|
textures.push_back(textures_loaded[j]);
|
||||||
skip = true; // A texture with the same filepath has already been loaded, continue to next one. (optimization)
|
skip = true; // A texture with the same filepath has already been loaded, continue to next one. (optimization)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!skip)
|
if (!skip) { // If texture hasn't been loaded already, load it
|
||||||
{ // If texture hasn't been loaded already, load it
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
Texture texture;
|
Texture texture;
|
||||||
if (textype == "embedded compressed texture")
|
if (textype == "embedded compressed texture") {
|
||||||
{
|
|
||||||
int textureindex = getTextureIndex(&str);
|
int textureindex = getTextureIndex(&str);
|
||||||
texture.texture = getTextureFromModel(scene, textureindex);
|
texture.texture = getTextureFromModel(scene, textureindex);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
string filename = string(str.C_Str());
|
string filename = string(str.C_Str());
|
||||||
filename = directory + '/' + filename;
|
filename = directory + '/' + filename;
|
||||||
wstring filenamews = wstring(filename.begin(), filename.end());
|
wstring filenamews = wstring(filename.begin(), filename.end());
|
||||||
|
@ -136,64 +128,52 @@ vector<Texture> ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextureTyp
|
||||||
return textures;
|
return textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelLoader::Close()
|
void ModelLoader::Close() {
|
||||||
{
|
for (auto& t : textures_loaded)
|
||||||
for (int i = 0; i < meshes.size(); i++)
|
t.Release();
|
||||||
{
|
|
||||||
|
for (int i = 0; i < meshes.size(); i++) {
|
||||||
meshes[i].Close();
|
meshes[i].Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelLoader::processNode(aiNode * node, const aiScene * scene)
|
void ModelLoader::processNode(aiNode * node, const aiScene * scene) {
|
||||||
{
|
for (UINT i = 0; i < node->mNumMeshes; i++) {
|
||||||
for (UINT i = 0; i < node->mNumMeshes; i++)
|
|
||||||
{
|
|
||||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
|
||||||
meshes.push_back(this->processMesh(mesh, scene));
|
meshes.push_back(this->processMesh(mesh, scene));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UINT i = 0; i < node->mNumChildren; i++)
|
for (UINT i = 0; i < node->mNumChildren; i++) {
|
||||||
{
|
|
||||||
this->processNode(node->mChildren[i], scene);
|
this->processNode(node->mChildren[i], scene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat)
|
string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat) {
|
||||||
{
|
|
||||||
aiString textypeStr;
|
aiString textypeStr;
|
||||||
mat->GetTexture(aiTextureType_DIFFUSE, 0, &textypeStr);
|
mat->GetTexture(aiTextureType_DIFFUSE, 0, &textypeStr);
|
||||||
string textypeteststr = textypeStr.C_Str();
|
string textypeteststr = textypeStr.C_Str();
|
||||||
if (textypeteststr == "*0" || textypeteststr == "*1" || textypeteststr == "*2" || textypeteststr == "*3" || textypeteststr == "*4" || textypeteststr == "*5")
|
if (textypeteststr == "*0" || textypeteststr == "*1" || textypeteststr == "*2" || textypeteststr == "*3" || textypeteststr == "*4" || textypeteststr == "*5") {
|
||||||
{
|
if (scene->mTextures[0]->mHeight == 0) {
|
||||||
if (scene->mTextures[0]->mHeight == 0)
|
|
||||||
{
|
|
||||||
return "embedded compressed texture";
|
return "embedded compressed texture";
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return "embedded non-compressed texture";
|
return "embedded non-compressed texture";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (textypeteststr.find('.') != string::npos)
|
if (textypeteststr.find('.') != string::npos) {
|
||||||
{
|
|
||||||
return "textures are on disk";
|
return "textures are on disk";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ".";
|
return ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
int ModelLoader::getTextureIndex(aiString * str)
|
int ModelLoader::getTextureIndex(aiString * str) {
|
||||||
{
|
|
||||||
string tistr;
|
string tistr;
|
||||||
tistr = str->C_Str();
|
tistr = str->C_Str();
|
||||||
tistr = tistr.substr(1);
|
tistr = tistr.substr(1);
|
||||||
return stoi(tistr);
|
return stoi(tistr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D11ShaderResourceView * ModelLoader::getTextureFromModel(const aiScene * scene, int textureindex)
|
ID3D11ShaderResourceView * ModelLoader::getTextureFromModel(const aiScene * scene, int textureindex) {
|
||||||
{
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
ID3D11ShaderResourceView *texture;
|
ID3D11ShaderResourceView *texture;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
with or without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the
|
||||||
|
following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the assimp team, nor the names of its
|
||||||
|
contributors may be used to endorse or promote products
|
||||||
|
derived from this software without specific prior
|
||||||
|
written permission of the assimp team.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma once
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Used to reduce to reduce the number of lines when calling Release()
|
||||||
|
on a D3D interface. Implemented as a template instead of a 'SAFE_RELEASE'
|
||||||
|
MACRO to ease debugging. */
|
||||||
|
template<typename T>
|
||||||
|
inline void SafeRelease(T*& x) {
|
||||||
|
if (x) {
|
||||||
|
x->Release();
|
||||||
|
x = nullptr;
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,12 +14,16 @@
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <shellapi.h>
|
||||||
|
#include <stdexcept>
|
||||||
#include <windowsx.h>
|
#include <windowsx.h>
|
||||||
#include <d3d11_1.h>
|
#include <d3d11_1.h>
|
||||||
#include <dxgi1_2.h>
|
#include <dxgi1_2.h>
|
||||||
#include <DirectXMath.h>
|
#include <DirectXMath.h>
|
||||||
#include <d3dcompiler.h>
|
#include <d3dcompiler.h>
|
||||||
#include "ModelLoader.h"
|
#include "ModelLoader.h"
|
||||||
|
#include "UTFConverter.h"
|
||||||
|
#include "SafeRelease.hpp"
|
||||||
|
|
||||||
#pragma comment (lib, "d3d11.lib")
|
#pragma comment (lib, "d3d11.lib")
|
||||||
#pragma comment (lib, "Dxgi.lib")
|
#pragma comment (lib, "Dxgi.lib")
|
||||||
|
@ -27,6 +31,10 @@
|
||||||
#pragma comment (lib, "dxguid.lib")
|
#pragma comment (lib, "dxguid.lib")
|
||||||
|
|
||||||
using namespace DirectX;
|
using namespace DirectX;
|
||||||
|
using namespace AssimpSamples::SharedCode;
|
||||||
|
|
||||||
|
#define VERTEX_SHADER_FILE L"VertexShader.hlsl"
|
||||||
|
#define PIXEL_SHADER_FILE L"PixelShader.hlsl"
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// Structs
|
// Structs
|
||||||
|
@ -45,29 +53,32 @@ struct ConstantBuffer {
|
||||||
|
|
||||||
const char g_szClassName[] = "directxWindowClass";
|
const char g_szClassName[] = "directxWindowClass";
|
||||||
|
|
||||||
|
static std::string g_ModelPath;
|
||||||
|
|
||||||
UINT width, height;
|
UINT width, height;
|
||||||
HWND hwnd;
|
HWND hwnd = nullptr;
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// DirectX Variables
|
// DirectX Variables
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
|
D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
|
||||||
D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
|
D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
|
||||||
ID3D11Device *dev;
|
ID3D11Device *dev = nullptr;
|
||||||
ID3D11Device1 *dev1;
|
ID3D11Device1 *dev1 = nullptr;
|
||||||
ID3D11DeviceContext *devcon;
|
ID3D11DeviceContext *devcon = nullptr;
|
||||||
ID3D11DeviceContext1 *devcon1;
|
ID3D11DeviceContext1 *devcon1 = nullptr;
|
||||||
IDXGISwapChain *swapchain;
|
IDXGISwapChain *swapchain = nullptr;
|
||||||
IDXGISwapChain1 *swapchain1;
|
IDXGISwapChain1 *swapchain1 = nullptr;
|
||||||
ID3D11RenderTargetView *backbuffer;
|
ID3D11RenderTargetView *backbuffer = nullptr;
|
||||||
ID3D11VertexShader *pVS;
|
ID3D11VertexShader *pVS = nullptr;
|
||||||
ID3D11PixelShader *pPS;
|
ID3D11PixelShader *pPS = nullptr;
|
||||||
ID3D11InputLayout *pLayout;
|
ID3D11InputLayout *pLayout = nullptr;
|
||||||
ID3D11Buffer *pConstantBuffer;
|
ID3D11Buffer *pConstantBuffer = nullptr;
|
||||||
ID3D11Texture2D *g_pDepthStencil;
|
ID3D11Texture2D *g_pDepthStencil = nullptr;
|
||||||
ID3D11DepthStencilView *g_pDepthStencilView;
|
ID3D11DepthStencilView *g_pDepthStencilView = nullptr;
|
||||||
ID3D11SamplerState *TexSamplerState;
|
ID3D11SamplerState *TexSamplerState = nullptr;
|
||||||
|
ID3D11RasterizerState *rasterstate = nullptr;
|
||||||
|
ID3D11Debug* d3d11debug = nullptr;
|
||||||
|
|
||||||
XMMATRIX m_World;
|
XMMATRIX m_World;
|
||||||
XMMATRIX m_View;
|
XMMATRIX m_View;
|
||||||
|
@ -91,7 +102,7 @@ void Throwanerror(LPCSTR errormessage);
|
||||||
// Our Model
|
// Our Model
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
ModelLoader *ourModel;
|
ModelLoader *ourModel = nullptr;
|
||||||
|
|
||||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
@ -109,9 +120,42 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
LPSTR lpCmdLine, int nCmdShow)
|
LPWSTR lpCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
|
int argc;
|
||||||
|
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||||
|
if (!argv) {
|
||||||
|
MessageBox(NULL,
|
||||||
|
TEXT("An error occured while reading command line arguments."),
|
||||||
|
TEXT("Error!"),
|
||||||
|
MB_ICONERROR | MB_OK);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free memory allocated from CommandLineToArgvW.
|
||||||
|
auto free_command_line_allocated_memory = [&argv]() {
|
||||||
|
if (argv) {
|
||||||
|
LocalFree(argv);
|
||||||
|
argv = nullptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Ensure that a model file has been specified.
|
||||||
|
if (argc < 2) {
|
||||||
|
MessageBox(NULL,
|
||||||
|
TEXT("No model file specified. The program will now close."),
|
||||||
|
TEXT("Error!"),
|
||||||
|
MB_ICONERROR | MB_OK);
|
||||||
|
free_command_line_allocated_memory();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the model file path.
|
||||||
|
g_ModelPath = UTFConverter(argv[1]).str();
|
||||||
|
|
||||||
|
free_command_line_allocated_memory();
|
||||||
|
|
||||||
WNDCLASSEX wc;
|
WNDCLASSEX wc;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
|
@ -160,26 +204,35 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
width = wr.right - wr.left;
|
width = wr.right - wr.left;
|
||||||
height = wr.bottom - wr.top;
|
height = wr.bottom - wr.top;
|
||||||
|
|
||||||
InitD3D(hInstance, hwnd);
|
try {
|
||||||
|
InitD3D(hInstance, hwnd);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
|
||||||
|
|
||||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
||||||
{
|
{
|
||||||
TranslateMessage(&msg);
|
|
||||||
DispatchMessage(&msg);
|
|
||||||
|
|
||||||
if (msg.message == WM_QUIT)
|
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
break;
|
{
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
|
||||||
|
if (msg.message == WM_QUIT)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderFrame();
|
CleanD3D();
|
||||||
|
return static_cast<int>(msg.wParam);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
MessageBox(hwnd, e.what(), TEXT("Error!"), MB_ICONERROR | MB_OK);
|
||||||
|
CleanD3D();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} catch (...) {
|
||||||
|
MessageBox(hwnd, TEXT("Caught an unknown exception."), TEXT("Error!"), MB_ICONERROR | MB_OK);
|
||||||
|
CleanD3D();
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
CleanD3D();
|
|
||||||
|
|
||||||
return msg.wParam;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
||||||
|
@ -227,6 +280,12 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
Throwanerror("Directx Device Creation Failed!");
|
Throwanerror("Directx Device Creation Failed!");
|
||||||
|
|
||||||
|
#if _DEBUG
|
||||||
|
hr = dev->QueryInterface(IID_PPV_ARGS(&d3d11debug));
|
||||||
|
if (FAILED(hr))
|
||||||
|
OutputDebugString(TEXT("Failed to retrieve DirectX 11 debug interface.\n"));
|
||||||
|
#endif
|
||||||
|
|
||||||
UINT m4xMsaaQuality;
|
UINT m4xMsaaQuality;
|
||||||
dev->CheckMultisampleQualityLevels(
|
dev->CheckMultisampleQualityLevels(
|
||||||
DXGI_FORMAT_R8G8B8A8_UNORM, 4, &m4xMsaaQuality);
|
DXGI_FORMAT_R8G8B8A8_UNORM, 4, &m4xMsaaQuality);
|
||||||
|
@ -348,7 +407,6 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
||||||
devcon->OMSetRenderTargets(1, &backbuffer, g_pDepthStencilView);
|
devcon->OMSetRenderTargets(1, &backbuffer, g_pDepthStencilView);
|
||||||
|
|
||||||
D3D11_RASTERIZER_DESC rasterDesc;
|
D3D11_RASTERIZER_DESC rasterDesc;
|
||||||
ID3D11RasterizerState *rasterState;
|
|
||||||
rasterDesc.AntialiasedLineEnable = false;
|
rasterDesc.AntialiasedLineEnable = false;
|
||||||
rasterDesc.CullMode = D3D11_CULL_BACK;
|
rasterDesc.CullMode = D3D11_CULL_BACK;
|
||||||
rasterDesc.DepthBias = 0;
|
rasterDesc.DepthBias = 0;
|
||||||
|
@ -360,8 +418,8 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
||||||
rasterDesc.ScissorEnable = false;
|
rasterDesc.ScissorEnable = false;
|
||||||
rasterDesc.SlopeScaledDepthBias = 0.0f;
|
rasterDesc.SlopeScaledDepthBias = 0.0f;
|
||||||
|
|
||||||
dev->CreateRasterizerState(&rasterDesc, &rasterState);
|
dev->CreateRasterizerState(&rasterDesc, &rasterstate);
|
||||||
devcon->RSSetState(rasterState);
|
devcon->RSSetState(rasterstate);
|
||||||
|
|
||||||
D3D11_VIEWPORT viewport;
|
D3D11_VIEWPORT viewport;
|
||||||
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
|
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
|
||||||
|
@ -381,19 +439,38 @@ void InitD3D(HINSTANCE hinstance, HWND hWnd)
|
||||||
|
|
||||||
void CleanD3D(void)
|
void CleanD3D(void)
|
||||||
{
|
{
|
||||||
swapchain->SetFullscreenState(FALSE, NULL);
|
if (swapchain)
|
||||||
|
swapchain->SetFullscreenState(FALSE, NULL);
|
||||||
|
|
||||||
ourModel->Close();
|
if (ourModel) {
|
||||||
g_pDepthStencil->Release();
|
ourModel->Close();
|
||||||
g_pDepthStencilView->Release();
|
delete ourModel;
|
||||||
pLayout->Release();
|
ourModel = nullptr;
|
||||||
pVS->Release();
|
}
|
||||||
pPS->Release();
|
SafeRelease(TexSamplerState);
|
||||||
pConstantBuffer->Release();
|
SafeRelease(pConstantBuffer);
|
||||||
swapchain->Release();
|
SafeRelease(pLayout);
|
||||||
backbuffer->Release();
|
SafeRelease(pVS);
|
||||||
dev->Release();
|
SafeRelease(pPS);
|
||||||
devcon->Release();
|
SafeRelease(rasterstate);
|
||||||
|
SafeRelease(g_pDepthStencilView);
|
||||||
|
SafeRelease(g_pDepthStencil);
|
||||||
|
SafeRelease(backbuffer);
|
||||||
|
SafeRelease(swapchain);
|
||||||
|
SafeRelease(swapchain1);
|
||||||
|
SafeRelease(devcon1);
|
||||||
|
SafeRelease(dev1);
|
||||||
|
SafeRelease(devcon);
|
||||||
|
#if _DEBUG
|
||||||
|
if (d3d11debug) {
|
||||||
|
OutputDebugString(TEXT("Dumping DirectX 11 live objects.\n"));
|
||||||
|
d3d11debug->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL);
|
||||||
|
SafeRelease(d3d11debug);
|
||||||
|
} else {
|
||||||
|
OutputDebugString(TEXT("Unable to dump live objects: no DirectX 11 debug interface available.\n"));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
SafeRelease(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderFrame(void)
|
void RenderFrame(void)
|
||||||
|
@ -431,8 +508,10 @@ void RenderFrame(void)
|
||||||
void InitPipeline()
|
void InitPipeline()
|
||||||
{
|
{
|
||||||
ID3DBlob *VS, *PS;
|
ID3DBlob *VS, *PS;
|
||||||
CompileShaderFromFile(L"VertexShader.hlsl", 0, "main", "vs_4_0", &VS);
|
if(FAILED(CompileShaderFromFile(SHADER_PATH VERTEX_SHADER_FILE, 0, "main", "vs_4_0", &VS)))
|
||||||
CompileShaderFromFile(L"PixelShader.hlsl", 0, "main", "ps_4_0", &PS);
|
Throwanerror(UTFConverter(L"Failed to compile shader from file " VERTEX_SHADER_FILE).c_str());
|
||||||
|
if(FAILED(CompileShaderFromFile(SHADER_PATH PIXEL_SHADER_FILE, 0, "main", "ps_4_0", &PS)))
|
||||||
|
Throwanerror(UTFConverter(L"Failed to compile shader from file " PIXEL_SHADER_FILE).c_str());
|
||||||
|
|
||||||
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
|
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
|
||||||
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);
|
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);
|
||||||
|
@ -485,7 +564,7 @@ void InitGraphics()
|
||||||
m_View = XMMatrixLookAtLH(Eye, At, Up);
|
m_View = XMMatrixLookAtLH(Eye, At, Up);
|
||||||
|
|
||||||
ourModel = new ModelLoader;
|
ourModel = new ModelLoader;
|
||||||
if (!ourModel->Load(hwnd, dev, devcon, "Models/myModel.fbx"))
|
if (!ourModel->Load(hwnd, dev, devcon, g_ModelPath))
|
||||||
Throwanerror("Model couldn't be loaded");
|
Throwanerror("Model couldn't be loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,5 +593,5 @@ HRESULT CompileShaderFromFile(LPCWSTR pFileName, const D3D_SHADER_MACRO* pDefine
|
||||||
|
|
||||||
void Throwanerror(LPCSTR errormessage)
|
void Throwanerror(LPCSTR errormessage)
|
||||||
{
|
{
|
||||||
MessageBox(hwnd, errormessage, "Error!", MB_ICONERROR | MB_OK);
|
throw std::runtime_error(errormessage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES(
|
||||||
${Assimp_SOURCE_DIR}/code
|
${Assimp_SOURCE_DIR}/code
|
||||||
${OPENGL_INCLUDE_DIR}
|
${OPENGL_INCLUDE_DIR}
|
||||||
${GLUT_INCLUDE_DIR}
|
${GLUT_INCLUDE_DIR}
|
||||||
|
${SAMPLES_SHARED_CODE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
LINK_DIRECTORIES(
|
LINK_DIRECTORIES(
|
||||||
|
@ -31,6 +32,8 @@ LINK_DIRECTORIES(
|
||||||
ADD_EXECUTABLE( assimp_simpletexturedogl WIN32
|
ADD_EXECUTABLE( assimp_simpletexturedogl WIN32
|
||||||
SimpleTexturedOpenGL/include/boost_includes.h
|
SimpleTexturedOpenGL/include/boost_includes.h
|
||||||
SimpleTexturedOpenGL/src/model_loading.cpp
|
SimpleTexturedOpenGL/src/model_loading.cpp
|
||||||
|
${SAMPLES_SHARED_CODE_DIR}/UTFConverter.cpp
|
||||||
|
${SAMPLES_SHARED_CODE_DIR}/UTFConverter.h
|
||||||
)
|
)
|
||||||
|
|
||||||
SET_PROPERTY(TARGET assimp_simpletexturedogl PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
SET_PROPERTY(TARGET assimp_simpletexturedogl PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "contrib/stb_image/stb_image.h"
|
#include "contrib/stb_image/stb_image.h"
|
||||||
|
|
||||||
#include <locale>
|
|
||||||
#include <codecvt>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
//to map image filenames to textureIds
|
//to map image filenames to textureIds
|
||||||
|
@ -35,7 +33,7 @@
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/LogStream.hpp>
|
#include <assimp/LogStream.hpp>
|
||||||
|
#include "UTFConverter.h"
|
||||||
|
|
||||||
// The default hard-coded path. Can be overridden by supplying a path through the command line.
|
// The default hard-coded path. Can be overridden by supplying a path through the command line.
|
||||||
static std::string modelpath = "../../test/models/OBJ/spider.obj";
|
static std::string modelpath = "../../test/models/OBJ/spider.obj";
|
||||||
|
@ -77,35 +75,7 @@ GLuint* textureIds; // pointer to texture Array
|
||||||
// Create an instance of the Importer class
|
// Create an instance of the Importer class
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
|
|
||||||
// Used to convert between multibyte and unicode strings.
|
using namespace AssimpSamples::SharedCode;
|
||||||
class UTFConverter {
|
|
||||||
using UTFConverterImpl = std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>;
|
|
||||||
public:
|
|
||||||
UTFConverter(const char* s) :
|
|
||||||
s_(s),
|
|
||||||
ws_(impl_.from_bytes(s)) {
|
|
||||||
}
|
|
||||||
UTFConverter(const std::string& s) :
|
|
||||||
s_(s),
|
|
||||||
ws_(impl_.from_bytes(s)) {
|
|
||||||
}
|
|
||||||
UTFConverter(const std::wstring& s) :
|
|
||||||
s_(impl_.to_bytes(s)),
|
|
||||||
ws_(s) {
|
|
||||||
}
|
|
||||||
inline const std::string& str() const {
|
|
||||||
return s_;
|
|
||||||
}
|
|
||||||
inline const wchar_t* c_wstr() const {
|
|
||||||
return ws_.c_str();
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
static UTFConverterImpl impl_;
|
|
||||||
std::string s_;
|
|
||||||
std::wstring ws_;
|
|
||||||
};
|
|
||||||
|
|
||||||
typename UTFConverter::UTFConverterImpl UTFConverter::impl_;
|
|
||||||
|
|
||||||
void createAILogger()
|
void createAILogger()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue