Merge branch 'master' into Q1MDLgroup
commit
1f76b2e6b9
|
@ -1 +1,2 @@
|
||||||
open_collective: assimp
|
open_collective: assimp
|
||||||
|
patreon: assimp
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
title: ''
|
title: 'Bug:'
|
||||||
labels: ''
|
labels: 'Bug'
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -23,16 +23,10 @@ A clear and concise description of what you expected to happen.
|
||||||
**Screenshots**
|
**Screenshots**
|
||||||
If applicable, add screenshots to help explain your problem.
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
**Platform (please complete the following information):**
|
||||||
- OS: [e.g. iOS]
|
- OS: [e.g. iOS]
|
||||||
- Browser [e.g. chrome, safari]
|
- Browser [e.g. chrome, safari]
|
||||||
- Version [e.g. 22]
|
- Version [e.g. 22]
|
||||||
|
|
||||||
**Smartphone (please complete the following information):**
|
|
||||||
- Device: [e.g. iPhone6]
|
|
||||||
- OS: [e.g. iOS8.1]
|
|
||||||
- Browser [e.g. stock browser, safari]
|
|
||||||
- Version [e.g. 22]
|
|
||||||
|
|
||||||
**Additional context**
|
**Additional context**
|
||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
name: Feature request
|
name: Feature request
|
||||||
about: Suggest an idea for this project
|
about: Suggest an idea for this project
|
||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: 'Feature-Request'
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
name: Technical debt
|
||||||
|
about: Create a report to help us to fix and detect tech debts
|
||||||
|
title: ''
|
||||||
|
labels: 'Techdebt'
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the technical debt**
|
||||||
|
A clear and concise description of what the tech debt is about.
|
||||||
|
|
||||||
|
**Better solution**
|
||||||
|
A clear and concise description of what you would expect.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
|
@ -25,7 +25,7 @@ CMakeSettings.json
|
||||||
# Output
|
# Output
|
||||||
bin/
|
bin/
|
||||||
lib/
|
lib/
|
||||||
|
x64/
|
||||||
# QtCreator
|
# QtCreator
|
||||||
CMakeLists.txt.user
|
CMakeLists.txt.user
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@ test/gtest/src/gtest-stamp/gtest-gitinfo.txt
|
||||||
test/gtest/src/gtest-stamp/gtest-gitclone-lastrun.txt
|
test/gtest/src/gtest-stamp/gtest-gitclone-lastrun.txt
|
||||||
Assimp.opensdf
|
Assimp.opensdf
|
||||||
contrib/zlib/CTestTestfile.cmake
|
contrib/zlib/CTestTestfile.cmake
|
||||||
|
contrib/zlib/Debug/zlibstaticd.pdb
|
||||||
ipch/assimp_viewer-44bbbcd1/assimp_viewerd-ccc45335.ipch
|
ipch/assimp_viewer-44bbbcd1/assimp_viewerd-ccc45335.ipch
|
||||||
bin64/assimp-vc140-mt.dll
|
bin64/assimp-vc140-mt.dll
|
||||||
bin64/assimp-vc140-mtd.dll
|
bin64/assimp-vc140-mtd.dll
|
||||||
|
|
|
@ -44,10 +44,10 @@ CMAKE_MINIMUM_REQUIRED( VERSION 3.10 )
|
||||||
option(ASSIMP_HUNTER_ENABLED "Enable Hunter package manager support" OFF)
|
option(ASSIMP_HUNTER_ENABLED "Enable Hunter package manager support" OFF)
|
||||||
|
|
||||||
IF(ASSIMP_HUNTER_ENABLED)
|
IF(ASSIMP_HUNTER_ENABLED)
|
||||||
include("cmake/HunterGate.cmake")
|
include("cmake-modules/HunterGate.cmake")
|
||||||
HunterGate(
|
HunterGate(
|
||||||
URL "https://github.com/cpp-pm/hunter/archive/v0.23.293.tar.gz"
|
URL "https://github.com/cpp-pm/hunter/archive/v0.23.311.tar.gz"
|
||||||
SHA1 "e8e5470652db77149d9b38656db2a6c0b7642693"
|
SHA1 "1a82b9b73055879181cb1466b2ab5d48ee8ae410"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_definitions(-DASSIMP_USE_HUNTER)
|
add_definitions(-DASSIMP_USE_HUNTER)
|
||||||
|
@ -135,11 +135,11 @@ IF ( WIN32 )
|
||||||
# Use subset of Windows.h
|
# Use subset of Windows.h
|
||||||
ADD_DEFINITIONS( -DWIN32_LEAN_AND_MEAN )
|
ADD_DEFINITIONS( -DWIN32_LEAN_AND_MEAN )
|
||||||
|
|
||||||
|
IF(MSVC)
|
||||||
OPTION ( ASSIMP_BUILD_ASSIMP_VIEW
|
OPTION ( ASSIMP_BUILD_ASSIMP_VIEW
|
||||||
"If the Assimp view tool is built. (requires DirectX)"
|
"If the Assimp view tool is built. (requires DirectX)"
|
||||||
OFF )
|
OFF )
|
||||||
|
|
||||||
IF(MSVC)
|
|
||||||
OPTION( ASSIMP_INSTALL_PDB
|
OPTION( ASSIMP_INSTALL_PDB
|
||||||
"Install MSVC debug files."
|
"Install MSVC debug files."
|
||||||
ON )
|
ON )
|
||||||
|
@ -267,7 +267,10 @@ ELSEIF(MSVC)
|
||||||
IF(MSVC12)
|
IF(MSVC12)
|
||||||
ADD_COMPILE_OPTIONS(/wd4351)
|
ADD_COMPILE_OPTIONS(/wd4351)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
ADD_COMPILE_OPTIONS(/wd4244) #supress warning for double to float conversion if Double precission is activated
|
||||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /Zi /Od")
|
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /Zi /Od")
|
||||||
|
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
|
||||||
|
SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG:FULL /PDBALTPATH:%_PDB% /OPT:REF /OPT:ICF")
|
||||||
ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
||||||
IF(NOT ASSIMP_HUNTER_ENABLED)
|
IF(NOT ASSIMP_HUNTER_ENABLED)
|
||||||
SET(CMAKE_CXX_STANDARD 11)
|
SET(CMAKE_CXX_STANDARD 11)
|
||||||
|
@ -334,9 +337,9 @@ INCLUDE (FindPkgMacros)
|
||||||
INCLUDE (PrecompiledHeader)
|
INCLUDE (PrecompiledHeader)
|
||||||
|
|
||||||
# Set Assimp project output directory variables.
|
# Set Assimp project output directory variables.
|
||||||
SET(ASSIMP_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
SET(ASSIMP_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" CACHE STRING "Path for runtime output files")
|
||||||
SET(ASSIMP_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
SET(ASSIMP_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" CACHE STRING "Path for library output files")
|
||||||
SET(ASSIMP_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
|
SET(ASSIMP_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib" CACHE STRING "Path for archive output files")
|
||||||
|
|
||||||
# Macro used to set the output directories of a target to the
|
# Macro used to set the output directories of a target to the
|
||||||
# respective Assimp output directories.
|
# respective Assimp output directories.
|
||||||
|
@ -395,14 +398,14 @@ set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||||
|
|
||||||
IF(ASSIMP_HUNTER_ENABLED)
|
IF(ASSIMP_HUNTER_ENABLED)
|
||||||
set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}")
|
set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}")
|
||||||
set(CMAKE_CONFIG_TEMPLATE_FILE "cmake/assimp-hunter-config.cmake.in")
|
set(CMAKE_CONFIG_TEMPLATE_FILE "cmake-modules/assimp-hunter-config.cmake.in")
|
||||||
set(NAMESPACE "${PROJECT_NAME}::")
|
set(NAMESPACE "${PROJECT_NAME}::")
|
||||||
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
||||||
set(VERSION_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
set(VERSION_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
||||||
set(PROJECT_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}Config.cmake")
|
set(PROJECT_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}Config.cmake")
|
||||||
ELSE()
|
ELSE()
|
||||||
set(CONFIG_INSTALL_DIR "${ASSIMP_LIB_INSTALL_DIR}/cmake/assimp-${ASSIMP_VERSION_MAJOR}.${ASSIMP_VERSION_MINOR}")
|
set(CONFIG_INSTALL_DIR "${ASSIMP_LIB_INSTALL_DIR}/cmake/assimp-${ASSIMP_VERSION_MAJOR}.${ASSIMP_VERSION_MINOR}")
|
||||||
set(CMAKE_CONFIG_TEMPLATE_FILE "cmake/assimp-plain-config.cmake.in")
|
set(CMAKE_CONFIG_TEMPLATE_FILE "cmake-modules/assimp-plain-config.cmake.in")
|
||||||
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWERCASE)
|
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWERCASE)
|
||||||
set(NAMESPACE "${PROJECT_NAME_LOWERCASE}::")
|
set(NAMESPACE "${PROJECT_NAME_LOWERCASE}::")
|
||||||
set(TARGETS_EXPORT_NAME "${PROJECT_NAME_LOWERCASE}Targets")
|
set(TARGETS_EXPORT_NAME "${PROJECT_NAME_LOWERCASE}Targets")
|
||||||
|
@ -527,12 +530,12 @@ ENDIF()
|
||||||
MARK_AS_ADVANCED ( ASSIMP_BUILD_ARCHITECTURE ASSIMP_BUILD_COMPILER )
|
MARK_AS_ADVANCED ( ASSIMP_BUILD_ARCHITECTURE ASSIMP_BUILD_COMPILER )
|
||||||
|
|
||||||
SET ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER OFF CACHE BOOL
|
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 (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
|
||||||
IF ( MSVC )
|
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
|
# pick the correct prebuilt library
|
||||||
IF(MSVC15)
|
IF(MSVC15)
|
||||||
|
@ -551,22 +554,23 @@ IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
|
||||||
)
|
)
|
||||||
ENDIF()
|
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
|
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"
|
"${C4D_LIB_BASE_PATH}/jpeglib${C4D_LIB_POSTFIX}/jpeglib_debug.lib"
|
||||||
)
|
)
|
||||||
SET(C4D_RELEASE_LIBRARIES
|
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"
|
"${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)
|
SET(C4D_EXTRA_LIBRARIES WSock32.lib Winmm.lib)
|
||||||
ELSE ()
|
ELSE ()
|
||||||
MESSAGE( FATAL_ERROR
|
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 ()
|
ENDIF ()
|
||||||
ELSE ()
|
ELSE ()
|
||||||
|
|
|
@ -8,10 +8,10 @@ A library to import and export various 3d-model-formats including scene-post-pro
|
||||||
<img alt="Coverity Scan Build Status"
|
<img alt="Coverity Scan Build Status"
|
||||||
src="https://scan.coverity.com/projects/5607/badge.svg"/>
|
src="https://scan.coverity.com/projects/5607/badge.svg"/>
|
||||||
</a>
|
</a>
|
||||||
|
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/9973693b7bdd4543b07084d5d9cf4745)](https://www.codacy.com/gh/assimp/assimp/dashboard?utm_source=github.com&utm_medium=referral&utm_content=assimp/assimp&utm_campaign=Badge_Grade)
|
||||||
[![Coverage Status](https://coveralls.io/repos/github/assimp/assimp/badge.svg?branch=master)](https://coveralls.io/github/assimp/assimp?branch=master)
|
[![Coverage Status](https://coveralls.io/repos/github/assimp/assimp/badge.svg?branch=master)](https://coveralls.io/github/assimp/assimp?branch=master)
|
||||||
[![Join the chat at https://gitter.im/assimp/assimp](https://badges.gitter.im/assimp/assimp.svg)](https://gitter.im/assimp/assimp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[![Join the chat at https://gitter.im/assimp/assimp](https://badges.gitter.im/assimp/assimp.svg)](https://gitter.im/assimp/assimp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/assimp/assimp.svg)](http://isitmaintained.com/project/assimp/assimp "Average time to resolve an issue")
|
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/assimp/assimp.svg)](http://isitmaintained.com/project/assimp/assimp "Average time to resolve an issue")
|
||||||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5be56faac64f46fc941ac890fb4febef)](https://www.codacy.com/app/kimkulling/assimp?utm_source=github.com&utm_medium=referral&utm_content=assimp/assimp&utm_campaign=Badge_Grade)
|
|
||||||
[![Total alerts](https://img.shields.io/lgtm/alerts/g/assimp/assimp.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/assimp/assimp/alerts/)
|
[![Total alerts](https://img.shields.io/lgtm/alerts/g/assimp/assimp.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/assimp/assimp/alerts/)
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ Take a look into the https://github.com/assimp/assimp/blob/master/Build.md file.
|
||||||
* [.NET](https://bitbucket.org/Starnick/assimpnet/src/master/)
|
* [.NET](https://bitbucket.org/Starnick/assimpnet/src/master/)
|
||||||
* [Pascal](port/AssimpPascal/Readme.md)
|
* [Pascal](port/AssimpPascal/Readme.md)
|
||||||
* [Javascript (Alpha)](https://github.com/makc/assimp2json)
|
* [Javascript (Alpha)](https://github.com/makc/assimp2json)
|
||||||
* [Unity 3d Plugin](https://www.assetstore.unity3d.com/en/#!/content/91777)
|
* [Unity 3d Plugin](https://ricardoreis.net/trilib-2/)
|
||||||
* [JVM](https://github.com/kotlin-graphics/assimp) Full jvm port (current [status](https://github.com/kotlin-graphics/assimp/wiki/Status))
|
* [JVM](https://github.com/kotlin-graphics/assimp) Full jvm port (current [status](https://github.com/kotlin-graphics/assimp/wiki/Status))
|
||||||
* [HAXE-Port](https://github.com/longde123/assimp-haxe) The Assimp-HAXE-port.
|
* [HAXE-Port](https://github.com/longde123/assimp-haxe) The Assimp-HAXE-port.
|
||||||
* [Rust](https://github.com/jkvargas/russimp)
|
* [Rust](https://github.com/jkvargas/russimp)
|
||||||
|
@ -68,7 +68,7 @@ The source code is organized in the following way:
|
||||||
|
|
||||||
code/Common The base implementation for importers and the infrastructure
|
code/Common The base implementation for importers and the infrastructure
|
||||||
code/PostProcessing The post-processing steps
|
code/PostProcessing The post-processing steps
|
||||||
code/<FormatName> Implementation for import and export for the format
|
code/AssetLib/<FormatName> Implementation for import and export for the format
|
||||||
|
|
||||||
### Where to get help ###
|
### Where to get help ###
|
||||||
For more information, visit [our website](http://assimp.org/). Or check out the `./doc`- folder, which contains the official documentation in HTML format.
|
For more information, visit [our website](http://assimp.org/). Or check out the `./doc`- folder, which contains the official documentation in HTML format.
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
# Find IrrXMl from irrlicht project
|
|
||||||
#
|
|
||||||
# Find LibIrrXML headers and library
|
|
||||||
#
|
|
||||||
# IRRXML_FOUND - IrrXML found
|
|
||||||
# IRRXML_INCLUDE_DIR - Headers location
|
|
||||||
# IRRXML_LIBRARY - IrrXML main library
|
|
||||||
|
|
||||||
find_path(IRRXML_INCLUDE_DIR irrXML.h
|
|
||||||
PATH_SUFFIXES include/irrlicht include/irrxml)
|
|
||||||
find_library(IRRXML_LIBRARY IrrXML)
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(IrrXML REQUIRED_VARS IRRXML_INCLUDE_DIR IRRXML_LIBRARY)
|
|
||||||
|
|
||||||
|
|
||||||
mark_as_advanced(IRRXML_INCLUDE_DIR IRRXML_LIBRARY)
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
find_package(RapidJSON CONFIG REQUIRED)
|
||||||
|
find_package(ZLIB CONFIG REQUIRED)
|
||||||
|
find_package(utf8cpp CONFIG REQUIRED)
|
||||||
|
find_package(minizip CONFIG REQUIRED)
|
||||||
|
find_package(openddlparser CONFIG REQUIRED)
|
||||||
|
find_package(poly2tri CONFIG REQUIRED)
|
||||||
|
find_package(polyclipping CONFIG REQUIRED)
|
||||||
|
find_package(zip CONFIG REQUIRED)
|
||||||
|
find_package(pugixml CONFIG REQUIRED)
|
||||||
|
find_package(stb CONFIG REQUIRED)
|
||||||
|
|
||||||
|
if(@ASSIMP_BUILD_DRACO@)
|
||||||
|
find_package(draco CONFIG REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
|
||||||
|
check_required_components("@PROJECT_NAME@")
|
|
@ -1,18 +0,0 @@
|
||||||
@PACKAGE_INIT@
|
|
||||||
|
|
||||||
find_package(RapidJSON CONFIG REQUIRED)
|
|
||||||
find_package(ZLIB CONFIG REQUIRED)
|
|
||||||
find_package(utf8cpp CONFIG REQUIRED)
|
|
||||||
find_package(minizip CONFIG REQUIRED)
|
|
||||||
find_package(openddlparser CONFIG REQUIRED)
|
|
||||||
find_package(poly2tri CONFIG REQUIRED)
|
|
||||||
find_package(polyclipping CONFIG REQUIRED)
|
|
||||||
find_package(zip CONFIG REQUIRED)
|
|
||||||
find_package(pugixml CONFIG REQUIRED)
|
|
||||||
|
|
||||||
if(@ASSIMP_BUILD_DRACO@)
|
|
||||||
find_package(draco CONFIG REQUIRED)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
|
|
||||||
check_required_components("@PROJECT_NAME@")
|
|
|
@ -68,8 +68,8 @@ void Discreet3DSImporter::ReplaceDefaultMaterial() {
|
||||||
unsigned int idx(NotSet);
|
unsigned int idx(NotSet);
|
||||||
for (unsigned int i = 0; i < mScene->mMaterials.size(); ++i) {
|
for (unsigned int i = 0; i < mScene->mMaterials.size(); ++i) {
|
||||||
std::string s = mScene->mMaterials[i].mName;
|
std::string s = mScene->mMaterials[i].mName;
|
||||||
for (std::string::iterator it = s.begin(); it != s.end(); ++it) {
|
for (char & it : s) {
|
||||||
*it = static_cast<char>(::tolower(*it));
|
it = static_cast<char>(::tolower(static_cast<unsigned char>(it)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::string::npos == s.find("default")) continue;
|
if (std::string::npos == s.find("default")) continue;
|
||||||
|
@ -79,12 +79,7 @@ void Discreet3DSImporter::ReplaceDefaultMaterial() {
|
||||||
mScene->mMaterials[i].mDiffuse.r !=
|
mScene->mMaterials[i].mDiffuse.r !=
|
||||||
mScene->mMaterials[i].mDiffuse.b) continue;
|
mScene->mMaterials[i].mDiffuse.b) continue;
|
||||||
|
|
||||||
if (mScene->mMaterials[i].sTexDiffuse.mMapName.length() != 0 ||
|
if (ContainsTextures(i)) {
|
||||||
mScene->mMaterials[i].sTexBump.mMapName.length() != 0 ||
|
|
||||||
mScene->mMaterials[i].sTexOpacity.mMapName.length() != 0 ||
|
|
||||||
mScene->mMaterials[i].sTexEmissive.mMapName.length() != 0 ||
|
|
||||||
mScene->mMaterials[i].sTexSpecular.mMapName.length() != 0 ||
|
|
||||||
mScene->mMaterials[i].sTexShininess.mMapName.length() != 0) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
idx = i;
|
idx = i;
|
||||||
|
@ -212,7 +207,7 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material &oldMat,
|
||||||
mat.AddProperty(&tex, AI_MATKEY_GLOBAL_BACKGROUND_IMAGE);
|
mat.AddProperty(&tex, AI_MATKEY_GLOBAL_BACKGROUND_IMAGE);
|
||||||
|
|
||||||
// Be sure this is only done for the first material
|
// Be sure this is only done for the first material
|
||||||
mBackgroundImage = std::string("");
|
mBackgroundImage = std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// At first add the base ambient color of the scene to the material
|
// At first add the base ambient color of the scene to the material
|
||||||
|
|
|
@ -56,8 +56,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace Assimp;
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
using namespace D3DS;
|
using namespace D3DS;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -102,13 +102,14 @@ private:
|
||||||
// preserves the mesh's given name if it has one. |index| is the index
|
// preserves the mesh's given name if it has one. |index| is the index
|
||||||
// of the mesh in |aiScene::mMeshes|.
|
// of the mesh in |aiScene::mMeshes|.
|
||||||
std::string GetMeshName(const aiMesh &mesh, unsigned int index, const aiNode &node) {
|
std::string GetMeshName(const aiMesh &mesh, unsigned int index, const aiNode &node) {
|
||||||
static const std::string underscore = "_";
|
static const char underscore = '_';
|
||||||
char postfix[10] = { 0 };
|
char postfix[10] = { 0 };
|
||||||
ASSIMP_itoa10(postfix, index);
|
ASSIMP_itoa10(postfix, index);
|
||||||
|
|
||||||
std::string result = node.mName.C_Str();
|
std::string result = node.mName.C_Str();
|
||||||
if (mesh.mName.length > 0) {
|
if (mesh.mName.length > 0) {
|
||||||
result += underscore + mesh.mName.C_Str();
|
result += underscore;
|
||||||
|
result += mesh.mName.C_Str();
|
||||||
}
|
}
|
||||||
return result + underscore + postfix;
|
return result + underscore + postfix;
|
||||||
}
|
}
|
||||||
|
@ -378,7 +379,7 @@ void Discreet3DSExporter::WriteTexture(const aiMaterial &mat, aiTextureType type
|
||||||
|
|
||||||
// TODO: handle embedded textures properly
|
// TODO: handle embedded textures properly
|
||||||
if (path.data[0] == '*') {
|
if (path.data[0] == '*') {
|
||||||
ASSIMP_LOG_ERROR("Ignoring embedded texture for export: " + std::string(path.C_Str()));
|
ASSIMP_LOG_ERROR("Ignoring embedded texture for export: ", path.C_Str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/light.h>
|
#include <assimp/light.h>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
#include <assimp/qnan.h>
|
#include <assimp/qnan.h>
|
||||||
#include <stdio.h> //sprintf
|
#include <cstdio> //sprintf
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace D3DS {
|
namespace D3DS {
|
||||||
|
@ -61,20 +61,10 @@ namespace D3DS {
|
||||||
#include <assimp/Compiler/pushpack1.h>
|
#include <assimp/Compiler/pushpack1.h>
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
/** Discreet3DS class: Helper class for loading 3ds files. Defines chunks
|
/** Defines chunks and data structures.
|
||||||
* and data structures.
|
|
||||||
*/
|
*/
|
||||||
class Discreet3DS {
|
namespace Discreet3DS {
|
||||||
private:
|
|
||||||
Discreet3DS() AI_NO_EXCEPT {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
~Discreet3DS() {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
//! data structure for a single chunk in a .3ds file
|
//! data structure for a single chunk in a .3ds file
|
||||||
struct Chunk {
|
struct Chunk {
|
||||||
uint16_t Flag;
|
uint16_t Flag;
|
||||||
|
@ -314,7 +304,7 @@ public:
|
||||||
// camera sub-chunks
|
// camera sub-chunks
|
||||||
CHUNK_CAM_RANGES = 0x4720
|
CHUNK_CAM_RANGES = 0x4720
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
/** Helper structure representing a 3ds mesh face */
|
/** Helper structure representing a 3ds mesh face */
|
||||||
|
@ -358,16 +348,16 @@ struct Texture {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture(Texture &&other) AI_NO_EXCEPT : mTextureBlend(std::move(other.mTextureBlend)),
|
Texture(Texture &&other) AI_NO_EXCEPT : mTextureBlend(other.mTextureBlend),
|
||||||
mMapName(std::move(other.mMapName)),
|
mMapName(std::move(other.mMapName)),
|
||||||
mOffsetU(std::move(other.mOffsetU)),
|
mOffsetU(other.mOffsetU),
|
||||||
mOffsetV(std::move(other.mOffsetV)),
|
mOffsetV(other.mOffsetV),
|
||||||
mScaleU(std::move(other.mScaleU)),
|
mScaleU(other.mScaleU),
|
||||||
mScaleV(std::move(other.mScaleV)),
|
mScaleV(other.mScaleV),
|
||||||
mRotation(std::move(other.mRotation)),
|
mRotation(other.mRotation),
|
||||||
mMapMode(std::move(other.mMapMode)),
|
mMapMode(other.mMapMode),
|
||||||
bPrivate(std::move(other.bPrivate)),
|
bPrivate(other.bPrivate),
|
||||||
iUVSrc(std::move(other.iUVSrc)) {
|
iUVSrc(other.iUVSrc) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,16 +366,16 @@ struct Texture {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTextureBlend = std::move(other.mTextureBlend);
|
mTextureBlend = other.mTextureBlend;
|
||||||
mMapName = std::move(other.mMapName);
|
mMapName = std::move(other.mMapName);
|
||||||
mOffsetU = std::move(other.mOffsetU);
|
mOffsetU = other.mOffsetU;
|
||||||
mOffsetV = std::move(other.mOffsetV);
|
mOffsetV = other.mOffsetV;
|
||||||
mScaleU = std::move(other.mScaleU);
|
mScaleU = other.mScaleU;
|
||||||
mScaleV = std::move(other.mScaleV);
|
mScaleV = other.mScaleV;
|
||||||
mRotation = std::move(other.mRotation);
|
mRotation = other.mRotation;
|
||||||
mMapMode = std::move(other.mMapMode);
|
mMapMode = other.mMapMode;
|
||||||
bPrivate = std::move(other.bPrivate);
|
bPrivate = other.bPrivate;
|
||||||
iUVSrc = std::move(other.iUVSrc);
|
iUVSrc = other.iUVSrc;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -471,13 +461,13 @@ struct Material {
|
||||||
|
|
||||||
//! Move constructor. This is explicitly written because MSVC doesn't support defaulting it
|
//! Move constructor. This is explicitly written because MSVC doesn't support defaulting it
|
||||||
Material(Material &&other) AI_NO_EXCEPT : mName(std::move(other.mName)),
|
Material(Material &&other) AI_NO_EXCEPT : mName(std::move(other.mName)),
|
||||||
mDiffuse(std::move(other.mDiffuse)),
|
mDiffuse(other.mDiffuse),
|
||||||
mSpecularExponent(std::move(other.mSpecularExponent)),
|
mSpecularExponent(other.mSpecularExponent),
|
||||||
mShininessStrength(std::move(other.mShininessStrength)),
|
mShininessStrength(other.mShininessStrength),
|
||||||
mSpecular(std::move(other.mSpecular)),
|
mSpecular(other.mSpecular),
|
||||||
mAmbient(std::move(other.mAmbient)),
|
mAmbient(other.mAmbient),
|
||||||
mShading(std::move(other.mShading)),
|
mShading(other.mShading),
|
||||||
mTransparency(std::move(other.mTransparency)),
|
mTransparency(other.mTransparency),
|
||||||
sTexDiffuse(std::move(other.sTexDiffuse)),
|
sTexDiffuse(std::move(other.sTexDiffuse)),
|
||||||
sTexOpacity(std::move(other.sTexOpacity)),
|
sTexOpacity(std::move(other.sTexOpacity)),
|
||||||
sTexSpecular(std::move(other.sTexSpecular)),
|
sTexSpecular(std::move(other.sTexSpecular)),
|
||||||
|
@ -485,10 +475,10 @@ struct Material {
|
||||||
sTexBump(std::move(other.sTexBump)),
|
sTexBump(std::move(other.sTexBump)),
|
||||||
sTexEmissive(std::move(other.sTexEmissive)),
|
sTexEmissive(std::move(other.sTexEmissive)),
|
||||||
sTexShininess(std::move(other.sTexShininess)),
|
sTexShininess(std::move(other.sTexShininess)),
|
||||||
mBumpHeight(std::move(other.mBumpHeight)),
|
mBumpHeight(other.mBumpHeight),
|
||||||
mEmissive(std::move(other.mEmissive)),
|
mEmissive(other.mEmissive),
|
||||||
sTexAmbient(std::move(other.sTexAmbient)),
|
sTexAmbient(std::move(other.sTexAmbient)),
|
||||||
mTwoSided(std::move(other.mTwoSided)) {
|
mTwoSided(other.mTwoSided) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,13 +488,13 @@ struct Material {
|
||||||
}
|
}
|
||||||
|
|
||||||
mName = std::move(other.mName);
|
mName = std::move(other.mName);
|
||||||
mDiffuse = std::move(other.mDiffuse);
|
mDiffuse = other.mDiffuse;
|
||||||
mSpecularExponent = std::move(other.mSpecularExponent);
|
mSpecularExponent = other.mSpecularExponent;
|
||||||
mShininessStrength = std::move(other.mShininessStrength),
|
mShininessStrength = other.mShininessStrength,
|
||||||
mSpecular = std::move(other.mSpecular);
|
mSpecular = other.mSpecular;
|
||||||
mAmbient = std::move(other.mAmbient);
|
mAmbient = other.mAmbient;
|
||||||
mShading = std::move(other.mShading);
|
mShading = other.mShading;
|
||||||
mTransparency = std::move(other.mTransparency);
|
mTransparency = other.mTransparency;
|
||||||
sTexDiffuse = std::move(other.sTexDiffuse);
|
sTexDiffuse = std::move(other.sTexDiffuse);
|
||||||
sTexOpacity = std::move(other.sTexOpacity);
|
sTexOpacity = std::move(other.sTexOpacity);
|
||||||
sTexSpecular = std::move(other.sTexSpecular);
|
sTexSpecular = std::move(other.sTexSpecular);
|
||||||
|
@ -512,10 +502,10 @@ struct Material {
|
||||||
sTexBump = std::move(other.sTexBump);
|
sTexBump = std::move(other.sTexBump);
|
||||||
sTexEmissive = std::move(other.sTexEmissive);
|
sTexEmissive = std::move(other.sTexEmissive);
|
||||||
sTexShininess = std::move(other.sTexShininess);
|
sTexShininess = std::move(other.sTexShininess);
|
||||||
mBumpHeight = std::move(other.mBumpHeight);
|
mBumpHeight = other.mBumpHeight;
|
||||||
mEmissive = std::move(other.mEmissive);
|
mEmissive = other.mEmissive;
|
||||||
sTexAmbient = std::move(other.sTexAmbient);
|
sTexAmbient = std::move(other.sTexAmbient);
|
||||||
mTwoSided = std::move(other.mTwoSided);
|
mTwoSided = other.mTwoSided;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,13 @@ void Discreet3DSImporter::SetupProperties(const Importer * /*pImp*/) {
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
void Discreet3DSImporter::InternReadFile(const std::string &pFile,
|
void Discreet3DSImporter::InternReadFile(const std::string &pFile,
|
||||||
aiScene *pScene, IOSystem *pIOHandler) {
|
aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
StreamReaderLE theStream(pIOHandler->Open(pFile, "rb"));
|
|
||||||
|
auto theFile = pIOHandler->Open(pFile, "rb");
|
||||||
|
if (!theFile) {
|
||||||
|
throw DeadlyImportError("3DS: Could not open ", pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamReaderLE theStream(theFile);
|
||||||
|
|
||||||
// We should have at least one chunk
|
// We should have at least one chunk
|
||||||
if (theStream.GetRemainingSize() < 16) {
|
if (theStream.GetRemainingSize() < 16) {
|
||||||
|
@ -164,7 +170,7 @@ void Discreet3DSImporter::InternReadFile(const std::string &pFile,
|
||||||
mRootNode->mHierarchyIndex = -1;
|
mRootNode->mHierarchyIndex = -1;
|
||||||
mRootNode->mParent = nullptr;
|
mRootNode->mParent = nullptr;
|
||||||
mMasterScale = 1.0f;
|
mMasterScale = 1.0f;
|
||||||
mBackgroundImage = "";
|
mBackgroundImage = std::string();
|
||||||
bHasBG = false;
|
bHasBG = false;
|
||||||
bIsPrj = false;
|
bIsPrj = false;
|
||||||
|
|
||||||
|
@ -299,7 +305,7 @@ void Discreet3DSImporter::ParseEditorChunk() {
|
||||||
// print the version number
|
// print the version number
|
||||||
char buff[10];
|
char buff[10];
|
||||||
ASSIMP_itoa10(buff, stream->GetI2());
|
ASSIMP_itoa10(buff, stream->GetI2());
|
||||||
ASSIMP_LOG_INFO_F(std::string("3DS file format version: "), buff);
|
ASSIMP_LOG_INFO("3DS file format version: ", buff);
|
||||||
} break;
|
} break;
|
||||||
};
|
};
|
||||||
ASSIMP_3DS_END_CHUNK();
|
ASSIMP_3DS_END_CHUNK();
|
||||||
|
@ -443,7 +449,7 @@ void Discreet3DSImporter::ParseChunk(const char *name, unsigned int num) {
|
||||||
// Read the lense angle
|
// Read the lense angle
|
||||||
camera->mHorizontalFOV = AI_DEG_TO_RAD(stream->GetF4());
|
camera->mHorizontalFOV = AI_DEG_TO_RAD(stream->GetF4());
|
||||||
if (camera->mHorizontalFOV < 0.001f) {
|
if (camera->mHorizontalFOV < 0.001f) {
|
||||||
camera->mHorizontalFOV = AI_DEG_TO_RAD(45.f);
|
camera->mHorizontalFOV = float(AI_DEG_TO_RAD(45.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now check for further subchunks
|
// Now check for further subchunks
|
||||||
|
@ -928,7 +934,7 @@ void Discreet3DSImporter::ParseFaceChunk() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0xcdcdcdcd == idx) {
|
if (0xcdcdcdcd == idx) {
|
||||||
ASSIMP_LOG_ERROR_F("3DS: Unknown material: ", sz);
|
ASSIMP_LOG_ERROR("3DS: Unknown material: ", sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now continue and read all material indices
|
// Now continue and read all material indices
|
||||||
|
@ -981,9 +987,9 @@ void Discreet3DSImporter::ParseMeshChunk() {
|
||||||
mMesh.mMat.a3 = stream->GetF4();
|
mMesh.mMat.a3 = stream->GetF4();
|
||||||
mMesh.mMat.b3 = stream->GetF4();
|
mMesh.mMat.b3 = stream->GetF4();
|
||||||
mMesh.mMat.c3 = stream->GetF4();
|
mMesh.mMat.c3 = stream->GetF4();
|
||||||
mMesh.mMat.d1 = stream->GetF4();
|
mMesh.mMat.a4 = stream->GetF4();
|
||||||
mMesh.mMat.d2 = stream->GetF4();
|
mMesh.mMat.b4 = stream->GetF4();
|
||||||
mMesh.mMat.d3 = stream->GetF4();
|
mMesh.mMat.c4 = stream->GetF4();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Discreet3DS::CHUNK_MAPLIST: {
|
case Discreet3DS::CHUNK_MAPLIST: {
|
||||||
|
|
|
@ -46,11 +46,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#ifndef AI_3DSIMPORTER_H_INC
|
#ifndef AI_3DSIMPORTER_H_INC
|
||||||
#define AI_3DSIMPORTER_H_INC
|
#define AI_3DSIMPORTER_H_INC
|
||||||
|
#ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
|
||||||
|
|
||||||
#include <assimp/BaseImporter.h>
|
#include <assimp/BaseImporter.h>
|
||||||
#include <assimp/types.h>
|
#include <assimp/types.h>
|
||||||
|
|
||||||
#ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
|
|
||||||
|
|
||||||
#include "3DSHelper.h"
|
#include "3DSHelper.h"
|
||||||
#include <assimp/StreamReader.h>
|
#include <assimp/StreamReader.h>
|
||||||
|
@ -75,14 +75,14 @@ public:
|
||||||
* See BaseImporter::CanRead() for details.
|
* See BaseImporter::CanRead() for details.
|
||||||
*/
|
*/
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Called prior to ReadFile().
|
/** Called prior to ReadFile().
|
||||||
* The function is a request to the importer to update its configuration
|
* The function is a request to the importer to update its configuration
|
||||||
* basing on the Importer's configuration property list.
|
* basing on the Importer's configuration property list.
|
||||||
*/
|
*/
|
||||||
void SetupProperties(const Importer* pImp);
|
void SetupProperties(const Importer* pImp) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -90,14 +90,14 @@ protected:
|
||||||
/** Return importer meta information.
|
/** Return importer meta information.
|
||||||
* See #BaseImporter::GetInfo for the details
|
* See #BaseImporter::GetInfo for the details
|
||||||
*/
|
*/
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc* GetInfo () const override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Imports the given file into the given scene structure.
|
/** Imports the given file into the given scene structure.
|
||||||
* See BaseImporter::InternReadFile() for details
|
* See BaseImporter::InternReadFile() for details
|
||||||
*/
|
*/
|
||||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||||
IOSystem* pIOHandler);
|
IOSystem* pIOHandler) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Converts a temporary material to the outer representation
|
/** Converts a temporary material to the outer representation
|
||||||
|
@ -208,6 +208,15 @@ protected:
|
||||||
*/
|
*/
|
||||||
void ReplaceDefaultMaterial();
|
void ReplaceDefaultMaterial();
|
||||||
|
|
||||||
|
bool ContainsTextures(unsigned int i) const {
|
||||||
|
return !mScene->mMaterials[i].sTexDiffuse.mMapName.empty() ||
|
||||||
|
!mScene->mMaterials[i].sTexBump.mMapName.empty() ||
|
||||||
|
!mScene->mMaterials[i].sTexOpacity.mMapName.empty() ||
|
||||||
|
!mScene->mMaterials[i].sTexEmissive.mMapName.empty() ||
|
||||||
|
!mScene->mMaterials[i].sTexSpecular.mMapName.empty() ||
|
||||||
|
!mScene->mMaterials[i].sTexShininess.mMapName.empty() ;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Convert the whole scene
|
/** Convert the whole scene
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2021, 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.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <assimp/vector3.h>
|
||||||
|
#include <assimp/matrix4x4.h>
|
||||||
|
#include <assimp/ParsingUtils.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct aiMaterial;
|
||||||
|
struct aiMesh;
|
||||||
|
|
||||||
|
namespace Assimp {
|
||||||
|
namespace D3MF {
|
||||||
|
|
||||||
|
enum class ResourceType {
|
||||||
|
RT_Object,
|
||||||
|
RT_BaseMaterials,
|
||||||
|
RT_EmbeddedTexture2D,
|
||||||
|
RT_Texture2DGroup,
|
||||||
|
RT_Unknown
|
||||||
|
}; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...)
|
||||||
|
|
||||||
|
class Resource {
|
||||||
|
public:
|
||||||
|
int mId;
|
||||||
|
|
||||||
|
Resource(int id) :
|
||||||
|
mId(id) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Resource() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ResourceType getType() const {
|
||||||
|
return ResourceType::RT_Unknown;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class EmbeddedTexture : public Resource {
|
||||||
|
public:
|
||||||
|
std::string mPath;
|
||||||
|
std::string mContentType;
|
||||||
|
std::string mTilestyleU;
|
||||||
|
std::string mTilestyleV;
|
||||||
|
std::vector<char> mBuffer;
|
||||||
|
|
||||||
|
EmbeddedTexture(int id) :
|
||||||
|
Resource(id),
|
||||||
|
mPath(),
|
||||||
|
mContentType(),
|
||||||
|
mTilestyleU(),
|
||||||
|
mTilestyleV() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
~EmbeddedTexture() = default;
|
||||||
|
|
||||||
|
ResourceType getType() const override {
|
||||||
|
return ResourceType::RT_EmbeddedTexture2D;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Texture2DGroup : public Resource {
|
||||||
|
public:
|
||||||
|
std::vector<aiVector2D> mTex2dCoords;
|
||||||
|
int mTexId;
|
||||||
|
Texture2DGroup(int id) :
|
||||||
|
Resource(id),
|
||||||
|
mTexId(-1) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
~Texture2DGroup() = default;
|
||||||
|
|
||||||
|
ResourceType getType() const override {
|
||||||
|
return ResourceType::RT_Texture2DGroup;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class BaseMaterials : public Resource {
|
||||||
|
public:
|
||||||
|
std::vector<unsigned int> mMaterialIndex;
|
||||||
|
|
||||||
|
BaseMaterials(int id) :
|
||||||
|
Resource(id),
|
||||||
|
mMaterialIndex() {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
~BaseMaterials() = default;
|
||||||
|
|
||||||
|
ResourceType getType() const override {
|
||||||
|
return ResourceType::RT_BaseMaterials;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Component {
|
||||||
|
int mObjectId;
|
||||||
|
aiMatrix4x4 mTransformation;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Object : public Resource {
|
||||||
|
public:
|
||||||
|
std::vector<aiMesh *> mMeshes;
|
||||||
|
std::vector<unsigned int> mMeshIndex;
|
||||||
|
std::vector<Component> mComponents;
|
||||||
|
std::string mName;
|
||||||
|
|
||||||
|
Object(int id) :
|
||||||
|
Resource(id),
|
||||||
|
mName(std::string("Object_") + ai_to_string(id)) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
|
|
||||||
|
~Object() = default;
|
||||||
|
|
||||||
|
ResourceType getType() const override {
|
||||||
|
return ResourceType::RT_Object;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace D3MF
|
||||||
|
} // namespace Assimp
|
|
@ -44,62 +44,73 @@ namespace Assimp {
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
|
|
||||||
namespace XmlTag {
|
namespace XmlTag {
|
||||||
|
// Root tag
|
||||||
|
const char* const RootTag = "3MF";
|
||||||
|
|
||||||
// Meta-data
|
// Meta-data
|
||||||
static const std::string meta = "metadata";
|
const char* const meta = "metadata";
|
||||||
static const std::string meta_name = "name";
|
const char* const meta_name = "name";
|
||||||
|
|
||||||
// Model-data specific tags
|
// Model-data specific tags
|
||||||
static const std::string model = "model";
|
const char* const model = "model";
|
||||||
static const std::string model_unit = "unit";
|
const char* const model_unit = "unit";
|
||||||
static const std::string metadata = "metadata";
|
const char* const metadata = "metadata";
|
||||||
static const std::string resources = "resources";
|
const char* const resources = "resources";
|
||||||
static const std::string object = "object";
|
const char* const object = "object";
|
||||||
static const std::string mesh = "mesh";
|
const char* const mesh = "mesh";
|
||||||
static const std::string components = "components";
|
const char* const components = "components";
|
||||||
static const std::string component = "component";
|
const char* const component = "component";
|
||||||
static const std::string vertices = "vertices";
|
const char* const vertices = "vertices";
|
||||||
static const std::string vertex = "vertex";
|
const char* const vertex = "vertex";
|
||||||
static const std::string triangles = "triangles";
|
const char* const triangles = "triangles";
|
||||||
static const std::string triangle = "triangle";
|
const char* const triangle = "triangle";
|
||||||
static const std::string x = "x";
|
const char* const x = "x";
|
||||||
static const std::string y = "y";
|
const char* const y = "y";
|
||||||
static const std::string z = "z";
|
const char* const z = "z";
|
||||||
static const std::string v1 = "v1";
|
const char* const v1 = "v1";
|
||||||
static const std::string v2 = "v2";
|
const char* const v2 = "v2";
|
||||||
static const std::string v3 = "v3";
|
const char* const v3 = "v3";
|
||||||
static const std::string id = "id";
|
const char* const id = "id";
|
||||||
static const std::string pid = "pid";
|
const char* const pid = "pid";
|
||||||
static const std::string pindex = "pindex";
|
const char* const pindex = "pindex";
|
||||||
static const std::string p1 = "p1";
|
const char* const p1 = "p1";
|
||||||
static const std::string name = "name";
|
const char* const name = "name";
|
||||||
static const std::string type = "type";
|
const char* const type = "type";
|
||||||
static const std::string build = "build";
|
const char* const build = "build";
|
||||||
static const std::string item = "item";
|
const char* const item = "item";
|
||||||
static const std::string objectid = "objectid";
|
const char* const objectid = "objectid";
|
||||||
static const std::string transform = "transform";
|
const char* const transform = "transform";
|
||||||
|
const char *const path = "path";
|
||||||
|
|
||||||
// Material definitions
|
// Material definitions
|
||||||
static const std::string basematerials = "basematerials";
|
const char* const basematerials = "basematerials";
|
||||||
static const std::string basematerials_id = "id";
|
const char* const basematerials_base = "base";
|
||||||
static const std::string basematerials_base = "base";
|
const char* const basematerials_name = "name";
|
||||||
static const std::string basematerials_name = "name";
|
const char* const basematerials_displaycolor = "displaycolor";
|
||||||
static const std::string basematerials_displaycolor = "displaycolor";
|
const char* const texture_2d = "m:texture2d";
|
||||||
|
const char *const texture_group = "m:texture2dgroup";
|
||||||
|
const char *const texture_content_type = "contenttype";
|
||||||
|
const char *const texture_tilestyleu = "tilestyleu";
|
||||||
|
const char *const texture_tilestylev = "tilestylev";
|
||||||
|
const char *const texture_2d_coord = "m:tex2coord";
|
||||||
|
const char *const texture_cuurd_u = "u";
|
||||||
|
const char *const texture_cuurd_v = "v";
|
||||||
|
|
||||||
// Meta info tags
|
// Meta info tags
|
||||||
static const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
|
const char* const CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
|
||||||
static const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
|
const char* const ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
|
||||||
static const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
|
const char* const SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
|
||||||
static const std::string SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
const char* const SCHEMA_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
|
||||||
static const std::string RELS_RELATIONSHIP_CONTAINER = "Relationships";
|
const char* const RELS_RELATIONSHIP_CONTAINER = "Relationships";
|
||||||
static const std::string RELS_RELATIONSHIP_NODE = "Relationship";
|
const char* const RELS_RELATIONSHIP_NODE = "Relationship";
|
||||||
static const std::string RELS_ATTRIB_TARGET = "Target";
|
const char* const RELS_ATTRIB_TARGET = "Target";
|
||||||
static const std::string RELS_ATTRIB_TYPE = "Type";
|
const char* const RELS_ATTRIB_TYPE = "Type";
|
||||||
static const std::string RELS_ATTRIB_ID = "Id";
|
const char* const RELS_ATTRIB_ID = "Id";
|
||||||
static const std::string PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
const char* const PACKAGE_START_PART_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
|
||||||
static const std::string PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
|
const char* const PACKAGE_PRINT_TICKET_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
|
||||||
static const std::string PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
|
const char* const PACKAGE_TEXTURE_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dtexture";
|
||||||
static const std::string PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
const char* const PACKAGE_CORE_PROPERTIES_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
|
||||||
static const std::string PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
|
const char* const PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Namespace D3MF
|
} // Namespace D3MF
|
||||||
|
|
|
@ -307,18 +307,26 @@ void D3MFExporter::writeMesh(aiMesh *mesh) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mModelOutput << "<" << XmlTag::mesh << ">" << std::endl;
|
mModelOutput << "<"
|
||||||
mModelOutput << "<" << XmlTag::vertices << ">" << std::endl;
|
<< XmlTag::mesh
|
||||||
|
<< ">" << "\n";
|
||||||
|
mModelOutput << "<"
|
||||||
|
<< XmlTag::vertices
|
||||||
|
<< ">" << "\n";
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
||||||
writeVertex(mesh->mVertices[i]);
|
writeVertex(mesh->mVertices[i]);
|
||||||
}
|
}
|
||||||
mModelOutput << "</" << XmlTag::vertices << ">" << std::endl;
|
mModelOutput << "</"
|
||||||
|
<< XmlTag::vertices << ">"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
const unsigned int matIdx(mesh->mMaterialIndex);
|
const unsigned int matIdx(mesh->mMaterialIndex);
|
||||||
|
|
||||||
writeFaces(mesh, matIdx);
|
writeFaces(mesh, matIdx);
|
||||||
|
|
||||||
mModelOutput << "</" << XmlTag::mesh << ">" << std::endl;
|
mModelOutput << "</"
|
||||||
|
<< XmlTag::mesh << ">"
|
||||||
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFExporter::writeVertex(const aiVector3D &pos) {
|
void D3MFExporter::writeVertex(const aiVector3D &pos) {
|
||||||
|
@ -334,27 +342,34 @@ void D3MFExporter::writeFaces(aiMesh *mesh, unsigned int matIdx) {
|
||||||
if (!mesh->HasFaces()) {
|
if (!mesh->HasFaces()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mModelOutput << "<" << XmlTag::triangles << ">" << std::endl;
|
mModelOutput << "<"
|
||||||
|
<< XmlTag::triangles << ">"
|
||||||
|
<< "\n";
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
for (unsigned int i = 0; i < mesh->mNumFaces; ++i) {
|
||||||
aiFace ¤tFace = mesh->mFaces[i];
|
aiFace ¤tFace = mesh->mFaces[i];
|
||||||
mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[0] << "\" v2=\""
|
mModelOutput << "<" << XmlTag::triangle << " v1=\"" << currentFace.mIndices[0] << "\" v2=\""
|
||||||
<< currentFace.mIndices[1] << "\" v3=\"" << currentFace.mIndices[2]
|
<< currentFace.mIndices[1] << "\" v3=\"" << currentFace.mIndices[2]
|
||||||
<< "\" pid=\"1\" p1=\"" + ai_to_string(matIdx) + "\" />";
|
<< "\" pid=\"1\" p1=\"" + ai_to_string(matIdx) + "\" />";
|
||||||
mModelOutput << std::endl;
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
mModelOutput << "</" << XmlTag::triangles << ">";
|
mModelOutput << "</"
|
||||||
mModelOutput << std::endl;
|
<< XmlTag::triangles
|
||||||
|
<< ">";
|
||||||
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFExporter::writeBuild() {
|
void D3MFExporter::writeBuild() {
|
||||||
mModelOutput << "<" << XmlTag::build << ">" << std::endl;
|
mModelOutput << "<"
|
||||||
|
<< XmlTag::build
|
||||||
|
<< ">"
|
||||||
|
<< "\n";
|
||||||
|
|
||||||
for (size_t i = 0; i < mBuildItems.size(); ++i) {
|
for (size_t i = 0; i < mBuildItems.size(); ++i) {
|
||||||
mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 2 << "\"/>";
|
mModelOutput << "<" << XmlTag::item << " objectid=\"" << i + 2 << "\"/>";
|
||||||
mModelOutput << std::endl;
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
mModelOutput << "</" << XmlTag::build << ">";
|
mModelOutput << "</" << XmlTag::build << ">";
|
||||||
mModelOutput << std::endl;
|
mModelOutput << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFExporter::zipContentType(const std::string &filename) {
|
void D3MFExporter::zipContentType(const std::string &filename) {
|
||||||
|
|
|
@ -40,6 +40,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||||
|
#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -58,8 +61,6 @@ class IOStream;
|
||||||
|
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
|
|
||||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
|
||||||
#ifndef ASSIMP_BUILD_NO_3MF_EXPORTER
|
|
||||||
|
|
||||||
struct OpcPackageRelationship;
|
struct OpcPackageRelationship;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
|
#ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
|
||||||
|
|
||||||
#include "D3MFImporter.h"
|
#include "D3MFImporter.h"
|
||||||
|
#include "3MFXmlTags.h"
|
||||||
|
#include "D3MFOpcPackage.h"
|
||||||
|
#include "XmlSerializer.h"
|
||||||
|
|
||||||
#include <assimp/StringComparison.h>
|
#include <assimp/StringComparison.h>
|
||||||
#include <assimp/StringUtils.h>
|
#include <assimp/StringUtils.h>
|
||||||
|
@ -51,517 +54,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
|
#include <assimp/fast_atof.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "3MFXmlTags.h"
|
|
||||||
#include "D3MFOpcPackage.h"
|
|
||||||
#include <assimp/fast_atof.h>
|
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace D3MF {
|
|
||||||
|
|
||||||
enum class ResourceType {
|
using namespace D3MF;
|
||||||
RT_Object,
|
|
||||||
RT_BaseMaterials,
|
|
||||||
RT_Unknown
|
|
||||||
}; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...)
|
|
||||||
|
|
||||||
class Resource
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Resource(int id) :
|
|
||||||
mId(id) {}
|
|
||||||
|
|
||||||
virtual ~Resource() {}
|
|
||||||
|
|
||||||
int mId;
|
|
||||||
|
|
||||||
virtual ResourceType getType() {
|
|
||||||
return ResourceType::RT_Unknown;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class BaseMaterials : public Resource {
|
|
||||||
public:
|
|
||||||
BaseMaterials(int id) :
|
|
||||||
Resource(id),
|
|
||||||
mMaterials(),
|
|
||||||
mMaterialIndex() {}
|
|
||||||
|
|
||||||
std::vector<aiMaterial *> mMaterials;
|
|
||||||
std::vector<unsigned int> mMaterialIndex;
|
|
||||||
|
|
||||||
virtual ResourceType getType() {
|
|
||||||
return ResourceType::RT_BaseMaterials;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Component {
|
|
||||||
int mObjectId;
|
|
||||||
aiMatrix4x4 mTransformation;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Object : public Resource {
|
|
||||||
public:
|
|
||||||
std::vector<aiMesh*> mMeshes;
|
|
||||||
std::vector<unsigned int> mMeshIndex;
|
|
||||||
std::vector<Component> mComponents;
|
|
||||||
std::string mName;
|
|
||||||
|
|
||||||
Object(int id) :
|
|
||||||
Resource(id),
|
|
||||||
mName(std::string("Object_") + ai_to_string(id)) {}
|
|
||||||
|
|
||||||
virtual ResourceType getType() {
|
|
||||||
return ResourceType::RT_Object;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class XmlSerializer {
|
|
||||||
public:
|
|
||||||
|
|
||||||
XmlSerializer(XmlParser *xmlParser) :
|
|
||||||
mResourcesDictionnary(),
|
|
||||||
mMaterialCount(0),
|
|
||||||
mMeshCount(0),
|
|
||||||
mXmlParser(xmlParser) {
|
|
||||||
// empty
|
|
||||||
}
|
|
||||||
|
|
||||||
~XmlSerializer() {
|
|
||||||
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
|
|
||||||
delete it->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImportXml(aiScene *scene) {
|
|
||||||
if (nullptr == scene) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
scene->mRootNode = new aiNode("3MF");
|
|
||||||
|
|
||||||
XmlNode node = mXmlParser->getRootNode().child("model");
|
|
||||||
if (node.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
XmlNode resNode = node.child("resources");
|
|
||||||
for (XmlNode currentNode = resNode.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
|
||||||
const std::string ¤tNodeName = currentNode.name();
|
|
||||||
if (currentNodeName == D3MF::XmlTag::object) {
|
|
||||||
ReadObject(currentNode);;
|
|
||||||
} else if (currentNodeName == D3MF::XmlTag::basematerials) {
|
|
||||||
ReadBaseMaterials(currentNode);
|
|
||||||
} else if (currentNodeName == D3MF::XmlTag::meta) {
|
|
||||||
ReadMetadata(currentNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XmlNode buildNode = node.child("build");
|
|
||||||
for (XmlNode currentNode = buildNode.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
|
||||||
const std::string ¤tNodeName = currentNode.name();
|
|
||||||
if (currentNodeName == D3MF::XmlTag::item) {
|
|
||||||
int objectId = -1;
|
|
||||||
std::string transformationMatrixStr;
|
|
||||||
aiMatrix4x4 transformationMatrix;
|
|
||||||
getNodeAttribute(currentNode, D3MF::XmlTag::objectid, objectId);
|
|
||||||
bool hasTransform = getNodeAttribute(currentNode, D3MF::XmlTag::transform, transformationMatrixStr);
|
|
||||||
|
|
||||||
auto it = mResourcesDictionnary.find(objectId);
|
|
||||||
if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
|
|
||||||
Object *obj = static_cast<Object *>(it->second);
|
|
||||||
if (hasTransform) {
|
|
||||||
transformationMatrix = parseTransformMatrix(transformationMatrixStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
addObjectToNode(scene->mRootNode, obj, transformationMatrix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// import the metadata
|
|
||||||
if (!mMetaData.empty()) {
|
|
||||||
const size_t numMeta(mMetaData.size());
|
|
||||||
scene->mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(numMeta));
|
|
||||||
for (size_t i = 0; i < numMeta; ++i) {
|
|
||||||
aiString val(mMetaData[i].value);
|
|
||||||
scene->mMetaData->Set(static_cast<unsigned int>(i), mMetaData[i].name, val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// import the meshes
|
|
||||||
scene->mNumMeshes = static_cast<unsigned int>(mMeshCount);
|
|
||||||
if (scene->mNumMeshes != 0) {
|
|
||||||
scene->mMeshes = new aiMesh *[scene->mNumMeshes]();
|
|
||||||
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
|
|
||||||
if (it->second->getType() == ResourceType::RT_Object) {
|
|
||||||
Object *obj = static_cast<Object*>(it->second);
|
|
||||||
for (unsigned int i = 0; i < obj->mMeshes.size(); ++i) {
|
|
||||||
scene->mMeshes[obj->mMeshIndex[i]] = obj->mMeshes[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// import the materials
|
|
||||||
scene->mNumMaterials = static_cast<unsigned int>(mMaterialCount);
|
|
||||||
if (scene->mNumMaterials != 0) {
|
|
||||||
scene->mMaterials = new aiMaterial *[scene->mNumMaterials];
|
|
||||||
for (auto it = mResourcesDictionnary.begin(); it != mResourcesDictionnary.end(); it++) {
|
|
||||||
if (it->second->getType() == ResourceType::RT_BaseMaterials) {
|
|
||||||
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
|
|
||||||
for (unsigned int i = 0; i < baseMaterials->mMaterials.size(); ++i) {
|
|
||||||
scene->mMaterials[baseMaterials->mMaterialIndex[i]] = baseMaterials->mMaterials[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void addObjectToNode(aiNode* parent, Object* obj, aiMatrix4x4 nodeTransform) {
|
|
||||||
aiNode *sceneNode = new aiNode(obj->mName);
|
|
||||||
sceneNode->mNumMeshes = static_cast<unsigned int>(obj->mMeshes.size());
|
|
||||||
sceneNode->mMeshes = new unsigned int[sceneNode->mNumMeshes];
|
|
||||||
std::copy(obj->mMeshIndex.begin(), obj->mMeshIndex.end(), sceneNode->mMeshes);
|
|
||||||
|
|
||||||
sceneNode->mTransformation = nodeTransform;
|
|
||||||
|
|
||||||
parent->addChildren(1, &sceneNode);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < obj->mComponents.size(); ++i) {
|
|
||||||
Component c = obj->mComponents[i];
|
|
||||||
auto it = mResourcesDictionnary.find(c.mObjectId);
|
|
||||||
if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
|
|
||||||
addObjectToNode(sceneNode, static_cast<Object*>(it->second), c.mTransformation);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getNodeAttribute(const XmlNode& node, const std::string& attribute, std::string& value) {
|
|
||||||
pugi::xml_attribute objectAttribute = node.attribute(attribute.c_str());
|
|
||||||
if (!objectAttribute.empty()) {
|
|
||||||
value = objectAttribute.as_string();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool getNodeAttribute(const XmlNode &node, const std::string &attribute, int &value) {
|
|
||||||
std::string strValue;
|
|
||||||
bool ret = getNodeAttribute(node, attribute, strValue);
|
|
||||||
if (ret) {
|
|
||||||
value = std::atoi(strValue.c_str());
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
aiMatrix4x4 parseTransformMatrix(std::string matrixStr) {
|
|
||||||
// split the string
|
|
||||||
std::vector<float> numbers;
|
|
||||||
std::string currentNumber;
|
|
||||||
for (size_t i = 0; i < matrixStr.size(); ++i) {
|
|
||||||
const char c = matrixStr[i];
|
|
||||||
if (c == ' ') {
|
|
||||||
if (currentNumber.size() > 0) {
|
|
||||||
float f = std::stof(currentNumber);
|
|
||||||
numbers.push_back(f);
|
|
||||||
currentNumber.clear();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentNumber.push_back(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (currentNumber.size() > 0) {
|
|
||||||
float f = std::stof(currentNumber);
|
|
||||||
numbers.push_back(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
aiMatrix4x4 transformMatrix;
|
|
||||||
transformMatrix.a1 = numbers[0];
|
|
||||||
transformMatrix.b1 = numbers[1];
|
|
||||||
transformMatrix.c1 = numbers[2];
|
|
||||||
transformMatrix.d1 = 0;
|
|
||||||
|
|
||||||
transformMatrix.a2 = numbers[3];
|
|
||||||
transformMatrix.b2 = numbers[4];
|
|
||||||
transformMatrix.c2 = numbers[5];
|
|
||||||
transformMatrix.d2 = 0;
|
|
||||||
|
|
||||||
transformMatrix.a3 = numbers[6];
|
|
||||||
transformMatrix.b3 = numbers[7];
|
|
||||||
transformMatrix.c3 = numbers[8];
|
|
||||||
transformMatrix.d3 = 0;
|
|
||||||
|
|
||||||
transformMatrix.a4 = numbers[9];
|
|
||||||
transformMatrix.b4 = numbers[10];
|
|
||||||
transformMatrix.c4 = numbers[11];
|
|
||||||
transformMatrix.d4 = 1;
|
|
||||||
return transformMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReadObject(XmlNode &node) {
|
|
||||||
int id = -1, pid = -1, pindex = -1;
|
|
||||||
bool hasId = getNodeAttribute(node, D3MF::XmlTag::id, id);
|
|
||||||
//bool hasType = getNodeAttribute(node, D3MF::XmlTag::type, type); not used currently
|
|
||||||
bool hasPid = getNodeAttribute(node, D3MF::XmlTag::pid, pid);
|
|
||||||
bool hasPindex = getNodeAttribute(node, D3MF::XmlTag::pindex, pindex);
|
|
||||||
|
|
||||||
std::string idStr = ai_to_string(id);
|
|
||||||
|
|
||||||
if (!hasId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object *obj = new Object(id);
|
|
||||||
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
|
||||||
const std::string ¤tName = currentNode.name();
|
|
||||||
if (currentName == D3MF::XmlTag::mesh) {
|
|
||||||
auto mesh = ReadMesh(currentNode);
|
|
||||||
mesh->mName.Set(idStr);
|
|
||||||
|
|
||||||
if (hasPid) {
|
|
||||||
auto it = mResourcesDictionnary.find(pid);
|
|
||||||
if (hasPindex && it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_BaseMaterials) {
|
|
||||||
BaseMaterials *materials = static_cast<BaseMaterials *>(it->second);
|
|
||||||
mesh->mMaterialIndex = materials->mMaterialIndex[pindex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->mMeshes.push_back(mesh);
|
|
||||||
obj->mMeshIndex.push_back(mMeshCount);
|
|
||||||
mMeshCount++;
|
|
||||||
} else if (currentName == D3MF::XmlTag::components) {
|
|
||||||
for (XmlNode currentSubNode = currentNode.first_child(); currentSubNode; currentSubNode = currentSubNode.next_sibling()) {
|
|
||||||
if (currentSubNode.name() == D3MF::XmlTag::component) {
|
|
||||||
int objectId = -1;
|
|
||||||
std::string componentTransformStr;
|
|
||||||
aiMatrix4x4 componentTransform;
|
|
||||||
if (getNodeAttribute(currentSubNode, D3MF::XmlTag::transform, componentTransformStr)) {
|
|
||||||
componentTransform = parseTransformMatrix(componentTransformStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getNodeAttribute(currentSubNode, D3MF::XmlTag::objectid, objectId))
|
|
||||||
obj->mComponents.push_back({ objectId, componentTransform });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mResourcesDictionnary.insert(std::make_pair(id, obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
aiMesh *ReadMesh(XmlNode &node) {
|
|
||||||
aiMesh *mesh = new aiMesh();
|
|
||||||
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
|
||||||
const std::string ¤tName = currentNode.name();
|
|
||||||
if (currentName == D3MF::XmlTag::vertices) {
|
|
||||||
ImportVertices(currentNode, mesh);
|
|
||||||
} else if (currentName == D3MF::XmlTag::triangles) {
|
|
||||||
ImportTriangles(currentNode, mesh);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return mesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReadMetadata(XmlNode &node) {
|
|
||||||
pugi::xml_attribute attribute = node.attribute(D3MF::XmlTag::meta_name.c_str());
|
|
||||||
const std::string name = attribute.as_string();
|
|
||||||
const std::string value = node.value();
|
|
||||||
if (name.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MetaEntry entry;
|
|
||||||
entry.name = name;
|
|
||||||
entry.value = value;
|
|
||||||
mMetaData.push_back(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImportVertices(XmlNode &node, aiMesh *mesh) {
|
|
||||||
std::vector<aiVector3D> vertices;
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
|
||||||
const std::string ¤tName = currentNode.name();
|
|
||||||
if (currentName == D3MF::XmlTag::vertex) {
|
|
||||||
vertices.push_back(ReadVertex(currentNode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh->mNumVertices = static_cast<unsigned int>(vertices.size());
|
|
||||||
mesh->mVertices = new aiVector3D[mesh->mNumVertices];
|
|
||||||
std::copy(vertices.begin(), vertices.end(), mesh->mVertices);
|
|
||||||
}
|
|
||||||
|
|
||||||
aiVector3D ReadVertex(XmlNode &node) {
|
|
||||||
aiVector3D vertex;
|
|
||||||
vertex.x = ai_strtof(node.attribute(D3MF::XmlTag::x.c_str()).as_string(), nullptr);
|
|
||||||
vertex.y = ai_strtof(node.attribute(D3MF::XmlTag::y.c_str()).as_string(), nullptr);
|
|
||||||
vertex.z = ai_strtof(node.attribute(D3MF::XmlTag::z.c_str()).as_string(), nullptr);
|
|
||||||
|
|
||||||
return vertex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImportTriangles(XmlNode &node, aiMesh *mesh) {
|
|
||||||
std::vector<aiFace> faces;
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
|
||||||
const std::string ¤tName = currentNode.name();
|
|
||||||
if (currentName == D3MF::XmlTag::triangle) {
|
|
||||||
aiFace face = ReadTriangle(currentNode);
|
|
||||||
faces.push_back(face);
|
|
||||||
|
|
||||||
int pid = 0, p1;
|
|
||||||
bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid);
|
|
||||||
bool hasP1 = getNodeAttribute(currentNode, D3MF::XmlTag::p1, p1);
|
|
||||||
|
|
||||||
if (hasPid && hasP1) {
|
|
||||||
auto it = mResourcesDictionnary.find(pid);
|
|
||||||
if (it != mResourcesDictionnary.end())
|
|
||||||
{
|
|
||||||
if (it->second->getType() == ResourceType::RT_BaseMaterials) {
|
|
||||||
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
|
|
||||||
mesh->mMaterialIndex = baseMaterials->mMaterialIndex[p1];
|
|
||||||
}
|
|
||||||
// TODO: manage the separation into several meshes if the triangles of the mesh do not all refer to the same material
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh->mNumFaces = static_cast<unsigned int>(faces.size());
|
|
||||||
mesh->mFaces = new aiFace[mesh->mNumFaces];
|
|
||||||
mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
|
||||||
|
|
||||||
std::copy(faces.begin(), faces.end(), mesh->mFaces);
|
|
||||||
}
|
|
||||||
|
|
||||||
aiFace ReadTriangle(XmlNode &node) {
|
|
||||||
aiFace face;
|
|
||||||
|
|
||||||
face.mNumIndices = 3;
|
|
||||||
face.mIndices = new unsigned int[face.mNumIndices];
|
|
||||||
face.mIndices[0] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v1.c_str()).as_string()));
|
|
||||||
face.mIndices[1] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v2.c_str()).as_string()));
|
|
||||||
face.mIndices[2] = static_cast<unsigned int>(std::atoi(node.attribute(D3MF::XmlTag::v3.c_str()).as_string()));
|
|
||||||
|
|
||||||
return face;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReadBaseMaterials(XmlNode &node) {
|
|
||||||
int id = -1;
|
|
||||||
if (getNodeAttribute(node, D3MF::XmlTag::basematerials_id, id)) {
|
|
||||||
BaseMaterials* baseMaterials = new BaseMaterials(id);
|
|
||||||
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling())
|
|
||||||
{
|
|
||||||
if (currentNode.name() == D3MF::XmlTag::basematerials_base) {
|
|
||||||
baseMaterials->mMaterialIndex.push_back(mMaterialCount);
|
|
||||||
baseMaterials->mMaterials.push_back(readMaterialDef(currentNode, id));
|
|
||||||
mMaterialCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mResourcesDictionnary.insert(std::make_pair(id, baseMaterials));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool parseColor(const char *color, aiColor4D &diffuse) {
|
|
||||||
if (nullptr == color) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1)
|
|
||||||
const size_t len(strlen(color));
|
|
||||||
if (9 != len && 7 != len) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *buf(color);
|
|
||||||
if ('#' != buf[0]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char r[3] = { buf[1], buf[2], '\0' };
|
|
||||||
diffuse.r = static_cast<ai_real>(strtol(r, nullptr, 16)) / ai_real(255.0);
|
|
||||||
|
|
||||||
char g[3] = { buf[3], buf[4], '\0' };
|
|
||||||
diffuse.g = static_cast<ai_real>(strtol(g, nullptr, 16)) / ai_real(255.0);
|
|
||||||
|
|
||||||
char b[3] = { buf[5], buf[6], '\0' };
|
|
||||||
diffuse.b = static_cast<ai_real>(strtol(b, nullptr, 16)) / ai_real(255.0);
|
|
||||||
|
|
||||||
if (7 == len)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
char a[3] = { buf[7], buf[8], '\0' };
|
|
||||||
diffuse.a = static_cast<ai_real>(strtol(a, nullptr, 16)) / ai_real(255.0);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void assignDiffuseColor(XmlNode &node, aiMaterial *mat) {
|
|
||||||
const char *color = node.attribute(D3MF::XmlTag::basematerials_displaycolor.c_str()).as_string();
|
|
||||||
aiColor4D diffuse;
|
|
||||||
if (parseColor(color, diffuse)) {
|
|
||||||
mat->AddProperty<aiColor4D>(&diffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
aiMaterial *readMaterialDef(XmlNode &node, unsigned int basematerialsId) {
|
|
||||||
aiMaterial *material = new aiMaterial();
|
|
||||||
material->mNumProperties = 0;
|
|
||||||
std::string name;
|
|
||||||
bool hasName = getNodeAttribute(node, D3MF::XmlTag::basematerials_name, name);
|
|
||||||
|
|
||||||
std::string stdMaterialName;
|
|
||||||
std::string strId(ai_to_string(basematerialsId));
|
|
||||||
stdMaterialName += "id";
|
|
||||||
stdMaterialName += strId;
|
|
||||||
stdMaterialName += "_";
|
|
||||||
if (hasName) {
|
|
||||||
stdMaterialName += std::string(name);
|
|
||||||
} else {
|
|
||||||
stdMaterialName += "basemat_";
|
|
||||||
stdMaterialName += ai_to_string(mMaterialCount - basematerialsId);
|
|
||||||
}
|
|
||||||
|
|
||||||
aiString assimpMaterialName(stdMaterialName);
|
|
||||||
material->AddProperty(&assimpMaterialName, AI_MATKEY_NAME);
|
|
||||||
|
|
||||||
assignDiffuseColor(node, material);
|
|
||||||
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct MetaEntry {
|
|
||||||
std::string name;
|
|
||||||
std::string value;
|
|
||||||
};
|
|
||||||
std::vector<MetaEntry> mMetaData;
|
|
||||||
std::map<unsigned int, Resource*> mResourcesDictionnary;
|
|
||||||
unsigned int mMaterialCount, mMeshCount;
|
|
||||||
XmlParser *mXmlParser;
|
|
||||||
};
|
|
||||||
|
|
||||||
} //namespace D3MF
|
|
||||||
|
|
||||||
static const aiImporterDesc desc = {
|
static const aiImporterDesc desc = {
|
||||||
"3mf Importer",
|
"3mf Importer",
|
||||||
|
@ -589,21 +94,23 @@ bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bo
|
||||||
const std::string extension(GetExtension(filename));
|
const std::string extension(GetExtension(filename));
|
||||||
if (extension == desc.mFileExtensions) {
|
if (extension == desc.mFileExtensions) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!extension.length() || checkSig) {
|
}
|
||||||
|
|
||||||
|
if (!extension.length() || checkSig) {
|
||||||
if (nullptr == pIOHandler) {
|
if (nullptr == pIOHandler) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) {
|
if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename);
|
D3MFOpcPackage opcPackage(pIOHandler, filename);
|
||||||
return opcPackage.validate();
|
return opcPackage.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFImporter::SetupProperties(const Importer * /*pImp*/) {
|
void D3MFImporter::SetupProperties(const Importer*) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -612,12 +119,21 @@ const aiImporterDesc *D3MFImporter::GetInfo() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3MFImporter::InternReadFile(const std::string &filename, aiScene *pScene, IOSystem *pIOHandler) {
|
void D3MFImporter::InternReadFile(const std::string &filename, aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename);
|
D3MFOpcPackage opcPackage(pIOHandler, filename);
|
||||||
|
|
||||||
XmlParser xmlParser;
|
XmlParser xmlParser;
|
||||||
if (xmlParser.parse(opcPackage.RootStream())) {
|
if (xmlParser.parse(opcPackage.RootStream())) {
|
||||||
D3MF::XmlSerializer xmlSerializer(&xmlParser);
|
XmlSerializer xmlSerializer(&xmlParser);
|
||||||
xmlSerializer.ImportXml(pScene);
|
xmlSerializer.ImportXml(pScene);
|
||||||
|
|
||||||
|
const std::vector<aiTexture*> &tex = opcPackage.GetEmbeddedTextures();
|
||||||
|
if (!tex.empty()) {
|
||||||
|
pScene->mNumTextures = static_cast<unsigned int>(tex.size());
|
||||||
|
pScene->mTextures = new aiTexture *[pScene->mNumTextures];
|
||||||
|
for (unsigned int i = 0; i < pScene->mNumTextures; ++i) {
|
||||||
|
pScene->mTextures[i] = tex[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,23 +42,50 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef AI_D3MFLOADER_H_INCLUDED
|
#ifndef AI_D3MFLOADER_H_INCLUDED
|
||||||
#define AI_D3MFLOADER_H_INCLUDED
|
#define AI_D3MFLOADER_H_INCLUDED
|
||||||
|
|
||||||
|
#ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
|
||||||
|
|
||||||
#include <assimp/BaseImporter.h>
|
#include <assimp/BaseImporter.h>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
/// @brief The 3MF-importer class.
|
||||||
|
///
|
||||||
|
/// Implements the basic topology import and embedded textures.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
class D3MFImporter : public BaseImporter {
|
class D3MFImporter : public BaseImporter {
|
||||||
public:
|
public:
|
||||||
// BaseImporter interface
|
/// @brief The default class constructor.
|
||||||
D3MFImporter();
|
D3MFImporter();
|
||||||
~D3MFImporter();
|
|
||||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const;
|
/// @brief The class destructor.
|
||||||
void SetupProperties(const Importer *pImp);
|
~D3MFImporter() override;
|
||||||
const aiImporterDesc *GetInfo() const;
|
|
||||||
|
/// @brief Performs the data format detection.
|
||||||
|
/// @param pFile The filename to check.
|
||||||
|
/// @param pIOHandler The used IO-System.
|
||||||
|
/// @param checkSig true for signature checking.
|
||||||
|
/// @return true for can be loaded, false for not.
|
||||||
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const override;
|
||||||
|
|
||||||
|
/// @brief Not used
|
||||||
|
/// @param pImp Not used
|
||||||
|
void SetupProperties(const Importer *pImp) override;
|
||||||
|
|
||||||
|
/// @brief The importer description getter.
|
||||||
|
/// @return The info
|
||||||
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
|
/// @brief Internal read function, performs the file parsing.
|
||||||
|
/// @param pFile The filename
|
||||||
|
/// @param pScene The scene to load in.
|
||||||
|
/// @param pIOHandler The io-system
|
||||||
|
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace Assimp
|
} // Namespace Assimp
|
||||||
|
|
||||||
|
#endif // #ifndef ASSIMP_BUILD_NO_3MF_IMPORTER
|
||||||
|
|
||||||
#endif // AI_D3MFLOADER_H_INCLUDED
|
#endif // AI_D3MFLOADER_H_INCLUDED
|
||||||
|
|
|
@ -43,20 +43,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "D3MFOpcPackage.h"
|
#include "D3MFOpcPackage.h"
|
||||||
#include <assimp/Exceptional.h>
|
#include <assimp/Exceptional.h>
|
||||||
|
|
||||||
#include <assimp/XmlParser.h>
|
#include <assimp/XmlParser.h>
|
||||||
#include <assimp/ZipArchiveIOSystem.h>
|
#include <assimp/ZipArchiveIOSystem.h>
|
||||||
#include <assimp/ai_assert.h>
|
#include <assimp/ai_assert.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <assimp/IOStream.hpp>
|
#include <assimp/IOStream.hpp>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
|
#include <assimp/texture.h>
|
||||||
#include "3MFXmlTags.h"
|
#include "3MFXmlTags.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
@ -64,11 +63,12 @@ namespace Assimp {
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef std::shared_ptr<OpcPackageRelationship> OpcPackageRelationshipPtr;
|
using OpcPackageRelationshipPtr = std::shared_ptr<OpcPackageRelationship>;
|
||||||
|
|
||||||
class OpcPackageRelationshipReader {
|
class OpcPackageRelationshipReader {
|
||||||
public:
|
public:
|
||||||
OpcPackageRelationshipReader(XmlParser &parser) {
|
OpcPackageRelationshipReader(XmlParser &parser) :
|
||||||
|
m_relationShips() {
|
||||||
XmlNode root = parser.getRootNode();
|
XmlNode root = parser.getRootNode();
|
||||||
ParseRootNode(root);
|
ParseRootNode(root);
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ public:
|
||||||
if (relPtr->id.empty() || relPtr->type.empty() || relPtr->target.empty()) {
|
if (relPtr->id.empty() || relPtr->type.empty() || relPtr->target.empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +101,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||||
std::string name = currentNode.name();
|
const std::string name = currentNode.name();
|
||||||
if (name == "Relationship") {
|
if (name == "Relationship") {
|
||||||
OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship());
|
OpcPackageRelationshipPtr relPtr(new OpcPackageRelationship());
|
||||||
relPtr->id = currentNode.attribute(XmlTag::RELS_ATTRIB_ID.c_str()).as_string();
|
relPtr->id = currentNode.attribute(XmlTag::RELS_ATTRIB_ID).as_string();
|
||||||
relPtr->type = currentNode.attribute(XmlTag::RELS_ATTRIB_TYPE.c_str()).as_string();
|
relPtr->type = currentNode.attribute(XmlTag::RELS_ATTRIB_TYPE).as_string();
|
||||||
relPtr->target = currentNode.attribute(XmlTag::RELS_ATTRIB_TARGET.c_str()).as_string();
|
relPtr->target = currentNode.attribute(XmlTag::RELS_ATTRIB_TARGET).as_string();
|
||||||
if (validateRels(relPtr)) {
|
if (validateRels(relPtr)) {
|
||||||
m_relationShips.push_back(relPtr);
|
m_relationShips.push_back(relPtr);
|
||||||
}
|
}
|
||||||
|
@ -116,11 +117,23 @@ public:
|
||||||
std::vector<OpcPackageRelationshipPtr> m_relationShips;
|
std::vector<OpcPackageRelationshipPtr> m_relationShips;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool IsEmbeddedTexture( const std::string &filename ) {
|
||||||
|
const std::string extension = BaseImporter::GetExtension(filename);
|
||||||
|
if (extension == "jpg" || extension == "png") {
|
||||||
|
std::string::size_type pos = filename.find("thumbnail");
|
||||||
|
if (pos == std::string::npos) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
D3MFOpcPackage::D3MFOpcPackage(IOSystem *pIOHandler, const std::string &rFile) :
|
D3MFOpcPackage::D3MFOpcPackage(IOSystem *pIOHandler, const std::string &rFile) :
|
||||||
mRootStream(nullptr),
|
mRootStream(nullptr),
|
||||||
mZipArchive() {
|
mZipArchive() {
|
||||||
mZipArchive.reset(new ZipArchiveIOSystem(pIOHandler, rFile));
|
mZipArchive = new ZipArchiveIOSystem(pIOHandler, rFile);
|
||||||
if (!mZipArchive->isOpen()) {
|
if (!mZipArchive->isOpen()) {
|
||||||
throw DeadlyImportError("Failed to open file ", rFile, ".");
|
throw DeadlyImportError("Failed to open file ", rFile, ".");
|
||||||
}
|
}
|
||||||
|
@ -141,7 +154,7 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem *pIOHandler, const std::string &rFile) :
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string rootFile = ReadPackageRootRelationship(fileStream);
|
std::string rootFile = ReadPackageRootRelationship(fileStream);
|
||||||
if (rootFile.size() > 0 && rootFile[0] == '/') {
|
if (!rootFile.empty() && rootFile[0] == '/') {
|
||||||
rootFile = rootFile.substr(1);
|
rootFile = rootFile.substr(1);
|
||||||
if (rootFile[0] == '/') {
|
if (rootFile[0] == '/') {
|
||||||
// deal with zip-bug
|
// deal with zip-bug
|
||||||
|
@ -156,39 +169,47 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem *pIOHandler, const std::string &rFile) :
|
||||||
mRootStream = mZipArchive->Open(rootFile.c_str());
|
mRootStream = mZipArchive->Open(rootFile.c_str());
|
||||||
ai_assert(mRootStream != nullptr);
|
ai_assert(mRootStream != nullptr);
|
||||||
if (nullptr == mRootStream) {
|
if (nullptr == mRootStream) {
|
||||||
throw DeadlyExportError("Cannot open root-file in archive : " + rootFile);
|
throw DeadlyImportError("Cannot open root-file in archive : " + rootFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (file == D3MF::XmlTag::CONTENT_TYPES_ARCHIVE) {
|
} else if (file == D3MF::XmlTag::CONTENT_TYPES_ARCHIVE) {
|
||||||
ASSIMP_LOG_WARN_F("Ignored file of unsupported type CONTENT_TYPES_ARCHIVES", file);
|
ASSIMP_LOG_WARN("Ignored file of unsupported type CONTENT_TYPES_ARCHIVES", file);
|
||||||
|
} else if (IsEmbeddedTexture(file)) {
|
||||||
|
IOStream *fileStream = mZipArchive->Open(file.c_str());
|
||||||
|
LoadEmbeddedTextures(fileStream, file);
|
||||||
|
mZipArchive->Close(fileStream);
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_WARN_F("Ignored file of unknown type: ", file);
|
ASSIMP_LOG_WARN("Ignored file of unknown type: ", file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
D3MFOpcPackage::~D3MFOpcPackage() {
|
D3MFOpcPackage::~D3MFOpcPackage() {
|
||||||
mZipArchive->Close(mRootStream);
|
mZipArchive->Close(mRootStream);
|
||||||
|
delete mZipArchive;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOStream *D3MFOpcPackage::RootStream() const {
|
IOStream *D3MFOpcPackage::RootStream() const {
|
||||||
return mRootStream;
|
return mRootStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::string ModelRef = "3D/3dmodel.model";
|
const std::vector<aiTexture *> &D3MFOpcPackage::GetEmbeddedTextures() const {
|
||||||
|
return mEmbeddedTextures;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *const ModelRef = "3D/3dmodel.model";
|
||||||
|
|
||||||
bool D3MFOpcPackage::validate() {
|
bool D3MFOpcPackage::validate() {
|
||||||
if (nullptr == mRootStream || nullptr == mZipArchive) {
|
if (nullptr == mRootStream || nullptr == mZipArchive) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mZipArchive->Exists(ModelRef.c_str());
|
return mZipArchive->Exists(ModelRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream *stream) {
|
std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream *stream) {
|
||||||
XmlParser xmlParser;
|
XmlParser xmlParser;
|
||||||
if (!xmlParser.parse(stream)) {
|
if (!xmlParser.parse(stream)) {
|
||||||
return "";
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
OpcPackageRelationshipReader reader(xmlParser);
|
OpcPackageRelationshipReader reader(xmlParser);
|
||||||
|
@ -204,6 +225,31 @@ std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream *stream) {
|
||||||
return (*itr)->target;
|
return (*itr)->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void D3MFOpcPackage::LoadEmbeddedTextures(IOStream *fileStream, const std::string &filename) {
|
||||||
|
if (nullptr == fileStream) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t size = fileStream->FileSize();
|
||||||
|
if (0 == size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char *data = new unsigned char[size];
|
||||||
|
fileStream->Read(data, 1, size);
|
||||||
|
aiTexture *texture = new aiTexture;
|
||||||
|
std::string embName = "*" + filename;
|
||||||
|
texture->mFilename.Set(embName.c_str());
|
||||||
|
texture->mWidth = static_cast<unsigned int>(size);
|
||||||
|
texture->mHeight = 0;
|
||||||
|
texture->achFormatHint[0] = 'p';
|
||||||
|
texture->achFormatHint[1] = 'n';
|
||||||
|
texture->achFormatHint[2] = 'g';
|
||||||
|
texture->achFormatHint[3] = '\0';
|
||||||
|
texture->pcData = (aiTexel*) data;
|
||||||
|
mEmbeddedTextures.emplace_back(texture);
|
||||||
|
}
|
||||||
|
|
||||||
} // Namespace D3MF
|
} // Namespace D3MF
|
||||||
} // Namespace Assimp
|
} // Namespace Assimp
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef D3MFOPCPACKAGE_H
|
#ifndef D3MFOPCPACKAGE_H
|
||||||
#define D3MFOPCPACKAGE_H
|
#define D3MFOPCPACKAGE_H
|
||||||
|
|
||||||
|
#include <assimp/IOSystem.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <assimp/IOSystem.hpp>
|
|
||||||
|
struct aiTexture;
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
class ZipArchiveIOSystem;
|
class ZipArchiveIOSystem;
|
||||||
|
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
|
@ -63,16 +66,19 @@ public:
|
||||||
~D3MFOpcPackage();
|
~D3MFOpcPackage();
|
||||||
IOStream* RootStream() const;
|
IOStream* RootStream() const;
|
||||||
bool validate();
|
bool validate();
|
||||||
|
const std::vector<aiTexture*> &GetEmbeddedTextures() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string ReadPackageRootRelationship(IOStream* stream);
|
std::string ReadPackageRootRelationship(IOStream* stream);
|
||||||
|
void LoadEmbeddedTextures(IOStream *fileStream, const std::string &filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IOStream* mRootStream;
|
IOStream* mRootStream;
|
||||||
std::unique_ptr<ZipArchiveIOSystem> mZipArchive;
|
ZipArchiveIOSystem *mZipArchive;
|
||||||
|
std::vector<aiTexture *> mEmbeddedTextures;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Namespace D3MF
|
} // namespace D3MF
|
||||||
} // Namespace Assimp
|
} // namespace Assimp
|
||||||
|
|
||||||
#endif // D3MFOPCPACKAGE_H
|
#endif // D3MFOPCPACKAGE_H
|
||||||
|
|
|
@ -0,0 +1,594 @@
|
||||||
|
/*
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2021, 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 "XmlSerializer.h"
|
||||||
|
#include "D3MFOpcPackage.h"
|
||||||
|
#include "3MFXmlTags.h"
|
||||||
|
#include "3MFTypes.h"
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
|
||||||
|
namespace Assimp {
|
||||||
|
namespace D3MF {
|
||||||
|
|
||||||
|
static const int IdNotSet = -1;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
static const size_t ColRGBA_Len = 9;
|
||||||
|
static const size_t ColRGB_Len = 7;
|
||||||
|
|
||||||
|
// format of the color string: #RRGGBBAA or #RRGGBB (3MF Core chapter 5.1.1)
|
||||||
|
bool validateColorString(const char *color) {
|
||||||
|
const size_t len = strlen(color);
|
||||||
|
if (ColRGBA_Len != len && ColRGB_Len != len) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
aiFace ReadTriangle(XmlNode &node) {
|
||||||
|
aiFace face;
|
||||||
|
|
||||||
|
face.mNumIndices = 3;
|
||||||
|
face.mIndices = new unsigned int[face.mNumIndices];
|
||||||
|
face.mIndices[0] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v1).as_string()));
|
||||||
|
face.mIndices[1] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v2).as_string()));
|
||||||
|
face.mIndices[2] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v3).as_string()));
|
||||||
|
|
||||||
|
return face;
|
||||||
|
}
|
||||||
|
|
||||||
|
aiVector3D ReadVertex(XmlNode &node) {
|
||||||
|
aiVector3D vertex;
|
||||||
|
vertex.x = ai_strtof(node.attribute(XmlTag::x).as_string(), nullptr);
|
||||||
|
vertex.y = ai_strtof(node.attribute(XmlTag::y).as_string(), nullptr);
|
||||||
|
vertex.z = ai_strtof(node.attribute(XmlTag::z).as_string(), nullptr);
|
||||||
|
|
||||||
|
return vertex;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getNodeAttribute(const XmlNode &node, const std::string &attribute, std::string &value) {
|
||||||
|
pugi::xml_attribute objectAttribute = node.attribute(attribute.c_str());
|
||||||
|
if (!objectAttribute.empty()) {
|
||||||
|
value = objectAttribute.as_string();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getNodeAttribute(const XmlNode &node, const std::string &attribute, int &value) {
|
||||||
|
std::string strValue;
|
||||||
|
const bool ret = getNodeAttribute(node, attribute, strValue);
|
||||||
|
if (ret) {
|
||||||
|
value = std::atoi(strValue.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
aiMatrix4x4 parseTransformMatrix(std::string matrixStr) {
|
||||||
|
// split the string
|
||||||
|
std::vector<float> numbers;
|
||||||
|
std::string currentNumber;
|
||||||
|
for (char c : matrixStr) {
|
||||||
|
if (c == ' ') {
|
||||||
|
if (!currentNumber.empty()) {
|
||||||
|
float f = std::stof(currentNumber);
|
||||||
|
numbers.push_back(f);
|
||||||
|
currentNumber.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentNumber.push_back(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!currentNumber.empty()) {
|
||||||
|
const float f = std::stof(currentNumber);
|
||||||
|
numbers.push_back(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
aiMatrix4x4 transformMatrix;
|
||||||
|
transformMatrix.a1 = numbers[0];
|
||||||
|
transformMatrix.b1 = numbers[1];
|
||||||
|
transformMatrix.c1 = numbers[2];
|
||||||
|
transformMatrix.d1 = 0;
|
||||||
|
|
||||||
|
transformMatrix.a2 = numbers[3];
|
||||||
|
transformMatrix.b2 = numbers[4];
|
||||||
|
transformMatrix.c2 = numbers[5];
|
||||||
|
transformMatrix.d2 = 0;
|
||||||
|
|
||||||
|
transformMatrix.a3 = numbers[6];
|
||||||
|
transformMatrix.b3 = numbers[7];
|
||||||
|
transformMatrix.c3 = numbers[8];
|
||||||
|
transformMatrix.d3 = 0;
|
||||||
|
|
||||||
|
transformMatrix.a4 = numbers[9];
|
||||||
|
transformMatrix.b4 = numbers[10];
|
||||||
|
transformMatrix.c4 = numbers[11];
|
||||||
|
transformMatrix.d4 = 1;
|
||||||
|
|
||||||
|
return transformMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool parseColor(const char *color, aiColor4D &diffuse) {
|
||||||
|
if (nullptr == color) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validateColorString(color)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//const char *buf(color);
|
||||||
|
if ('#' != color[0]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char r[3] = { color[1], color[2], '\0' };
|
||||||
|
diffuse.r = static_cast<ai_real>(strtol(r, nullptr, 16)) / ai_real(255.0);
|
||||||
|
|
||||||
|
char g[3] = { color[3], color[4], '\0' };
|
||||||
|
diffuse.g = static_cast<ai_real>(strtol(g, nullptr, 16)) / ai_real(255.0);
|
||||||
|
|
||||||
|
char b[3] = { color[5], color[6], '\0' };
|
||||||
|
diffuse.b = static_cast<ai_real>(strtol(b, nullptr, 16)) / ai_real(255.0);
|
||||||
|
const size_t len = strlen(color);
|
||||||
|
if (ColRGB_Len == len) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char a[3] = { color[7], color[8], '\0' };
|
||||||
|
diffuse.a = static_cast<ai_real>(strtol(a, nullptr, 16)) / ai_real(255.0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void assignDiffuseColor(XmlNode &node, aiMaterial *mat) {
|
||||||
|
const char *color = node.attribute(XmlTag::basematerials_displaycolor).as_string();
|
||||||
|
aiColor4D diffuse;
|
||||||
|
if (parseColor(color, diffuse)) {
|
||||||
|
mat->AddProperty<aiColor4D>(&diffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
XmlSerializer::XmlSerializer(XmlParser *xmlParser) :
|
||||||
|
mResourcesDictionnary(),
|
||||||
|
mMeshCount(0),
|
||||||
|
mXmlParser(xmlParser) {
|
||||||
|
ai_assert(nullptr != xmlParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlSerializer::~XmlSerializer() {
|
||||||
|
for (auto &it : mResourcesDictionnary) {
|
||||||
|
delete it.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ImportXml(aiScene *scene) {
|
||||||
|
if (nullptr == scene) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scene->mRootNode = new aiNode(XmlTag::RootTag);
|
||||||
|
XmlNode node = mXmlParser->getRootNode().child(XmlTag::model);
|
||||||
|
if (node.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlNode resNode = node.child(XmlTag::resources);
|
||||||
|
for (auto ¤tNode : resNode.children()) {
|
||||||
|
const std::string currentNodeName = currentNode.name();
|
||||||
|
if (currentNodeName == XmlTag::texture_2d) {
|
||||||
|
ReadEmbeddecTexture(currentNode);
|
||||||
|
} else if (currentNodeName == XmlTag::texture_group) {
|
||||||
|
ReadTextureGroup(currentNode);
|
||||||
|
} else if (currentNodeName == XmlTag::object) {
|
||||||
|
ReadObject(currentNode);
|
||||||
|
} else if (currentNodeName == XmlTag::basematerials) {
|
||||||
|
ReadBaseMaterials(currentNode);
|
||||||
|
} else if (currentNodeName == XmlTag::meta) {
|
||||||
|
ReadMetadata(currentNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StoreMaterialsInScene(scene);
|
||||||
|
XmlNode buildNode = node.child(XmlTag::build);
|
||||||
|
if (buildNode.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto ¤tNode : buildNode.children()) {
|
||||||
|
const std::string currentNodeName = currentNode.name();
|
||||||
|
if (currentNodeName == XmlTag::item) {
|
||||||
|
int objectId = IdNotSet;
|
||||||
|
std::string transformationMatrixStr;
|
||||||
|
aiMatrix4x4 transformationMatrix;
|
||||||
|
getNodeAttribute(currentNode, D3MF::XmlTag::objectid, objectId);
|
||||||
|
bool hasTransform = getNodeAttribute(currentNode, D3MF::XmlTag::transform, transformationMatrixStr);
|
||||||
|
|
||||||
|
auto it = mResourcesDictionnary.find(objectId);
|
||||||
|
if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
|
||||||
|
Object *obj = static_cast<Object *>(it->second);
|
||||||
|
if (hasTransform) {
|
||||||
|
transformationMatrix = parseTransformMatrix(transformationMatrixStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
addObjectToNode(scene->mRootNode, obj, transformationMatrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// import the metadata
|
||||||
|
if (!mMetaData.empty()) {
|
||||||
|
const size_t numMeta = mMetaData.size();
|
||||||
|
scene->mMetaData = aiMetadata::Alloc(static_cast<unsigned int>(numMeta));
|
||||||
|
for (size_t i = 0; i < numMeta; ++i) {
|
||||||
|
aiString val(mMetaData[i].value);
|
||||||
|
scene->mMetaData->Set(static_cast<unsigned int>(i), mMetaData[i].name, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// import the meshes, materials are already stored
|
||||||
|
scene->mNumMeshes = static_cast<unsigned int>(mMeshCount);
|
||||||
|
if (scene->mNumMeshes != 0) {
|
||||||
|
scene->mMeshes = new aiMesh *[scene->mNumMeshes]();
|
||||||
|
for (auto &it : mResourcesDictionnary) {
|
||||||
|
if (it.second->getType() == ResourceType::RT_Object) {
|
||||||
|
Object *obj = static_cast<Object *>(it.second);
|
||||||
|
ai_assert(nullptr != obj);
|
||||||
|
for (unsigned int i = 0; i < obj->mMeshes.size(); ++i) {
|
||||||
|
scene->mMeshes[obj->mMeshIndex[i]] = obj->mMeshes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::addObjectToNode(aiNode *parent, Object *obj, aiMatrix4x4 nodeTransform) {
|
||||||
|
ai_assert(nullptr != obj);
|
||||||
|
|
||||||
|
aiNode *sceneNode = new aiNode(obj->mName);
|
||||||
|
sceneNode->mNumMeshes = static_cast<unsigned int>(obj->mMeshes.size());
|
||||||
|
sceneNode->mMeshes = new unsigned int[sceneNode->mNumMeshes];
|
||||||
|
std::copy(obj->mMeshIndex.begin(), obj->mMeshIndex.end(), sceneNode->mMeshes);
|
||||||
|
|
||||||
|
sceneNode->mTransformation = nodeTransform;
|
||||||
|
if (nullptr != parent) {
|
||||||
|
parent->addChildren(1, &sceneNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Assimp::D3MF::Component c : obj->mComponents) {
|
||||||
|
auto it = mResourcesDictionnary.find(c.mObjectId);
|
||||||
|
if (it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_Object) {
|
||||||
|
addObjectToNode(sceneNode, static_cast<Object *>(it->second), c.mTransformation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ReadObject(XmlNode &node) {
|
||||||
|
int id = IdNotSet, pid = IdNotSet, pindex = IdNotSet;
|
||||||
|
bool hasId = getNodeAttribute(node, XmlTag::id, id);
|
||||||
|
if (!hasId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasPid = getNodeAttribute(node, XmlTag::pid, pid);
|
||||||
|
bool hasPindex = getNodeAttribute(node, XmlTag::pindex, pindex);
|
||||||
|
|
||||||
|
Object *obj = new Object(id);
|
||||||
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
|
const std::string currentName = currentNode.name();
|
||||||
|
if (currentName == D3MF::XmlTag::mesh) {
|
||||||
|
auto mesh = ReadMesh(currentNode);
|
||||||
|
mesh->mName.Set(ai_to_string(id));
|
||||||
|
|
||||||
|
if (hasPid) {
|
||||||
|
auto it = mResourcesDictionnary.find(pid);
|
||||||
|
if (hasPindex && it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_BaseMaterials) {
|
||||||
|
BaseMaterials *materials = static_cast<BaseMaterials *>(it->second);
|
||||||
|
mesh->mMaterialIndex = materials->mMaterialIndex[pindex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obj->mMeshes.push_back(mesh);
|
||||||
|
obj->mMeshIndex.push_back(mMeshCount);
|
||||||
|
mMeshCount++;
|
||||||
|
} else if (currentName == D3MF::XmlTag::components) {
|
||||||
|
for (XmlNode ¤tSubNode : currentNode.children()) {
|
||||||
|
const std::string subNodeName = currentSubNode.name();
|
||||||
|
if (subNodeName == D3MF::XmlTag::component) {
|
||||||
|
int objectId = IdNotSet;
|
||||||
|
std::string componentTransformStr;
|
||||||
|
aiMatrix4x4 componentTransform;
|
||||||
|
if (getNodeAttribute(currentSubNode, D3MF::XmlTag::transform, componentTransformStr)) {
|
||||||
|
componentTransform = parseTransformMatrix(componentTransformStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getNodeAttribute(currentSubNode, D3MF::XmlTag::objectid, objectId)) {
|
||||||
|
obj->mComponents.push_back({ objectId, componentTransform });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mResourcesDictionnary.insert(std::make_pair(id, obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
aiMesh *XmlSerializer::ReadMesh(XmlNode &node) {
|
||||||
|
if (node.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
aiMesh *mesh = new aiMesh();
|
||||||
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
|
const std::string currentName = currentNode.name();
|
||||||
|
if (currentName == XmlTag::vertices) {
|
||||||
|
ImportVertices(currentNode, mesh);
|
||||||
|
} else if (currentName == XmlTag::triangles) {
|
||||||
|
ImportTriangles(currentNode, mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ReadMetadata(XmlNode &node) {
|
||||||
|
pugi::xml_attribute attribute = node.attribute(D3MF::XmlTag::meta_name);
|
||||||
|
const std::string name = attribute.as_string();
|
||||||
|
const std::string value = node.value();
|
||||||
|
if (name.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MetaEntry entry;
|
||||||
|
entry.name = name;
|
||||||
|
entry.value = value;
|
||||||
|
mMetaData.push_back(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ImportVertices(XmlNode &node, aiMesh *mesh) {
|
||||||
|
ai_assert(nullptr != mesh);
|
||||||
|
|
||||||
|
std::vector<aiVector3D> vertices;
|
||||||
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
|
const std::string currentName = currentNode.name();
|
||||||
|
if (currentName == XmlTag::vertex) {
|
||||||
|
vertices.push_back(ReadVertex(currentNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh->mNumVertices = static_cast<unsigned int>(vertices.size());
|
||||||
|
mesh->mVertices = new aiVector3D[mesh->mNumVertices];
|
||||||
|
std::copy(vertices.begin(), vertices.end(), mesh->mVertices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ImportTriangles(XmlNode &node, aiMesh *mesh) {
|
||||||
|
std::vector<aiFace> faces;
|
||||||
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
|
const std::string currentName = currentNode.name();
|
||||||
|
if (currentName == XmlTag::triangle) {
|
||||||
|
int pid = IdNotSet, p1 = IdNotSet;
|
||||||
|
bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid);
|
||||||
|
bool hasP1 = getNodeAttribute(currentNode, D3MF::XmlTag::p1, p1);
|
||||||
|
|
||||||
|
if (hasPid && hasP1) {
|
||||||
|
auto it = mResourcesDictionnary.find(pid);
|
||||||
|
if (it != mResourcesDictionnary.end()) {
|
||||||
|
if (it->second->getType() == ResourceType::RT_BaseMaterials) {
|
||||||
|
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
|
||||||
|
mesh->mMaterialIndex = baseMaterials->mMaterialIndex[p1];
|
||||||
|
} else if (it->second->getType() == ResourceType::RT_Texture2DGroup) {
|
||||||
|
if (mesh->mTextureCoords[0] == nullptr) {
|
||||||
|
Texture2DGroup *group = static_cast<Texture2DGroup *>(it->second);
|
||||||
|
const std::string name = ai_to_string(group->mTexId);
|
||||||
|
for (size_t i = 0; i < mMaterials.size(); ++i) {
|
||||||
|
if (name == mMaterials[i]->GetName().C_Str()) {
|
||||||
|
mesh->mMaterialIndex = static_cast<unsigned int>(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mesh->mTextureCoords[0] = new aiVector3D[group->mTex2dCoords.size()];
|
||||||
|
for (unsigned int i = 0; i < group->mTex2dCoords.size(); ++i) {
|
||||||
|
mesh->mTextureCoords[0][i] = aiVector3D(group->mTex2dCoords[i].x, group->mTex2dCoords[i].y, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aiFace face = ReadTriangle(currentNode);
|
||||||
|
faces.push_back(face);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh->mNumFaces = static_cast<unsigned int>(faces.size());
|
||||||
|
mesh->mFaces = new aiFace[mesh->mNumFaces];
|
||||||
|
mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
||||||
|
|
||||||
|
std::copy(faces.begin(), faces.end(), mesh->mFaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ReadBaseMaterials(XmlNode &node) {
|
||||||
|
int id = IdNotSet;
|
||||||
|
if (getNodeAttribute(node, D3MF::XmlTag::id, id)) {
|
||||||
|
BaseMaterials *baseMaterials = new BaseMaterials(id);
|
||||||
|
|
||||||
|
for (XmlNode ¤tNode : node.children()) {
|
||||||
|
const std::string currentName = currentNode.name();
|
||||||
|
if (currentName == XmlTag::basematerials_base) {
|
||||||
|
baseMaterials->mMaterialIndex.push_back(static_cast<unsigned int>(mMaterials.size()));
|
||||||
|
mMaterials.push_back(readMaterialDef(currentNode, id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mResourcesDictionnary.insert(std::make_pair(id, baseMaterials));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ReadEmbeddecTexture(XmlNode &node) {
|
||||||
|
if (node.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string value;
|
||||||
|
EmbeddedTexture *tex2D = nullptr;
|
||||||
|
if (XmlParser::getStdStrAttribute(node, XmlTag::id, value)) {
|
||||||
|
tex2D = new EmbeddedTexture(atoi(value.c_str()));
|
||||||
|
}
|
||||||
|
if (nullptr == tex2D) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (XmlParser::getStdStrAttribute(node, XmlTag::path, value)) {
|
||||||
|
tex2D->mPath = value;
|
||||||
|
}
|
||||||
|
if (XmlParser::getStdStrAttribute(node, XmlTag::texture_content_type, value)) {
|
||||||
|
tex2D->mContentType = value;
|
||||||
|
}
|
||||||
|
if (XmlParser::getStdStrAttribute(node, XmlTag::texture_tilestyleu, value)) {
|
||||||
|
tex2D->mTilestyleU = value;
|
||||||
|
}
|
||||||
|
if (XmlParser::getStdStrAttribute(node, XmlTag::texture_tilestylev, value)) {
|
||||||
|
tex2D->mTilestyleV = value;
|
||||||
|
}
|
||||||
|
mEmbeddedTextures.emplace_back(tex2D);
|
||||||
|
StoreEmbeddedTexture(tex2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::StoreEmbeddedTexture(EmbeddedTexture *tex) {
|
||||||
|
aiMaterial *mat = new aiMaterial;
|
||||||
|
aiString s;
|
||||||
|
s.Set(ai_to_string(tex->mId).c_str());
|
||||||
|
mat->AddProperty(&s, AI_MATKEY_NAME);
|
||||||
|
const std::string name = "*" + tex->mPath;
|
||||||
|
s.Set(name);
|
||||||
|
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||||
|
|
||||||
|
aiColor3D col;
|
||||||
|
mat->AddProperty<aiColor3D>(&col, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
|
mat->AddProperty<aiColor3D>(&col, 1, AI_MATKEY_COLOR_AMBIENT);
|
||||||
|
mat->AddProperty<aiColor3D>(&col, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||||
|
mat->AddProperty<aiColor3D>(&col, 1, AI_MATKEY_COLOR_SPECULAR);
|
||||||
|
mMaterials.emplace_back(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ReadTextureCoords2D(XmlNode &node, Texture2DGroup *tex2DGroup) {
|
||||||
|
if (node.empty() || nullptr == tex2DGroup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = IdNotSet;
|
||||||
|
if (XmlParser::getIntAttribute(node, "texid", id)) {
|
||||||
|
tex2DGroup->mTexId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
double value = 0.0;
|
||||||
|
for (XmlNode currentNode : node.children()) {
|
||||||
|
const std::string currentName = currentNode.name();
|
||||||
|
aiVector2D texCoord;
|
||||||
|
if (currentName == XmlTag::texture_2d_coord) {
|
||||||
|
XmlParser::getDoubleAttribute(currentNode, XmlTag::texture_cuurd_u, value);
|
||||||
|
texCoord.x = (ai_real)value;
|
||||||
|
XmlParser::getDoubleAttribute(currentNode, XmlTag::texture_cuurd_v, value);
|
||||||
|
texCoord.y = (ai_real)value;
|
||||||
|
tex2DGroup->mTex2dCoords.push_back(texCoord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::ReadTextureGroup(XmlNode &node) {
|
||||||
|
if (node.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = IdNotSet;
|
||||||
|
if (!XmlParser::getIntAttribute(node, XmlTag::id, id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture2DGroup *group = new Texture2DGroup(id);
|
||||||
|
ReadTextureCoords2D(node, group);
|
||||||
|
mResourcesDictionnary.insert(std::make_pair(id, group));
|
||||||
|
}
|
||||||
|
|
||||||
|
aiMaterial *XmlSerializer::readMaterialDef(XmlNode &node, unsigned int basematerialsId) {
|
||||||
|
aiMaterial *material = new aiMaterial();
|
||||||
|
material->mNumProperties = 0;
|
||||||
|
std::string name;
|
||||||
|
bool hasName = getNodeAttribute(node, D3MF::XmlTag::basematerials_name, name);
|
||||||
|
|
||||||
|
std::string stdMaterialName;
|
||||||
|
const std::string strId(ai_to_string(basematerialsId));
|
||||||
|
stdMaterialName += "id";
|
||||||
|
stdMaterialName += strId;
|
||||||
|
stdMaterialName += "_";
|
||||||
|
if (hasName) {
|
||||||
|
stdMaterialName += std::string(name);
|
||||||
|
} else {
|
||||||
|
stdMaterialName += "basemat_";
|
||||||
|
stdMaterialName += ai_to_string(mMaterials.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
aiString assimpMaterialName(stdMaterialName);
|
||||||
|
material->AddProperty(&assimpMaterialName, AI_MATKEY_NAME);
|
||||||
|
|
||||||
|
assignDiffuseColor(node, material);
|
||||||
|
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlSerializer::StoreMaterialsInScene(aiScene *scene) {
|
||||||
|
if (nullptr == scene || mMaterials.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scene->mNumMaterials = static_cast<unsigned int>(mMaterials.size());
|
||||||
|
scene->mMaterials = new aiMaterial *[scene->mNumMaterials];
|
||||||
|
for (size_t i = 0; i < mMaterials.size(); ++i) {
|
||||||
|
scene->mMaterials[i] = mMaterials[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace D3MF
|
||||||
|
} // namespace Assimp
|
|
@ -3,6 +3,7 @@ Open Asset Import Library (assimp)
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -37,22 +38,59 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#ifndef AI_DEFINES_H_INC
|
|
||||||
#define AI_DEFINES_H_INC
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#include <assimp/XmlParser.h>
|
||||||
# pragma GCC system_header
|
#include <assimp/mesh.h>
|
||||||
#endif
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
// We need those constants, workaround for any platforms where nobody defined them yet
|
struct aiNode;
|
||||||
#if (!defined SIZE_MAX)
|
struct aiMesh;
|
||||||
# define SIZE_MAX (~((size_t)0))
|
struct aiMaterial;
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (!defined UINT_MAX)
|
namespace Assimp {
|
||||||
# define UINT_MAX (~((unsigned int)0))
|
namespace D3MF {
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // AI_DEINES_H_INC
|
class Resource;
|
||||||
|
class D3MFOpcPackage;
|
||||||
|
class Object;
|
||||||
|
class Texture2DGroup;
|
||||||
|
class EmbeddedTexture;
|
||||||
|
|
||||||
|
class XmlSerializer {
|
||||||
|
public:
|
||||||
|
XmlSerializer(XmlParser *xmlParser);
|
||||||
|
~XmlSerializer();
|
||||||
|
void ImportXml(aiScene *scene);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addObjectToNode(aiNode *parent, Object *obj, aiMatrix4x4 nodeTransform);
|
||||||
|
void ReadObject(XmlNode &node);
|
||||||
|
aiMesh *ReadMesh(XmlNode &node);
|
||||||
|
void ReadMetadata(XmlNode &node);
|
||||||
|
void ImportVertices(XmlNode &node, aiMesh *mesh);
|
||||||
|
void ImportTriangles(XmlNode &node, aiMesh *mesh);
|
||||||
|
void ReadBaseMaterials(XmlNode &node);
|
||||||
|
void ReadEmbeddecTexture(XmlNode &node);
|
||||||
|
void StoreEmbeddedTexture(EmbeddedTexture *tex);
|
||||||
|
void ReadTextureCoords2D(XmlNode &node, Texture2DGroup *tex2DGroup);
|
||||||
|
void ReadTextureGroup(XmlNode &node);
|
||||||
|
aiMaterial *readMaterialDef(XmlNode &node, unsigned int basematerialsId);
|
||||||
|
void StoreMaterialsInScene(aiScene *scene);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct MetaEntry {
|
||||||
|
std::string name;
|
||||||
|
std::string value;
|
||||||
|
};
|
||||||
|
std::vector<MetaEntry> mMetaData;
|
||||||
|
std::vector<EmbeddedTexture *> mEmbeddedTextures;
|
||||||
|
std::vector<aiMaterial *> mMaterials;
|
||||||
|
std::map<unsigned int, Resource *> mResourcesDictionnary;
|
||||||
|
unsigned int mMeshCount;
|
||||||
|
XmlParser *mXmlParser;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace D3MF
|
||||||
|
} // namespace Assimp
|
|
@ -116,7 +116,7 @@ inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *name
|
||||||
buffer = AcSkipToNextToken(buffer);
|
buffer = AcSkipToNextToken(buffer);
|
||||||
if (0 != name_length) {
|
if (0 != name_length) {
|
||||||
if (0 != strncmp(buffer, name, name_length) || !IsSpace(buffer[name_length])) {
|
if (0 != strncmp(buffer, name, name_length) || !IsSpace(buffer[name_length])) {
|
||||||
ASSIMP_LOG_ERROR("AC3D: Unexpexted token. " + std::string(name) + " was expected.");
|
ASSIMP_LOG_ERROR("AC3D: Unexpected token. ", name, " was expected.");
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
buffer += name_length + 1;
|
buffer += name_length + 1;
|
||||||
|
@ -492,7 +492,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Coerce unknowns to a polygon and warn
|
// Coerce unknowns to a polygon and warn
|
||||||
ASSIMP_LOG_WARN_F("AC3D: The type flag of a surface is unknown: ", (*it).flags);
|
ASSIMP_LOG_WARN("AC3D: The type flag of a surface is unknown: ", (*it).flags);
|
||||||
(*it).flags &= ~(Surface::Mask);
|
(*it).flags &= ~(Surface::Mask);
|
||||||
// fallthrough
|
// fallthrough
|
||||||
|
|
||||||
|
@ -690,7 +690,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
||||||
if (object.subDiv) {
|
if (object.subDiv) {
|
||||||
if (configEvalSubdivision) {
|
if (configEvalSubdivision) {
|
||||||
std::unique_ptr<Subdivider> div(Subdivider::Create(Subdivider::CATMULL_CLARKE));
|
std::unique_ptr<Subdivider> div(Subdivider::Create(Subdivider::CATMULL_CLARKE));
|
||||||
ASSIMP_LOG_INFO("AC3D: Evaluating subdivision surface: " + object.name);
|
ASSIMP_LOG_INFO("AC3D: Evaluating subdivision surface: ", object.name);
|
||||||
|
|
||||||
std::vector<aiMesh *> cpy(meshes.size() - oldm, nullptr);
|
std::vector<aiMesh *> cpy(meshes.size() - oldm, nullptr);
|
||||||
div->Subdivide(&meshes[oldm], cpy.size(), &cpy.front(), object.subDiv, true);
|
div->Subdivide(&meshes[oldm], cpy.size(), &cpy.front(), object.subDiv, true);
|
||||||
|
@ -698,7 +698,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
||||||
|
|
||||||
// previous meshes are deleted vy Subdivide().
|
// previous meshes are deleted vy Subdivide().
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_INFO("AC3D: Letting the subdivision surface untouched due to my configuration: " + object.name);
|
ASSIMP_LOG_INFO("AC3D: Letting the subdivision surface untouched due to my configuration: ", object.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -782,7 +782,7 @@ void AC3DImporter::InternReadFile(const std::string &pFile,
|
||||||
unsigned int version = HexDigitToDecimal(buffer[4]);
|
unsigned int version = HexDigitToDecimal(buffer[4]);
|
||||||
char msg[3];
|
char msg[3];
|
||||||
ASSIMP_itoa10(msg, 3, version);
|
ASSIMP_itoa10(msg, 3, version);
|
||||||
ASSIMP_LOG_INFO_F("AC3D file format version: ", msg);
|
ASSIMP_LOG_INFO("AC3D file format version: ", msg);
|
||||||
|
|
||||||
std::vector<Material> materials;
|
std::vector<Material> materials;
|
||||||
materials.reserve(5);
|
materials.reserve(5);
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace Assimp {
|
||||||
class AC3DImporter : public BaseImporter {
|
class AC3DImporter : public BaseImporter {
|
||||||
public:
|
public:
|
||||||
AC3DImporter();
|
AC3DImporter();
|
||||||
~AC3DImporter();
|
~AC3DImporter() override;
|
||||||
|
|
||||||
// Represents an AC3D material
|
// Represents an AC3D material
|
||||||
struct Material {
|
struct Material {
|
||||||
|
@ -123,9 +123,9 @@ public:
|
||||||
struct Object {
|
struct Object {
|
||||||
Object() :
|
Object() :
|
||||||
type(World),
|
type(World),
|
||||||
name(""),
|
name(),
|
||||||
children(),
|
children(),
|
||||||
texture(""),
|
texture(),
|
||||||
texRepeat(1.f, 1.f),
|
texRepeat(1.f, 1.f),
|
||||||
texOffset(0.0f, 0.0f),
|
texOffset(0.0f, 0.0f),
|
||||||
rotation(),
|
rotation(),
|
||||||
|
@ -185,25 +185,25 @@ public:
|
||||||
* See BaseImporter::CanRead() for details.
|
* See BaseImporter::CanRead() for details.
|
||||||
*/
|
*/
|
||||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Return importer meta information.
|
/** Return importer meta information.
|
||||||
* See #BaseImporter::GetInfo for the details */
|
* See #BaseImporter::GetInfo for the details */
|
||||||
const aiImporterDesc *GetInfo() const;
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Imports the given file into the given scene structure.
|
/** Imports the given file into the given scene structure.
|
||||||
* See BaseImporter::InternReadFile() for details*/
|
* See BaseImporter::InternReadFile() for details*/
|
||||||
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||||
IOSystem *pIOHandler);
|
IOSystem *pIOHandler) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Called prior to ReadFile().
|
/** Called prior to ReadFile().
|
||||||
* The function is a request to the importer to update its configuration
|
* The function is a request to the importer to update its configuration
|
||||||
* basing on the Importer's configuration property list.*/
|
* basing on the Importer's configuration property list.*/
|
||||||
void SetupProperties(const Importer *pImp);
|
void SetupProperties(const Importer *pImp) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
|
@ -205,7 +205,7 @@ void AMFImporter::ParseHelper_FixTruncatedFloatString(const char *pInStr, std::s
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ParseHelper_Decode_Base64_IsBase64(const char pChar) {
|
static bool ParseHelper_Decode_Base64_IsBase64(const char pChar) {
|
||||||
return (isalnum(pChar) || (pChar == '+') || (pChar == '/'));
|
return (isalnum((unsigned char)pChar) || (pChar == '+') || (pChar == '/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AMFImporter::ParseHelper_Decode_Base64(const std::string &pInputBase64, std::vector<uint8_t> &pOutputData) const {
|
void AMFImporter::ParseHelper_Decode_Base64(const std::string &pInputBase64, std::vector<uint8_t> &pOutputData) const {
|
||||||
|
@ -268,7 +268,8 @@ void AMFImporter::ParseFile(const std::string &pFile, IOSystem *pIOHandler) {
|
||||||
mXmlParser = new XmlParser();
|
mXmlParser = new XmlParser();
|
||||||
if (!mXmlParser->parse(file.get())) {
|
if (!mXmlParser->parse(file.get())) {
|
||||||
delete mXmlParser;
|
delete mXmlParser;
|
||||||
throw DeadlyImportError("Failed to create XML reader for file" + pFile + ".");
|
mXmlParser = nullptr;
|
||||||
|
throw DeadlyImportError("Failed to create XML reader for file ", pFile, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start reading, search for root tag <amf>
|
// Start reading, search for root tag <amf>
|
||||||
|
@ -510,17 +511,13 @@ bool AMFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool p
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extension.empty() || pCheckSig) {
|
if (extension.empty() || pCheckSig) {
|
||||||
const char *tokens[] = { "<amf" };
|
static const char * const tokens[] = { "<amf" };
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AMFImporter::GetExtensionList(std::set<std::string> &pExtensionList) {
|
|
||||||
pExtensionList.insert("amf");
|
|
||||||
}
|
|
||||||
|
|
||||||
const aiImporterDesc *AMFImporter::GetInfo() const {
|
const aiImporterDesc *AMFImporter::GetInfo() const {
|
||||||
return &Description;
|
return &Description;
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,7 @@ public:
|
||||||
AMFImporter() AI_NO_EXCEPT;
|
AMFImporter() AI_NO_EXCEPT;
|
||||||
|
|
||||||
/// Default destructor.
|
/// Default destructor.
|
||||||
~AMFImporter();
|
~AMFImporter() override;
|
||||||
|
|
||||||
/// Parse AMF file and fill scene graph. The function has no return value. Result can be found by analyzing the generated graph.
|
/// Parse AMF file and fill scene graph. The function has no return value. Result can be found by analyzing the generated graph.
|
||||||
/// Also exception can be thrown if trouble will found.
|
/// Also exception can be thrown if trouble will found.
|
||||||
|
@ -276,10 +276,9 @@ public:
|
||||||
void ParseFile(const std::string &pFile, IOSystem *pIOHandler);
|
void ParseFile(const std::string &pFile, IOSystem *pIOHandler);
|
||||||
void ParseHelper_Node_Enter(AMFNodeElementBase *child);
|
void ParseHelper_Node_Enter(AMFNodeElementBase *child);
|
||||||
void ParseHelper_Node_Exit();
|
void ParseHelper_Node_Exit();
|
||||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool pCheckSig) const;
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool pCheckSig) const override;
|
||||||
void GetExtensionList(std::set<std::string> &pExtensionList);
|
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
|
||||||
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
|
const aiImporterDesc *GetInfo() const override;
|
||||||
const aiImporterDesc *GetInfo() const;
|
|
||||||
bool Find_NodeElement(const std::string &pID, const AMFNodeElementBase::EType pType, AMFNodeElementBase **pNodeElement) const;
|
bool Find_NodeElement(const std::string &pID, const AMFNodeElementBase::EType pType, AMFNodeElementBase **pNodeElement) const;
|
||||||
bool Find_ConvertedNode(const std::string &pID, NodeArray &nodeArray, aiNode **pNode) const;
|
bool Find_ConvertedNode(const std::string &pID, NodeArray &nodeArray, aiNode **pNode) const;
|
||||||
bool Find_ConvertedMaterial(const std::string &pID, const SPP_Material **pConvertedMaterial) const;
|
bool Find_ConvertedMaterial(const std::string &pID, const SPP_Material **pConvertedMaterial) const;
|
||||||
|
|
|
@ -48,15 +48,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef INCLUDED_AI_AMF_IMPORTER_NODE_H
|
#ifndef INCLUDED_AI_AMF_IMPORTER_NODE_H
|
||||||
#define INCLUDED_AI_AMF_IMPORTER_NODE_H
|
#define INCLUDED_AI_AMF_IMPORTER_NODE_H
|
||||||
|
|
||||||
// Header files, stdlib.
|
// Header files, Assimp.
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/types.h>
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Header files, Assimp.
|
|
||||||
#include "assimp/scene.h"
|
|
||||||
#include "assimp/types.h"
|
|
||||||
|
|
||||||
/// \class CAMFImporter_NodeElement
|
/// \class CAMFImporter_NodeElement
|
||||||
/// Base class for elements of nodes.
|
/// Base class for elements of nodes.
|
||||||
class AMFNodeElementBase {
|
class AMFNodeElementBase {
|
||||||
|
|
|
@ -428,10 +428,10 @@ void AMFImporter::Postprocess_BuildMeshSet(const AMFMesh &pNodeElement, const st
|
||||||
|
|
||||||
if (pBiggerThan != nullptr) {
|
if (pBiggerThan != nullptr) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
const size_t biggerThan = *pBiggerThan;
|
||||||
for (const SComplexFace &face : pFaceList) {
|
for (const SComplexFace &face : pFaceList) {
|
||||||
for (size_t idx_vert = 0; idx_vert < face.Face.mNumIndices; idx_vert++) {
|
for (size_t idx_vert = 0; idx_vert < face.Face.mNumIndices; idx_vert++) {
|
||||||
if (face.Face.mIndices[idx_vert] > *pBiggerThan) {
|
if (face.Face.mIndices[idx_vert] > biggerThan) {
|
||||||
rv = face.Face.mIndices[idx_vert];
|
rv = face.Face.mIndices[idx_vert];
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -106,7 +104,7 @@ bool ASEImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!extension.length() || cs) && pIOHandler) {
|
if ((!extension.length() || cs) && pIOHandler) {
|
||||||
const char *tokens[] = { "*3dsmax_asciiexport" };
|
static const char * const tokens[] = { "*3dsmax_asciiexport" };
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -614,7 +612,7 @@ void ASEImporter::AddNodes(const std::vector<BaseNode *> &nodes,
|
||||||
node->mNumChildren++;
|
node->mNumChildren++;
|
||||||
|
|
||||||
// What we did is so great, it is at least worth a debug message
|
// What we did is so great, it is at least worth a debug message
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG("ASE: Generating separate target node (" + snode->mName + ")");
|
ASSIMP_LOG_VERBOSE_DEBUG("ASE: Generating separate target node (", snode->mName, ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,42 +62,37 @@ namespace Assimp {
|
||||||
class ASEImporter : public BaseImporter {
|
class ASEImporter : public BaseImporter {
|
||||||
public:
|
public:
|
||||||
ASEImporter();
|
ASEImporter();
|
||||||
~ASEImporter();
|
~ASEImporter() override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns whether the class can handle the format of the given file.
|
/** Returns whether the class can handle the format of the given file.
|
||||||
* See BaseImporter::CanRead() for details.
|
* See BaseImporter::CanRead() for details.
|
||||||
*/
|
*/
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Return importer meta information.
|
/** Return importer meta information.
|
||||||
* See #BaseImporter::GetInfo for the details
|
* See #BaseImporter::GetInfo for the details
|
||||||
*/
|
*/
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc* GetInfo () const override;
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Imports the given file into the given scene structure.
|
/** Imports the given file into the given scene structure.
|
||||||
* See BaseImporter::InternReadFile() for details
|
* See BaseImporter::InternReadFile() for details
|
||||||
*/
|
*/
|
||||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||||
IOSystem* pIOHandler);
|
IOSystem* pIOHandler) override;
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Called prior to ReadFile().
|
/** Called prior to ReadFile().
|
||||||
* The function is a request to the importer to update its configuration
|
* The function is a request to the importer to update its configuration
|
||||||
* basing on the Importer's configuration property list.
|
* basing on the Importer's configuration property list.
|
||||||
*/
|
*/
|
||||||
void SetupProperties(const Importer* pImp);
|
void SetupProperties(const Importer* pImp) override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Generate normal vectors basing on smoothing groups
|
/** Generate normal vectors basing on smoothing groups
|
||||||
* (in some cases the normal are already contained in the file)
|
* (in some cases the normal are already contained in the file)
|
||||||
|
@ -106,7 +101,6 @@ private:
|
||||||
*/
|
*/
|
||||||
bool GenerateNormals(ASE::Mesh& mesh);
|
bool GenerateNormals(ASE::Mesh& mesh);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Create valid vertex/normal/UV/color/face lists.
|
/** Create valid vertex/normal/UV/color/face lists.
|
||||||
* All elements are unique, faces have only one set of indices
|
* All elements are unique, faces have only one set of indices
|
||||||
|
@ -115,51 +109,43 @@ private:
|
||||||
*/
|
*/
|
||||||
void BuildUniqueRepresentation(ASE::Mesh& mesh);
|
void BuildUniqueRepresentation(ASE::Mesh& mesh);
|
||||||
|
|
||||||
|
|
||||||
/** Create one-material-per-mesh meshes ;-)
|
/** Create one-material-per-mesh meshes ;-)
|
||||||
* \param mesh Mesh to work with
|
* \param mesh Mesh to work with
|
||||||
* \param Receives the list of all created meshes
|
* \param Receives the list of all created meshes
|
||||||
*/
|
*/
|
||||||
void ConvertMeshes(ASE::Mesh& mesh, std::vector<aiMesh*>& avOut);
|
void ConvertMeshes(ASE::Mesh& mesh, std::vector<aiMesh*>& avOut);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Convert a material to a aiMaterial object
|
/** Convert a material to a aiMaterial object
|
||||||
* \param mat Input material
|
* \param mat Input material
|
||||||
*/
|
*/
|
||||||
void ConvertMaterial(ASE::Material& mat);
|
void ConvertMaterial(ASE::Material& mat);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Setup the final material indices for each mesh
|
/** Setup the final material indices for each mesh
|
||||||
*/
|
*/
|
||||||
void BuildMaterialIndices();
|
void BuildMaterialIndices();
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Build the node graph
|
/** Build the node graph
|
||||||
*/
|
*/
|
||||||
void BuildNodes(std::vector<ASE::BaseNode*>& nodes);
|
void BuildNodes(std::vector<ASE::BaseNode*>& nodes);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Build output cameras
|
/** Build output cameras
|
||||||
*/
|
*/
|
||||||
void BuildCameras();
|
void BuildCameras();
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Build output lights
|
/** Build output lights
|
||||||
*/
|
*/
|
||||||
void BuildLights();
|
void BuildLights();
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Build output animations
|
/** Build output animations
|
||||||
*/
|
*/
|
||||||
void BuildAnimations(const std::vector<ASE::BaseNode*>& nodes);
|
void BuildAnimations(const std::vector<ASE::BaseNode*>& nodes);
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Add sub nodes to a node
|
/** Add sub nodes to a node
|
||||||
* \param pcParent parent node to be filled
|
* \param pcParent parent node to be filled
|
||||||
|
@ -183,7 +169,6 @@ private:
|
||||||
void GenerateDefaultMaterial();
|
void GenerateDefaultMaterial();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** Parser instance */
|
/** Parser instance */
|
||||||
ASE::Parser* mParser;
|
ASE::Parser* mParser;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -498,6 +496,12 @@ void Parser::ParseLV1MaterialListBlock() {
|
||||||
ParseLV2MaterialBlock(sMat);
|
ParseLV2MaterialBlock(sMat);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if( iDepth == 1 ){
|
||||||
|
// CRUDE HACK: support missing brace after "Ascii Scene Exporter v2.51"
|
||||||
|
LogWarning("Missing closing brace in material list");
|
||||||
|
--filePtr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AI_ASE_HANDLE_TOP_LEVEL_SECTION();
|
AI_ASE_HANDLE_TOP_LEVEL_SECTION();
|
||||||
}
|
}
|
||||||
|
@ -671,7 +675,7 @@ void Parser::ParseLV3MapBlock(Texture &map) {
|
||||||
if (!ParseString(temp, "*MAP_CLASS"))
|
if (!ParseString(temp, "*MAP_CLASS"))
|
||||||
SkipToNextToken();
|
SkipToNextToken();
|
||||||
if (temp != "Bitmap" && temp != "Normal Bump") {
|
if (temp != "Bitmap" && temp != "Normal Bump") {
|
||||||
ASSIMP_LOG_WARN_F("ASE: Skipping unknown map type: ", temp);
|
ASSIMP_LOG_WARN("ASE: Skipping unknown map type: ", temp);
|
||||||
parsePath = false;
|
parsePath = false;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -685,7 +689,7 @@ void Parser::ParseLV3MapBlock(Texture &map) {
|
||||||
// Files with 'None' as map name are produced by
|
// Files with 'None' as map name are produced by
|
||||||
// an Maja to ASE exporter which name I forgot ..
|
// an Maja to ASE exporter which name I forgot ..
|
||||||
ASSIMP_LOG_WARN("ASE: Skipping invalid map entry");
|
ASSIMP_LOG_WARN("ASE: Skipping invalid map entry");
|
||||||
map.mMapName = "";
|
map.mMapName = std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -1119,7 +1123,7 @@ void Parser::ParseLV2NodeTransformBlock(ASE::BaseNode &mesh) {
|
||||||
"this is no spot light or target camera");
|
"this is no spot light or target camera");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_ERROR("ASE: Unknown node transformation: " + temp);
|
ASSIMP_LOG_ERROR("ASE: Unknown node transformation: ", temp);
|
||||||
// mode = 0
|
// mode = 0
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -95,8 +95,8 @@ struct Material : public D3DS::Material {
|
||||||
Material(Material &&other) AI_NO_EXCEPT
|
Material(Material &&other) AI_NO_EXCEPT
|
||||||
: D3DS::Material(std::move(other)),
|
: D3DS::Material(std::move(other)),
|
||||||
avSubMaterials(std::move(other.avSubMaterials)),
|
avSubMaterials(std::move(other.avSubMaterials)),
|
||||||
pcInstance(std::move(other.pcInstance)),
|
pcInstance(other.pcInstance),
|
||||||
bNeed(std::move(other.bNeed)) {
|
bNeed(other.bNeed) {
|
||||||
other.pcInstance = nullptr;
|
other.pcInstance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ struct Material : public D3DS::Material {
|
||||||
//D3DS::Material::operator=(std::move(other));
|
//D3DS::Material::operator=(std::move(other));
|
||||||
|
|
||||||
avSubMaterials = std::move(other.avSubMaterials);
|
avSubMaterials = std::move(other.avSubMaterials);
|
||||||
pcInstance = std::move(other.pcInstance);
|
pcInstance = other.pcInstance;
|
||||||
bNeed = std::move(other.bNeed);
|
bNeed = other.bNeed;
|
||||||
|
|
||||||
other.pcInstance = nullptr;
|
other.pcInstance = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
/** @file AssbinExporter.h
|
/** @file AssbinExporter.h
|
||||||
* ASSBIN Exporter Main Header
|
* ASSBIN Exporter Main Header
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef AI_ASSBINEXPORTER_H_INC
|
#ifndef AI_ASSBINEXPORTER_H_INC
|
||||||
#define AI_ASSBINEXPORTER_H_INC
|
#define AI_ASSBINEXPORTER_H_INC
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ inline size_t Write<aiQuaternion>(IOStream *stream, const aiQuaternion &v) {
|
||||||
t += Write<float>(stream, v.z);
|
t += Write<float>(stream, v.z);
|
||||||
ai_assert(t == 16);
|
ai_assert(t == 16);
|
||||||
|
|
||||||
return 16;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -671,7 +671,7 @@ void AssbinImporter::ReadBinaryScene(IOStream *stream, aiScene *scene) {
|
||||||
void AssbinImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
void AssbinImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
IOStream *stream = pIOHandler->Open(pFile, "rb");
|
IOStream *stream = pIOHandler->Open(pFile, "rb");
|
||||||
if (nullptr == stream) {
|
if (nullptr == stream) {
|
||||||
return;
|
throw DeadlyImportError("ASSBIN: Could not open ", pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// signature
|
// signature
|
||||||
|
|
|
@ -5,7 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -74,17 +73,11 @@ private:
|
||||||
bool compressed;
|
bool compressed;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool CanRead(
|
bool CanRead(const std::string& pFile,
|
||||||
const std::string& pFile,
|
IOSystem* pIOHandler, bool checkSig) const override;
|
||||||
IOSystem* pIOHandler,
|
const aiImporterDesc* GetInfo() const override;
|
||||||
bool checkSig
|
void InternReadFile(
|
||||||
) const;
|
const std::string& pFile,aiScene* pScene,IOSystem* pIOHandler) override;
|
||||||
virtual const aiImporterDesc* GetInfo() const;
|
|
||||||
virtual void InternReadFile(
|
|
||||||
const std::string& pFile,
|
|
||||||
aiScene* pScene,
|
|
||||||
IOSystem* pIOHandler
|
|
||||||
);
|
|
||||||
void ReadHeader();
|
void ReadHeader();
|
||||||
void ReadBinaryScene( IOStream * stream, aiScene* pScene );
|
void ReadBinaryScene( IOStream * stream, aiScene* pScene );
|
||||||
void ReadBinaryNode( IOStream * stream, aiNode** mRootNode, aiNode* parent );
|
void ReadBinaryNode( IOStream * stream, aiNode** mRootNode, aiNode* parent );
|
||||||
|
|
|
@ -41,12 +41,17 @@ public:
|
||||||
enum {
|
enum {
|
||||||
Flag_DoNotIndent = 0x1,
|
Flag_DoNotIndent = 0x1,
|
||||||
Flag_WriteSpecialFloats = 0x2,
|
Flag_WriteSpecialFloats = 0x2,
|
||||||
|
Flag_SkipWhitespaces = 0x4
|
||||||
};
|
};
|
||||||
|
|
||||||
JSONWriter(Assimp::IOStream &out, unsigned int flags = 0u) :
|
JSONWriter(Assimp::IOStream &out, unsigned int flags = 0u) :
|
||||||
out(out), first(), flags(flags) {
|
out(out), indent (""), newline("\n"), space(" "), buff (), first(false), flags(flags) {
|
||||||
// make sure that all formatting happens using the standard, C locale and not the user's current locale
|
// make sure that all formatting happens using the standard, C locale and not the user's current locale
|
||||||
buff.imbue(std::locale("C"));
|
buff.imbue(std::locale("C"));
|
||||||
|
if (flags & Flag_SkipWhitespaces) {
|
||||||
|
newline = "";
|
||||||
|
space = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~JSONWriter() {
|
~JSONWriter() {
|
||||||
|
@ -70,7 +75,7 @@ public:
|
||||||
void Key(const std::string &name) {
|
void Key(const std::string &name) {
|
||||||
AddIndentation();
|
AddIndentation();
|
||||||
Delimit();
|
Delimit();
|
||||||
buff << '\"' + name + "\": ";
|
buff << '\"' + name + "\":" << space;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Literal>
|
template <typename Literal>
|
||||||
|
@ -78,12 +83,12 @@ public:
|
||||||
AddIndentation();
|
AddIndentation();
|
||||||
Delimit();
|
Delimit();
|
||||||
|
|
||||||
LiteralToString(buff, name) << '\n';
|
LiteralToString(buff, name) << newline;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Literal>
|
template <typename Literal>
|
||||||
void SimpleValue(const Literal &s) {
|
void SimpleValue(const Literal &s) {
|
||||||
LiteralToString(buff, s) << '\n';
|
LiteralToString(buff, s) << newline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleValue(const void *buffer, size_t len) {
|
void SimpleValue(const void *buffer, size_t len) {
|
||||||
|
@ -102,7 +107,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buff << '\"' << cur_out << "\"\n";
|
buff << '\"' << cur_out << "\"" << newline;
|
||||||
delete[] cur_out;
|
delete[] cur_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +120,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first = true;
|
first = true;
|
||||||
buff << "{\n";
|
buff << "{" << newline;
|
||||||
PushIndent();
|
PushIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +128,7 @@ public:
|
||||||
PopIndent();
|
PopIndent();
|
||||||
AddIndentation();
|
AddIndentation();
|
||||||
first = false;
|
first = false;
|
||||||
buff << "}\n";
|
buff << "}" << newline;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartArray(bool is_element = false) {
|
void StartArray(bool is_element = false) {
|
||||||
|
@ -135,19 +140,19 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first = true;
|
first = true;
|
||||||
buff << "[\n";
|
buff << "[" << newline;
|
||||||
PushIndent();
|
PushIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndArray() {
|
void EndArray() {
|
||||||
PopIndent();
|
PopIndent();
|
||||||
AddIndentation();
|
AddIndentation();
|
||||||
buff << "]\n";
|
buff << "]" << newline;
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddIndentation() {
|
void AddIndentation() {
|
||||||
if (!(flags & Flag_DoNotIndent)) {
|
if (!(flags & Flag_DoNotIndent) && !(flags & Flag_SkipWhitespaces)) {
|
||||||
buff << indent;
|
buff << indent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +161,7 @@ public:
|
||||||
if (!first) {
|
if (!first) {
|
||||||
buff << ',';
|
buff << ',';
|
||||||
} else {
|
} else {
|
||||||
buff << ' ';
|
buff << space;
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,7 +232,9 @@ private:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Assimp::IOStream &out;
|
Assimp::IOStream &out;
|
||||||
std::string indent, newline;
|
std::string indent;
|
||||||
|
std::string newline;
|
||||||
|
std::string space;
|
||||||
std::stringstream buff;
|
std::stringstream buff;
|
||||||
bool first;
|
bool first;
|
||||||
|
|
||||||
|
@ -765,7 +772,7 @@ void Write(JSONWriter &out, const aiScene &ai) {
|
||||||
out.EndObj();
|
out.EndObj();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportAssimp2Json(const char *file, Assimp::IOSystem *io, const aiScene *scene, const Assimp::ExportProperties *) {
|
void ExportAssimp2Json(const char *file, Assimp::IOSystem *io, const aiScene *scene, const Assimp::ExportProperties *pProperties) {
|
||||||
std::unique_ptr<Assimp::IOStream> str(io->Open(file, "wt"));
|
std::unique_ptr<Assimp::IOStream> str(io->Open(file, "wt"));
|
||||||
if (!str) {
|
if (!str) {
|
||||||
throw DeadlyExportError("could not open output file");
|
throw DeadlyExportError("could not open output file");
|
||||||
|
@ -782,7 +789,12 @@ void ExportAssimp2Json(const char *file, Assimp::IOSystem *io, const aiScene *sc
|
||||||
splitter.Execute(scenecopy_tmp);
|
splitter.Execute(scenecopy_tmp);
|
||||||
|
|
||||||
// XXX Flag_WriteSpecialFloats is turned on by default, right now we don't have a configuration interface for exporters
|
// XXX Flag_WriteSpecialFloats is turned on by default, right now we don't have a configuration interface for exporters
|
||||||
JSONWriter s(*str, JSONWriter::Flag_WriteSpecialFloats);
|
|
||||||
|
unsigned int flags = JSONWriter::Flag_WriteSpecialFloats;
|
||||||
|
if (pProperties->GetPropertyBool("JSON_SKIP_WHITESPACES", false)) {
|
||||||
|
flags |= JSONWriter::Flag_SkipWhitespaces;
|
||||||
|
}
|
||||||
|
JSONWriter s(*str, flags);
|
||||||
Write(s, *scenecopy_tmp);
|
Write(s, *scenecopy_tmp);
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
|
@ -69,13 +69,12 @@ void MeshSplitter::UpdateNode(aiNode* pcNode, const std::vector<std::pair<aiMesh
|
||||||
for (unsigned int i = 0, end = pcNode->mNumChildren; i < end;++i) {
|
for (unsigned int i = 0, end = pcNode->mNumChildren; i < end;++i) {
|
||||||
UpdateNode ( pcNode->mChildren[i], source_mesh_map );
|
UpdateNode ( pcNode->mChildren[i], source_mesh_map );
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WAS_NOT_COPIED 0xffffffff
|
static const unsigned int WAS_NOT_COPIED = 0xffffffff;
|
||||||
|
|
||||||
typedef std::pair <unsigned int,float> PerVertexWeight;
|
using PerVertexWeight = std::pair <unsigned int,float>;
|
||||||
typedef std::vector <PerVertexWeight> VertexWeightTable;
|
using VertexWeightTable = std::vector <PerVertexWeight>;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
VertexWeightTable* ComputeVertexBoneWeightTable(const aiMesh* pMesh) {
|
VertexWeightTable* ComputeVertexBoneWeightTable(const aiMesh* pMesh) {
|
||||||
|
@ -89,7 +88,7 @@ VertexWeightTable* ComputeVertexBoneWeightTable(const aiMesh* pMesh) {
|
||||||
aiBone* bone = pMesh->mBones[i];
|
aiBone* bone = pMesh->mBones[i];
|
||||||
for (unsigned int a = 0; a < bone->mNumWeights;++a) {
|
for (unsigned int a = 0; a < bone->mNumWeights;++a) {
|
||||||
const aiVertexWeight& weight = bone->mWeights[a];
|
const aiVertexWeight& weight = bone->mWeights[a];
|
||||||
avPerVertexWeights[weight.mVertexId].push_back( std::make_pair(i,weight.mWeight) );
|
avPerVertexWeights[weight.mVertexId].emplace_back(i,weight.mWeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return avPerVertexWeights;
|
return avPerVertexWeights;
|
||||||
|
@ -100,7 +99,7 @@ void MeshSplitter :: SplitMesh(unsigned int a, aiMesh* in_mesh, std::vector<std:
|
||||||
// TODO: should better use std::(multi)set for source_mesh_map.
|
// TODO: should better use std::(multi)set for source_mesh_map.
|
||||||
|
|
||||||
if (in_mesh->mNumVertices <= LIMIT) {
|
if (in_mesh->mNumVertices <= LIMIT) {
|
||||||
source_mesh_map.push_back(std::make_pair(in_mesh,a));
|
source_mesh_map.emplace_back(in_mesh,a);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +186,7 @@ void MeshSplitter :: SplitMesh(unsigned int a, aiMesh* in_mesh, std::vector<std:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vFaces.push_back(aiFace());
|
vFaces.emplace_back();
|
||||||
aiFace& rFace = vFaces.back();
|
aiFace& rFace = vFaces.back();
|
||||||
|
|
||||||
// setup face type and number of indices
|
// setup face type and number of indices
|
||||||
|
|
|
@ -24,10 +24,9 @@ struct aiNode;
|
||||||
/** Splits meshes of unique vertices into meshes with no more vertices than
|
/** Splits meshes of unique vertices into meshes with no more vertices than
|
||||||
* a given, configurable threshold value.
|
* a given, configurable threshold value.
|
||||||
*/
|
*/
|
||||||
class MeshSplitter
|
class MeshSplitter {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
unsigned int LIMIT;
|
||||||
|
|
||||||
void SetLimit(unsigned int l) {
|
void SetLimit(unsigned int l) {
|
||||||
LIMIT = l;
|
LIMIT = l;
|
||||||
|
@ -37,8 +36,6 @@ public:
|
||||||
return LIMIT;
|
return LIMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Executes the post processing step on the given imported data.
|
/** Executes the post processing step on the given imported data.
|
||||||
* At the moment a process is not supposed to fail.
|
* At the moment a process is not supposed to fail.
|
||||||
|
@ -46,16 +43,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void Execute(aiScene *pScene);
|
void Execute(aiScene *pScene);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void UpdateNode(aiNode *pcNode, const std::vector<std::pair<aiMesh *, unsigned int>> &source_mesh_map);
|
void UpdateNode(aiNode *pcNode, const std::vector<std::pair<aiMesh *, unsigned int>> &source_mesh_map);
|
||||||
void SplitMesh(unsigned int index, aiMesh *mesh, std::vector<std::pair<aiMesh *, unsigned int>> &source_mesh_map);
|
void SplitMesh(unsigned int index, aiMesh *mesh, std::vector<std::pair<aiMesh *, unsigned int>> &source_mesh_map);
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
unsigned int LIMIT;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDED_MESH_SPLITTER
|
#endif // INCLUDED_MESH_SPLITTER
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
/** @file AssxmlExporter.h
|
/** @file AssxmlExporter.h
|
||||||
* ASSXML Exporter Main Header
|
* ASSXML Exporter Main Header
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef AI_ASSXMLEXPORTER_H_INC
|
#ifndef AI_ASSXMLEXPORTER_H_INC
|
||||||
#define AI_ASSXMLEXPORTER_H_INC
|
#define AI_ASSXMLEXPORTER_H_INC
|
||||||
|
|
||||||
|
|
|
@ -598,8 +598,11 @@ static void WriteDump(const char *pFile, const char *cmd, const aiScene *scene,
|
||||||
if (!mesh->mTextureCoords[a])
|
if (!mesh->mTextureCoords[a])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ioprintf(io, "\t\t<TextureCoords num=\"%u\" set=\"%u\" num_components=\"%u\"> \n", mesh->mNumVertices,
|
ioprintf(io, "\t\t<TextureCoords num=\"%u\" set=\"%u\" name=\"%s\" num_components=\"%u\"> \n",
|
||||||
a, mesh->mNumUVComponents[a]);
|
mesh->mNumVertices,
|
||||||
|
a,
|
||||||
|
mesh->mTextureCoordsNames[a].C_Str(),
|
||||||
|
mesh->mNumUVComponents[a]);
|
||||||
|
|
||||||
if (!shortened) {
|
if (!shortened) {
|
||||||
if (mesh->mNumUVComponents[a] == 3) {
|
if (mesh->mNumUVComponents[a] == 3) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
/** @file AssxmlFileWriter.h
|
/** @file AssxmlFileWriter.h
|
||||||
* @brief Declaration of Assxml file writer.
|
* @brief Declaration of Assxml file writer.
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef AI_ASSXMLFILEWRITER_H_INC
|
#ifndef AI_ASSXMLFILEWRITER_H_INC
|
||||||
#define AI_ASSXMLFILEWRITER_H_INC
|
#define AI_ASSXMLFILEWRITER_H_INC
|
||||||
|
|
||||||
|
|
|
@ -143,9 +143,9 @@ AI_WONT_RETURN void B3DImporter::Oops() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
AI_WONT_RETURN void B3DImporter::Fail(string str) {
|
AI_WONT_RETURN void B3DImporter::Fail(const string &str) {
|
||||||
#ifdef DEBUG_B3D
|
#ifdef DEBUG_B3D
|
||||||
ASSIMP_LOG_ERROR_F("Error in B3D file data: ", str);
|
ASSIMP_LOG_ERROR("Error in B3D file data: ", str);
|
||||||
#endif
|
#endif
|
||||||
throw DeadlyImportError("B3D Importer - error in B3D file data: ", str);
|
throw DeadlyImportError("B3D Importer - error in B3D file data: ", str);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ string B3DImporter::ReadChunk() {
|
||||||
tag += char(ReadByte());
|
tag += char(ReadByte());
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_B3D
|
#ifdef DEBUG_B3D
|
||||||
ASSIMP_LOG_DEBUG_F("ReadChunk: ", tag);
|
ASSIMP_LOG_DEBUG("ReadChunk: ", tag);
|
||||||
#endif
|
#endif
|
||||||
unsigned sz = (unsigned)ReadInt();
|
unsigned sz = (unsigned)ReadInt();
|
||||||
_stack.push_back(_pos + sz);
|
_stack.push_back(_pos + sz);
|
||||||
|
@ -397,7 +397,7 @@ void B3DImporter::ReadTRIS(int v0) {
|
||||||
matid = 0;
|
matid = 0;
|
||||||
} else if (matid < 0 || matid >= (int)_materials.size()) {
|
} else if (matid < 0 || matid >= (int)_materials.size()) {
|
||||||
#ifdef DEBUG_B3D
|
#ifdef DEBUG_B3D
|
||||||
ASSIMP_LOG_ERROR_F("material id=", matid);
|
ASSIMP_LOG_ERROR("material id=", matid);
|
||||||
#endif
|
#endif
|
||||||
Fail("Bad material id");
|
Fail("Bad material id");
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ void B3DImporter::ReadTRIS(int v0) {
|
||||||
int i2 = ReadInt() + v0;
|
int i2 = ReadInt() + v0;
|
||||||
if (i0 < 0 || i0 >= (int)_vertices.size() || i1 < 0 || i1 >= (int)_vertices.size() || i2 < 0 || i2 >= (int)_vertices.size()) {
|
if (i0 < 0 || i0 >= (int)_vertices.size() || i1 < 0 || i1 >= (int)_vertices.size() || i2 < 0 || i2 >= (int)_vertices.size()) {
|
||||||
#ifdef DEBUG_B3D
|
#ifdef DEBUG_B3D
|
||||||
ASSIMP_LOG_ERROR_F("Bad triangle index: i0=", i0, ", i1=", i1, ", i2=", i2);
|
ASSIMP_LOG_ERROR("Bad triangle index: i0=", i0, ", i1=", i1, ", i2=", i2);
|
||||||
#endif
|
#endif
|
||||||
Fail("Bad triangle index");
|
Fail("Bad triangle index");
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -40,8 +39,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @file Definition of the .b3d importer class. */
|
/**
|
||||||
|
* @file Definition of the .b3d importer class.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef AI_B3DIMPORTER_H_INC
|
#ifndef AI_B3DIMPORTER_H_INC
|
||||||
#define AI_B3DIMPORTER_H_INC
|
#define AI_B3DIMPORTER_H_INC
|
||||||
|
|
||||||
|
@ -62,14 +63,12 @@ namespace Assimp{
|
||||||
class B3DImporter : public BaseImporter{
|
class B3DImporter : public BaseImporter{
|
||||||
public:
|
public:
|
||||||
B3DImporter() = default;
|
B3DImporter() = default;
|
||||||
virtual ~B3DImporter();
|
~B3DImporter() override;
|
||||||
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const override;
|
||||||
virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
const aiImporterDesc* GetInfo () const override;
|
||||||
virtual const aiImporterDesc* GetInfo () const;
|
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) override;
|
||||||
virtual void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -96,7 +95,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
AI_WONT_RETURN void Oops() AI_WONT_RETURN_SUFFIX;
|
AI_WONT_RETURN void Oops() AI_WONT_RETURN_SUFFIX;
|
||||||
AI_WONT_RETURN void Fail( std::string str ) AI_WONT_RETURN_SUFFIX;
|
AI_WONT_RETURN void Fail(const std::string &str) AI_WONT_RETURN_SUFFIX;
|
||||||
|
|
||||||
void ReadTEXS();
|
void ReadTEXS();
|
||||||
void ReadBRUS();
|
void ReadBRUS();
|
||||||
|
@ -113,7 +112,6 @@ private:
|
||||||
void ReadBB3D( aiScene *scene );
|
void ReadBB3D( aiScene *scene );
|
||||||
|
|
||||||
size_t _pos;
|
size_t _pos;
|
||||||
// unsigned _size;
|
|
||||||
std::vector<unsigned char> _buf;
|
std::vector<unsigned char> _buf;
|
||||||
std::vector<size_t> _stack;
|
std::vector<size_t> _stack;
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ bool BVHLoader::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool cs)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ((!extension.length() || cs) && pIOHandler) {
|
if ((!extension.length() || cs) && pIOHandler) {
|
||||||
const char *tokens[] = { "HIERARCHY" };
|
static const char * const tokens[] = { "HIERARCHY" };
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -359,7 +359,7 @@ void BVHLoader::ReadMotion(aiScene * /*pScene*/) {
|
||||||
std::string BVHLoader::GetNextToken() {
|
std::string BVHLoader::GetNextToken() {
|
||||||
// skip any preceding whitespace
|
// skip any preceding whitespace
|
||||||
while (mReader != mBuffer.end()) {
|
while (mReader != mBuffer.end()) {
|
||||||
if (!isspace(*mReader))
|
if (!isspace((unsigned char)*mReader))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// count lines
|
// count lines
|
||||||
|
@ -372,7 +372,7 @@ std::string BVHLoader::GetNextToken() {
|
||||||
// collect all chars till the next whitespace. BVH is easy in respect to that.
|
// collect all chars till the next whitespace. BVH is easy in respect to that.
|
||||||
std::string token;
|
std::string token;
|
||||||
while (mReader != mBuffer.end()) {
|
while (mReader != mBuffer.end()) {
|
||||||
if (isspace(*mReader))
|
if (isspace((unsigned char)*mReader))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
token.push_back(*mReader);
|
token.push_back(*mReader);
|
||||||
|
|
|
@ -198,9 +198,9 @@ void DNAParser::Parse() {
|
||||||
s.size = offset;
|
s.size = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIMP_LOG_DEBUG_F("BlenderDNA: Got ", dna.structures.size(), " structures with totally ", fields, " fields");
|
ASSIMP_LOG_DEBUG("BlenderDNA: Got ", dna.structures.size(), " structures with totally ", fields, " fields");
|
||||||
|
|
||||||
#ifdef ASSIMP_BUILD_BLENDER_DEBUG
|
#if ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
||||||
dna.DumpToFile();
|
dna.DumpToFile();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ void DNAParser::Parse() {
|
||||||
dna.RegisterConverters();
|
dna.RegisterConverters();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ASSIMP_BUILD_BLENDER_DEBUG
|
#if ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -237,7 +237,7 @@ void DNA ::DumpToFile() {
|
||||||
|
|
||||||
ASSIMP_LOG_INFO("BlenderDNA: Dumped dna to dna.txt");
|
ASSIMP_LOG_INFO("BlenderDNA: Dumped dna to dna.txt");
|
||||||
}
|
}
|
||||||
#endif
|
#endif // ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
/*static*/ void DNA ::ExtractArraySize(
|
/*static*/ void DNA ::ExtractArraySize(
|
||||||
|
|
|
@ -59,6 +59,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define ASSIMP_BUILD_BLENDER_DEBUG
|
#define ASSIMP_BUILD_BLENDER_DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// set this to non-zero to dump BlenderDNA stuff to dna.txt.
|
||||||
|
// you could set it on the assimp build command line too without touching it here.
|
||||||
|
// !!! please make sure this is set to 0 in the repo !!!
|
||||||
|
#ifndef ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
||||||
|
#define ASSIMP_BUILD_BLENDER_DEBUG_DNA 0
|
||||||
|
#endif
|
||||||
|
|
||||||
// #define ASSIMP_BUILD_BLENDER_NO_STATS
|
// #define ASSIMP_BUILD_BLENDER_NO_STATS
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
@ -495,7 +502,7 @@ public:
|
||||||
const Structure &structure,
|
const Structure &structure,
|
||||||
const FileDatabase &db) const;
|
const FileDatabase &db) const;
|
||||||
|
|
||||||
#ifdef ASSIMP_BUILD_BLENDER_DEBUG
|
#if ASSIMP_BUILD_BLENDER_DEBUG_DNA
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
/** Dump the DNA to a text file. This is for debugging purposes.
|
/** Dump the DNA to a text file. This is for debugging purposes.
|
||||||
* The output file is `dna.txt` in the current working folder*/
|
* The output file is `dna.txt` in the current working folder*/
|
||||||
|
|
|
@ -565,7 +565,7 @@ template <> bool Structure :: ResolvePointer<std::shared_ptr,ElemBase>(std::shar
|
||||||
// this might happen if DNA::RegisterConverters hasn't been called so far
|
// this might happen if DNA::RegisterConverters hasn't been called so far
|
||||||
// or if the target type is not contained in `our` DNA.
|
// or if the target type is not contained in `our` DNA.
|
||||||
out.reset();
|
out.reset();
|
||||||
ASSIMP_LOG_WARN_F( "Failed to find a converter for the `",s.name,"` structure" );
|
ASSIMP_LOG_WARN( "Failed to find a converter for the `",s.name,"` structure" );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ using namespace Assimp::Blender;
|
||||||
using namespace Assimp::Formatter;
|
using namespace Assimp::Formatter;
|
||||||
|
|
||||||
static const aiImporterDesc blenderDesc = {
|
static const aiImporterDesc blenderDesc = {
|
||||||
"Blender 3D Importer \nhttp://www.blender3d.org",
|
"Blender 3D Importer (http://www.blender3d.org)",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
"No animation support yet",
|
"No animation support yet",
|
||||||
|
@ -113,8 +113,8 @@ BlenderImporter::~BlenderImporter() {
|
||||||
delete modifier_cache;
|
delete modifier_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *Tokens[] = { "BLENDER" };
|
static const char * const Tokens[] = { "BLENDER" };
|
||||||
static const char *TokensForSearch[] = { "blender" };
|
static const char * const TokensForSearch[] = { "blender" };
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// Returns whether the class can handle the format of the given file.
|
||||||
|
@ -132,12 +132,6 @@ bool BlenderImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
// List all extensions handled by this loader
|
|
||||||
void BlenderImporter::GetExtensionList(std::set<std::string> &app) {
|
|
||||||
app.insert("blend");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Loader registry entry
|
// Loader registry entry
|
||||||
const aiImporterDesc *BlenderImporter::GetInfo() const {
|
const aiImporterDesc *BlenderImporter::GetInfo() const {
|
||||||
|
@ -241,9 +235,9 @@ void BlenderImporter::InternReadFile(const std::string &pFile,
|
||||||
stream->Read(magic, 3, 1);
|
stream->Read(magic, 3, 1);
|
||||||
magic[3] = '\0';
|
magic[3] = '\0';
|
||||||
|
|
||||||
LogInfo((format(), "Blender version is ", magic[0], ".", magic + 1,
|
LogInfo("Blender version is ", magic[0], ".", magic + 1,
|
||||||
" (64bit: ", file.i64bit ? "true" : "false",
|
" (64bit: ", file.i64bit ? "true" : "false",
|
||||||
", little endian: ", file.little ? "true" : "false", ")"));
|
", little endian: ", file.little ? "true" : "false", ")");
|
||||||
|
|
||||||
ParseBlendFile(file, stream);
|
ParseBlendFile(file, stream);
|
||||||
|
|
||||||
|
@ -316,7 +310,7 @@ void BlenderImporter::ExtractScene(Scene &out, const FileDatabase &file) {
|
||||||
ss.Convert(out, file);
|
ss.Convert(out, file);
|
||||||
|
|
||||||
#ifndef ASSIMP_BUILD_BLENDER_NO_STATS
|
#ifndef ASSIMP_BUILD_BLENDER_NO_STATS
|
||||||
ASSIMP_LOG_INFO_F(
|
ASSIMP_LOG_INFO(
|
||||||
"(Stats) Fields read: ", file.stats().fields_read,
|
"(Stats) Fields read: ", file.stats().fields_read,
|
||||||
", pointers resolved: ", file.stats().pointers_resolved,
|
", pointers resolved: ", file.stats().pointers_resolved,
|
||||||
", cache hits: ", file.stats().cache_hits,
|
", cache hits: ", file.stats().cache_hits,
|
||||||
|
@ -426,9 +420,9 @@ void BlenderImporter::ResolveImage(aiMaterial *out, const Material *mat, const M
|
||||||
--s;
|
--s;
|
||||||
}
|
}
|
||||||
|
|
||||||
curTex->achFormatHint[0] = s + 1 > e ? '\0' : (char)::tolower(s[1]);
|
curTex->achFormatHint[0] = s + 1 > e ? '\0' : (char)::tolower((unsigned char)s[1]);
|
||||||
curTex->achFormatHint[1] = s + 2 > e ? '\0' : (char)::tolower(s[2]);
|
curTex->achFormatHint[1] = s + 2 > e ? '\0' : (char)::tolower((unsigned char)s[2]);
|
||||||
curTex->achFormatHint[2] = s + 3 > e ? '\0' : (char)::tolower(s[3]);
|
curTex->achFormatHint[2] = s + 3 > e ? '\0' : (char)::tolower((unsigned char)s[3]);
|
||||||
curTex->achFormatHint[3] = '\0';
|
curTex->achFormatHint[3] = '\0';
|
||||||
|
|
||||||
// tex->mHeight = 0;
|
// tex->mHeight = 0;
|
||||||
|
@ -440,7 +434,7 @@ void BlenderImporter::ResolveImage(aiMaterial *out, const Material *mat, const M
|
||||||
|
|
||||||
curTex->pcData = reinterpret_cast<aiTexel *>(ch);
|
curTex->pcData = reinterpret_cast<aiTexel *>(ch);
|
||||||
|
|
||||||
LogInfo("Reading embedded texture, original file was " + std::string(img->name));
|
LogInfo("Reading embedded texture, original file was ", img->name);
|
||||||
} else {
|
} else {
|
||||||
name = aiString(img->name);
|
name = aiString(img->name);
|
||||||
}
|
}
|
||||||
|
@ -522,7 +516,7 @@ void BlenderImporter::ResolveTexture(aiMaterial *out, const Material *mat, const
|
||||||
case Tex::Type_POINTDENSITY:
|
case Tex::Type_POINTDENSITY:
|
||||||
case Tex::Type_VOXELDATA:
|
case Tex::Type_VOXELDATA:
|
||||||
|
|
||||||
LogWarn(std::string("Encountered a texture with an unsupported type: ") + dispnam);
|
LogWarn("Encountered a texture with an unsupported type: ", dispnam);
|
||||||
AddSentinelTexture(out, mat, tex, conv_data);
|
AddSentinelTexture(out, mat, tex, conv_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -685,7 +679,7 @@ void BlenderImporter::BuildMaterials(ConversionData &conv_data) {
|
||||||
|
|
||||||
BuildDefaultMaterial(conv_data);
|
BuildDefaultMaterial(conv_data);
|
||||||
|
|
||||||
for (std::shared_ptr<Material> mat : conv_data.materials_raw) {
|
for (const std::shared_ptr<Material> &mat : conv_data.materials_raw) {
|
||||||
|
|
||||||
// reset per material global counters
|
// reset per material global counters
|
||||||
for (size_t i = 0; i < sizeof(conv_data.next_texture) / sizeof(conv_data.next_texture[0]); ++i) {
|
for (size_t i = 0; i < sizeof(conv_data.next_texture) / sizeof(conv_data.next_texture[0]); ++i) {
|
||||||
|
@ -758,7 +752,7 @@ void BlenderImporter::CheckActualType(const ElemBase *dt, const char *check) {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void BlenderImporter::NotSupportedObjectType(const Object *obj, const char *type) {
|
void BlenderImporter::NotSupportedObjectType(const Object *obj, const char *type) {
|
||||||
LogWarn((format(), "Object `", obj->id.name, "` - type is unsupported: `", type, "`, skipping"));
|
LogWarn("Object `", obj->id.name, "` - type is unsupported: `", type, "`, skipping");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
/** @file BlenderLoader.h
|
/** @file BlenderLoader.h
|
||||||
* @brief Declaration of the Blender 3D (*.blend) importer class.
|
* @brief Declaration of the Blender 3D (*.blend) importer class.
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef INCLUDED_AI_BLEND_LOADER_H
|
#ifndef INCLUDED_AI_BLEND_LOADER_H
|
||||||
#define INCLUDED_AI_BLEND_LOADER_H
|
#define INCLUDED_AI_BLEND_LOADER_H
|
||||||
|
|
||||||
|
@ -60,15 +60,19 @@ namespace Assimp {
|
||||||
|
|
||||||
// TinyFormatter.h
|
// TinyFormatter.h
|
||||||
namespace Formatter {
|
namespace Formatter {
|
||||||
template <typename T,typename TR, typename A> class basic_formatter;
|
|
||||||
|
template <typename T, typename TR, typename A>
|
||||||
|
class basic_formatter;
|
||||||
|
|
||||||
typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
|
typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
|
||||||
}
|
|
||||||
|
} // namespace Formatter
|
||||||
|
|
||||||
// BlenderDNA.h
|
// BlenderDNA.h
|
||||||
namespace Blender {
|
namespace Blender {
|
||||||
class FileDatabase;
|
class FileDatabase;
|
||||||
struct ElemBase;
|
struct ElemBase;
|
||||||
}
|
} // namespace Blender
|
||||||
|
|
||||||
// BlenderScene.h
|
// BlenderScene.h
|
||||||
namespace Blender {
|
namespace Blender {
|
||||||
|
@ -80,39 +84,36 @@ namespace Assimp {
|
||||||
struct MTex;
|
struct MTex;
|
||||||
struct Image;
|
struct Image;
|
||||||
struct Material;
|
struct Material;
|
||||||
}
|
} // namespace Blender
|
||||||
|
|
||||||
// BlenderIntermediate.h
|
// BlenderIntermediate.h
|
||||||
namespace Blender {
|
namespace Blender {
|
||||||
struct ConversionData;
|
struct ConversionData;
|
||||||
template <template <typename,typename> class TCLASS, typename T> struct TempArray;
|
template <template <typename, typename> class TCLASS, typename T>
|
||||||
}
|
struct TempArray;
|
||||||
|
} // namespace Blender
|
||||||
|
|
||||||
// BlenderModifier.h
|
// BlenderModifier.h
|
||||||
namespace Blender {
|
namespace Blender {
|
||||||
class BlenderModifierShowcase;
|
class BlenderModifierShowcase;
|
||||||
class BlenderModifier;
|
class BlenderModifier;
|
||||||
}
|
} // namespace Blender
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
/** Load blenders official binary format. The actual file structure (the `DNA` how they
|
/** Load blenders official binary format. The actual file structure (the `DNA` how they
|
||||||
* call it is outsourced to BlenderDNA.cpp/BlenderDNA.h. This class only performs the
|
* call it is outsourced to BlenderDNA.cpp/BlenderDNA.h. This class only performs the
|
||||||
* conversion from intermediate format to aiScene. */
|
* conversion from intermediate format to aiScene. */
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
class BlenderImporter : public BaseImporter, public LogFunctions<BlenderImporter>
|
class BlenderImporter : public BaseImporter, public LogFunctions<BlenderImporter> {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BlenderImporter();
|
BlenderImporter();
|
||||||
~BlenderImporter();
|
~BlenderImporter() override;
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc *GetInfo() const override;
|
||||||
void GetExtensionList(std::set<std::string>& app);
|
void SetupProperties(const Importer *pImp) override;
|
||||||
void SetupProperties(const Importer* pImp);
|
void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) override;
|
||||||
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
|
||||||
void ParseBlendFile(Blender::FileDatabase &out, std::shared_ptr<IOStream> stream);
|
void ParseBlendFile(Blender::FileDatabase &out, std::shared_ptr<IOStream> stream);
|
||||||
void ExtractScene(Blender::Scene &out, const Blender::FileDatabase &file);
|
void ExtractScene(Blender::Scene &out, const Blender::FileDatabase &file);
|
||||||
void ConvertBlendFile(aiScene *out, const Blender::Scene &in, const Blender::FileDatabase &file);
|
void ConvertBlendFile(aiScene *out, const Blender::Scene &in, const Blender::FileDatabase &file);
|
||||||
|
@ -121,52 +122,46 @@ private:
|
||||||
aiNode *ConvertNode(const Blender::Scene &in,
|
aiNode *ConvertNode(const Blender::Scene &in,
|
||||||
const Blender::Object *obj,
|
const Blender::Object *obj,
|
||||||
Blender::ConversionData &conv_info,
|
Blender::ConversionData &conv_info,
|
||||||
const aiMatrix4x4& parentTransform
|
const aiMatrix4x4 &parentTransform);
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
void ConvertMesh(const Blender::Scene &in,
|
void ConvertMesh(const Blender::Scene &in,
|
||||||
const Blender::Object *obj,
|
const Blender::Object *obj,
|
||||||
const Blender::Mesh *mesh,
|
const Blender::Mesh *mesh,
|
||||||
Blender::ConversionData &conv_data,
|
Blender::ConversionData &conv_data,
|
||||||
Blender::TempArray<std::vector,aiMesh>& temp
|
Blender::TempArray<std::vector, aiMesh> &temp);
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
aiLight *ConvertLight(const Blender::Scene &in,
|
aiLight *ConvertLight(const Blender::Scene &in,
|
||||||
const Blender::Object *obj,
|
const Blender::Object *obj,
|
||||||
const Blender::Lamp *mesh,
|
const Blender::Lamp *mesh,
|
||||||
Blender::ConversionData& conv_data
|
Blender::ConversionData &conv_data);
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
aiCamera *ConvertCamera(const Blender::Scene &in,
|
aiCamera *ConvertCamera(const Blender::Scene &in,
|
||||||
const Blender::Object *obj,
|
const Blender::Object *obj,
|
||||||
const Blender::Camera *mesh,
|
const Blender::Camera *mesh,
|
||||||
Blender::ConversionData& conv_data
|
Blender::ConversionData &conv_data);
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
void BuildDefaultMaterial(
|
void BuildDefaultMaterial(
|
||||||
Blender::ConversionData& conv_data
|
Blender::ConversionData &conv_data);
|
||||||
);
|
|
||||||
|
|
||||||
|
// --------------------
|
||||||
void AddBlendParams(
|
void AddBlendParams(
|
||||||
aiMaterial *result,
|
aiMaterial *result,
|
||||||
const Blender::Material* source
|
const Blender::Material *source);
|
||||||
);
|
|
||||||
|
|
||||||
|
// --------------------
|
||||||
void BuildMaterials(
|
void BuildMaterials(
|
||||||
Blender::ConversionData& conv_data
|
Blender::ConversionData &conv_data);
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
void ResolveTexture(
|
void ResolveTexture(
|
||||||
aiMaterial *out,
|
aiMaterial *out,
|
||||||
const Blender::Material *mat,
|
const Blender::Material *mat,
|
||||||
const Blender::MTex *tex,
|
const Blender::MTex *tex,
|
||||||
Blender::ConversionData& conv_data
|
Blender::ConversionData &conv_data);
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
void ResolveImage(
|
void ResolveImage(
|
||||||
|
@ -174,31 +169,25 @@ private:
|
||||||
const Blender::Material *mat,
|
const Blender::Material *mat,
|
||||||
const Blender::MTex *tex,
|
const Blender::MTex *tex,
|
||||||
const Blender::Image *img,
|
const Blender::Image *img,
|
||||||
Blender::ConversionData& conv_data
|
Blender::ConversionData &conv_data);
|
||||||
);
|
|
||||||
|
|
||||||
|
// --------------------
|
||||||
void AddSentinelTexture(
|
void AddSentinelTexture(
|
||||||
aiMaterial *out,
|
aiMaterial *out,
|
||||||
const Blender::Material *mat,
|
const Blender::Material *mat,
|
||||||
const Blender::MTex *tex,
|
const Blender::MTex *tex,
|
||||||
Blender::ConversionData& conv_data
|
Blender::ConversionData &conv_data);
|
||||||
);
|
|
||||||
|
|
||||||
private: // static stuff, mostly logging and error reporting.
|
private: // static stuff, mostly logging and error reporting.
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
static void CheckActualType(const Blender::ElemBase *dt,
|
static void CheckActualType(const Blender::ElemBase *dt,
|
||||||
const char* check
|
const char *check);
|
||||||
);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
static void NotSupportedObjectType(const Blender::Object *obj,
|
static void NotSupportedObjectType(const Blender::Object *obj,
|
||||||
const char* type
|
const char *type);
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Blender::BlenderModifierShowcase *modifier_cache;
|
Blender::BlenderModifierShowcase *modifier_cache;
|
||||||
|
|
||||||
}; // !class BlenderImporter
|
}; // !class BlenderImporter
|
||||||
|
|
|
@ -90,7 +90,7 @@ void BlenderModifierShowcase::ApplyModifiers(aiNode &out, ConversionData &conv_d
|
||||||
|
|
||||||
const Structure *s = conv_data.db.dna.Get(cur->dna_type);
|
const Structure *s = conv_data.db.dna.Get(cur->dna_type);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
ASSIMP_LOG_WARN_F("BlendModifier: could not resolve DNA name: ", cur->dna_type);
|
ASSIMP_LOG_WARN("BlendModifier: could not resolve DNA name: ", cur->dna_type);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ void BlenderModifierShowcase::ApplyModifiers(aiNode &out, ConversionData &conv_d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (curgod) {
|
if (curgod) {
|
||||||
ASSIMP_LOG_WARN_F("Couldn't find a handler for modifier: ", dat.name);
|
ASSIMP_LOG_WARN("Couldn't find a handler for modifier: ", dat.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ void BlenderModifierShowcase::ApplyModifiers(aiNode &out, ConversionData &conv_d
|
||||||
// object, we still can't say whether our modifier implementations were
|
// object, we still can't say whether our modifier implementations were
|
||||||
// able to fully do their job.
|
// able to fully do their job.
|
||||||
if (ful) {
|
if (ful) {
|
||||||
ASSIMP_LOG_DEBUG_F("BlendModifier: found handlers for ", cnt, " of ", ful, " modifiers on `", orig_object.id.name,
|
ASSIMP_LOG_DEBUG("BlendModifier: found handlers for ", cnt, " of ", ful, " modifiers on `", orig_object.id.name,
|
||||||
"`, check log messages above for errors");
|
"`, check log messages above for errors");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ void BlenderModifier_Mirror ::DoIt(aiNode &out, ConversionData &conv_data, const
|
||||||
out.mMeshes = nind;
|
out.mMeshes = nind;
|
||||||
out.mNumMeshes *= 2;
|
out.mNumMeshes *= 2;
|
||||||
|
|
||||||
ASSIMP_LOG_INFO_F("BlendModifier: Applied the `Mirror` modifier to `",
|
ASSIMP_LOG_INFO("BlendModifier: Applied the `Mirror` modifier to `",
|
||||||
orig_object.id.name, "`");
|
orig_object.id.name, "`");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ void BlenderModifier_Subdivision ::DoIt(aiNode &out, ConversionData &conv_data,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ASSIMP_LOG_WARN_F("BlendModifier: Unrecognized subdivision algorithm: ", mir.subdivType);
|
ASSIMP_LOG_WARN("BlendModifier: Unrecognized subdivision algorithm: ", mir.subdivType);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ void BlenderModifier_Subdivision ::DoIt(aiNode &out, ConversionData &conv_data,
|
||||||
subd->Subdivide(meshes, out.mNumMeshes, tempmeshes.get(), std::max(mir.renderLevels, mir.levels), true);
|
subd->Subdivide(meshes, out.mNumMeshes, tempmeshes.get(), std::max(mir.renderLevels, mir.levels), true);
|
||||||
std::copy(tempmeshes.get(), tempmeshes.get() + out.mNumMeshes, meshes);
|
std::copy(tempmeshes.get(), tempmeshes.get() + out.mNumMeshes, meshes);
|
||||||
|
|
||||||
ASSIMP_LOG_INFO_F("BlendModifier: Applied the `Subdivision` modifier to `",
|
ASSIMP_LOG_INFO("BlendModifier: Applied the `Subdivision` modifier to `",
|
||||||
orig_object.id.name, "`");
|
orig_object.id.name, "`");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ public:
|
||||||
const Scene& /*in*/,
|
const Scene& /*in*/,
|
||||||
const Object& /*orig_object*/
|
const Object& /*orig_object*/
|
||||||
) {
|
) {
|
||||||
ASSIMP_LOG_INFO_F("This modifier is not supported, skipping: ",orig_modifier.dna_type );
|
ASSIMP_LOG_INFO("This modifier is not supported, skipping: ",orig_modifier.dna_type );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Open Asset Import Library (assimp)
|
Open Asset Import Library (assimp)
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -51,7 +51,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "C4DImporter.h"
|
#include "C4DImporter.h"
|
||||||
#include <assimp/TinyFormatter.h>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
#include <assimp/scene.h>
|
#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 "c4d_file.h"
|
||||||
#include "default_alien_overloads.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
|
// overload this function and fill in your own unique data
|
||||||
void GetWriterInfo(int &id, String &appname) {
|
void GetWriterInfo(int &id, String &appname) {
|
||||||
|
@ -73,9 +84,6 @@ void GetWriterInfo(int &id, String &appname) {
|
||||||
appname = "Open Asset Import Library";
|
appname = "Open Asset Import Library";
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace Assimp;
|
|
||||||
using namespace Assimp::Formatter;
|
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
template<> const char* LogFunctions<C4DImporter>::Prefix() {
|
template<> const char* LogFunctions<C4DImporter>::Prefix() {
|
||||||
static auto prefix = "C4D: ";
|
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 {
|
bool C4DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
|
||||||
const std::string& extension = GetExtension(pFile);
|
const std::string& extension = GetExtension(pFile);
|
||||||
|
@ -125,11 +122,6 @@ const aiImporterDesc* C4DImporter::GetInfo () const {
|
||||||
return &desc;
|
return &desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
void C4DImporter::SetupProperties(const Importer* /*pImp*/) {
|
|
||||||
// nothing to be done for the moment
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
|
@ -154,8 +146,14 @@ void C4DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
|
||||||
ThrowException("failed to read document " + pFile);
|
ThrowException("failed to read document " + pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate the root-node
|
||||||
pScene->mRootNode = new aiNode("<C4DRoot>");
|
pScene->mRootNode = new aiNode("<C4DRoot>");
|
||||||
|
|
||||||
|
// convert left-handed to right-handed
|
||||||
|
pScene->mRootNode->mTransformation.a1 = 0.01f;
|
||||||
|
pScene->mRootNode->mTransformation.b2 = 0.01f;
|
||||||
|
pScene->mRootNode->mTransformation.c3 = -0.01f;
|
||||||
|
|
||||||
// first convert all materials
|
// first convert all materials
|
||||||
ReadMaterials(doc->GetFirstMaterial());
|
ReadMaterials(doc->GetFirstMaterial());
|
||||||
|
|
||||||
|
@ -199,8 +197,8 @@ void C4DImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
bool C4DImporter::ReadShader(aiMaterial* out, melange::BaseShader* shader) {
|
bool C4DImporter::ReadShader(aiMaterial* out, BaseShader* shader) {
|
||||||
// based on Melange sample code (C4DImportExport.cpp)
|
// based on Cineware sample code (C4DImportExport.cpp)
|
||||||
while(shader) {
|
while(shader) {
|
||||||
if(shader->GetType() == Xlayer) {
|
if(shader->GetType() == Xlayer) {
|
||||||
BaseContainer* container = shader->GetDataInstance();
|
BaseContainer* container = shader->GetDataInstance();
|
||||||
|
@ -242,13 +240,11 @@ bool C4DImporter::ReadShader(aiMaterial* out, melange::BaseShader* shader) {
|
||||||
lsl = lsl->GetNext();
|
lsl = lsl->GetNext();
|
||||||
}
|
}
|
||||||
} else if ( shader->GetType() == Xbitmap ) {
|
} else if ( shader->GetType() == Xbitmap ) {
|
||||||
aiString path;
|
auto const path = aiStringFrom(shader->GetFileName().GetString());
|
||||||
shader->GetFileName().GetString().GetCString(path.data, MAXLEN-1);
|
|
||||||
path.length = ::strlen(path.data);
|
|
||||||
out->AddProperty(&path, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
out->AddProperty(&path, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LogWarn("ignoring shader type: " + std::string(GetObjectTypeName(shader->GetType())));
|
LogWarn("ignoring shader type: ", GetObjectTypeName(shader->GetType()));
|
||||||
}
|
}
|
||||||
shader = shader->GetNext();
|
shader = shader->GetNext();
|
||||||
}
|
}
|
||||||
|
@ -257,18 +253,15 @@ bool C4DImporter::ReadShader(aiMaterial* out, melange::BaseShader* shader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void C4DImporter::ReadMaterials(melange::BaseMaterial* mat) {
|
void C4DImporter::ReadMaterials(BaseMaterial* mat) {
|
||||||
// based on Melange sample code
|
// based on Cineware sample code
|
||||||
while (mat) {
|
while (mat) {
|
||||||
const String& name = mat->GetName();
|
|
||||||
if (mat->GetType() == Mmaterial) {
|
if (mat->GetType() == Mmaterial) {
|
||||||
aiMaterial* out = new aiMaterial();
|
aiMaterial* out = new aiMaterial();
|
||||||
material_mapping[mat] = static_cast<unsigned int>(materials.size());
|
material_mapping[mat] = static_cast<unsigned int>(materials.size());
|
||||||
materials.push_back(out);
|
materials.push_back(out);
|
||||||
|
|
||||||
aiString ai_name;
|
auto const ai_name = aiStringFrom(mat->GetName());
|
||||||
name.GetCString(ai_name.data, MAXLEN-1);
|
|
||||||
ai_name.length = ::strlen(ai_name.data);
|
|
||||||
out->AddProperty(&ai_name, AI_MATKEY_NAME);
|
out->AddProperty(&ai_name, AI_MATKEY_NAME);
|
||||||
|
|
||||||
Material& m = dynamic_cast<Material&>(*mat);
|
Material& m = dynamic_cast<Material&>(*mat);
|
||||||
|
@ -294,7 +287,7 @@ void C4DImporter::ReadMaterials(melange::BaseMaterial* mat) {
|
||||||
ReadShader(out, shader);
|
ReadShader(out, shader);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LogWarn("ignoring plugin material: " + std::string(GetObjectTypeName(mat->GetType())));
|
LogWarn("ignoring plugin material: ", GetObjectTypeName(mat->GetType()));
|
||||||
}
|
}
|
||||||
mat = mat->GetNext();
|
mat = mat->GetNext();
|
||||||
}
|
}
|
||||||
|
@ -305,19 +298,15 @@ void C4DImporter::RecurseHierarchy(BaseObject* object, aiNode* parent) {
|
||||||
ai_assert(parent != nullptr );
|
ai_assert(parent != nullptr );
|
||||||
std::vector<aiNode*> nodes;
|
std::vector<aiNode*> nodes;
|
||||||
|
|
||||||
// based on Melange sample code
|
// based on Cineware sample code
|
||||||
while (object) {
|
while (object) {
|
||||||
const String& name = object->GetName();
|
|
||||||
const LONG type = object->GetType();
|
const LONG type = object->GetType();
|
||||||
const Matrix& ml = object->GetMl();
|
const Matrix& ml = object->GetMl();
|
||||||
|
|
||||||
aiString string;
|
|
||||||
name.GetCString(string.data, MAXLEN-1);
|
|
||||||
string.length = ::strlen(string.data);
|
|
||||||
aiNode* const nd = new aiNode();
|
aiNode* const nd = new aiNode();
|
||||||
|
|
||||||
nd->mParent = parent;
|
nd->mParent = parent;
|
||||||
nd->mName = string;
|
nd->mName = aiStringFrom(object->GetName());
|
||||||
|
|
||||||
nd->mTransformation.a1 = ml.v1.x;
|
nd->mTransformation.a1 = ml.v1.x;
|
||||||
nd->mTransformation.b1 = ml.v1.y;
|
nd->mTransformation.b1 = ml.v1.y;
|
||||||
|
@ -352,7 +341,7 @@ void C4DImporter::RecurseHierarchy(BaseObject* object, aiNode* parent) {
|
||||||
meshes.push_back(mesh);
|
meshes.push_back(mesh);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LogWarn("ignoring object: " + std::string(GetObjectTypeName(type)));
|
LogWarn("ignoring object: ", GetObjectTypeName(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
RecurseHierarchy(object->GetDown(), nd);
|
RecurseHierarchy(object->GetDown(), nd);
|
||||||
|
@ -370,7 +359,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) {
|
||||||
ai_assert(object != nullptr);
|
ai_assert(object != nullptr);
|
||||||
ai_assert( object->GetType() == Opolygon );
|
ai_assert( object->GetType() == Opolygon );
|
||||||
|
|
||||||
// based on Melange sample code
|
// based on Cineware sample code
|
||||||
PolygonObject* const polyObject = dynamic_cast<PolygonObject*>(object);
|
PolygonObject* const polyObject = dynamic_cast<PolygonObject*>(object);
|
||||||
ai_assert(polyObject != nullptr);
|
ai_assert(polyObject != nullptr);
|
||||||
|
|
||||||
|
@ -618,4 +607,3 @@ unsigned int C4DImporter::ResolveMaterial(PolygonObject* obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ASSIMP_BUILD_NO_C4D_IMPORTER
|
#endif // ASSIMP_BUILD_NO_C4D_IMPORTER
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Open Asset Import Library (assimp)
|
Open Asset Import Library (assimp)
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -56,8 +56,8 @@ struct aiMaterial;
|
||||||
|
|
||||||
struct aiImporterDesc;
|
struct aiImporterDesc;
|
||||||
|
|
||||||
namespace melange {
|
namespace cineware {
|
||||||
class BaseObject; // c4d_file.h
|
class BaseObject;
|
||||||
class PolygonObject;
|
class PolygonObject;
|
||||||
class BaseMaterial;
|
class BaseMaterial;
|
||||||
class BaseShader;
|
class BaseShader;
|
||||||
|
@ -71,43 +71,34 @@ namespace Assimp {
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
/** Importer class to load Cinema4D files using the Melange library to be obtained from
|
/** Importer class to load Cinema4D files using the Cineware library to be obtained from
|
||||||
* www.plugincafe.com
|
* 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> {
|
class C4DImporter : public BaseImporter, public LogFunctions<C4DImporter> {
|
||||||
public:
|
public:
|
||||||
C4DImporter();
|
bool CanRead( const std::string& pFile, IOSystem*, bool checkSig) const override;
|
||||||
~C4DImporter();
|
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
|
||||||
bool checkSig) const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// --------------------
|
const aiImporterDesc* GetInfo () const override;
|
||||||
const aiImporterDesc* GetInfo () const;
|
|
||||||
|
|
||||||
// --------------------
|
void InternReadFile( const std::string& pFile, aiScene*, IOSystem* ) override;
|
||||||
void SetupProperties(const Importer* pImp);
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
|
||||||
IOSystem* pIOHandler);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void ReadMaterials(melange::BaseMaterial* mat);
|
void ReadMaterials(cineware::BaseMaterial* mat);
|
||||||
void RecurseHierarchy(melange::BaseObject* object, aiNode* parent);
|
void RecurseHierarchy(cineware::BaseObject* object, aiNode* parent);
|
||||||
aiMesh* ReadMesh(melange::BaseObject* object);
|
aiMesh* ReadMesh(cineware::BaseObject* object);
|
||||||
unsigned int ResolveMaterial(melange::PolygonObject* obj);
|
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<aiMesh*> meshes;
|
||||||
std::vector<aiMaterial*> materials;
|
std::vector<aiMaterial*> materials;
|
||||||
|
|
||||||
typedef std::map<melange::BaseMaterial*, unsigned int> MaterialMap;
|
typedef std::map<cineware::BaseMaterial*, unsigned int> MaterialMap;
|
||||||
MaterialMap material_mapping;
|
MaterialMap material_mapping;
|
||||||
|
|
||||||
}; // !class C4DImporter
|
}; // !class C4DImporter
|
||||||
|
|
|
@ -110,7 +110,7 @@ bool COBImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ((!extension.length() || checkSig) && pIOHandler) {
|
else if ((!extension.length() || checkSig) && pIOHandler) {
|
||||||
const char *tokens[] = { "Caligary" };
|
static const char * const tokens[] = { "Caligary" };
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -137,7 +137,13 @@ void COBImporter::SetupProperties(const Importer * /*pImp*/) {
|
||||||
// Imports the given file into the given scene structure.
|
// Imports the given file into the given scene structure.
|
||||||
void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
|
||||||
COB::Scene scene;
|
COB::Scene scene;
|
||||||
std::unique_ptr<StreamReaderLE> stream(new StreamReaderLE(pIOHandler->Open(pFile, "rb")));
|
|
||||||
|
auto file = pIOHandler->Open(pFile, "rb");
|
||||||
|
if (!file) {
|
||||||
|
ThrowException("Could not open " + pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<StreamReaderLE> stream(new StreamReaderLE(file));
|
||||||
|
|
||||||
// check header
|
// check header
|
||||||
char head[32];
|
char head[32];
|
||||||
|
@ -146,7 +152,7 @@ void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
ThrowException("Could not found magic id: `Caligari`");
|
ThrowException("Could not found magic id: `Caligari`");
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIMP_LOG_INFO_F("File format tag: ", std::string(head + 9, 6));
|
ASSIMP_LOG_INFO("File format tag: ", std::string(head + 9, 6));
|
||||||
if (head[16] != 'L') {
|
if (head[16] != 'L') {
|
||||||
ThrowException("File is big-endian, which is not supported");
|
ThrowException("File is big-endian, which is not supported");
|
||||||
}
|
}
|
||||||
|
@ -224,7 +230,7 @@ void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void ConvertTexture(std::shared_ptr<Texture> tex, aiMaterial *out, aiTextureType type) {
|
void ConvertTexture(const std::shared_ptr<Texture> &tex, aiMaterial *out, aiTextureType type) {
|
||||||
const aiString path(tex->path);
|
const aiString path(tex->path);
|
||||||
out->AddProperty(&path, AI_MATKEY_TEXTURE(type, 0));
|
out->AddProperty(&path, AI_MATKEY_TEXTURE(type, 0));
|
||||||
out->AddProperty(&tex->transform, 1, AI_MATKEY_UVTRANSFORM(type, 0));
|
out->AddProperty(&tex->transform, 1, AI_MATKEY_UVTRANSFORM(type, 0));
|
||||||
|
@ -295,8 +301,7 @@ aiNode *COBImporter::BuildNodes(const Node &root, const Scene &scin, aiScene *fi
|
||||||
}
|
}
|
||||||
std::unique_ptr<const Material> defmat;
|
std::unique_ptr<const Material> defmat;
|
||||||
if (!min) {
|
if (!min) {
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG(format() << "Could not resolve material index "
|
ASSIMP_LOG_VERBOSE_DEBUG("Could not resolve material index ", reflist.first, " - creating default material for this slot");
|
||||||
<< reflist.first << " - creating default material for this slot");
|
|
||||||
|
|
||||||
defmat.reset(min = new Material());
|
defmat.reset(min = new Material());
|
||||||
}
|
}
|
||||||
|
@ -521,7 +526,7 @@ void COBImporter::ReadMat1_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
|
|
||||||
++splitter;
|
++splitter;
|
||||||
if (!splitter.match_start("mat# ")) {
|
if (!splitter.match_start("mat# ")) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `mat#` line in `Mat1` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `mat#` line in `Mat1` chunk ", nfo.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,7 +538,7 @@ void COBImporter::ReadMat1_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
++splitter;
|
++splitter;
|
||||||
|
|
||||||
if (!splitter.match_start("shader: ")) {
|
if (!splitter.match_start("shader: ")) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `mat#` line in `Mat1` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `mat#` line in `Mat1` chunk ", nfo.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string shader = std::string(splitter[1]);
|
std::string shader = std::string(splitter[1]);
|
||||||
|
@ -544,12 +549,12 @@ void COBImporter::ReadMat1_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
} else if (shader == "phong") {
|
} else if (shader == "phong") {
|
||||||
mat.shader = Material::PHONG;
|
mat.shader = Material::PHONG;
|
||||||
} else if (shader != "flat") {
|
} else if (shader != "flat") {
|
||||||
ASSIMP_LOG_WARN_F("Unknown value for `shader` in `Mat1` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Unknown value for `shader` in `Mat1` chunk ", nfo.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
++splitter;
|
++splitter;
|
||||||
if (!splitter.match_start("rgb ")) {
|
if (!splitter.match_start("rgb ")) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `rgb` line in `Mat1` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `rgb` line in `Mat1` chunk ", nfo.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *rgb = splitter[1];
|
const char *rgb = splitter[1];
|
||||||
|
@ -557,7 +562,7 @@ void COBImporter::ReadMat1_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
|
|
||||||
++splitter;
|
++splitter;
|
||||||
if (!splitter.match_start("alpha ")) {
|
if (!splitter.match_start("alpha ")) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `alpha` line in `Mat1` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `alpha` line in `Mat1` chunk ", nfo.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *tokens[10];
|
const char *tokens[10];
|
||||||
|
@ -577,7 +582,7 @@ void COBImporter::ReadUnit_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
}
|
}
|
||||||
++splitter;
|
++splitter;
|
||||||
if (!splitter.match_start("Units ")) {
|
if (!splitter.match_start("Units ")) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `Units` line in `Unit` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `Units` line in `Unit` chunk ", nfo.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,12 +593,12 @@ void COBImporter::ReadUnit_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
const unsigned int t = strtoul10(splitter[1]);
|
const unsigned int t = strtoul10(splitter[1]);
|
||||||
|
|
||||||
nd->unit_scale = t >= sizeof(units) / sizeof(units[0]) ? (
|
nd->unit_scale = t >= sizeof(units) / sizeof(units[0]) ? (
|
||||||
ASSIMP_LOG_WARN_F(t, " is not a valid value for `Units` attribute in `Unit chunk` ", nfo.id), 1.f) :
|
ASSIMP_LOG_WARN(t, " is not a valid value for `Units` attribute in `Unit chunk` ", nfo.id), 1.f) :
|
||||||
units[t];
|
units[t];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ASSIMP_LOG_WARN_F("`Unit` chunk ", nfo.id, " is a child of ", nfo.parent_id, " which does not exist");
|
ASSIMP_LOG_WARN("`Unit` chunk ", nfo.id, " is a child of ", nfo.parent_id, " which does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -622,13 +627,13 @@ void COBImporter::ReadLght_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
} else if (splitter.match_start("Spot ")) {
|
} else if (splitter.match_start("Spot ")) {
|
||||||
msh.ltype = Light::SPOT;
|
msh.ltype = Light::SPOT;
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_WARN_F("Unknown kind of light source in `Lght` chunk ", nfo.id, " : ", *splitter);
|
ASSIMP_LOG_WARN("Unknown kind of light source in `Lght` chunk ", nfo.id, " : ", *splitter);
|
||||||
msh.ltype = Light::SPOT;
|
msh.ltype = Light::SPOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
++splitter;
|
++splitter;
|
||||||
if (!splitter.match_start("color ")) {
|
if (!splitter.match_start("color ")) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `color` line in `Lght` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `color` line in `Lght` chunk ", nfo.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *rgb = splitter[1];
|
const char *rgb = splitter[1];
|
||||||
|
@ -636,14 +641,14 @@ void COBImporter::ReadLght_Ascii(Scene &out, LineSplitter &splitter, const Chunk
|
||||||
|
|
||||||
SkipSpaces(&rgb);
|
SkipSpaces(&rgb);
|
||||||
if (strncmp(rgb, "cone angle", 10) != 0) {
|
if (strncmp(rgb, "cone angle", 10) != 0) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `cone angle` entity in `color` line in `Lght` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `cone angle` entity in `color` line in `Lght` chunk ", nfo.id);
|
||||||
}
|
}
|
||||||
SkipSpaces(rgb + 10, &rgb);
|
SkipSpaces(rgb + 10, &rgb);
|
||||||
msh.angle = fast_atof(&rgb);
|
msh.angle = fast_atof(&rgb);
|
||||||
|
|
||||||
SkipSpaces(&rgb);
|
SkipSpaces(&rgb);
|
||||||
if (strncmp(rgb, "inner angle", 11) != 0) {
|
if (strncmp(rgb, "inner angle", 11) != 0) {
|
||||||
ASSIMP_LOG_WARN_F("Expected `inner angle` entity in `color` line in `Lght` chunk ", nfo.id);
|
ASSIMP_LOG_WARN("Expected `inner angle` entity in `color` line in `Lght` chunk ", nfo.id);
|
||||||
}
|
}
|
||||||
SkipSpaces(rgb + 11, &rgb);
|
SkipSpaces(rgb + 11, &rgb);
|
||||||
msh.inner_angle = fast_atof(&rgb);
|
msh.inner_angle = fast_atof(&rgb);
|
||||||
|
@ -1027,7 +1032,7 @@ void COBImporter::ReadMat1_Binary(COB::Scene &out, StreamReaderLE &reader, const
|
||||||
mat.type = Material::METAL;
|
mat.type = Material::METAL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSIMP_LOG_ERROR_F("Unrecognized shader type in `Mat1` chunk with id ", nfo.id);
|
ASSIMP_LOG_ERROR("Unrecognized shader type in `Mat1` chunk with id ", nfo.id);
|
||||||
mat.type = Material::FLAT;
|
mat.type = Material::FLAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,7 +1047,7 @@ void COBImporter::ReadMat1_Binary(COB::Scene &out, StreamReaderLE &reader, const
|
||||||
mat.autofacet = Material::SMOOTH;
|
mat.autofacet = Material::SMOOTH;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ASSIMP_LOG_ERROR_F("Unrecognized faceting mode in `Mat1` chunk with id ", nfo.id);
|
ASSIMP_LOG_ERROR("Unrecognized faceting mode in `Mat1` chunk with id ", nfo.id);
|
||||||
mat.autofacet = Material::FACETED;
|
mat.autofacet = Material::FACETED;
|
||||||
}
|
}
|
||||||
mat.autofacet_angle = static_cast<float>(reader.GetI1());
|
mat.autofacet_angle = static_cast<float>(reader.GetI1());
|
||||||
|
@ -1170,13 +1175,13 @@ void COBImporter::ReadUnit_Binary(COB::Scene &out, StreamReaderLE &reader, const
|
||||||
if (nd->id == nfo.parent_id) {
|
if (nd->id == nfo.parent_id) {
|
||||||
const unsigned int t = reader.GetI2();
|
const unsigned int t = reader.GetI2();
|
||||||
nd->unit_scale = t >= sizeof(units) / sizeof(units[0]) ? (
|
nd->unit_scale = t >= sizeof(units) / sizeof(units[0]) ? (
|
||||||
ASSIMP_LOG_WARN_F(t, " is not a valid value for `Units` attribute in `Unit chunk` ", nfo.id), 1.f) :
|
ASSIMP_LOG_WARN(t, " is not a valid value for `Units` attribute in `Unit chunk` ", nfo.id), 1.f) :
|
||||||
units[t];
|
units[t];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ASSIMP_LOG_WARN_F("`Unit` chunk ", nfo.id, " is a child of ", nfo.parent_id, " which does not exist");
|
ASSIMP_LOG_WARN("`Unit` chunk ", nfo.id, " is a child of ", nfo.parent_id, " which does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ASSIMP_BUILD_NO_COB_IMPORTER
|
#endif // ASSIMP_BUILD_NO_COB_IMPORTER
|
||||||
|
|
|
@ -56,46 +56,44 @@ namespace Assimp {
|
||||||
|
|
||||||
// TinyFormatter.h
|
// TinyFormatter.h
|
||||||
namespace Formatter {
|
namespace Formatter {
|
||||||
template <typename T,typename TR, typename A> class basic_formatter;
|
template <typename T, typename TR, typename A>
|
||||||
|
class basic_formatter;
|
||||||
typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
|
typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
|
||||||
}
|
} // namespace Formatter
|
||||||
|
|
||||||
// COBScene.h
|
// COBScene.h
|
||||||
namespace COB {
|
namespace COB {
|
||||||
struct ChunkInfo;
|
struct ChunkInfo;
|
||||||
struct Node;
|
struct Node;
|
||||||
struct Scene;
|
struct Scene;
|
||||||
}
|
} // namespace COB
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
/** Importer class to load TrueSpace files (cob,scn) up to v6.
|
/** Importer class to load TrueSpace files (cob,scn) up to v6.
|
||||||
*
|
*
|
||||||
* Currently relatively limited, loads only ASCII files and needs more test coverage. */
|
* Currently relatively limited, loads only ASCII files and needs more test coverage. */
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
class COBImporter : public BaseImporter
|
class COBImporter : public BaseImporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
COBImporter();
|
COBImporter();
|
||||||
~COBImporter();
|
~COBImporter() override;
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// --------------------
|
||||||
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
const aiImporterDesc* GetInfo () const;
|
void SetupProperties(const Importer *pImp) override;
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void SetupProperties(const Importer* pImp);
|
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||||
IOSystem* pIOHandler);
|
IOSystem *pIOHandler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Prepend 'COB: ' and throw msg.*/
|
/** Prepend 'COB: ' and throw msg.*/
|
||||||
AI_WONT_RETURN static void ThrowException(const std::string &msg) AI_WONT_RETURN_SUFFIX;
|
AI_WONT_RETURN static void ThrowException(const std::string &msg) AI_WONT_RETURN_SUFFIX;
|
||||||
|
@ -113,7 +111,6 @@ private:
|
||||||
void ReadBinaryFile(COB::Scene &out, StreamReaderLE *stream);
|
void ReadBinaryFile(COB::Scene &out, StreamReaderLE *stream);
|
||||||
|
|
||||||
// Conversion to Assimp output format
|
// Conversion to Assimp output format
|
||||||
|
|
||||||
aiNode *BuildNodes(const COB::Node &root, const COB::Scene &scin, aiScene *fill);
|
aiNode *BuildNodes(const COB::Node &root, const COB::Scene &scin, aiScene *fill);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -122,7 +119,8 @@ private:
|
||||||
void UnsupportedChunk_Ascii(LineSplitter &splitter, const COB::ChunkInfo &nfo, const char *name);
|
void UnsupportedChunk_Ascii(LineSplitter &splitter, const COB::ChunkInfo &nfo, const char *name);
|
||||||
void ReadChunkInfo_Ascii(COB::ChunkInfo &out, const LineSplitter &splitter);
|
void ReadChunkInfo_Ascii(COB::ChunkInfo &out, const LineSplitter &splitter);
|
||||||
void ReadBasicNodeInfo_Ascii(COB::Node &msh, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
void ReadBasicNodeInfo_Ascii(COB::Node &msh, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
||||||
template <typename T> void ReadFloat3Tuple_Ascii(T& fill, const char** in);
|
template <typename T>
|
||||||
|
void ReadFloat3Tuple_Ascii(T &fill, const char **in);
|
||||||
|
|
||||||
void ReadPolH_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
void ReadPolH_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
||||||
void ReadBitM_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
void ReadBitM_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
||||||
|
@ -134,7 +132,6 @@ private:
|
||||||
void ReadUnit_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
void ReadUnit_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
||||||
void ReadChan_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
void ReadChan_Ascii(COB::Scene &out, LineSplitter &splitter, const COB::ChunkInfo &nfo);
|
||||||
|
|
||||||
|
|
||||||
// Binary file support
|
// Binary file support
|
||||||
|
|
||||||
void UnsupportedChunk_Binary(StreamReaderLE &reader, const COB::ChunkInfo &nfo, const char *name);
|
void UnsupportedChunk_Binary(StreamReaderLE &reader, const COB::ChunkInfo &nfo, const char *name);
|
||||||
|
@ -149,7 +146,6 @@ private:
|
||||||
void ReadGrou_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
|
void ReadGrou_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
|
||||||
void ReadUnit_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
|
void ReadUnit_Binary(COB::Scene &out, StreamReaderLE &reader, const COB::ChunkInfo &nfo);
|
||||||
|
|
||||||
|
|
||||||
}; // !class COBImporter
|
}; // !class COBImporter
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,16 +42,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
/** @file COBScene.h
|
/** @file COBScene.h
|
||||||
* @brief Utilities for the COB importer.
|
* @brief Utilities for the COB importer.
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef INCLUDED_AI_COB_SCENE_H
|
#ifndef INCLUDED_AI_COB_SCENE_H
|
||||||
#define INCLUDED_AI_COB_SCENE_H
|
#define INCLUDED_AI_COB_SCENE_H
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <deque>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include <assimp/BaseImporter.h>
|
#include <assimp/BaseImporter.h>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
|
|
||||||
|
#include <deque>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace COB {
|
namespace COB {
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ bool CSMImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ((checkSig || !extension.length()) && pIOHandler) {
|
if ((checkSig || !extension.length()) && pIOHandler) {
|
||||||
const char* tokens[] = {"$Filename"};
|
static const char * const tokens[] = {"$Filename"};
|
||||||
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -59,35 +58,32 @@ namespace Assimp {
|
||||||
* Link to file format specification:
|
* Link to file format specification:
|
||||||
* <max_8_dvd>\samples\Motion\Docs\CSM.rtf
|
* <max_8_dvd>\samples\Motion\Docs\CSM.rtf
|
||||||
*/
|
*/
|
||||||
class CSMImporter : public BaseImporter
|
class CSMImporter : public BaseImporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
CSMImporter();
|
CSMImporter();
|
||||||
~CSMImporter();
|
~CSMImporter() override;
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// -------------------------------------------------------------------
|
||||||
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
const aiImporterDesc* GetInfo () const;
|
void SetupProperties(const Importer *pImp) override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
|
||||||
void SetupProperties(const Importer* pImp);
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||||
IOSystem* pIOHandler);
|
IOSystem *pIOHandler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool noSkeletonMesh;
|
bool noSkeletonMesh;
|
||||||
|
|
||||||
}; // end of class CSMImporter
|
}; // end of class CSMImporter
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
||||||
#endif // AI_AC3DIMPORTER_H_INC
|
#endif // AI_AC3DIMPORTER_H_INC
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "ColladaParser.h"
|
#include "ColladaParser.h"
|
||||||
#include <assimp/ColladaMetaData.h>
|
#include <assimp/ColladaMetaData.h>
|
||||||
#include <assimp/CreateAnimMesh.h>
|
#include <assimp/CreateAnimMesh.h>
|
||||||
#include <assimp/Defines.h>
|
|
||||||
#include <assimp/ParsingUtils.h>
|
#include <assimp/ParsingUtils.h>
|
||||||
#include <assimp/SkeletonMeshBuilder.h>
|
#include <assimp/SkeletonMeshBuilder.h>
|
||||||
#include <assimp/ZipArchiveIOSystem.h>
|
#include <assimp/ZipArchiveIOSystem.h>
|
||||||
|
@ -75,7 +74,7 @@ static const aiImporterDesc desc = {
|
||||||
3,
|
3,
|
||||||
1,
|
1,
|
||||||
5,
|
5,
|
||||||
"dae zae"
|
"dae xml zae"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const float kMillisecondsFromSeconds = 1000.f;
|
static const float kMillisecondsFromSeconds = 1000.f;
|
||||||
|
@ -135,14 +134,15 @@ bool ColladaLoader::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool
|
||||||
|
|
||||||
// XML - too generic, we need to open the file and search for typical keywords
|
// XML - too generic, we need to open the file and search for typical keywords
|
||||||
if (extension == "xml" || !extension.length() || checkSig) {
|
if (extension == "xml" || !extension.length() || checkSig) {
|
||||||
/* If CanRead() is called in order to check whether we
|
// If CanRead() is called in order to check whether we
|
||||||
* support a specific file extension in general pIOHandler
|
// support a specific file extension in general pIOHandler
|
||||||
* might be nullptr and it's our duty to return true here.
|
// might be nullptr and it's our duty to return true here.
|
||||||
*/
|
if (nullptr == pIOHandler) {
|
||||||
if (!pIOHandler) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
static const char *tokens[] = { "<collada" };
|
static const char * const tokens[] = {
|
||||||
|
"<collada"
|
||||||
|
};
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ void ColladaLoader::ResolveNodeInstances(const ColladaParser &pParser, const Nod
|
||||||
nd = FindNode(pParser.mRootNode, nodeInst.mNode);
|
nd = FindNode(pParser.mRootNode, nodeInst.mNode);
|
||||||
}
|
}
|
||||||
if (nullptr == nd) {
|
if (nullptr == nd) {
|
||||||
ASSIMP_LOG_ERROR_F("Collada: Unable to resolve reference to instanced node ", nodeInst.mNode);
|
ASSIMP_LOG_ERROR("Collada: Unable to resolve reference to instanced node ", nodeInst.mNode);
|
||||||
} else {
|
} else {
|
||||||
// attach this node to the list of children
|
// attach this node to the list of children
|
||||||
resolved.push_back(nd);
|
resolved.push_back(nd);
|
||||||
|
@ -347,7 +347,7 @@ void ColladaLoader::BuildLightsForNode(const ColladaParser &pParser, const Node
|
||||||
// find the referred light
|
// find the referred light
|
||||||
ColladaParser::LightLibrary::const_iterator srcLightIt = pParser.mLightLibrary.find(lid.mLight);
|
ColladaParser::LightLibrary::const_iterator srcLightIt = pParser.mLightLibrary.find(lid.mLight);
|
||||||
if (srcLightIt == pParser.mLightLibrary.end()) {
|
if (srcLightIt == pParser.mLightLibrary.end()) {
|
||||||
ASSIMP_LOG_WARN_F("Collada: Unable to find light for ID \"", lid.mLight, "\". Skipping.");
|
ASSIMP_LOG_WARN("Collada: Unable to find light for ID \"", lid.mLight, "\". Skipping.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const Collada::Light *srcLight = &srcLightIt->second;
|
const Collada::Light *srcLight = &srcLightIt->second;
|
||||||
|
@ -412,7 +412,7 @@ void ColladaLoader::BuildCamerasForNode(const ColladaParser &pParser, const Node
|
||||||
// find the referred light
|
// find the referred light
|
||||||
ColladaParser::CameraLibrary::const_iterator srcCameraIt = pParser.mCameraLibrary.find(cid.mCamera);
|
ColladaParser::CameraLibrary::const_iterator srcCameraIt = pParser.mCameraLibrary.find(cid.mCamera);
|
||||||
if (srcCameraIt == pParser.mCameraLibrary.end()) {
|
if (srcCameraIt == pParser.mCameraLibrary.end()) {
|
||||||
ASSIMP_LOG_WARN_F("Collada: Unable to find camera for ID \"", cid.mCamera, "\". Skipping.");
|
ASSIMP_LOG_WARN("Collada: Unable to find camera for ID \"", cid.mCamera, "\". Skipping.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const Collada::Camera *srcCamera = &srcCameraIt->second;
|
const Collada::Camera *srcCamera = &srcCameraIt->second;
|
||||||
|
@ -486,7 +486,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nullptr == srcMesh) {
|
if (nullptr == srcMesh) {
|
||||||
ASSIMP_LOG_WARN_F("Collada: Unable to find geometry for ID \"", mid.mMeshOrController, "\". Skipping.");
|
ASSIMP_LOG_WARN("Collada: Unable to find geometry for ID \"", mid.mMeshOrController, "\". Skipping.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -511,7 +511,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
||||||
table = &meshMatIt->second;
|
table = &meshMatIt->second;
|
||||||
meshMaterial = table->mMatName;
|
meshMaterial = table->mMatName;
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_WARN_F("Collada: No material specified for subgroup <", submesh.mMaterial, "> in geometry <",
|
ASSIMP_LOG_WARN("Collada: No material specified for subgroup <", submesh.mMaterial, "> in geometry <",
|
||||||
mid.mMeshOrController, ">.");
|
mid.mMeshOrController, ">.");
|
||||||
if (!mid.mMaterials.empty()) {
|
if (!mid.mMaterials.empty()) {
|
||||||
meshMaterial = mid.mMaterials.begin()->second.mMatName;
|
meshMaterial = mid.mMaterials.begin()->second.mMatName;
|
||||||
|
@ -573,7 +573,7 @@ void ColladaLoader::BuildMeshesForNode(const ColladaParser &pParser, const Node
|
||||||
|
|
||||||
// now place all mesh references we gathered in the target node
|
// now place all mesh references we gathered in the target node
|
||||||
pTarget->mNumMeshes = static_cast<unsigned int>(newMeshRefs.size());
|
pTarget->mNumMeshes = static_cast<unsigned int>(newMeshRefs.size());
|
||||||
if (newMeshRefs.size()) {
|
if (!newMeshRefs.empty()) {
|
||||||
struct UIntTypeConverter {
|
struct UIntTypeConverter {
|
||||||
unsigned int operator()(const size_t &v) const {
|
unsigned int operator()(const size_t &v) const {
|
||||||
return static_cast<unsigned int>(v);
|
return static_cast<unsigned int>(v);
|
||||||
|
@ -619,6 +619,10 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc
|
||||||
dstMesh->mName = pSrcMesh->mId;
|
dstMesh->mName = pSrcMesh->mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pSrcMesh->mPositions.empty()) {
|
||||||
|
return dstMesh.release();
|
||||||
|
}
|
||||||
|
|
||||||
// count the vertices addressed by its faces
|
// count the vertices addressed by its faces
|
||||||
const size_t numVertices = std::accumulate(pSrcMesh->mFaceSize.begin() + pStartFace,
|
const size_t numVertices = std::accumulate(pSrcMesh->mFaceSize.begin() + pStartFace,
|
||||||
pSrcMesh->mFaceSize.begin() + pStartFace + pSubMesh.mNumFaces, size_t(0));
|
pSrcMesh->mFaceSize.begin() + pStartFace + pSubMesh.mNumFaces, size_t(0));
|
||||||
|
@ -883,7 +887,7 @@ aiMesh *ColladaLoader::CreateMesh(const ColladaParser &pParser, const Mesh *pSrc
|
||||||
if (nullptr != bnode) {
|
if (nullptr != bnode) {
|
||||||
bone->mName.Set(FindNameForNode(bnode));
|
bone->mName.Set(FindNameForNode(bnode));
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_WARN_F("ColladaLoader::CreateMesh(): could not find corresponding node for joint \"", bone->mName.data, "\".");
|
ASSIMP_LOG_WARN("ColladaLoader::CreateMesh(): could not find corresponding node for joint \"", bone->mName.data, "\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// and insert bone
|
// and insert bone
|
||||||
|
@ -1184,7 +1188,7 @@ void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParse
|
||||||
else if (subElement == "Z")
|
else if (subElement == "Z")
|
||||||
entry.mSubElement = 2;
|
entry.mSubElement = 2;
|
||||||
else
|
else
|
||||||
ASSIMP_LOG_WARN_F("Unknown anim subelement <", subElement, ">. Ignoring");
|
ASSIMP_LOG_WARN("Unknown anim subelement <", subElement, ">. Ignoring");
|
||||||
} else {
|
} else {
|
||||||
// no sub-element following, transformId is remaining string
|
// no sub-element following, transformId is remaining string
|
||||||
entry.mTransformId = srcChannel.mTarget.substr(slashPos + 1);
|
entry.mTransformId = srcChannel.mTarget.substr(slashPos + 1);
|
||||||
|
@ -1241,7 +1245,7 @@ void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParse
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
entry.mTargetId = entry.mTransformId;
|
entry.mTargetId = entry.mTransformId;
|
||||||
entry.mTransformId = "";
|
entry.mTransformId = std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.mChannel = &(*cit);
|
entry.mChannel = &(*cit);
|
||||||
|
@ -1682,7 +1686,7 @@ void ColladaLoader::BuildMaterials(ColladaParser &pParser, aiScene * /*pScene*/)
|
||||||
|
|
||||||
// store the material
|
// store the material
|
||||||
mMaterialIndexByName[matIt->first] = newMats.size();
|
mMaterialIndexByName[matIt->first] = newMats.size();
|
||||||
newMats.push_back(std::pair<Effect *, aiMaterial *>(&effect, mat));
|
newMats.emplace_back(&effect, mat);
|
||||||
}
|
}
|
||||||
// ScenePreprocessor generates a default material automatically if none is there.
|
// ScenePreprocessor generates a default material automatically if none is there.
|
||||||
// All further code here in this loader works well without a valid material so
|
// All further code here in this loader works well without a valid material so
|
||||||
|
@ -1711,7 +1715,7 @@ aiString ColladaLoader::FindFilenameForEffectTexture(const ColladaParser &pParse
|
||||||
// find the image referred by this name in the image library of the scene
|
// find the image referred by this name in the image library of the scene
|
||||||
ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find(name);
|
ColladaParser::ImageLibrary::const_iterator imIt = pParser.mImageLibrary.find(name);
|
||||||
if (imIt == pParser.mImageLibrary.end()) {
|
if (imIt == pParser.mImageLibrary.end()) {
|
||||||
ASSIMP_LOG_WARN_F("Collada: Unable to resolve effect texture entry \"", pName, "\", ended up at ID \"", name, "\".");
|
ASSIMP_LOG_WARN("Collada: Unable to resolve effect texture entry \"", pName, "\", ended up at ID \"", name, "\".");
|
||||||
|
|
||||||
//set default texture file name
|
//set default texture file name
|
||||||
result.Set(name + ".jpg");
|
result.Set(name + ".jpg");
|
||||||
|
|
|
@ -71,7 +71,7 @@ static void ReportWarning(const char *msg, ...) {
|
||||||
ai_assert(iLen > 0);
|
ai_assert(iLen > 0);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
ASSIMP_LOG_WARN_F("Validation warning: ", std::string(szBuffer, iLen));
|
ASSIMP_LOG_WARN("Validation warning: ", std::string(szBuffer, iLen));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool FindCommonKey(const std::string &collada_key, const MetaKeyPairVector &key_renaming, size_t &found_index) {
|
static bool FindCommonKey(const std::string &collada_key, const MetaKeyPairVector &key_renaming, size_t &found_index) {
|
||||||
|
@ -231,11 +231,7 @@ void ColladaParser::UriDecodePath(aiString &ss) {
|
||||||
|
|
||||||
// Maxon Cinema Collada Export writes "file:///C:\andsoon" with three slashes...
|
// Maxon Cinema Collada Export writes "file:///C:\andsoon" with three slashes...
|
||||||
// I need to filter it without destroying linux paths starting with "/somewhere"
|
// I need to filter it without destroying linux paths starting with "/somewhere"
|
||||||
#if defined(_MSC_VER)
|
|
||||||
if (ss.data[0] == '/' && isalpha((unsigned char)ss.data[1]) && ss.data[2] == ':') {
|
if (ss.data[0] == '/' && isalpha((unsigned char)ss.data[1]) && ss.data[2] == ':') {
|
||||||
#else
|
|
||||||
if (ss.data[0] == '/' && isalpha(ss.data[1]) && ss.data[2] == ':') {
|
|
||||||
#endif
|
|
||||||
--ss.length;
|
--ss.length;
|
||||||
::memmove(ss.data, ss.data + 1, ss.length);
|
::memmove(ss.data, ss.data + 1, ss.length);
|
||||||
ss.data[ss.length] = 0;
|
ss.data[ss.length] = 0;
|
||||||
|
@ -453,7 +449,7 @@ void ColladaParser::PostProcessRootAnimations() {
|
||||||
|
|
||||||
temp.mSubAnims.push_back(clip);
|
temp.mSubAnims.push_back(clip);
|
||||||
|
|
||||||
for (std::string animationID : it.second) {
|
for (const std::string &animationID : it.second) {
|
||||||
AnimationLibrary::iterator animation = mAnimationLibrary.find(animationID);
|
AnimationLibrary::iterator animation = mAnimationLibrary.find(animationID);
|
||||||
|
|
||||||
if (animation != mAnimationLibrary.end()) {
|
if (animation != mAnimationLibrary.end()) {
|
||||||
|
@ -623,12 +619,9 @@ void ColladaParser::ReadController(XmlNode &node, Collada::Controller &controlle
|
||||||
controller.mType = Skin;
|
controller.mType = Skin;
|
||||||
controller.mMethod = Normalized;
|
controller.mMethod = Normalized;
|
||||||
|
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
|
|
||||||
//for (XmlNode ¤tNode : node.children()) {
|
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
if (currentName == "morph") {
|
if (currentName == "morph") {
|
||||||
controller.mType = Morph;
|
controller.mType = Morph;
|
||||||
|
@ -921,7 +914,7 @@ void ColladaParser::ReadMaterial(XmlNode &node, Collada::Material &pMaterial) {
|
||||||
if (currentName == "instance_effect") {
|
if (currentName == "instance_effect") {
|
||||||
std::string url;
|
std::string url;
|
||||||
readUrlAttribute(currentNode, url);
|
readUrlAttribute(currentNode, url);
|
||||||
pMaterial.mEffect = url.c_str();
|
pMaterial.mEffect = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -929,8 +922,7 @@ void ColladaParser::ReadMaterial(XmlNode &node, Collada::Material &pMaterial) {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Reads a light entry into the given light
|
// Reads a light entry into the given light
|
||||||
void ColladaParser::ReadLight(XmlNode &node, Collada::Light &pLight) {
|
void ColladaParser::ReadLight(XmlNode &node, Collada::Light &pLight) {
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
|
@ -991,10 +983,8 @@ void ColladaParser::ReadLight(XmlNode &node, Collada::Light &pLight) {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Reads a camera entry into the given light
|
// Reads a camera entry into the given light
|
||||||
void ColladaParser::ReadCamera(XmlNode &node, Collada::Camera &camera) {
|
void ColladaParser::ReadCamera(XmlNode &node, Collada::Camera &camera) {
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
|
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
if (currentName == "orthographic") {
|
if (currentName == "orthographic") {
|
||||||
|
@ -1050,11 +1040,10 @@ void ColladaParser::ReadEffect(XmlNode &node, Collada::Effect &pEffect) {
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Reads an COMMON effect profile
|
// Reads an COMMON effect profile
|
||||||
void ColladaParser::ReadEffectProfileCommon(XmlNode &node, Collada::Effect &pEffect) {
|
void ColladaParser::ReadEffectProfileCommon(XmlNode &node, Collada::Effect &pEffect) {
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string currentName = currentNode.name();
|
||||||
if (currentName == "newparam") {
|
if (currentName == "newparam") {
|
||||||
// save ID
|
// save ID
|
||||||
std::string sid = currentNode.attribute("sid").as_string();
|
std::string sid = currentNode.attribute("sid").as_string();
|
||||||
|
@ -1145,10 +1134,9 @@ void ColladaParser::ReadSamplerProperties(XmlNode &node, Sampler &out) {
|
||||||
if (node.empty()) {
|
if (node.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
XmlNodeIterator xmlIt(node);
|
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
|
||||||
|
|
||||||
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
// MAYA extensions
|
// MAYA extensions
|
||||||
|
@ -1208,10 +1196,9 @@ void ColladaParser::ReadEffectColor(XmlNode &node, aiColor4D &pColor, Sampler &p
|
||||||
if (node.empty()) {
|
if (node.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
XmlNodeIterator xmlIt(node);
|
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
|
||||||
|
|
||||||
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
if (currentName == "color") {
|
if (currentName == "color") {
|
||||||
|
@ -1273,8 +1260,7 @@ void ColladaParser::ReadEffectParam(XmlNode &node, Collada::EffectParam &pParam)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
|
@ -1360,8 +1346,7 @@ void ColladaParser::ReadMesh(XmlNode &node, Mesh &pMesh) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
|
@ -1386,8 +1371,7 @@ void ColladaParser::ReadSource(XmlNode &node) {
|
||||||
|
|
||||||
std::string sourceID;
|
std::string sourceID;
|
||||||
XmlParser::getStdStrAttribute(node, "id", sourceID);
|
XmlParser::getStdStrAttribute(node, "id", sourceID);
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
|
@ -1449,9 +1433,8 @@ void ColladaParser::ReadDataArray(XmlNode &node) {
|
||||||
throw DeadlyImportError("Expected more values while reading float_array contents.");
|
throw DeadlyImportError("Expected more values while reading float_array contents.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ai_real value;
|
|
||||||
// read a number
|
// read a number
|
||||||
//SkipSpacesAndLineEnd(&content);
|
ai_real value;
|
||||||
content = fast_atoreal_move<ai_real>(content, value);
|
content = fast_atoreal_move<ai_real>(content, value);
|
||||||
data.mValues.push_back(value);
|
data.mValues.push_back(value);
|
||||||
// skip whitespace after it
|
// skip whitespace after it
|
||||||
|
@ -1490,8 +1473,7 @@ void ColladaParser::ReadAccessor(XmlNode &node, const std::string &pID) {
|
||||||
acc.mSource = source.c_str() + 1; // ignore the leading '#'
|
acc.mSource = source.c_str() + 1; // ignore the leading '#'
|
||||||
acc.mSize = 0; // gets incremented with every param
|
acc.mSize = 0; // gets incremented with every param
|
||||||
|
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
|
@ -1500,11 +1482,10 @@ void ColladaParser::ReadAccessor(XmlNode &node, const std::string &pID) {
|
||||||
std::string name;
|
std::string name;
|
||||||
if (XmlParser::hasAttribute(currentNode, "name")) {
|
if (XmlParser::hasAttribute(currentNode, "name")) {
|
||||||
XmlParser::getStdStrAttribute(currentNode, "name", name);
|
XmlParser::getStdStrAttribute(currentNode, "name", name);
|
||||||
//name = mReader->getAttributeValue(attrName);
|
|
||||||
|
|
||||||
// analyse for common type components and store it's sub-offset in the corresponding field
|
// analyse for common type components and store it's sub-offset in the corresponding field
|
||||||
|
|
||||||
/* Cartesian coordinates */
|
// Cartesian coordinates
|
||||||
if (name == "X")
|
if (name == "X")
|
||||||
acc.mSubOffset[0] = acc.mParams.size();
|
acc.mSubOffset[0] = acc.mParams.size();
|
||||||
else if (name == "Y")
|
else if (name == "Y")
|
||||||
|
@ -1608,8 +1589,7 @@ void ColladaParser::ReadIndexData(XmlNode &node, Mesh &pMesh) {
|
||||||
ai_assert(primType != Prim_Invalid);
|
ai_assert(primType != Prim_Invalid);
|
||||||
|
|
||||||
// also a number of <input> elements, but in addition a <p> primitive collection and probably index counts for all primitives
|
// also a number of <input> elements, but in addition a <p> primitive collection and probably index counts for all primitives
|
||||||
XmlNodeIterator xmlIt(node);
|
XmlNodeIterator xmlIt(node, XmlNodeIterator::PreOrderMode);
|
||||||
xmlIt.collectChildrenPreOrder(node);
|
|
||||||
XmlNode currentNode;
|
XmlNode currentNode;
|
||||||
while (xmlIt.getNext(currentNode)) {
|
while (xmlIt.getNext(currentNode)) {
|
||||||
const std::string ¤tName = currentNode.name();
|
const std::string ¤tName = currentNode.name();
|
||||||
|
@ -1686,11 +1666,8 @@ void ColladaParser::ReadInputChannel(XmlNode &node, std::vector<InputChannel> &p
|
||||||
|
|
||||||
// read set if texture coordinates
|
// read set if texture coordinates
|
||||||
if (channel.mType == IT_Texcoord || channel.mType == IT_Color) {
|
if (channel.mType == IT_Texcoord || channel.mType == IT_Color) {
|
||||||
int attrSet = -1;
|
unsigned int attrSet = 0;
|
||||||
if (XmlParser::hasAttribute(node, "set")) {
|
if (XmlParser::getUIntAttribute(node, "set", attrSet))
|
||||||
XmlParser::getIntAttribute(node, "set", attrSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.mIndex = attrSet;
|
channel.mIndex = attrSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2182,10 +2159,10 @@ void ColladaParser::ReadNodeTransformation(XmlNode &node, Node *pNode, Transform
|
||||||
|
|
||||||
// read as many parameters and store in the transformation
|
// read as many parameters and store in the transformation
|
||||||
for (unsigned int a = 0; a < sNumParameters[pType]; a++) {
|
for (unsigned int a = 0; a < sNumParameters[pType]; a++) {
|
||||||
|
// skip whitespace before the number
|
||||||
|
SkipSpacesAndLineEnd(&content);
|
||||||
// read a number
|
// read a number
|
||||||
content = fast_atoreal_move<ai_real>(content, tf.f[a]);
|
content = fast_atoreal_move<ai_real>(content, tf.f[a]);
|
||||||
// skip whitespace after it
|
|
||||||
SkipSpacesAndLineEnd(&content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// place the transformation at the queue of the node
|
// place the transformation at the queue of the node
|
||||||
|
@ -2227,8 +2204,8 @@ void ColladaParser::ReadMaterialVertexInputBinding(XmlNode &node, Collada::Seman
|
||||||
|
|
||||||
void ColladaParser::ReadEmbeddedTextures(ZipArchiveIOSystem &zip_archive) {
|
void ColladaParser::ReadEmbeddedTextures(ZipArchiveIOSystem &zip_archive) {
|
||||||
// Attempt to load any undefined Collada::Image in ImageLibrary
|
// Attempt to load any undefined Collada::Image in ImageLibrary
|
||||||
for (ImageLibrary::iterator it = mImageLibrary.begin(); it != mImageLibrary.end(); ++it) {
|
for (auto & it : mImageLibrary) {
|
||||||
Collada::Image &image = (*it).second;
|
Collada::Image &image = it.second;
|
||||||
|
|
||||||
if (image.mImageData.empty()) {
|
if (image.mImageData.empty()) {
|
||||||
std::unique_ptr<IOStream> image_file(zip_archive.Open(image.mFileName.c_str()));
|
std::unique_ptr<IOStream> image_file(zip_archive.Open(image.mFileName.c_str()));
|
||||||
|
@ -2400,7 +2377,7 @@ Collada::InputType ColladaParser::GetTypeForSemantic(const std::string &semantic
|
||||||
else if (semantic == "TANGENT" || semantic == "TEXTANGENT")
|
else if (semantic == "TANGENT" || semantic == "TEXTANGENT")
|
||||||
return IT_Tangent;
|
return IT_Tangent;
|
||||||
|
|
||||||
ASSIMP_LOG_WARN_F("Unknown vertex input type \"", semantic, "\". Ignoring.");
|
ASSIMP_LOG_WARN("Unknown vertex input type \"", semantic, "\". Ignoring.");
|
||||||
return IT_Invalid;
|
return IT_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
* @brief Defines the parser helper class for the collada loader
|
* @brief Defines the parser helper class for the collada loader
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
#ifndef AI_COLLADAPARSER_H_INC
|
#ifndef AI_COLLADAPARSER_H_INC
|
||||||
#define AI_COLLADAPARSER_H_INC
|
#define AI_COLLADAPARSER_H_INC
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ public:
|
||||||
for(;splitter->length() && splitter->at(0) != '}'; splitter++, cnt++);
|
for(;splitter->length() && splitter->at(0) != '}'; splitter++, cnt++);
|
||||||
|
|
||||||
splitter++;
|
splitter++;
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG((Formatter::format("DXF: skipped over control group ("),cnt," lines)"));
|
ASSIMP_LOG_VERBOSE_DEBUG("DXF: skipped over control group (",cnt," lines)");
|
||||||
}
|
}
|
||||||
} catch(std::logic_error&) {
|
} catch(std::logic_error&) {
|
||||||
ai_assert(!splitter);
|
ai_assert(!splitter);
|
||||||
|
|
|
@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -63,11 +61,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
// AutoCAD Binary DXF<CR><LF><SUB><NULL>
|
// AutoCAD Binary DXF<CR><LF><SUB><NULL>
|
||||||
const std::string AI_DXF_BINARY_IDENT = std::string("AutoCAD Binary DXF\r\n\x1a\0");
|
static constexpr char AI_DXF_BINARY_IDENT[] = "AutoCAD Binary DXF\r\n\x1a";
|
||||||
const size_t AI_DXF_BINARY_IDENT_LEN = 24u;
|
static constexpr size_t AI_DXF_BINARY_IDENT_LEN = sizeof AI_DXF_BINARY_IDENT;
|
||||||
|
|
||||||
// default vertex color that all uncolored vertices will receive
|
// default vertex color that all uncolored vertices will receive
|
||||||
const aiColor4D AI_DXF_DEFAULT_COLOR(aiColor4D(0.6f, 0.6f, 0.6f, 0.6f));
|
static const aiColor4D AI_DXF_DEFAULT_COLOR(aiColor4D(0.6f, 0.6f, 0.6f, 0.6f));
|
||||||
|
|
||||||
// color indices for DXF - 16 are supported, the table is
|
// color indices for DXF - 16 are supported, the table is
|
||||||
// taken directly from the DXF spec.
|
// taken directly from the DXF spec.
|
||||||
|
@ -132,8 +130,8 @@ bool DXFImporter::CanRead( const std::string& filename, IOSystem* pIOHandler, bo
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( extension.empty() || checkSig ) {
|
if ( extension.empty() || checkSig ) {
|
||||||
const char *pTokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" };
|
static const char * const pTokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" };
|
||||||
return BaseImporter::SearchFileHeaderForToken(pIOHandler, filename, pTokens, 4, 32 );
|
return SearchFileHeaderForToken(pIOHandler, filename, pTokens, 4, 32 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -156,10 +154,10 @@ void DXFImporter::InternReadFile( const std::string& filename, aiScene* pScene,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether this is a binary DXF file - we can't read binary DXF files :-(
|
// Check whether this is a binary DXF file - we can't read binary DXF files :-(
|
||||||
char buff[AI_DXF_BINARY_IDENT_LEN+1] = {0};
|
char buff[AI_DXF_BINARY_IDENT_LEN] = {0};
|
||||||
file->Read(buff,AI_DXF_BINARY_IDENT_LEN,1);
|
file->Read(buff,AI_DXF_BINARY_IDENT_LEN,1);
|
||||||
|
|
||||||
if (0 == strncmp(AI_DXF_BINARY_IDENT.c_str(),buff,AI_DXF_BINARY_IDENT_LEN)) {
|
if (0 == memcmp(AI_DXF_BINARY_IDENT,buff,AI_DXF_BINARY_IDENT_LEN)) {
|
||||||
throw DeadlyImportError("DXF: Binary files are not supported at the moment");
|
throw DeadlyImportError("DXF: Binary files are not supported at the moment");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +200,7 @@ void DXFImporter::InternReadFile( const std::string& filename, aiScene* pScene,
|
||||||
|
|
||||||
// comments
|
// comments
|
||||||
else if (reader.Is(999)) {
|
else if (reader.Is(999)) {
|
||||||
ASSIMP_LOG_INFO_F("DXF Comment: ", reader.Value());
|
ASSIMP_LOG_INFO("DXF Comment: ", reader.Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't read past the official EOF sign
|
// don't read past the official EOF sign
|
||||||
|
@ -241,7 +239,7 @@ void DXFImporter::ConvertMeshes(aiScene* pScene, DXF::FileData& output) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG_F("DXF: Unexpanded polycount is ", icount, ", vertex count is ", vcount);
|
ASSIMP_LOG_VERBOSE_DEBUG("DXF: Unexpanded polycount is ", icount, ", vertex count is ", vcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! output.blocks.size() ) {
|
if (! output.blocks.size() ) {
|
||||||
|
@ -372,7 +370,7 @@ void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& bloc
|
||||||
// first check if the referenced blocks exists ...
|
// first check if the referenced blocks exists ...
|
||||||
const DXF::BlockMap::const_iterator it = blocks_by_name.find(insert.name);
|
const DXF::BlockMap::const_iterator it = blocks_by_name.find(insert.name);
|
||||||
if (it == blocks_by_name.end()) {
|
if (it == blocks_by_name.end()) {
|
||||||
ASSIMP_LOG_ERROR_F("DXF: Failed to resolve block reference: ", insert.name,"; skipping" );
|
ASSIMP_LOG_ERROR("DXF: Failed to resolve block reference: ", insert.name,"; skipping" );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +471,7 @@ void DXFImporter::ParseBlocks(DXF::LineReader& reader, DXF::FileData& output) {
|
||||||
++reader;
|
++reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG_F("DXF: got ", output.blocks.size()," entries in BLOCKS" );
|
ASSIMP_LOG_VERBOSE_DEBUG("DXF: got ", output.blocks.size()," entries in BLOCKS" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -549,7 +547,7 @@ void DXFImporter::ParseEntities(DXF::LineReader& reader, DXF::FileData& output)
|
||||||
++reader;
|
++reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG_F( "DXF: got ", block.lines.size()," polylines and ", block.insertions.size(),
|
ASSIMP_LOG_VERBOSE_DEBUG( "DXF: got ", block.lines.size()," polylines and ", block.insertions.size(),
|
||||||
" inserted blocks in ENTITIES" );
|
" inserted blocks in ENTITIES" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,7 +652,7 @@ void DXFImporter::ParsePolyLine(DXF::LineReader& reader, DXF::FileData& output)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (vguess && line.positions.size() != vguess) {
|
if (vguess && line.positions.size() != vguess) {
|
||||||
ASSIMP_LOG_WARN_F("DXF: unexpected vertex count in polymesh: ",
|
ASSIMP_LOG_WARN("DXF: unexpected vertex count in polymesh: ",
|
||||||
line.positions.size(),", expected ", vguess );
|
line.positions.size(),", expected ", vguess );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,7 +668,7 @@ void DXFImporter::ParsePolyLine(DXF::LineReader& reader, DXF::FileData& output)
|
||||||
// to set the 71 and 72 fields, respectively, to valid values.
|
// to set the 71 and 72 fields, respectively, to valid values.
|
||||||
// So just fire a warning.
|
// So just fire a warning.
|
||||||
if (iguess && line.counts.size() != iguess) {
|
if (iguess && line.counts.size() != iguess) {
|
||||||
ASSIMP_LOG_WARN_F( "DXF: unexpected face count in polymesh: ", line.counts.size(),", expected ", iguess );
|
ASSIMP_LOG_WARN( "DXF: unexpected face count in polymesh: ", line.counts.size(),", expected ", iguess );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!line.indices.size() && !line.counts.size()) {
|
else if (!line.indices.size() && !line.counts.size()) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
/** @file DXFLoader.h
|
/** @file DXFLoader.h
|
||||||
* @brief Declaration of the .dxf importer class.
|
* @brief Declaration of the .dxf importer class.
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef AI_DXFLOADER_H_INCLUDED
|
#ifndef AI_DXFLOADER_H_INCLUDED
|
||||||
#define AI_DXFLOADER_H_INCLUDED
|
#define AI_DXFLOADER_H_INCLUDED
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ namespace DXF {
|
||||||
struct Block;
|
struct Block;
|
||||||
struct InsertBlock;
|
struct InsertBlock;
|
||||||
|
|
||||||
typedef std::map<std::string, const DXF::Block*> BlockMap;
|
using BlockMap = std::map<std::string, const DXF::Block*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@ -69,29 +69,26 @@ namespace DXF {
|
||||||
class DXFImporter : public BaseImporter {
|
class DXFImporter : public BaseImporter {
|
||||||
public:
|
public:
|
||||||
DXFImporter();
|
DXFImporter();
|
||||||
~DXFImporter();
|
~DXFImporter() override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns whether the class can handle the format of the given file.
|
/** Returns whether the class can handle the format of the given file.
|
||||||
* See BaseImporter::CanRead() for details. */
|
* See BaseImporter::CanRead() for details. */
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Return importer meta information.
|
/** Return importer meta information.
|
||||||
* See #BaseImporter::GetInfo for the details*/
|
* See #BaseImporter::GetInfo for the details*/
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc* GetInfo () const override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Imports the given file into the given scene structure.
|
/** Imports the given file into the given scene structure.
|
||||||
* See BaseImporter::InternReadFile() for details */
|
* See BaseImporter::InternReadFile() for details */
|
||||||
void InternReadFile( const std::string& pFile,
|
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) override;
|
||||||
aiScene* pScene,
|
|
||||||
IOSystem* pIOHandler);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
void SkipSection(DXF::LineReader& reader);
|
void SkipSection(DXF::LineReader& reader);
|
||||||
|
|
||||||
|
|
|
@ -459,7 +459,7 @@ void TokenizeBinary(TokenList& output_tokens, const char* input, size_t length)
|
||||||
/*Result ignored*/ ReadByte(input, cursor, input + length);
|
/*Result ignored*/ ReadByte(input, cursor, input + length);
|
||||||
/*Result ignored*/ ReadByte(input, cursor, input + length);
|
/*Result ignored*/ ReadByte(input, cursor, input + length);
|
||||||
const uint32_t version = ReadWord(input, cursor, input + length);
|
const uint32_t version = ReadWord(input, cursor, input + length);
|
||||||
ASSIMP_LOG_DEBUG_F("FBX version: ", version);
|
ASSIMP_LOG_DEBUG("FBX version: ", version);
|
||||||
const bool is64bits = version >= 7500;
|
const bool is64bits = version >= 7500;
|
||||||
const char *end = input + length;
|
const char *end = input + length;
|
||||||
try
|
try
|
||||||
|
|
|
@ -62,16 +62,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifdef ASSIMP_FBX_USE_UNORDERED_MULTIMAP
|
#ifdef ASSIMP_FBX_USE_UNORDERED_MULTIMAP
|
||||||
# include <unordered_map>
|
# include <unordered_map>
|
||||||
# include <unordered_set>
|
# include <unordered_set>
|
||||||
# if _MSC_VER > 1600
|
# if defined(_MSC_VER) && _MSC_VER <= 1600
|
||||||
# define fbx_unordered_map unordered_map
|
|
||||||
# define fbx_unordered_multimap unordered_multimap
|
|
||||||
# define fbx_unordered_set unordered_set
|
|
||||||
# define fbx_unordered_multiset unordered_multiset
|
|
||||||
# else
|
|
||||||
# define fbx_unordered_map tr1::unordered_map
|
# define fbx_unordered_map tr1::unordered_map
|
||||||
# define fbx_unordered_multimap tr1::unordered_multimap
|
# define fbx_unordered_multimap tr1::unordered_multimap
|
||||||
# define fbx_unordered_set tr1::unordered_set
|
# define fbx_unordered_set tr1::unordered_set
|
||||||
# define fbx_unordered_multiset tr1::unordered_multiset
|
# define fbx_unordered_multiset tr1::unordered_multiset
|
||||||
|
# else
|
||||||
|
# define fbx_unordered_map unordered_map
|
||||||
|
# define fbx_unordered_multimap unordered_multimap
|
||||||
|
# define fbx_unordered_set unordered_set
|
||||||
|
# define fbx_unordered_multiset unordered_multiset
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -811,7 +811,7 @@ bool FBXConverter::GenerateTransformationNodeChain(const Model &model, const std
|
||||||
// we need to generate a full node chain to accommodate for assimp's
|
// we need to generate a full node chain to accommodate for assimp's
|
||||||
// lack to express pivots and offsets.
|
// lack to express pivots and offsets.
|
||||||
if ((chainBits & chainMaskComplex) && doc.Settings().preservePivots) {
|
if ((chainBits & chainMaskComplex) && doc.Settings().preservePivots) {
|
||||||
FBXImporter::LogInfo("generating full transformation chain for node: " + name);
|
FBXImporter::LogInfo("generating full transformation chain for node: ", name);
|
||||||
|
|
||||||
// query the anim_chain_bits dictionary to find out which chain elements
|
// query the anim_chain_bits dictionary to find out which chain elements
|
||||||
// have associated node animation channels. These can not be dropped
|
// have associated node animation channels. These can not be dropped
|
||||||
|
@ -917,8 +917,10 @@ void FBXConverter::ConvertModel(const Model &model, aiNode *parent, aiNode *root
|
||||||
} else if (line) {
|
} else if (line) {
|
||||||
const std::vector<unsigned int> &indices = ConvertLine(*line, root_node);
|
const std::vector<unsigned int> &indices = ConvertLine(*line, root_node);
|
||||||
std::copy(indices.begin(), indices.end(), std::back_inserter(meshes));
|
std::copy(indices.begin(), indices.end(), std::back_inserter(meshes));
|
||||||
|
} else if (geo) {
|
||||||
|
FBXImporter::LogWarn("ignoring unrecognized geometry: ", geo->Name());
|
||||||
} else {
|
} else {
|
||||||
FBXImporter::LogWarn("ignoring unrecognized geometry: " + geo->Name());
|
FBXImporter::LogWarn("skipping null geometry");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,7 +946,7 @@ FBXConverter::ConvertMesh(const MeshGeometry &mesh, const Model &model, aiNode *
|
||||||
const std::vector<aiVector3D> &vertices = mesh.GetVertices();
|
const std::vector<aiVector3D> &vertices = mesh.GetVertices();
|
||||||
const std::vector<unsigned int> &faces = mesh.GetFaceIndexCounts();
|
const std::vector<unsigned int> &faces = mesh.GetFaceIndexCounts();
|
||||||
if (vertices.empty() || faces.empty()) {
|
if (vertices.empty() || faces.empty()) {
|
||||||
FBXImporter::LogWarn("ignoring empty geometry: " + mesh.Name());
|
FBXImporter::LogWarn("ignoring empty geometry: ", mesh.Name());
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -971,7 +973,7 @@ std::vector<unsigned int> FBXConverter::ConvertLine(const LineGeometry &line, ai
|
||||||
const std::vector<aiVector3D> &vertices = line.GetVertices();
|
const std::vector<aiVector3D> &vertices = line.GetVertices();
|
||||||
const std::vector<int> &indices = line.GetIndices();
|
const std::vector<int> &indices = line.GetIndices();
|
||||||
if (vertices.empty() || indices.empty()) {
|
if (vertices.empty() || indices.empty()) {
|
||||||
FBXImporter::LogWarn("ignoring empty line: " + line.Name());
|
FBXImporter::LogWarn("ignoring empty line: ", line.Name());
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1126,6 +1128,8 @@ unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, c
|
||||||
*out_uv++ = aiVector3D(v.x, v.y, 0.0f);
|
*out_uv++ = aiVector3D(v.x, v.y, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out_mesh->mTextureCoordsNames[i] = mesh.GetTextureCoordChannelName(i);
|
||||||
|
|
||||||
out_mesh->mNumUVComponents[i] = 2;
|
out_mesh->mNumUVComponents[i] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1542,10 +1546,10 @@ void FBXConverter::ConvertCluster(std::vector<aiBone *> &local_mesh_bones, const
|
||||||
aiBone *bone = nullptr;
|
aiBone *bone = nullptr;
|
||||||
|
|
||||||
if (bone_map.count(deformer_name)) {
|
if (bone_map.count(deformer_name)) {
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG_F("retrieved bone from lookup ", bone_name.C_Str(), ". Deformer:", deformer_name);
|
ASSIMP_LOG_VERBOSE_DEBUG("retrieved bone from lookup ", bone_name.C_Str(), ". Deformer:", deformer_name);
|
||||||
bone = bone_map[deformer_name];
|
bone = bone_map[deformer_name];
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG_F("created new bone ", bone_name.C_Str(), ". Deformer: ", deformer_name);
|
ASSIMP_LOG_VERBOSE_DEBUG("created new bone ", bone_name.C_Str(), ". Deformer: ", deformer_name);
|
||||||
bone = new aiBone();
|
bone = new aiBone();
|
||||||
bone->mName = bone_name;
|
bone->mName = bone_name;
|
||||||
|
|
||||||
|
@ -1591,7 +1595,7 @@ void FBXConverter::ConvertCluster(std::vector<aiBone *> &local_mesh_bones, const
|
||||||
bone_map.insert(std::pair<const std::string, aiBone *>(deformer_name, bone));
|
bone_map.insert(std::pair<const std::string, aiBone *>(deformer_name, bone));
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIMP_LOG_DEBUG_F("bone research: Indicies size: ", out_indices.size());
|
ASSIMP_LOG_DEBUG("bone research: Indicies size: ", out_indices.size());
|
||||||
|
|
||||||
// lookup must be populated in case something goes wrong
|
// lookup must be populated in case something goes wrong
|
||||||
// this also allocates bones to mesh instance outside
|
// this also allocates bones to mesh instance outside
|
||||||
|
@ -1764,6 +1768,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const TextureMap
|
||||||
// XXX handle all kinds of UV transformations
|
// XXX handle all kinds of UV transformations
|
||||||
uvTrafo.mScaling = tex->UVScaling();
|
uvTrafo.mScaling = tex->UVScaling();
|
||||||
uvTrafo.mTranslation = tex->UVTranslation();
|
uvTrafo.mTranslation = tex->UVTranslation();
|
||||||
|
uvTrafo.mRotation = tex->UVRotation();
|
||||||
out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, 0);
|
out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, 0);
|
||||||
|
|
||||||
const PropertyTable &props = tex->Props();
|
const PropertyTable &props = tex->Props();
|
||||||
|
@ -1815,14 +1820,14 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const TextureMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material");
|
FBXImporter::LogWarn("did not find UV channel named ", uvSet, " in a mesh using this material");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
uvIndex = index;
|
uvIndex = index;
|
||||||
} else {
|
} else {
|
||||||
FBXImporter::LogWarn("the UV channel named " + uvSet +
|
FBXImporter::LogWarn("the UV channel named ", uvSet,
|
||||||
" appears at different positions in meshes, results will be wrong");
|
" appears at different positions in meshes, results will be wrong");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1839,7 +1844,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const TextureMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material");
|
FBXImporter::LogWarn("did not find UV channel named ", uvSet, " in a mesh using this material");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
|
@ -1848,7 +1853,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const TextureMap
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
FBXImporter::LogWarn("failed to resolve UV channel " + uvSet + ", using first UV channel");
|
FBXImporter::LogWarn("failed to resolve UV channel ", uvSet, ", using first UV channel");
|
||||||
uvIndex = 0;
|
uvIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1883,6 +1888,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const LayeredTex
|
||||||
// XXX handle all kinds of UV transformations
|
// XXX handle all kinds of UV transformations
|
||||||
uvTrafo.mScaling = tex->UVScaling();
|
uvTrafo.mScaling = tex->UVScaling();
|
||||||
uvTrafo.mTranslation = tex->UVTranslation();
|
uvTrafo.mTranslation = tex->UVTranslation();
|
||||||
|
uvTrafo.mRotation = tex->UVRotation();
|
||||||
out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, texIndex);
|
out_mat->AddProperty(&uvTrafo, 1, _AI_MATKEY_UVTRANSFORM_BASE, target, texIndex);
|
||||||
|
|
||||||
const PropertyTable &props = tex->Props();
|
const PropertyTable &props = tex->Props();
|
||||||
|
@ -1934,14 +1940,14 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const LayeredTex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material");
|
FBXImporter::LogWarn("did not find UV channel named ", uvSet, " in a mesh using this material");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
uvIndex = index;
|
uvIndex = index;
|
||||||
} else {
|
} else {
|
||||||
FBXImporter::LogWarn("the UV channel named " + uvSet +
|
FBXImporter::LogWarn("the UV channel named ", uvSet,
|
||||||
" appears at different positions in meshes, results will be wrong");
|
" appears at different positions in meshes, results will be wrong");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1958,7 +1964,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const LayeredTex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material");
|
FBXImporter::LogWarn("did not find UV channel named ", uvSet, " in a mesh using this material");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
|
@ -1967,7 +1973,7 @@ void FBXConverter::TrySetTextureProperties(aiMaterial *out_mat, const LayeredTex
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
FBXImporter::LogWarn("failed to resolve UV channel " + uvSet + ", using first UV channel");
|
FBXImporter::LogWarn("failed to resolve UV channel ", uvSet, ", using first UV channel");
|
||||||
uvIndex = 0;
|
uvIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2126,6 +2132,11 @@ void FBXConverter::SetShadingPropertiesCommon(aiMaterial *out_mat, const Propert
|
||||||
const aiColor3D &Emissive = GetColorPropertyFromMaterial(props, "Emissive", ok);
|
const aiColor3D &Emissive = GetColorPropertyFromMaterial(props, "Emissive", ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
out_mat->AddProperty(&Emissive, 1, AI_MATKEY_COLOR_EMISSIVE);
|
out_mat->AddProperty(&Emissive, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||||
|
} else {
|
||||||
|
const aiColor3D &emissiveColor = GetColorProperty(props, "Maya|emissive", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&emissiveColor, 1, AI_MATKEY_COLOR_EMISSIVE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const aiColor3D &Ambient = GetColorPropertyFromMaterial(props, "Ambient", ok);
|
const aiColor3D &Ambient = GetColorPropertyFromMaterial(props, "Ambient", ok);
|
||||||
|
@ -2207,6 +2218,52 @@ void FBXConverter::SetShadingPropertiesCommon(aiMaterial *out_mat, const Propert
|
||||||
if (ok) {
|
if (ok) {
|
||||||
out_mat->AddProperty(&DispFactor, 1, "$mat.displacementscaling", 0, 0);
|
out_mat->AddProperty(&DispFactor, 1, "$mat.displacementscaling", 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PBR material information
|
||||||
|
const aiColor3D &baseColor = GetColorProperty(props, "Maya|base_color", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&baseColor, 1, AI_MATKEY_BASE_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float useColorMap = PropertyGet<float>(props, "Maya|use_color_map", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&useColorMap, 1, AI_MATKEY_USE_COLOR_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float useMetallicMap = PropertyGet<float>(props, "Maya|use_metallic_map", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&useMetallicMap, 1, AI_MATKEY_USE_METALLIC_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float metallicFactor = PropertyGet<float>(props, "Maya|metallic", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&metallicFactor, 1, AI_MATKEY_METALLIC_FACTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float useRoughnessMap = PropertyGet<float>(props, "Maya|use_roughness_map", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&useRoughnessMap, 1, AI_MATKEY_USE_ROUGHNESS_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float roughnessFactor = PropertyGet<float>(props, "Maya|roughness", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&roughnessFactor, 1, AI_MATKEY_ROUGHNESS_FACTOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float useEmissiveMap = PropertyGet<float>(props, "Maya|use_emissive_map", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&useEmissiveMap, 1, AI_MATKEY_USE_EMISSIVE_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float emissiveIntensity = PropertyGet<float>(props, "Maya|emissive_intensity", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&emissiveIntensity, 1, AI_MATKEY_EMISSIVE_INTENSITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float useAOMap = PropertyGet<float>(props, "Maya|use_ao_map", ok);
|
||||||
|
if (ok) {
|
||||||
|
out_mat->AddProperty(&useAOMap, 1, AI_MATKEY_USE_AO_MAP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTable &props, const TextureMap &_textures, const MeshGeometry *const mesh) {
|
void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTable &props, const TextureMap &_textures, const MeshGeometry *const mesh) {
|
||||||
|
@ -2271,6 +2328,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTa
|
||||||
// XXX handle all kinds of UV transformations
|
// XXX handle all kinds of UV transformations
|
||||||
uvTrafo.mScaling = tex->UVScaling();
|
uvTrafo.mScaling = tex->UVScaling();
|
||||||
uvTrafo.mTranslation = tex->UVTranslation();
|
uvTrafo.mTranslation = tex->UVTranslation();
|
||||||
|
uvTrafo.mRotation = tex->UVRotation();
|
||||||
out_mat->AddProperty(&uvTrafo, 1, (name + "|uvtrafo").c_str(), aiTextureType_UNKNOWN, 0);
|
out_mat->AddProperty(&uvTrafo, 1, (name + "|uvtrafo").c_str(), aiTextureType_UNKNOWN, 0);
|
||||||
|
|
||||||
int uvIndex = 0;
|
int uvIndex = 0;
|
||||||
|
@ -2319,14 +2377,14 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material");
|
FBXImporter::LogWarn("did not find UV channel named ", uvSet, " in a mesh using this material");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
uvIndex = index;
|
uvIndex = index;
|
||||||
} else {
|
} else {
|
||||||
FBXImporter::LogWarn("the UV channel named " + uvSet + " appears at different positions in meshes, results will be wrong");
|
FBXImporter::LogWarn("the UV channel named ", uvSet, " appears at different positions in meshes, results will be wrong");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2342,7 +2400,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
FBXImporter::LogWarn("did not find UV channel named " + uvSet + " in a mesh using this material");
|
FBXImporter::LogWarn("did not find UV channel named ", uvSet, " in a mesh using this material");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
|
@ -2351,7 +2409,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTa
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndex == -1) {
|
if (uvIndex == -1) {
|
||||||
FBXImporter::LogWarn("failed to resolve UV channel " + uvSet + ", using first UV channel");
|
FBXImporter::LogWarn("failed to resolve UV channel ", uvSet, ", using first UV channel");
|
||||||
uvIndex = 0;
|
uvIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2546,7 +2604,7 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) {
|
||||||
anim->mMorphMeshChannels = new aiMeshMorphAnim *[numMorphMeshChannels];
|
anim->mMorphMeshChannels = new aiMeshMorphAnim *[numMorphMeshChannels];
|
||||||
anim->mNumMorphMeshChannels = numMorphMeshChannels;
|
anim->mNumMorphMeshChannels = numMorphMeshChannels;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
for (auto morphAnimIt : morphAnimDatas) {
|
for (const auto &morphAnimIt : morphAnimDatas) {
|
||||||
morphAnimData *animData = morphAnimIt.second;
|
morphAnimData *animData = morphAnimIt.second;
|
||||||
unsigned int numKeys = static_cast<unsigned int>(animData->size());
|
unsigned int numKeys = static_cast<unsigned int>(animData->size());
|
||||||
aiMeshMorphAnim *meshMorphAnim = new aiMeshMorphAnim();
|
aiMeshMorphAnim *meshMorphAnim = new aiMeshMorphAnim();
|
||||||
|
@ -2574,7 +2632,7 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) {
|
||||||
// empty animations would fail validation, so drop them
|
// empty animations would fail validation, so drop them
|
||||||
delete anim;
|
delete anim;
|
||||||
animations.pop_back();
|
animations.pop_back();
|
||||||
FBXImporter::LogInfo("ignoring empty AnimationStack (using IK?): " + name);
|
FBXImporter::LogInfo("ignoring empty AnimationStack (using IK?): ", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2707,13 +2765,13 @@ void FBXConverter::GenerateNodeAnimations(std::vector<aiNodeAnim *> &node_anims,
|
||||||
ai_assert(node);
|
ai_assert(node);
|
||||||
|
|
||||||
if (node->TargetProperty().empty()) {
|
if (node->TargetProperty().empty()) {
|
||||||
FBXImporter::LogWarn("target property for animation curve not set: " + node->Name());
|
FBXImporter::LogWarn("target property for animation curve not set: ", node->Name());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
curve_node = node;
|
curve_node = node;
|
||||||
if (node->Curves().empty()) {
|
if (node->Curves().empty()) {
|
||||||
FBXImporter::LogWarn("no animation curves assigned to AnimationCurveNode: " + node->Name());
|
FBXImporter::LogWarn("no animation curves assigned to AnimationCurveNode: ", node->Name());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2748,7 +2806,7 @@ void FBXConverter::GenerateNodeAnimations(std::vector<aiNodeAnim *> &node_anims,
|
||||||
if (doc.Settings().optimizeEmptyAnimationCurves &&
|
if (doc.Settings().optimizeEmptyAnimationCurves &&
|
||||||
IsRedundantAnimationData(target, comp, (chain[i]->second))) {
|
IsRedundantAnimationData(target, comp, (chain[i]->second))) {
|
||||||
|
|
||||||
FBXImporter::LogVerboseDebug("dropping redundant animation channel for node " + target.Name());
|
FBXImporter::LogVerboseDebug("dropping redundant animation channel for node ", target.Name());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace FBX {
|
namespace FBX {
|
||||||
|
@ -248,10 +249,8 @@ Object::~Object()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
FileGlobalSettings::FileGlobalSettings(const Document& doc, std::shared_ptr<const PropertyTable> props)
|
FileGlobalSettings::FileGlobalSettings(const Document &doc, std::shared_ptr<const PropertyTable> props) :
|
||||||
: props(props)
|
props(std::move(props)), doc(doc) {
|
||||||
, doc(doc)
|
|
||||||
{
|
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +311,7 @@ void Document::ReadHeader() {
|
||||||
|
|
||||||
const Scope& shead = *ehead->Compound();
|
const Scope& shead = *ehead->Compound();
|
||||||
fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
|
fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
|
||||||
ASSIMP_LOG_DEBUG_F("FBX Version: ", fbxVersion);
|
ASSIMP_LOG_DEBUG("FBX Version: ", fbxVersion);
|
||||||
|
|
||||||
// While we may have some success with newer files, we don't support
|
// While we may have some success with newer files, we don't support
|
||||||
// the older 6.n fbx format
|
// the older 6.n fbx format
|
||||||
|
|
|
@ -500,6 +500,10 @@ public:
|
||||||
return uvScaling;
|
return uvScaling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ai_real &UVRotation() const {
|
||||||
|
return uvRotation;
|
||||||
|
}
|
||||||
|
|
||||||
const PropertyTable& Props() const {
|
const PropertyTable& Props() const {
|
||||||
ai_assert(props.get());
|
ai_assert(props.get());
|
||||||
return *props.get();
|
return *props.get();
|
||||||
|
@ -517,6 +521,7 @@ public:
|
||||||
private:
|
private:
|
||||||
aiVector2D uvTrans;
|
aiVector2D uvTrans;
|
||||||
aiVector2D uvScaling;
|
aiVector2D uvScaling;
|
||||||
|
ai_real uvRotation;
|
||||||
|
|
||||||
std::string type;
|
std::string type;
|
||||||
std::string relativeFileName;
|
std::string relativeFileName;
|
||||||
|
|
|
@ -79,7 +79,7 @@ void DOMError(const std::string& message, const Element* element /*= nullptr*/)
|
||||||
void DOMWarning(const std::string& message, const Token& token)
|
void DOMWarning(const std::string& message, const Token& token)
|
||||||
{
|
{
|
||||||
if(DefaultLogger::get()) {
|
if(DefaultLogger::get()) {
|
||||||
ASSIMP_LOG_WARN_F("FBX-DOM", Util::GetTokenText(&token), message);
|
ASSIMP_LOG_WARN("FBX-DOM", Util::GetTokenText(&token), message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void DOMWarning(const std::string& message, const Element* element /*= nullptr*/
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(DefaultLogger::get()) {
|
if(DefaultLogger::get()) {
|
||||||
ASSIMP_LOG_WARN("FBX-DOM: " + message);
|
ASSIMP_LOG_WARN("FBX-DOM: ", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,9 +144,8 @@ void FBX::Node::AddP70time(
|
||||||
// public member functions for writing nodes to stream
|
// public member functions for writing nodes to stream
|
||||||
|
|
||||||
void FBX::Node::Dump(
|
void FBX::Node::Dump(
|
||||||
std::shared_ptr<Assimp::IOStream> outfile,
|
const std::shared_ptr<Assimp::IOStream> &outfile,
|
||||||
bool binary, int indent
|
bool binary, int indent) {
|
||||||
) {
|
|
||||||
if (binary) {
|
if (binary) {
|
||||||
Assimp::StreamWriterLE outstream(outfile);
|
Assimp::StreamWriterLE outstream(outfile);
|
||||||
DumpBinary(outstream);
|
DumpBinary(outstream);
|
||||||
|
|
|
@ -157,9 +157,8 @@ public: // member functions for writing data to a file or stream
|
||||||
|
|
||||||
// write the full node to the given file or stream
|
// write the full node to the given file or stream
|
||||||
void Dump(
|
void Dump(
|
||||||
std::shared_ptr<Assimp::IOStream> outfile,
|
const std::shared_ptr<Assimp::IOStream> &outfile,
|
||||||
bool binary, int indent
|
bool binary, int indent);
|
||||||
);
|
|
||||||
void Dump(Assimp::StreamWriterLE &s, bool binary, int indent);
|
void Dump(Assimp::StreamWriterLE &s, bool binary, int indent);
|
||||||
|
|
||||||
// these other functions are for writing data piece by piece.
|
// these other functions are for writing data piece by piece.
|
||||||
|
|
|
@ -541,10 +541,17 @@ void FBXExporter::WriteReferences ()
|
||||||
// (before any actual data is written)
|
// (before any actual data is written)
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
size_t count_nodes(const aiNode* n) {
|
size_t count_nodes(const aiNode* n, const aiNode* root) {
|
||||||
size_t count = 1;
|
size_t count;
|
||||||
|
if (n == root) {
|
||||||
|
count = n->mNumMeshes; // (not counting root node)
|
||||||
|
} else if (n->mNumMeshes > 1) {
|
||||||
|
count = n->mNumMeshes + 1;
|
||||||
|
} else {
|
||||||
|
count = 1;
|
||||||
|
}
|
||||||
for (size_t i = 0; i < n->mNumChildren; ++i) {
|
for (size_t i = 0; i < n->mNumChildren; ++i) {
|
||||||
count += count_nodes(n->mChildren[i]);
|
count += count_nodes(n->mChildren[i], root);
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -714,7 +721,7 @@ void FBXExporter::WriteDefinitions ()
|
||||||
|
|
||||||
// Model / FbxNode
|
// Model / FbxNode
|
||||||
// <~~ node hierarchy
|
// <~~ node hierarchy
|
||||||
count = int32_t(count_nodes(mScene->mRootNode)) - 1; // (not counting root node)
|
count = int32_t(count_nodes(mScene->mRootNode, mScene->mRootNode));
|
||||||
if (count) {
|
if (count) {
|
||||||
n = FBX::Node("ObjectType", "Model");
|
n = FBX::Node("ObjectType", "Model");
|
||||||
n.AddChild("Count", count);
|
n.AddChild("Count", count);
|
||||||
|
@ -1681,6 +1688,10 @@ void FBXExporter::WriteObjects ()
|
||||||
// link the image data to the texture
|
// link the image data to the texture
|
||||||
connections.emplace_back("C", "OO", image_uid, texture_uid);
|
connections.emplace_back("C", "OO", image_uid, texture_uid);
|
||||||
|
|
||||||
|
aiUVTransform trafo;
|
||||||
|
unsigned int max = sizeof(aiUVTransform);
|
||||||
|
aiGetMaterialFloatArray(mat, AI_MATKEY_UVTRANSFORM(aiTextureType_DIFFUSE, 0), (ai_real *)&trafo, &max);
|
||||||
|
|
||||||
// now write the actual texture node
|
// now write the actual texture node
|
||||||
FBX::Node tnode("Texture");
|
FBX::Node tnode("Texture");
|
||||||
// TODO: some way to determine texture name?
|
// TODO: some way to determine texture name?
|
||||||
|
@ -1691,6 +1702,9 @@ void FBXExporter::WriteObjects ()
|
||||||
tnode.AddChild("Version", int32_t(202));
|
tnode.AddChild("Version", int32_t(202));
|
||||||
tnode.AddChild("TextureName", texture_name);
|
tnode.AddChild("TextureName", texture_name);
|
||||||
FBX::Node p("Properties70");
|
FBX::Node p("Properties70");
|
||||||
|
p.AddP70vectorA("Translation", trafo.mTranslation[0], trafo.mTranslation[1], 0.0);
|
||||||
|
p.AddP70vectorA("Rotation", 0, 0, trafo.mRotation);
|
||||||
|
p.AddP70vectorA("Scaling", trafo.mScaling[0], trafo.mScaling[1], 0.0);
|
||||||
p.AddP70enum("CurrentTextureBlendMode", 0); // TODO: verify
|
p.AddP70enum("CurrentTextureBlendMode", 0); // TODO: verify
|
||||||
//p.AddP70string("UVSet", ""); // TODO: how should this work?
|
//p.AddP70string("UVSet", ""); // TODO: how should this work?
|
||||||
p.AddP70bool("UseMaterial", 1);
|
p.AddP70bool("UseMaterial", 1);
|
||||||
|
@ -1789,13 +1803,13 @@ void FBXExporter::WriteObjects ()
|
||||||
blendchannel_uid, blendshape_name + FBX::SEPARATOR + "SubDeformer", "BlendShapeChannel"
|
blendchannel_uid, blendshape_name + FBX::SEPARATOR + "SubDeformer", "BlendShapeChannel"
|
||||||
);
|
);
|
||||||
sdnode.AddChild("Version", int32_t(100));
|
sdnode.AddChild("Version", int32_t(100));
|
||||||
sdnode.AddChild("DeformPercent", int32_t(100));
|
sdnode.AddChild("DeformPercent", float(0.0));
|
||||||
FBX::Node p("Properties70");
|
FBX::Node p("Properties70");
|
||||||
p.AddP70numberA("DeformPercent", 100.);
|
p.AddP70numberA("DeformPercent", 0.0);
|
||||||
sdnode.AddChild(p);
|
sdnode.AddChild(p);
|
||||||
// TODO: Normally just one weight per channel, adding stub for later development
|
// TODO: Normally just one weight per channel, adding stub for later development
|
||||||
std::vector<float>fFullWeights;
|
std::vector<float>fFullWeights;
|
||||||
fFullWeights.push_back(0.);
|
fFullWeights.push_back(100.);
|
||||||
sdnode.AddChild("FullWeights", fFullWeights);
|
sdnode.AddChild("FullWeights", fFullWeights);
|
||||||
sdnode.Dump(outstream, binary, indent);
|
sdnode.Dump(outstream, binary, indent);
|
||||||
|
|
||||||
|
@ -2196,7 +2210,65 @@ void FBXExporter::WriteObjects ()
|
||||||
bpnode.Dump(outstream, binary, indent);
|
bpnode.Dump(outstream, binary, indent);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// TODO: cameras, lights
|
// lights
|
||||||
|
indent = 1;
|
||||||
|
lights_uids.clear();
|
||||||
|
for (size_t li = 0; li < mScene->mNumLights; ++li) {
|
||||||
|
aiLight* l = mScene->mLights[li];
|
||||||
|
|
||||||
|
int64_t uid = generate_uid();
|
||||||
|
const std::string lightNodeAttributeName = l->mName.C_Str() + FBX::SEPARATOR + "NodeAttribute";
|
||||||
|
|
||||||
|
FBX::Node lna("NodeAttribute");
|
||||||
|
lna.AddProperties(uid, lightNodeAttributeName, "Light");
|
||||||
|
FBX::Node lnap("Properties70");
|
||||||
|
|
||||||
|
// Light color.
|
||||||
|
lnap.AddP70colorA("Color", l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b);
|
||||||
|
|
||||||
|
// TODO Assimp light description is quite concise and do not handle light intensity.
|
||||||
|
// Default value to 1000W.
|
||||||
|
lnap.AddP70numberA("Intensity", 1000);
|
||||||
|
|
||||||
|
// FBXLight::EType conversion
|
||||||
|
switch (l->mType) {
|
||||||
|
case aiLightSource_POINT:
|
||||||
|
lnap.AddP70enum("LightType", 0);
|
||||||
|
break;
|
||||||
|
case aiLightSource_DIRECTIONAL:
|
||||||
|
lnap.AddP70enum("LightType", 1);
|
||||||
|
break;
|
||||||
|
case aiLightSource_SPOT:
|
||||||
|
lnap.AddP70enum("LightType", 2);
|
||||||
|
lnap.AddP70numberA("InnerAngle", AI_RAD_TO_DEG(l->mAngleInnerCone));
|
||||||
|
lnap.AddP70numberA("OuterAngle", AI_RAD_TO_DEG(l->mAngleOuterCone));
|
||||||
|
break;
|
||||||
|
// TODO Assimp do not handle 'area' nor 'volume' lights, but FBX does.
|
||||||
|
/*case aiLightSource_AREA:
|
||||||
|
lnap.AddP70enum("LightType", 3);
|
||||||
|
lnap.AddP70enum("AreaLightShape", 0); // 0=Rectangle, 1=Sphere
|
||||||
|
break;
|
||||||
|
case aiLightSource_VOLUME:
|
||||||
|
lnap.AddP70enum("LightType", 4);
|
||||||
|
break;*/
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Did not understood how to configure the decay so disabling attenuation.
|
||||||
|
lnap.AddP70enum("DecayType", 0);
|
||||||
|
|
||||||
|
// Dump to FBX stream
|
||||||
|
lna.AddChild(lnap);
|
||||||
|
lna.AddChild("TypeFlags", FBX::FBXExportProperty("Light"));
|
||||||
|
lna.AddChild("GeometryVersion", FBX::FBXExportProperty(int32_t(124)));
|
||||||
|
lna.Dump(outstream, binary, indent);
|
||||||
|
|
||||||
|
// Store name and uid (will be used later when parsing scene nodes)
|
||||||
|
lights_uids[l->mName.C_Str()] = uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: cameras
|
||||||
|
|
||||||
// write nodes (i.e. model hierarchy)
|
// write nodes (i.e. model hierarchy)
|
||||||
// start at root node
|
// start at root node
|
||||||
|
@ -2599,12 +2671,21 @@ void FBXExporter::WriteModelNodes(
|
||||||
na.Dump(outstream, binary, 1);
|
na.Dump(outstream, binary, 1);
|
||||||
// and connect them
|
// and connect them
|
||||||
connections.emplace_back("C", "OO", node_attribute_uid, node_uid);
|
connections.emplace_back("C", "OO", node_attribute_uid, node_uid);
|
||||||
|
} else {
|
||||||
|
const auto& lightIt = lights_uids.find(node->mName.C_Str());
|
||||||
|
if(lightIt != lights_uids.end()) {
|
||||||
|
// Node has a light connected to it.
|
||||||
|
WriteModelNode(
|
||||||
|
outstream, binary, node, node_uid, "Light", transform_chain
|
||||||
|
);
|
||||||
|
connections.emplace_back("C", "OO", lightIt->second, node_uid);
|
||||||
} else {
|
} else {
|
||||||
// generate a null node so we can add children to it
|
// generate a null node so we can add children to it
|
||||||
WriteModelNode(
|
WriteModelNode(
|
||||||
outstream, binary, node, node_uid, "Null", transform_chain
|
outstream, binary, node, node_uid, "Null", transform_chain
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if more than one child mesh, make nodes for each mesh
|
// if more than one child mesh, make nodes for each mesh
|
||||||
if (node->mNumMeshes > 1 || node == mScene->mRootNode) {
|
if (node->mNumMeshes > 1 || node == mScene->mRootNode) {
|
||||||
|
@ -2625,17 +2706,14 @@ void FBXExporter::WriteModelNodes(
|
||||||
],
|
],
|
||||||
new_node_uid
|
new_node_uid
|
||||||
);
|
);
|
||||||
// write model node
|
|
||||||
FBX::Node m("Model");
|
aiNode new_node;
|
||||||
// take name from mesh name, if it exists
|
// take name from mesh name, if it exists
|
||||||
std::string name = mScene->mMeshes[node->mMeshes[i]]->mName.C_Str();
|
new_node.mName = mScene->mMeshes[node->mMeshes[i]]->mName;
|
||||||
name += FBX::SEPARATOR + "Model";
|
// write model node
|
||||||
m.AddProperties(new_node_uid, name, "Mesh");
|
WriteModelNode(
|
||||||
m.AddChild("Version", int32_t(232));
|
outstream, binary, &new_node, new_node_uid, "Mesh", std::vector<std::pair<std::string,aiVector3D>>()
|
||||||
FBX::Node p("Properties70");
|
);
|
||||||
p.AddP70enum("InheritType", 1);
|
|
||||||
m.AddChild(p);
|
|
||||||
m.Dump(outstream, binary, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2647,16 +2725,14 @@ void FBXExporter::WriteModelNodes(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FBXExporter::WriteAnimationCurveNode(
|
void FBXExporter::WriteAnimationCurveNode(
|
||||||
StreamWriterLE &outstream,
|
StreamWriterLE &outstream,
|
||||||
int64_t uid,
|
int64_t uid,
|
||||||
const std::string &name, // "T", "R", or "S"
|
const std::string &name, // "T", "R", or "S"
|
||||||
aiVector3D default_value,
|
aiVector3D default_value,
|
||||||
std::string property_name, // "Lcl Translation" etc
|
const std::string &property_name, // "Lcl Translation" etc
|
||||||
int64_t layer_uid,
|
int64_t layer_uid,
|
||||||
int64_t node_uid
|
int64_t node_uid) {
|
||||||
) {
|
|
||||||
FBX::Node n("AnimationCurveNode");
|
FBX::Node n("AnimationCurveNode");
|
||||||
n.AddProperties(uid, name + FBX::SEPARATOR + "AnimCurveNode", "");
|
n.AddProperties(uid, name + FBX::SEPARATOR + "AnimCurveNode", "");
|
||||||
FBX::Node p("Properties70");
|
FBX::Node p("Properties70");
|
||||||
|
@ -2671,7 +2747,6 @@ void FBXExporter::WriteAnimationCurveNode(
|
||||||
this->connections.emplace_back("C", "OP", uid, node_uid, property_name);
|
this->connections.emplace_back("C", "OP", uid, node_uid, property_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FBXExporter::WriteAnimationCurve(
|
void FBXExporter::WriteAnimationCurve(
|
||||||
StreamWriterLE& outstream,
|
StreamWriterLE& outstream,
|
||||||
double default_value,
|
double default_value,
|
||||||
|
|
|
@ -63,10 +63,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
struct aiScene;
|
struct aiScene;
|
||||||
struct aiNode;
|
struct aiNode;
|
||||||
//struct aiMaterial;
|
struct aiLight;
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp {
|
||||||
{
|
|
||||||
class IOSystem;
|
class IOSystem;
|
||||||
class IOStream;
|
class IOStream;
|
||||||
class ExportProperties;
|
class ExportProperties;
|
||||||
|
@ -95,6 +94,7 @@ namespace Assimp
|
||||||
std::vector<int64_t> mesh_uids;
|
std::vector<int64_t> mesh_uids;
|
||||||
std::vector<int64_t> material_uids;
|
std::vector<int64_t> material_uids;
|
||||||
std::map<const aiNode*,int64_t> node_uids;
|
std::map<const aiNode*,int64_t> node_uids;
|
||||||
|
std::map<std::string,int64_t> lights_uids;
|
||||||
|
|
||||||
// this crude unique-ID system is actually fine
|
// this crude unique-ID system is actually fine
|
||||||
int64_t last_uid = 999999;
|
int64_t last_uid = 999999;
|
||||||
|
@ -158,10 +158,9 @@ namespace Assimp
|
||||||
int64_t uid,
|
int64_t uid,
|
||||||
const std::string &name, // "T", "R", or "S"
|
const std::string &name, // "T", "R", or "S"
|
||||||
aiVector3D default_value,
|
aiVector3D default_value,
|
||||||
std::string property_name, // "Lcl Translation" etc
|
const std::string &property_name, // "Lcl Translation" etc
|
||||||
int64_t animation_layer_uid,
|
int64_t animation_layer_uid,
|
||||||
int64_t node_uid
|
int64_t node_uid);
|
||||||
);
|
|
||||||
void WriteAnimationCurve(
|
void WriteAnimationCurve(
|
||||||
StreamWriterLE& outstream,
|
StreamWriterLE& outstream,
|
||||||
double default_value,
|
double default_value,
|
||||||
|
|
|
@ -108,7 +108,7 @@ bool FBXImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
||||||
|
|
||||||
else if ((!extension.length() || checkSig) && pIOHandler) {
|
else if ((!extension.length() || checkSig) && pIOHandler) {
|
||||||
// at least ASCII-FBX files usually have a 'FBX' somewhere in their head
|
// at least ASCII-FBX files usually have a 'FBX' somewhere in their head
|
||||||
const char *tokens[] = { "fbx" };
|
static const char * const tokens[] = { "fbx" };
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -70,28 +70,29 @@ typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>
|
||||||
class FBXImporter : public BaseImporter, public LogFunctions<FBXImporter> {
|
class FBXImporter : public BaseImporter, public LogFunctions<FBXImporter> {
|
||||||
public:
|
public:
|
||||||
FBXImporter();
|
FBXImporter();
|
||||||
virtual ~FBXImporter();
|
~FBXImporter() override;
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
bool CanRead(const std::string &pFile,
|
bool CanRead(const std::string &pFile,
|
||||||
IOSystem *pIOHandler,
|
IOSystem *pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// --------------------
|
// --------------------
|
||||||
const aiImporterDesc *GetInfo() const;
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
void SetupProperties(const Importer *pImp);
|
void SetupProperties(const Importer *pImp) override;
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
void InternReadFile(const std::string &pFile,
|
void InternReadFile(const std::string &pFile,
|
||||||
aiScene *pScene,
|
aiScene *pScene,
|
||||||
IOSystem *pIOHandler);
|
IOSystem *pIOHandler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FBX::ImportSettings settings;
|
FBX::ImportSettings settings;
|
||||||
}; // !class FBXImporter
|
}; // !class FBXImporter
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
||||||
#endif // !INCLUDED_AI_FBX_IMPORTER_H
|
#endif // !INCLUDED_AI_FBX_IMPORTER_H
|
||||||
|
|
|
@ -82,7 +82,7 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con
|
||||||
|
|
||||||
// lower-case shading because Blender (for example) writes "Phong"
|
// lower-case shading because Blender (for example) writes "Phong"
|
||||||
for (size_t i = 0; i < shading.length(); ++i) {
|
for (size_t i = 0; i < shading.length(); ++i) {
|
||||||
shading[i] = static_cast<char>(tolower(shading[i]));
|
shading[i] = static_cast<char>(tolower(static_cast<unsigned char>(shading[i])));
|
||||||
}
|
}
|
||||||
std::string templateName;
|
std::string templateName;
|
||||||
if(shading == "phong") {
|
if(shading == "phong") {
|
||||||
|
@ -210,6 +210,11 @@ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const
|
||||||
uvTrans.y = trans.y;
|
uvTrans.y = trans.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const aiVector3D &rotation = PropertyGet<aiVector3D>(*props, "Rotation", ok);
|
||||||
|
if (ok) {
|
||||||
|
uvRotation = rotation.z;
|
||||||
|
}
|
||||||
|
|
||||||
// resolve video links
|
// resolve video links
|
||||||
if(doc.Settings().readTextures) {
|
if(doc.Settings().readTextures) {
|
||||||
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID());
|
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID());
|
||||||
|
@ -352,7 +357,7 @@ Video::Video(uint64_t id, const Element& element, const Document& doc, const std
|
||||||
}
|
}
|
||||||
} catch (const runtime_error& runtimeError) {
|
} catch (const runtime_error& runtimeError) {
|
||||||
//we don't need the content data for contents that has already been loaded
|
//we don't need the content data for contents that has already been loaded
|
||||||
ASSIMP_LOG_VERBOSE_DEBUG_F("Caught exception in FBXMaterial (likely because content was already loaded): ",
|
ASSIMP_LOG_VERBOSE_DEBUG("Caught exception in FBXMaterial (likely because content was already loaded): ",
|
||||||
runtimeError.what());
|
runtimeError.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,8 +307,8 @@ void MeshGeometry::ReadLayerElement(const Scope& layerElement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FBXImporter::LogError(Formatter::format("failed to resolve vertex layer element: ")
|
FBXImporter::LogError("failed to resolve vertex layer element: ",
|
||||||
<< type << ", index: " << typedIndex);
|
type, ", index: ", typedIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -324,13 +324,13 @@ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scop
|
||||||
|
|
||||||
if (type == "LayerElementUV") {
|
if (type == "LayerElementUV") {
|
||||||
if(index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
|
if(index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
|
||||||
FBXImporter::LogError(Formatter::format("ignoring UV layer, maximum number of UV channels exceeded: ")
|
FBXImporter::LogError("ignoring UV layer, maximum number of UV channels exceeded: ",
|
||||||
<< index << " (limit is " << AI_MAX_NUMBER_OF_TEXTURECOORDS << ")" );
|
index, " (limit is ", AI_MAX_NUMBER_OF_TEXTURECOORDS, ")" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Element* Name = source["Name"];
|
const Element* Name = source["Name"];
|
||||||
m_uvNames[index] = "";
|
m_uvNames[index] = std::string();
|
||||||
if(Name) {
|
if(Name) {
|
||||||
m_uvNames[index] = ParseTokenAsString(GetRequiredToken(*Name,0));
|
m_uvNames[index] = ParseTokenAsString(GetRequiredToken(*Name,0));
|
||||||
}
|
}
|
||||||
|
@ -402,8 +402,8 @@ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scop
|
||||||
}
|
}
|
||||||
else if (type == "LayerElementColor") {
|
else if (type == "LayerElementColor") {
|
||||||
if(index >= AI_MAX_NUMBER_OF_COLOR_SETS) {
|
if(index >= AI_MAX_NUMBER_OF_COLOR_SETS) {
|
||||||
FBXImporter::LogError(Formatter::format("ignoring vertex color layer, maximum number of color sets exceeded: ")
|
FBXImporter::LogError("ignoring vertex color layer, maximum number of color sets exceeded: ",
|
||||||
<< index << " (limit is " << AI_MAX_NUMBER_OF_COLOR_SETS << ")" );
|
index, " (limit is ", AI_MAX_NUMBER_OF_COLOR_SETS, ")" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,8 +449,8 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
||||||
|
|
||||||
if (tempData.size() != mapping_offsets.size()) {
|
if (tempData.size() != mapping_offsets.size()) {
|
||||||
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
|
FBXImporter::LogError("length of input data unexpected for ByVertice mapping: ",
|
||||||
<< tempData.size() << ", expected " << mapping_offsets.size());
|
tempData.size(), ", expected ", mapping_offsets.size());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,8 +470,8 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
||||||
|
|
||||||
if (uvIndices.size() != vertex_count) {
|
if (uvIndices.size() != vertex_count) {
|
||||||
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
|
FBXImporter::LogError("length of input data unexpected for ByVertice mapping: ",
|
||||||
<< uvIndices.size() << ", expected " << vertex_count);
|
uvIndices.size(), ", expected ", vertex_count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,8 +493,8 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
||||||
|
|
||||||
if (tempData.size() != vertex_count) {
|
if (tempData.size() != vertex_count) {
|
||||||
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ")
|
FBXImporter::LogError("length of input data unexpected for ByPolygon mapping: ",
|
||||||
<< tempData.size() << ", expected " << vertex_count
|
tempData.size(), ", expected ", vertex_count
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -509,14 +509,14 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
||||||
|
|
||||||
if (uvIndices.size() > vertex_count) {
|
if (uvIndices.size() > vertex_count) {
|
||||||
FBXImporter::LogWarn(Formatter::format("trimming length of input array for ByPolygonVertex mapping: ")
|
FBXImporter::LogWarn("trimming length of input array for ByPolygonVertex mapping: ",
|
||||||
<< uvIndices.size() << ", expected " << vertex_count);
|
uvIndices.size(), ", expected ", vertex_count);
|
||||||
uvIndices.resize(vertex_count);
|
uvIndices.resize(vertex_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uvIndices.size() != vertex_count) {
|
if (uvIndices.size() != vertex_count) {
|
||||||
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygonVertex mapping: ")
|
FBXImporter::LogError("length of input data unexpected for ByPolygonVertex mapping: ",
|
||||||
<< uvIndices.size() << ", expected " << vertex_count);
|
uvIndices.size(), ", expected ", vertex_count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,8 +537,8 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FBXImporter::LogError(Formatter::format("ignoring vertex data channel, access type not implemented: ")
|
FBXImporter::LogError("ignoring vertex data channel, access type not implemented: ",
|
||||||
<< MappingInformationType << "," << ReferenceInformationType);
|
MappingInformationType, ",", ReferenceInformationType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,15 +604,15 @@ void MeshGeometry::ReadVertexDataTangents(std::vector<aiVector3D>& tangents_out,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
static const std::string BinormalIndexToken = "BinormalIndex";
|
static const char * BinormalIndexToken = "BinormalIndex";
|
||||||
static const std::string BinormalsIndexToken = "BinormalsIndex";
|
static const char * BinormalsIndexToken = "BinormalsIndex";
|
||||||
|
|
||||||
void MeshGeometry::ReadVertexDataBinormals(std::vector<aiVector3D>& binormals_out, const Scope& source,
|
void MeshGeometry::ReadVertexDataBinormals(std::vector<aiVector3D>& binormals_out, const Scope& source,
|
||||||
const std::string& MappingInformationType,
|
const std::string& MappingInformationType,
|
||||||
const std::string& ReferenceInformationType)
|
const std::string& ReferenceInformationType)
|
||||||
{
|
{
|
||||||
const char * str = source.Elements().count( "Binormals" ) > 0 ? "Binormals" : "Binormal";
|
const char * str = source.Elements().count( "Binormals" ) > 0 ? "Binormals" : "Binormal";
|
||||||
const char * strIdx = source.Elements().count( "Binormals" ) > 0 ? BinormalsIndexToken.c_str() : BinormalIndexToken.c_str();
|
const char * strIdx = source.Elements().count( "Binormals" ) > 0 ? BinormalsIndexToken : BinormalIndexToken;
|
||||||
ResolveVertexDataArray(binormals_out,source,MappingInformationType,ReferenceInformationType,
|
ResolveVertexDataArray(binormals_out,source,MappingInformationType,ReferenceInformationType,
|
||||||
str,
|
str,
|
||||||
strIdx,
|
strIdx,
|
||||||
|
@ -642,10 +642,10 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, cons
|
||||||
if (MappingInformationType == "AllSame") {
|
if (MappingInformationType == "AllSame") {
|
||||||
// easy - same material for all faces
|
// easy - same material for all faces
|
||||||
if (materials_out.empty()) {
|
if (materials_out.empty()) {
|
||||||
FBXImporter::LogError(Formatter::format("expected material index, ignoring"));
|
FBXImporter::LogError("expected material index, ignoring");
|
||||||
return;
|
return;
|
||||||
} else if (materials_out.size() > 1) {
|
} else if (materials_out.size() > 1) {
|
||||||
FBXImporter::LogWarn(Formatter::format("expected only a single material index, ignoring all except the first one"));
|
FBXImporter::LogWarn("expected only a single material index, ignoring all except the first one");
|
||||||
materials_out.clear();
|
materials_out.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,14 +655,14 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, cons
|
||||||
materials_out.resize(face_count);
|
materials_out.resize(face_count);
|
||||||
|
|
||||||
if(materials_out.size() != face_count) {
|
if(materials_out.size() != face_count) {
|
||||||
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ")
|
FBXImporter::LogError("length of input data unexpected for ByPolygon mapping: ",
|
||||||
<< materials_out.size() << ", expected " << face_count
|
materials_out.size(), ", expected ", face_count
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FBXImporter::LogError(Formatter::format("ignoring material assignments, access type not implemented: ")
|
FBXImporter::LogError("ignoring material assignments, access type not implemented: ",
|
||||||
<< MappingInformationType << "," << ReferenceInformationType);
|
MappingInformationType, ",", ReferenceInformationType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -192,6 +192,10 @@ Scope::Scope(Parser& parser,bool topLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& str = n->StringContents();
|
const std::string& str = n->StringContents();
|
||||||
|
if (str.empty()) {
|
||||||
|
ParseError("unexpected content: empty string.");
|
||||||
|
}
|
||||||
|
|
||||||
elements.insert(ElementMap::value_type(str,new_Element(*n,parser)));
|
elements.insert(ElementMap::value_type(str,new_Element(*n,parser)));
|
||||||
|
|
||||||
// Element() should stop at the next Key token (or right after a Close token)
|
// Element() should stop at the next Key token (or right after a Close token)
|
||||||
|
@ -462,7 +466,7 @@ std::string ParseTokenAsString(const Token& t, const char*& err_out)
|
||||||
|
|
||||||
if (t.Type() != TokenType_DATA) {
|
if (t.Type() != TokenType_DATA) {
|
||||||
err_out = "expected TOK_DATA token";
|
err_out = "expected TOK_DATA token";
|
||||||
return "";
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(t.IsBinary())
|
if(t.IsBinary())
|
||||||
|
@ -470,7 +474,7 @@ std::string ParseTokenAsString(const Token& t, const char*& err_out)
|
||||||
const char* data = t.begin();
|
const char* data = t.begin();
|
||||||
if (data[0] != 'S') {
|
if (data[0] != 'S') {
|
||||||
err_out = "failed to parse S(tring), unexpected data type (binary)";
|
err_out = "failed to parse S(tring), unexpected data type (binary)";
|
||||||
return "";
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// read string length
|
// read string length
|
||||||
|
@ -484,13 +488,13 @@ std::string ParseTokenAsString(const Token& t, const char*& err_out)
|
||||||
const size_t length = static_cast<size_t>(t.end() - t.begin());
|
const size_t length = static_cast<size_t>(t.end() - t.begin());
|
||||||
if(length < 2) {
|
if(length < 2) {
|
||||||
err_out = "token is too short to hold a string";
|
err_out = "token is too short to hold a string";
|
||||||
return "";
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* s = t.begin(), *e = t.end() - 1;
|
const char* s = t.begin(), *e = t.end() - 1;
|
||||||
if (*s != '\"' || *e != '\"') {
|
if (*s != '\"' || *e != '\"') {
|
||||||
err_out = "expected double quoted string";
|
err_out = "expected double quoted string";
|
||||||
return "";
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::string(s+1,length-2);
|
return std::string(s+1,length-2);
|
||||||
|
@ -642,8 +646,7 @@ void ParseVectorDataArray(std::vector<aiVector3D>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,8 +736,7 @@ void ParseVectorDataArray(std::vector<aiColor4D>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,8 +818,7 @@ void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -892,8 +893,7 @@ void ParseVectorDataArray(std::vector<int>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * 4;
|
uint64_t dataToRead = static_cast<uint64_t>(count) * 4;
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -954,8 +954,7 @@ void ParseVectorDataArray(std::vector<float>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1019,8 +1018,7 @@ void ParseVectorDataArray(std::vector<unsigned int>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * 4;
|
uint64_t dataToRead = static_cast<uint64_t>(count) * 4;
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1088,8 +1086,7 @@ void ParseVectorDataArray(std::vector<uint64_t>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * 8;
|
uint64_t dataToRead = static_cast<uint64_t>(count) * 8;
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1150,8 +1147,7 @@ void ParseVectorDataArray(std::vector<int64_t>& out, const Element& el)
|
||||||
|
|
||||||
ai_assert(data == end);
|
ai_assert(data == end);
|
||||||
uint64_t dataToRead = static_cast<uint64_t>(count) * 8;
|
uint64_t dataToRead = static_cast<uint64_t>(count) * 8;
|
||||||
ai_assert(buff.size() == dataToRead);
|
if (dataToRead != buff.size()) {
|
||||||
if (dataToRead > buff.size()) {
|
|
||||||
ParseError("Invalid read size (binary)",&el);
|
ParseError("Invalid read size (binary)",&el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "FBXDocumentUtil.h"
|
#include "FBXDocumentUtil.h"
|
||||||
#include "FBXProperties.h"
|
#include "FBXProperties.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace FBX {
|
namespace FBX {
|
||||||
|
|
||||||
|
@ -131,7 +133,7 @@ Property* ReadTypedProperty(const Element& element)
|
||||||
ParseTokenAsFloat(*tok[6]))
|
ParseTokenAsFloat(*tok[6]))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (!strcmp(cs,"double") || !strcmp(cs,"Number") || !strcmp(cs,"Float") || !strcmp(cs,"FieldOfView") || !strcmp( cs, "UnitScaleFactor" ) ) {
|
else if (!strcmp(cs,"double") || !strcmp(cs,"Number") || !strcmp(cs,"float") || !strcmp(cs,"Float") || !strcmp(cs,"FieldOfView") || !strcmp( cs, "UnitScaleFactor" ) ) {
|
||||||
checkTokenCount(tok, 5);
|
checkTokenCount(tok, 5);
|
||||||
return new TypedProperty<float>(ParseTokenAsFloat(*tok[4]));
|
return new TypedProperty<float>(ParseTokenAsFloat(*tok[4]));
|
||||||
}
|
}
|
||||||
|
@ -155,7 +157,7 @@ std::string PeekPropertyName(const Element& element)
|
||||||
ai_assert(element.KeyToken().StringContents() == "P");
|
ai_assert(element.KeyToken().StringContents() == "P");
|
||||||
const TokenList& tok = element.Tokens();
|
const TokenList& tok = element.Tokens();
|
||||||
if(tok.size() < 4) {
|
if(tok.size() < 4) {
|
||||||
return "";
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ParseTokenAsString(*tok[0]);
|
return ParseTokenAsString(*tok[0]);
|
||||||
|
@ -172,10 +174,8 @@ PropertyTable::PropertyTable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
PropertyTable::PropertyTable(const Element& element, std::shared_ptr<const PropertyTable> templateProps)
|
PropertyTable::PropertyTable(const Element &element, std::shared_ptr<const PropertyTable> templateProps) :
|
||||||
: templateProps(templateProps)
|
templateProps(std::move(templateProps)), element(&element) {
|
||||||
, element(&element)
|
|
||||||
{
|
|
||||||
const Scope& scope = GetRequiredScope(element);
|
const Scope& scope = GetRequiredScope(element);
|
||||||
for(const ElementMap::value_type& v : scope.Elements()) {
|
for(const ElementMap::value_type& v : scope.Elements()) {
|
||||||
if(v.first != "P") {
|
if(v.first != "P") {
|
||||||
|
@ -199,7 +199,6 @@ PropertyTable::PropertyTable(const Element& element, std::shared_ptr<const Prope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
PropertyTable::~PropertyTable()
|
PropertyTable::~PropertyTable()
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "AssetLib/HMP/HMPLoader.h"
|
#include "AssetLib/HMP/HMPLoader.h"
|
||||||
#include "AssetLib/MD2/MD2FileData.h"
|
#include "AssetLib/MD2/MD2FileData.h"
|
||||||
|
|
||||||
|
#include <assimp/StringUtils.h>
|
||||||
#include <assimp/importerdesc.h>
|
#include <assimp/importerdesc.h>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
|
@ -151,12 +152,7 @@ void HMPImporter::InternReadFile(const std::string &pFile,
|
||||||
InternReadFile_HMP7();
|
InternReadFile_HMP7();
|
||||||
} else {
|
} else {
|
||||||
// Print the magic word to the logger
|
// Print the magic word to the logger
|
||||||
char szBuffer[5];
|
std::string szBuffer = ai_str_toprintable((const char *)&iMagic, sizeof(iMagic));
|
||||||
szBuffer[0] = ((char *)&iMagic)[0];
|
|
||||||
szBuffer[1] = ((char *)&iMagic)[1];
|
|
||||||
szBuffer[2] = ((char *)&iMagic)[2];
|
|
||||||
szBuffer[3] = ((char *)&iMagic)[3];
|
|
||||||
szBuffer[4] = '\0';
|
|
||||||
|
|
||||||
delete[] mBuffer;
|
delete[] mBuffer;
|
||||||
mBuffer = nullptr;
|
mBuffer = nullptr;
|
||||||
|
|
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2021, assimp team
|
Copyright (c) 2006-2021, 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,
|
||||||
|
@ -42,15 +41,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
/** @file HMPLoader.h
|
/** @file HMPLoader.h
|
||||||
* @brief Declaration of the HMP importer class
|
* @brief Declaration of the HMP importer class
|
||||||
*/
|
*/
|
||||||
|
#pragma once
|
||||||
#ifndef AI_HMPLOADER_H_INCLUDED
|
#ifndef AI_HMPLOADER_H_INCLUDED
|
||||||
#define AI_HMPLOADER_H_INCLUDED
|
#define AI_HMPLOADER_H_INCLUDED
|
||||||
|
|
||||||
// internal headers
|
|
||||||
#include <assimp/BaseImporter.h>
|
#include <assimp/BaseImporter.h>
|
||||||
|
|
||||||
#include "AssetLib/MDL/MDLLoader.h"
|
// internal headers
|
||||||
#include "AssetLib/HMP/HMPFileData.h"
|
#include "AssetLib/HMP/HMPFileData.h"
|
||||||
|
#include "AssetLib/MDL/MDLLoader.h"
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
using namespace HMP;
|
using namespace HMP;
|
||||||
|
@ -58,39 +57,31 @@ using namespace HMP;
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
/** Used to load 3D GameStudio HMP files (terrains)
|
/** Used to load 3D GameStudio HMP files (terrains)
|
||||||
*/
|
*/
|
||||||
class HMPImporter : public MDLImporter
|
class HMPImporter : public MDLImporter {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
HMPImporter();
|
HMPImporter();
|
||||||
~HMPImporter();
|
~HMPImporter() override;
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns whether the class can handle the format of the given file.
|
/** Returns whether the class can handle the format of the given file.
|
||||||
* See BaseImporter::CanRead() for details.
|
* See BaseImporter::CanRead() for details.
|
||||||
*/
|
*/
|
||||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Return importer meta information.
|
/** Return importer meta information.
|
||||||
* See #BaseImporter::GetInfo for the details
|
* See #BaseImporter::GetInfo for the details
|
||||||
*/
|
*/
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Imports the given file into the given scene structure.
|
/** Imports the given file into the given scene structure.
|
||||||
* See BaseImporter::InternReadFile() for details
|
* See BaseImporter::InternReadFile() for details
|
||||||
*/
|
*/
|
||||||
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||||
IOSystem* pIOHandler);
|
IOSystem *pIOHandler) override;
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Import a HMP4 file
|
/** Import a HMP4 file
|
||||||
|
@ -142,12 +133,8 @@ protected:
|
||||||
*/
|
*/
|
||||||
void ReadFirstSkin(unsigned int iNumSkins, const unsigned char *szCursor,
|
void ReadFirstSkin(unsigned int iNumSkins, const unsigned char *szCursor,
|
||||||
const unsigned char **szCursorOut);
|
const unsigned char **szCursorOut);
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
||||||
#endif // AI_HMPIMPORTER_H_INC
|
#endif // AI_HMPIMPORTER_H_INC
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "Common/PolyTools.h"
|
#include "Common/PolyTools.h"
|
||||||
#include "PostProcessing/ProcessHelper.h"
|
#include "PostProcessing/ProcessHelper.h"
|
||||||
|
|
||||||
#include <assimp/Defines.h>
|
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
@ -513,7 +512,7 @@ void ProcessPolygonalBoundedBooleanHalfSpaceDifference(const Schema_2x3::IfcPoly
|
||||||
}
|
}
|
||||||
|
|
||||||
// we got a list of in-out-combinations of intersections. That should be an even number of intersections, or
|
// we got a list of in-out-combinations of intersections. That should be an even number of intersections, or
|
||||||
// we're fucked.
|
// we are facing a non-recoverable error.
|
||||||
if ((intersections.size() & 1) != 0) {
|
if ((intersections.size() & 1) != 0) {
|
||||||
IFCImporter::LogWarn("Odd number of intersections, can't work with that. Omitting half space boundary check.");
|
IFCImporter::LogWarn("Odd number of intersections, can't work with that. Omitting half space boundary check.");
|
||||||
continue;
|
continue;
|
||||||
|
@ -715,7 +714,7 @@ void ProcessBoolean(const Schema_2x3::IfcBooleanResult &boolean, TempMesh &resul
|
||||||
// DIFFERENCE
|
// DIFFERENCE
|
||||||
if (const Schema_2x3::IfcBooleanResult *const clip = boolean.ToPtr<Schema_2x3::IfcBooleanResult>()) {
|
if (const Schema_2x3::IfcBooleanResult *const clip = boolean.ToPtr<Schema_2x3::IfcBooleanResult>()) {
|
||||||
if (clip->Operator != "DIFFERENCE") {
|
if (clip->Operator != "DIFFERENCE") {
|
||||||
IFCImporter::LogWarn("encountered unsupported boolean operator: " + (std::string)clip->Operator);
|
IFCImporter::LogWarn("encountered unsupported boolean operator: ", (std::string)clip->Operator);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,7 +755,7 @@ void ProcessBoolean(const Schema_2x3::IfcBooleanResult &boolean, TempMesh &resul
|
||||||
ProcessBooleanExtrudedAreaSolidDifference(as, result, first_operand, conv);
|
ProcessBooleanExtrudedAreaSolidDifference(as, result, first_operand, conv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcBooleanResult entity, type is " + boolean.GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcBooleanResult entity, type is ", boolean.GetClassName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ void ProcessConnectedFaceSet(const Schema_2x3::IfcConnectedFaceSet& fset, TempMe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcFaceBound entity, type is " + bound.Bound->GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcFaceBound entity, type is ", bound.Bound->GetClassName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,7 +729,7 @@ void ProcessSweptAreaSolid(const Schema_2x3::IfcSweptAreaSolid& swept, TempMesh&
|
||||||
ProcessRevolvedAreaSolid(*rev,meshout,conv);
|
ProcessRevolvedAreaSolid(*rev,meshout,conv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcSweptAreaSolid entity, type is " + swept.GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcSweptAreaSolid entity, type is ", swept.GetClassName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,7 +740,7 @@ bool ProcessGeometricItem(const Schema_2x3::IfcRepresentationItem& geo, unsigned
|
||||||
bool fix_orientation = false;
|
bool fix_orientation = false;
|
||||||
std::shared_ptr< TempMesh > meshtmp = std::make_shared<TempMesh>();
|
std::shared_ptr< TempMesh > meshtmp = std::make_shared<TempMesh>();
|
||||||
if(const Schema_2x3::IfcShellBasedSurfaceModel* shellmod = geo.ToPtr<Schema_2x3::IfcShellBasedSurfaceModel>()) {
|
if(const Schema_2x3::IfcShellBasedSurfaceModel* shellmod = geo.ToPtr<Schema_2x3::IfcShellBasedSurfaceModel>()) {
|
||||||
for(std::shared_ptr<const Schema_2x3::IfcShell> shell :shellmod->SbsmBoundary) {
|
for (const std::shared_ptr<const Schema_2x3::IfcShell> &shell : shellmod->SbsmBoundary) {
|
||||||
try {
|
try {
|
||||||
const ::Assimp::STEP::EXPRESS::ENTITY& e = shell->To<::Assimp::STEP::EXPRESS::ENTITY>();
|
const ::Assimp::STEP::EXPRESS::ENTITY& e = shell->To<::Assimp::STEP::EXPRESS::ENTITY>();
|
||||||
const Schema_2x3::IfcConnectedFaceSet& fs = conv.db.MustGetObject(e).To<Schema_2x3::IfcConnectedFaceSet>();
|
const Schema_2x3::IfcConnectedFaceSet& fs = conv.db.MustGetObject(e).To<Schema_2x3::IfcConnectedFaceSet>();
|
||||||
|
@ -781,7 +781,7 @@ bool ProcessGeometricItem(const Schema_2x3::IfcRepresentationItem& geo, unsigned
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcGeometricRepresentationItem entity, type is " + geo.GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcGeometricRepresentationItem entity, type is ", geo.GetClassName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ static const aiImporterDesc desc = {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
"ifc ifczip stp"
|
"ifc ifczip step stp"
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -137,9 +137,8 @@ bool IFCImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
||||||
// note: this is the common identification for STEP-encoded files, so
|
// note: this is the common identification for STEP-encoded files, so
|
||||||
// it is only unambiguous as long as we don't support any further
|
// it is only unambiguous as long as we don't support any further
|
||||||
// file formats with STEP as their encoding.
|
// file formats with STEP as their encoding.
|
||||||
const char *tokens[] = { "ISO-10303-21" };
|
static const char * const tokens[] = { "ISO-10303-21" };
|
||||||
const bool found(SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1));
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -243,12 +242,12 @@ void IFCImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DefaultLogger::isNullLogger()) {
|
if (!DefaultLogger::isNullLogger()) {
|
||||||
LogDebug("File schema is \'" + head.fileSchema + '\'');
|
LogDebug("File schema is \'", head.fileSchema, '\'');
|
||||||
if (head.timestamp.length()) {
|
if (head.timestamp.length()) {
|
||||||
LogDebug("Timestamp \'" + head.timestamp + '\'');
|
LogDebug("Timestamp \'", head.timestamp, '\'');
|
||||||
}
|
}
|
||||||
if (head.app.length()) {
|
if (head.app.length()) {
|
||||||
LogDebug("Application/Exporter identline is \'" + head.app + '\'');
|
LogDebug("Application/Exporter identline is \'", head.app, '\'');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +314,7 @@ void IFCImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
|
|
||||||
// this must be last because objects are evaluated lazily as we process them
|
// this must be last because objects are evaluated lazily as we process them
|
||||||
if (!DefaultLogger::isNullLogger()) {
|
if (!DefaultLogger::isNullLogger()) {
|
||||||
LogDebug((Formatter::format(), "STEP: evaluated ", db->GetEvaluatedObjectCount(), " object records"));
|
LogDebug("STEP: evaluated ", db->GetEvaluatedObjectCount(), " object records");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +402,7 @@ void ResolveObjectPlacement(aiMatrix4x4 &m, const Schema_2x3::IfcObjectPlacement
|
||||||
m = tmpM * m;
|
m = tmpM * m;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcObjectPlacement entity, type is " + place.GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcObjectPlacement entity, type is ", place.GetClassName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +437,7 @@ bool ProcessMappedItem(const Schema_2x3::IfcMappedItem &mapped, aiNode *nd_src,
|
||||||
bool got = false;
|
bool got = false;
|
||||||
for (const Schema_2x3::IfcRepresentationItem &item : repr.Items) {
|
for (const Schema_2x3::IfcRepresentationItem &item : repr.Items) {
|
||||||
if (!ProcessRepresentationItem(item, localmatid, meshes, conv)) {
|
if (!ProcessRepresentationItem(item, localmatid, meshes, conv)) {
|
||||||
IFCImporter::LogWarn("skipping mapped entity of type " + item.GetClassName() + ", no representations could be generated");
|
IFCImporter::LogWarn("skipping mapped entity of type ", item.GetClassName(), ", no representations could be generated");
|
||||||
} else
|
} else
|
||||||
got = true;
|
got = true;
|
||||||
}
|
}
|
||||||
|
@ -567,7 +566,7 @@ typedef std::map<std::string, std::string> Metadata;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void ProcessMetadata(const Schema_2x3::ListOf<Schema_2x3::Lazy<Schema_2x3::IfcProperty>, 1, 0> &set, ConversionData &conv, Metadata &properties,
|
void ProcessMetadata(const Schema_2x3::ListOf<Schema_2x3::Lazy<Schema_2x3::IfcProperty>, 1, 0> &set, ConversionData &conv, Metadata &properties,
|
||||||
const std::string &prefix = "",
|
const std::string &prefix = std::string(),
|
||||||
unsigned int nest = 0) {
|
unsigned int nest = 0) {
|
||||||
for (const Schema_2x3::IfcProperty &property : set) {
|
for (const Schema_2x3::IfcProperty &property : set) {
|
||||||
const std::string &key = prefix.length() > 0 ? (prefix + "." + property.Name) : property.Name;
|
const std::string &key = prefix.length() > 0 ? (prefix + "." + property.Name) : property.Name;
|
||||||
|
@ -618,7 +617,7 @@ void ProcessMetadata(const Schema_2x3::ListOf<Schema_2x3::Lazy<Schema_2x3::IfcPr
|
||||||
ProcessMetadata(complexProp->HasProperties, conv, properties, key, nest + 1);
|
ProcessMetadata(complexProp->HasProperties, conv, properties, key, nest + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
properties[key] = "";
|
properties[key] = std::string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -856,7 +855,7 @@ void ProcessSpatialStructures(ConversionData &conv) {
|
||||||
if (!prod) {
|
if (!prod) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
IFCImporter::LogVerboseDebug("looking at spatial structure `" + (prod->Name ? prod->Name.Get() : "unnamed") + "`" + (prod->ObjectType ? " which is of type " + prod->ObjectType.Get() : ""));
|
IFCImporter::LogVerboseDebug("looking at spatial structure `", (prod->Name ? prod->Name.Get() : "unnamed"), "`", (prod->ObjectType ? " which is of type " + prod->ObjectType.Get() : ""));
|
||||||
|
|
||||||
// the primary sites are referenced by an IFCRELAGGREGATES element which assigns them to the IFCPRODUCT
|
// the primary sites are referenced by an IFCRELAGGREGATES element which assigns them to the IFCPRODUCT
|
||||||
const STEP::DB::RefMap &refs = conv.db.GetRefs();
|
const STEP::DB::RefMap &refs = conv.db.GetRefs();
|
||||||
|
|
|
@ -53,14 +53,18 @@ namespace Assimp {
|
||||||
|
|
||||||
// TinyFormatter.h
|
// TinyFormatter.h
|
||||||
namespace Formatter {
|
namespace Formatter {
|
||||||
template <typename T,typename TR, typename A> class basic_formatter;
|
|
||||||
|
template <typename T, typename TR, typename A>
|
||||||
|
class basic_formatter;
|
||||||
typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
|
typedef class basic_formatter<char, std::char_traits<char>, std::allocator<char>> format;
|
||||||
}
|
|
||||||
|
} // namespace Formatter
|
||||||
|
|
||||||
namespace STEP {
|
namespace STEP {
|
||||||
class DB;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
class DB;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
/** Load the IFC format, which is an open specification to describe building and construction
|
/** Load the IFC format, which is an open specification to describe building and construction
|
||||||
|
@ -69,52 +73,12 @@ namespace Assimp {
|
||||||
See http://en.wikipedia.org/wiki/Industry_Foundation_Classes
|
See http://en.wikipedia.org/wiki/Industry_Foundation_Classes
|
||||||
*/
|
*/
|
||||||
// -------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------
|
||||||
class IFCImporter : public BaseImporter, public LogFunctions<IFCImporter>
|
class IFCImporter : public BaseImporter, public LogFunctions<IFCImporter> {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
IFCImporter();
|
|
||||||
~IFCImporter();
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
bool CanRead( const std::string& pFile,
|
|
||||||
IOSystem* pIOHandler,
|
|
||||||
bool checkSig
|
|
||||||
) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
const aiImporterDesc* GetInfo () const;
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void SetupProperties(const Importer* pImp);
|
|
||||||
|
|
||||||
// --------------------
|
|
||||||
void InternReadFile( const std::string& pFile,
|
|
||||||
aiScene* pScene,
|
|
||||||
IOSystem* pIOHandler
|
|
||||||
);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
// loader settings, publicly accessible via their corresponding AI_CONFIG constants
|
// loader settings, publicly accessible via their corresponding AI_CONFIG constants
|
||||||
struct Settings
|
struct Settings {
|
||||||
{
|
Settings() :
|
||||||
Settings()
|
skipSpaceRepresentations(), useCustomTriangulation(), skipAnnotations(), conicSamplingAngle(10.f), cylindricalTessellation(32) {}
|
||||||
: skipSpaceRepresentations()
|
|
||||||
, useCustomTriangulation()
|
|
||||||
, skipAnnotations()
|
|
||||||
, conicSamplingAngle(10.f)
|
|
||||||
, cylindricalTessellation(32)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
bool skipSpaceRepresentations;
|
bool skipSpaceRepresentations;
|
||||||
bool useCustomTriangulation;
|
bool useCustomTriangulation;
|
||||||
|
@ -123,9 +87,27 @@ public:
|
||||||
int cylindricalTessellation;
|
int cylindricalTessellation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IFCImporter();
|
||||||
|
~IFCImporter() override;
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
bool CanRead(const std::string &pFile,
|
||||||
|
IOSystem *pIOHandler,
|
||||||
|
bool checkSig) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// --------------------
|
||||||
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
void SetupProperties(const Importer *pImp) override;
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
void InternReadFile(const std::string &pFile,
|
||||||
|
aiScene *pScene,
|
||||||
|
IOSystem *pIOHandler) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
||||||
}; // !class IFCImporter
|
}; // !class IFCImporter
|
||||||
|
|
|
@ -64,7 +64,7 @@ static int ConvertShadingMode(const std::string& name) {
|
||||||
else if (name == "PHONG") {
|
else if (name == "PHONG") {
|
||||||
return aiShadingMode_Phong;
|
return aiShadingMode_Phong;
|
||||||
}
|
}
|
||||||
IFCImporter::LogWarn("shading mode "+name+" not recognized by Assimp, using Phong instead");
|
IFCImporter::LogWarn("shading mode ", name, " not recognized by Assimp, using Phong instead");
|
||||||
return aiShadingMode_Phong;
|
return aiShadingMode_Phong;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ static void FillMaterial(aiMaterial* mat,const IFC::Schema_2x3::IfcSurfaceStyle*
|
||||||
mat->AddProperty(&name,AI_MATKEY_NAME);
|
mat->AddProperty(&name,AI_MATKEY_NAME);
|
||||||
|
|
||||||
// now see which kinds of surface information are present
|
// now see which kinds of surface information are present
|
||||||
for(std::shared_ptr< const IFC::Schema_2x3::IfcSurfaceStyleElementSelect > sel2 : surf->Styles) {
|
for (const std::shared_ptr<const IFC::Schema_2x3::IfcSurfaceStyleElementSelect> &sel2 : surf->Styles) {
|
||||||
if (const IFC::Schema_2x3::IfcSurfaceStyleShading* shade = sel2->ResolveSelectPtr<IFC::Schema_2x3::IfcSurfaceStyleShading>(conv.db)) {
|
if (const IFC::Schema_2x3::IfcSurfaceStyleShading* shade = sel2->ResolveSelectPtr<IFC::Schema_2x3::IfcSurfaceStyleShading>(conv.db)) {
|
||||||
aiColor4D col_base,col;
|
aiColor4D col_base,col;
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ unsigned int ProcessMaterials(uint64_t id, unsigned int prevMatId, ConversionDat
|
||||||
for(;range.first != range.second; ++range.first) {
|
for(;range.first != range.second; ++range.first) {
|
||||||
if(const IFC::Schema_2x3::IfcStyledItem* const styled = conv.db.GetObject((*range.first).second)->ToPtr<IFC::Schema_2x3::IfcStyledItem>()) {
|
if(const IFC::Schema_2x3::IfcStyledItem* const styled = conv.db.GetObject((*range.first).second)->ToPtr<IFC::Schema_2x3::IfcStyledItem>()) {
|
||||||
for(const IFC::Schema_2x3::IfcPresentationStyleAssignment& as : styled->Styles) {
|
for(const IFC::Schema_2x3::IfcPresentationStyleAssignment& as : styled->Styles) {
|
||||||
for(std::shared_ptr<const IFC::Schema_2x3::IfcPresentationStyleSelect> sel : as.Styles) {
|
for (const std::shared_ptr<const IFC::Schema_2x3::IfcPresentationStyleSelect> &sel : as.Styles) {
|
||||||
|
|
||||||
if( const IFC::Schema_2x3::IfcSurfaceStyle* const surf = sel->ResolveSelectPtr<IFC::Schema_2x3::IfcSurfaceStyle>(conv.db) ) {
|
if( const IFC::Schema_2x3::IfcSurfaceStyle* const surf = sel->ResolveSelectPtr<IFC::Schema_2x3::IfcSurfaceStyle>(conv.db) ) {
|
||||||
// try to satisfy from cache
|
// try to satisfy from cache
|
||||||
|
@ -145,7 +145,7 @@ unsigned int ProcessMaterials(uint64_t id, unsigned int prevMatId, ConversionDat
|
||||||
// not found, create new material
|
// not found, create new material
|
||||||
const std::string side = static_cast<std::string>(surf->Side);
|
const std::string side = static_cast<std::string>(surf->Side);
|
||||||
if( side != "BOTH" ) {
|
if( side != "BOTH" ) {
|
||||||
IFCImporter::LogWarn("ignoring surface side marker on IFC::IfcSurfaceStyle: " + side);
|
IFCImporter::LogWarn("ignoring surface side marker on IFC::IfcSurfaceStyle: ", side);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<aiMaterial> mat(new aiMaterial());
|
std::unique_ptr<aiMaterial> mat(new aiMaterial());
|
||||||
|
|
|
@ -68,7 +68,7 @@ bool ProcessCurve(const Schema_2x3::IfcCurve& curve, TempMesh& meshout, Convers
|
||||||
{
|
{
|
||||||
std::unique_ptr<const Curve> cv(Curve::Convert(curve,conv));
|
std::unique_ptr<const Curve> cv(Curve::Convert(curve,conv));
|
||||||
if (!cv) {
|
if (!cv) {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcCurve entity, type is " + curve.GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcCurve entity, type is ", curve.GetClassName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ bool ProcessCurve(const Schema_2x3::IfcCurve& curve, TempMesh& meshout, Convers
|
||||||
bc->SampleDiscrete(meshout);
|
bc->SampleDiscrete(meshout);
|
||||||
}
|
}
|
||||||
catch(const CurveError& cv) {
|
catch(const CurveError& cv) {
|
||||||
IFCImporter::LogError(cv.mStr + " (error occurred while processing curve)");
|
IFCImporter::LogError(cv.mStr, " (error occurred while processing curve)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
meshout.mVertcnt.push_back(static_cast<unsigned int>(meshout.mVerts.size()));
|
meshout.mVertcnt.push_back(static_cast<unsigned int>(meshout.mVerts.size()));
|
||||||
|
@ -152,7 +152,7 @@ void ProcessParametrizedProfile(const Schema_2x3::IfcParameterizedProfileDef& de
|
||||||
meshout.mVertcnt.push_back(12);
|
meshout.mVertcnt.push_back(12);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcParameterizedProfileDef entity, type is " + def.GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcParameterizedProfileDef entity, type is ", def.GetClassName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ bool ProcessProfile(const Schema_2x3::IfcProfileDef& prof, TempMesh& meshout, Co
|
||||||
ProcessParametrizedProfile(*cparam,meshout,conv);
|
ProcessParametrizedProfile(*cparam,meshout,conv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IFCImporter::LogWarn("skipping unknown IfcProfileDef entity, type is " + prof.GetClassName());
|
IFCImporter::LogWarn("skipping unknown IfcProfileDef entity, type is ", prof.GetClassName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
meshout.RemoveAdjacentDuplicates();
|
meshout.RemoveAdjacentDuplicates();
|
||||||
|
|
|
@ -49,7 +49,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "AssetLib/IFC/IFCUtil.h"
|
#include "AssetLib/IFC/IFCUtil.h"
|
||||||
#include "Common/PolyTools.h"
|
#include "Common/PolyTools.h"
|
||||||
#include "PostProcessing/ProcessHelper.h"
|
#include "PostProcessing/ProcessHelper.h"
|
||||||
#include <assimp/Defines.h>
|
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace IFC {
|
namespace IFC {
|
||||||
|
@ -506,7 +505,7 @@ IfcFloat ConvertSIPrefix(const std::string& prefix)
|
||||||
return 1e-18f;
|
return 1e-18f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
IFCImporter::LogError("Unrecognized SI prefix: " + prefix);
|
IFCImporter::LogError("Unrecognized SI prefix: ", prefix);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/mesh.h>
|
#include <assimp/mesh.h>
|
||||||
#include <assimp/material.h>
|
#include <assimp/material.h>
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
struct aiNode;
|
struct aiNode;
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
@ -139,12 +141,8 @@ struct TempOpening
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
TempOpening(const IFC::Schema_2x3::IfcSolidModel *solid, IfcVector3 extrusionDir,
|
TempOpening(const IFC::Schema_2x3::IfcSolidModel *solid, IfcVector3 extrusionDir,
|
||||||
std::shared_ptr<TempMesh> profileMesh,
|
std::shared_ptr<TempMesh> profileMesh,
|
||||||
std::shared_ptr<TempMesh> profileMesh2D)
|
std::shared_ptr<TempMesh> profileMesh2D) :
|
||||||
: solid(solid)
|
solid(solid), extrusionDir(extrusionDir), profileMesh(std::move(profileMesh)), profileMesh2D(std::move(profileMesh2D)) {
|
||||||
, extrusionDir(extrusionDir)
|
|
||||||
, profileMesh(profileMesh)
|
|
||||||
, profileMesh2D(profileMesh2D)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -106,7 +106,7 @@ bool IRRImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c
|
||||||
if (nullptr == pIOHandler) {
|
if (nullptr == pIOHandler) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const char *tokens[] = { "irr_scene" };
|
static const char * const tokens[] = { "irr_scene" };
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,7 +639,7 @@ void IRRImporter::GenerateGraph(Node *root, aiNode *rootOut, aiScene *scene,
|
||||||
// graph we're currently building
|
// graph we're currently building
|
||||||
aiScene *localScene = batch.GetImport(root->id);
|
aiScene *localScene = batch.GetImport(root->id);
|
||||||
if (!localScene) {
|
if (!localScene) {
|
||||||
ASSIMP_LOG_ERROR("IRR: Unable to load external file: " + root->meshPath);
|
ASSIMP_LOG_ERROR("IRR: Unable to load external file: ", root->meshPath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
attach.push_back(AttachmentInfo(localScene, rootOut));
|
attach.push_back(AttachmentInfo(localScene, rootOut));
|
||||||
|
@ -859,13 +859,13 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
|
|
||||||
// Check whether we can read from the file
|
// Check whether we can read from the file
|
||||||
if (file.get() == nullptr) {
|
if (file.get() == nullptr) {
|
||||||
throw DeadlyImportError("Failed to open IRR file " + pFile + "");
|
throw DeadlyImportError("Failed to open IRR file ", pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the irrXML parser
|
// Construct the irrXML parser
|
||||||
XmlParser st;
|
XmlParser st;
|
||||||
if (!st.parse( file.get() )) {
|
if (!st.parse( file.get() )) {
|
||||||
return;
|
throw DeadlyImportError("XML parse error while loading IRR file ", pFile);
|
||||||
}
|
}
|
||||||
pugi::xml_node rootElement = st.getRootNode();
|
pugi::xml_node rootElement = st.getRootNode();
|
||||||
|
|
||||||
|
@ -963,7 +963,7 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
ASSIMP_LOG_ERROR("IRR: Billboards are not supported by Assimp");
|
ASSIMP_LOG_ERROR("IRR: Billboards are not supported by Assimp");
|
||||||
nd = new Node(Node::DUMMY);
|
nd = new Node(Node::DUMMY);
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_WARN("IRR: Found unknown node: " + std::string(attrib.name()));
|
ASSIMP_LOG_WARN("IRR: Found unknown node: ", attrib.name());
|
||||||
|
|
||||||
/* We skip the contents of nodes we don't know.
|
/* We skip the contents of nodes we don't know.
|
||||||
* We parse the transformation and all animators
|
* We parse the transformation and all animators
|
||||||
|
@ -1181,7 +1181,7 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
lights.pop_back();
|
lights.pop_back();
|
||||||
curNode->type = Node::DUMMY;
|
curNode->type = Node::DUMMY;
|
||||||
|
|
||||||
ASSIMP_LOG_ERROR("Ignoring light of unknown type: " + prop.value);
|
ASSIMP_LOG_ERROR("Ignoring light of unknown type: ", prop.value);
|
||||||
}
|
}
|
||||||
} else if ((prop.name == "Mesh" && Node::MESH == curNode->type) ||
|
} else if ((prop.name == "Mesh" && Node::MESH == curNode->type) ||
|
||||||
Node::ANIMMESH == curNode->type) {
|
Node::ANIMMESH == curNode->type) {
|
||||||
|
@ -1225,7 +1225,7 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
||||||
} else if (prop.value == "followSpline") {
|
} else if (prop.value == "followSpline") {
|
||||||
curAnim->type = Animator::FOLLOW_SPLINE;
|
curAnim->type = Animator::FOLLOW_SPLINE;
|
||||||
} else {
|
} else {
|
||||||
ASSIMP_LOG_WARN("IRR: Ignoring unknown animator: " + prop.value);
|
ASSIMP_LOG_WARN("IRR: Ignoring unknown animator: ", prop.value);
|
||||||
|
|
||||||
curAnim->type = Animator::UNKNOWN;
|
curAnim->type = Animator::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,22 +65,21 @@ namespace Assimp {
|
||||||
class IRRImporter : public BaseImporter, public IrrlichtBase {
|
class IRRImporter : public BaseImporter, public IrrlichtBase {
|
||||||
public:
|
public:
|
||||||
IRRImporter();
|
IRRImporter();
|
||||||
~IRRImporter();
|
~IRRImporter() override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns whether the class can handle the format of the given file.
|
/** Returns whether the class can handle the format of the given file.
|
||||||
* See BaseImporter::CanRead() for details.
|
* See BaseImporter::CanRead() for details.
|
||||||
*/
|
*/
|
||||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const aiImporterDesc* GetInfo () const;
|
const aiImporterDesc* GetInfo () const override;
|
||||||
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) override;
|
||||||
void SetupProperties(const Importer* pImp);
|
void SetupProperties(const Importer* pImp) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Data structure for a scene-graph node animator
|
/** Data structure for a scene-graph node animator
|
||||||
*/
|
*/
|
||||||
struct Animator {
|
struct Animator {
|
||||||
|
|
|
@ -101,7 +101,7 @@ bool IRRMeshImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bo
|
||||||
* must return true here.
|
* must return true here.
|
||||||
*/
|
*/
|
||||||
if (!pIOHandler) return true;
|
if (!pIOHandler) return true;
|
||||||
const char *tokens[] = { "irrmesh" };
|
static const char * const tokens[] = { "irrmesh" };
|
||||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -135,12 +135,12 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
|
||||||
|
|
||||||
// Check whether we can read from the file
|
// Check whether we can read from the file
|
||||||
if (file.get() == NULL)
|
if (file.get() == NULL)
|
||||||
throw DeadlyImportError("Failed to open IRRMESH file " + pFile + "");
|
throw DeadlyImportError("Failed to open IRRMESH file ", pFile);
|
||||||
|
|
||||||
// Construct the irrXML parser
|
// Construct the irrXML parser
|
||||||
XmlParser parser;
|
XmlParser parser;
|
||||||
if (!parser.parse( file.get() )) {
|
if (!parser.parse( file.get() )) {
|
||||||
return;
|
throw DeadlyImportError("XML parse error while loading IRRMESH file ", pFile);
|
||||||
}
|
}
|
||||||
XmlNode root = parser.getRootNode();
|
XmlNode root = parser.getRootNode();
|
||||||
|
|
||||||
|
|
|
@ -63,28 +63,28 @@ namespace Assimp {
|
||||||
class IRRMeshImporter : public BaseImporter, public IrrlichtBase {
|
class IRRMeshImporter : public BaseImporter, public IrrlichtBase {
|
||||||
public:
|
public:
|
||||||
IRRMeshImporter();
|
IRRMeshImporter();
|
||||||
~IRRMeshImporter();
|
~IRRMeshImporter() override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns whether the class can handle the format of the given file.
|
/** Returns whether the class can handle the format of the given file.
|
||||||
* See BaseImporter::CanRead() for details.
|
* See BaseImporter::CanRead() for details.
|
||||||
*/
|
*/
|
||||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||||
bool checkSig) const;
|
bool checkSig) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Return importer meta information.
|
/** Return importer meta information.
|
||||||
* See #BaseImporter::GetInfo for the details
|
* See #BaseImporter::GetInfo for the details
|
||||||
*/
|
*/
|
||||||
const aiImporterDesc *GetInfo() const;
|
const aiImporterDesc *GetInfo() const override;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Imports the given file into the given scene structure.
|
/** Imports the given file into the given scene structure.
|
||||||
* See BaseImporter::InternReadFile() for details
|
* See BaseImporter::InternReadFile() for details
|
||||||
*/
|
*/
|
||||||
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||||
IOSystem *pIOHandler);
|
IOSystem *pIOHandler) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue