Merge branch 'master' into UnitTestBlenderSubdivision

pull/5345/head
Kim Kulling 2024-05-08 10:44:44 +02:00 committed by GitHub
commit c89688b363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
746 changed files with 6876 additions and 3516 deletions

View File

@ -54,7 +54,7 @@ jobs:
- name: Cache DX SDK - name: Cache DX SDK
id: dxcache id: dxcache
if: contains(matrix.name, 'windows') if: contains(matrix.name, 'windows')
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: '${{ github.workspace }}/DX_SDK' path: '${{ github.workspace }}/DX_SDK'
key: ${{ runner.os }}-DX_SDK key: ${{ runner.os }}-DX_SDK
@ -98,7 +98,7 @@ jobs:
run: cd build/bin && ./unit ${{ steps.hunter_extra_test_args.outputs.args }} run: cd build/bin && ./unit ${{ steps.hunter_extra_test_args.outputs.args }}
shell: bash shell: bash
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
if: matrix.name == 'windows-msvc' if: matrix.name == 'windows-msvc'
with: with:
name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}' name: 'assimp-bins-${{ matrix.name }}-${{ github.sha }}'

View File

@ -19,7 +19,7 @@ jobs:
dry-run: false dry-run: false
language: c++ language: c++
- name: Upload Crash - name: Upload Crash
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
if: failure() && steps.build.outcome == 'success' if: failure() && steps.build.outcome == 'success'
with: with:
name: artifacts name: artifacts

View File

@ -1,6 +1,6 @@
# Open Asset Import Library (assimp) # Open Asset Import Library (assimp)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Copyright (c) 2006-2023, assimp team # Copyright (c) 2006-2024, assimp team
# #
# All rights reserved. # All rights reserved.
# #
@ -38,9 +38,9 @@ SET(CMAKE_POLICY_DEFAULT_CMP0012 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW) SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0092 NEW) SET(CMAKE_POLICY_DEFAULT_CMP0092 NEW)
CMAKE_MINIMUM_REQUIRED( VERSION 3.10 ) CMAKE_MINIMUM_REQUIRED( VERSION 3.22 )
# Disabled importers: m3d for 5.1 # Disabled importers: m3d for 5.1 or later
ADD_DEFINITIONS( -DASSIMP_BUILD_NO_M3D_IMPORTER) ADD_DEFINITIONS( -DASSIMP_BUILD_NO_M3D_IMPORTER)
ADD_DEFINITIONS( -DASSIMP_BUILD_NO_M3D_EXPORTER) ADD_DEFINITIONS( -DASSIMP_BUILD_NO_M3D_EXPORTER)
# Toggles the use of the hunter package manager # Toggles the use of the hunter package manager
@ -49,13 +49,13 @@ option(ASSIMP_HUNTER_ENABLED "Enable Hunter package manager support" OFF)
IF(ASSIMP_HUNTER_ENABLED) IF(ASSIMP_HUNTER_ENABLED)
include("cmake-modules/HunterGate.cmake") include("cmake-modules/HunterGate.cmake")
HunterGate( HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.24.18.tar.gz" URL "https://github.com/cpp-pm/hunter/archive/v0.25.5.tar.gz"
SHA1 "1292e4d661e1770d6d6ca08c12c07cf34a0bf718" SHA1 "a20151e4c0740ee7d0f9994476856d813cdead29"
) )
add_definitions(-DASSIMP_USE_HUNTER) add_definitions(-DASSIMP_USE_HUNTER)
ENDIF() ENDIF()
PROJECT(Assimp VERSION 5.3.0) PROJECT(Assimp VERSION 5.4.0)
# All supported options ############################################### # All supported options ###############################################
@ -131,18 +131,18 @@ OPTION ( ASSIMP_IGNORE_GIT_HASH
IF (WIN32) IF (WIN32)
OPTION( ASSIMP_BUILD_ZLIB OPTION( ASSIMP_BUILD_ZLIB
"Build your own zlib" "Build your zlib"
ON ON
) )
ELSE() ELSE()
OPTION( ASSIMP_BUILD_ZLIB OPTION( ASSIMP_BUILD_ZLIB
"Build your own zlib" "Build your zlib"
ON OFF
) )
ENDIF() ENDIF()
IF (WIN32) IF (WIN32)
# Use subset of Windows.h # Use a subset of Windows.h
ADD_DEFINITIONS( -DWIN32_LEAN_AND_MEAN ) ADD_DEFINITIONS( -DWIN32_LEAN_AND_MEAN )
IF(MSVC) IF(MSVC)
@ -150,16 +150,16 @@ IF (WIN32)
"Install MSVC debug files." "Install MSVC debug files."
ON ) ON )
IF(NOT (MSVC_VERSION LESS 1900)) IF(NOT (MSVC_VERSION LESS 1900))
# Multibyte character set is deprecated since at least MSVC2015 (possibly earlier) # Multibyte character set has been deprecated since at least MSVC2015 (possibly earlier)
ADD_DEFINITIONS( -DUNICODE -D_UNICODE ) ADD_DEFINITIONS( -DUNICODE -D_UNICODE )
ENDIF() ENDIF()
# Link statically against c/c++ lib to avoid missing redistriburable such as # Link statically against c/c++ lib to avoid missing redistributable such as
# "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users # "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users
# a choice to opt for the shared runtime if they want. # a choice to opt for the shared runtime if they want.
option(USE_STATIC_CRT "Link against the static runtime libraries." OFF) option(USE_STATIC_CRT "Link against the static runtime libraries." OFF)
# The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative # The CMAKE_CXX_FLAGS vars can be overridden by some Visual Studio generators, so we use an alternative
# global method here: # global method here:
if (${USE_STATIC_CRT}) if (${USE_STATIC_CRT})
add_compile_options( add_compile_options(
@ -249,9 +249,9 @@ SET(ASSIMP_LIBRARY_SUFFIX "" CACHE STRING "Suffix to append to library names")
IF( UNIX ) IF( UNIX )
# Use GNUInstallDirs for Unix predefined directories # Use GNUInstallDirs for Unix predefined directories
INCLUDE(GNUInstallDirs) INCLUDE(GNUInstallDirs)
# Ensure that we do not run into issues like http://www.tcm.phy.cam.ac.uk/sw/inodes64.html on 32 bit linux # Ensure that we do not run into issues like http://www.tcm.phy.cam.ac.uk/sw/inodes64.html on 32 bit Linux
IF(NOT ${OPERATING_SYSTEM} MATCHES "Android") IF(NOT ${OPERATING_SYSTEM} MATCHES "Android")
IF ( CMAKE_SIZEOF_VOID_P EQUAL 4) # only necessary for 32-bit linux IF ( CMAKE_SIZEOF_VOID_P EQUAL 4) # only necessary for 32-bit Linux
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 ) ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 )
ENDIF() ENDIF()
ENDIF() ENDIF()
@ -289,7 +289,7 @@ ELSEIF(MSVC)
IF(MSVC12) IF(MSVC12)
ADD_COMPILE_OPTIONS(/wd4351) ADD_COMPILE_OPTIONS(/wd4351)
ENDIF() ENDIF()
# supress warning for double to float conversion if Double precission is activated # supress warning for double to float conversion if Double precision is activated
ADD_COMPILE_OPTIONS(/wd4244) ADD_COMPILE_OPTIONS(/wd4244)
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}") SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
@ -311,9 +311,9 @@ ELSEIF( MINGW )
SET(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") SET(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
ENDIF() ENDIF()
IF (CMAKE_BUILD_TYPE STREQUAL "Debug") IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long -Wa,-mbig-obj -g ${CMAKE_CXX_FLAGS}") SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wno-dangling-reference -Wall -Wno-long-long -Wa,-mbig-obj -g ${CMAKE_CXX_FLAGS}")
ELSE() ELSE()
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wall -Wno-long-long -Wa,-mbig-obj -O3 ${CMAKE_CXX_FLAGS}") SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -fno-strict-aliasing -Wno-dangling-reference -Wall -Wno-long-long -Wa,-mbig-obj -O3 ${CMAKE_CXX_FLAGS}")
ENDIF() ENDIF()
SET(CMAKE_C_FLAGS "-fno-strict-aliasing ${CMAKE_C_FLAGS}") SET(CMAKE_C_FLAGS "-fno-strict-aliasing ${CMAKE_C_FLAGS}")
ENDIF() ENDIF()
@ -452,18 +452,20 @@ configure_package_config_file(
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}" INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
) )
install( if(ASSIMP_INSTALL)
FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}" install(
DESTINATION "${CONFIG_INSTALL_DIR}" FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}"
COMPONENT ${LIBASSIMP-DEV_COMPONENT} DESTINATION "${CONFIG_INSTALL_DIR}"
) COMPONENT ${LIBASSIMP-DEV_COMPONENT}
)
install( install(
EXPORT "${TARGETS_EXPORT_NAME}" EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${NAMESPACE}" NAMESPACE "${NAMESPACE}"
DESTINATION "${CONFIG_INSTALL_DIR}" DESTINATION "${CONFIG_INSTALL_DIR}"
COMPONENT ${LIBASSIMP-DEV_COMPONENT} COMPONENT ${LIBASSIMP-DEV_COMPONENT}
) )
endif()
IF( ASSIMP_BUILD_DOCS ) IF( ASSIMP_BUILD_DOCS )
ADD_SUBDIRECTORY(doc) ADD_SUBDIRECTORY(doc)
@ -481,7 +483,7 @@ IF(ASSIMP_HUNTER_ENABLED)
set(ASSIMP_BUILD_MINIZIP TRUE) set(ASSIMP_BUILD_MINIZIP TRUE)
ELSE() ELSE()
# If the zlib is already found outside, add an export in case assimpTargets can't find it. # If the zlib is already found outside, add an export in case assimpTargets can't find it.
IF( ZLIB_FOUND ) IF( ZLIB_FOUND AND ASSIMP_INSTALL)
INSTALL( TARGETS zlib zlibstatic INSTALL( TARGETS zlib zlibstatic
EXPORT "${TARGETS_EXPORT_NAME}") EXPORT "${TARGETS_EXPORT_NAME}")
ENDIF() ENDIF()
@ -563,9 +565,9 @@ SET ( ASSIMP_BUILD_NONFREE_C4D_IMPORTER OFF CACHE BOOL
) )
IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER) IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
IF ( MSVC ) SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/includes")
SET(C4D_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/includes")
IF (WIN32)
# pick the correct prebuilt library # pick the correct prebuilt library
IF(MSVC143) IF(MSVC143)
SET(C4D_LIB_POSTFIX "_2022") SET(C4D_LIB_POSTFIX "_2022")
@ -583,7 +585,7 @@ IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
SET(C4D_LIB_POSTFIX "_2010") SET(C4D_LIB_POSTFIX "_2010")
ELSE() ELSE()
MESSAGE( FATAL_ERROR MESSAGE( FATAL_ERROR
"C4D is currently only supported with MSVC 10, 11, 12, 14, 14.2, 14.3" "C4D for Windows is currently only supported with MSVC 10, 11, 12, 14, 14.2, 14.3"
) )
ENDIF() ENDIF()
@ -601,15 +603,30 @@ IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
# winsock and winmm are necessary (and undocumented) dependencies of Cineware SDK because # winsock and winmm are necessary (and undocumented) dependencies of Cineware SDK because
# it can be used to communicate with a running Cinema 4D instance # 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)
ELSEIF (APPLE)
SET(C4D_LIB_BASE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Cineware/libraries/osx")
SET(C4D_DEBUG_LIBRARIES
"${C4D_LIB_BASE_PATH}/debug/libcinewarelib.a"
"${C4D_LIB_BASE_PATH}/debug/libjpeglib.a"
)
SET(C4D_RELEASE_LIBRARIES
"${C4D_LIB_BASE_PATH}/release/libcinewarelib.a"
"${C4D_LIB_BASE_PATH}/release/libjpeglib.a"
)
ELSE () ELSE ()
MESSAGE( FATAL_ERROR MESSAGE( FATAL_ERROR
"C4D is currently only available on Windows with Cineware SDK installed in contrib/Cineware" "C4D is currently only available on Windows and macOS with Cineware SDK installed in contrib/Cineware"
) )
ENDIF () ENDIF ()
ELSE () ELSE ()
ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER ) ADD_DEFINITIONS( -DASSIMP_BUILD_NO_C4D_IMPORTER )
ENDIF () ENDIF ()
if(ASSIMP_BUILD_DRACO_STATIC)
set(ASSIMP_BUILD_DRACO ON)
endif()
# Draco requires cmake 3.12 # Draco requires cmake 3.12
IF (DEFINED CMAKE_VERSION AND "${CMAKE_VERSION}" VERSION_LESS "3.12") IF (DEFINED CMAKE_VERSION AND "${CMAKE_VERSION}" VERSION_LESS "3.12")
message(NOTICE "draco requires cmake 3.12 or newer, cmake is ${CMAKE_VERSION} . Draco is disabled") message(NOTICE "draco requires cmake 3.12 or newer, cmake is ${CMAKE_VERSION} . Draco is disabled")
@ -645,22 +662,29 @@ ELSE()
"-Wno-sign-compare" "-Wno-sign-compare"
"-Wno-unused-local-typedefs" "-Wno-unused-local-typedefs"
) )
# Draco 1.4.1 does not explicitly export any symbols under GCC/clang
list(APPEND DRACO_CXX_FLAGS if(NOT ASSIMP_BUILD_DRACO_STATIC)
"-fvisibility=default" # Draco 1.4.1 does not explicitly export any symbols under GCC/clang
) list(APPEND DRACO_CXX_FLAGS
"-fvisibility=default"
)
endif()
ENDIF() ENDIF()
# Don't build or install all of Draco by default # Don't build or install all of Draco by default
ADD_SUBDIRECTORY( "contrib/draco" EXCLUDE_FROM_ALL ) ADD_SUBDIRECTORY( "contrib/draco" EXCLUDE_FROM_ALL )
if(ASSIMP_BUILD_DRACO_STATIC)
set_property(DIRECTORY "contrib/draco" PROPERTY BUILD_SHARED_LIBS OFF)
endif()
if(MSVC OR WIN32) if(MSVC OR WIN32)
set(draco_LIBRARIES "draco") set(draco_LIBRARIES "draco")
else() else()
if(BUILD_SHARED_LIBS) if(ASSIMP_BUILD_DRACO_STATIC)
set(draco_LIBRARIES "draco_shared")
else()
set(draco_LIBRARIES "draco_static") set(draco_LIBRARIES "draco_static")
else()
set(draco_LIBRARIES "draco_shared")
endif() endif()
endif() endif()
@ -683,15 +707,17 @@ ELSE()
set(draco_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/draco/src") set(draco_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/draco/src")
# This is probably wrong # This is probably wrong
INSTALL( TARGETS ${draco_LIBRARIES} if (ASSIMP_INSTALL)
EXPORT "${TARGETS_EXPORT_NAME}" INSTALL( TARGETS ${draco_LIBRARIES}
LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR} EXPORT "${TARGETS_EXPORT_NAME}"
ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR} LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR} ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR} RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR}
COMPONENT ${LIBASSIMP_COMPONENT} FRAMEWORK DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
INCLUDES DESTINATION include COMPONENT ${LIBASSIMP_COMPONENT}
) INCLUDES DESTINATION include
)
endif()
ENDIF() ENDIF()
ENDIF() ENDIF()
ENDIF() ENDIF()

View File

@ -6,6 +6,7 @@ RUN apt-get update && apt-get install -y ninja-build \
RUN add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update RUN add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update
WORKDIR /opt WORKDIR /opt
RUN apt install zlib1g-dev
# Build Assimp # Build Assimp
RUN git clone https://github.com/assimp/assimp.git /opt/assimp RUN git clone https://github.com/assimp/assimp.git /opt/assimp

View File

@ -16,26 +16,27 @@ APIs are provided for C and C++. There are various bindings to other languages (
Additionally, assimp features various __mesh post-processing tools__: normals and tangent space generation, triangulation, vertex cache locality optimization, removal of degenerate primitives and duplicate vertices, sorting by primitive type, merging of redundant materials and many more. Additionally, assimp features various __mesh post-processing tools__: normals and tangent space generation, triangulation, vertex cache locality optimization, removal of degenerate primitives and duplicate vertices, sorting by primitive type, merging of redundant materials and many more.
### Documentation ### ### Documentation ###
Please check the latest documents at [Asset-Importer-Lib-Doc](https://assimp-docs.readthedocs.io/en/latest/). Read [our latest documentation](https://assimp-docs.readthedocs.io/en/latest/).
### Pre-built binaries ### ### Pre-built binaries ###
Please check our [Itchi Projectspace](https://kimkulling.itch.io/the-asset-importer-lib) Download binaries from [our Itchi Projectspace](https://kimkulling.itch.io/the-asset-importer-lib).
If you want to check our Model-Database, use the following repo: https://github.com/assimp/assimp-mdb ### Test data ###
Clone [our model database](https://github.com/assimp/assimp-mdb).
### Communities ### ### Communities ###
- Ask a question at [The Assimp-Discussion Board](https://github.com/assimp/assimp/discussions) - Ask questions at [the Assimp Discussion Board](https://github.com/assimp/assimp/discussions).
- Ask on [Assimp-Community on Reddit](https://www.reddit.com/r/Assimp/) - Ask [the Assimp community on Reddit](https://www.reddit.com/r/Assimp/).
- Ask on [StackOverflow with the assimp-tag](http://stackoverflow.com/questions/tagged/assimp?sort=newest). - Ask on [StackOverflow with the assimp-tag](http://stackoverflow.com/questions/tagged/assimp?sort=newest).
- Nothing has worked? File a question or an issue-report at [The Assimp-Issue Tracker](https://github.com/assimp/assimp/issues) - Nothing has worked? File a question or an issue-report at [The Assimp-Issue Tracker](https://github.com/assimp/assimp/issues)
And we also have a Gitter-channel:Gitter [![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)<br> And we also have a Gitter-channel:Gitter [![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)<br>
#### Supported file formats #### #### Supported file formats ####
You can find the complete list of supported file-formats [here](https://github.com/assimp/assimp/blob/master/doc/Fileformats.md) See [the complete list of supported formats](https://github.com/assimp/assimp/blob/master/doc/Fileformats.md).
### Building ### ### Building ###
Take a look [here](https://github.com/assimp/assimp/blob/master/Build.md) to get started. We are available in vcpkg, and our build system is CMake; if you used CMake before there is a good chance you know what to do. Start by reading [our build instructions](https://github.com/assimp/assimp/blob/master/Build.md). We are available in vcpkg, and our build system is CMake; if you used CMake before there is a good chance you know what to do.
### Ports ### ### Ports ###
* [Android](port/AndroidJNI/README.md) * [Android](port/AndroidJNI/README.md)

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -57,6 +57,7 @@ enum class ResourceType {
RT_BaseMaterials, RT_BaseMaterials,
RT_EmbeddedTexture2D, RT_EmbeddedTexture2D,
RT_Texture2DGroup, RT_Texture2DGroup,
RT_ColorGroup,
RT_Unknown RT_Unknown
}; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...) }; // To be extended with other resource types (eg. material extension resources like Texture2d, Texture2dGroup...)
@ -117,6 +118,21 @@ public:
} }
}; };
class ColorGroup : public Resource {
public:
std::vector<aiColor4D> mColors;
ColorGroup(int id) :
Resource(id){
// empty
}
~ColorGroup() override = default;
ResourceType getType() const override {
return ResourceType::RT_ColorGroup;
}
};
class BaseMaterials : public Resource { class BaseMaterials : public Resource {
public: public:
std::vector<unsigned int> mMaterialIndex; std::vector<unsigned int> mMaterialIndex;

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -98,6 +98,11 @@ namespace XmlTag {
const char *const texture_cuurd_u = "u"; const char *const texture_cuurd_u = "u";
const char *const texture_cuurd_v = "v"; const char *const texture_cuurd_v = "v";
// vertex color definitions
const char *const colorgroup = "m:colorgroup";
const char *const color_item = "m:color";
const char *const color_vaule = "color";
// Meta info tags // Meta info tags
const char* const CONTENT_TYPES_ARCHIVE = "[Content_Types].xml"; const char* const CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
const char* const ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels"; const char* const ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -81,12 +81,17 @@ static constexpr aiImporterDesc desc = {
"3mf" "3mf"
}; };
bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bool /*checkSig*/) const { bool D3MFImporter::CanRead(const std::string &filename, IOSystem *pIOHandler, bool ) const {
if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) { if (!ZipArchiveIOSystem::isZipArchive(pIOHandler, filename)) {
return false; return false;
} }
D3MF::D3MFOpcPackage opcPackage(pIOHandler, filename); static const char *const ModelRef = "3D/3dmodel.model";
return opcPackage.validate(); ZipArchiveIOSystem archive(pIOHandler, filename);
if (!archive.Exists(ModelRef)) {
return false;
}
return true;
} }
void D3MFImporter::SetupProperties(const Importer*) { void D3MFImporter::SetupProperties(const Importer*) {

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -119,9 +119,9 @@ public:
static bool IsEmbeddedTexture( const std::string &filename ) { static bool IsEmbeddedTexture( const std::string &filename ) {
const std::string extension = BaseImporter::GetExtension(filename); const std::string extension = BaseImporter::GetExtension(filename);
if (extension == "jpg" || extension == "png") { if (extension == "jpg" || extension == "png" || extension == "jpeg") {
std::string::size_type pos = filename.find("thumbnail"); std::string::size_type pos = filename.find("thumbnail");
if (pos == std::string::npos) { if (pos != std::string::npos) {
return false; return false;
} }
return true; return true;

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -75,7 +75,7 @@ aiFace ReadTriangle(XmlNode &node, int &texId0, int &texId1, int &texId2) {
face.mIndices[1] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v2).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())); face.mIndices[2] = static_cast<unsigned int>(std::atoi(node.attribute(XmlTag::v3).as_string()));
texId0 = texId1 = texId2 = -1; texId0 = texId1 = texId2 = IdNotSet;
XmlParser::getIntAttribute(node, XmlTag::p1, texId0); XmlParser::getIntAttribute(node, XmlTag::p1, texId0);
XmlParser::getIntAttribute(node, XmlTag::p2, texId1); XmlParser::getIntAttribute(node, XmlTag::p2, texId1);
XmlParser::getIntAttribute(node, XmlTag::p3, texId2); XmlParser::getIntAttribute(node, XmlTag::p3, texId2);
@ -236,6 +236,8 @@ void XmlSerializer::ImportXml(aiScene *scene) {
ReadBaseMaterials(currentNode); ReadBaseMaterials(currentNode);
} else if (currentNodeName == XmlTag::meta) { } else if (currentNodeName == XmlTag::meta) {
ReadMetadata(currentNode); ReadMetadata(currentNode);
} else if (currentNodeName == XmlTag::colorgroup) {
ReadColorGroup(currentNode);
} }
} }
StoreMaterialsInScene(scene); StoreMaterialsInScene(scene);
@ -331,9 +333,49 @@ void XmlSerializer::ReadObject(XmlNode &node) {
if (hasPid) { if (hasPid) {
auto it = mResourcesDictionnary.find(pid); auto it = mResourcesDictionnary.find(pid);
if (hasPindex && it != mResourcesDictionnary.end() && it->second->getType() == ResourceType::RT_BaseMaterials) { if (hasPindex && it != mResourcesDictionnary.end()) {
BaseMaterials *materials = static_cast<BaseMaterials *>(it->second); if (it->second->getType() == ResourceType::RT_BaseMaterials) {
mesh->mMaterialIndex = materials->mMaterialIndex[pindex]; BaseMaterials *materials = static_cast<BaseMaterials *>(it->second);
mesh->mMaterialIndex = materials->mMaterialIndex[pindex];
} else if (it->second->getType() == ResourceType::RT_Texture2DGroup) {
Texture2DGroup *group = static_cast<Texture2DGroup *>(it->second);
if (mesh->mTextureCoords[0] == nullptr) {
mesh->mNumUVComponents[0] = 2;
for (unsigned int i = 1; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
mesh->mNumUVComponents[i] = 0;
}
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[mesh->mNumVertices];
for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) {
mesh->mTextureCoords[0][vertex_idx] =
aiVector3D(group->mTex2dCoords[pindex].x, group->mTex2dCoords[pindex].y, 0.0f);
}
} else {
for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) {
if (mesh->mTextureCoords[0][vertex_idx].z < 0) {
// use default
mesh->mTextureCoords[0][vertex_idx] =
aiVector3D(group->mTex2dCoords[pindex].x, group->mTex2dCoords[pindex].y, 0.0f);
}
}
}
}else if (it->second->getType() == ResourceType::RT_ColorGroup) {
if (mesh->mColors[0] == nullptr) {
mesh->mColors[0] = new aiColor4D[mesh->mNumVertices];
ColorGroup *group = static_cast<ColorGroup *>(it->second);
for (unsigned int vertex_idx = 0; vertex_idx < mesh->mNumVertices; vertex_idx++) {
mesh->mColors[0][vertex_idx] = group->mColors[pindex];
}
}
}
} }
} }
@ -415,27 +457,36 @@ void XmlSerializer::ImportTriangles(XmlNode &node, aiMesh *mesh) {
for (XmlNode &currentNode : node.children()) { for (XmlNode &currentNode : node.children()) {
const std::string currentName = currentNode.name(); const std::string currentName = currentNode.name();
if (currentName == XmlTag::triangle) { if (currentName == XmlTag::triangle) {
int pid = IdNotSet, p1 = IdNotSet; int pid = IdNotSet;
bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid); bool hasPid = getNodeAttribute(currentNode, D3MF::XmlTag::pid, pid);
bool hasP1 = getNodeAttribute(currentNode, D3MF::XmlTag::p1, p1);
int texId[3]; int pindex[3];
Texture2DGroup *group = nullptr; aiFace face = ReadTriangle(currentNode, pindex[0], pindex[1], pindex[2]);
aiFace face = ReadTriangle(currentNode, texId[0], texId[1], texId[2]); if (hasPid && (pindex[0] != IdNotSet || pindex[1] != IdNotSet || pindex[2] != IdNotSet)) {
if (hasPid && hasP1) {
auto it = mResourcesDictionnary.find(pid); auto it = mResourcesDictionnary.find(pid);
if (it != mResourcesDictionnary.end()) { if (it != mResourcesDictionnary.end()) {
if (it->second->getType() == ResourceType::RT_BaseMaterials) { if (it->second->getType() == ResourceType::RT_BaseMaterials) {
BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second); BaseMaterials *baseMaterials = static_cast<BaseMaterials *>(it->second);
mesh->mMaterialIndex = baseMaterials->mMaterialIndex[p1];
auto update_material = [&](int idx) {
if (pindex[idx] != IdNotSet) {
mesh->mMaterialIndex = baseMaterials->mMaterialIndex[pindex[idx]];
}
};
update_material(0);
update_material(1);
update_material(2);
} else if (it->second->getType() == ResourceType::RT_Texture2DGroup) { } else if (it->second->getType() == ResourceType::RT_Texture2DGroup) {
// Load texture coordinates into mesh, when any
Texture2DGroup *group = static_cast<Texture2DGroup *>(it->second); // fix bug
if (mesh->mTextureCoords[0] == nullptr) { if (mesh->mTextureCoords[0] == nullptr) {
mesh->mNumUVComponents[0] = 2; mesh->mNumUVComponents[0] = 2;
for (unsigned int i = 1; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { for (unsigned int i = 1; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
mesh->mNumUVComponents[i] = 0; mesh->mNumUVComponents[i] = 0;
} }
group = static_cast<Texture2DGroup *>(it->second);
const std::string name = ai_to_string(group->mTexId); const std::string name = ai_to_string(group->mTexId);
for (size_t i = 0; i < mMaterials.size(); ++i) { for (size_t i = 0; i < mMaterials.size(); ++i) {
if (name == mMaterials[i]->GetName().C_Str()) { if (name == mMaterials[i]->GetName().C_Str()) {
@ -443,21 +494,44 @@ void XmlSerializer::ImportTriangles(XmlNode &node, aiMesh *mesh) {
} }
} }
mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices]; mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices];
for (unsigned int vertex_index = 0; vertex_index < mesh->mNumVertices; vertex_index++) {
mesh->mTextureCoords[0][vertex_index].z = IdNotSet;//mark not set
}
} }
auto update_texture = [&](int idx) {
if (pindex[idx] != IdNotSet) {
size_t vertex_index = face.mIndices[idx];
mesh->mTextureCoords[0][vertex_index] =
aiVector3D(group->mTex2dCoords[pindex[idx]].x, group->mTex2dCoords[pindex[idx]].y, 0.0f);
}
};
update_texture(0);
update_texture(1);
update_texture(2);
} else if (it->second->getType() == ResourceType::RT_ColorGroup) {
// Load vertex color into mesh, when any
ColorGroup *group = static_cast<ColorGroup *>(it->second);
if (mesh->mColors[0] == nullptr) {
mesh->mColors[0] = new aiColor4D[mesh->mNumVertices];
}
auto update_color = [&](int idx) {
if (pindex[idx] != IdNotSet) {
size_t vertex_index = face.mIndices[idx];
mesh->mColors[0][vertex_index] = group->mColors[pindex[idx]];
}
};
update_color(0);
update_color(1);
update_color(2);
} }
} }
} }
// Load texture coordinates into mesh, when any
if (group != nullptr) {
size_t i0 = face.mIndices[0];
size_t i1 = face.mIndices[1];
size_t i2 = face.mIndices[2];
mesh->mTextureCoords[0][i0] = aiVector3D(group->mTex2dCoords[texId[0]].x, group->mTex2dCoords[texId[0]].y, 0.0f);
mesh->mTextureCoords[0][i1] = aiVector3D(group->mTex2dCoords[texId[1]].x, group->mTex2dCoords[texId[1]].y, 0.0f);
mesh->mTextureCoords[0][i2] = aiVector3D(group->mTex2dCoords[texId[2]].x, group->mTex2dCoords[texId[2]].y, 0.0f);
}
faces.push_back(face); faces.push_back(face);
} }
} }
@ -598,6 +672,38 @@ aiMaterial *XmlSerializer::readMaterialDef(XmlNode &node, unsigned int basemater
return material; return material;
} }
void XmlSerializer::ReadColor(XmlNode &node, ColorGroup *colorGroup) {
if (node.empty() || nullptr == colorGroup) {
return;
}
for (XmlNode currentNode : node.children()) {
const std::string currentName = currentNode.name();
if (currentName == XmlTag::color_item) {
const char *color = currentNode.attribute(XmlTag::color_vaule).as_string();
aiColor4D color_value;
if (parseColor(color, color_value)) {
colorGroup->mColors.push_back(color_value);
}
}
}
}
void XmlSerializer::ReadColorGroup(XmlNode &node) {
if (node.empty()) {
return;
}
int id = IdNotSet;
if (!XmlParser::getIntAttribute(node, XmlTag::id, id)) {
return;
}
ColorGroup *group = new ColorGroup(id);
ReadColor(node, group);
mResourcesDictionnary.insert(std::make_pair(id, group));
}
void XmlSerializer::StoreMaterialsInScene(aiScene *scene) { void XmlSerializer::StoreMaterialsInScene(aiScene *scene) {
if (nullptr == scene) { if (nullptr == scene) {
return; return;

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -57,6 +57,7 @@ class D3MFOpcPackage;
class Object; class Object;
class Texture2DGroup; class Texture2DGroup;
class EmbeddedTexture; class EmbeddedTexture;
class ColorGroup;
class XmlSerializer { class XmlSerializer {
public: public:
@ -78,6 +79,8 @@ private:
void ReadTextureGroup(XmlNode &node); void ReadTextureGroup(XmlNode &node);
aiMaterial *readMaterialDef(XmlNode &node, unsigned int basematerialsId); aiMaterial *readMaterialDef(XmlNode &node, unsigned int basematerialsId);
void StoreMaterialsInScene(aiScene *scene); void StoreMaterialsInScene(aiScene *scene);
void ReadColorGroup(XmlNode &node);
void ReadColor(XmlNode &node, ColorGroup *colorGroup);
private: private:
struct MetaEntry { struct MetaEntry {

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -77,8 +77,8 @@ static constexpr aiImporterDesc desc = {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// skip to the next token // skip to the next token
inline const char *AcSkipToNextToken(const char *buffer) { inline const char *AcSkipToNextToken(const char *buffer, const char *end) {
if (!SkipSpaces(&buffer)) { if (!SkipSpaces(&buffer, end)) {
ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL"); ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL");
} }
return buffer; return buffer;
@ -86,13 +86,13 @@ inline const char *AcSkipToNextToken(const char *buffer) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// read a string (may be enclosed in double quotation marks). buffer must point to " // read a string (may be enclosed in double quotation marks). buffer must point to "
inline const char *AcGetString(const char *buffer, std::string &out) { inline const char *AcGetString(const char *buffer, const char *end, std::string &out) {
if (*buffer == '\0') { if (*buffer == '\0') {
throw DeadlyImportError("AC3D: Unexpected EOF in string"); throw DeadlyImportError("AC3D: Unexpected EOF in string");
} }
++buffer; ++buffer;
const char *sz = buffer; const char *sz = buffer;
while ('\"' != *buffer) { while ('\"' != *buffer && buffer != end) {
if (IsLineEnd(*buffer)) { if (IsLineEnd(*buffer)) {
ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL in string"); ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL in string");
out = "ERROR"; out = "ERROR";
@ -112,8 +112,8 @@ inline const char *AcGetString(const char *buffer, std::string &out) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// read 1 to n floats prefixed with an optional predefined identifier // read 1 to n floats prefixed with an optional predefined identifier
template <class T> template <class T>
inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *name, size_t name_length, size_t num, T *out) { inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *end, const char *name, size_t name_length, size_t num, T *out) {
buffer = AcSkipToNextToken(buffer); buffer = AcSkipToNextToken(buffer, end);
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: Unexpected token. ", name, " was expected."); ASSIMP_LOG_ERROR("AC3D: Unexpected token. ", name, " was expected.");
@ -122,7 +122,7 @@ inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *name
buffer += name_length + 1; buffer += name_length + 1;
} }
for (unsigned int _i = 0; _i < num; ++_i) { for (unsigned int _i = 0; _i < num; ++_i) {
buffer = AcSkipToNextToken(buffer); buffer = AcSkipToNextToken(buffer, end);
buffer = fast_atoreal_move<float>(buffer, ((float *)out)[_i]); buffer = fast_atoreal_move<float>(buffer, ((float *)out)[_i]);
} }
@ -132,7 +132,7 @@ inline const char *TAcCheckedLoadFloatArray(const char *buffer, const char *name
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer // Constructor to be privately used by Importer
AC3DImporter::AC3DImporter() : AC3DImporter::AC3DImporter() :
buffer(), mBuffer(),
configSplitBFCull(), configSplitBFCull(),
configEvalSubdivision(), configEvalSubdivision(),
mNumMeshes(), mNumMeshes(),
@ -164,17 +164,17 @@ const aiImporterDesc *AC3DImporter::GetInfo() const {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Get a pointer to the next line from the file // Get a pointer to the next line from the file
bool AC3DImporter::GetNextLine() { bool AC3DImporter::GetNextLine() {
SkipLine(&buffer); SkipLine(&mBuffer.data, mBuffer.end);
return SkipSpaces(&buffer); return SkipSpaces(&mBuffer.data, mBuffer.end);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Parse an object section in an AC file // Parse an object section in an AC file
void AC3DImporter::LoadObjectSection(std::vector<Object> &objects) { bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
if (!TokenMatch(buffer, "OBJECT", 6)) if (!TokenMatch(mBuffer.data, "OBJECT", 6))
return; return false;
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
++mNumMeshes; ++mNumMeshes;
@ -182,7 +182,7 @@ void AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
Object &obj = objects.back(); Object &obj = objects.back();
aiLight *light = nullptr; aiLight *light = nullptr;
if (!ASSIMP_strincmp(buffer, "light", 5)) { if (!ASSIMP_strincmp(mBuffer.data, "light", 5)) {
// This is a light source. Add it to the list // This is a light source. Add it to the list
mLights->push_back(light = new aiLight()); mLights->push_back(light = new aiLight());
@ -198,62 +198,66 @@ void AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
ASSIMP_LOG_VERBOSE_DEBUG("AC3D: Light source encountered"); ASSIMP_LOG_VERBOSE_DEBUG("AC3D: Light source encountered");
obj.type = Object::Light; obj.type = Object::Light;
} else if (!ASSIMP_strincmp(buffer, "group", 5)) { } else if (!ASSIMP_strincmp(mBuffer.data, "group", 5)) {
obj.type = Object::Group; obj.type = Object::Group;
} else if (!ASSIMP_strincmp(buffer, "world", 5)) { } else if (!ASSIMP_strincmp(mBuffer.data, "world", 5)) {
obj.type = Object::World; obj.type = Object::World;
} else } else
obj.type = Object::Poly; obj.type = Object::Poly;
while (GetNextLine()) { while (GetNextLine()) {
if (TokenMatch(buffer, "kids", 4)) { if (TokenMatch(mBuffer.data, "kids", 4)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
unsigned int num = strtoul10(buffer, &buffer); unsigned int num = strtoul10(mBuffer.data, &mBuffer.data);
GetNextLine(); GetNextLine();
if (num) { if (num) {
// load the children of this object recursively // load the children of this object recursively
obj.children.reserve(num); obj.children.reserve(num);
for (unsigned int i = 0; i < num; ++i) for (unsigned int i = 0; i < num; ++i) {
LoadObjectSection(obj.children); if (!LoadObjectSection(obj.children)) {
ASSIMP_LOG_WARN("AC3D: wrong number of kids");
break;
}
}
} }
return; return true;
} else if (TokenMatch(buffer, "name", 4)) { } else if (TokenMatch(mBuffer.data, "name", 4)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.data);
buffer = AcGetString(buffer, obj.name); mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, obj.name);
// If this is a light source, we'll also need to store // If this is a light source, we'll also need to store
// the name of the node in it. // the name of the node in it.
if (light) { if (light) {
light->mName.Set(obj.name); light->mName.Set(obj.name);
} }
} else if (TokenMatch(buffer, "texture", 7)) { } else if (TokenMatch(mBuffer.data, "texture", 7)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
std::string texture; std::string texture;
buffer = AcGetString(buffer, texture); mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, texture);
obj.textures.push_back(texture); obj.textures.push_back(texture);
} else if (TokenMatch(buffer, "texrep", 6)) { } else if (TokenMatch(mBuffer.data, "texrep", 6)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 2, &obj.texRepeat); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 2, &obj.texRepeat);
if (!obj.texRepeat.x || !obj.texRepeat.y) if (!obj.texRepeat.x || !obj.texRepeat.y)
obj.texRepeat = aiVector2D(1.f, 1.f); obj.texRepeat = aiVector2D(1.f, 1.f);
} else if (TokenMatch(buffer, "texoff", 6)) { } else if (TokenMatch(mBuffer.data, "texoff", 6)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 2, &obj.texOffset); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 2, &obj.texOffset);
} else if (TokenMatch(buffer, "rot", 3)) { } else if (TokenMatch(mBuffer.data, "rot", 3)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 9, &obj.rotation); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 9, &obj.rotation);
} else if (TokenMatch(buffer, "loc", 3)) { } else if (TokenMatch(mBuffer.data, "loc", 3)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 3, &obj.translation); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 3, &obj.translation);
} else if (TokenMatch(buffer, "subdiv", 6)) { } else if (TokenMatch(mBuffer.data, "subdiv", 6)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
obj.subDiv = strtoul10(buffer, &buffer); obj.subDiv = strtoul10(mBuffer.data, &mBuffer.data);
} else if (TokenMatch(buffer, "crease", 6)) { } else if (TokenMatch(mBuffer.data, "crease", 6)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
obj.crease = fast_atof(buffer); obj.crease = fast_atof(mBuffer.data);
} else if (TokenMatch(buffer, "numvert", 7)) { } else if (TokenMatch(mBuffer.data, "numvert", 7)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
unsigned int t = strtoul10(buffer, &buffer); unsigned int t = strtoul10(mBuffer.data, &mBuffer.data);
if (t >= AI_MAX_ALLOC(aiVector3D)) { if (t >= AI_MAX_ALLOC(aiVector3D)) {
throw DeadlyImportError("AC3D: Too many vertices, would run out of memory"); throw DeadlyImportError("AC3D: Too many vertices, would run out of memory");
} }
@ -262,59 +266,59 @@ void AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
if (!GetNextLine()) { if (!GetNextLine()) {
ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: not all vertices have been parsed yet"); ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: not all vertices have been parsed yet");
break; break;
} else if (!IsNumeric(*buffer)) { } else if (!IsNumeric(*mBuffer.data)) {
ASSIMP_LOG_ERROR("AC3D: Unexpected token: not all vertices have been parsed yet"); ASSIMP_LOG_ERROR("AC3D: Unexpected token: not all vertices have been parsed yet");
--buffer; // make sure the line is processed a second time --mBuffer.data; // make sure the line is processed a second time
break; break;
} }
obj.vertices.emplace_back(); obj.vertices.emplace_back();
aiVector3D &v = obj.vertices.back(); aiVector3D &v = obj.vertices.back();
buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 3, &v.x); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 3, &v.x);
} }
} else if (TokenMatch(buffer, "numsurf", 7)) { } else if (TokenMatch(mBuffer.data, "numsurf", 7)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
bool Q3DWorkAround = false; bool Q3DWorkAround = false;
const unsigned int t = strtoul10(buffer, &buffer); const unsigned int t = strtoul10(mBuffer.data, &mBuffer.data);
obj.surfaces.reserve(t); obj.surfaces.reserve(t);
for (unsigned int i = 0; i < t; ++i) { for (unsigned int i = 0; i < t; ++i) {
GetNextLine(); GetNextLine();
if (!TokenMatch(buffer, "SURF", 4)) { if (!TokenMatch(mBuffer.data, "SURF", 4)) {
// FIX: this can occur for some files - Quick 3D for // FIX: this can occur for some files - Quick 3D for
// example writes no surf chunks // example writes no surf chunks
if (!Q3DWorkAround) { if (!Q3DWorkAround) {
ASSIMP_LOG_WARN("AC3D: SURF token was expected"); ASSIMP_LOG_WARN("AC3D: SURF token was expected");
ASSIMP_LOG_VERBOSE_DEBUG("Continuing with Quick3D Workaround enabled"); ASSIMP_LOG_VERBOSE_DEBUG("Continuing with Quick3D Workaround enabled");
} }
--buffer; // make sure the line is processed a second time --mBuffer.data; // make sure the line is processed a second time
// break; --- see fix notes above // break; --- see fix notes above
Q3DWorkAround = true; Q3DWorkAround = true;
} }
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
obj.surfaces.emplace_back(); obj.surfaces.emplace_back();
Surface &surf = obj.surfaces.back(); Surface &surf = obj.surfaces.back();
surf.flags = strtoul_cppstyle(buffer); surf.flags = strtoul_cppstyle(mBuffer.data);
while (true) { while (true) {
if (!GetNextLine()) { if (!GetNextLine()) {
throw DeadlyImportError("AC3D: Unexpected EOF: surface is incomplete"); throw DeadlyImportError("AC3D: Unexpected EOF: surface is incomplete");
} }
if (TokenMatch(buffer, "mat", 3)) { if (TokenMatch(mBuffer.data, "mat", 3)) {
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
surf.mat = strtoul10(buffer); surf.mat = strtoul10(mBuffer.data);
} else if (TokenMatch(buffer, "refs", 4)) { } else if (TokenMatch(mBuffer.data, "refs", 4)) {
// --- see fix notes above // --- see fix notes above
if (Q3DWorkAround) { if (Q3DWorkAround) {
if (!surf.entries.empty()) { if (!surf.entries.empty()) {
buffer -= 6; mBuffer.data -= 6;
break; break;
} }
} }
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
const unsigned int m = strtoul10(buffer); const unsigned int m = strtoul10(mBuffer.data);
surf.entries.reserve(m); surf.entries.reserve(m);
obj.numRefs += m; obj.numRefs += m;
@ -327,12 +331,12 @@ void AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
surf.entries.emplace_back(); surf.entries.emplace_back();
Surface::SurfaceEntry &entry = surf.entries.back(); Surface::SurfaceEntry &entry = surf.entries.back();
entry.first = strtoul10(buffer, &buffer); entry.first = strtoul10(mBuffer.data, &mBuffer.data);
SkipSpaces(&buffer); SkipSpaces(&mBuffer.data, mBuffer.end);
buffer = TAcCheckedLoadFloatArray(buffer, "", 0, 2, &entry.second); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "", 0, 2, &entry.second);
} }
} else { } else {
--buffer; // make sure the line is processed a second time --mBuffer.data; // make sure the line is processed a second time
break; break;
} }
} }
@ -340,6 +344,7 @@ void AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
} }
} }
ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: \'kids\' line was expected"); ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: \'kids\' line was expected");
return false;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -445,7 +450,7 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
idx = 0; idx = 0;
} }
if ((*it).entries.empty()) { if ((*it).entries.empty()) {
ASSIMP_LOG_WARN("AC3D: surface her zero vertex references"); ASSIMP_LOG_WARN("AC3D: surface has zero vertex references");
} }
// validate all vertex indices to make sure we won't crash here // validate all vertex indices to make sure we won't crash here
@ -463,16 +468,15 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
} }
switch ((*it).GetType()) { switch ((*it).GetType()) {
// closed line case Surface::ClosedLine: // closed line
case Surface::ClosedLine: needMat[idx].first += static_cast<unsigned int>((*it).entries.size());
needMat[idx].first += (unsigned int)(*it).entries.size(); needMat[idx].second += static_cast<unsigned int>((*it).entries.size() << 1u);
needMat[idx].second += (unsigned int)(*it).entries.size() << 1u;
break; break;
// unclosed line // unclosed line
case Surface::OpenLine: case Surface::OpenLine:
needMat[idx].first += (unsigned int)(*it).entries.size() - 1; needMat[idx].first += static_cast<unsigned int>((*it).entries.size() - 1);
needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u; needMat[idx].second += static_cast<unsigned int>(((*it).entries.size() - 1) << 1u);
break; break;
// triangle strip // triangle strip
@ -574,15 +578,6 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
const Surface::SurfaceEntry &entry2 = src.entries[i + 1]; const Surface::SurfaceEntry &entry2 = src.entries[i + 1];
const Surface::SurfaceEntry &entry3 = src.entries[i + 2]; const Surface::SurfaceEntry &entry3 = src.entries[i + 2];
// skip degenerate triangles
if (object.vertices[entry1.first] == object.vertices[entry2.first] ||
object.vertices[entry1.first] == object.vertices[entry3.first] ||
object.vertices[entry2.first] == object.vertices[entry3.first]) {
mesh->mNumFaces--;
mesh->mNumVertices -= 3;
continue;
}
aiFace &face = *faces++; aiFace &face = *faces++;
face.mNumIndices = 3; face.mNumIndices = 3;
face.mIndices = new unsigned int[face.mNumIndices]; face.mIndices = new unsigned int[face.mNumIndices];
@ -760,17 +755,18 @@ void AC3DImporter::InternReadFile(const std::string &pFile,
std::vector<char> mBuffer2; std::vector<char> mBuffer2;
TextFileToBuffer(file.get(), mBuffer2); TextFileToBuffer(file.get(), mBuffer2);
buffer = &mBuffer2[0]; mBuffer.data = &mBuffer2[0];
mBuffer.end = &mBuffer2[0] + mBuffer2.size();
mNumMeshes = 0; mNumMeshes = 0;
mLightsCounter = mPolysCounter = mWorldsCounter = mGroupsCounter = 0; mLightsCounter = mPolysCounter = mWorldsCounter = mGroupsCounter = 0;
if (::strncmp(buffer, "AC3D", 4)) { if (::strncmp(mBuffer.data, "AC3D", 4)) {
throw DeadlyImportError("AC3D: No valid AC3D file, magic sequence not found"); throw DeadlyImportError("AC3D: No valid AC3D file, magic sequence not found");
} }
// print the file format version to the console // print the file format version to the console
unsigned int version = HexDigitToDecimal(buffer[4]); unsigned int version = HexDigitToDecimal(mBuffer.data[4]);
char msg[3]; char msg[3];
ASSIMP_itoa10(msg, 3, version); ASSIMP_itoa10(msg, 3, version);
ASSIMP_LOG_INFO("AC3D file format version: ", msg); ASSIMP_LOG_INFO("AC3D file format version: ", msg);
@ -785,30 +781,31 @@ void AC3DImporter::InternReadFile(const std::string &pFile,
mLights = &lights; mLights = &lights;
while (GetNextLine()) { while (GetNextLine()) {
if (TokenMatch(buffer, "MATERIAL", 8)) { if (TokenMatch(mBuffer.data, "MATERIAL", 8)) {
materials.emplace_back(); materials.emplace_back();
Material &mat = materials.back(); Material &mat = materials.back();
// manually parse the material ... sscanf would use the buldin atof ... // manually parse the material ... sscanf would use the buldin atof ...
// Format: (name) rgb %f %f %f amb %f %f %f emis %f %f %f spec %f %f %f shi %d trans %f // Format: (name) rgb %f %f %f amb %f %f %f emis %f %f %f spec %f %f %f shi %d trans %f
buffer = AcSkipToNextToken(buffer); mBuffer.data = AcSkipToNextToken(mBuffer.data, mBuffer.end);
if ('\"' == *buffer) { if ('\"' == *mBuffer.data) {
buffer = AcGetString(buffer, mat.name); mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, mat.name);
buffer = AcSkipToNextToken(buffer); mBuffer.data = AcSkipToNextToken(mBuffer.data, mBuffer.end);
} }
buffer = TAcCheckedLoadFloatArray(buffer, "rgb", 3, 3, &mat.rgb); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "rgb", 3, 3, &mat.rgb);
buffer = TAcCheckedLoadFloatArray(buffer, "amb", 3, 3, &mat.amb); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "amb", 3, 3, &mat.amb);
buffer = TAcCheckedLoadFloatArray(buffer, "emis", 4, 3, &mat.emis); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "emis", 4, 3, &mat.emis);
buffer = TAcCheckedLoadFloatArray(buffer, "spec", 4, 3, &mat.spec); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "spec", 4, 3, &mat.spec);
buffer = TAcCheckedLoadFloatArray(buffer, "shi", 3, 1, &mat.shin); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "shi", 3, 1, &mat.shin);
buffer = TAcCheckedLoadFloatArray(buffer, "trans", 5, 1, &mat.trans); mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "trans", 5, 1, &mat.trans);
} else {
LoadObjectSection(rootObjects);
} }
LoadObjectSection(rootObjects);
} }
if (rootObjects.empty() || !mNumMeshes) { if (rootObjects.empty() || mNumMeshes == 0u) {
throw DeadlyImportError("AC3D: No meshes have been loaded"); throw DeadlyImportError("AC3D: No meshes have been loaded");
} }
if (materials.empty()) { if (materials.empty()) {
@ -824,7 +821,7 @@ void AC3DImporter::InternReadFile(const std::string &pFile,
materials.reserve(mNumMeshes); materials.reserve(mNumMeshes);
// generate a dummy root if there are multiple objects on the top layer // generate a dummy root if there are multiple objects on the top layer
Object *root; Object *root = nullptr;
if (1 == rootObjects.size()) if (1 == rootObjects.size())
root = &rootObjects[0]; root = &rootObjects[0];
else { else {
@ -837,7 +834,7 @@ void AC3DImporter::InternReadFile(const std::string &pFile,
delete root; delete root;
} }
if (!::strncmp(pScene->mRootNode->mName.data, "Node", 4)) { if (::strncmp(pScene->mRootNode->mName.data, "Node", 4) == 0) {
pScene->mRootNode->mName.Set("<AC3DWorld>"); pScene->mRootNode->mName.Set("<AC3DWorld>");
} }
@ -856,7 +853,7 @@ void AC3DImporter::InternReadFile(const std::string &pFile,
// copy lights // copy lights
pScene->mNumLights = (unsigned int)lights.size(); pScene->mNumLights = (unsigned int)lights.size();
if (lights.size()) { if (!lights.empty()) {
pScene->mLights = new aiLight *[lights.size()]; pScene->mLights = new aiLight *[lights.size()];
::memcpy(pScene->mLights, &lights[0], lights.size() * sizeof(void *)); ::memcpy(pScene->mLights, &lights[0], lights.size() * sizeof(void *));
} }

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -216,7 +216,7 @@ private:
* load subobjects, the method returns after a 'kids 0' was * load subobjects, the method returns after a 'kids 0' was
* encountered. * encountered.
* @objects List of output objects*/ * @objects List of output objects*/
void LoadObjectSection(std::vector<Object> &objects); bool LoadObjectSection(std::vector<Object> &objects);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Convert all objects into meshes and nodes. /** Convert all objects into meshes and nodes.
@ -242,7 +242,7 @@ private:
private: private:
// points to the next data line // points to the next data line
const char *buffer; aiBuffer mBuffer;
// Configuration option: if enabled, up to two meshes // Configuration option: if enabled, up to two meshes
// are generated per material: those faces who have // are generated per material: those faces who have

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -110,10 +110,12 @@ using namespace Assimp::ASE;
++filePtr; ++filePtr;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Parser::Parser(const char *szFile, unsigned int fileFormatDefault) { Parser::Parser(const char *szFile, unsigned int fileFormatDefault) :
filePtr(nullptr), mEnd (nullptr) {
ai_assert(nullptr != szFile); ai_assert(nullptr != szFile);
filePtr = szFile; filePtr = szFile;
mEnd = filePtr + std::strlen(filePtr);
iFileFormat = fileFormatDefault; iFileFormat = fileFormatDefault;
// make sure that the color values are invalid // make sure that the color values are invalid
@ -179,14 +181,22 @@ bool Parser::SkipToNextToken() {
while (true) { while (true) {
char me = *filePtr; char me = *filePtr;
if (filePtr == mEnd) {
return false;
}
// increase the line number counter if necessary // increase the line number counter if necessary
if (IsLineEnd(me) && !bLastWasEndLine) { if (IsLineEnd(me) && !bLastWasEndLine) {
++iLineNumber; ++iLineNumber;
bLastWasEndLine = true; bLastWasEndLine = true;
} else } else
bLastWasEndLine = false; bLastWasEndLine = false;
if ('*' == me || '}' == me || '{' == me) return true; if ('*' == me || '}' == me || '{' == me) {
if ('\0' == me) return false; return true;
}
if ('\0' == me) {
return false;
}
++filePtr; ++filePtr;
} }
@ -344,8 +354,9 @@ void Parser::ParseLV1SoftSkinBlock() {
unsigned int numVerts = 0; unsigned int numVerts = 0;
const char *sz = filePtr; const char *sz = filePtr;
while (!IsSpaceOrNewLine(*filePtr)) while (!IsSpaceOrNewLine(*filePtr)) {
++filePtr; ++filePtr;
}
const unsigned int diff = (unsigned int)(filePtr - sz); const unsigned int diff = (unsigned int)(filePtr - sz);
if (diff) { if (diff) {
@ -363,24 +374,24 @@ void Parser::ParseLV1SoftSkinBlock() {
// Skip the mesh data - until we find a new mesh // Skip the mesh data - until we find a new mesh
// or the end of the *MESH_SOFTSKINVERTS section // or the end of the *MESH_SOFTSKINVERTS section
while (true) { while (true) {
SkipSpacesAndLineEnd(&filePtr); SkipSpacesAndLineEnd(&filePtr, mEnd);
if (*filePtr == '}') { if (*filePtr == '}') {
++filePtr; ++filePtr;
return; return;
} else if (!IsNumeric(*filePtr)) } else if (!IsNumeric(*filePtr))
break; break;
SkipLine(&filePtr); SkipLine(&filePtr, mEnd);
} }
} else { } else {
SkipSpacesAndLineEnd(&filePtr); SkipSpacesAndLineEnd(&filePtr, mEnd);
ParseLV4MeshLong(numVerts); ParseLV4MeshLong(numVerts);
// Reserve enough storage // Reserve enough storage
curMesh->mBoneVertices.reserve(numVerts); curMesh->mBoneVertices.reserve(numVerts);
for (unsigned int i = 0; i < numVerts; ++i) { for (unsigned int i = 0; i < numVerts; ++i) {
SkipSpacesAndLineEnd(&filePtr); SkipSpacesAndLineEnd(&filePtr, mEnd);
unsigned int numWeights; unsigned int numWeights;
ParseLV4MeshLong(numWeights); ParseLV4MeshLong(numWeights);
@ -422,7 +433,7 @@ void Parser::ParseLV1SoftSkinBlock() {
if (*filePtr == '\0') if (*filePtr == '\0')
return; return;
++filePtr; ++filePtr;
SkipSpacesAndLineEnd(&filePtr); SkipSpacesAndLineEnd(&filePtr, mEnd);
} }
} }
@ -489,6 +500,13 @@ void Parser::ParseLV1MaterialListBlock() {
continue; continue;
} }
if (TokenMatch(filePtr, "MATERIAL", 8)) { if (TokenMatch(filePtr, "MATERIAL", 8)) {
// ensure we have at least one material allocated
if (iMaterialCount == 0) {
LogWarning("*MATERIAL_COUNT unspecified or 0");
iMaterialCount = 1;
m_vMaterials.resize(iOldMaterialCount + iMaterialCount, Material("INVALID"));
}
unsigned int iIndex = 0; unsigned int iIndex = 0;
ParseLV4MeshLong(iIndex); ParseLV4MeshLong(iIndex);
@ -642,6 +660,12 @@ void Parser::ParseLV2MaterialBlock(ASE::Material &mat) {
} }
// submaterial chunks // submaterial chunks
if (TokenMatch(filePtr, "SUBMATERIAL", 11)) { if (TokenMatch(filePtr, "SUBMATERIAL", 11)) {
// ensure we have at least one material allocated
if (iNumSubMaterials == 0) {
LogWarning("*NUMSUBMTLS unspecified or 0");
iNumSubMaterials = 1;
mat.avSubMaterials.resize(iNumSubMaterials, Material("INVALID SUBMATERIAL"));
}
unsigned int iIndex = 0; unsigned int iIndex = 0;
ParseLV4MeshLong(iIndex); ParseLV4MeshLong(iIndex);
@ -743,7 +767,7 @@ void Parser::ParseLV3MapBlock(Texture &map) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool Parser::ParseString(std::string &out, const char *szName) { bool Parser::ParseString(std::string &out, const char *szName) {
char szBuffer[1024]; char szBuffer[1024];
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Unexpected EOL", szName); ai_snprintf(szBuffer, 1024, "Unable to parse %s block: Unexpected EOL", szName);
LogWarning(szBuffer); LogWarning(szBuffer);
@ -1355,7 +1379,7 @@ void Parser::ParseLV4MeshBones(unsigned int iNumBones, ASE::Mesh &mesh) {
// Mesh bone with name ... // Mesh bone with name ...
if (TokenMatch(filePtr, "MESH_BONE_NAME", 14)) { if (TokenMatch(filePtr, "MESH_BONE_NAME", 14)) {
// parse an index ... // parse an index ...
if (SkipSpaces(&filePtr)) { if (SkipSpaces(&filePtr, mEnd)) {
unsigned int iIndex = strtoul10(filePtr, &filePtr); unsigned int iIndex = strtoul10(filePtr, &filePtr);
if (iIndex >= iNumBones) { if (iIndex >= iNumBones) {
LogWarning("Bone index is out of bounds"); LogWarning("Bone index is out of bounds");
@ -1395,11 +1419,11 @@ void Parser::ParseLV4MeshBonesVertices(unsigned int iNumVertices, ASE::Mesh &mes
std::pair<int, float> pairOut; std::pair<int, float> pairOut;
while (true) { while (true) {
// first parse the bone index ... // first parse the bone index ...
if (!SkipSpaces(&filePtr)) break; if (!SkipSpaces(&filePtr, mEnd)) break;
pairOut.first = strtoul10(filePtr, &filePtr); pairOut.first = strtoul10(filePtr, &filePtr);
// then parse the vertex weight // then parse the vertex weight
if (!SkipSpaces(&filePtr)) break; if (!SkipSpaces(&filePtr, mEnd)) break;
filePtr = fast_atoreal_move<float>(filePtr, pairOut.second); filePtr = fast_atoreal_move<float>(filePtr, pairOut.second);
// -1 marks unused entries // -1 marks unused entries
@ -1675,7 +1699,7 @@ void Parser::ParseLV3MeshNormalListBlock(ASE::Mesh &sMesh) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFace(ASE::Face &out) { void Parser::ParseLV4MeshFace(ASE::Face &out) {
// skip spaces and tabs // skip spaces and tabs
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]"); LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL [#1]");
SkipToNextToken(); SkipToNextToken();
return; return;
@ -1685,7 +1709,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) {
out.iFace = strtoul10(filePtr, &filePtr); out.iFace = strtoul10(filePtr, &filePtr);
// next character should be ':' // next character should be ':'
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
// FIX: there are some ASE files which haven't got : here .... // FIX: there are some ASE files which haven't got : here ....
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]"); LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. \':\' expected [#2]");
SkipToNextToken(); SkipToNextToken();
@ -1697,7 +1721,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) {
// Parse all mesh indices // Parse all mesh indices
for (unsigned int i = 0; i < 3; ++i) { for (unsigned int i = 0; i < 3; ++i) {
unsigned int iIndex = 0; unsigned int iIndex = 0;
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL"); LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL");
SkipToNextToken(); SkipToNextToken();
return; return;
@ -1723,7 +1747,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) {
++filePtr; ++filePtr;
// next character should be ':' // next character should be ':'
if (!SkipSpaces(&filePtr) || ':' != *filePtr) { if (!SkipSpaces(&filePtr, mEnd) || ':' != *filePtr) {
LogWarning("Unable to parse *MESH_FACE Element: " LogWarning("Unable to parse *MESH_FACE Element: "
"Unexpected EOL. \':\' expected [#2]"); "Unexpected EOL. \':\' expected [#2]");
SkipToNextToken(); SkipToNextToken();
@ -1731,9 +1755,9 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) {
} }
++filePtr; ++filePtr;
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. " LogWarning("Unable to parse *MESH_FACE Element: Unexpected EOL. "
"Vertex index ecpected [#4]"); "Vertex index expected [#4]");
SkipToNextToken(); SkipToNextToken();
return; return;
} }
@ -1752,7 +1776,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) {
// parse the smoothing group of the face // parse the smoothing group of the face
if (TokenMatch(filePtr, "*MESH_SMOOTHING", 15)) { if (TokenMatch(filePtr, "*MESH_SMOOTHING", 15)) {
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
LogWarning("Unable to parse *MESH_SMOOTHING Element: " LogWarning("Unable to parse *MESH_SMOOTHING Element: "
"Unexpected EOL. Smoothing group(s) expected [#5]"); "Unexpected EOL. Smoothing group(s) expected [#5]");
SkipToNextToken(); SkipToNextToken();
@ -1771,12 +1795,12 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) {
LogWarning(message.c_str()); LogWarning(message.c_str());
} }
} }
SkipSpaces(&filePtr); SkipSpaces(&filePtr, mEnd);
if (',' != *filePtr) { if (',' != *filePtr) {
break; break;
} }
++filePtr; ++filePtr;
SkipSpaces(&filePtr); SkipSpaces(&filePtr, mEnd);
} }
} }
@ -1792,7 +1816,7 @@ void Parser::ParseLV4MeshFace(ASE::Face &out) {
} }
if (TokenMatch(filePtr, "*MESH_MTLID", 11)) { if (TokenMatch(filePtr, "*MESH_MTLID", 11)) {
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. " LogWarning("Unable to parse *MESH_MTLID Element: Unexpected EOL. "
"Material index expected [#6]"); "Material index expected [#6]");
SkipToNextToken(); SkipToNextToken();
@ -1840,7 +1864,7 @@ void Parser::ParseLV4MeshFloatTriple(ai_real *apOut) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshFloat(ai_real &fOut) { void Parser::ParseLV4MeshFloat(ai_real &fOut) {
// skip spaces and tabs // skip spaces and tabs
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
// LOG // LOG
LogWarning("Unable to parse float: unexpected EOL [#1]"); LogWarning("Unable to parse float: unexpected EOL [#1]");
fOut = 0.0; fOut = 0.0;
@ -1853,7 +1877,7 @@ void Parser::ParseLV4MeshFloat(ai_real &fOut) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Parser::ParseLV4MeshLong(unsigned int &iOut) { void Parser::ParseLV4MeshLong(unsigned int &iOut) {
// Skip spaces and tabs // Skip spaces and tabs
if (!SkipSpaces(&filePtr)) { if (!SkipSpaces(&filePtr, mEnd)) {
// LOG // LOG
LogWarning("Unable to parse long: unexpected EOL [#1]"); LogWarning("Unable to parse long: unexpected EOL [#1]");
iOut = 0; iOut = 0;

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -620,6 +620,9 @@ public:
//! Pointer to current data //! Pointer to current data
const char *filePtr; const char *filePtr;
/// The end pointer of the file data
const char *mEnd;
//! background color to be passed to the viewer //! background color to be passed to the viewer
//! QNAN if none was found //! QNAN if none was found
aiColor3D m_clrBackground; aiColor3D m_clrBackground;

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -4,7 +4,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team

View File

@ -4,7 +4,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, 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,

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, 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,

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -46,10 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// no #ifdefing here, Cinema4D support is carried out in a branch of assimp // no #ifdefing here, Cinema4D support is carried out in a branch of assimp
// where it is turned on in the CMake settings. // where it is turned on in the CMake settings.
#ifndef _MSC_VER
# error C4D support is currently MSVC only
#endif
#include "C4DImporter.h" #include "C4DImporter.h"
#include <memory> #include <memory>
#include <assimp/IOSystem.hpp> #include <assimp/IOSystem.hpp>
@ -111,7 +107,7 @@ C4DImporter::C4DImporter() = default;
C4DImporter::~C4DImporter() = default; C4DImporter::~C4DImporter() = default;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
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);
if (extension == "c4d") { if (extension == "c4d") {
return true; return true;
@ -305,7 +301,7 @@ void C4DImporter::RecurseHierarchy(BaseObject* object, aiNode* parent) {
// based on Cineware sample code // based on Cineware sample code
while (object) { while (object) {
const LONG type = object->GetType(); const Int32 type = object->GetType();
const Matrix& ml = object->GetMl(); const Matrix& ml = object->GetMl();
aiNode* const nd = new aiNode(); aiNode* const nd = new aiNode();
@ -368,8 +364,8 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) {
PolygonObject* const polyObject = dynamic_cast<PolygonObject*>(object); PolygonObject* const polyObject = dynamic_cast<PolygonObject*>(object);
ai_assert(polyObject != nullptr); ai_assert(polyObject != nullptr);
const LONG pointCount = polyObject->GetPointCount(); const Int32 pointCount = polyObject->GetPointCount();
const LONG polyCount = polyObject->GetPolygonCount(); const Int32 polyCount = polyObject->GetPolygonCount();
if(!polyObject || !pointCount) { if(!polyObject || !pointCount) {
LogWarn("ignoring mesh with zero vertices or faces"); LogWarn("ignoring mesh with zero vertices or faces");
return nullptr; return nullptr;
@ -391,7 +387,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) {
unsigned int vcount = 0; unsigned int vcount = 0;
// first count vertices // first count vertices
for (LONG i = 0; i < polyCount; i++) for (Int32 i = 0; i < polyCount; i++)
{ {
vcount += 3; vcount += 3;
@ -434,7 +430,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) {
} }
// copy vertices and extra channels over and populate faces // copy vertices and extra channels over and populate faces
for (LONG i = 0; i < polyCount; ++i, ++face) { for (Int32 i = 0; i < polyCount; ++i, ++face) {
ai_assert(polys[i].a < pointCount && polys[i].a >= 0); ai_assert(polys[i].a < pointCount && polys[i].a >= 0);
const Vector& pointA = points[polys[i].a]; const Vector& pointA = points[polys[i].a];
verts->x = pointA.x; verts->x = pointA.x;
@ -511,7 +507,7 @@ aiMesh* C4DImporter::ReadMesh(BaseObject* object) {
if (tangents_src) { if (tangents_src) {
for(unsigned int k = 0; k < face->mNumIndices; ++k) { for(unsigned int k = 0; k < face->mNumIndices; ++k) {
LONG l; Int32 l;
switch(k) { switch(k) {
case 0: case 0:
l = polys[i].a; l = polys[i].a;

View File

@ -78,6 +78,8 @@ namespace Assimp {
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
class C4DImporter : public BaseImporter, public LogFunctions<C4DImporter> { class C4DImporter : public BaseImporter, public LogFunctions<C4DImporter> {
public: public:
C4DImporter();
~C4DImporter() override;
bool CanRead( const std::string& pFile, IOSystem*, bool checkSig) const override; bool CanRead( const std::string& pFile, IOSystem*, bool checkSig) const override;
protected: protected:

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -473,8 +473,9 @@ void COBImporter::ReadBasicNodeInfo_Ascii(Node &msh, LineSplitter &splitter, con
} else if (splitter.match_start("Transform")) { } else if (splitter.match_start("Transform")) {
for (unsigned int y = 0; y < 4 && ++splitter; ++y) { for (unsigned int y = 0; y < 4 && ++splitter; ++y) {
const char *s = splitter->c_str(); const char *s = splitter->c_str();
const char *end = s + splitter->size();
for (unsigned int x = 0; x < 4; ++x) { for (unsigned int x = 0; x < 4; ++x) {
SkipSpaces(&s); SkipSpaces(&s, end);
msh.transform[y][x] = fast_atof(&s); msh.transform[y][x] = fast_atof(&s);
} }
} }
@ -486,12 +487,12 @@ void COBImporter::ReadBasicNodeInfo_Ascii(Node &msh, LineSplitter &splitter, con
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
void COBImporter::ReadFloat3Tuple_Ascii(T &fill, const char **in) { void COBImporter::ReadFloat3Tuple_Ascii(T &fill, const char **in, const char *end) {
const char *rgb = *in; const char *rgb = *in;
for (unsigned int i = 0; i < 3; ++i) { for (unsigned int i = 0; i < 3; ++i) {
SkipSpaces(&rgb); SkipSpaces(&rgb, end);
if (*rgb == ',') ++rgb; if (*rgb == ',') ++rgb;
SkipSpaces(&rgb); SkipSpaces(&rgb, end);
fill[i] = fast_atof(&rgb); fill[i] = fast_atof(&rgb);
} }
@ -538,7 +539,7 @@ void COBImporter::ReadMat1_Ascii(Scene &out, LineSplitter &splitter, const Chunk
} }
const char *rgb = splitter[1]; const char *rgb = splitter[1];
ReadFloat3Tuple_Ascii(mat.rgb, &rgb); ReadFloat3Tuple_Ascii(mat.rgb, &rgb, splitter.getEnd());
++splitter; ++splitter;
if (!splitter.match_start("alpha ")) { if (!splitter.match_start("alpha ")) {
@ -617,20 +618,21 @@ void COBImporter::ReadLght_Ascii(Scene &out, LineSplitter &splitter, const Chunk
} }
const char *rgb = splitter[1]; const char *rgb = splitter[1];
ReadFloat3Tuple_Ascii(msh.color, &rgb); const char *end = splitter.getEnd();
ReadFloat3Tuple_Ascii(msh.color, &rgb, end);
SkipSpaces(&rgb); SkipSpaces(&rgb, end);
if (strncmp(rgb, "cone angle", 10) != 0) { if (strncmp(rgb, "cone angle", 10) != 0) {
ASSIMP_LOG_WARN("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, end);
msh.angle = fast_atof(&rgb); msh.angle = fast_atof(&rgb);
SkipSpaces(&rgb); SkipSpaces(&rgb, end);
if (strncmp(rgb, "inner angle", 11) != 0) { if (strncmp(rgb, "inner angle", 11) != 0) {
ASSIMP_LOG_WARN("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, end);
msh.inner_angle = fast_atof(&rgb); msh.inner_angle = fast_atof(&rgb);
// skip the rest for we can't handle this kind of physically-based lighting information. // skip the rest for we can't handle this kind of physically-based lighting information.
@ -703,14 +705,14 @@ void COBImporter::ReadPolH_Ascii(Scene &out, LineSplitter &splitter, const Chunk
for (unsigned int cur = 0; cur < cnt && ++splitter; ++cur) { for (unsigned int cur = 0; cur < cnt && ++splitter; ++cur) {
const char *s = splitter->c_str(); const char *s = splitter->c_str();
const char *end = splitter.getEnd();
aiVector3D &v = msh.vertex_positions[cur]; aiVector3D &v = msh.vertex_positions[cur];
SkipSpaces(&s); SkipSpaces(&s, end);
v.x = fast_atof(&s); v.x = fast_atof(&s);
SkipSpaces(&s); SkipSpaces(&s, end);
v.y = fast_atof(&s); v.y = fast_atof(&s);
SkipSpaces(&s); SkipSpaces(&s, end);
v.z = fast_atof(&s); v.z = fast_atof(&s);
} }
} else if (splitter.match_start("Texture Vertices")) { } else if (splitter.match_start("Texture Vertices")) {
@ -719,12 +721,13 @@ void COBImporter::ReadPolH_Ascii(Scene &out, LineSplitter &splitter, const Chunk
for (unsigned int cur = 0; cur < cnt && ++splitter; ++cur) { for (unsigned int cur = 0; cur < cnt && ++splitter; ++cur) {
const char *s = splitter->c_str(); const char *s = splitter->c_str();
const char *end = splitter.getEnd();
aiVector2D &v = msh.texture_coords[cur]; aiVector2D &v = msh.texture_coords[cur];
SkipSpaces(&s); SkipSpaces(&s, end);
v.x = fast_atof(&s); v.x = fast_atof(&s);
SkipSpaces(&s); SkipSpaces(&s, end);
v.y = fast_atof(&s); v.y = fast_atof(&s);
} }
} else if (splitter.match_start("Faces")) { } else if (splitter.match_start("Faces")) {
@ -749,8 +752,9 @@ void COBImporter::ReadPolH_Ascii(Scene &out, LineSplitter &splitter, const Chunk
face.material = strtoul10(splitter[6]); face.material = strtoul10(splitter[6]);
const char *s = (++splitter)->c_str(); const char *s = (++splitter)->c_str();
const char *end = splitter.getEnd();
for (size_t i = 0; i < face.indices.size(); ++i) { for (size_t i = 0; i < face.indices.size(); ++i) {
if (!SkipSpaces(&s)) { if (!SkipSpaces(&s, end)) {
ThrowException("Expected EOL token in Face entry"); ThrowException("Expected EOL token in Face entry");
} }
if ('<' != *s++) { if ('<' != *s++) {

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -120,7 +120,7 @@ private:
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> template <typename T>
void ReadFloat3Tuple_Ascii(T &fill, const char **in); void ReadFloat3Tuple_Ascii(T &fill, const char **in, const char *end);
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);

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
@ -82,23 +82,20 @@ CSMImporter::CSMImporter() : noSkeletonMesh(){
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file. // Returns whether the class can handle the format of the given file.
bool CSMImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const bool CSMImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const {
{
static const char* tokens[] = {"$Filename"}; static const char* tokens[] = {"$Filename"};
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,AI_COUNT_OF(tokens)); return SearchFileHeaderForToken(pIOHandler,pFile,tokens,AI_COUNT_OF(tokens));
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Build a string of all file extensions supported // Build a string of all file extensions supported
const aiImporterDesc* CSMImporter::GetInfo () const const aiImporterDesc* CSMImporter::GetInfo () const {
{
return &desc; return &desc;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Setup configuration properties for the loader // Setup configuration properties for the loader
void CSMImporter::SetupProperties(const Importer* pImp) void CSMImporter::SetupProperties(const Importer* pImp) {
{
noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0; noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,0) != 0;
} }
@ -118,29 +115,29 @@ void CSMImporter::InternReadFile( const std::string& pFile,
std::vector<char> mBuffer2; std::vector<char> mBuffer2;
TextFileToBuffer(file.get(),mBuffer2); TextFileToBuffer(file.get(),mBuffer2);
const char* buffer = &mBuffer2[0]; const char* buffer = &mBuffer2[0];
const char *end = &mBuffer2[mBuffer2.size() - 1] + 1;
std::unique_ptr<aiAnimation> anim(new aiAnimation()); std::unique_ptr<aiAnimation> anim(new aiAnimation());
int first = 0, last = 0x00ffffff; int first = 0, last = 0x00ffffff;
// now process the file and look out for '$' sections // now process the file and look out for '$' sections
while (true) { while (true) {
SkipSpaces(&buffer); SkipSpaces(&buffer, end);
if ('\0' == *buffer) if ('\0' == *buffer)
break; break;
if ('$' == *buffer) { if ('$' == *buffer) {
++buffer; ++buffer;
if (TokenMatchI(buffer,"firstframe",10)) { if (TokenMatchI(buffer,"firstframe",10)) {
SkipSpaces(&buffer); SkipSpaces(&buffer, end);
first = strtol10(buffer,&buffer); first = strtol10(buffer,&buffer);
} }
else if (TokenMatchI(buffer,"lastframe",9)) { else if (TokenMatchI(buffer,"lastframe",9)) {
SkipSpaces(&buffer); SkipSpaces(&buffer, end);
last = strtol10(buffer,&buffer); last = strtol10(buffer,&buffer);
} }
else if (TokenMatchI(buffer,"rate",4)) { else if (TokenMatchI(buffer,"rate",4)) {
SkipSpaces(&buffer); SkipSpaces(&buffer, end);
float d; float d = { 0.0f };
buffer = fast_atoreal_move<float>(buffer,d); buffer = fast_atoreal_move<float>(buffer,d);
anim->mTicksPerSecond = d; anim->mTicksPerSecond = d;
} }
@ -148,8 +145,8 @@ void CSMImporter::InternReadFile( const std::string& pFile,
std::vector< aiNodeAnim* > anims_temp; std::vector< aiNodeAnim* > anims_temp;
anims_temp.reserve(30); anims_temp.reserve(30);
while (true) { while (true) {
SkipSpaces(&buffer); SkipSpaces(&buffer, end);
if (IsLineEnd(*buffer) && SkipSpacesAndLineEnd(&buffer) && *buffer == '$') if (IsLineEnd(*buffer) && SkipSpacesAndLineEnd(&buffer, end) && *buffer == '$')
break; // next section break; // next section
// Construct a new node animation channel and setup its name // Construct a new node animation channel and setup its name
@ -157,41 +154,43 @@ void CSMImporter::InternReadFile( const std::string& pFile,
aiNodeAnim* nda = anims_temp.back(); aiNodeAnim* nda = anims_temp.back();
char* ot = nda->mNodeName.data; char* ot = nda->mNodeName.data;
while (!IsSpaceOrNewLine(*buffer)) while (!IsSpaceOrNewLine(*buffer)) {
*ot++ = *buffer++; *ot++ = *buffer++;
}
*ot = '\0'; *ot = '\0';
nda->mNodeName.length = static_cast<ai_uint32>(ot-nda->mNodeName.data); nda->mNodeName.length = static_cast<ai_uint32>(ot-nda->mNodeName.data);
} }
anim->mNumChannels = static_cast<unsigned int>(anims_temp.size()); anim->mNumChannels = static_cast<unsigned int>(anims_temp.size());
if (!anim->mNumChannels) if (!anim->mNumChannels) {
throw DeadlyImportError("CSM: Empty $order section"); throw DeadlyImportError("CSM: Empty $order section");
}
// copy over to the output animation // copy over to the output animation
anim->mChannels = new aiNodeAnim*[anim->mNumChannels]; anim->mChannels = new aiNodeAnim*[anim->mNumChannels];
::memcpy(anim->mChannels,&anims_temp[0],sizeof(aiNodeAnim*)*anim->mNumChannels); ::memcpy(anim->mChannels,&anims_temp[0],sizeof(aiNodeAnim*)*anim->mNumChannels);
} } else if (TokenMatchI(buffer,"points",6)) {
else if (TokenMatchI(buffer,"points",6)) { if (!anim->mNumChannels) {
if (!anim->mNumChannels)
throw DeadlyImportError("CSM: \'$order\' section is required to appear prior to \'$points\'"); throw DeadlyImportError("CSM: \'$order\' section is required to appear prior to \'$points\'");
}
// If we know how many frames we'll read, we can preallocate some storage // If we know how many frames we'll read, we can preallocate some storage
unsigned int alloc = 100; unsigned int alloc = 100;
if (last != 0x00ffffff) if (last != 0x00ffffff) {
{
alloc = last-first; alloc = last-first;
alloc += alloc>>2u; // + 25% alloc += alloc>>2u; // + 25%
for (unsigned int i = 0; i < anim->mNumChannels;++i) for (unsigned int i = 0; i < anim->mNumChannels; ++i) {
anim->mChannels[i]->mPositionKeys = new aiVectorKey[alloc]; anim->mChannels[i]->mPositionKeys = new aiVectorKey[alloc];
}
} }
unsigned int filled = 0; unsigned int filled = 0;
// Now read all point data. // Now read all point data.
while (true) { while (true) {
SkipSpaces(&buffer); SkipSpaces(&buffer, end);
if (IsLineEnd(*buffer) && (!SkipSpacesAndLineEnd(&buffer) || *buffer == '$')) { if (IsLineEnd(*buffer) && (!SkipSpacesAndLineEnd(&buffer, end) || *buffer == '$')) {
break; // next section break; // next section
} }
@ -202,8 +201,8 @@ void CSMImporter::InternReadFile( const std::string& pFile,
for (unsigned int i = 0; i < anim->mNumChannels;++i) { for (unsigned int i = 0; i < anim->mNumChannels;++i) {
aiNodeAnim* s = anim->mChannels[i]; aiNodeAnim* s = anim->mChannels[i];
if (s->mNumPositionKeys == alloc) { /* need to reallocate? */ if (s->mNumPositionKeys == alloc) {
// need to reallocate?
aiVectorKey* old = s->mPositionKeys; aiVectorKey* old = s->mPositionKeys;
s->mPositionKeys = new aiVectorKey[s->mNumPositionKeys = alloc*2]; s->mPositionKeys = new aiVectorKey[s->mNumPositionKeys = alloc*2];
::memcpy(s->mPositionKeys,old,sizeof(aiVectorKey)*alloc); ::memcpy(s->mPositionKeys,old,sizeof(aiVectorKey)*alloc);
@ -211,24 +210,26 @@ void CSMImporter::InternReadFile( const std::string& pFile,
} }
// read x,y,z // read x,y,z
if(!SkipSpacesAndLineEnd(&buffer)) if (!SkipSpacesAndLineEnd(&buffer, end)) {
throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample x coord"); throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample x coord");
}
if (TokenMatchI(buffer, "DROPOUT", 7)) { if (TokenMatchI(buffer, "DROPOUT", 7)) {
// seems this is invalid marker data; at least the doc says it's possible // seems this is invalid marker data; at least the doc says it's possible
ASSIMP_LOG_WARN("CSM: Encountered invalid marker data (DROPOUT)"); ASSIMP_LOG_WARN("CSM: Encountered invalid marker data (DROPOUT)");
} } else {
else {
aiVectorKey* sub = s->mPositionKeys + s->mNumPositionKeys; aiVectorKey* sub = s->mPositionKeys + s->mNumPositionKeys;
sub->mTime = (double)frame; sub->mTime = (double)frame;
buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.x); buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.x);
if(!SkipSpacesAndLineEnd(&buffer)) if (!SkipSpacesAndLineEnd(&buffer, end)) {
throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample y coord"); throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample y coord");
}
buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.y); buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.y);
if(!SkipSpacesAndLineEnd(&buffer)) if (!SkipSpacesAndLineEnd(&buffer, end)) {
throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample z coord"); throw DeadlyImportError("CSM: Unexpected EOF occurred reading sample z coord");
}
buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.z); buffer = fast_atoreal_move<float>(buffer, (float&)sub->mValue.z);
++s->mNumPositionKeys; ++s->mNumPositionKeys;
@ -236,22 +237,22 @@ void CSMImporter::InternReadFile( const std::string& pFile,
} }
// update allocation granularity // update allocation granularity
if (filled == alloc) if (filled == alloc) {
alloc *= 2; alloc *= 2;
}
++filled; ++filled;
} }
// all channels must be complete in order to continue safely. // all channels must be complete in order to continue safely.
for (unsigned int i = 0; i < anim->mNumChannels;++i) { for (unsigned int i = 0; i < anim->mNumChannels;++i) {
if (!anim->mChannels[i]->mNumPositionKeys) {
if (!anim->mChannels[i]->mNumPositionKeys)
throw DeadlyImportError("CSM: Invalid marker track"); throw DeadlyImportError("CSM: Invalid marker track");
}
} }
} }
} } else {
else {
// advance to the next line // advance to the next line
SkipLine(&buffer); SkipLine(&buffer, end);
} }
} }
@ -265,7 +266,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
pScene->mRootNode->mNumChildren = anim->mNumChannels; pScene->mRootNode->mNumChildren = anim->mNumChannels;
pScene->mRootNode->mChildren = new aiNode* [anim->mNumChannels]; pScene->mRootNode->mChildren = new aiNode* [anim->mNumChannels];
for (unsigned int i = 0; i < anim->mNumChannels;++i) { for (unsigned int i = 0; i < anim->mNumChannels;++i) {
aiNodeAnim* na = anim->mChannels[i]; aiNodeAnim* na = anim->mChannels[i];
aiNode* nd = pScene->mRootNode->mChildren[i] = new aiNode(); aiNode* nd = pScene->mRootNode->mChildren[i] = new aiNode();

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -247,7 +247,9 @@ aiNode *ColladaLoader::BuildHierarchy(const ColladaParser &pParser, const Collad
// add children. first the *real* ones // add children. first the *real* ones
node->mNumChildren = static_cast<unsigned int>(pNode->mChildren.size() + instances.size()); node->mNumChildren = static_cast<unsigned int>(pNode->mChildren.size() + instances.size());
node->mChildren = new aiNode *[node->mNumChildren]; if (node->mNumChildren != 0) {
node->mChildren = new aiNode * [node->mNumChildren];
}
for (size_t a = 0; a < pNode->mChildren.size(); ++a) { for (size_t a = 0; a < pNode->mChildren.size(); ++a) {
node->mChildren[a] = BuildHierarchy(pParser, pNode->mChildren[a]); node->mChildren[a] = BuildHierarchy(pParser, pNode->mChildren[a]);

View File

@ -4,7 +4,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -635,7 +635,8 @@ void ColladaParser::ReadController(XmlNode &node, Collada::Controller &controlle
const std::string &currentName = currentNode.name(); const std::string &currentName = currentNode.name();
if (currentName == "morph") { if (currentName == "morph") {
controller.mType = Morph; controller.mType = Morph;
controller.mMeshId = currentNode.attribute("source").as_string(); std::string id = currentNode.attribute("source").as_string();
controller.mMeshId = id.substr(1, id.size() - 1);
int methodIndex = currentNode.attribute("method").as_int(); int methodIndex = currentNode.attribute("method").as_int();
if (methodIndex > 0) { if (methodIndex > 0) {
std::string method; std::string method;
@ -654,12 +655,13 @@ void ColladaParser::ReadController(XmlNode &node, Collada::Controller &controlle
std::string v; std::string v;
XmlParser::getValueAsString(currentNode, v); XmlParser::getValueAsString(currentNode, v);
const char *content = v.c_str(); const char *content = v.c_str();
const char *end = content + v.size();
for (unsigned int a = 0; a < 16; a++) { for (unsigned int a = 0; a < 16; a++) {
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
// read a number // read a number
content = fast_atoreal_move<ai_real>(content, controller.mBindShapeMatrix[a]); content = fast_atoreal_move<ai_real>(content, controller.mBindShapeMatrix[a]);
// skip whitespace after it // skip whitespace after it
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
} }
} else if (currentName == "source") { } else if (currentName == "source") {
ReadSource(currentNode); ReadSource(currentNode);
@ -740,7 +742,9 @@ void ColladaParser::ReadControllerWeights(XmlNode &node, Collada::Controller &pC
throw DeadlyImportError("Unknown semantic \"", attrSemantic, "\" in <vertex_weights> data <input> element"); throw DeadlyImportError("Unknown semantic \"", attrSemantic, "\" in <vertex_weights> data <input> element");
} }
} else if (currentName == "vcount" && vertexCount > 0) { } else if (currentName == "vcount" && vertexCount > 0) {
const char *text = currentNode.text().as_string(); const std::string stdText = currentNode.text().as_string();
const char *text = stdText.c_str();
const char *end = text + stdText.size();
size_t numWeights = 0; size_t numWeights = 0;
for (std::vector<size_t>::iterator it = pController.mWeightCounts.begin(); it != pController.mWeightCounts.end(); ++it) { for (std::vector<size_t>::iterator it = pController.mWeightCounts.begin(); it != pController.mWeightCounts.end(); ++it) {
if (*text == 0) { if (*text == 0) {
@ -749,7 +753,7 @@ void ColladaParser::ReadControllerWeights(XmlNode &node, Collada::Controller &pC
*it = strtoul10(text, &text); *it = strtoul10(text, &text);
numWeights += *it; numWeights += *it;
SkipSpacesAndLineEnd(&text); SkipSpacesAndLineEnd(&text, end);
} }
// reserve weight count // reserve weight count
pController.mWeights.resize(numWeights); pController.mWeights.resize(numWeights);
@ -758,18 +762,19 @@ void ColladaParser::ReadControllerWeights(XmlNode &node, Collada::Controller &pC
std::string stdText; std::string stdText;
XmlParser::getValueAsString(currentNode, stdText); XmlParser::getValueAsString(currentNode, stdText);
const char *text = stdText.c_str(); const char *text = stdText.c_str();
const char *end = text + stdText.size();
for (std::vector<std::pair<size_t, size_t>>::iterator it = pController.mWeights.begin(); it != pController.mWeights.end(); ++it) { for (std::vector<std::pair<size_t, size_t>>::iterator it = pController.mWeights.begin(); it != pController.mWeights.end(); ++it) {
if (text == nullptr) { if (text == nullptr) {
throw DeadlyImportError("Out of data while reading <vertex_weights>"); throw DeadlyImportError("Out of data while reading <vertex_weights>");
} }
SkipSpacesAndLineEnd(&text); SkipSpacesAndLineEnd(&text, end);
it->first = strtoul10(text, &text); it->first = strtoul10(text, &text);
SkipSpacesAndLineEnd(&text); SkipSpacesAndLineEnd(&text, end);
if (*text == 0) { if (*text == 0) {
throw DeadlyImportError("Out of data while reading <vertex_weights>"); throw DeadlyImportError("Out of data while reading <vertex_weights>");
} }
it->second = strtoul10(text, &text); it->second = strtoul10(text, &text);
SkipSpacesAndLineEnd(&text); SkipSpacesAndLineEnd(&text, end);
} }
} }
} }
@ -952,15 +957,16 @@ void ColladaParser::ReadLight(XmlNode &node, Collada::Light &pLight) {
std::string v; std::string v;
XmlParser::getValueAsString(currentNode, v); XmlParser::getValueAsString(currentNode, v);
const char *content = v.c_str(); const char *content = v.c_str();
const char *end = content + v.size();
content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.r); content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.r);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.g); content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.g);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.b); content = fast_atoreal_move<ai_real>(content, (ai_real &)pLight.mColor.b);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
} else if (currentName == "constant_attenuation") { } else if (currentName == "constant_attenuation") {
XmlParser::getValueAsFloat(currentNode, pLight.mAttConstant); XmlParser::getValueAsFloat(currentNode, pLight.mAttConstant);
} else if (currentName == "linear_attenuation") { } else if (currentName == "linear_attenuation") {
@ -1220,18 +1226,19 @@ void ColladaParser::ReadEffectColor(XmlNode &node, aiColor4D &pColor, Sampler &p
std::string v; std::string v;
XmlParser::getValueAsString(currentNode, v); XmlParser::getValueAsString(currentNode, v);
const char *content = v.c_str(); const char *content = v.c_str();
const char *end = v.c_str() + v.size() + 1;
content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.r); content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.r);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.g); content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.g);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.b); content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.b);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.a); content = fast_atoreal_move<ai_real>(content, (ai_real &)pColor.a);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
} else if (currentName == "texture") { } else if (currentName == "texture") {
// get name of source texture/sampler // get name of source texture/sampler
XmlParser::getStdStrAttribute(currentNode, "texture", pSampler.mName); XmlParser::getStdStrAttribute(currentNode, "texture", pSampler.mName);
@ -1345,6 +1352,7 @@ void ColladaParser::ReadGeometry(XmlNode &node, Collada::Mesh &pMesh) {
if (node.empty()) { if (node.empty()) {
return; return;
} }
for (XmlNode &currentNode : node.children()) { for (XmlNode &currentNode : node.children()) {
const std::string &currentName = currentNode.name(); const std::string &currentName = currentNode.name();
if (currentName == "mesh") { if (currentName == "mesh") {
@ -1415,6 +1423,7 @@ void ColladaParser::ReadDataArray(XmlNode &node) {
XmlParser::getValueAsString(node, v); XmlParser::getValueAsString(node, v);
v = ai_trim(v); v = ai_trim(v);
const char *content = v.c_str(); const char *content = v.c_str();
const char *end = content + v.size();
// read values and store inside an array in the data library // read values and store inside an array in the data library
mDataLibrary[id] = Data(); mDataLibrary[id] = Data();
@ -1433,11 +1442,13 @@ void ColladaParser::ReadDataArray(XmlNode &node) {
} }
s.clear(); s.clear();
while (!IsSpaceOrNewLine(*content)) while (!IsSpaceOrNewLine(*content)) {
s += *content++; s += *content;
content++;
}
data.mStrings.push_back(s); data.mStrings.push_back(s);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
} }
} else { } else {
data.mValues.reserve(count); data.mValues.reserve(count);
@ -1452,7 +1463,7 @@ void ColladaParser::ReadDataArray(XmlNode &node) {
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
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
} }
} }
} }
@ -1617,8 +1628,10 @@ void ColladaParser::ReadIndexData(XmlNode &node, Mesh &pMesh) {
std::string v; std::string v;
XmlParser::getValueAsString(currentNode, v); XmlParser::getValueAsString(currentNode, v);
const char *content = v.c_str(); const char *content = v.c_str();
const char *end = content + v.size();
vcount.reserve(numPrimitives); vcount.reserve(numPrimitives);
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
for (unsigned int a = 0; a < numPrimitives; a++) { for (unsigned int a = 0; a < numPrimitives; a++) {
if (*content == 0) { if (*content == 0) {
throw DeadlyImportError("Expected more values while reading <vcount> contents."); throw DeadlyImportError("Expected more values while reading <vcount> contents.");
@ -1626,7 +1639,7 @@ void ColladaParser::ReadIndexData(XmlNode &node, Mesh &pMesh) {
// read a number // read a number
vcount.push_back((size_t)strtoul10(content, &content)); vcount.push_back((size_t)strtoul10(content, &content));
// skip whitespace after it // skip whitespace after it
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
} }
} }
} }
@ -1735,14 +1748,16 @@ size_t ColladaParser::ReadPrimitives(XmlNode &node, Mesh &pMesh, std::vector<Inp
std::string v; std::string v;
XmlParser::getValueAsString(node, v); XmlParser::getValueAsString(node, v);
const char *content = v.c_str(); const char *content = v.c_str();
SkipSpacesAndLineEnd(&content); const char *end = content + v.size();
SkipSpacesAndLineEnd(&content, end);
while (*content != 0) { while (*content != 0) {
// read a value. // read a value.
// Hack: (thom) Some exporters put negative indices sometimes. We just try to carry on anyways. // Hack: (thom) Some exporters put negative indices sometimes. We just try to carry on anyways.
int value = std::max(0, strtol10(content, &content)); int value = std::max(0, strtol10(content, &content));
indices.push_back(size_t(value)); indices.push_back(size_t(value));
// skip whitespace after it // skip whitespace after it
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
} }
} }
@ -1772,6 +1787,10 @@ size_t ColladaParser::ReadPrimitives(XmlNode &node, Mesh &pMesh, std::vector<Inp
const Accessor *acc = input.mResolved; const Accessor *acc = input.mResolved;
if (!acc->mData) { if (!acc->mData) {
acc->mData = &ResolveLibraryReference(mDataLibrary, acc->mSource); acc->mData = &ResolveLibraryReference(mDataLibrary, acc->mSource);
const size_t dataSize = acc->mOffset + acc->mCount * acc->mStride;
if (dataSize > acc->mData->mValues.size()) {
throw DeadlyImportError("Not enough data for accessor");
}
} }
} }
// and the same for the per-index channels // and the same for the per-index channels
@ -1796,13 +1815,19 @@ size_t ColladaParser::ReadPrimitives(XmlNode &node, Mesh &pMesh, std::vector<Inp
const Accessor *acc = input.mResolved; const Accessor *acc = input.mResolved;
if (!acc->mData) { if (!acc->mData) {
acc->mData = &ResolveLibraryReference(mDataLibrary, acc->mSource); acc->mData = &ResolveLibraryReference(mDataLibrary, acc->mSource);
const size_t dataSize = acc->mOffset + acc->mCount * acc->mStride;
if (dataSize > acc->mData->mValues.size()) {
throw DeadlyImportError("Not enough data for accessor");
}
} }
} }
// For continued primitives, the given count does not come all in one <p>, but only one primitive per <p> // For continued primitives, the given count does not come all in one <p>, but only one primitive per <p>
size_t numPrimitives = pNumPrimitives; size_t numPrimitives = pNumPrimitives;
if (pPrimType == Prim_TriFans || pPrimType == Prim_Polygon) if (pPrimType == Prim_TriFans || pPrimType == Prim_Polygon) {
numPrimitives = 1; numPrimitives = 1;
}
// For continued primitives, the given count is actually the number of <p>'s inside the parent tag // For continued primitives, the given count is actually the number of <p>'s inside the parent tag
if (pPrimType == Prim_TriStrips) { if (pPrimType == Prim_TriStrips) {
size_t numberOfVertices = indices.size() / numOffsets; size_t numberOfVertices = indices.size() / numOffsets;
@ -2166,15 +2191,15 @@ void ColladaParser::ReadNodeTransformation(XmlNode &node, Node *pNode, Transform
} }
// how many parameters to read per transformation type // how many parameters to read per transformation type
static const unsigned int sNumParameters[] = { 9, 4, 3, 3, 7, 16 }; static constexpr unsigned int sNumParameters[] = { 9, 4, 3, 3, 7, 16 };
std::string value; std::string value;
XmlParser::getValueAsString(node, value); XmlParser::getValueAsString(node, value);
const char *content = value.c_str(); const char *content = value.c_str();
const char *end = value.c_str() + value.size();
// 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 // skip whitespace before the number
SkipSpacesAndLineEnd(&content); SkipSpacesAndLineEnd(&content, end);
// 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]);
} }

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -43,7 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @brief Implementation of the DXF importer class * @brief Implementation of the DXF importer class
*/ */
#ifndef ASSIMP_BUILD_NO_DXF_IMPORTER #ifndef ASSIMP_BUILD_NO_DXF_IMPORTER
#include "AssetLib/DXF/DXFLoader.h" #include "AssetLib/DXF/DXFLoader.h"
@ -68,25 +67,267 @@ 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
static 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 - 256 are supported, the table is
// taken directly from the DXF spec. // taken directly from the AutoCad Index (ACI) table
static const aiColor4D g_aclrDxfIndexColors[] = { // https://gohtx.com/acadcolors.php
aiColor4D(0.6f, 0.6f, 0.6f, 1.0f), //STH 2024-0126
aiColor4D (1.0f, 0.0f, 0.0f, 1.0f), // red static const aiColor4D g_aclrDxfIndexColors[256] = {
aiColor4D (0.0f, 1.0f, 0.0f, 1.0f), // green aiColor4D (0.0f, 0.0f ,0.0f, 1.0f), //dxf color code 0
aiColor4D (0.0f, 0.0f, 1.0f, 1.0f), // blue aiColor4D (1.0f, 0.0f ,0.0f, 1.0f), //dxf color code 1
aiColor4D (0.3f, 1.0f, 0.3f, 1.0f), // light green aiColor4D (1.0f, 1.0f ,0.0f, 1.0f), //dxf color code 2
aiColor4D (0.3f, 0.3f, 1.0f, 1.0f), // light blue aiColor4D (0.0f, 1.0f ,0.0f, 1.0f), //dxf color code 3
aiColor4D (1.0f, 0.3f, 0.3f, 1.0f), // light red aiColor4D (0.0f, 1.0f ,1.0f, 1.0f), //dxf color code 4
aiColor4D (1.0f, 0.0f, 1.0f, 1.0f), // pink aiColor4D (0.0f, 0.0f ,1.0f, 1.0f), //dxf color code 5
aiColor4D (1.0f, 0.6f, 0.0f, 1.0f), // orange aiColor4D (1.0f, 0.0f ,1.0f, 1.0f), //dxf color code 6
aiColor4D (0.6f, 0.3f, 0.0f, 1.0f), // dark orange aiColor4D (1.0f, 1.0f ,1.0f, 1.0f), //dxf color code 7
aiColor4D (1.0f, 1.0f, 0.0f, 1.0f), // yellow aiColor4D (0.3f, 0.3f ,0.3f, 1.0f), //dxf color code 8
aiColor4D (0.3f, 0.3f, 0.3f, 1.0f), // dark gray aiColor4D (0.5f, 0.5f ,0.5f, 1.0f), //dxf color code 9
aiColor4D (0.8f, 0.8f, 0.8f, 1.0f), // light gray aiColor4D (1.0f, 0.0f ,0.0f, 1.0f), //dxf color code 10
aiColor4D (0.0f, 00.f, 0.0f, 1.0f), // black aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 11
aiColor4D (1.0f, 1.0f, 1.0f, 1.0f), // white aiColor4D (0.7f, 0.0f ,0.0f, 1.0f), //dxf color code 12
aiColor4D (0.6f, 0.0f, 1.0f, 1.0f) // violet aiColor4D (0.7f, 0.5f ,0.5f, 1.0f), //dxf color code 13
aiColor4D (0.5f, 0.0f ,0.0f, 1.0f), //dxf color code 14
aiColor4D (0.5f, 0.3f ,0.3f, 1.0f), //dxf color code 15
aiColor4D (0.4f, 0.0f ,0.0f, 1.0f), //dxf color code 16
aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 17
aiColor4D (0.3f, 0.0f ,0.0f, 1.0f), //dxf color code 18
aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 19
aiColor4D (1.0f, 0.2f ,0.0f, 1.0f), //dxf color code 20
aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 21
aiColor4D (0.7f, 0.2f ,0.0f, 1.0f), //dxf color code 22
aiColor4D (0.7f, 0.6f ,0.5f, 1.0f), //dxf color code 23
aiColor4D (0.5f, 0.1f ,0.0f, 1.0f), //dxf color code 24
aiColor4D (0.5f, 0.4f ,0.3f, 1.0f), //dxf color code 25
aiColor4D (0.4f, 0.1f ,0.0f, 1.0f), //dxf color code 26
aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 27
aiColor4D (0.3f, 0.1f ,0.0f, 1.0f), //dxf color code 28
aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 29
aiColor4D (1.0f, 0.5f ,0.0f, 1.0f), //dxf color code 30
aiColor4D (1.0f, 0.8f ,0.7f, 1.0f), //dxf color code 31
aiColor4D (0.7f, 0.4f ,0.0f, 1.0f), //dxf color code 32
aiColor4D (0.7f, 0.6f ,0.5f, 1.0f), //dxf color code 33
aiColor4D (0.5f, 0.3f ,0.0f, 1.0f), //dxf color code 34
aiColor4D (0.5f, 0.4f ,0.3f, 1.0f), //dxf color code 35
aiColor4D (0.4f, 0.2f ,0.0f, 1.0f), //dxf color code 36
aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 37
aiColor4D (0.3f, 0.2f ,0.0f, 1.0f), //dxf color code 38
aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 39
aiColor4D (1.0f, 0.7f ,0.0f, 1.0f), //dxf color code 40
aiColor4D (1.0f, 0.9f ,0.7f, 1.0f), //dxf color code 41
aiColor4D (0.7f, 0.6f ,0.0f, 1.0f), //dxf color code 42
aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 43
aiColor4D (0.5f, 0.4f ,0.0f, 1.0f), //dxf color code 44
aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 45
aiColor4D (0.4f, 0.3f ,0.0f, 1.0f), //dxf color code 46
aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 47
aiColor4D (0.3f, 0.2f ,0.0f, 1.0f), //dxf color code 48
aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 49
aiColor4D (1.0f, 1.0f ,0.0f, 1.0f), //dxf color code 50
aiColor4D (1.0f, 1.0f ,0.7f, 1.0f), //dxf color code 51
aiColor4D (0.7f, 0.7f ,0.0f, 1.0f), //dxf color code 52
aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 53
aiColor4D (0.5f, 0.5f ,0.0f, 1.0f), //dxf color code 54
aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 55
aiColor4D (0.4f, 0.4f ,0.0f, 1.0f), //dxf color code 56
aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 57
aiColor4D (0.3f, 0.3f ,0.0f, 1.0f), //dxf color code 58
aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 59
aiColor4D (0.7f, 1.0f ,0.0f, 1.0f), //dxf color code 60
aiColor4D (0.9f, 1.0f ,0.7f, 1.0f), //dxf color code 61
aiColor4D (0.6f, 0.7f ,0.0f, 1.0f), //dxf color code 62
aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 63
aiColor4D (0.4f, 0.5f ,0.0f, 1.0f), //dxf color code 64
aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 65
aiColor4D (0.3f, 0.4f ,0.0f, 1.0f), //dxf color code 66
aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 67
aiColor4D (0.2f, 0.3f ,0.0f, 1.0f), //dxf color code 68
aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 69
aiColor4D (0.5f, 1.0f ,0.0f, 1.0f), //dxf color code 70
aiColor4D (0.8f, 1.0f ,0.7f, 1.0f), //dxf color code 71
aiColor4D (0.4f, 0.7f ,0.0f, 1.0f), //dxf color code 72
aiColor4D (0.6f, 0.7f ,0.5f, 1.0f), //dxf color code 73
aiColor4D (0.3f, 0.5f ,0.0f, 1.0f), //dxf color code 74
aiColor4D (0.4f, 0.5f ,0.3f, 1.0f), //dxf color code 75
aiColor4D (0.2f, 0.4f ,0.0f, 1.0f), //dxf color code 76
aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 77
aiColor4D (0.2f, 0.3f ,0.0f, 1.0f), //dxf color code 78
aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 79
aiColor4D (0.2f, 1.0f ,0.0f, 1.0f), //dxf color code 80
aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 81
aiColor4D (0.2f, 0.7f ,0.0f, 1.0f), //dxf color code 82
aiColor4D (0.6f, 0.7f ,0.5f, 1.0f), //dxf color code 83
aiColor4D (0.1f, 0.5f ,0.0f, 1.0f), //dxf color code 84
aiColor4D (0.4f, 0.5f ,0.3f, 1.0f), //dxf color code 85
aiColor4D (0.1f, 0.4f ,0.0f, 1.0f), //dxf color code 86
aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 87
aiColor4D (0.1f, 0.3f ,0.0f, 1.0f), //dxf color code 88
aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 89
aiColor4D (0.0f, 1.0f ,0.0f, 1.0f), //dxf color code 90
aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 91
aiColor4D (0.0f, 0.7f ,0.0f, 1.0f), //dxf color code 92
aiColor4D (0.5f, 0.7f ,0.5f, 1.0f), //dxf color code 93
aiColor4D (0.0f, 0.5f ,0.0f, 1.0f), //dxf color code 94
aiColor4D (0.3f, 0.5f ,0.3f, 1.0f), //dxf color code 95
aiColor4D (0.0f, 0.4f ,0.0f, 1.0f), //dxf color code 96
aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 97
aiColor4D (0.0f, 0.3f ,0.0f, 1.0f), //dxf color code 98
aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 99
aiColor4D (0.0f, 1.0f ,0.2f, 1.0f), //dxf color code 100
aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 101
aiColor4D (0.0f, 0.7f ,0.2f, 1.0f), //dxf color code 102
aiColor4D (0.5f, 0.7f ,0.6f, 1.0f), //dxf color code 103
aiColor4D (0.0f, 0.5f ,0.1f, 1.0f), //dxf color code 104
aiColor4D (0.3f, 0.5f ,0.4f, 1.0f), //dxf color code 105
aiColor4D (0.0f, 0.4f ,0.1f, 1.0f), //dxf color code 106
aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 107
aiColor4D (0.0f, 0.3f ,0.1f, 1.0f), //dxf color code 108
aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 109
aiColor4D (0.0f, 1.0f ,0.5f, 1.0f), //dxf color code 110
aiColor4D (0.7f, 1.0f ,0.8f, 1.0f), //dxf color code 111
aiColor4D (0.0f, 0.7f ,0.4f, 1.0f), //dxf color code 112
aiColor4D (0.5f, 0.7f ,0.6f, 1.0f), //dxf color code 113
aiColor4D (0.0f, 0.5f ,0.3f, 1.0f), //dxf color code 114
aiColor4D (0.3f, 0.5f ,0.4f, 1.0f), //dxf color code 115
aiColor4D (0.0f, 0.4f ,0.2f, 1.0f), //dxf color code 116
aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 117
aiColor4D (0.0f, 0.3f ,0.2f, 1.0f), //dxf color code 118
aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 119
aiColor4D (0.0f, 1.0f ,0.7f, 1.0f), //dxf color code 120
aiColor4D (0.7f, 1.0f ,0.9f, 1.0f), //dxf color code 121
aiColor4D (0.0f, 0.7f ,0.6f, 1.0f), //dxf color code 122
aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 123
aiColor4D (0.0f, 0.5f ,0.4f, 1.0f), //dxf color code 124
aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 125
aiColor4D (0.0f, 0.4f ,0.3f, 1.0f), //dxf color code 126
aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 127
aiColor4D (0.0f, 0.3f ,0.2f, 1.0f), //dxf color code 128
aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 129
aiColor4D (0.0f, 1.0f ,1.0f, 1.0f), //dxf color code 130
aiColor4D (0.7f, 1.0f ,1.0f, 1.0f), //dxf color code 131
aiColor4D (0.0f, 0.7f ,0.7f, 1.0f), //dxf color code 132
aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 133
aiColor4D (0.0f, 0.5f ,0.5f, 1.0f), //dxf color code 134
aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 135
aiColor4D (0.0f, 0.4f ,0.4f, 1.0f), //dxf color code 136
aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 137
aiColor4D (0.0f, 0.3f ,0.3f, 1.0f), //dxf color code 138
aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 139
aiColor4D (0.0f, 0.7f ,1.0f, 1.0f), //dxf color code 140
aiColor4D (0.7f, 0.9f ,1.0f, 1.0f), //dxf color code 141
aiColor4D (0.0f, 0.6f ,0.7f, 1.0f), //dxf color code 142
aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 143
aiColor4D (0.0f, 0.4f ,0.5f, 1.0f), //dxf color code 144
aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 145
aiColor4D (0.0f, 0.3f ,0.4f, 1.0f), //dxf color code 146
aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 147
aiColor4D (0.0f, 0.2f ,0.3f, 1.0f), //dxf color code 148
aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 149
aiColor4D (0.0f, 0.5f ,1.0f, 1.0f), //dxf color code 150
aiColor4D (0.7f, 0.8f ,1.0f, 1.0f), //dxf color code 151
aiColor4D (0.0f, 0.4f ,0.7f, 1.0f), //dxf color code 152
aiColor4D (0.5f, 0.6f ,0.7f, 1.0f), //dxf color code 153
aiColor4D (0.0f, 0.3f ,0.5f, 1.0f), //dxf color code 154
aiColor4D (0.3f, 0.4f ,0.5f, 1.0f), //dxf color code 155
aiColor4D (0.0f, 0.2f ,0.4f, 1.0f), //dxf color code 156
aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 157
aiColor4D (0.0f, 0.2f ,0.3f, 1.0f), //dxf color code 158
aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 159
aiColor4D (0.0f, 0.2f ,1.0f, 1.0f), //dxf color code 160
aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 161
aiColor4D (0.0f, 0.2f ,0.7f, 1.0f), //dxf color code 162
aiColor4D (0.5f, 0.6f ,0.7f, 1.0f), //dxf color code 163
aiColor4D (0.0f, 0.1f ,0.5f, 1.0f), //dxf color code 164
aiColor4D (0.3f, 0.4f ,0.5f, 1.0f), //dxf color code 165
aiColor4D (0.0f, 0.1f ,0.4f, 1.0f), //dxf color code 166
aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 167
aiColor4D (0.0f, 0.1f ,0.3f, 1.0f), //dxf color code 168
aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 169
aiColor4D (0.0f, 0.0f ,1.0f, 1.0f), //dxf color code 170
aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 171
aiColor4D (0.0f, 0.0f ,0.7f, 1.0f), //dxf color code 172
aiColor4D (0.5f, 0.5f ,0.7f, 1.0f), //dxf color code 173
aiColor4D (0.0f, 0.0f ,0.5f, 1.0f), //dxf color code 174
aiColor4D (0.3f, 0.3f ,0.5f, 1.0f), //dxf color code 175
aiColor4D (0.0f, 0.0f ,0.4f, 1.0f), //dxf color code 176
aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 177
aiColor4D (0.0f, 0.0f ,0.3f, 1.0f), //dxf color code 178
aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 179
aiColor4D (0.2f, 0.0f ,1.0f, 1.0f), //dxf color code 180
aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 181
aiColor4D (0.2f, 0.0f ,0.7f, 1.0f), //dxf color code 182
aiColor4D (0.6f, 0.5f ,0.7f, 1.0f), //dxf color code 183
aiColor4D (0.1f, 0.0f ,0.5f, 1.0f), //dxf color code 184
aiColor4D (0.4f, 0.3f ,0.5f, 1.0f), //dxf color code 185
aiColor4D (0.1f, 0.0f ,0.4f, 1.0f), //dxf color code 186
aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 187
aiColor4D (0.1f, 0.0f ,0.3f, 1.0f), //dxf color code 188
aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 189
aiColor4D (0.5f, 0.0f ,1.0f, 1.0f), //dxf color code 190
aiColor4D (0.8f, 0.7f ,1.0f, 1.0f), //dxf color code 191
aiColor4D (0.4f, 0.0f ,0.7f, 1.0f), //dxf color code 192
aiColor4D (0.6f, 0.5f ,0.7f, 1.0f), //dxf color code 193
aiColor4D (0.3f, 0.0f ,0.5f, 1.0f), //dxf color code 194
aiColor4D (0.4f, 0.3f ,0.5f, 1.0f), //dxf color code 195
aiColor4D (0.2f, 0.0f ,0.4f, 1.0f), //dxf color code 196
aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 197
aiColor4D (0.2f, 0.0f ,0.3f, 1.0f), //dxf color code 198
aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 199
aiColor4D (0.7f, 0.0f ,1.0f, 1.0f), //dxf color code 200
aiColor4D (0.9f, 0.7f ,1.0f, 1.0f), //dxf color code 201
aiColor4D (0.6f, 0.0f ,0.7f, 1.0f), //dxf color code 202
aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 203
aiColor4D (0.4f, 0.0f ,0.5f, 1.0f), //dxf color code 204
aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 205
aiColor4D (0.3f, 0.0f ,0.4f, 1.0f), //dxf color code 206
aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 207
aiColor4D (0.2f, 0.0f ,0.3f, 1.0f), //dxf color code 208
aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 209
aiColor4D (1.0f, 0.0f ,1.0f, 1.0f), //dxf color code 210
aiColor4D (1.0f, 0.7f ,1.0f, 1.0f), //dxf color code 211
aiColor4D (0.7f, 0.0f ,0.7f, 1.0f), //dxf color code 212
aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 213
aiColor4D (0.5f, 0.0f ,0.5f, 1.0f), //dxf color code 214
aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 215
aiColor4D (0.4f, 0.0f ,0.4f, 1.0f), //dxf color code 216
aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 217
aiColor4D (0.3f, 0.0f ,0.3f, 1.0f), //dxf color code 218
aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 219
aiColor4D (1.0f, 0.0f ,0.7f, 1.0f), //dxf color code 220
aiColor4D (1.0f, 0.7f ,0.9f, 1.0f), //dxf color code 221
aiColor4D (0.7f, 0.0f ,0.6f, 1.0f), //dxf color code 222
aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 223
aiColor4D (0.5f, 0.0f ,0.4f, 1.0f), //dxf color code 224
aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 225
aiColor4D (0.4f, 0.0f ,0.3f, 1.0f), //dxf color code 226
aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 227
aiColor4D (0.3f, 0.0f ,0.2f, 1.0f), //dxf color code 228
aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 229
aiColor4D (1.0f, 0.0f ,0.5f, 1.0f), //dxf color code 230
aiColor4D (1.0f, 0.7f ,0.8f, 1.0f), //dxf color code 231
aiColor4D (0.7f, 0.0f ,0.4f, 1.0f), //dxf color code 232
aiColor4D (0.7f, 0.5f ,0.6f, 1.0f), //dxf color code 233
aiColor4D (0.5f, 0.0f ,0.3f, 1.0f), //dxf color code 234
aiColor4D (0.5f, 0.3f ,0.4f, 1.0f), //dxf color code 235
aiColor4D (0.4f, 0.0f ,0.2f, 1.0f), //dxf color code 236
aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 237
aiColor4D (0.3f, 0.0f ,0.2f, 1.0f), //dxf color code 238
aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 239
aiColor4D (1.0f, 0.0f ,0.2f, 1.0f), //dxf color code 240
aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 241
aiColor4D (0.7f, 0.0f ,0.2f, 1.0f), //dxf color code 242
aiColor4D (0.7f, 0.5f ,0.6f, 1.0f), //dxf color code 243
aiColor4D (0.5f, 0.0f ,0.1f, 1.0f), //dxf color code 244
aiColor4D (0.5f, 0.3f ,0.4f, 1.0f), //dxf color code 245
aiColor4D (0.4f, 0.0f ,0.1f, 1.0f), //dxf color code 246
aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 247
aiColor4D (0.3f, 0.0f ,0.1f, 1.0f), //dxf color code 248
aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 249
aiColor4D (0.2f, 0.2f ,0.2f, 1.0f), //dxf color code 250
aiColor4D (0.3f, 0.3f ,0.3f, 1.0f), //dxf color code 251
aiColor4D (0.4f, 0.4f ,0.4f, 1.0f), //dxf color code 252
aiColor4D (0.5f, 0.5f ,0.5f, 1.0f), //dxf color code 253
aiColor4D (0.7f, 0.7f ,0.7f, 1.0f), //dxf color code 254
aiColor4D (1.0f, 1.0f ,1.0f, 1.0f) //dxf color code 255
}; };
#define AI_DXF_NUM_INDEX_COLORS (sizeof(g_aclrDxfIndexColors)/sizeof(g_aclrDxfIndexColors[0])) #define AI_DXF_NUM_INDEX_COLORS (sizeof(g_aclrDxfIndexColors)/sizeof(g_aclrDxfIndexColors[0]))
@ -372,8 +613,12 @@ void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& bloc
// XXX order // XXX order
aiMatrix4x4 trafo, tmp; aiMatrix4x4 trafo, tmp;
aiMatrix4x4::Translation(-bl_src.base,trafo); aiMatrix4x4::Translation(-bl_src.base,trafo);
trafo *= aiMatrix4x4::Scaling(insert.scale,tmp); //Need to translate position before scaling the insert
//otherwise the position ends up being the position*scaling
//STH 2024.01.17
trafo *= aiMatrix4x4::Translation(insert.pos,tmp); trafo *= aiMatrix4x4::Translation(insert.pos,tmp);
trafo *= aiMatrix4x4::Scaling(insert.scale,tmp);
//trafo *= aiMatrix4x4::Translation(insert.pos,tmp);
// XXX rotation currently ignored - I didn't find an appropriate sample model. // XXX rotation currently ignored - I didn't find an appropriate sample model.
if (insert.angle != 0.f) { if (insert.angle != 0.f) {

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -76,6 +76,53 @@ using namespace Util;
#define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000LL #define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000LL
static void correctRootTransform(const aiScene *scene) {
if (scene == nullptr) {
return;
}
if (scene->mMetaData == nullptr) {
return;
}
int32_t UpAxis = 1, UpAxisSign = 1, FrontAxis = 2, FrontAxisSign = 1, CoordAxis = 0, CoordAxisSign = 1;
double UnitScaleFactor = 1.0;
for (unsigned MetadataIndex = 0; MetadataIndex < scene->mMetaData->mNumProperties; ++MetadataIndex) {
if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UpAxis") == 0) {
scene->mMetaData->Get<int32_t>(MetadataIndex, UpAxis);
}
if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UpAxisSign") == 0) {
scene->mMetaData->Get<int32_t>(MetadataIndex, UpAxisSign);
}
if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "FrontAxis") == 0) {
scene->mMetaData->Get<int32_t>(MetadataIndex, FrontAxis);
}
if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "FrontAxisSign") == 0) {
scene->mMetaData->Get<int32_t>(MetadataIndex, FrontAxisSign);
}
if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "CoordAxis") == 0) {
scene->mMetaData->Get<int32_t>(MetadataIndex, CoordAxis);
}
if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "CoordAxisSign") == 0) {
scene->mMetaData->Get<int32_t>(MetadataIndex, CoordAxisSign);
}
if (strcmp(scene->mMetaData->mKeys[MetadataIndex].C_Str(), "UnitScaleFactor") == 0) {
scene->mMetaData->Get<double>(MetadataIndex, UnitScaleFactor);
}
}
aiVector3D upVec, forwardVec, rightVec;
upVec[UpAxis] = UpAxisSign * static_cast<float>(UnitScaleFactor);
forwardVec[FrontAxis] = FrontAxisSign * static_cast<float>(UnitScaleFactor);
rightVec[CoordAxis] = CoordAxisSign * (float)UnitScaleFactor;
aiMatrix4x4 mat(rightVec.x, rightVec.y, rightVec.z, 0.0f,
upVec.x, upVec.y, upVec.z, 0.0f,
forwardVec.x, forwardVec.y, forwardVec.z, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
scene->mRootNode->mTransformation *= mat;
}
FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBones) : FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBones) :
defaultMaterialIndex(), defaultMaterialIndex(),
mMeshes(), mMeshes(),
@ -133,6 +180,8 @@ FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBo
// need not contain geometry (i.e. camera animations, raw armatures). // need not contain geometry (i.e. camera animations, raw armatures).
if (out->mNumMeshes == 0) { if (out->mNumMeshes == 0) {
out->mFlags |= AI_SCENE_FLAGS_INCOMPLETE; out->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
} else {
correctRootTransform(mSceneOut);
} }
} }
@ -3239,9 +3288,9 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
} }
if (keyframeLists[TransformationComp_Rotation].size() > 0) { if (keyframeLists[TransformationComp_Rotation].size() > 0) {
InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], AI_DEG_TO_RAD(defRotation), maxTime, minTime, rotOrder); InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder);
} else { } else {
aiQuaternion defQuat = EulerToQuaternion(AI_DEG_TO_RAD(defRotation), rotOrder); aiQuaternion defQuat = EulerToQuaternion(defRotation, rotOrder);
for (size_t i = 0; i < keyCount; ++i) { for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps; outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps;
outRotations[i].mValue = defQuat; outRotations[i].mValue = defQuat;
@ -3263,7 +3312,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
const aiVector3D& preRotation = PropertyGet<aiVector3D>(props, "PreRotation", ok); const aiVector3D& preRotation = PropertyGet<aiVector3D>(props, "PreRotation", ok);
if (ok && preRotation.SquareLength() > zero_epsilon) { if (ok && preRotation.SquareLength() > zero_epsilon) {
const aiQuaternion preQuat = EulerToQuaternion(AI_DEG_TO_RAD(preRotation), Model::RotOrder_EulerXYZ); const aiQuaternion preQuat = EulerToQuaternion(preRotation, Model::RotOrder_EulerXYZ);
for (size_t i = 0; i < keyCount; ++i) { for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mValue = preQuat * outRotations[i].mValue; outRotations[i].mValue = preQuat * outRotations[i].mValue;
} }
@ -3271,7 +3320,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
const aiVector3D& postRotation = PropertyGet<aiVector3D>(props, "PostRotation", ok); const aiVector3D& postRotation = PropertyGet<aiVector3D>(props, "PostRotation", ok);
if (ok && postRotation.SquareLength() > zero_epsilon) { if (ok && postRotation.SquareLength() > zero_epsilon) {
const aiQuaternion postQuat = EulerToQuaternion(AI_DEG_TO_RAD(postRotation), Model::RotOrder_EulerXYZ); const aiQuaternion postQuat = EulerToQuaternion(postRotation, Model::RotOrder_EulerXYZ);
for (size_t i = 0; i < keyCount; ++i) { for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mValue = outRotations[i].mValue * postQuat; outRotations[i].mValue = outRotations[i].mValue * postQuat;
} }

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.
@ -69,6 +69,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unordered_set> #include <unordered_set>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <cmath>
// RESOURCES: // RESOURCES:
// https://code.blender.org/2013/08/fbx-binary-file-format-specification/ // https://code.blender.org/2013/08/fbx-binary-file-format-specification/
@ -1062,7 +1063,7 @@ aiMatrix4x4 get_world_transform(const aiNode* node, const aiScene* scene)
} }
inline int64_t to_ktime(double ticks, const aiAnimation* anim) { inline int64_t to_ktime(double ticks, const aiAnimation* anim) {
if (anim->mTicksPerSecond <= 0) { if (FP_ZERO == std::fpclassify(anim->mTicksPerSecond)) {
return static_cast<int64_t>(ticks) * FBX::SECOND; return static_cast<int64_t>(ticks) * FBX::SECOND;
} }
return (static_cast<int64_t>(ticks / anim->mTicksPerSecond)) * FBX::SECOND; return (static_cast<int64_t>(ticks / anim->mTicksPerSecond)) * FBX::SECOND;
@ -1088,6 +1089,8 @@ void FBXExporter::WriteObjects ()
bool bJoinIdenticalVertices = mProperties->GetPropertyBool("bJoinIdenticalVertices", true); bool bJoinIdenticalVertices = mProperties->GetPropertyBool("bJoinIdenticalVertices", true);
std::vector<std::vector<int32_t>> vVertexIndice;//save vertex_indices as it is needed later std::vector<std::vector<int32_t>> vVertexIndice;//save vertex_indices as it is needed later
const auto bTransparencyFactorReferencedToOpacity = mProperties->GetPropertyBool(AI_CONFIG_EXPORT_FBX_TRANSPARENCY_FACTOR_REFER_TO_OPACITY, false);
// geometry (aiMesh) // geometry (aiMesh)
mesh_uids.clear(); mesh_uids.clear();
indent = 1; indent = 1;
@ -1444,13 +1447,21 @@ void FBXExporter::WriteObjects ()
// "TransparentColor" / "TransparencyFactor"... // "TransparentColor" / "TransparencyFactor"...
// thanks FBX, for your insightful interpretation of consistency // thanks FBX, for your insightful interpretation of consistency
p.AddP70colorA("TransparentColor", c.r, c.g, c.b); p.AddP70colorA("TransparentColor", c.r, c.g, c.b);
// TransparencyFactor defaults to 0.0, so set it to 1.0.
// note: Maya always sets this to 1.0, if (!bTransparencyFactorReferencedToOpacity) {
// so we can't use it sensibly as "Opacity". // TransparencyFactor defaults to 0.0, so set it to 1.0.
// In stead we rely on the legacy "Opacity" value, below. // note: Maya always sets this to 1.0,
// Blender also relies on "Opacity" not "TransparencyFactor", // so we can't use it sensibly as "Opacity".
// probably for a similar reason. // In stead we rely on the legacy "Opacity" value, below.
p.AddP70numberA("TransparencyFactor", 1.0); // Blender also relies on "Opacity" not "TransparencyFactor",
// probably for a similar reason.
p.AddP70numberA("TransparencyFactor", 1.0);
}
}
if (bTransparencyFactorReferencedToOpacity) {
if (m->Get(AI_MATKEY_OPACITY, f) == aiReturn_SUCCESS) {
p.AddP70numberA("TransparencyFactor", 1.0 - f);
}
} }
if (m->Get(AI_MATKEY_COLOR_REFLECTIVE, c) == aiReturn_SUCCESS) { if (m->Get(AI_MATKEY_COLOR_REFLECTIVE, c) == aiReturn_SUCCESS) {
p.AddP70colorA("ReflectionColor", c.r, c.g, c.b); p.AddP70colorA("ReflectionColor", c.r, c.g, c.b);
@ -1748,7 +1759,7 @@ void FBXExporter::WriteObjects ()
int64_t blendshape_uid = generate_uid(); int64_t blendshape_uid = generate_uid();
mesh_uids.push_back(blendshape_uid); mesh_uids.push_back(blendshape_uid);
bsnode.AddProperty(blendshape_uid); bsnode.AddProperty(blendshape_uid);
bsnode.AddProperty(blendshape_name + FBX::SEPARATOR + "Blendshape"); bsnode.AddProperty(blendshape_name + FBX::SEPARATOR + "Geometry");
bsnode.AddProperty("Shape"); bsnode.AddProperty("Shape");
bsnode.AddChild("Version", int32_t(100)); bsnode.AddChild("Version", int32_t(100));
bsnode.Begin(outstream, binary, indent); bsnode.Begin(outstream, binary, indent);
@ -1807,7 +1818,7 @@ void FBXExporter::WriteObjects ()
p.AddP70numberA("DeformPercent", 0.0); 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<double>fFullWeights;
fFullWeights.push_back(100.); fFullWeights.push_back(100.);
sdnode.AddChild("FullWeights", fFullWeights); sdnode.AddChild("FullWeights", fFullWeights);
sdnode.Dump(outstream, binary, indent); sdnode.Dump(outstream, binary, indent);

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2023, assimp team Copyright (c) 2006-2024, assimp team
All rights reserved. All rights reserved.

Some files were not shown because too many files have changed in this diff Show More