From 729c214c003efb738c08f27817d569feb318dbf5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 7 Jul 2021 16:52:49 +0200 Subject: [PATCH] Drop XML implementation, related code and dependent features --- examples/09.Meshviewer/main.cpp | 52 +- examples/15.LoadIrrFile/LoadIrrFile.cbp | 54 - examples/15.LoadIrrFile/LoadIrrFile.vcproj | 162 - .../LoadIrrFile.xcodeproj/project.pbxproj | 324 -- .../xcschemes/15.LoadIrrFile.xcscheme | 91 - .../15.LoadIrrFile/LoadIrrFile_vc10.vcxproj | 235 -- .../15.LoadIrrFile/LoadIrrFile_vc11.vcxproj | 235 -- .../15.LoadIrrFile/LoadIrrFile_vc12.vcxproj | 235 -- .../15.LoadIrrFile/LoadIrrFile_vc14.vcxproj | 235 -- examples/15.LoadIrrFile/Makefile | 56 - examples/15.LoadIrrFile/main.cpp | 181 - examples/15.LoadIrrFile/tutorial.html | 129 - examples/25.XmlHandling/Makefile | 56 - examples/25.XmlHandling/XmlHandling.cbp | 55 - examples/25.XmlHandling/XmlHandling.vcproj | 195 -- .../XmlHandling.xcodeproj/project.pbxproj | 324 -- .../xcschemes/25.XmlHandling.xcscheme | 91 - .../25.XmlHandling/XmlHandling_vc10.vcxproj | 182 - .../25.XmlHandling/XmlHandling_vc11.vcxproj | 182 - .../25.XmlHandling/XmlHandling_vc12.vcxproj | 182 - .../25.XmlHandling/XmlHandling_vc14.vcxproj | 182 - examples/25.XmlHandling/main.cpp | 510 --- examples/CMakeLists.txt | 2 - include/IAttributes.h | 16 - include/IColladaMeshWriter.h | 456 --- include/IFileSystem.h | 66 - include/IGUIEnvironment.h | 8 - include/ISceneManager.h | 59 - include/IXMLReader.h | 31 - include/IXMLWriter.h | 26 - include/IrrCompileConfig.h | 34 - include/irrXML.h | 645 ---- include/irrlicht.h | 6 +- source/Irrlicht/CAttributes.cpp | 277 -- source/Irrlicht/CAttributes.h | 11 - source/Irrlicht/CColladaFileLoader.cpp | 3008 ----------------- source/Irrlicht/CColladaFileLoader.h | 410 --- source/Irrlicht/CColladaMeshWriter.cpp | 2309 ------------- source/Irrlicht/CColladaMeshWriter.h | 282 -- source/Irrlicht/CFileSystem.cpp | 129 - source/Irrlicht/CFileSystem.h | 24 - source/Irrlicht/CGUIEnvironment.cpp | 229 +- source/Irrlicht/CGUIEnvironment.h | 6 - source/Irrlicht/CGUIFont.cpp | 3 +- source/Irrlicht/CGUIFont.h | 5 - source/Irrlicht/CIrrMeshFileLoader.cpp | 556 --- source/Irrlicht/CIrrMeshFileLoader.h | 90 - source/Irrlicht/CIrrMeshWriter.cpp | 312 -- source/Irrlicht/CIrrMeshWriter.h | 61 - source/Irrlicht/CMakeLists.txt | 8 - source/Irrlicht/CSceneLoaderIrr.cpp | 284 -- source/Irrlicht/CSceneLoaderIrr.h | 83 - source/Irrlicht/CSceneManager.cpp | 216 +- source/Irrlicht/CSceneManager.h | 12 - source/Irrlicht/CXMLReader.cpp | 84 - source/Irrlicht/CXMLReader.h | 30 - source/Irrlicht/CXMLReaderImpl.h | 821 ----- source/Irrlicht/CXMLWriter.cpp | 472 --- source/Irrlicht/CXMLWriter.h | 156 - source/Irrlicht/irrXML.cpp | 185 - 60 files changed, 10 insertions(+), 15350 deletions(-) delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile.cbp delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile.vcproj delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/project.pbxproj delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/xcshareddata/xcschemes/15.LoadIrrFile.xcscheme delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile_vc10.vcxproj delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile_vc11.vcxproj delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile_vc12.vcxproj delete mode 100644 examples/15.LoadIrrFile/LoadIrrFile_vc14.vcxproj delete mode 100644 examples/15.LoadIrrFile/Makefile delete mode 100644 examples/15.LoadIrrFile/main.cpp delete mode 100644 examples/15.LoadIrrFile/tutorial.html delete mode 100644 examples/25.XmlHandling/Makefile delete mode 100644 examples/25.XmlHandling/XmlHandling.cbp delete mode 100644 examples/25.XmlHandling/XmlHandling.vcproj delete mode 100644 examples/25.XmlHandling/XmlHandling.xcodeproj/project.pbxproj delete mode 100644 examples/25.XmlHandling/XmlHandling.xcodeproj/xcshareddata/xcschemes/25.XmlHandling.xcscheme delete mode 100644 examples/25.XmlHandling/XmlHandling_vc10.vcxproj delete mode 100644 examples/25.XmlHandling/XmlHandling_vc11.vcxproj delete mode 100644 examples/25.XmlHandling/XmlHandling_vc12.vcxproj delete mode 100644 examples/25.XmlHandling/XmlHandling_vc14.vcxproj delete mode 100644 examples/25.XmlHandling/main.cpp delete mode 100644 include/IColladaMeshWriter.h delete mode 100644 include/IXMLReader.h delete mode 100644 include/IXMLWriter.h delete mode 100644 include/irrXML.h delete mode 100644 source/Irrlicht/CColladaFileLoader.cpp delete mode 100644 source/Irrlicht/CColladaFileLoader.h delete mode 100644 source/Irrlicht/CColladaMeshWriter.cpp delete mode 100644 source/Irrlicht/CColladaMeshWriter.h delete mode 100644 source/Irrlicht/CIrrMeshFileLoader.cpp delete mode 100644 source/Irrlicht/CIrrMeshFileLoader.h delete mode 100644 source/Irrlicht/CIrrMeshWriter.cpp delete mode 100644 source/Irrlicht/CIrrMeshWriter.h delete mode 100644 source/Irrlicht/CSceneLoaderIrr.cpp delete mode 100644 source/Irrlicht/CSceneLoaderIrr.h delete mode 100644 source/Irrlicht/CXMLReader.cpp delete mode 100644 source/Irrlicht/CXMLReader.h delete mode 100644 source/Irrlicht/CXMLReaderImpl.h delete mode 100644 source/Irrlicht/CXMLWriter.cpp delete mode 100644 source/Irrlicht/CXMLWriter.h delete mode 100644 source/Irrlicht/irrXML.cpp diff --git a/examples/09.Meshviewer/main.cpp b/examples/09.Meshviewer/main.cpp index 1a5f51a..024c7fa 100644 --- a/examples/09.Meshviewer/main.cpp +++ b/examples/09.Meshviewer/main.cpp @@ -4,8 +4,7 @@ This tutorial show how to create a more complex application with the engine. We construct a simple mesh viewer using the user interface API and the scene management of Irrlicht. The tutorial show how to create and use Buttons, Windows, Toolbars, Menus, ComboBoxes, Tabcontrols, Editboxes, Images, -MessageBoxes, SkyBoxes, and how to parse XML files with the integrated XML -reader of the engine. +MessageBoxes, SkyBoxes. We start like in most other tutorials: Include all necessary header files, add a comment to let the engine be linked with the correct .lib file in Visual @@ -766,55 +765,6 @@ int main(int argc, char* argv[]) // add our media directory as "search path" Device->getFileSystem()->addFileArchive(getExampleMediaPath()); - /* - The next step is to read the configuration file. It is stored in the xml - format and looks a little bit like this: - - @verbatim - - - - - Hello! - - - @endverbatim - - We need the data stored in there to be written into the global variables - StartUpModelFile, MessageText and Caption. This is now done using the - Irrlicht Engine integrated XML parser: - */ - - // read configuration from xml file - - io::IXMLReader* xml = Device->getFileSystem()->createXMLReader( L"config.xml"); - - while(xml && xml->read()) - { - switch(xml->getNodeType()) - { - case io::EXN_TEXT: - // in this xml file, the only text which occurs is the - // messageText - MessageText = xml->getNodeData(); - break; - case io::EXN_ELEMENT: - { - if (core::stringw("startUpModel") == xml->getNodeName()) - StartUpModelFile = xml->getAttributeValue(L"file"); - else - if (core::stringw("messageText") == xml->getNodeName()) - Caption = xml->getAttributeValue(L"caption"); - } - break; - default: - break; - } - } - - if (xml) - xml->drop(); // don't forget to delete the xml reader - // We can pass a model to load per command line parameter if (argc > 1) StartUpModelFile = argv[1]; diff --git a/examples/15.LoadIrrFile/LoadIrrFile.cbp b/examples/15.LoadIrrFile/LoadIrrFile.cbp deleted file mode 100644 index a087158..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile.cbp +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - diff --git a/examples/15.LoadIrrFile/LoadIrrFile.vcproj b/examples/15.LoadIrrFile/LoadIrrFile.vcproj deleted file mode 100644 index fef4626..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile.vcproj +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/project.pbxproj b/examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/project.pbxproj deleted file mode 100644 index 69bd041..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/project.pbxproj +++ /dev/null @@ -1,324 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 5E34CC751B7F8EEF00F212E8 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E34CC741B7F8EEF00F212E8 /* main.cpp */; }; - 5E8570B61B7F9A3200B267D2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E8570B01B7F99F500B267D2 /* Cocoa.framework */; }; - 5E8570B71B7F9A3200B267D2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E8570B41B7F9A0700B267D2 /* IOKit.framework */; }; - 5E8570B81B7F9A3200B267D2 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E8570B21B7F99FE00B267D2 /* OpenGL.framework */; }; - 5E8570BF1B7F9D3A00B267D2 /* media in Resources */ = {isa = PBXBuildFile; fileRef = 5E8570BE1B7F9D3A00B267D2 /* media */; }; - 5E8571181B7FBE8D00B267D2 /* libIrrlicht.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E34CC781B7F90A000F212E8 /* libIrrlicht.a */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 5E34CC511B7F8E6E00F212E8 /* 15.LoadIrrFile.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 15.LoadIrrFile.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 5E34CC741B7F8EEF00F212E8 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; - 5E34CC781B7F90A000F212E8 /* libIrrlicht.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libIrrlicht.a; path = ../../lib/OSX/libIrrlicht.a; sourceTree = ""; }; - 5E8570B01B7F99F500B267D2 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; - 5E8570B21B7F99FE00B267D2 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; - 5E8570B41B7F9A0700B267D2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; }; - 5E8570BE1B7F9D3A00B267D2 /* media */ = {isa = PBXFileReference; lastKnownFileType = folder; name = media; path = ../../media; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 5E34CC4E1B7F8E6E00F212E8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 5E8570B61B7F9A3200B267D2 /* Cocoa.framework in Frameworks */, - 5E8570B71B7F9A3200B267D2 /* IOKit.framework in Frameworks */, - 5E8570B81B7F9A3200B267D2 /* OpenGL.framework in Frameworks */, - 5E8571181B7FBE8D00B267D2 /* libIrrlicht.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 5E34C6D81B7F4A0C00F212E8 = { - isa = PBXGroup; - children = ( - 5E34CC741B7F8EEF00F212E8 /* main.cpp */, - 5E34CC761B7F905600F212E8 /* Libraries */, - 5E34CC521B7F8E6E00F212E8 /* Products */, - 5E34CC771B7F906D00F212E8 /* Resources */, - ); - sourceTree = ""; - }; - 5E34CC521B7F8E6E00F212E8 /* Products */ = { - isa = PBXGroup; - children = ( - 5E34CC511B7F8E6E00F212E8 /* 15.LoadIrrFile.app */, - ); - name = Products; - sourceTree = ""; - }; - 5E34CC761B7F905600F212E8 /* Libraries */ = { - isa = PBXGroup; - children = ( - 5E8570B01B7F99F500B267D2 /* Cocoa.framework */, - 5E8570B41B7F9A0700B267D2 /* IOKit.framework */, - 5E8570B21B7F99FE00B267D2 /* OpenGL.framework */, - 5E34CC781B7F90A000F212E8 /* libIrrlicht.a */, - ); - name = Libraries; - sourceTree = ""; - }; - 5E34CC771B7F906D00F212E8 /* Resources */ = { - isa = PBXGroup; - children = ( - 5E8570BE1B7F9D3A00B267D2 /* media */, - ); - name = Resources; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 5E34CC501B7F8E6E00F212E8 /* 15.LoadIrrFile */ = { - isa = PBXNativeTarget; - buildConfigurationList = 5E34CC701B7F8E6E00F212E8 /* Build configuration list for PBXNativeTarget "15.LoadIrrFile" */; - buildPhases = ( - 5E34CC4D1B7F8E6E00F212E8 /* Sources */, - 5E34CC4E1B7F8E6E00F212E8 /* Frameworks */, - 5E34CC4F1B7F8E6E00F212E8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = 15.LoadIrrFile; - productName = 01.HelloWorld; - productReference = 5E34CC511B7F8E6E00F212E8 /* 15.LoadIrrFile.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 5E34C6D91B7F4A0C00F212E8 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0830; - TargetAttributes = { - 5E34CC501B7F8E6E00F212E8 = { - CreatedOnToolsVersion = 6.1; - }; - }; - }; - buildConfigurationList = 5E34C6DC1B7F4A0C00F212E8 /* Build configuration list for PBXProject "LoadIrrFile" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 5E34C6D81B7F4A0C00F212E8; - productRefGroup = 5E34CC521B7F8E6E00F212E8 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 5E34CC501B7F8E6E00F212E8 /* 15.LoadIrrFile */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 5E34CC4F1B7F8E6E00F212E8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 5E8570BF1B7F9D3A00B267D2 /* media in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 5E34CC4D1B7F8E6E00F212E8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 5E34CC751B7F8EEF00F212E8 /* main.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 5E34C6DD1B7F4A0C00F212E8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = c11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; - ONLY_ACTIVE_ARCH = YES; - }; - name = Debug; - }; - 5E34C6DE1B7F4A0C00F212E8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = c11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; - }; - name = Release; - }; - 5E34CC6C1B7F8E6E00F212E8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEPLOYMENT_LOCATION = YES; - DSTROOT = "$(SRCROOT)/../../bin/OSX"; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(SRCROOT)/../../include", - ); - INFOPLIST_FILE = "$(SRCROOT)/../../media/info_osx.plist"; - INSTALL_PATH = /; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../../lib/OSX"; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 5E34CC6D1B7F8E6E00F212E8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEPLOYMENT_LOCATION = YES; - DSTROOT = "$(SRCROOT)/../../bin/OSX"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(SRCROOT)/../../include", - ); - INFOPLIST_FILE = "$(SRCROOT)/../../media/info_osx.plist"; - INSTALL_PATH = /; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../../lib/OSX"; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 5E34C6DC1B7F4A0C00F212E8 /* Build configuration list for PBXProject "LoadIrrFile" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5E34C6DD1B7F4A0C00F212E8 /* Debug */, - 5E34C6DE1B7F4A0C00F212E8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 5E34CC701B7F8E6E00F212E8 /* Build configuration list for PBXNativeTarget "15.LoadIrrFile" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5E34CC6C1B7F8E6E00F212E8 /* Debug */, - 5E34CC6D1B7F8E6E00F212E8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 5E34C6D91B7F4A0C00F212E8 /* Project object */; -} diff --git a/examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/xcshareddata/xcschemes/15.LoadIrrFile.xcscheme b/examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/xcshareddata/xcschemes/15.LoadIrrFile.xcscheme deleted file mode 100644 index 0de8a80..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile.xcodeproj/xcshareddata/xcschemes/15.LoadIrrFile.xcscheme +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/15.LoadIrrFile/LoadIrrFile_vc10.vcxproj b/examples/15.LoadIrrFile/LoadIrrFile_vc10.vcxproj deleted file mode 100644 index db6dec2..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile_vc10.vcxproj +++ /dev/null @@ -1,235 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 15.LoadIrrFile - {78C9F424-523C-49AC-94B7-823AA4A26BF9} - LoadIrrFile - - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - - \ No newline at end of file diff --git a/examples/15.LoadIrrFile/LoadIrrFile_vc11.vcxproj b/examples/15.LoadIrrFile/LoadIrrFile_vc11.vcxproj deleted file mode 100644 index db6dec2..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile_vc11.vcxproj +++ /dev/null @@ -1,235 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 15.LoadIrrFile - {78C9F424-523C-49AC-94B7-823AA4A26BF9} - LoadIrrFile - - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - - \ No newline at end of file diff --git a/examples/15.LoadIrrFile/LoadIrrFile_vc12.vcxproj b/examples/15.LoadIrrFile/LoadIrrFile_vc12.vcxproj deleted file mode 100644 index 97b4c71..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile_vc12.vcxproj +++ /dev/null @@ -1,235 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 15.LoadIrrFile - {78C9F424-523C-49AC-94B7-823AA4A26BF9} - LoadIrrFile - - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - Application - false - MultiByte - Windows7.1SDK - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - - \ No newline at end of file diff --git a/examples/15.LoadIrrFile/LoadIrrFile_vc14.vcxproj b/examples/15.LoadIrrFile/LoadIrrFile_vc14.vcxproj deleted file mode 100644 index 0811f13..0000000 --- a/examples/15.LoadIrrFile/LoadIrrFile_vc14.vcxproj +++ /dev/null @@ -1,235 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 15.LoadIrrFile - {78C9F424-523C-49AC-94B7-823AA4A26BF9} - LoadIrrFile - - - - Application - false - MultiByte - v140 - - - Application - false - MultiByte - v140 - - - Application - false - MultiByte - v140 - - - Application - false - MultiByte - v140 - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - - - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Debug/LoadIrrFile.tlb - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win32-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - .\Release/LoadIrrFile.tlb - - - - - MaxSpeed - OnlyExplicitInline - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - - - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0c07 - - - ..\..\bin\Win64-VisualStudio\15.LoadIrrFile.exe - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - Console - - - - - - - Disabled - Disabled - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - EnableFastChecks - EnableFastChecks - MaxSpeed - MaxSpeed - %(AdditionalIncludeDirectories) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(PreprocessorDefinitions) - - - - - - \ No newline at end of file diff --git a/examples/15.LoadIrrFile/Makefile b/examples/15.LoadIrrFile/Makefile deleted file mode 100644 index 5fde118..0000000 --- a/examples/15.LoadIrrFile/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -# Makefile for Irrlicht Examples -# It's usually sufficient to change just the target name and source file list -# and be sure that CXX is set to a valid compiler - -# Name of the executable created (.exe will be added automatically if necessary) -Target := 15.LoadIrrFile -# List of source files, separated by spaces -Sources := main.cpp -# Path to Irrlicht directory, should contain include/ and lib/ -IrrlichtHome := ../.. -# Path for the executable. Note that Irrlicht.dll should usually also be there for win32 systems -BinPath = ../../bin/$(SYSTEM) - -# general compiler settings (might need to be set when compiling the lib, too) -CPPFLAGS += -I$(IrrlichtHome)/include -I/usr/X11R6/include -ifndef NDEBUG -CXXFLAGS += -g -Wall -else -CXXFLAGS += -O3 -endif - -#default target is Linux -all: all_linux - -# target specific settings -all_linux all_win32 static_win32: LDFLAGS += -L$(IrrlichtHome)/lib/$(SYSTEM) -lIrrlicht -all_linux: LDFLAGS += -L/usr/X11R6/lib$(LIBSELECT) -lGL -lEGL -lGLESv1_CM -lGLESv2 -lXxf86vm -lXext -lX11 -lXcursor -all_linux clean_linux: SYSTEM=Linux -all_win32 clean_win32 static_win32: SYSTEM=Win32-gcc -all_win32 clean_win32 static_win32: SUF=.exe -static_win32: CPPFLAGS += -D_IRR_STATIC_LIB_ -all_win32: LDFLAGS += -lopengl32 -lEGL -lGLESv1_CM -lGLESv2 -lm -static_win32: LDFLAGS += -lgdi32 -lwinspool -lcomdlg32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lopengl32 -lEGL -lGLESv1_CM -lGLESv2 -# name of the binary - only valid for targets which set SYSTEM -DESTPATH = $(BinPath)/$(Target)$(SUF) - -all_linux all_win32 static_win32: - $(warning Building...) - $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS) - -clean: clean_linux clean_win32 - $(warning Cleaning...) - -clean_linux clean_win32: - @$(RM) $(DESTPATH) - -.PHONY: all all_win32 static_win32 clean clean_linux clean_win32 - -#multilib handling -ifeq ($(HOSTTYPE), x86_64) -LIBSELECT=64 -endif -#solaris real-time features -ifeq ($(HOSTTYPE), sun4) -LDFLAGS += -lrt -endif diff --git a/examples/15.LoadIrrFile/main.cpp b/examples/15.LoadIrrFile/main.cpp deleted file mode 100644 index d28e6f6..0000000 --- a/examples/15.LoadIrrFile/main.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/** Example 015 Loading Scenes from .irr Files - -Since version 1.1, Irrlicht is able to save and load -the full scene graph into an .irr file, an xml based -format. There is an editor available to edit -those files, named irrEdit (http://www.ambiera.com/irredit) -which can also be used as world and particle editor. -This tutorial shows how to use .irr files. - -Lets start: Create an Irrlicht device and setup the window. -*/ - -#include -#include "driverChoice.h" -#include "exampleHelper.h" - -using namespace irr; - -#ifdef _MSC_VER -#pragma comment(lib, "Irrlicht.lib") -#endif - -int main(int argc, char** argv) -{ - // ask user for driver - video::E_DRIVER_TYPE driverType=driverChoiceConsole(); - if (driverType==video::EDT_COUNT) - return 1; - - // create device and exit if creation failed - - IrrlichtDevice* device = - createDevice(driverType, core::dimension2d(640, 480)); - - if (device == 0) - return 1; // could not create selected driver. - - device->setWindowCaption(L"Load .irr file example"); - - video::IVideoDriver* driver = device->getVideoDriver(); - scene::ISceneManager* smgr = device->getSceneManager(); - - /* - Now load our .irr file. - .irr files can store the whole scene graph including animators, - materials and particle systems. And there is also the possibility to - store arbitrary user data for every scene node in that file. To keep - this example simple, we are simply loading the scene here. See the - documentation at ISceneManager::loadScene and ISceneManager::saveScene - for more information. So to load and display a complicated huge scene, - we only need a single call to loadScene(). - */ - - // load the scene - /* You might have to work around some minor problems in current .irr loader: - - It can't load meshes relative to the .irr file, but only relative to the working directory. - So you might have to change your working directory to the path where the .irr file is in. - - When passing a custom parent node to loadScene then irr_scene attributes will be passed to that. - Usually not a problem, but for example AmbientLight will not change that way unless you create a custom - SceneNode type which can interpret those attributes. - */ - if (argc>1) - smgr->loadScene(argv[1]); - else - smgr->loadScene(getExampleMediaPath() + "example.irr"); - - /* - Now we'll create a camera, and give it a collision response animator - that's built from the mesh nodes in the scene we just loaded. - */ - scene::ICameraSceneNode * camera = smgr->addCameraSceneNodeFPS(0, 50.f, 0.1f); - - // Create a meta triangle selector to hold several triangle selectors. - scene::IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector(); - - /* - Now we will find all the nodes in the scene and create triangle - selectors for all suitable nodes. Typically, you would want to make a - more informed decision about which nodes to performs collision checks - on; you could capture that information in the node name or Id. - */ - core::array nodes; - smgr->getSceneNodesFromType(scene::ESNT_ANY, nodes); // Find all nodes - - for (u32 i=0; i < nodes.size(); ++i) - { - scene::ISceneNode * node = nodes[i]; - scene::ITriangleSelector * selector = 0; - - switch(node->getType()) - { - case scene::ESNT_CUBE: - case scene::ESNT_ANIMATED_MESH: - // Because the selector won't animate with the mesh, - // and is only being used for camera collision, we'll just use an approximate - // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0) - selector = smgr->createTriangleSelectorFromBoundingBox(node); - break; - - case scene::ESNT_MESH: - case scene::ESNT_SPHERE: // Derived from IMeshSceneNode - selector = smgr->createTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node); - break; - - case scene::ESNT_TERRAIN: - selector = smgr->createTerrainTriangleSelector((scene::ITerrainSceneNode*)node); - break; - - case scene::ESNT_OCTREE: - selector = smgr->createOctreeTriangleSelector(((scene::IMeshSceneNode*)node)->getMesh(), node); - break; - - default: - // Don't create a selector for this node type - break; - } - - if(selector) - { - // Add it to the meta selector, which will take a reference to it - meta->addTriangleSelector(selector); - // And drop my reference to it, so that the meta selector owns it. - selector->drop(); - } - } - - /* - Now that the mesh scene nodes have had triangle selectors created and added - to the meta selector, create a collision response animator from that meta selector. - */ - scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( - meta, camera, core::vector3df(5,5,5), - core::vector3df(0,0,0)); - meta->drop(); // I'm done with the meta selector now - - camera->addAnimator(anim); - anim->drop(); // I'm done with the animator now - - // And set the camera position so that it doesn't start off stuck in the geometry - camera->setPosition(core::vector3df(0.f, 20.f, 0.f)); - - // Point the camera at the cube node, by finding the first node of type ESNT_CUBE - scene::ISceneNode * cube = smgr->getSceneNodeFromType(scene::ESNT_CUBE); - if(cube) - camera->setTarget(cube->getAbsolutePosition()); - - /* - That's it. Draw everything and finish as usual. - */ - - int lastFPS = -1; - - while(device->run()) - if (device->isWindowActive()) - { - driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,200,200,200)); - smgr->drawAll(); - driver->endScene(); - - int fps = driver->getFPS(); - - if (lastFPS != fps) - { - core::stringw str = L"Load Irrlicht File example - Irrlicht Engine ["; - str += driver->getName(); - str += "] FPS:"; - str += fps; - - device->setWindowCaption(str.c_str()); - lastFPS = fps; - } - - } - - device->drop(); - - return 0; -} - -/* -**/ diff --git a/examples/15.LoadIrrFile/tutorial.html b/examples/15.LoadIrrFile/tutorial.html deleted file mode 100644 index e3e4a6b..0000000 --- a/examples/15.LoadIrrFile/tutorial.html +++ /dev/null @@ -1,129 +0,0 @@ - - -Irrlicht Engine Tutorial - - - - -
- - - - - - - - -
- Tutorial 15. Load .irr File
-

Since version 1.1, Irrlicht is able to save and load the full scene - graph into an .irr file, an xml based format. There is also an editor - available to edit those files, named irrEdit on http://www.ambiera.com/irredit, - which can also be used as world and particle editor. This tutorial shows - how to use .irr files.

-


-

-
-
- - - - - - - -
- Lets start!
-

Lets start: Create an Irrlicht device and setup the window.

- - - - -
#include 
-#include 
-using namespace irr;
-
-#pragma comment(lib, "Irrlicht.lib")
-
-int main()
-{
-	// ask user for driver
-
-	video::E_DRIVER_TYPE driverType;
-
-	printf("Please select the driver you want for this example:\n"\
-		" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
-		" (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\
-		" (f) NullDevice\n (otherKey) exit\n\n");
-
-	char i;
-	std::cin >> i;
-
-	switch(i)
-	{
-		case 'a': driverType = video::EDT_DIRECT3D9;break;
-		case 'b': driverType = video::EDT_DIRECT3D8;break;
-		case 'c': driverType = video::EDT_OPENGL;   break;
-		case 'd': driverType = video::EDT_SOFTWARE; break;
-		case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
-		case 'f': driverType = video::EDT_NULL;     break;
-		default: return 1;
-	}	
-
-	// create device and exit if creation failed
-
-	IrrlichtDevice* device =
-		createDevice(driverType, core::dimension2d(640, 480));
-
-	if (device == 0)
-		return 1; // could not create selected driver.
-
-	device->setWindowCaption(L"Load .irr file example");
-
-	video::IVideoDriver* driver = device->getVideoDriver();
-	scene::ISceneManager* smgr = device->getSceneManager();
-
-

Now load our .irr file. .irr files can store the whole scene graph - including animators, materials and particle systems. And there is also - the possibility to store arbitrary user data for every scene node in - that file. To keep this example simple, we are simply loading the scene - here. See the documentation at ISceneManager::loadScene and ISceneManager::saveScene - for more information. So to load and display a complicated huge scene, - we only need a single call to loadScene().

- - - - -
// load the scene
smgr->loadScene("../../media/example.irr");
-

That was it already. Now add a camera and draw the scene.

- - - - -
	// add a user controlled camera
-
-	smgr->addCameraSceneNodeFPS();
-
-	// and draw everything.
-	
-	while(device->run())
-	if (device->isWindowActive())
-	{
-		driver->beginScene(true, true, video::SColor(0,200,200,200));
-		smgr->drawAll();
-		driver->endScene();
-	}
-
-	device->drop();
-	
-	return 0;
-}
-
- -
-

 

-
-

 

-

 

- - diff --git a/examples/25.XmlHandling/Makefile b/examples/25.XmlHandling/Makefile deleted file mode 100644 index 359b8f0..0000000 --- a/examples/25.XmlHandling/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -# Makefile for Irrlicht Examples -# It's usually sufficient to change just the target name and source file list -# and be sure that CXX is set to a valid compiler - -# Name of the executable created (.exe will be added automatically if necessary) -Target := 25.XmlHandling -# List of source files, separated by spaces -Sources := main.cpp -# Path to Irrlicht directory, should contain include/ and lib/ -IrrlichtHome := ../.. -# Path for the executable. Note that Irrlicht.dll should usually also be there for win32 systems -BinPath = ../../bin/$(SYSTEM) - -# general compiler settings (might need to be set when compiling the lib, too) -CPPFLAGS += -I$(IrrlichtHome)/include -I/usr/X11R6/include -ifndef NDEBUG -CXXFLAGS += -g -Wall -else -CXXFLAGS += -O3 -endif - -#default target is Linux -all: all_linux - -# target specific settings -all_linux all_win32 static_win32: LDFLAGS += -L$(IrrlichtHome)/lib/$(SYSTEM) -lIrrlicht -all_linux: LDFLAGS += -L/usr/X11R6/lib$(LIBSELECT) -lGL -lEGL -lGLESv1_CM -lGLESv2 -lXxf86vm -lXext -lX11 -lXcursor -all_linux clean_linux: SYSTEM=Linux -all_win32 clean_win32 static_win32: SYSTEM=Win32-gcc -all_win32 clean_win32 static_win32: SUF=.exe -static_win32: CPPFLAGS += -D_IRR_STATIC_LIB_ -all_win32: LDFLAGS += -lopengl32 -lEGL -lGLESv1_CM -lGLESv2 -lm -static_win32: LDFLAGS += -lgdi32 -lwinspool -lcomdlg32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lopengl32 -lEGL -lGLESv1_CM -lGLESv2 -# name of the binary - only valid for targets which set SYSTEM -DESTPATH = $(BinPath)/$(Target)$(SUF) - -all_linux all_win32 static_win32: - $(warning Building...) - $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS) - -clean: clean_linux clean_win32 - $(warning Cleaning...) - -clean_linux clean_win32: - @$(RM) $(DESTPATH) - -.PHONY: all all_win32 static_win32 clean clean_linux clean_win32 - -#multilib handling -ifeq ($(HOSTTYPE), x86_64) -LIBSELECT=64 -endif -#solaris real-time features -ifeq ($(HOSTTYPE), sun4) -LDFLAGS += -lrt -endif diff --git a/examples/25.XmlHandling/XmlHandling.cbp b/examples/25.XmlHandling/XmlHandling.cbp deleted file mode 100644 index b9bc5c9..0000000 --- a/examples/25.XmlHandling/XmlHandling.cbp +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - diff --git a/examples/25.XmlHandling/XmlHandling.vcproj b/examples/25.XmlHandling/XmlHandling.vcproj deleted file mode 100644 index 152a415..0000000 --- a/examples/25.XmlHandling/XmlHandling.vcproj +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/25.XmlHandling/XmlHandling.xcodeproj/project.pbxproj b/examples/25.XmlHandling/XmlHandling.xcodeproj/project.pbxproj deleted file mode 100644 index 6a16233..0000000 --- a/examples/25.XmlHandling/XmlHandling.xcodeproj/project.pbxproj +++ /dev/null @@ -1,324 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 5E34CC751B7F8EEF00F212E8 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E34CC741B7F8EEF00F212E8 /* main.cpp */; }; - 5E8570B61B7F9A3200B267D2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E8570B01B7F99F500B267D2 /* Cocoa.framework */; }; - 5E8570B71B7F9A3200B267D2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E8570B41B7F9A0700B267D2 /* IOKit.framework */; }; - 5E8570B81B7F9A3200B267D2 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E8570B21B7F99FE00B267D2 /* OpenGL.framework */; }; - 5E8570BF1B7F9D3A00B267D2 /* media in Resources */ = {isa = PBXBuildFile; fileRef = 5E8570BE1B7F9D3A00B267D2 /* media */; }; - 5E8571181B7FBE8D00B267D2 /* libIrrlicht.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E34CC781B7F90A000F212E8 /* libIrrlicht.a */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 5E34CC511B7F8E6E00F212E8 /* 25.XmlHandling.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 25.XmlHandling.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 5E34CC741B7F8EEF00F212E8 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; - 5E34CC781B7F90A000F212E8 /* libIrrlicht.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libIrrlicht.a; path = ../../lib/OSX/libIrrlicht.a; sourceTree = ""; }; - 5E8570B01B7F99F500B267D2 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; - 5E8570B21B7F99FE00B267D2 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; }; - 5E8570B41B7F9A0700B267D2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; }; - 5E8570BE1B7F9D3A00B267D2 /* media */ = {isa = PBXFileReference; lastKnownFileType = folder; name = media; path = ../../media; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 5E34CC4E1B7F8E6E00F212E8 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 5E8570B61B7F9A3200B267D2 /* Cocoa.framework in Frameworks */, - 5E8570B71B7F9A3200B267D2 /* IOKit.framework in Frameworks */, - 5E8570B81B7F9A3200B267D2 /* OpenGL.framework in Frameworks */, - 5E8571181B7FBE8D00B267D2 /* libIrrlicht.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 5E34C6D81B7F4A0C00F212E8 = { - isa = PBXGroup; - children = ( - 5E34CC741B7F8EEF00F212E8 /* main.cpp */, - 5E34CC761B7F905600F212E8 /* Libraries */, - 5E34CC521B7F8E6E00F212E8 /* Products */, - 5E34CC771B7F906D00F212E8 /* Resources */, - ); - sourceTree = ""; - }; - 5E34CC521B7F8E6E00F212E8 /* Products */ = { - isa = PBXGroup; - children = ( - 5E34CC511B7F8E6E00F212E8 /* 25.XmlHandling.app */, - ); - name = Products; - sourceTree = ""; - }; - 5E34CC761B7F905600F212E8 /* Libraries */ = { - isa = PBXGroup; - children = ( - 5E8570B01B7F99F500B267D2 /* Cocoa.framework */, - 5E8570B41B7F9A0700B267D2 /* IOKit.framework */, - 5E8570B21B7F99FE00B267D2 /* OpenGL.framework */, - 5E34CC781B7F90A000F212E8 /* libIrrlicht.a */, - ); - name = Libraries; - sourceTree = ""; - }; - 5E34CC771B7F906D00F212E8 /* Resources */ = { - isa = PBXGroup; - children = ( - 5E8570BE1B7F9D3A00B267D2 /* media */, - ); - name = Resources; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 5E34CC501B7F8E6E00F212E8 /* 25.XmlHandling */ = { - isa = PBXNativeTarget; - buildConfigurationList = 5E34CC701B7F8E6E00F212E8 /* Build configuration list for PBXNativeTarget "25.XmlHandling" */; - buildPhases = ( - 5E34CC4D1B7F8E6E00F212E8 /* Sources */, - 5E34CC4E1B7F8E6E00F212E8 /* Frameworks */, - 5E34CC4F1B7F8E6E00F212E8 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = 25.XmlHandling; - productName = 01.HelloWorld; - productReference = 5E34CC511B7F8E6E00F212E8 /* 25.XmlHandling.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 5E34C6D91B7F4A0C00F212E8 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0830; - TargetAttributes = { - 5E34CC501B7F8E6E00F212E8 = { - CreatedOnToolsVersion = 6.1; - }; - }; - }; - buildConfigurationList = 5E34C6DC1B7F4A0C00F212E8 /* Build configuration list for PBXProject "XmlHandling" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 5E34C6D81B7F4A0C00F212E8; - productRefGroup = 5E34CC521B7F8E6E00F212E8 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 5E34CC501B7F8E6E00F212E8 /* 25.XmlHandling */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 5E34CC4F1B7F8E6E00F212E8 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 5E8570BF1B7F9D3A00B267D2 /* media in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 5E34CC4D1B7F8E6E00F212E8 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 5E34CC751B7F8EEF00F212E8 /* main.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 5E34C6DD1B7F4A0C00F212E8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = c11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; - ONLY_ACTIVE_ARCH = YES; - }; - name = Debug; - }; - 5E34C6DE1B7F4A0C00F212E8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = c11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; - }; - name = Release; - }; - 5E34CC6C1B7F8E6E00F212E8 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEPLOYMENT_LOCATION = YES; - DSTROOT = "$(SRCROOT)/../../bin/OSX"; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(SRCROOT)/../../include", - ); - INFOPLIST_FILE = "$(SRCROOT)/../../media/info_osx.plist"; - INSTALL_PATH = /; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../../lib/OSX"; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 5E34CC6D1B7F8E6E00F212E8 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "-"; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEPLOYMENT_LOCATION = YES; - DSTROOT = "$(SRCROOT)/../../bin/OSX"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - "$(SRCROOT)/../../include", - ); - INFOPLIST_FILE = "$(SRCROOT)/../../media/info_osx.plist"; - INSTALL_PATH = /; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../../lib/OSX"; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 5E34C6DC1B7F4A0C00F212E8 /* Build configuration list for PBXProject "XmlHandling" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5E34C6DD1B7F4A0C00F212E8 /* Debug */, - 5E34C6DE1B7F4A0C00F212E8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 5E34CC701B7F8E6E00F212E8 /* Build configuration list for PBXNativeTarget "25.XmlHandling" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5E34CC6C1B7F8E6E00F212E8 /* Debug */, - 5E34CC6D1B7F8E6E00F212E8 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 5E34C6D91B7F4A0C00F212E8 /* Project object */; -} diff --git a/examples/25.XmlHandling/XmlHandling.xcodeproj/xcshareddata/xcschemes/25.XmlHandling.xcscheme b/examples/25.XmlHandling/XmlHandling.xcodeproj/xcshareddata/xcschemes/25.XmlHandling.xcscheme deleted file mode 100644 index 2d21c8e..0000000 --- a/examples/25.XmlHandling/XmlHandling.xcodeproj/xcshareddata/xcschemes/25.XmlHandling.xcscheme +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/25.XmlHandling/XmlHandling_vc10.vcxproj b/examples/25.XmlHandling/XmlHandling_vc10.vcxproj deleted file mode 100644 index 43f9e73..0000000 --- a/examples/25.XmlHandling/XmlHandling_vc10.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 25.XmlHandling - {8FDA260E-EF27-4F8C-8720-7AF707DD0D9E} - 25.XmlHandling - Win32Proj - - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - - - - - \ No newline at end of file diff --git a/examples/25.XmlHandling/XmlHandling_vc11.vcxproj b/examples/25.XmlHandling/XmlHandling_vc11.vcxproj deleted file mode 100644 index 43f9e73..0000000 --- a/examples/25.XmlHandling/XmlHandling_vc11.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 25.XmlHandling - {8FDA260E-EF27-4F8C-8720-7AF707DD0D9E} - 25.XmlHandling - Win32Proj - - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - - - - - \ No newline at end of file diff --git a/examples/25.XmlHandling/XmlHandling_vc12.vcxproj b/examples/25.XmlHandling/XmlHandling_vc12.vcxproj deleted file mode 100644 index 5354637..0000000 --- a/examples/25.XmlHandling/XmlHandling_vc12.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 25.XmlHandling - {8FDA260E-EF27-4F8C-8720-7AF707DD0D9E} - 25.XmlHandling - Win32Proj - - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - Application - MultiByte - Windows7.1SDK - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - - - - - \ No newline at end of file diff --git a/examples/25.XmlHandling/XmlHandling_vc14.vcxproj b/examples/25.XmlHandling/XmlHandling_vc14.vcxproj deleted file mode 100644 index 4fdb56a..0000000 --- a/examples/25.XmlHandling/XmlHandling_vc14.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - 25.XmlHandling - {8FDA260E-EF27-4F8C-8720-7AF707DD0D9E} - 25.XmlHandling - Win32Proj - - - - Application - MultiByte - v140 - - - Application - MultiByte - v140 - - - Application - MultiByte - v140 - - - Application - MultiByte - v140 - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - ..\..\bin\Win32-VisualStudio\ - ..\..\bin\Win64-VisualStudio\ - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebug - - - Level3 - EditAndContinue - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - Disabled - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebug - - - Level3 - ProgramDatabase - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - true - Console - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - true - Speed - ..\..\include;%(AdditionalIncludeDirectories) - WIN32;WIN64;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - - - Level3 - - - Cdecl - - - ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) - false - Console - true - true - - - - - - - - - - - \ No newline at end of file diff --git a/examples/25.XmlHandling/main.cpp b/examples/25.XmlHandling/main.cpp deleted file mode 100644 index d022e5c..0000000 --- a/examples/25.XmlHandling/main.cpp +++ /dev/null @@ -1,510 +0,0 @@ -/** Example 025 Xml Handling - -Demonstrates loading and saving of configurations via XML - -@author Y.M. Bosman \ - -This demo features a fully usable system for configuration handling. The code -can easily be integrated into own apps. - -*/ - -#include -#include "exampleHelper.h" - -using namespace irr; -using namespace core; -using namespace scene; -using namespace video; -using namespace io; -using namespace gui; - -#ifdef _MSC_VER -#pragma comment(lib, "Irrlicht.lib") -#endif - - -/* SettingManager class. - -This class loads and writes the settings and manages the options. - -The class makes use of irrMap which is a an associative arrays using a -red-black tree it allows easy mapping of a key to a value, along the way there -is some information on how to use it. -*/ - -class SettingManager -{ -public: - - // Construct setting managers and set default settings - SettingManager(const stringw& settings_file): SettingsFile(settings_file), NullDevice(0) - { - // Irrlicht null device, we want to load settings before we actually created our device, therefore, nulldevice - NullDevice = irr::createDevice(irr::video::EDT_NULL); - - //DriverOptions is an irrlicht map, - //we can insert values in the map in two ways by calling insert(key,value) or by using the [key] operator - //the [] operator overrides values if they already exist - DriverOptions.insert(L"Software", EDT_SOFTWARE); - DriverOptions.insert(L"OpenGL", EDT_OPENGL); - DriverOptions.insert(L"Direct3D9", EDT_DIRECT3D9); - - //some resolution options - ResolutionOptions.insert(L"640x480", dimension2du(640,480)); - ResolutionOptions.insert(L"800x600", dimension2du(800,600)); - ResolutionOptions.insert(L"1024x768", dimension2du(1024,768)); - - //our preferred defaults - SettingMap.insert(L"driver", L"Direct3D9"); - SettingMap.insert(L"resolution", L"640x480"); - SettingMap.insert(L"fullscreen", L"0"); //0 is false - } - - // Destructor, you could store settings automatically on exit of your - // application if you wanted to in our case we simply drop the - // nulldevice - ~SettingManager() - { - if (NullDevice) - { - NullDevice->closeDevice(); - NullDevice->drop(); - } - }; - - /* - Load xml from disk, overwrite default settings - The xml we are trying to load has the following structure - settings nested in sections nested in the root node, like so -
-		
-		
-			
-		
-	
- */ - bool load() - { - //if not able to create device don't attempt to load - if (!NullDevice) - return false; - - irr::io::IXMLReader* xml = NullDevice->getFileSystem()->createXMLReader(SettingsFile); //create xml reader - if (!xml) - return false; - - const stringw settingTag(L"setting"); //we'll be looking for this tag in the xml - stringw currentSection; //keep track of our current section - const stringw videoTag(L"video"); //constant for videotag - - //while there is more to read - while (xml->read()) - { - //check the node type - switch (xml->getNodeType()) - { - //we found a new element - case irr::io::EXN_ELEMENT: - { - //we currently are in the empty or mygame section and find the video tag so we set our current section to video - if (currentSection.empty() && videoTag.equals_ignore_case(xml->getNodeName())) - { - currentSection = videoTag; - } - //we are in the video section and we find a setting to parse - else if (currentSection.equals_ignore_case(videoTag) && settingTag.equals_ignore_case(xml->getNodeName() )) - { - //read in the key - stringw key = xml->getAttributeValueSafe(L"name"); - //if there actually is a key to set - if (!key.empty()) - { - //set the setting in the map to the value, - //the [] operator overrides values if they already exist or inserts a new key value - //pair into the settings map if it was not defined yet - SettingMap[key] = xml->getAttributeValueSafe(L"value"); - } - } - - //.. - // You can add your own sections and tags to read in here - //.. - } - break; - - //we found the end of an element - case irr::io::EXN_ELEMENT_END: - //we were at the end of the video section so we reset our tag - currentSection=L""; - break; - default: - break; - } - } - - // don't forget to delete the xml reader - xml->drop(); - - return true; - } - - // Save the xml to disk. We use the nulldevice. - bool save() - { - - //if not able to create device don't attempt to save - if (!NullDevice) - return false; - - //create xml writer - irr::io::IXMLWriter* xwriter = NullDevice->getFileSystem()->createXMLWriter( SettingsFile ); - if (!xwriter) - return false; - - //write out the obligatory xml header. Each xml-file needs to have exactly one of those. - xwriter->writeXMLHeader(); - - //start element mygame, you replace the label "mygame" with anything you want - xwriter->writeElement(L"mygame"); - xwriter->writeLineBreak(); //new line - - //start section with video settings - xwriter->writeElement(L"video"); - xwriter->writeLineBreak(); //new line - - // getIterator gets us a pointer to the first node of the settings map - // every iteration we increase the iterator which gives us the next map node - // until we reach the end we write settings one by one by using the nodes key and value functions - map::Iterator i = SettingMap.getIterator(); - for(; !i.atEnd(); i++) - { - //write element as - //the second parameter indicates this is an empty element with no children, just attributes - xwriter->writeElement(L"setting",true, L"name", i->getKey().c_str(), L"value",i->getValue().c_str() ); - xwriter->writeLineBreak(); - } - xwriter->writeLineBreak(); - - //close video section - xwriter->writeClosingTag(L"video"); - xwriter->writeLineBreak(); - - //.. - // You can add writing sound settings, savegame information etc - //.. - - //close mygame section - xwriter->writeClosingTag(L"mygame"); - - //delete xml writer - xwriter->drop(); - - return true; - } - - // Set setting in our manager - void setSetting(const stringw& name, const stringw& value) - { - SettingMap[name]=value; - } - - // set setting overload to quickly assign integers to our setting map - void setSetting(const stringw& name, s32 value) - { - SettingMap[name]=stringw(value); - } - - // Get setting as string - stringw getSetting(const stringw& key) const - { - //the find function or irrmap returns a pointer to a map Node - //if the key can be found, otherwise it returns null - //the map node has the function getValue and getKey, as we already know the key, we return node->getValue() - map::Node* n = SettingMap.find(key); - if (n) - return n->getValue(); - else - return L""; - } - - // - bool getSettingAsBoolean(const stringw& key ) const - { - stringw s = getSetting(key); - if (s.empty()) - return false; - return s.equals_ignore_case(L"1"); - } - - // - s32 getSettingAsInteger(const stringw& key) const - { - //we implicitly cast to string instead of stringw because strtol10 does not accept wide strings - const stringc s = getSetting(key); - if (s.empty()) - return 0; - - return strtol10(s.c_str()); - } - -public: - map DriverOptions; //available options for driver config - map ResolutionOptions; //available options for resolution config -private: - SettingManager(const SettingManager& other); // defined but not implemented - SettingManager& operator=(const SettingManager& other); // defined but not implemented - - map SettingMap; //current config - - stringw SettingsFile; // location of the xml, usually the - irr::IrrlichtDevice* NullDevice; -}; - -/* -Application context for global variables -*/ -struct SAppContext -{ - SAppContext() - : Device(0),Gui(0), Driver(0), Settings(0), ShouldQuit(false), - ButtonSave(0), ButtonExit(0), ListboxDriver(0), - ListboxResolution(0), CheckboxFullscreen(0) - { - } - - ~SAppContext() - { - if (Settings) - delete Settings; - - if (Device) - { - Device->closeDevice(); - Device->drop(); - } - } - - IrrlichtDevice* Device; - IGUIEnvironment* Gui; - IVideoDriver* Driver; - SettingManager* Settings; - bool ShouldQuit; - - //settings dialog - IGUIButton* ButtonSave; - IGUIButton* ButtonExit; - IGUIListBox* ListboxDriver; - IGUIListBox* ListboxResolution; - IGUICheckBox* CheckboxFullscreen; -}; - -/* - A typical event receiver. -*/ -class MyEventReceiver : public IEventReceiver -{ -public: - MyEventReceiver(SAppContext & a) : App(a) { } - - virtual bool OnEvent(const SEvent& event) - { - if (event.EventType == EET_GUI_EVENT ) - { - switch ( event.GUIEvent.EventType ) - { - //handle button click events - case EGET_BUTTON_CLICKED: - { - //Our save button was called so we obtain the settings from our dialog and save them - if ( event.GUIEvent.Caller == App.ButtonSave ) - { - //if there is a selection write it - if ( App.ListboxDriver->getSelected() != -1) - App.Settings->setSetting(L"driver", App.ListboxDriver->getListItem(App.ListboxDriver->getSelected())); - - //if there is a selection write it - if ( App.ListboxResolution->getSelected() != -1) - App.Settings->setSetting(L"resolution", App.ListboxResolution->getListItem(App.ListboxResolution->getSelected())); - - App.Settings->setSetting(L"fullscreen", App.CheckboxFullscreen->isChecked()); - - - if (App.Settings->save()) - { - App.Gui->addMessageBox(L"settings save",L"settings saved, please restart for settings to change effect","",true); - } - } - // cancel/exit button clicked, tell the application to exit - else if ( event.GUIEvent.Caller == App.ButtonExit) - { - App.ShouldQuit = true; - } - } - break; - default: - break; - } - } - - return false; - } - -private: - SAppContext & App; -}; - - -/* -Function to create a video settings dialog -This dialog shows the current settings from the configuration xml and allows them to be changed -*/ -void createSettingsDialog(SAppContext& app) -{ - // first get rid of alpha in gui - for (irr::s32 i=0; igetSkin()->getColor((irr::gui::EGUI_DEFAULT_COLOR)i); - col.setAlpha(255); - app.Gui->getSkin()->setColor((irr::gui::EGUI_DEFAULT_COLOR)i, col); - } - - //create video settings windows - gui::IGUIWindow* windowSettings = app.Gui->addWindow(rect(10,10,400,400),true,L"Videosettings"); - app.Gui->addStaticText (L"Select your desired video settings", rect< s32 >(10,20, 200, 40), false, true, windowSettings); - - // add listbox for driver choice - app.Gui->addStaticText (L"Driver", rect< s32 >(10,50, 200, 60), false, true, windowSettings); - app.ListboxDriver = app.Gui->addListBox(rect(10,60,220,120), windowSettings, 1,true); - - //add all available options to the driver choice listbox - map::Iterator i = app.Settings->DriverOptions.getIterator(); - for(; !i.atEnd(); i++) - app.ListboxDriver->addItem(i->getKey().c_str()); - - //set currently selected driver - app.ListboxDriver->setSelected(app.Settings->getSetting("driver").c_str()); - - // add listbox for resolution choice - app.Gui->addStaticText (L"Resolution", rect< s32 >(10,130, 200, 140), false, true, windowSettings); - app.ListboxResolution = app.Gui->addListBox(rect(10,140,220,200), windowSettings, 1,true); - - //add all available options to the resolution listbox - map::Iterator ri = app.Settings->ResolutionOptions.getIterator(); - for(; !ri.atEnd(); ri++) - app.ListboxResolution->addItem(ri->getKey().c_str()); - - //set currently selected resolution - app.ListboxResolution->setSelected(app.Settings->getSetting("resolution").c_str()); - - //add checkbox to toggle fullscreen, initially set to loaded setting - app.CheckboxFullscreen = app.Gui->addCheckBox( - app.Settings->getSettingAsBoolean("fullscreen"), - rect(10,220,220,240), windowSettings, -1, - L"Fullscreen"); - - //last but not least add save button - app.ButtonSave = app.Gui->addButton( - rect(80,250,150,270), windowSettings, 2, - L"Save video settings"); - - //exit/cancel button - app.ButtonExit = app.Gui->addButton( - rect(160,250,240,270), windowSettings, 2, - L"Cancel and exit"); -} - -/* -The main function. Creates all objects and does the XML handling. -*/ -int main() -{ - //create new application context - SAppContext app; - - //create device creation parameters that can get overwritten by our settings file - SIrrlichtCreationParameters param; - param.DriverType = EDT_SOFTWARE; - param.WindowSize.set(640,480); - - // Try to load config. - // I leave it as an exercise of the reader to store the configuration in the local application data folder, - // the only logical place to store config data for games. For all other operating systems I redirect to your manuals - app.Settings = new SettingManager(getExampleMediaPath() + "settings.xml"); - if ( !app.Settings->load() ) - { - // ... - // Here add your own exception handling, for now we continue because there are defaults set in SettingManager constructor - // ... - } - else - { - //settings xml loaded from disk, - - //map driversetting to driver type and test if the setting is valid - //the DriverOptions map contains string representations mapped to to irrlicht E_DRIVER_TYPE enum - //e.g "direct3d9" will become 4 - //see DriverOptions in the settingmanager class for details - map::Node* driver = app.Settings->DriverOptions.find( app.Settings->getSetting("driver") ); - - if (driver) - { - if ( irr::IrrlichtDevice::isDriverSupported( static_cast( driver->getValue() ))) - { - // selected driver is supported, so we use it. - param.DriverType = static_cast( driver->getValue()); - } - } - - //map resolution setting to dimension in a similar way as demonstrated above - map::Node* res = app.Settings->ResolutionOptions.find( app.Settings->getSetting("resolution") ); - if (res) - { - param.WindowSize = res->getValue(); - } - - //get fullscreen setting from config - param.Fullscreen = app.Settings->getSettingAsBoolean("fullscreen"); - } - - //create the irrlicht device using the settings - app.Device = createDeviceEx(param); - if (app.Device == 0) - { - // You can add your own exception handling on driver failure - exit(0); - } - - app.Device->setWindowCaption(L"Xmlhandling - Irrlicht engine tutorial"); - app.Driver = app.Device->getVideoDriver(); - app.Gui = app.Device->getGUIEnvironment(); - - createSettingsDialog(app); - - //set event receiver so we can respond to gui events - MyEventReceiver receiver(app); - app.Device->setEventReceiver(&receiver); - - //enter main loop - while (!app.ShouldQuit && app.Device->run()) - { - if (app.Device->isWindowActive()) - { - app.Driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0,200,200,200)); - app.Gui->drawAll(); - app.Driver->endScene(); - } - app.Device->sleep(10); - } - - //app destroys device in destructor - - return 0; -} - -/* -**/ diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index aca268b..4f42e74 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -13,7 +13,6 @@ set(IRREXAMPLES 11.PerPixelLighting 12.TerrainRendering 13.RenderToTexture - 15.LoadIrrFile 16.Quake3MapShader 18.SplitScreen 19.MouseAndJoystick @@ -22,7 +21,6 @@ set(IRREXAMPLES 22.MaterialViewer 23.SMeshHandling 24.CursorControl - 25.XmlHandling 26.OcclusionQuery 27.PostProcessing 28.CubeMapping diff --git a/include/IAttributes.h b/include/IAttributes.h index 507561d..270bd0e 100644 --- a/include/IAttributes.h +++ b/include/IAttributes.h @@ -23,8 +23,6 @@ #include "line3d.h" #include "irrString.h" #include "irrArray.h" -#include "IXMLReader.h" -#include "IXMLWriter.h" #include "EAttributes.h" #include "path.h" @@ -76,20 +74,6 @@ public: //! Removes all attributes virtual void clear() = 0; - //! Reads attributes from a xml file. - //! \param reader The XML reader to read from - //! \param readCurrentElementOnly If set to true, reading only works if current element has the name 'attributes' or - //! the name specified using elementName. - //! \param elementName The surrounding element name. If it is null, the default one, "attributes" will be taken. - //! If set to false, the first appearing list of attributes are read. - virtual bool read(io::IXMLReader* reader, bool readCurrentElementOnly=false, const wchar_t* elementName=0) = 0; - - //! Write these attributes into a xml file - //! \param writer: The XML writer to write to - //! \param writeXMLHeader: Writes a header to the XML file, required if at the beginning of the file - //! \param elementName: The surrounding element name. If it is null, the default one, "attributes" will be taken. - virtual bool write(io::IXMLWriter* writer, bool writeXMLHeader=false, const wchar_t* elementName=0) = 0; - /* diff --git a/include/IColladaMeshWriter.h b/include/IColladaMeshWriter.h deleted file mode 100644 index a8c6dd2..0000000 --- a/include/IColladaMeshWriter.h +++ /dev/null @@ -1,456 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__ -#define __IRR_I_COLLADA_MESH_WRITER_H_INCLUDED__ - -#include "IMeshWriter.h" -#include "ISceneNode.h" -#include "IAnimatedMesh.h" -#include "SMaterial.h" - -namespace irr -{ -namespace io -{ - class IWriteFile; -} // end namespace io - -namespace scene -{ - //! Lighting models - more or less the way Collada categorizes materials - enum E_COLLADA_TECHNIQUE_FX - { - //! Blinn-phong which is default for opengl and dx fixed function pipelines. - //! But several well-known renderers don't support it and prefer phong. - ECTF_BLINN, - //! Phong shading, default in many external renderers. - ECTF_PHONG, - //! diffuse shaded surface that is independent of lighting. - ECTF_LAMBERT, - // constantly shaded surface that is independent of lighting. - ECTF_CONSTANT - }; - - //! How to interpret the opacity in collada - enum E_COLLADA_TRANSPARENT_FX - { - //! default - only alpha channel of color or texture is used. - ECOF_A_ONE = 0, - - //! Alpha values for each RGB channel of color or texture are used. - ECOF_RGB_ZERO = 1 - }; - - //! Color names collada uses in it's color samplers - enum E_COLLADA_COLOR_SAMPLER - { - ECCS_DIFFUSE, - ECCS_AMBIENT, - ECCS_EMISSIVE, - ECCS_SPECULAR, - ECCS_TRANSPARENT, - ECCS_REFLECTIVE - }; - - //! Irrlicht colors which can be mapped to E_COLLADA_COLOR_SAMPLER values - enum E_COLLADA_IRR_COLOR - { - //! Don't write this element at all - ECIC_NONE, - - //! Check IColladaMeshWriterProperties for custom color - ECIC_CUSTOM, - - //! Use SMaterial::DiffuseColor - ECIC_DIFFUSE, - - //! Use SMaterial::AmbientColor - ECIC_AMBIENT, - - //! Use SMaterial::EmissiveColor - ECIC_EMISSIVE, - - //! Use SMaterial::SpecularColor - ECIC_SPECULAR - }; - - //! Control when geometry elements are created - enum E_COLLADA_GEOMETRY_WRITING - { - //! Default - write each mesh exactly once to collada. Optimal but will not work with many tools. - ECGI_PER_MESH, - - //! Write each mesh as often as it's used with different materials-names in the scene. - //! Material names which are used here are created on export, so using the IColladaMeshWriterNames - //! interface you have some control over how many geometries are written. - ECGI_PER_MESH_AND_MATERIAL - }; - - //! Callback interface for properties which can be used to influence collada writing - class IColladaMeshWriterProperties : public virtual IReferenceCounted - { - public: - virtual ~IColladaMeshWriterProperties () {} - - //! Which lighting model should be used in the technique (FX) section when exporting effects (materials) - virtual E_COLLADA_TECHNIQUE_FX getTechniqueFx(const video::SMaterial& material) const = 0; - - //! Which texture index should be used when writing the texture of the given sampler color. - /** \return the index to the texture-layer or -1 if that texture should never be exported - Note: for ECCS_TRANSPARENT by default the alpha channel is used, if you want to use RGB you have to set - also the ECOF_RGB_ZERO flag in getTransparentFx. */ - virtual s32 getTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0; - - //! Return which color from Irrlicht should be used for the color requested by collada - /** Note that collada allows exporting either texture or color, not both. - So color mapping is only checked if we have no valid texture already. - By default we try to return best fits when possible. For example ECCS_DIFFUSE is mapped to ECIC_DIFFUSE. - When ECIC_CUSTOM is returned then the result of getCustomColor will be used. */ - virtual E_COLLADA_IRR_COLOR getColorMapping(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0; - - //! Return custom colors for certain color types requested by collada. - /** Only used when getColorMapping returns ECIC_CUSTOM for the same parameters. */ - virtual video::SColor getCustomColor(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const = 0; - - //! Return the transparence color interpretation. - /** Not this is only about ECCS_TRANSPARENT and does not affect getTransparency. */ - virtual E_COLLADA_TRANSPARENT_FX getTransparentFx(const video::SMaterial& material) const = 0; - - //! Transparency value for that material. - /** This value is additional to transparent settings, if both are set they will be multiplicated. - \return 1.0 for fully transparent, 0.0 for not transparent and not written at all when < 0.f */ - virtual f32 getTransparency(const video::SMaterial& material) const = 0; - - //! Reflectivity value for that material - /** The amount of perfect mirror reflection to be added to the reflected light - \return 0.0 - 1.0 for reflectivity and element is not written at all when < 0.f */ - virtual f32 getReflectivity(const video::SMaterial& material) const = 0; - - //! Return index of refraction for that material - /** By default we don't write that. - \return a value greater equal 0.f to write \ when it is lesser than 0 nothing will be written */ - virtual f32 getIndexOfRefraction(const video::SMaterial& material) const = 0; - - //! Should node be used in scene export? (only needed for scene-writing, ignored in mesh-writing) - //! By default all visible nodes are exported. - virtual bool isExportable(const irr::scene::ISceneNode * node) const = 0; - - //! Return the mesh for the given node. If it has no mesh or shouldn't export it's mesh - //! you can return 0 in which case only the transformation matrix of the node will be used. - // TODO: Function is not const because there is no const getMesh() function for several Irrlicht nodes. - virtual IMesh* getMesh(irr::scene::ISceneNode * node) = 0; - - //! Return if the node has it's own material overwriting the mesh-materials - /** Usually true except for mesh-nodes which have isReadOnlyMaterials set. - This is mostly important for naming (as ISceneNode::getMaterial() already returns the correct material). - You have to override it when exporting custom scenenodes with own materials. - \return true => The node's own material is used, false => ignore node material and use the one from the mesh */ - virtual bool useNodeMaterial(const scene::ISceneNode* node) const = 0; - - }; - - //! Callback interface to use custom names on collada writing. - /** You can either modify names and id's written to collada or you can use - this interface to just find out which names are used on writing. - Names are often used later as xs:anyURI, so avoid whitespace, '#' and '%' in the names. - */ - class IColladaMeshWriterNames : public virtual IReferenceCounted - { - public: - - virtual ~IColladaMeshWriterNames () {} - - //! Return a unique name for the given mesh - /** Note that names really must be unique here per mesh-pointer, so - mostly it's a good idea to return the nameForMesh from - IColladaMeshWriter::getDefaultNameGenerator(). Also names must follow - the xs:NCName standard to be valid, you can run them through - IColladaMeshWriter::toNCName to ensure that. - \param mesh Pointer to the mesh which needs a name - \param instance When E_COLLADA_GEOMETRY_WRITING is not ECGI_PER_MESH then - several instances of the same mesh can be written and this counts them. - */ - virtual irr::core::stringc nameForMesh(const scene::IMesh* mesh, int instance) = 0; - - //! Return a unique name for the given node - /** Note that names really must be unique here per node-pointer, so - mostly it's a good idea to return the nameForNode from - IColladaMeshWriter::getDefaultNameGenerator(). Also names must follow - the xs:NCName standard to be valid, you can run them through - IColladaMeshWriter::toNCName to ensure that. - */ - virtual irr::core::stringc nameForNode(const scene::ISceneNode* node) = 0; - - //! Return a name for the material - /** There is one material created in the writer for each unique name. - So you can use this to control the number of materials which get written. - For example Irrlicht does by default write one material for each material - instanced by a node. So if you know that in your application material - instances per node are identical between different nodes you can reduce - the number of exported materials using that knowledge by using identical - names for such shared materials. - Names must follow the xs:NCName standard to be valid, you can run them - through IColladaMeshWriter::toNCName to ensure that. - */ - virtual irr::core::stringc nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) = 0; - }; - - - //! Interface for writing meshes - class IColladaMeshWriter : public IMeshWriter - { - public: - - IColladaMeshWriter() - : Properties(0), DefaultProperties(0), NameGenerator(0), DefaultNameGenerator(0) - , WriteTextures(true), WriteDefaultScene(true), ExportSMaterialOnce(true) - , AmbientLight(0.f, 0.f, 0.f, 1.f) - , UnitMeter(1.f), UnitName("meter") - , GeometryWriting(ECGI_PER_MESH) - { - ParamNamesUV[0] = "U"; - ParamNamesUV[1] = "V"; - } - - //! Destructor - virtual ~IColladaMeshWriter() - { - if ( Properties ) - Properties->drop(); - if ( DefaultProperties ) - DefaultProperties->drop(); - if ( NameGenerator ) - NameGenerator->drop(); - if ( DefaultNameGenerator ) - DefaultNameGenerator->drop(); - } - - //! writes a scene starting with the given node - //\param writeRoot: 0 = no, 1=yes unless root is scenemanager, 2=yes - virtual bool writeScene(io::IWriteFile* file, scene::ISceneNode* root, int writeRoot=1) = 0; - - - //! Set if texture information should be written - virtual void setWriteTextures(bool write) - { - WriteTextures = write; - } - - //! Get if texture information should be written - virtual bool getWriteTextures() const - { - return WriteTextures; - } - - //! Set if a default scene should be written when writing meshes. - /** Many collada readers fail to read a mesh if the collada files doesn't contain a scene as well. - The scene is doing an instantiation of the mesh. - When using writeScene this flag is ignored (as we have scene there already) - */ - virtual void setWriteDefaultScene(bool write) - { - WriteDefaultScene = write; - } - - //! Get if a default scene should be written - virtual bool getWriteDefaultScene() const - { - return WriteDefaultScene; - } - - //! Sets ambient color of the scene to write - virtual void setAmbientLight(const video::SColorf &ambientColor) - { - AmbientLight = ambientColor; - } - - //! Return ambient light of the scene which is written - virtual video::SColorf getAmbientLight() const - { - return AmbientLight; - } - - //! Set the unit distances for all elements and objects - /** - \param meter: Real-world meters to use per unit. Default 1 unit = 1 meter. For 1 unit = 1cm you would set to 0.01 - \param name: Name to use for distance unit. Default is "meter". */ - virtual void setUnit(irr::f32 meter, const irr::core::stringc& name) - { - UnitMeter = meter; - UnitName = name; - } - - //! Return real world meters to use per unit for all elements and objects - virtual irr::f32 getUnitMeter() const - { - return UnitMeter; - } - - //! Return name to use for distance units. Like p.E. "meter". - virtual irr::core::stringc getUnitName() const - { - return UnitName; - } - - //! Control when and how often a mesh is written - /** Optimally ECGI_PER_MESH would be always sufficient - writing geometry once per mesh. - Unfortunately many tools (at the time of writing this nearly all of them) have trouble - on import when different materials are used per node. So when you override materials - per node and importing the resulting collada has materials problems in other tools try - using other values here. - \param writeStyle One of the E_COLLADA_GEOMETRY_WRITING settings. - */ - virtual void setGeometryWriting(E_COLLADA_GEOMETRY_WRITING writeStyle) - { - GeometryWriting = writeStyle; - } - - //! Get the current style of geometry writing. - virtual E_COLLADA_GEOMETRY_WRITING getGeometryWriting() const - { - return GeometryWriting; - } - - //! Make certain there is only one collada material generated per Irrlicht material - /** Checks before creating a collada material-name if an identical - irr:::video::SMaterial has been exported already. If so don't export it with - another name. This is set by default and leads to way smaller .dae files. - Note that if you need to disable this flag for some reason you can still - get a similar effect using the IColladaMeshWriterNames::nameForMaterial - by returning identical names for identical materials there. - */ - virtual void setExportSMaterialsOnlyOnce(bool exportOnce) - { - ExportSMaterialOnce = exportOnce; - } - - virtual bool getExportSMaterialsOnlyOnce() const - { - return ExportSMaterialOnce; - } - - //! Set properties to use by the meshwriter instead of it's default properties. - /** Overloading properties with an own class allows modifying the writing process in certain ways. - By default properties are set to the DefaultProperties. */ - virtual void setProperties(IColladaMeshWriterProperties * p) - { - if ( p == Properties ) - return; - if ( p ) - p->grab(); - if ( Properties ) - Properties->drop(); - Properties = p; - } - - //! Get properties which are currently used. - virtual IColladaMeshWriterProperties * getProperties() const - { - return Properties; - } - - //! Return the original default properties of the writer. - /** You can use this pointer in your own properties to access and return default values. */ - IColladaMeshWriterProperties * getDefaultProperties() const - { - return DefaultProperties; - } - - //! Install a generator to create custom names on export. - virtual void setNameGenerator(IColladaMeshWriterNames * nameGenerator) - { - if ( nameGenerator == NameGenerator ) - return; - if ( nameGenerator ) - nameGenerator->grab(); - if ( NameGenerator ) - NameGenerator->drop(); - NameGenerator = nameGenerator; - } - - //! Get currently used name generator - virtual IColladaMeshWriterNames * getNameGenerator() const - { - return NameGenerator; - } - - //! Return the original default name generator of the writer. - /** You can use this pointer in your own generator to access and return default values. */ - IColladaMeshWriterNames * getDefaultNameGenerator() const - { - return DefaultNameGenerator; - } - - //! Restrict the characters of oldString a set of allowed characters in xs:NCName and add the prefix. - /** A tool function to help when using a custom name generator to generative valid names for collada names and id's. */ - virtual irr::core::stringc toNCName(const irr::core::stringc& oldString, const irr::core::stringc& prefix=irr::core::stringc("_NC_")) const = 0; - - //! After export you can find out which name had been used for writing the geometry for this node. - /** The name comes from IColladaMeshWriterNames::nameForMesh, but you can't access the node there. - \return Either a pointer to the name or NULL */ - // TODO: Function is not const because there is no const getMesh() function for several Irrlicht nodes. - virtual const irr::core::stringc* findGeometryNameForNode(ISceneNode* node) = 0; - - //! Change param name used for UV's. - /** Param names for UV's have a name. By default it's "U" and "V". - Usually it doesn't matter as names are optional in Collada anyway. - But unfortunately some tools insist on specific names. - So if "U", "V" does not work then try to export by setting this to "S", "T". - One tool which insists on "S", "T" is for example SketchUp. - */ - void SetParamNamesUV(const core::stringc& u, const core::stringc& v) - { - ParamNamesUV[0] = u; - ParamNamesUV[1] = v; - } - - - protected: - // NOTE: You usually should also call setProperties with the same parameter when using setDefaultProperties - virtual void setDefaultProperties(IColladaMeshWriterProperties * p) - { - if ( p == DefaultProperties ) - return; - if ( p ) - p->grab(); - if ( DefaultProperties ) - DefaultProperties->drop(); - DefaultProperties = p; - } - - // NOTE: You usually should also call setNameGenerator with the same parameter when using setDefaultProperties - virtual void setDefaultNameGenerator(IColladaMeshWriterNames * p) - { - if ( p == DefaultNameGenerator ) - return; - if ( p ) - p->grab(); - if ( DefaultNameGenerator ) - DefaultNameGenerator->drop(); - DefaultNameGenerator = p; - } - - protected: - irr::core::stringc ParamNamesUV[2]; - - private: - IColladaMeshWriterProperties * Properties; - IColladaMeshWriterProperties * DefaultProperties; - IColladaMeshWriterNames * NameGenerator; - IColladaMeshWriterNames * DefaultNameGenerator; - bool WriteTextures; - bool WriteDefaultScene; - bool ExportSMaterialOnce; - video::SColorf AmbientLight; - irr::f32 UnitMeter; - irr::core::stringc UnitName; - E_COLLADA_GEOMETRY_WRITING GeometryWriting; - }; - - -} // end namespace -} // end namespace - -#endif diff --git a/include/IFileSystem.h b/include/IFileSystem.h index f9a6ee6..afecaf1 100644 --- a/include/IFileSystem.h +++ b/include/IFileSystem.h @@ -6,8 +6,6 @@ #define __I_FILE_SYSTEM_H_INCLUDED__ #include "IReferenceCounted.h" -#include "IXMLReader.h" -#include "IXMLWriter.h" #include "IFileArchive.h" namespace irr @@ -318,70 +316,6 @@ public: \return True if file exists, and false if it does not exist or an error occurred. */ virtual bool existFile(const path& filename) const =0; - //! Creates a XML Reader from a file which returns all parsed strings as wide characters (wchar_t*). - /** Use createXMLReaderUTF8() if you prefer char* instead of wchar_t*. See IIrrXMLReader for - more information on how to use the parser. - \return 0, if file could not be opened, otherwise a pointer to the created - IXMLReader is returned. After use, the reader - has to be deleted using its IXMLReader::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLReader* createXMLReader(const path& filename) =0; - - //! Creates a XML Reader from a file which returns all parsed strings as wide characters (wchar_t*). - /** Use createXMLReaderUTF8() if you prefer char* instead of wchar_t*. See IIrrXMLReader for - more information on how to use the parser. - \return 0, if file could not be opened, otherwise a pointer to the created - IXMLReader is returned. After use, the reader - has to be deleted using its IXMLReader::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLReader* createXMLReader(IReadFile* file) =0; - - //! Creates a XML Reader from a file which returns all parsed strings as ASCII/UTF-8 characters (char*). - /** Use createXMLReader() if you prefer wchar_t* instead of char*. See IIrrXMLReader for - more information on how to use the parser. - \return 0, if file could not be opened, otherwise a pointer to the created - IXMLReader is returned. After use, the reader - has to be deleted using its IXMLReaderUTF8::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLReaderUTF8* createXMLReaderUTF8(const path& filename) =0; - - //! Creates a XML Reader from a file which returns all parsed strings as ASCII/UTF-8 characters (char*). - /** Use createXMLReader() if you prefer wchar_t* instead of char*. See IIrrXMLReader for - more information on how to use the parser. - \return 0, if file could not be opened, otherwise a pointer to the created - IXMLReader is returned. After use, the reader - has to be deleted using its IXMLReaderUTF8::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLReaderUTF8* createXMLReaderUTF8(IReadFile* file) =0; - - //! Creates a XML Writer from a file which will write ASCII/UTF-8 characters (char*). - /** \return 0, if file could not be opened, otherwise a pointer to the created - IXMLWriter is returned. After use, the reader - has to be deleted using its IXMLWriter::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLWriterUTF8* createXMLWriterUTF8(const path& filename) =0; - - //! Creates a XML Writer from a file which will write ASCII/UTF-8 characters (char*). - /** \return 0, if file could not be opened, otherwise a pointer to the created - IXMLWriter is returned. After use, the reader - has to be deleted using its IXMLWriter::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLWriterUTF8* createXMLWriterUTF8(IWriteFile* file) =0; - - //! Creates a XML Writer from a file. - /** \return 0, if file could not be opened, otherwise a pointer to the created - IXMLWriter is returned. After use, the reader - has to be deleted using its IXMLWriter::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLWriter* createXMLWriter(const path& filename) =0; - - //! Creates a XML Writer from a file. - /** \return 0, if file could not be opened, otherwise a pointer to the created - IXMLWriter is returned. After use, the reader - has to be deleted using its IXMLWriter::drop() method. - See IReferenceCounted::drop() for more information. */ - virtual IXMLWriter* createXMLWriter(IWriteFile* file) =0; - //! Creates a new empty collection of attributes, usable for serialization and more. /** \param driver: Video driver to be used to load textures when specified as attribute values. Can be null to prevent automatic texture loading by attributes. diff --git a/include/IGUIEnvironment.h b/include/IGUIEnvironment.h index 4bd3db8..3b6095b 100644 --- a/include/IGUIEnvironment.h +++ b/include/IGUIEnvironment.h @@ -11,8 +11,6 @@ #include "EMessageBoxFlags.h" #include "EFocusFlags.h" #include "IEventReceiver.h" -#include "IXMLReader.h" -#include "IXMLWriter.h" #include "path.h" namespace irr @@ -622,12 +620,6 @@ public: //! Reads attributes of the gui environment virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)=0; - //! writes an element - virtual void writeGUIElement(io::IXMLWriter* writer, IGUIElement* element) =0; - - //! reads an element - virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* element) =0; - //! Find the next element which would be selected when pressing the tab-key /** If you set the focus for the result you can manually force focus-changes like they would happen otherwise by the tab-keys. diff --git a/include/ISceneManager.h b/include/ISceneManager.h index 65e81c3..ac860a7 100644 --- a/include/ISceneManager.h +++ b/include/ISceneManager.h @@ -19,7 +19,6 @@ #include "SceneParameters.h" #include "IGeometryCreator.h" #include "ISkinnedMesh.h" -#include "IXMLWriter.h" namespace irr { @@ -199,37 +198,6 @@ namespace scene * directly in Irrlicht. * * - * COLLADA (.dae, .xml) - * COLLADA is an open Digital Asset Exchange Schema for - * the interactive 3D industry. There are exporters and - * importers for this format available for most of the - * big 3d packagesat http://collada.org. Irrlicht can - * import COLLADA files by using the - * ISceneManager::getMesh() method. COLLADA files need - * not contain only one single mesh but multiple meshes - * and a whole scene setup with lights, cameras and mesh - * instances, this loader can set up a scene as - * described by the COLLADA file instead of loading and - * returning one single mesh. By default, this loader - * behaves like the other loaders and does not create - * instances, but it can be switched into this mode by - * using - * SceneManager->getParameters()->setAttribute(COLLADA_CREATE_SCENE_INSTANCES, true); - * Created scene nodes will be named as the names of the - * nodes in the COLLADA file. The returned mesh is just - * a dummy object in this mode. Meshes included in the - * scene will be added into the scene manager with the - * following naming scheme: - * "path/to/file/file.dea#meshname". The loading of such - * meshes is logged. Currently, this loader is able to - - - * create meshes (made of only polygons), lights, and - * cameras. Materials and animations are currently not - * supported but this will change with future releases. - * - * - * * Delgine DeleD (.dmf) * DeleD (delgine.com) is a 3D editor and level-editor * combined into one and is specifically designed for 3D @@ -266,13 +234,6 @@ namespace scene * by Fabio Concas and adapted by Thomas Alten. * * - * Irrlicht Mesh (.irrMesh) - * This is a static mesh format written in XML, native - * to Irrlicht and written by the irr mesh writer. - * This format is exported by the CopperCube engine's - * lightmapper. - * - * * LightWave (.lwo) * Native to NewTek's LightWave 3D, the LWO format is well * known and supported by many exporters. This loader will @@ -1586,26 +1547,6 @@ namespace scene \return True if successful. */ virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0; - //! Saves the current scene into a file. - /** Scene nodes with the option isDebugObject set to true are - not being saved. The scene is usually written to an .irr file, - an xml based format. .irr files can Be edited with the Irrlicht - Engine Editor, irrEdit (http://www.ambiera.com/irredit/). To - load .irr files again, see ISceneManager::loadScene(). - \param writer XMLWriter with which the scene is saved. - \param currentPath Path which is used for relative file names. - Usually the directory of the file written into. - \param userDataSerializer If you want to save some user data - for every scene node into the file, implement the - ISceneUserDataSerializer interface and provide it as parameter - here. Otherwise, simply specify 0 as this parameter. - \param node Node which is taken as the top node of the scene. - This node and all of its descendants are saved into the scene - file. Pass 0 or the scene manager to save the full scene (which - is also the default). - \return True if successful. */ - virtual bool saveScene(io::IXMLWriter* writer, const io::path& currentPath, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) = 0; - //! Loads a scene. Note that the current scene is not cleared before. /** The scene is usually loaded from an .irr file, an xml based format, but other scene formats can be added to the engine via diff --git a/include/IXMLReader.h b/include/IXMLReader.h deleted file mode 100644 index 7babb45..0000000 --- a/include/IXMLReader.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __I_XML_READER_H_INCLUDED__ -#define __I_XML_READER_H_INCLUDED__ - -#include "IReferenceCounted.h" -#include "irrXML.h" - -namespace irr -{ -namespace io -{ - //! An xml reader for wide characters, derived from IReferenceCounted. - /** This XML Parser can read any type of text files from any source - Irrlicht can read. Just call IFileSystem::createXMLReader(). For more - information on how to use the parser, see IIrrXMLReader */ - typedef IIrrXMLReader IXMLReader; - - //! An xml reader for ASCII or UTF-8 characters, derived from IReferenceCounted. - /** This XML Parser can read any type of text files from any source - Irrlicht can read. Just call IFileSystem::createXMLReaderUTF8(). For - more information on how to use the parser, see IIrrXMLReader */ - typedef IIrrXMLReader IXMLReaderUTF8; - -} // end namespace io -} // end namespace irr - -#endif - diff --git a/include/IXMLWriter.h b/include/IXMLWriter.h deleted file mode 100644 index 18c40e2..0000000 --- a/include/IXMLWriter.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __I_XML_WRITER_H_INCLUDED__ -#define __I_XML_WRITER_H_INCLUDED__ - -#include "IReferenceCounted.h" -#include "irrXML.h" - -namespace irr -{ -namespace io -{ - //! An xml writer for wide characters, derived from IReferenceCounted. - /** Call IFileSystem::createXMLReader(). to create an IXMLWriter */ - typedef IIrrXMLWriter IXMLWriter; - - //! An xml writer for ASCII or UTF-8 characters, derived from IReferenceCounted. - /** Call IFileSystem::createXMLReaderUtf8(). to create an IXMLWriter */ - typedef IIrrXMLWriter IXMLWriterUTF8; - -} // end namespace io -} // end namespace irr - -#endif diff --git a/include/IrrCompileConfig.h b/include/IrrCompileConfig.h index 5c54dd6..f674bbd 100644 --- a/include/IrrCompileConfig.h +++ b/include/IrrCompileConfig.h @@ -151,12 +151,6 @@ //! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht. #define _IRR_MATERIAL_MAX_TEXTURES_ 8 -//! Whether to support XML and XML-based formats (irrmesh, collada...) -#define _IRR_COMPILE_WITH_XML_ -#ifdef NO_IRR_COMPILE_WITH_XML_ -#undef _IRR_COMPILE_WITH_XML_ -#endif - //! Add a leak-hunter to Irrlicht which helps finding unreleased reference counted objects. //! NOTE: This is slow and should only be used for debugging //#define _IRR_COMPILE_WITH_LEAK_HUNTER_ @@ -532,11 +526,6 @@ B3D, MS3D or X meshes */ #endif #endif // _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_ -//! Define _IRR_COMPILE_WITH_IRR_MESH_LOADER_ if you want to load Irrlicht Engine .irrmesh files -#define _IRR_COMPILE_WITH_IRR_MESH_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_IRR_MESH_LOADER_ -#undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_ -#endif //! Define _IRR_COMPILE_WITH_HALFLIFE_LOADER_ if you want to load Halflife animated files #define _IRR_COMPILE_WITH_HALFLIFE_LOADER_ #ifdef NO_IRR_COMPILE_WITH_HALFLIFE_LOADER_ @@ -557,11 +546,6 @@ B3D, MS3D or X meshes */ #ifdef NO_IRR_COMPILE_WITH_3DS_LOADER_ #undef _IRR_COMPILE_WITH_3DS_LOADER_ #endif -//! Define _IRR_COMPILE_WITH_COLLADA_LOADER_ if you want to load Collada files -#define _IRR_COMPILE_WITH_COLLADA_LOADER_ -#ifdef NO_IRR_COMPILE_WITH_COLLADA_LOADER_ -#undef _IRR_COMPILE_WITH_COLLADA_LOADER_ -#endif //! Define _IRR_COMPILE_WITH_CSM_LOADER_ if you want to load Cartography Shop files #define _IRR_COMPILE_WITH_CSM_LOADER_ #ifdef NO_IRR_COMPILE_WITH_CSM_LOADER_ @@ -618,16 +602,6 @@ B3D, MS3D or X meshes */ #undef _IRR_COMPILE_WITH_SMF_LOADER_ #endif -//! Define _IRR_COMPILE_WITH_IRR_WRITER_ if you want to write static .irrMesh files -#define _IRR_COMPILE_WITH_IRR_WRITER_ -#ifdef NO_IRR_COMPILE_WITH_IRR_WRITER_ -#undef _IRR_COMPILE_WITH_IRR_WRITER_ -#endif -//! Define _IRR_COMPILE_WITH_COLLADA_WRITER_ if you want to write Collada files -#define _IRR_COMPILE_WITH_COLLADA_WRITER_ -#ifdef NO_IRR_COMPILE_WITH_COLLADA_WRITER_ -#undef _IRR_COMPILE_WITH_COLLADA_WRITER_ -#endif //! Define _IRR_COMPILE_WITH_STL_WRITER_ if you want to write .stl files #define _IRR_COMPILE_WITH_STL_WRITER_ #ifdef NO_IRR_COMPILE_WITH_STL_WRITER_ @@ -866,14 +840,6 @@ precision will be lower but speed higher. currently X86 only #undef __IRR_HAS_S64 #endif -// These depend on XML -#ifndef _IRR_COMPILE_WITH_XML_ - #undef _IRR_COMPILE_WITH_IRR_MESH_LOADER_ - #undef _IRR_COMPILE_WITH_IRR_WRITER_ - #undef _IRR_COMPILE_WITH_COLLADA_WRITER_ - #undef _IRR_COMPILE_WITH_COLLADA_LOADER_ -#endif - #if defined(__BORLANDC__) #include diff --git a/include/irrXML.h b/include/irrXML.h deleted file mode 100644 index 57c3b54..0000000 --- a/include/irrXML.h +++ /dev/null @@ -1,645 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine" and the "irrXML" project. -// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h - -#ifndef __IRR_XML_H_INCLUDED__ -#define __IRR_XML_H_INCLUDED__ - -#include -#include "IrrCompileConfig.h" -#include "irrArray.h" -#include "irrString.h" - -/** \mainpage irrXML 1.2 API documentation -
- - \section intro Introduction - - Welcome to the irrXML API documentation. - Here you'll find any information you'll need to develop applications with - irrXML. If you look for a tutorial on how to start, take a look at the \ref irrxmlexample, - at the homepage of irrXML at www.ambiera.com/irrxml/ - or into the SDK in the directory example. - - irrXML is intended to be a high speed and easy-to-use XML Parser for C++, and - this documentation is an important part of it. If you have any questions or - suggestions, just send a email to the author of the engine, Nikolaus Gebhardt - (niko (at) irrlicht3d.org). For more information about this parser, see \ref history. - - \section features Features - - irrXML provides forward-only, read-only - access to a stream of non validated XML data. It was fully implemented by - Nikolaus Gebhardt. Its current features are: - - - It it fast as lighting and has very low memory usage. It was - developed with the intention of being used in 3D games, as it already has been. - - irrXML is very small: It only consists of 60 KB of code and can be added easily - to your existing project. - - Of course, it is platform independent and works with lots of compilers. - - It is able to parse ASCII, UTF-8, UTF-16 and UTF-32 text files, both in - little and big endian format. - - Independent of the input file format, the parser can return all strings in ASCII, UTF-8, - UTF-16 and UTF-32 format. - - With its optional file access abstraction it has the advantage that it can read not - only from files but from any type of data (memory, network, ...). For example when - used with the Irrlicht Engine, it directly reads from compressed .zip files. - - Just like the Irrlicht Engine for which it was originally created, it is extremely easy - to use. - - It has no external dependencies, it does not even need the STL. - - Although irrXML has some strengths, it currently also has the following limitations: - - - The input xml file is not validated and assumed to be correct. - - \section irrxmlexample Example - - The following code demonstrates the basic usage of irrXML. A simple xml - file like this is parsed: - \code - - - - - - Welcome to the Mesh Viewer of the "Irrlicht Engine". - - - \endcode - - The code for parsing this file would look like this: - \code - #include - using namespace irr; // irrXML is located in the namespace irr::io - using namespace io; - - #include // we use STL strings to store data in this example - - void main() - { - // create the reader using one of the factory functions - - IrrXMLReader* xml = createIrrXMLReader("config.xml"); - - // strings for storing the data we want to get out of the file - std::string modelFile; - std::string messageText; - std::string caption; - - // parse the file until end reached - - while(xml && xml->read()) - { - switch(xml->getNodeType()) - { - case EXN_TEXT: - // in this xml file, the only text which occurs is the messageText - messageText = xml->getNodeData(); - break; - case EXN_ELEMENT: - { - if (!strcmp("model", xml->getNodeName())) - modelFile = xml->getAttributeValue("file"); - else - if (!strcmp("messageText", xml->getNodeName())) - caption = xml->getAttributeValue("caption"); - } - break; - } - } - - // delete the xml parser after usage - delete xml; - } - \endcode - - \section howto How to use - - Simply add the source files in the /src directory of irrXML to your project. Done. - - \section license License - - The irrXML license is based on the zlib license. Basically, this means you can do with - irrXML whatever you want: - - Copyright (C) 2002-2012 Nikolaus Gebhardt - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source distribution. - - \section history History - - As lots of references in this documentation and the source show, this xml - parser has originally been a part of the - Irrlicht Engine. But because - the parser has become very useful with the latest release, people asked for a - separate version of it, to be able to use it in non Irrlicht projects. With - irrXML 1.0, this has now been done. -*/ - -namespace irr -{ -namespace io -{ - //! Enumeration of all supported source text file formats - enum ETEXT_FORMAT - { - //! ASCII, file without byte order mark, or not a text file - ETF_ASCII, - - //! UTF-8 format - ETF_UTF8, - - //! UTF-16 format, big endian - ETF_UTF16_BE, - - //! UTF-16 format, little endian - ETF_UTF16_LE, - - //! UTF-32 format, big endian - ETF_UTF32_BE, - - //! UTF-32 format, little endian - ETF_UTF32_LE - }; - - - //! Enumeration for all xml nodes which are parsed by IrrXMLReader - enum EXML_NODE - { - //! No xml node. This is usually the node if you did not read anything yet. - EXN_NONE, - - //! An xml element such as <foo> - EXN_ELEMENT, - - //! End of an xml element such as </foo> - EXN_ELEMENT_END, - - //! Text within an xml element: <foo> this is the text. </foo> - //! Also text between 2 xml elements: </foo> this is the text. <foo> - EXN_TEXT, - - //! An xml comment like <!-- I am a comment --> or a DTD definition. - EXN_COMMENT, - - //! An xml cdata section like <![CDATA[ this is some CDATA ]]> - EXN_CDATA, - - //! Unknown element. - EXN_UNKNOWN - }; - - //! Callback class for file read abstraction. - /** With this, it is possible to make the xml parser read in other - things than just files. The Irrlicht engine is using this for example to - read xml from compressed .zip files. To make the parser read in - any other data, derive a class from this interface, implement the - two methods to read your data and give a pointer to an instance of - your implementation when calling createIrrXMLReader(), - createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */ - class IFileReadCallBack - { - public: - - //! Destructor - virtual ~IFileReadCallBack() {} - - //! Reads an amount of bytes from the file. - /** \param buffer: Pointer to buffer where to read bytes will be written to. - \param sizeToRead: Amount of bytes to read from the file. - \return Returns how much bytes were read. */ - virtual int read(void* buffer, int sizeToRead) = 0; - - //! Returns size of file in bytes on success or -1L on failure. - virtual long getSize() const = 0; - }; - - //! Empty class to be used as parent class for IrrXMLReader. - /** If you need another class as base class for the xml reader, you can do this by creating - the reader using for example new CXMLReaderImpl(yourcallback); - The Irrlicht Engine for example needs IReferenceCounted as base class for every object to - let it automatically reference counted, hence it replaces IXMLBase with IReferenceCounted. - See irrXML.cpp on how this can be done in detail. */ - class IXMLBase - { - }; - - //! Interface providing easy read access to a XML file. - /** You can create an instance of this reader using one of the factory functions - createIrrXMLReader(), createIrrXMLReaderUTF16() and createIrrXMLReaderUTF32(). - If using the parser from the Irrlicht Engine, please use IFileSystem::createXMLReader() - instead. - For a detailed intro how to use the parser, see \ref irrxmlexample and \ref features. - - The typical usage of this parser looks like this: - \code - #include - using namespace irr; // irrXML is located in the namespace irr::io - using namespace io; - - void main() - { - // create the reader using one of the factory functions - IrrXMLReader* xml = createIrrXMLReader("config.xml"); - - if (xml == 0) - return; // file could not be opened - - // parse the file until end reached - while(xml->read()) - { - // based on xml->getNodeType(), do something. - } - - // delete the xml parser after usage - delete xml; - } - \endcode - See \ref irrxmlexample for a more detailed example. - */ - template - class IIrrXMLReader : public super_class - { - public: - - //! Destructor - virtual ~IIrrXMLReader() {} - - //! Reads forward to the next xml node. - /** \return Returns false, if there was no further node. */ - virtual bool read() = 0; - - //! Returns the type of the current XML node. - virtual EXML_NODE getNodeType() const = 0; - - //! Returns attribute count of the current XML node. - /** This is usually - non null if the current node is EXN_ELEMENT, and the element has attributes. - \return Returns amount of attributes of this xml node. */ - virtual unsigned int getAttributeCount() const = 0; - - //! Returns name of an attribute. - /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1. - \return Name of the attribute, 0 if an attribute with this index does not exist. */ - virtual const char_type* getAttributeName(int idx) const = 0; - - //! Returns the value of an attribute. - /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1. - \return Value of the attribute, 0 if an attribute with this index does not exist. */ - virtual const char_type* getAttributeValue(int idx) const = 0; - - //! Returns the value of an attribute. - /** \param name: Name of the attribute. - \return Value of the attribute, 0 if an attribute with this name does not exist. */ - virtual const char_type* getAttributeValue(const char_type* name) const = 0; - - //! Returns the value of an attribute in a safe way. - /** Like getAttributeValue(), but does not - return 0 if the attribute does not exist. An empty string ("") is returned then. - \param name: Name of the attribute. - \return Value of the attribute, and "" if an attribute with this name does not exist */ - virtual const char_type* getAttributeValueSafe(const char_type* name) const = 0; - - //! Returns the value of an attribute as integer. - /** \param name Name of the attribute. - \param defaultNotFound Value returned when name does not exist - \return Value of the attribute as integer or value of defaultNotFound - when name was not found or 0 when value could not be interpreted as integer */ - virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound=0) const = 0; - - //! Returns the value of an attribute as integer. - /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1. - \param defaultNotFound Value returned when index does not exist. - \return Value of the attribute as integer or value of defaultNotFound parameter for invalid index - or 0 when value could not be interpreted as integer */ - virtual int getAttributeValueAsInt(int idx, int defaultNotFound=0) const = 0; - - //! Returns the value of an attribute as float. - /** \param name: Name of the attribute. - \param defaultNotFound Value returned when name does not exist. - \return Value of the attribute as float or value of defaultNotFound parameter on failure - or 0 when value could not be interpreted as float. */ - virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound=0.f) const = 0; - - //! Returns the value of an attribute as float. - /** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1. - \param defaultNotFound Value returned when index does not exist. - \return Value of the attribute as float or value of defaultNotFound parameter on failure - or 0 when value could not be interpreted as float. */ - virtual float getAttributeValueAsFloat(int idx, float defaultNotFound=0.f) const = 0; - - //! Returns the name of the current node. - /** Only valid, if the node type is EXN_ELEMENT. - \return Name of the current node or 0 if the node has no name. */ - virtual const char_type* getNodeName() const = 0; - - //! Returns data of the current node. - /** Only valid if the node has some - data and it is of type EXN_TEXT, EXN_COMMENT, EXN_CDATA or EXN_UNKNOWN. */ - virtual const char_type* getNodeData() const = 0; - - //! Returns if an element is an empty element, like <foo /> - virtual bool isEmptyElement() const = 0; - - //! Returns format of the source xml file. - /** It is not necessary to use - this method because the parser will convert the input file format - to the format wanted by the user when creating the parser. This - method is useful to get/display additional information. */ - virtual ETEXT_FORMAT getSourceFormat() const = 0; - - //! Returns format of the strings returned by the parser. - /** This will be UTF8 for example when you created a parser with - IrrXMLReaderUTF8() and UTF32 when it has been created using - IrrXMLReaderUTF32. It should not be necessary to call this - method and only exists for informational purposes. */ - virtual ETEXT_FORMAT getParserFormat() const = 0; - }; - - //! Interface providing methods for making it easier to write XML files. - template - class IIrrXMLWriter : public super_class - { - public: - - //! Destructor - virtual ~IIrrXMLWriter() {} - - //! Writes an xml 1.0 header. - /** Looks like <?xml version="1.0"?>. This should always - be called before writing anything other, because also the text - file header for Unicode texts is written out with this method. */ - virtual void writeXMLHeader() = 0; - - //! Writes an xml element with maximal 5 attributes like "" or - //! <foo optAttr="value" />. - /** The element can be empty or not. - \param name: Name of the element - \param empty: Specifies if the element should be empty. Like - "". If You set this to false, something like this is - written instead: "". - \param attr1Name: 1st attributes name - \param attr1Value: 1st attributes value - \param attr2Name: 2nd attributes name - \param attr2Value: 2nd attributes value - \param attr3Name: 3rd attributes name - \param attr3Value: 3rd attributes value - \param attr4Name: 4th attributes name - \param attr4Value: 4th attributes value - \param attr5Name: 5th attributes name - \param attr5Value: 5th attributes value */ - virtual void writeElement(const char_type* name, bool empty=false, - const char_type* attr1Name = 0, const char_type* attr1Value = 0, - const char_type* attr2Name = 0, const char_type* attr2Value = 0, - const char_type* attr3Name = 0, const char_type* attr3Value = 0, - const char_type* attr4Name = 0, const char_type* attr4Value = 0, - const char_type* attr5Name = 0, const char_type* attr5Value = 0) = 0; - - //! Writes an xml element with any number of attributes - virtual void writeElement(const char_type* name, bool empty, - core::array > &names, core::array > &values) = 0; - - //! Writes a comment into the xml file - virtual void writeComment(const char_type* comment) = 0; - - //! Writes the closing tag for an element. Like "" - virtual void writeClosingTag(const char_type* name) = 0; - - //! Writes a text into the file. - /** All occurrences of special characters such as - & (&), < (<), > (>), and " (") are automatically - replaced. */ - virtual void writeText(const char_type* text) = 0; - - //! Writes a line break - virtual void writeLineBreak() = 0; - }; - - - template - struct xmlChar - { - T c; - xmlChar() {} - xmlChar(char in) : c(static_cast(in)) {} - xmlChar(wchar_t in) : c(static_cast(in)) {} -#if defined(__BORLANDC__) - // Note - removing explicit for Borland was to get it to even compile. - // There haven't been any kind of tests for that besides that. - xmlChar(unsigned char in) : c(static_cast(in)) {} - xmlChar(unsigned short in) : c(static_cast(in)) {} - xmlChar(unsigned int in) : c(static_cast(in)) {} - xmlChar(unsigned long in) : c(static_cast(in)) {} -#else - explicit xmlChar(unsigned char in) : c(static_cast(in)) {} - -#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) // VS compiling without native wchar_t can't have it - explicit xmlChar(unsigned short in) : c(static_cast(in)) {} -#endif - explicit xmlChar(unsigned int in) : c(static_cast(in)) {} - explicit xmlChar(unsigned long in) : c(static_cast(in)) {} -#endif - operator T() const { return c; } - void operator=(int t) { c=static_cast(t); } - }; - - //! defines the utf-16 type. - /** Not using wchar_t for this because - wchar_t has 16 bit on windows and 32 bit on other operating systems. */ - typedef xmlChar char16; - - //! defines the utf-32 type. - /** Not using wchar_t for this because - wchar_t has 16 bit on windows and 32 bit on other operating systems. */ - typedef xmlChar char32; - - //! A UTF-8 or ASCII character xml parser. - /** This means that all character data will be returned in 8 bit ASCII or UTF-8 by this parser. - The file to read can be in any format, it will be converted to UTF-8 if it is not - in this format. - Create an instance of this with createIrrXMLReader(); - See IIrrXMLReader for description on how to use it. */ - typedef IIrrXMLReader IrrXMLReader; - - //! A UTF-16 xml parser. - /** This means that all character data will be returned in UTF-16 by this parser. - The file to read can be in any format, it will be converted to UTF-16 if it is not - in this format. - Create an instance of this with createIrrXMLReaderUTF16(); - See IIrrXMLReader for description on how to use it. */ - typedef IIrrXMLReader IrrXMLReaderUTF16; - - //! A UTF-32 xml parser. - /** This means that all character data will be returned in UTF-32 by this parser. - The file to read can be in any format, it will be converted to UTF-32 if it is not - in this format. - Create an instance of this with createIrrXMLReaderUTF32(); - See IIrrXMLReader for description on how to use it. */ - typedef IIrrXMLReader IrrXMLReaderUTF32; - -#ifdef _IRR_COMPILE_WITH_XML_ - - //! Creates an instance of an UFT-8 or ASCII character xml parser. - /** This means that all character data will be returned in 8 bit ASCII or UTF-8. - The file to read can be in any format, it will be converted to UTF-8 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReaderUTF8() instead. - \param filename: Name of file to be opened. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename); - - //! Creates an instance of an UFT-8 or ASCII character xml parser. - /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can - be in any format, it will be converted to UTF-8 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReaderUTF8() instead. - \param file: Pointer to opened file, must have been opened in binary mode, e.g. - using fopen("foo.bar", "wb"); The file will not be closed after it has been read. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file); - - //! Creates an instance of an UFT-8 or ASCII character xml parser. - /** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can - be in any format, it will be converted to UTF-8 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReaderUTF8() instead. - \param callback: Callback for file read abstraction. Implement your own - callback to make the xml parser read in other things than just files. See - IFileReadCallBack for more information about this. - \param deleteCallback: if true, the callback will be deleted after the file - has been read. Otherwise the caller is responsible for cleaning it up. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback, - bool deleteCallback = false); - - //! Creates an instance of an UFT-16 xml parser. - /** This means that - all character data will be returned in UTF-16. The file to read can - be in any format, it will be converted to UTF-16 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReader() instead. - \param filename: Name of file to be opened. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename); - - //! Creates an instance of an UFT-16 xml parser. - /** This means that all character data will be returned in UTF-16. The file to read can - be in any format, it will be converted to UTF-16 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReader() instead. - \param file: Pointer to opened file, must have been opened in binary mode, e.g. - using fopen("foo.bar", "wb"); The file will not be closed after it has been read. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file); - - //! Creates an instance of an UFT-16 xml parser. - /** This means that all character data will be returned in UTF-16. The file to read can - be in any format, it will be converted to UTF-16 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReader() instead. - \param callback: Callback for file read abstraction. Implement your own - callback to make the xml parser read in other things than just files. See - IFileReadCallBack for more information about this. - \param deleteCallback: if true, the callback will be deleted after the file - has been read. Otherwise the caller is responsible for cleaning it up. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback, - bool deleteCallback = false); - - - //! Creates an instance of an UFT-32 xml parser. - /** This means that all character data will be returned in UTF-32. The file to read can - be in any format, it will be converted to UTF-32 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReader() instead. - \param filename: Name of file to be opened. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename); - - //! Creates an instance of an UFT-32 xml parser. - /** This means that all character data will be returned in UTF-32. The file to read can - be in any format, it will be converted to UTF-32 if it is not in this format. - if you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReader() instead. - \param file: Pointer to opened file, must have been opened in binary mode, e.g. - using fopen("foo.bar", "wb"); The file will not be closed after it has been read. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file); - - //! Creates an instance of an UFT-32 xml parser. - /** This means that - all character data will be returned in UTF-32. The file to read can - be in any format, it will be converted to UTF-32 if it is not in this format. - If you are using the Irrlicht Engine, it is better not to use this function but - IFileSystem::createXMLReader() instead. - \param callback: Callback for file read abstraction. Implement your own - callback to make the xml parser read in other things than just files. See - IFileReadCallBack for more information about this. - \param deleteCallback: if true, the callback will be deleted after the file - has been read. Otherwise the caller is responsible for cleaning it up. - \return Returns a pointer to the created xml parser. This pointer should be - deleted using 'delete' after no longer needed. Returns 0 if an error occurred - and the file could not be opened. */ - IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(IFileReadCallBack* callback, - bool deleteCallback = false); - -#endif // _IRR_COMPILE_WITH_XML_ - - /*! \file irrXML.h - \brief Header file of the irrXML, the Irrlicht XML parser. - - This file includes everything needed for using irrXML, - the XML parser of the Irrlicht Engine. To use irrXML, - you only need to include this file in your project: - - \code - #include - \endcode - - It is also common to use the two namespaces in which irrXML is included, - directly after including irrXML.h: - - \code - #include - using namespace irr; - using namespace io; - \endcode - */ - -} // end namespace io -} // end namespace irr - -#endif // __IRR_XML_H_INCLUDED__ - diff --git a/include/irrlicht.h b/include/irrlicht.h index ec62348..62ded3c 100644 --- a/include/irrlicht.h +++ b/include/irrlicht.h @@ -116,7 +116,6 @@ #include "IMeshSceneNode.h" #include "IMeshWriter.h" #include "IOctreeSceneNode.h" -#include "IColladaMeshWriter.h" #include "IMetaTriangleSelector.h" #include "IOSOperator.h" #include "IParticleSystemSceneNode.h" // also includes all emitters and attractors @@ -134,7 +133,6 @@ #include "irrString.h" #include "irrTypes.h" #include "path.h" -#include "irrXML.h" #include "ISceneCollisionManager.h" #include "ISceneLoader.h" #include "ISceneManager.h" @@ -159,8 +157,6 @@ #include "IVideoModeList.h" #include "IVolumeLightSceneNode.h" #include "IWriteFile.h" -#include "IXMLReader.h" -#include "IXMLWriter.h" #include "ILightManager.h" #include "Keycodes.h" #include "line2d.h" @@ -375,7 +371,7 @@ namespace irr { } - //! This namespace provides interfaces for input/output: Reading and writing files, accessing zip archives, xml files, ... + //! This namespace provides interfaces for input/output: Reading and writing files, accessing zip archives, ... namespace io { } diff --git a/source/Irrlicht/CAttributes.cpp b/source/Irrlicht/CAttributes.cpp index 7b1f06e..e044b6d 100644 --- a/source/Irrlicht/CAttributes.cpp +++ b/source/Irrlicht/CAttributes.cpp @@ -5,13 +5,8 @@ #include "CAttributes.h" #include "CAttributeImpl.h" #include "ITexture.h" -#include "IXMLWriter.h" #include "IVideoDriver.h" -#ifndef _IRR_COMPILE_WITH_XML_ - #include "CXMLReader.h" // for noXML -#endif - namespace irr { namespace io @@ -1381,278 +1376,6 @@ void CAttributes::setAttribute(s32 index, void* userPointer) } -//! Reads attributes from a xml file. -//! \param readCurrentElementOnly: If set to true, reading only works if current element has the name 'attributes'. -//! IF set to false, the first appearing list attributes are read. -bool CAttributes::read(io::IXMLReader* reader, bool readCurrentElementOnly, - const wchar_t* nonDefaultElementName) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - if (!reader) - return false; - - clear(); - - core::stringw elementName = L"attributes"; - if (nonDefaultElementName) - elementName = nonDefaultElementName; - - if (readCurrentElementOnly) - { - if (elementName != reader->getNodeName()) - return false; - } - - while(reader->read()) - { - switch(reader->getNodeType()) - { - case io::EXN_ELEMENT: - readAttributeFromXML(reader); - break; - case io::EXN_ELEMENT_END: - if (elementName == reader->getNodeName()) - return true; - break; - default: - break; - } - } - - return true; -#else - noXML(); - return false; -#endif -} - - -void CAttributes::readAttributeFromXML(const io::IXMLReader* reader) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - core::stringw element = reader->getNodeName(); - core::stringc name = reader->getAttributeValue(L"name"); - - if (element == L"enum") - { - addEnum(name.c_str(), 0, 0); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"binary") - { - addBinary(name.c_str(), 0, 0); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"color") - { - addColor(name.c_str(), video::SColor()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"colorf") - { - addColorf(name.c_str(), video::SColorf()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"float") - { - addFloat(name.c_str(), 0); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"int") - { - addInt(name.c_str(), 0); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"bool") - { - addBool(name.c_str(), 0); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"string") - { - addString(name.c_str(), L""); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"texture") - { - addTexture(name.c_str(), 0); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"vector3d") - { - addVector3d(name.c_str(), core::vector3df()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"vector2d") - { - addVector2d(name.c_str(), core::vector2df()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"position") - { - addPosition2d(name.c_str(), core::position2di()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"rect") - { - addRect(name.c_str(), core::rect()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"matrix") - { - addMatrix(name.c_str(), core::matrix4()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"quaternion") - { - addQuaternion(name.c_str(), core::quaternion()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"box3d") - { - addBox3d(name.c_str(), core::aabbox3df()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"plane") - { - addPlane3d(name.c_str(), core::plane3df()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"triangle") - { - addTriangle3d(name.c_str(), core::triangle3df()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"line2d") - { - addLine2d(name.c_str(), core::line2df()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"line3d") - { - addLine3d(name.c_str(), core::line3df()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } - else - if (element == L"stringwarray") - { - core::array tmpArray; - - const s32 count = reader->getAttributeValueAsInt(L"count"); - s32 n=0; - const core::stringw tmpName(L"value"); - for (; ngetAttributeValue((tmpName+core::stringw(n)).c_str())); - } - addArray(name.c_str(),tmpArray); - } - else - if (element == L"userPointer") - { - // It's debatable if a pointer should be set or not, but it's more likely that adding it now would wreck user-applications. - // Also it probably doesn't makes sense setting this to a value when it comes from file. - } - else - if (element == L"dimension2d") - { - addDimension2d(name.c_str(), core::dimension2d()); - Attributes.getLast()->setString(reader->getAttributeValue(L"value")); - } -#else - noXML(); -#endif -} - -//! Write these attributes into a xml file -bool CAttributes::write(io::IXMLWriter* writer, bool writeXMLHeader, - const wchar_t* nonDefaultElementName) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - if (!writer) - return false; - - if (writeXMLHeader) - writer->writeXMLHeader(); - - core::stringw elementName = L"attributes"; - if (nonDefaultElementName) - elementName = nonDefaultElementName; - - writer->writeElement(elementName.c_str(), false); - writer->writeLineBreak(); - - s32 i=0; - for (; i<(s32)Attributes.size(); ++i) - { - if ( Attributes[i]->getType() == EAT_STRINGWARRAY ) - { - core::array arraynames, arrayvalues; - core::array arrayinput = Attributes[i]->getArray(); - - // build arrays - - // name - arraynames.push_back(core::stringw(L"name")); - arrayvalues.push_back(core::stringw(Attributes[i]->Name.c_str()) ); - - // count - arraynames.push_back(core::stringw(L"count")); - arrayvalues.push_back(core::stringw((s32)arrayinput.size())); - - // array... - u32 n=0; - const core::stringw tmpName(L"value"); - for (; n < arrayinput.size(); ++n) - { - arraynames.push_back((tmpName+core::stringw(n)).c_str()); - arrayvalues.push_back(arrayinput[n]); - } - - // write them - writer->writeElement( Attributes[i]->getTypeString(), true, arraynames, arrayvalues); - } - else - { - writer->writeElement( - Attributes[i]->getTypeString(), true, - L"name", core::stringw(Attributes[i]->Name.c_str()).c_str(), - L"value", Attributes[i]->getStringW().c_str() ); - } - - writer->writeLineBreak(); - } - - writer->writeClosingTag(elementName.c_str()); - writer->writeLineBreak(); - - return true; -#else - noXML(); - return false; -#endif -} - - } // end namespace io } // end namespace irr diff --git a/source/Irrlicht/CAttributes.h b/source/Irrlicht/CAttributes.h index 466e904..169fe95 100644 --- a/source/Irrlicht/CAttributes.h +++ b/source/Irrlicht/CAttributes.h @@ -62,15 +62,6 @@ public: //! Removes all attributes virtual void clear() _IRR_OVERRIDE_; - //! Reads attributes from a xml file. - //! \param readCurrentElementOnly: If set to true, reading only works if current element has the name 'attributes'. - //! IF set to false, the first appearing list attributes are read. - virtual bool read(io::IXMLReader* reader, bool readCurrentElementOnly=false, - const wchar_t* nonDefaultElementName = 0) _IRR_OVERRIDE_; - - //! Write these attributes into a xml file - virtual bool write(io::IXMLWriter* writer, bool writeXMLHeader=false, const wchar_t* nonDefaultElementName=0) _IRR_OVERRIDE_; - /* @@ -722,8 +713,6 @@ public: protected: - void readAttributeFromXML(const io::IXMLReader* reader); - core::array Attributes; IAttribute* getAttributeP(const c8* attributeName) const; diff --git a/source/Irrlicht/CColladaFileLoader.cpp b/source/Irrlicht/CColladaFileLoader.cpp deleted file mode 100644 index 7645254..0000000 --- a/source/Irrlicht/CColladaFileLoader.cpp +++ /dev/null @@ -1,3008 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_COLLADA_LOADER_ - -#include "CColladaFileLoader.h" -#include "CMeshTextureLoader.h" -#include "os.h" -#include "IXMLReader.h" -#include "IDummyTransformationSceneNode.h" -#include "SAnimatedMesh.h" -#include "fast_atof.h" -#include "quaternion.h" -#include "ILightSceneNode.h" -#include "ICameraSceneNode.h" -#include "IMeshManipulator.h" -#include "IReadFile.h" -#include "IAttributes.h" -#include "IMeshCache.h" -#include "IMeshSceneNode.h" -#include "SMeshBufferLightMap.h" -#include "irrMap.h" - -#ifdef _DEBUG -#define COLLADA_READER_DEBUG -#endif -namespace irr -{ -namespace scene -{ -namespace -{ - // currently supported COLLADA tag names - const core::stringc colladaSectionName = "COLLADA"; - const core::stringc librarySectionName = "library"; - const core::stringc libraryNodesSectionName = "library_nodes"; - const core::stringc libraryGeometriesSectionName = "library_geometries"; - const core::stringc libraryMaterialsSectionName = "library_materials"; - const core::stringc libraryImagesSectionName = "library_images"; - const core::stringc libraryVisualScenesSectionName = "library_visual_scenes"; - const core::stringc libraryCamerasSectionName = "library_cameras"; - const core::stringc libraryLightsSectionName = "library_lights"; - const core::stringc libraryEffectsSectionName = "library_effects"; - const core::stringc assetSectionName = "asset"; - const core::stringc sceneSectionName = "scene"; - const core::stringc visualSceneSectionName = "visual_scene"; - - const core::stringc lightPrefabName = "light"; - const core::stringc cameraPrefabName = "camera"; - const core::stringc materialSectionName = "material"; - const core::stringc geometrySectionName = "geometry"; - const core::stringc imageSectionName = "image"; - const core::stringc textureSectionName = "texture"; - const core::stringc effectSectionName = "effect"; - - const core::stringc pointSectionName = "point"; - const core::stringc directionalSectionName ="directional"; - const core::stringc spotSectionName = "spot"; - const core::stringc ambientSectionName = "ambient"; - const core::stringc meshSectionName = "mesh"; - const core::stringc sourceSectionName = "source"; - const core::stringc arraySectionName = "array"; - const core::stringc floatArraySectionName ="float_array"; - const core::stringc intArraySectionName = "int_array"; - const core::stringc techniqueCommonSectionName = "technique_common"; - const core::stringc accessorSectionName = "accessor"; - const core::stringc verticesSectionName = "vertices"; - const core::stringc inputTagName = "input"; - const core::stringc polylistSectionName = "polylist"; - const core::stringc trianglesSectionName = "triangles"; - const core::stringc polygonsSectionName = "polygons"; - const core::stringc primitivesName = "p"; - const core::stringc vcountName = "vcount"; - - const core::stringc upAxisNodeName = "up_axis"; - const core::stringc nodeSectionName = "node"; - const core::stringc lookatNodeName = "lookat"; - const core::stringc matrixNodeName = "matrix"; - const core::stringc perspectiveNodeName = "perspective"; - const core::stringc rotateNodeName = "rotate"; - const core::stringc scaleNodeName = "scale"; - const core::stringc translateNodeName = "translate"; - const core::stringc skewNodeName = "skew"; - const core::stringc minNodeName = "min"; - const core::stringc maxNodeName = "max"; - const core::stringc instanceName = "instance"; - const core::stringc instanceGeometryName = "instance_geometry"; - const core::stringc instanceSceneName = "instance_visual_scene"; - const core::stringc instanceEffectName = "instance_effect"; - const core::stringc instanceMaterialName = "instance_material"; - const core::stringc instanceLightName = "instance_light"; - const core::stringc instanceNodeName = "instance_node"; - const core::stringc instanceCameraName = "instance_camera"; - const core::stringc bindMaterialName = "bind_material"; - const core::stringc extraNodeName = "extra"; - const core::stringc techniqueNodeName = "technique"; - const core::stringc colorNodeName = "color"; - const core::stringc floatNodeName = "float"; - const core::stringc float2NodeName = "float2"; - const core::stringc float3NodeName = "float3"; - - const core::stringc newParamName = "newparam"; - const core::stringc paramTagName = "param"; - const core::stringc initFromName = "init_from"; - const core::stringc dataName = "data"; - const core::stringc wrapsName = "wrap_s"; - const core::stringc wraptName = "wrap_t"; - const core::stringc wraprName = "wrap_r"; // for downward compatibility to bug in old Irrlicht collada writer. Not standard but we wrote that accidentally up to Irrlicht 1.8, so we should still be able to load those files - const core::stringc wrappName = "wrap_p"; - const core::stringc minfilterName = "minfilter"; - const core::stringc magfilterName = "magfilter"; - const core::stringc mipfilterName = "mipfilter"; - - const core::stringc textureNodeName = "texture"; - const core::stringc doubleSidedNodeName = "double_sided"; - const core::stringc constantAttenuationNodeName = "constant_attenuation"; - const core::stringc linearAttenuationNodeName = "linear_attenuation"; - const core::stringc quadraticAttenuationNodeName = "quadratic_attenuation"; - const core::stringc falloffAngleNodeName = "falloff_angle"; - const core::stringc falloffExponentNodeName = "falloff_exponent"; - - const core::stringc profileCOMMONSectionName = "profile_COMMON"; - const core::stringc profileCOMMONAttributeName = "COMMON"; - - const char* const inputSemanticNames[] = {"POSITION", "VERTEX", "NORMAL", "TEXCOORD", - "UV", "TANGENT", "IMAGE", "TEXTURE", "COLOR", 0}; - - // We have to read ambient lights like other light types here, so we need a type for it - const video::E_LIGHT_TYPE ELT_AMBIENT = video::E_LIGHT_TYPE(video::ELT_COUNT+1); -} - - //! following class is for holding and creating instances of library - //! objects, named prefabs in this loader. - class CPrefab : public IColladaPrefab - { - public: - - CPrefab(const core::stringc& id) : Id(id) - { - } - - //! creates an instance of this prefab - virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent, - scene::ISceneManager* mgr) _IRR_OVERRIDE_ - { - // empty implementation - return 0; - } - - //! returns id of this prefab - virtual const core::stringc& getId() _IRR_OVERRIDE_ - { - return Id; - } - - protected: - - core::stringc Id; - }; - - - //! prefab for a light scene node - class CLightPrefab : public CPrefab - { - public: - - CLightPrefab(const core::stringc& id) : CPrefab(id) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: loaded light prefab", Id.c_str(), ELL_DEBUG); - #endif - } - - video::SLight LightData; // publically accessible - - //! creates an instance of this prefab - virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent, - scene::ISceneManager* mgr) _IRR_OVERRIDE_ - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: Constructing light instance", Id.c_str(), ELL_DEBUG); - #endif - - if ( LightData.Type == ELT_AMBIENT ) - { - mgr->setAmbientLight( LightData.DiffuseColor ); - return 0; - } - - scene::ILightSceneNode* l = mgr->addLightSceneNode(parent); - if (l) - { - l->setLightData ( LightData ); - l->setName(getId()); - } - return l; - } - }; - - - //! prefab for a mesh scene node - class CGeometryPrefab : public CPrefab - { - public: - - CGeometryPrefab(const core::stringc& id) : CPrefab(id) - { - } - - scene::IMesh* Mesh; - - //! creates an instance of this prefab - virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent, - scene::ISceneManager* mgr) _IRR_OVERRIDE_ - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: Constructing mesh instance", Id.c_str(), ELL_DEBUG); - #endif - - scene::ISceneNode* m = mgr->addMeshSceneNode(Mesh, parent); - if (m) - { - m->setName(getId()); -// m->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false); -// m->setDebugDataVisible(scene::EDS_FULL); - } - return m; - } - }; - - - //! prefab for a camera scene node - class CCameraPrefab : public CPrefab - { - public: - - CCameraPrefab(const core::stringc& id) - : CPrefab(id), YFov(core::PI / 2.5f), ZNear(1.0f), ZFar(3000.0f) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: loaded camera prefab", Id.c_str(), ELL_DEBUG); - #endif - } - - // publicly accessible data - f32 YFov; - f32 ZNear; - f32 ZFar; - - //! creates an instance of this prefab - virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent, - scene::ISceneManager* mgr) _IRR_OVERRIDE_ - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: Constructing camera instance", Id.c_str(), ELL_DEBUG); - #endif - - scene::ICameraSceneNode* c = mgr->addCameraSceneNode(parent, core::vector3df(0,0,0), core::vector3df(0,0,100), -1, false); - if (c) - { - c->setFOV(YFov); - c->setNearValue(ZNear); - c->setFarValue(ZFar); - c->setName(getId()); - } - return c; - } - }; - - - //! prefab for a container scene node - //! Collects other prefabs and instantiates them upon instantiation - //! Uses a dummy scene node to return the children as one scene node - class CScenePrefab : public CPrefab - { - public: - CScenePrefab(const core::stringc& id) : CPrefab(id) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: loaded scene prefab", Id.c_str(), ELL_DEBUG); - #endif - } - - //! creates an instance of this prefab - virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent, - scene::ISceneManager* mgr) _IRR_OVERRIDE_ - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: Constructing scene instance", Id.c_str(), ELL_DEBUG); - #endif - - if (Children.size()==0) - return 0; - - scene::IDummyTransformationSceneNode* s = mgr->addDummyTransformationSceneNode(parent); - if (s) - { - s->setName(getId()); - s->getRelativeTransformationMatrix() = Transformation; - s->updateAbsolutePosition(); - core::stringc t; - for (u32 i=0; i<16; ++i) - { - t+=core::stringc((double)Transformation[i]); - t+=" "; - } - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA: Transformation", t.c_str(), ELL_DEBUG); - #endif - - for (u32 i=0; iaddInstance(s, mgr); - } - - return s; - } - - core::array Children; - core::matrix4 Transformation; - }; - - -//! Constructor -CColladaFileLoader::CColladaFileLoader(scene::ISceneManager* smgr, - io::IFileSystem* fs) -: SceneManager(smgr), FileSystem(fs), DummyMesh(0), - FirstLoadedMesh(0), LoadedMeshCount(0), CreateInstances(false) -{ - #ifdef _DEBUG - setDebugName("CColladaFileLoader"); - #endif - - // Escape characters, see https://www.w3schools.com/tags/ref_urlencode.asp - // TODO: There should be more, but usually people just escape the space character anyway. - // And I'm not sure if our xml files are utf-8 or windows-1252, so let's avoid the ambiguous ones. - EscapeCharsAnyURI.push_back(EscapeCharacterURL(' ', "%20")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('"', "%22")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('#', "%23")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('$', "%24")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('%', "%25")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('&', "%26")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('\'', "%27")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('(', "%28")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL(')', "%29")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('/', "%2F")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('\\', "%5C")); - - - TextureLoader = new CMeshTextureLoader( FileSystem, SceneManager->getVideoDriver() ); -} - - -//! destructor -CColladaFileLoader::~CColladaFileLoader() -{ - if (DummyMesh) - DummyMesh->drop(); - - if (FirstLoadedMesh) - FirstLoadedMesh->drop(); -} - - -//! Returns true if the file maybe is able to be loaded by this class. -/** This decision should be based only on the file extension (e.g. ".cob") */ -bool CColladaFileLoader::isALoadableFileExtension(const io::path& filename) const -{ - return core::hasFileExtension ( filename, "xml", "dae" ); -} - - -//! creates/loads an animated mesh from the file. -//! \return Pointer to the created mesh. Returns 0 if loading failed. -//! If you no longer need the mesh, you should call IAnimatedMesh::drop(). -//! See IReferenceCounted::drop() for more information. -IAnimatedMesh* CColladaFileLoader::createMesh(io::IReadFile* file) -{ - io::IXMLReaderUTF8* reader = FileSystem->createXMLReaderUTF8(file); - if (!reader) - return 0; - - if ( getMeshTextureLoader() ) - getMeshTextureLoader()->setMeshFile(file); - - CurrentlyLoadingMesh = file->getFileName(); - CreateInstances = SceneManager->getParameters()->getAttributeAsBool( - scene::COLLADA_CREATE_SCENE_INSTANCES); - Version = 0; - FlipAxis = false; - - // read until COLLADA section, skip other parts - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (colladaSectionName == reader->getNodeName()) - readColladaSection(reader); - else - skipSection(reader, true); // unknown section - } - } - - reader->drop(); - if (!Version) - return 0; - - // because this loader loads and creates a complete scene instead of - // a single mesh, return an empty dummy mesh to make the scene manager - // know that everything went well. - if (!DummyMesh) - DummyMesh = new SAnimatedMesh(); - scene::IAnimatedMesh* returnMesh = DummyMesh; - - if (Version < 10400) - instantiateNode(SceneManager->getRootSceneNode()); - - // add the first loaded mesh into the mesh cache too, if more than one - // meshes have been loaded from the file - if (LoadedMeshCount>1 && FirstLoadedMesh) - { - os::Printer::log("Added COLLADA mesh", FirstLoadedMeshName.c_str()); - SceneManager->getMeshCache()->addMesh(FirstLoadedMeshName.c_str(), FirstLoadedMesh); - } - - // clean up temporary loaded data - clearData(); - - returnMesh->grab(); // store until this loader is destroyed - - DummyMesh->drop(); - DummyMesh = 0; - - if (FirstLoadedMesh) - FirstLoadedMesh->drop(); - FirstLoadedMesh = 0; - LoadedMeshCount = 0; - - return returnMesh; -} - - -//! skips an (unknown) section in the collada document -void CColladaFileLoader::skipSection(io::IXMLReaderUTF8* reader, bool reportSkipping) -{ - #ifndef COLLADA_READER_DEBUG - if (reportSkipping) // always report in COLLADA_READER_DEBUG mode - #endif - os::Printer::log("COLLADA skipping section", core::stringc(reader->getNodeName()).c_str(), ELL_DEBUG); - - // skip if this element is empty anyway. - if (reader->isEmptyElement()) - return; - - // read until we've reached the last element in this section - u32 tagCounter = 1; - - while(tagCounter && reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT && - !reader->isEmptyElement()) - { - #ifdef COLLADA_READER_DEBUG - if (reportSkipping) - os::Printer::log("Skipping COLLADA unknown element", core::stringc(reader->getNodeName()).c_str(), ELL_DEBUG); - #endif - - ++tagCounter; - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - --tagCounter; - } -} - - -//! reads the section and its content -void CColladaFileLoader::readColladaSection(io::IXMLReaderUTF8* reader) -{ - if (reader->isEmptyElement()) - return; - - // todo: patch level needs to be handled - const f32 version = core::fast_atof(core::stringc(reader->getAttributeValue("version")).c_str()); - Version = core::floor32(version)*10000+core::round32(core::fract(version)*1000.0f); - // Version 1.4 can be checked for by if (Version >= 10400) - - while(reader->read()) - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (assetSectionName == reader->getNodeName()) - readAssetSection(reader); - else - if (librarySectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryNodesSectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryGeometriesSectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryMaterialsSectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryEffectsSectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryImagesSectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryCamerasSectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryLightsSectionName == reader->getNodeName()) - readLibrarySection(reader); - else - if (libraryVisualScenesSectionName == reader->getNodeName()) - readVisualScene(reader); - else - if (assetSectionName == reader->getNodeName()) - readAssetSection(reader); - else - if (sceneSectionName == reader->getNodeName()) - readSceneSection(reader); - else - { - os::Printer::log("COLLADA loader warning: Wrong tag usage found", reader->getNodeName(), ELL_WARNING); - skipSection(reader, true); // unknown section - } - } -} - - -//! reads a section and its content -void CColladaFileLoader::readLibrarySection(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading library", ELL_DEBUG); - #endif - - if (reader->isEmptyElement()) - return; - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - // animation section tbd - if (cameraPrefabName == reader->getNodeName()) - readCameraPrefab(reader); - else - // code section tbd - // controller section tbd - if (geometrySectionName == reader->getNodeName()) - readGeometry(reader); - else - if (imageSectionName == reader->getNodeName()) - readImage(reader); - else - if (lightPrefabName == reader->getNodeName()) - readLightPrefab(reader); - else - if (materialSectionName == reader->getNodeName()) - readMaterial(reader); - else - if (nodeSectionName == reader->getNodeName()) - { - CScenePrefab p(""); - - readNodeSection(reader, SceneManager->getRootSceneNode(), &p); - } - else - if (effectSectionName == reader->getNodeName()) - readEffect(reader); - else - // program section tbd - if (textureSectionName == reader->getNodeName()) - readTexture(reader); - else - skipSection(reader, true); // unknown section, not all allowed supported yet - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (librarySectionName == reader->getNodeName()) - break; // end reading. - if (libraryNodesSectionName == reader->getNodeName()) - break; // end reading. - if (libraryGeometriesSectionName == reader->getNodeName()) - break; // end reading. - if (libraryMaterialsSectionName == reader->getNodeName()) - break; // end reading. - if (libraryEffectsSectionName == reader->getNodeName()) - break; // end reading. - if (libraryImagesSectionName == reader->getNodeName()) - break; // end reading. - if (libraryLightsSectionName == reader->getNodeName()) - break; // end reading. - if (libraryCamerasSectionName == reader->getNodeName()) - break; // end reading. - } - } -} - - -//! reads a element and stores it as a prefab -void CColladaFileLoader::readVisualScene(io::IXMLReaderUTF8* reader) -{ - CScenePrefab* p = 0; - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (visualSceneSectionName == reader->getNodeName()) - p = new CScenePrefab(readId(reader)); - else - if (p && nodeSectionName == reader->getNodeName()) // as a child of visual_scene - readNodeSection(reader, SceneManager->getRootSceneNode(), p); - else - if (assetSectionName == reader->getNodeName()) - readAssetSection(reader); - else - if (extraNodeName == reader->getNodeName()) - skipSection(reader, false); // ignore all other sections - else - { - os::Printer::log("COLLADA loader warning: Wrong tag usage found", reader->getNodeName(), ELL_WARNING); - skipSection(reader, true); // ignore all other sections - } - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (libraryVisualScenesSectionName == reader->getNodeName()) - return; - else - if ((visualSceneSectionName == reader->getNodeName()) && p) - { - Prefabs.push_back(p); - p = 0; - } - } - } -} - - -//! reads a section and its content -void CColladaFileLoader::readSceneSection(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading scene", ELL_DEBUG); - #endif - - if (reader->isEmptyElement()) - return; - - // read the scene - - core::matrix4 transform; // transformation of this node - scene::IDummyTransformationSceneNode* node = 0; - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (lookatNodeName == reader->getNodeName()) - transform *= readLookAtNode(reader); - else - if (matrixNodeName == reader->getNodeName()) - transform *= readMatrixNode(reader); - else - if (perspectiveNodeName == reader->getNodeName()) - transform *= readPerspectiveNode(reader); - else - if (rotateNodeName == reader->getNodeName()) - transform *= readRotateNode(reader); - else - if (scaleNodeName == reader->getNodeName()) - transform *= readScaleNode(reader); - else - if (skewNodeName == reader->getNodeName()) - transform *= readSkewNode(reader); - else - if (translateNodeName == reader->getNodeName()) - transform *= readTranslateNode(reader); - else - if (nodeSectionName == reader->getNodeName()) - { - // create dummy node if there is none yet. - if (!node) - node = SceneManager->addDummyTransformationSceneNode(SceneManager->getRootSceneNode()); - - readNodeSection(reader, node); - } - else - if ((instanceSceneName == reader->getNodeName())) - readInstanceNode(reader, SceneManager->getRootSceneNode(), 0, 0,instanceSceneName); - else - if (extraNodeName == reader->getNodeName()) - skipSection(reader, false); - else - { - os::Printer::log("COLLADA loader warning: Wrong tag usage found", reader->getNodeName(), ELL_WARNING); - skipSection(reader, true); // ignore all other sections - } - } - else - if ((reader->getNodeType() == io::EXN_ELEMENT_END) && - (sceneSectionName == reader->getNodeName())) - return; - } - if (node) - node->getRelativeTransformationMatrix() = transform; -} - - -//! reads a section and its content -void CColladaFileLoader::readAssetSection(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading asset", ELL_DEBUG); - #endif - - if (reader->isEmptyElement()) - return; - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (upAxisNodeName == reader->getNodeName()) - { - reader->read(); - FlipAxis = (core::stringc("Z_UP") == reader->getNodeData()); - } - } - else - if ((reader->getNodeType() == io::EXN_ELEMENT_END) && - (assetSectionName == reader->getNodeName())) - return; - } -} - - -//! reads a section and its content -void CColladaFileLoader::readNodeSection(io::IXMLReaderUTF8* reader, scene::ISceneNode* parent, CScenePrefab* p) -{ - if (reader->isEmptyElement()) - { - return; - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading empty node", ELL_DEBUG); - #endif - } - - core::stringc name = readId(reader); - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading node", name, ELL_DEBUG); - #endif - - core::matrix4 transform; // transformation of this node - scene::ISceneNode* node = 0; // instance - CScenePrefab* nodeprefab = 0; // prefab for library_nodes usage - - if (p) - { - nodeprefab = new CScenePrefab(readId(reader)); - p->Children.push_back(nodeprefab); - Prefabs.push_back(nodeprefab); // in order to delete them later on - } - - // read the node - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (assetSectionName == reader->getNodeName()) - readAssetSection(reader); - else - if (lookatNodeName == reader->getNodeName()) - transform *= readLookAtNode(reader); - else - if (matrixNodeName == reader->getNodeName()) - transform *= readMatrixNode(reader); - else - if (perspectiveNodeName == reader->getNodeName()) - transform *= readPerspectiveNode(reader); - else - if (rotateNodeName == reader->getNodeName()) - transform *= readRotateNode(reader); - else - if (scaleNodeName == reader->getNodeName()) - transform *= readScaleNode(reader); - else - if (skewNodeName == reader->getNodeName()) - transform *= readSkewNode(reader); - else - if (translateNodeName == reader->getNodeName()) - transform *= readTranslateNode(reader); - else - if ((instanceName == reader->getNodeName()) || - (instanceNodeName == reader->getNodeName()) || - (instanceGeometryName == reader->getNodeName()) || - (instanceLightName == reader->getNodeName()) || - (instanceCameraName == reader->getNodeName()) - ) - { - scene::ISceneNode* newnode = 0; - readInstanceNode(reader, parent, &newnode, nodeprefab, reader->getNodeName()); - - if (node && newnode) - { - // move children from dummy to new node - ISceneNodeList::ConstIterator it = node->getChildren().begin(); - for (; it != node->getChildren().end(); it = node->getChildren().begin()) - (*it)->setParent(newnode); - - // remove previous dummy node - node->remove(); - node = newnode; - } - } - else - if (nodeSectionName == reader->getNodeName()) - { - // create dummy node if there is none yet. - if (CreateInstances && !node) - { - scene::IDummyTransformationSceneNode* dummy = - SceneManager->addDummyTransformationSceneNode(parent); - dummy->getRelativeTransformationMatrix() = transform; - node = dummy; - } - else - node = parent; - - // read and add child - readNodeSection(reader, node, nodeprefab); - } - else - if (extraNodeName == reader->getNodeName()) - skipSection(reader, false); - else - skipSection(reader, true); // ignore all other sections - - } // end if node - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (nodeSectionName == reader->getNodeName()) - break; - } - } - - if (nodeprefab) - nodeprefab->Transformation = transform; - else - if (node) - { - // set transformation correctly into node. - node->setPosition(transform.getTranslation()); - node->setRotation(transform.getRotationDegrees()); - node->setScale(transform.getScale()); - node->updateAbsolutePosition(); - - node->setName(name); - } -} - - -//! reads a element and its content and creates a matrix from it -core::matrix4 CColladaFileLoader::readLookAtNode(io::IXMLReaderUTF8* reader) -{ - core::matrix4 mat; - if (reader->isEmptyElement()) - return mat; - - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading look at node", ELL_DEBUG); - #endif - - f32 floats[9]; - readFloatsInsideElement(reader, floats, 9); - - if (FlipAxis) - { - mat.buildCameraLookAtMatrixLH( - core::vector3df(floats[0], floats[2], floats[1]), - core::vector3df(floats[3], floats[5], floats[4]), - core::vector3df(floats[6], floats[8], floats[7])); - } - else - { - mat.buildCameraLookAtMatrixLH( - core::vector3df(floats[0], floats[1], floats[2]*-1.f), - core::vector3df(floats[3], floats[4], floats[5]*-1.f), - core::vector3df(floats[6], floats[7], floats[8]*-1.f)); - } - - return mat; -} - - -//! reads a element and its content and creates a matrix from it -core::matrix4 CColladaFileLoader::readSkewNode(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading skew node", ELL_DEBUG); - #endif - - core::matrix4 mat; - if (reader->isEmptyElement()) - return mat; - - f32 floats[7]; // angle rotation-axis translation-axis - readFloatsInsideElement(reader, floats, 7); - - // build skew matrix from these 7 floats - // TODO: missing example, not sure if rotation is in correct direction. - // TODO: shouldn't FlipAxis also be regarded here? - core::quaternion q; - q.fromAngleAxis(floats[0]*core::DEGTORAD, core::vector3df(floats[1], floats[2], floats[3])); - mat = q.getMatrix(); - - if (floats[4]==1.f) // along x-axis - { - mat[4]=0.f; - mat[6]=0.f; - mat[8]=0.f; - mat[9]=0.f; - } - else - if (floats[5]==1.f) // along y-axis - { - mat[1]=0.f; - mat[2]=0.f; - mat[8]=0.f; - mat[9]=0.f; - } - else - if (floats[6]==1.f) // along z-axis - { - mat[1]=0.f; - mat[2]=0.f; - mat[4]=0.f; - mat[6]=0.f; - } - - if ( FlipAxis ) - return mat; - else - return flipZAxis(mat); -} - -//! reads a element and its content and creates a matrix from it -core::matrix4 CColladaFileLoader::readMatrixNode(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading matrix node", ELL_DEBUG); - #endif - - core::matrix4 mat; - if (reader->isEmptyElement()) - return mat; - - readFloatsInsideElement(reader, mat.pointer(), 16); - - // put translation into the correct place - if (FlipAxis) - { - core::matrix4 mat2(mat, core::matrix4::EM4CONST_TRANSPOSED); - mat2[1]=mat[8]; - mat2[2]=mat[4]; - mat2[4]=mat[2]; - mat2[5]=mat[10]; - mat2[6]=mat[6]; - mat2[8]=mat[1]; - mat2[9]=mat[9]; - mat2[10]=mat[5]; - mat2[12]=mat[3]; - mat2[13]=mat[11]; - mat2[14]=mat[7]; - return mat2; - } - else - return flipZAxis(core::matrix4(mat, core::matrix4::EM4CONST_TRANSPOSED)); -} - - -//! reads a element and its content and creates a matrix from it -core::matrix4 CColladaFileLoader::readPerspectiveNode(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading perspective node", ELL_DEBUG); - #endif - - core::matrix4 mat; - if (reader->isEmptyElement()) - return mat; - - f32 floats[1]; - readFloatsInsideElement(reader, floats, 1); - - // TODO: build perspective matrix from this float - - os::Printer::log("COLLADA loader warning: not implemented yet.", ELL_WARNING); - - return mat; -} - - -//! reads a element and its content and creates a matrix from it -core::matrix4 CColladaFileLoader::readRotateNode(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading rotate node", ELL_DEBUG); - #endif - - core::matrix4 mat; - if (reader->isEmptyElement()) - return mat; - - f32 floats[4]; - readFloatsInsideElement(reader, floats, 4); - floats[3] *= -1.f; // to left handed rotation - - if (!core::iszero(floats[3])) - { - core::quaternion q; - if (FlipAxis) - q.fromAngleAxis(floats[3]*core::DEGTORAD, core::vector3df(floats[0], floats[2], floats[1])); - else - q.fromAngleAxis(floats[3]*core::DEGTORAD, core::vector3df(floats[0], floats[1], floats[2]*-1.f)); - return q.getMatrix(); - } - else - return core::IdentityMatrix; -} - - -//! reads a element and its content and creates a matrix from it -core::matrix4 CColladaFileLoader::readScaleNode(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading scale node", ELL_DEBUG); - #endif - - core::matrix4 mat; - if (reader->isEmptyElement()) - return mat; - - f32 floats[3]; - readFloatsInsideElement(reader, floats, 3); - - if (FlipAxis) - mat.setScale(core::vector3df(floats[0], floats[2], floats[1])); - else - mat.setScale(core::vector3df(floats[0], floats[1], floats[2])); - - return mat; -} - - -//! reads a element and its content and creates a matrix from it -core::matrix4 CColladaFileLoader::readTranslateNode(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading translate node", ELL_DEBUG); - #endif - - core::matrix4 mat; - if (reader->isEmptyElement()) - return mat; - - f32 floats[3]; - readFloatsInsideElement(reader, floats, 3); - - if (FlipAxis) - mat.setTranslation(core::vector3df(floats[0], floats[2], floats[1])); - else - mat.setTranslation(core::vector3df(floats[0], floats[1], floats[2]*-1.f)); - - return mat; -} - - -//! reads any kind of node -void CColladaFileLoader::readInstanceNode(io::IXMLReaderUTF8* reader, - scene::ISceneNode* parent, scene::ISceneNode** outNode, - CScenePrefab* p, const core::stringc& type) -{ - // find prefab of the specified id - core::stringc url = reader->getAttributeValue("url"); - uriToId(url); - - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading instance", url, ELL_DEBUG); - #endif - - if (!reader->isEmptyElement()) - { - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (bindMaterialName == reader->getNodeName()) - readBindMaterialSection(reader,url); - else - if (extraNodeName == reader->getNodeName()) - skipSection(reader, false); - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - break; - } - } - instantiateNode(parent, outNode, p, url, type); -} - - -void CColladaFileLoader::instantiateNode(scene::ISceneNode* parent, - scene::ISceneNode** outNode, CScenePrefab* p, const core::stringc& url, - const core::stringc& type) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA instantiate node", ELL_DEBUG); - #endif - - for (u32 i=0; igetId()) - { - if (p) - p->Children.push_back(Prefabs[i]); - else - if (CreateInstances) - { - scene::ISceneNode * newNode - = Prefabs[i]->addInstance(parent, SceneManager); - if (outNode) - { - *outNode = newNode; - if (*outNode) - (*outNode)->setName(url); - } - } - return; - } - } - if (p) - { - if (instanceGeometryName==type) - { - Prefabs.push_back(new CGeometryPrefab(url)); - p->Children.push_back(Prefabs.getLast()); - } - } -} - - -//! reads a element and stores it as prefab -void CColladaFileLoader::readCameraPrefab(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading camera prefab", ELL_DEBUG); - #endif - - CCameraPrefab* prefab = new CCameraPrefab(readId(reader)); - - if (!reader->isEmptyElement()) - { - // read techniques optics and imager (the latter is completely ignored, though) - readColladaParameters(reader, cameraPrefabName); - - SColladaParam* p; - - // XFOV not yet supported - p = getColladaParameter(ECPN_YFOV); - if (p && p->Type == ECPT_FLOAT) - prefab->YFov = p->Floats[0]; - - p = getColladaParameter(ECPN_ZNEAR); - if (p && p->Type == ECPT_FLOAT) - prefab->ZNear = p->Floats[0]; - - p = getColladaParameter(ECPN_ZFAR); - if (p && p->Type == ECPT_FLOAT) - prefab->ZFar = p->Floats[0]; - // orthographic camera uses LEFT, RIGHT, TOP, and BOTTOM - } - - Prefabs.push_back(prefab); -} - - -//! reads a element and stores it in the image section -void CColladaFileLoader::readImage(io::IXMLReaderUTF8* reader) -{ - // add image to list of loaded images. - Images.push_back(SColladaImage()); - SColladaImage& image=Images.getLast(); - - image.Id = readId(reader); - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading image", core::stringc(image.Id), ELL_DEBUG); - #endif - image.Dimension.Height = (u32)reader->getAttributeValueAsInt("height"); - image.Dimension.Width = (u32)reader->getAttributeValueAsInt("width"); - - if (Version >= 10400) // start with 1.4 - { - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (assetSectionName == reader->getNodeName()) - skipSection(reader, false); - else - if (initFromName == reader->getNodeName()) - { - reader->read(); - image.Source = reader->getNodeData(); - image.Source.trim(); - unescape(image.Source); - image.SourceIsFilename=true; - } - else - if (dataName == reader->getNodeName()) - { - reader->read(); - image.Source = reader->getNodeData(); - image.Source.trim(); - image.SourceIsFilename=false; - } - else - if (extraNodeName == reader->getNodeName()) - skipSection(reader, false); - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (initFromName == reader->getNodeName()) - return; - } - } - } - else - { - image.Source = reader->getAttributeValue("source"); - image.Source.trim(); - image.SourceIsFilename=false; - } -} - - -//! reads a element and stores it in the texture section -void CColladaFileLoader::readTexture(io::IXMLReaderUTF8* reader) -{ - // add texture to list of loaded textures. - Textures.push_back(SColladaTexture()); - SColladaTexture& texture=Textures.getLast(); - - texture.Id = readId(reader); - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading texture", core::stringc(texture.Id), ELL_DEBUG); - #endif - - if (!reader->isEmptyElement()) - { - readColladaInputs(reader, textureSectionName); - SColladaInput* input = getColladaInput(ECIS_IMAGE); - if (input) - { - const core::stringc imageName = input->Source; - texture.Texture = getTextureFromImage(imageName, NULL); - } - } -} - - -//! reads a element and stores it in the material section -void CColladaFileLoader::readMaterial(io::IXMLReaderUTF8* reader) -{ - // add material to list of loaded materials. - Materials.push_back(SColladaMaterial()); - - SColladaMaterial& material = Materials.getLast(); - material.Id = readId(reader); - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading material", core::stringc(material.Id), ELL_DEBUG); - #endif - - if (Version >= 10400) - { - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT && - instanceEffectName == reader->getNodeName()) - { - material.InstanceEffectId = reader->getAttributeValue("url"); - uriToId(material.InstanceEffectId); - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END && - materialSectionName == reader->getNodeName()) - { - break; - } - } // end while reader->read(); - } - else - { - if (!reader->isEmptyElement()) - { - readColladaInputs(reader, materialSectionName); - SColladaInput* input = getColladaInput(ECIS_TEXTURE); - if (input) - { - core::stringc textureName = input->Source; - uriToId(textureName); - for (u32 i=0; iType == ECPT_FLOAT3) - material.Mat.AmbientColor = video::SColorf(p->Floats[0],p->Floats[1],p->Floats[2]).toSColor(); - p = getColladaParameter(ECPN_DIFFUSE); - if (p && p->Type == ECPT_FLOAT3) - material.Mat.DiffuseColor = video::SColorf(p->Floats[0],p->Floats[1],p->Floats[2]).toSColor(); - p = getColladaParameter(ECPN_SPECULAR); - if (p && p->Type == ECPT_FLOAT3) - material.Mat.DiffuseColor = video::SColorf(p->Floats[0],p->Floats[1],p->Floats[2]).toSColor(); - p = getColladaParameter(ECPN_SHININESS); - if (p && p->Type == ECPT_FLOAT) - material.Mat.Shininess = p->Floats[0]; -#endif - } - } -} - -void CColladaFileLoader::readEffect(io::IXMLReaderUTF8* reader, SColladaEffect * effect) -{ - static const core::stringc constantNode("constant"); - static const core::stringc lambertNode("lambert"); - static const core::stringc phongNode("phong"); - static const core::stringc blinnNode("blinn"); - static const core::stringc emissionNode("emission"); - static const core::stringc ambientNode("ambient"); - static const core::stringc diffuseNode("diffuse"); - static const core::stringc specularNode("specular"); - static const core::stringc shininessNode("shininess"); - static const core::stringc reflectiveNode("reflective"); - static const core::stringc reflectivityNode("reflectivity"); - static const core::stringc transparentNode("transparent"); - static const core::stringc transparencyNode("transparency"); - static const core::stringc indexOfRefractionNode("index_of_refraction"); - - if (!effect) - { - Effects.push_back(SColladaEffect()); - effect = &Effects.getLast(); - effect->Parameters = new io::CAttributes(); - effect->Id = readId(reader); - effect->Transparency = 1.f; - effect->Mat.Lighting=true; - effect->Mat.NormalizeNormals=true; - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading effect", core::stringc(effect->Id), ELL_DEBUG); - #endif - } - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - // first come the tags we descend, but ignore the top-levels - if (!reader->isEmptyElement() && ((profileCOMMONSectionName == reader->getNodeName()) || - (techniqueNodeName == reader->getNodeName()))) - readEffect(reader,effect); - else - if (newParamName == reader->getNodeName()) - readParameter(reader, effect->Parameters); - else - // these are the actual materials inside technique - if (constantNode == reader->getNodeName() || - lambertNode == reader->getNodeName() || - phongNode == reader->getNodeName() || - blinnNode == reader->getNodeName()) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading effect part", reader->getNodeName(), ELL_DEBUG); - #endif - effect->Mat.setFlag(irr::video::EMF_GOURAUD_SHADING, - phongNode == reader->getNodeName() || - blinnNode == reader->getNodeName()); - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - const core::stringc node = reader->getNodeName(); - if (emissionNode == node || ambientNode == node || - diffuseNode == node || specularNode == node || - reflectiveNode == node || transparentNode == node ) - { - // color or texture types - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT && - colorNodeName == reader->getNodeName()) - { - const video::SColorf colorf = readColorNode(reader); - const video::SColor color = colorf.toSColor(); - if (emissionNode == node) - effect->Mat.EmissiveColor = color; - else - if (ambientNode == node) - effect->Mat.AmbientColor = color; - else - if (diffuseNode == node) - effect->Mat.DiffuseColor = color; - else - if (specularNode == node) - effect->Mat.SpecularColor = color; - else - if (transparentNode == node) - effect->Transparency = colorf.getAlpha(); - } - else - if (reader->getNodeType() == io::EXN_ELEMENT && - textureNodeName == reader->getNodeName()) - { - effect->Textures.push_back(reader->getAttributeValue("texture")); - break; - } - else - if (reader->getNodeType() == io::EXN_ELEMENT) - skipSection(reader, false); - else - if (reader->getNodeType() == io::EXN_ELEMENT_END && - node == reader->getNodeName()) - break; - } - } - else - if (shininessNode == node || reflectivityNode == node || - transparencyNode == node || indexOfRefractionNode == node ) - { - // float or param types - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT && - floatNodeName == reader->getNodeName()) - { - f32 f = readFloatNode(reader); - if (shininessNode == node) - effect->Mat.Shininess = f; - else - if (transparencyNode == node) - effect->Transparency *= f; - } - else - if (reader->getNodeType() == io::EXN_ELEMENT) - skipSection(reader, false); - else - if (reader->getNodeType() == io::EXN_ELEMENT_END && - node == reader->getNodeName()) - break; - } - } - else - skipSection(reader, true); // ignore all other nodes - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END && ( - constantNode == reader->getNodeName() || - lambertNode == reader->getNodeName() || - phongNode == reader->getNodeName() || - blinnNode == reader->getNodeName() - )) - break; - } - } - else - if (!reader->isEmptyElement() && (extraNodeName == reader->getNodeName())) - readEffect(reader,effect); - else - if (doubleSidedNodeName == reader->getNodeName()) - { - // read the GoogleEarth extra flag for double sided polys - s32 doubleSided = 0; - readIntsInsideElement(reader,&doubleSided,1); - if (doubleSided) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("Setting double sided flag for effect.", ELL_DEBUG); - #endif - - effect->Mat.setFlag(irr::video::EMF_BACK_FACE_CULLING,false); - } - } - else - skipSection(reader, true); // ignore all other sections - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (effectSectionName == reader->getNodeName()) - break; - else - if (profileCOMMONSectionName == reader->getNodeName()) - break; - else - if (techniqueNodeName == reader->getNodeName()) - break; - else - if (extraNodeName == reader->getNodeName()) - break; - } - } - - if (effect->Mat.AmbientColor == video::SColor(0) && - effect->Mat.DiffuseColor != video::SColor(0)) - effect->Mat.AmbientColor = effect->Mat.DiffuseColor; - if (effect->Mat.DiffuseColor == video::SColor(0) && - effect->Mat.AmbientColor != video::SColor(0)) - effect->Mat.DiffuseColor = effect->Mat.AmbientColor; - if ((effect->Transparency != 0.0f) && (effect->Transparency != 1.0f)) - { - effect->Mat.MaterialType = irr::video::EMT_TRANSPARENT_VERTEX_ALPHA; - effect->Mat.ZWriteEnable = video::EZW_OFF; - } - - video::E_TEXTURE_CLAMP twu = video::ETC_REPEAT; - s32 idx = effect->Parameters->findAttribute(wrapsName.c_str()); - if ( idx >= 0 ) - twu = (video::E_TEXTURE_CLAMP)(effect->Parameters->getAttributeAsInt(idx)); - video::E_TEXTURE_CLAMP twv = video::ETC_REPEAT; - idx = effect->Parameters->findAttribute(wraptName.c_str()); - if ( idx >= 0 ) - twv = (video::E_TEXTURE_CLAMP)(effect->Parameters->getAttributeAsInt(idx)); - video::E_TEXTURE_CLAMP twr = video::ETC_REPEAT; - idx = effect->Parameters->findAttribute(wrappName.c_str()); - if ( idx >= 0 ) - twr = (video::E_TEXTURE_CLAMP)(effect->Parameters->getAttributeAsInt(idx)); - else - { - // for downward compatibility with older Irrlicht collada writer - idx = effect->Parameters->findAttribute(wraprName.c_str()); - if ( idx >= 0 ) - twr = (video::E_TEXTURE_CLAMP)(effect->Parameters->getAttributeAsInt(idx)); - } - - for (u32 i=0; iMat.TextureLayer[i].TextureWrapU = twu; - effect->Mat.TextureLayer[i].TextureWrapV = twv; - effect->Mat.TextureLayer[i].TextureWrapW = twr; - } - - effect->Mat.setFlag(video::EMF_BILINEAR_FILTER, effect->Parameters->getAttributeAsBool("bilinear")); - effect->Mat.setFlag(video::EMF_TRILINEAR_FILTER, effect->Parameters->getAttributeAsBool("trilinear")); - effect->Mat.setFlag(video::EMF_ANISOTROPIC_FILTER, effect->Parameters->getAttributeAsBool("anisotropic")); -} - - -const SColladaMaterial* CColladaFileLoader::findMaterial(const core::stringc& materialName) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA find material", materialName, ELL_DEBUG); - #endif - - // do a quick lookup in the materials - SColladaMaterial matToFind; - matToFind.Id = materialName; - s32 mat = Materials.binary_search(matToFind); - if (mat == -1) - return 0; - // instantiate the material effect if needed - if (Materials[mat].InstanceEffectId.size() != 0) - { - // do a quick lookup in the effects - SColladaEffect effectToFind; - effectToFind.Id = Materials[mat].InstanceEffectId; - s32 effect = Effects.binary_search(effectToFind); - if (effect != -1) - { - // found the effect, instantiate by copying into the material - Materials[mat].Mat = Effects[effect].Mat; - if (Effects[effect].Textures.size()) - Materials[mat].Mat.setTexture(0, getTextureFromImage(Effects[effect].Textures[0], &(Effects[effect]))); - Materials[mat].Transparency = Effects[effect].Transparency; - // and indicate the material is instantiated by removing the effect ref - Materials[mat].InstanceEffectId = ""; - } - else - return 0; - } - return &Materials[mat]; -} - - -void CColladaFileLoader::readBindMaterialSection(io::IXMLReaderUTF8* reader, const core::stringc & id) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading bind material", ELL_DEBUG); - #endif - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (instanceMaterialName == reader->getNodeName()) - { - // the symbol to retarget, and the target material - core::stringc meshbufferReference = reader->getAttributeValue("symbol"); - if (meshbufferReference.size()==0) - continue; - core::stringc target = reader->getAttributeValue("target"); - uriToId(target); - if (target.size()==0) - continue; - const SColladaMaterial * material = findMaterial(target); - if (!material) - continue; - // bind any pending materials for this node - meshbufferReference = id+"/"+meshbufferReference; -#ifdef COLLADA_READER_DEBUG - os::Printer::log((core::stringc("Material binding: ")+meshbufferReference+" "+target).c_str(), ELL_DEBUG); -#endif - if (MaterialsToBind.find(meshbufferReference)) - { - core::array & toBind - = MeshesToBind[MaterialsToBind[meshbufferReference]]; -#ifdef COLLADA_READER_DEBUG - os::Printer::log("Material binding now ",material->Id.c_str(), ELL_DEBUG); - os::Printer::log("#meshbuffers",core::stringc(toBind.size()).c_str(), ELL_DEBUG); -#endif - SMesh tmpmesh; - for (u32 i = 0; i < toBind.size(); ++i) - { - toBind[i]->getMaterial() = material->Mat; - tmpmesh.addMeshBuffer(toBind[i]); - - if ((material->Transparency!=0.0f) && (material->Transparency!=1.0f)) - { - toBind[i]->getMaterial().MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; - toBind[i]->getMaterial().ZWriteEnable = video::EZW_OFF; - } - } - SceneManager->getMeshManipulator()->setVertexColors(&tmpmesh,material->Mat.DiffuseColor); - if ((material->Transparency!=0.0f) && (material->Transparency!=1.0f)) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA found transparency material", core::stringc(material->Transparency).c_str(), ELL_DEBUG); - #endif - SceneManager->getMeshManipulator()->setVertexColorAlpha(&tmpmesh, core::floor32(material->Transparency*255.0f)); - } - } - } - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END && - bindMaterialName == reader->getNodeName()) - break; - } -} - - -//! reads a element and stores it as mesh if possible -void CColladaFileLoader::readGeometry(io::IXMLReaderUTF8* reader) -{ - core::stringc id = readId(reader); - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading geometry", id, ELL_DEBUG); - #endif - - SAnimatedMesh* amesh = new SAnimatedMesh(); - scene::SMesh* mesh = new SMesh(); - amesh->addMesh(mesh); - core::array sources; - bool okToReadArray = false; - - // handles geometry node and the mesh children in this loop - // read sources with arrays and accessor for each mesh - if (!reader->isEmptyElement()) - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - const char* nodeName = reader->getNodeName(); - if (meshSectionName == nodeName) - { - // inside a mesh section. Don't have to do anything here. - } - else - if (sourceSectionName == nodeName) - { - // create a new source - sources.push_back(SSource()); - sources.getLast().Id = readId(reader); - - #ifdef COLLADA_READER_DEBUG - os::Printer::log("Reading source", sources.getLast().Id.c_str(), ELL_DEBUG); - #endif - } - else - if (arraySectionName == nodeName || floatArraySectionName == nodeName || intArraySectionName == nodeName) - { - // create a new array and read it. - if (!sources.empty()) - { - sources.getLast().Array.Name = readId(reader); - - int count = reader->getAttributeValueAsInt("count"); - sources.getLast().Array.Data.set_used(count); // pre allocate - - // check if type of array is ok - const char* type = reader->getAttributeValue("type"); - okToReadArray = (type && (!strcmp("float", type) || !strcmp("int", type))) || floatArraySectionName == nodeName || intArraySectionName == nodeName; - - #ifdef COLLADA_READER_DEBUG - os::Printer::log("Read array", sources.getLast().Array.Name.c_str(), ELL_DEBUG); - #endif - } - #ifdef COLLADA_READER_DEBUG - else - os::Printer::log("Warning, array outside source found", - readId(reader).c_str(), ELL_DEBUG); - #endif - - } - else - if (accessorSectionName == nodeName) // child of source (below a technique tag) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("Reading accessor", ELL_DEBUG); - #endif - SAccessor accessor; - accessor.Count = reader->getAttributeValueAsInt("count"); - accessor.Offset = reader->getAttributeValueAsInt("offset"); - accessor.Stride = reader->getAttributeValueAsInt("stride"); - if (accessor.Stride == 0) - accessor.Stride = 1; - - // the accessor contains some information on how to access (boi!) the array, - // the info is stored in collada style parameters, so just read them. - readColladaParameters(reader, accessorSectionName); - if (!sources.empty()) - { - sources.getLast().Accessors.push_back(accessor); - sources.getLast().Accessors.getLast().Parameters = ColladaParameters; - } - } - else - if (verticesSectionName == nodeName) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("Reading vertices", ELL_DEBUG); - #endif - // read vertex input position source - readColladaInputs(reader, verticesSectionName); - } - else - // lines and linestrips missing - if (polygonsSectionName == nodeName || - polylistSectionName == nodeName || - trianglesSectionName == nodeName) - { - // read polygons section - readPolygonSection(reader, sources, mesh, id); - } - else - // trifans, and tristrips missing - if (doubleSidedNodeName == reader->getNodeName()) - { - // read the extra flag for double sided polys - s32 doubleSided = 0; - readIntsInsideElement(reader,&doubleSided,1); - if (doubleSided) - { - #ifdef COLLADA_READER_DEBUG - os::Printer::log("Setting double sided flag for mesh.", ELL_DEBUG); - #endif - amesh->setMaterialFlag(irr::video::EMF_BACK_FACE_CULLING,false); - } - } - else - // techniqueCommon or 'technique profile=common' must not be skipped - if ((techniqueCommonSectionName != nodeName) // Collada 1.2/1.3 - && (techniqueNodeName != nodeName) // Collada 1.4+ - && (extraNodeName != nodeName)) - { - os::Printer::log("COLLADA loader warning: Wrong tag usage found in geometry", reader->getNodeName(), ELL_WARNING); - skipSection(reader, true); // ignore all other sections - } - } // end if node type is element - else - if (reader->getNodeType() == io::EXN_TEXT) - { - // read array data - if (okToReadArray && !sources.empty()) - { - core::array& a = sources.getLast().Array.Data; - core::stringc data = reader->getNodeData(); - data.trim(); - const c8* p = &data[0]; - - for (u32 i=0; igetNodeType() == io::EXN_ELEMENT_END) - { - if (geometrySectionName == reader->getNodeName()) - { - // end of geometry section reached, cancel out - break; - } - } - } // end while reader->read(); - - // add mesh as geometry - - mesh->recalculateBoundingBox(); - amesh->recalculateBoundingBox(); - - // create virtual file name - io::path filename = CurrentlyLoadingMesh; - filename += '#'; - filename += id; - - // add to scene manager - if (LoadedMeshCount) - { - SceneManager->getMeshCache()->addMesh(filename.c_str(), amesh); - os::Printer::log("Added COLLADA mesh", filename.c_str(), ELL_DEBUG); - } - else - { - FirstLoadedMeshName = filename; - FirstLoadedMesh = amesh; - FirstLoadedMesh->grab(); - } - - ++LoadedMeshCount; - mesh->drop(); - amesh->drop(); - - // create geometry prefab - u32 i; - for (i=0; igetId()==id) - { - ((CGeometryPrefab*)Prefabs[i])->Mesh=mesh; - break; - } - } - if (i==Prefabs.size()) - { - CGeometryPrefab* prefab = new CGeometryPrefab(id); - prefab->Mesh = mesh; - Prefabs.push_back(prefab); - } - - // store as dummy mesh if no instances will be created - if (!CreateInstances && !DummyMesh) - { - DummyMesh = amesh; - DummyMesh->grab(); - } -} - - -struct SPolygon -{ - core::array Indices; -}; - -//! reads a polygons section and creates a mesh from it -void CColladaFileLoader::readPolygonSection(io::IXMLReaderUTF8* reader, - core::array& sources, scene::SMesh* mesh, - const core::stringc& geometryId) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading polygon section", ELL_DEBUG); - #endif - - core::stringc materialName = reader->getAttributeValue("material"); - - core::stringc polygonType = reader->getNodeName(); - const int polygonCount = reader->getAttributeValueAsInt("count"); // Not useful because it only determines the number of primitives, which have arbitrary vertices in case of polygon - core::array polygons; - if (polygonType == polygonsSectionName) - polygons.reallocate(polygonCount); - core::array vCounts; - bool parsePolygonOK = false; - bool parseVcountOK = false; - u32 inputSemanticCount = 0; - u32 maxOffset = 0; - core::array localInputs; - - // read all and primitives - if (!reader->isEmptyElement()) - while(reader->read()) - { - const char* nodeName = reader->getNodeName(); - - if (reader->getNodeType() == io::EXN_ELEMENT) - { - // polygon node may contain params - if (inputTagName == nodeName) - { - // read input tag - readColladaInput(reader, localInputs); - - // resolve input source - SColladaInput& inp = localInputs.getLast(); - - // get input source array id, if it is a vertex input, take - // the -source attribute. - if (inp.Semantic == ECIS_VERTEX) - { - inp.Source = Inputs[0].Source; - for (u32 i=1; igetNodeType() == io::EXN_ELEMENT_END) - { - if (primitivesName == nodeName) - parsePolygonOK = false; // end parsing a polygon - else - if (vcountName == nodeName) - parseVcountOK = false; // end parsing vcounts - else - if (polygonType == nodeName) - break; // cancel out and create mesh - - } // end is element end - else - if (reader->getNodeType() == io::EXN_TEXT) - { - if (parseVcountOK) - { - core::stringc data = reader->getNodeData(); - data.trim(); - const c8* p = &data[0]; - while(*p) - { - findNextNoneWhiteSpace(&p); - if (*p) - vCounts.push_back(readInt(&p)); - } - parseVcountOK = false; - } - else - if (parsePolygonOK && polygons.size()) - { - core::stringc data = reader->getNodeData(); - data.trim(); - const c8* p = &data[0]; - SPolygon& poly = polygons.getLast(); - if (polygonType == polygonsSectionName) - poly.Indices.reallocate((maxOffset+1)*3); - else - poly.Indices.reallocate(polygonCount*(maxOffset+1)*3); - - if (vCounts.empty()) - { - while(*p) - { - findNextNoneWhiteSpace(&p); - poly.Indices.push_back(readInt(&p)); - } - } - else - { - for (u32 i = 0; i < vCounts.size(); i++) - { - const int polyVCount = vCounts[i]; - core::array polyCorners; - - for (u32 j = 0; j < polyVCount * inputSemanticCount; j++) - { - if (!*p) - break; - findNextNoneWhiteSpace(&p); - polyCorners.push_back(readInt(&p)); - } - - while (polyCorners.size() >= 3 * inputSemanticCount) - { - // add one triangle's worth of indices - for (u32 k = 0; k < inputSemanticCount * 3; ++k) - { - poly.Indices.push_back(polyCorners[k]); - } - - // remove one corner from our poly - polyCorners.erase(inputSemanticCount,inputSemanticCount); - } - polyCorners.clear(); - } - vCounts.clear(); - } - parsePolygonOK = false; - } - } - } // end while reader->read() - - // find source array (we'll ignore accessors for this implementation) - for (u32 i=0; i vertMap; - - for (u32 i=0; i indices; - const u32 vertexCount = polygons[i].Indices.size() / maxOffset; - mbuffer->Vertices.reallocate(mbuffer->Vertices.size()+vertexCount); - - // for all index/semantic groups - for (u32 v=0; v::Node* n = vertMap.find(vtx); - if (n) - { - indices.push_back(n->getValue()); - } - else - { - indices.push_back(mbuffer->getVertexCount()); - mbuffer->Vertices.push_back(vtx); - vertMap.insert(vtx, mbuffer->getVertexCount()-1); - } - } // end for all vertices - - if (polygonsSectionName == polygonType && - indices.size() > 3) - { - // need to tessellate for polygons of 4 or more vertices - // for now we naively turn interpret it as a triangle fan - // as full tessellation is problematic - for (u32 ind = 0; ind+2 < indices.size(); ++ind) - { - mbuffer->Indices.push_back(indices[0]); - mbuffer->Indices.push_back(indices[ind+2]); - mbuffer->Indices.push_back(indices[ind+1]); - } - } - else - { - // it's just triangles - for (u32 ind = 0; ind < indices.size(); ind+=3) - { - mbuffer->Indices.push_back(indices[ind+2]); - mbuffer->Indices.push_back(indices[ind+1]); - mbuffer->Indices.push_back(indices[ind+0]); - } - } - - } // end for all polygons - } - else - { - // lightmap mesh buffer - - scene::SMeshBufferLightMap* mbuffer = new SMeshBufferLightMap(); - buffer = mbuffer; - - for (u32 i=0; iVertices.reallocate(mbuffer->Vertices.size()+vertexCount); - // for all vertices in array - for (u32 v=0; vVertices.push_back(vtx); - - } // end for all vertices - - // add vertex indices - const u32 oldVertexCount = mbuffer->Vertices.size() - vertexCount; - for (u32 face=0; faceIndices.push_back(oldVertexCount + 0); - mbuffer->Indices.push_back(oldVertexCount + 1 + face); - mbuffer->Indices.push_back(oldVertexCount + 2 + face); - } - - } // end for all polygons - } - - const SColladaMaterial* m = findMaterial(materialName); - if (m) - { - buffer->getMaterial() = m->Mat; - SMesh tmpmesh; - tmpmesh.addMeshBuffer(buffer); - SceneManager->getMeshManipulator()->setVertexColors(&tmpmesh,m->Mat.DiffuseColor); - if (m->Transparency != 1.0f) - SceneManager->getMeshManipulator()->setVertexColorAlpha(&tmpmesh,core::floor32(m->Transparency*255.0f)); - } - // add future bind reference for the material - core::stringc meshbufferReference = geometryId+"/"+materialName; - if (!MaterialsToBind.find(meshbufferReference)) - { - MaterialsToBind[meshbufferReference] = MeshesToBind.size(); - MeshesToBind.push_back(core::array()); - } - MeshesToBind[MaterialsToBind[meshbufferReference]].push_back(buffer); - - // calculate normals if there is no slot for it - - if (!normalSlotCount) - SceneManager->getMeshManipulator()->recalculateNormals(buffer, true); - - // recalculate bounding box - buffer->recalculateBoundingBox(); - - // add mesh buffer - mesh->addMeshBuffer(buffer); - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA added meshbuffer", core::stringc(buffer->getVertexCount())+" vertices, "+core::stringc(buffer->getIndexCount())+" indices.", ELL_DEBUG); - #endif - - buffer->drop(); -} - - -//! reads a element and stores it as prefab -void CColladaFileLoader::readLightPrefab(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading light prefab", ELL_DEBUG); - #endif - - CLightPrefab* prefab = new CLightPrefab(readId(reader)); - - if (!reader->isEmptyElement()) - { - if (Version >= 10400) // start with 1.4 - { - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (pointSectionName == reader->getNodeName()) - prefab->LightData.Type=video::ELT_POINT; - else - if (directionalSectionName == reader->getNodeName()) - prefab->LightData.Type=video::ELT_DIRECTIONAL; - else - if (spotSectionName == reader->getNodeName()) - prefab->LightData.Type=video::ELT_SPOT; - else - if (ambientSectionName == reader->getNodeName()) - prefab->LightData.Type=ELT_AMBIENT; - else - if (colorNodeName == reader->getNodeName()) - prefab->LightData.DiffuseColor=readColorNode(reader); - else - if (constantAttenuationNodeName == reader->getNodeName()) - readFloatsInsideElement(reader,&prefab->LightData.Attenuation.X,1); - else - if (linearAttenuationNodeName == reader->getNodeName()) - readFloatsInsideElement(reader,&prefab->LightData.Attenuation.Y,1); - else - if (quadraticAttenuationNodeName == reader->getNodeName()) - readFloatsInsideElement(reader,&prefab->LightData.Attenuation.Z,1); - else - if (falloffAngleNodeName == reader->getNodeName()) - { - readFloatsInsideElement(reader,&prefab->LightData.OuterCone,1); - prefab->LightData.OuterCone *= core::DEGTORAD; - } - else - if (falloffExponentNodeName == reader->getNodeName()) - readFloatsInsideElement(reader,&prefab->LightData.Falloff,1); - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if ((pointSectionName == reader->getNodeName()) || - (directionalSectionName == reader->getNodeName()) || - (spotSectionName == reader->getNodeName()) || - (ambientSectionName == reader->getNodeName())) - break; - } - } - } - else - { - readColladaParameters(reader, lightPrefabName); - - SColladaParam* p = getColladaParameter(ECPN_COLOR); - if (p && p->Type == ECPT_FLOAT3) - prefab->LightData.DiffuseColor.set(p->Floats[0], p->Floats[1], p->Floats[2]); - } - } - - Prefabs.push_back(prefab); -} - - -//! returns a collada parameter or none if not found -SColladaParam* CColladaFileLoader::getColladaParameter(ECOLLADA_PARAM_NAME name) -{ - for (u32 i=0; i& inputs) -{ - // parse param - SColladaInput p; - - // get type - core::stringc semanticName = reader->getAttributeValue("semantic"); - for (u32 i=0; inputSemanticNames[i]; ++i) - { - if (semanticName == inputSemanticNames[i]) - { - p.Semantic = (ECOLLADA_INPUT_SEMANTIC)i; - break; - } - } - - // get source - p.Source = reader->getAttributeValue("source"); - if (reader->getAttributeValue("offset")) // Collada 1.4+ - p.Offset = (u32)reader->getAttributeValueAsInt("offset"); - else // Collada 1.2/1.3 - p.Offset = (u32)reader->getAttributeValueAsInt("idx"); - p.Set = (u32)reader->getAttributeValueAsInt("set"); - - // add input - inputs.push_back(p); -} - -//! parses all collada inputs inside an element and stores them in Inputs -void CColladaFileLoader::readColladaInputs(io::IXMLReaderUTF8* reader, const core::stringc& parentName) -{ - Inputs.clear(); - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT && - inputTagName == reader->getNodeName()) - { - readColladaInput(reader, Inputs); - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (parentName == reader->getNodeName()) - return; // end of parent reached - } - - } // end while reader->read(); -} - -//! parses all collada parameters inside an element and stores them in ColladaParameters -void CColladaFileLoader::readColladaParameters(io::IXMLReaderUTF8* reader, - const core::stringc& parentName) -{ - ColladaParameters.clear(); - - const char* const paramNames[] = {"COLOR", "AMBIENT", "DIFFUSE", - "SPECULAR", "SHININESS", "YFOV", "ZNEAR", "ZFAR", 0}; - - const char* const typeNames[] = {"float", "float2", "float3", 0}; - - while(reader->read()) - { - const char* nodeName = reader->getNodeName(); - if (reader->getNodeType() == io::EXN_ELEMENT && - paramTagName == nodeName) - { - // parse param - SColladaParam p; - - // get type - u32 i; - core::stringc typeName = reader->getAttributeValue("type"); - for (i=0; typeNames[i]; ++i) - if (typeName == typeNames[i]) - { - p.Type = (ECOLLADA_PARAM_TYPE)i; - break; - } - - // get name - core::stringc nameName = reader->getAttributeValue("name"); - for (i=0; typeNames[i]; ++i) - if (nameName == paramNames[i]) - { - p.Name = (ECOLLADA_PARAM_NAME)i; - break; - } - - // read parameter data inside parameter tags - switch(p.Type) - { - case ECPT_FLOAT: - case ECPT_FLOAT2: - case ECPT_FLOAT3: - case ECPT_FLOAT4: - readFloatsInsideElement(reader, p.Floats, p.Type - ECPT_FLOAT + 1); - break; - - // TODO: other types of data (ints, bools or whatever) - default: - break; - } - - // add param - ColladaParameters.push_back(p); - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (parentName == reader->getNodeName()) - return; // end of parent reached - } - - } // end while reader->read(); -} - - -//! parses a float from a char pointer and moves the pointer -//! to the end of the parsed float -inline f32 CColladaFileLoader::readFloat(const c8** p) -{ - f32 ftmp; - *p = core::fast_atof_move(*p, ftmp); - return ftmp; -} - - -//! parses an int from a char pointer and moves the pointer to -//! the end of the parsed float -inline s32 CColladaFileLoader::readInt(const c8** p) -{ - return (s32)readFloat(p); -} - - -//! places pointer to next begin of a token -void CColladaFileLoader::findNextNoneWhiteSpace(const c8** start) -{ - const c8* p = *start; - - while(*p && (*p==' ' || *p=='\n' || *p=='\r' || *p=='\t')) - ++p; - - // TODO: skip comments - - *start = p; -} - - -//! reads floats from inside of xml element until end of xml element -void CColladaFileLoader::readFloatsInsideElement(io::IXMLReaderUTF8* reader, f32* floats, u32 count) -{ - if (reader->isEmptyElement()) - return; - - while(reader->read()) - { - // TODO: check for comments inside the element - // and ignore them. - - if (reader->getNodeType() == io::EXN_TEXT) - { - // parse float data - core::stringc data = reader->getNodeData(); - data.trim(); - const c8* p = &data[0]; - - for (u32 i=0; igetNodeType() == io::EXN_ELEMENT_END) - break; // end parsing text - } -} - - -//! reads ints from inside of xml element until end of xml element -void CColladaFileLoader::readIntsInsideElement(io::IXMLReaderUTF8* reader, s32* ints, u32 count) -{ - if (reader->isEmptyElement()) - return; - - while(reader->read()) - { - // TODO: check for comments inside the element - // and ignore them. - - if (reader->getNodeType() == io::EXN_TEXT) - { - // parse float data - core::stringc data = reader->getNodeData(); - data.trim(); - const c8* p = &data[0]; - - for (u32 i=0; igetNodeType() == io::EXN_ELEMENT_END) - break; // end parsing text - } -} - - -video::SColorf CColladaFileLoader::readColorNode(io::IXMLReaderUTF8* reader) -{ - if (reader->getNodeType() == io::EXN_ELEMENT && - colorNodeName == reader->getNodeName()) - { - f32 color[4]; - readFloatsInsideElement(reader,color,4); - return video::SColorf(color[0], color[1], color[2], color[3]); - } - - return video::SColorf(); -} - - -f32 CColladaFileLoader::readFloatNode(io::IXMLReaderUTF8* reader) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading ", ELL_DEBUG); - #endif - - f32 result = 0.0f; - if (reader->getNodeType() == io::EXN_ELEMENT && - floatNodeName == reader->getNodeName()) - { - readFloatsInsideElement(reader,&result,1); - } - - return result; -} - - -//! clears all loaded data -void CColladaFileLoader::clearData() -{ - // delete all prefabs - - for (u32 i=0; idrop(); - - Prefabs.clear(); - - // clear all parameters - ColladaParameters.clear(); - - // clear all materials - Images.clear(); - - // clear all materials - Textures.clear(); - - // clear all materials - Materials.clear(); - - // clear all inputs - Inputs.clear(); - - // clear all effects - for ( u32 i=0; idrop(); - Effects.clear(); - - // clear all the materials to bind - MaterialsToBind.clear(); - MeshesToBind.clear(); -} - - -//! changes the XML URI into an internal id -void CColladaFileLoader::uriToId(core::stringc& str) -{ - // Currently, we only remove the # from the beginning - // as we don't support referencing other files. - if (!str.size()) - return; - - if (str[0] == '#') - str.erase(0); -} - - -//! read Collada Id, uses id or name if id is missing -core::stringc CColladaFileLoader::readId(io::IXMLReaderUTF8* reader) -{ - core::stringc id = reader->getAttributeValue("id"); - if (id.size()==0) - id = reader->getAttributeValue("name"); - return id; -} - - -//! create an Irrlicht texture from the reference -video::ITexture* CColladaFileLoader::getTextureFromImage(core::stringc uri, SColladaEffect * effect) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA searching texture", uri, ELL_DEBUG); - #endif - video::IVideoDriver* driver = SceneManager->getVideoDriver(); - for (;;) - { - uriToId(uri); - for (u32 i=0; igetTexture( Images[i].Source ) : NULL; - } - else - if (Images[i].Source.size()) - { - //const u32 size = Images[i].Dimension.getArea(); - const u32 size = Images[i].Dimension.Width * Images[i].Dimension.Height;; - u32* data = new u32[size]; // we assume RGBA - u32* ptrdest = data; - const c8* ptrsrc = Images[i].Source.c_str(); - for (u32 j=0; jcreateImageFromData(video::ECF_A8R8G8B8, Images[i].Dimension, data, true, true); - video::ITexture* tex = driver->addTexture((CurrentlyLoadingMesh+"#"+Images[i].Id).c_str(), img); - img->drop(); - return tex; - } - break; - } - } - if (effect && effect->Parameters->getAttributeType(uri.c_str())==io::EAT_STRING) - { - uri = effect->Parameters->getAttributeAsString(uri.c_str()); -#ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA now searching texture", uri.c_str(), ELL_DEBUG); -#endif - } - else - break; - } - return 0; -} - - -//! read a parameter and value -void CColladaFileLoader::readParameter(io::IXMLReaderUTF8* reader, io::IAttributes* parameters) -{ - #ifdef COLLADA_READER_DEBUG - os::Printer::log("COLLADA reading parameter", ELL_DEBUG); - #endif - - if ( !parameters ) - return; - - const core::stringc name = reader->getAttributeValue("sid"); - if (!reader->isEmptyElement()) - { - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (floatNodeName == reader->getNodeName()) - { - const f32 f = readFloatNode(reader); - parameters->addFloat(name.c_str(), f); - } - else - if (float2NodeName == reader->getNodeName()) - { - f32 f[2]; - readFloatsInsideElement(reader, f, 2); -// Parameters.addVector2d(name.c_str(), core::vector2df(f[0],f[1])); - } - else - if (float3NodeName == reader->getNodeName()) - { - f32 f[3]; - readFloatsInsideElement(reader, f, 3); - parameters->addVector3d(name.c_str(), core::vector3df(f[0],f[1],f[2])); - } - else - if ((initFromName == reader->getNodeName()) || - (sourceSectionName == reader->getNodeName())) - { - reader->read(); - parameters->addString(name.c_str(), reader->getNodeData()); - } - else - if (wrapsName == reader->getNodeName()) - { - reader->read(); - const core::stringc val = reader->getNodeData(); - if (val == "WRAP") - parameters->addInt(wrapsName.c_str(), (int)video::ETC_REPEAT); - else if ( val== "MIRROR") - parameters->addInt(wrapsName.c_str(), (int)video::ETC_MIRROR); - else if ( val== "CLAMP") - parameters->addInt(wrapsName.c_str(), (int)video::ETC_CLAMP_TO_EDGE); - else if ( val== "BORDER") - parameters->addInt(wrapsName.c_str(), (int)video::ETC_CLAMP_TO_BORDER); - else if ( val== "NONE") - parameters->addInt(wrapsName.c_str(), (int)video::ETC_CLAMP_TO_BORDER); - } - else - if (wraptName == reader->getNodeName()) - { - reader->read(); - const core::stringc val = reader->getNodeData(); - if (val == "WRAP") - parameters->addInt(wraptName.c_str(), (int)video::ETC_REPEAT); - else if ( val== "MIRROR") - parameters->addInt(wraptName.c_str(), (int)video::ETC_MIRROR); - else if ( val== "CLAMP") - parameters->addInt(wraptName.c_str(), (int)video::ETC_CLAMP_TO_EDGE); - else if ( val== "BORDER") - parameters->addInt(wraptName.c_str(), (int)video::ETC_CLAMP_TO_BORDER); - else if ( val== "NONE") - parameters->addInt(wraptName.c_str(), (int)video::ETC_CLAMP_TO_BORDER); - } - else - if (minfilterName == reader->getNodeName()) - { - reader->read(); - const core::stringc val = reader->getNodeData(); - if (val == "LINEAR_MIPMAP_LINEAR") - parameters->addBool("trilinear", true); - else - if (val == "LINEAR_MIPMAP_NEAREST") - parameters->addBool("bilinear", true); - } - else - if (magfilterName == reader->getNodeName()) - { - reader->read(); - const core::stringc val = reader->getNodeData(); - if (val != "LINEAR") - { - parameters->addBool("bilinear", false); - parameters->addBool("trilinear", false); - } - } - else - if (mipfilterName == reader->getNodeName()) - { - parameters->addBool("anisotropic", true); - } - } - else - if(reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (newParamName == reader->getNodeName()) - break; - } - } - } -} - -core::matrix4 CColladaFileLoader::flipZAxis(const core::matrix4& m) -{ - core::matrix4 matrix(m); - matrix[2] *= -1.f; - matrix[6] *= -1.f; - matrix[8] *= -1.f; - matrix[9] *= -1.f; - matrix[11] *= -1.f; - matrix[14] *= -1.f; - - return matrix; -} - -void CColladaFileLoader::unescape(irr::core::stringc& uri) -{ - u32 len = uri.size(); - for (u32 i=0; i Textures; - video::SMaterial Mat; - // TODO: Parameters looks somewhat lazy workaround, I think we should really read all parameters correct. - io::IAttributes * Parameters; - - inline bool operator< (const SColladaEffect & other) const - { - return Id < other.Id; - } -}; - - -struct SNumberArray // for storing float and int arrays -{ - core::stringc Name; - core::array Data; -}; - -struct SAccessor -{ - SAccessor() - : Count(0), Offset(0), Stride(1) {} - // I don't store the source of the accessor here because I assume - // it to use the array of the source this accessor is located in. - - int Count; - int Offset; - int Stride; - - core::array Parameters; // parameters defining the accessor -}; - -struct SSource -{ - core::stringc Id; - SNumberArray Array; - core::array Accessors; -}; - -class CScenePrefab; - -//! Meshloader capable of loading COLLADA meshes and scene descriptions into Irrlicht. -class CColladaFileLoader : public IMeshLoader -{ -public: - - //! Constructor - CColladaFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs); - - //! destructor - virtual ~CColladaFileLoader(); - - //! returns true if the file maybe is able to be loaded by this class - //! based on the file extension (e.g. ".cob") - virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_; - - //! creates/loads an animated mesh from the file. - //! \return Pointer to the created mesh. Returns 0 if loading failed. - //! If you no longer need the mesh, you should call IAnimatedMesh::drop(). - //! See IReferenceCounted::drop() for more information. - virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_; - -private: - - //! skips an (unknown) section in the collada document - void skipSection(io::IXMLReaderUTF8* reader, bool reportSkipping); - - //! reads the section and its content - void readColladaSection(io::IXMLReaderUTF8* reader); - - //! reads a section and its content - void readLibrarySection(io::IXMLReaderUTF8* reader); - - //! reads a element and stores it as a prefab - void readVisualScene(io::IXMLReaderUTF8* reader); - - //! reads a section and its content - void readSceneSection(io::IXMLReaderUTF8* reader); - - //! reads a section and its content - void readAssetSection(io::IXMLReaderUTF8* reader); - - //! reads a section and its content - //! if a prefab pointer is passed the nodes are created as scene prefabs children of that prefab - void readNodeSection(io::IXMLReaderUTF8* reader, scene::ISceneNode* parent, CScenePrefab* p=0); - - //! reads a element and its content and creates a matrix from it - core::matrix4 readLookAtNode(io::IXMLReaderUTF8* reader); - - //! reads a element and its content and creates a matrix from it - core::matrix4 readMatrixNode(io::IXMLReaderUTF8* reader); - - //! reads a element and its content and creates a matrix from it - core::matrix4 readPerspectiveNode(io::IXMLReaderUTF8* reader); - - //! reads a element and its content and creates a matrix from it - core::matrix4 readRotateNode(io::IXMLReaderUTF8* reader); - - //! reads a element and its content and creates a matrix from it - core::matrix4 readSkewNode(io::IXMLReaderUTF8* reader); - - //! reads a element and its content and stores it in bbox - void readBboxNode(io::IXMLReaderUTF8* reader, core::aabbox3df& bbox); - - //! reads a element and its content and creates a matrix from it - core::matrix4 readScaleNode(io::IXMLReaderUTF8* reader); - - //! reads a element and its content and creates a matrix from it - core::matrix4 readTranslateNode(io::IXMLReaderUTF8* reader); - - //! reads a element - video::SColorf readColorNode(io::IXMLReaderUTF8* reader); - - //! reads a element - f32 readFloatNode(io::IXMLReaderUTF8* reader); - - //! reads a node - void readInstanceNode(io::IXMLReaderUTF8* reader, - scene::ISceneNode* parent, scene::ISceneNode** outNode, - CScenePrefab* p=0, const core::stringc& type=core::stringc()); - - //! creates a scene node from Prefabs (with name given in 'url') - void instantiateNode(scene::ISceneNode* parent, scene::ISceneNode** outNode=0, - CScenePrefab* p=0, const core::stringc& url="", - const core::stringc& type=core::stringc()); - - //! reads a element and stores it as prefab - void readLightPrefab(io::IXMLReaderUTF8* reader); - - //! reads a element and stores it as prefab - void readCameraPrefab(io::IXMLReaderUTF8* reader); - - //! reads a element and stores it in the image section - void readImage(io::IXMLReaderUTF8* reader); - - //! reads a element and stores it in the texture section - void readTexture(io::IXMLReaderUTF8* reader); - - //! reads a element and stores it in the material section - void readMaterial(io::IXMLReaderUTF8* reader); - - //! reads a element and stores it in the effects section - void readEffect(io::IXMLReaderUTF8* reader, SColladaEffect * effect = 0); - - //! reads a element and stores it as mesh if possible - void readGeometry(io::IXMLReaderUTF8* reader); - - //! parses a float from a char pointer and moves the pointer to - //! the end of the parsed float - inline f32 readFloat(const c8** p); - - //! parses an int from a char pointer and moves the pointer to - //! the end of the parsed float - inline s32 readInt(const c8** p); - - //! places pointer to next begin of a token - void findNextNoneWhiteSpace(const c8** p); - - //! reads floats from inside of xml element until end of xml element - void readFloatsInsideElement(io::IXMLReaderUTF8* reader, f32* floats, u32 count); - - //! reads ints from inside of xml element until end of xml element - void readIntsInsideElement(io::IXMLReaderUTF8* reader, s32* ints, u32 count); - - //! clears all loaded data - void clearData(); - - //! parses all collada parameters inside an element and stores them in ColladaParameters - void readColladaParameters(io::IXMLReaderUTF8* reader, const core::stringc& parentName); - - //! returns a collada parameter or none if not found - SColladaParam* getColladaParameter(ECOLLADA_PARAM_NAME name); - - //! parses all collada inputs inside an element and stores them in Inputs. Reads - //! until first tag which is not an input tag or the end of the parent is reached - void readColladaInputs(io::IXMLReaderUTF8* reader, const core::stringc& parentName); - - //! reads a collada input tag and adds it to the input parameter - void readColladaInput(io::IXMLReaderUTF8* reader, core::array& inputs); - - //! returns a collada input or none if not found - SColladaInput* getColladaInput(ECOLLADA_INPUT_SEMANTIC input); - - //! read Collada Id, uses id or name if id is missing - core::stringc readId(io::IXMLReaderUTF8* reader); - - //! changes the XML URI into an internal id - void uriToId(core::stringc& str); - - //! reads a polygons section and creates a mesh from it - void readPolygonSection(io::IXMLReaderUTF8* reader, - core::array& sources, scene::SMesh* mesh, - const core::stringc& geometryId); - - //! finds a material, possible instancing it - const SColladaMaterial * findMaterial(const core::stringc & materialName); - - //! reads and bind materials as given by the symbol->target bind mapping - void readBindMaterialSection(io::IXMLReaderUTF8* reader, const core::stringc & id); - - //! create an Irrlicht texture from the SColladaImage - video::ITexture* getTextureFromImage(core::stringc uri, SColladaEffect * effect); - - //! read a parameter and value - void readParameter(io::IXMLReaderUTF8* reader, io::IAttributes* parameters); - - //! Flip z axis in matrix around to convert between right-handed and left-handed coordinate system. - //! Note that function is symmetric (no difference if called before or after a transpose). - core::matrix4 flipZAxis(const core::matrix4& m); - - //! replace escape characters with the unescaped ones - void unescape(irr::core::stringc& uri); - - scene::ISceneManager* SceneManager; - io::IFileSystem* FileSystem; - - scene::IAnimatedMesh* DummyMesh; - core::stringc CurrentlyLoadingMesh; - - scene::IAnimatedMesh* FirstLoadedMesh; - io::path FirstLoadedMeshName; - s32 LoadedMeshCount; - u32 Version; - bool FlipAxis; - - core::array Prefabs; - core::array ColladaParameters; - core::array Images; - core::array Textures; - core::array Materials; - core::array Inputs; - core::array Effects; - //! meshbuffer reference ("geomid/matname") -> index into MeshesToBind - core::map MaterialsToBind; - //! Array of buffers for each material binding - core::array< core::array > MeshesToBind; - - bool CreateInstances; - - struct EscapeCharacterURL - { - EscapeCharacterURL(irr::c8 c, const irr::c8* e) - : Character(c) - { - Escape = e; - } - - irr::c8 Character; // unescaped (like ' ') - irr::core::stringc Escape; // escaped (like '%20') - }; - irr::core::array EscapeCharsAnyURI; -}; - - - -//! following class is for holding and createing instances of library objects, -//! named prefabs in this loader. -class IColladaPrefab : public virtual IReferenceCounted -{ -public: - //! creates an instance of this prefab - virtual scene::ISceneNode* addInstance(scene::ISceneNode* parent, - scene::ISceneManager* mgr) = 0; - - //! returns id of this prefab - virtual const core::stringc& getId() = 0; -}; - - -} // end namespace scene -} // end namespace irr - -#endif - diff --git a/source/Irrlicht/CColladaMeshWriter.cpp b/source/Irrlicht/CColladaMeshWriter.cpp deleted file mode 100644 index 52653a0..0000000 --- a/source/Irrlicht/CColladaMeshWriter.cpp +++ /dev/null @@ -1,2309 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -// TODO: second UV-coordinates currently ignored in textures - -#include "IrrCompileConfig.h" - -#ifdef _IRR_COMPILE_WITH_COLLADA_WRITER_ - -#include "CColladaMeshWriter.h" -#include "os.h" -#include "IFileSystem.h" -#include "IWriteFile.h" -#include "IXMLWriter.h" -#include "IMesh.h" -#include "IAttributes.h" -#include "IAnimatedMeshSceneNode.h" -#include "IMeshSceneNode.h" -#include "ITerrainSceneNode.h" -#include "ILightSceneNode.h" -#include "ICameraSceneNode.h" -#include "ISceneManager.h" - -namespace irr -{ -namespace scene -{ - -//! Which lighting model should be used in the technique (FX) section when exporting effects (materials) -E_COLLADA_TECHNIQUE_FX CColladaMeshWriterProperties::getTechniqueFx(const video::SMaterial& material) const -{ - return ECTF_BLINN; -} - -//! Which texture index should be used when writing the texture of the given sampler color. -s32 CColladaMeshWriterProperties::getTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const -{ - // So far we just export in a way which is similar to how we import colladas. - // There might be better ways to do this, but I suppose it depends a lot for which target - // application we export, so in most cases it will have to be done in user-code anyway. - switch ( cs ) - { - case ECCS_DIFFUSE: - return 2; - case ECCS_AMBIENT: - return 1; - case ECCS_EMISSIVE: - return 0; - case ECCS_SPECULAR: - return 3; - case ECCS_TRANSPARENT: - return -1; - case ECCS_REFLECTIVE: - return -1; - }; - return -1; -} - -E_COLLADA_IRR_COLOR CColladaMeshWriterProperties::getColorMapping(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const -{ - switch ( cs ) - { - case ECCS_DIFFUSE: - return ECIC_DIFFUSE; - case ECCS_AMBIENT: - return ECIC_AMBIENT; - case ECCS_EMISSIVE: - return ECIC_EMISSIVE; - case ECCS_SPECULAR: - return ECIC_SPECULAR; - case ECCS_TRANSPARENT: - return ECIC_NONE; - case ECCS_REFLECTIVE: - return ECIC_CUSTOM; - }; - - return ECIC_NONE; -} - -//! Return custom colors for certain color types requested by collada. -video::SColor CColladaMeshWriterProperties::getCustomColor(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) const -{ - return video::SColor(255, 0, 0, 0); -} - - -//! Return the settings for transparence -E_COLLADA_TRANSPARENT_FX CColladaMeshWriterProperties::getTransparentFx(const video::SMaterial& material) const -{ - // TODO: figure out best default mapping - return ECOF_A_ONE; -} - -//! Transparency value for the material. -f32 CColladaMeshWriterProperties::getTransparency(const video::SMaterial& material) const -{ - // TODO: figure out best default mapping - return -1.f; -} - -//! Reflectivity value for that material -f32 CColladaMeshWriterProperties::getReflectivity(const video::SMaterial& material) const -{ - // TODO: figure out best default mapping - return 0.f; -} - -//! Return index of refraction for that material -f32 CColladaMeshWriterProperties::getIndexOfRefraction(const video::SMaterial& material) const -{ - return -1.f; -} - -bool CColladaMeshWriterProperties::isExportable(const irr::scene::ISceneNode * node) const -{ - return node && node->isVisible(); -} - -IMesh* CColladaMeshWriterProperties::getMesh(irr::scene::ISceneNode * node) -{ - if ( !node ) - return 0; - if ( node->getType() == ESNT_ANIMATED_MESH ) - return static_cast(node)->getMesh()->getMesh(0); - // TODO: we need some ISceneNode::hasType() function to get rid of those checks - if ( node->getType() == ESNT_MESH - || node->getType() == ESNT_CUBE - || node->getType() == ESNT_SPHERE - || node->getType() == ESNT_WATER_SURFACE - || node->getType() == ESNT_Q3SHADER_SCENE_NODE - ) - return static_cast(node)->getMesh(); - if ( node->getType() == ESNT_TERRAIN ) - return static_cast(node)->getMesh(); - return 0; -} - -// Check if the node has it's own material overwriting the mesh-materials -bool CColladaMeshWriterProperties::useNodeMaterial(const scene::ISceneNode* node) const -{ - if ( !node ) - return false; - - // TODO: we need some ISceneNode::hasType() function to get rid of those checks - bool useMeshMaterial = ( (node->getType() == ESNT_MESH || - node->getType() == ESNT_CUBE || - node->getType() == ESNT_SPHERE || - node->getType() == ESNT_WATER_SURFACE || - node->getType() == ESNT_Q3SHADER_SCENE_NODE) - && static_cast(node)->isReadOnlyMaterials()) - - || (node->getType() == ESNT_ANIMATED_MESH - && static_cast(node)->isReadOnlyMaterials() ); - - return !useMeshMaterial; -} - - - -CColladaMeshWriterNames::CColladaMeshWriterNames(IColladaMeshWriter * writer) - : ColladaMeshWriter(writer) -{ -} - -irr::core::stringc CColladaMeshWriterNames::nameForMesh(const scene::IMesh* mesh, int instance) -{ - irr::core::stringc name("mesh"); - name += nameForPtr(mesh); - if ( instance > 0 ) - { - name += "i"; - name += irr::core::stringc(instance); - } - return ColladaMeshWriter->toNCName(name); -} - -irr::core::stringc CColladaMeshWriterNames::nameForNode(const scene::ISceneNode* node) -{ - irr::core::stringc name; - // Prefix, because xs:ID can't start with a number, also nicer name - if ( node && node->getType() == ESNT_LIGHT ) - name = "light"; - else - name = "node"; - name += nameForPtr(node); - if ( node ) - { - name += irr::core::stringc(node->getName()); - } - return ColladaMeshWriter->toNCName(name); -} - -irr::core::stringc CColladaMeshWriterNames::nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) -{ - core::stringc strMat("mat"); - - bool nodeMaterial = ColladaMeshWriter->getProperties()->useNodeMaterial(node); - if ( nodeMaterial ) - { - strMat += "node"; - strMat += nameForPtr(node); - strMat += irr::core::stringc(node->getName()); - } - strMat += "mesh"; - strMat += nameForPtr(mesh); - strMat += materialId; - return ColladaMeshWriter->toNCName(strMat); -} - -irr::core::stringc CColladaMeshWriterNames::nameForPtr(const void* ptr) const -{ - c8 buf[32]; - snprintf_irr(buf, 32, "%p", ptr); - return irr::core::stringc(buf); -} - - - -CColladaMeshWriter::CColladaMeshWriter( ISceneManager * smgr, video::IVideoDriver* driver, - io::IFileSystem* fs) - : FileSystem(fs), VideoDriver(driver), Writer(0) -{ - - #ifdef _DEBUG - setDebugName("CColladaMeshWriter"); - #endif - - if (VideoDriver) - VideoDriver->grab(); - - if (FileSystem) - FileSystem->grab(); - - if ( smgr ) - setAmbientLight( smgr->getAmbientLight() ); - - // Escape some characters - // Slightly fuzzy definition for xs:anyURI. - // In theory not even spaces would need to be escaped, - // but it's strongly encouraged to do so and many Apps rely on it. - // If there are any apps out there which need more escapes we can add them. - // See https://www.w3schools.com/tags/ref_urlencode.asp for a list. - // NOTE: Never replace by empty characters (so not the place to delete chars!) - EscapeCharsAnyURI.push_back(EscapeCharacterURL(' ', "%20")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('#', "%23")); - EscapeCharsAnyURI.push_back(EscapeCharacterURL('%', "%25")); - - CColladaMeshWriterProperties * p = new CColladaMeshWriterProperties(); - setDefaultProperties(p); - setProperties(p); - p->drop(); - - CColladaMeshWriterNames * nameGenerator = new CColladaMeshWriterNames(this); - setDefaultNameGenerator(nameGenerator); - setNameGenerator(nameGenerator); - nameGenerator->drop(); -} - - -CColladaMeshWriter::~CColladaMeshWriter() -{ - if (VideoDriver) - VideoDriver->drop(); - - if (FileSystem) - FileSystem->drop(); -} - - -void CColladaMeshWriter::reset() -{ - LibraryImages.clear(); - Meshes.clear(); - LightNodes.clear(); - CameraNodes.clear(); - MaterialsWritten.clear(); - EffectsWritten.clear(); - MaterialNameCache.clear(); -} - -//! Returns the type of the mesh writer -EMESH_WRITER_TYPE CColladaMeshWriter::getType() const -{ - return EMWT_COLLADA; -} - -//! writes a scene starting with the given node -bool CColladaMeshWriter::writeScene(io::IWriteFile* file, scene::ISceneNode* root, int writeRoot) -{ - if (!file || !root) - return false; - - reset(); - - Writer = FileSystem->createXMLWriterUTF8(file); - - if (!Writer) - { - os::Printer::log("Could not write file", file->getFileName()); - return false; - } - - Directory = FileSystem->getFileDir(FileSystem->getAbsolutePath( file->getFileName() )); - - // make names for all nodes with exportable meshes - makeMeshNames(root); - - os::Printer::log("Writing scene", file->getFileName()); - - // write COLLADA header - - Writer->writeXMLHeader(); - - Writer->writeElement("COLLADA", false, - "xmlns", "http://www.collada.org/2005/11/COLLADASchema", - "version", "1.4.1"); - Writer->writeLineBreak(); - - // write asset data - writeAsset(); - - // write all materials - Writer->writeElement("library_materials", false); - Writer->writeLineBreak(); - writeNodeMaterials(root); - Writer->writeClosingTag("library_materials"); - Writer->writeLineBreak(); - - Writer->writeElement("library_effects", false); - Writer->writeLineBreak(); - writeNodeEffects(root); - Writer->writeClosingTag("library_effects"); - Writer->writeLineBreak(); - - - // images - writeLibraryImages(); - - // lights - Writer->writeElement("library_lights", false); - Writer->writeLineBreak(); - - writeAmbientLightElement( getAmbientLight() ); - writeNodeLights(root); - - Writer->writeClosingTag("library_lights"); - Writer->writeLineBreak(); - - // cameras - Writer->writeElement("library_cameras", false); - Writer->writeLineBreak(); - writeNodeCameras(root); - Writer->writeClosingTag("library_cameras"); - Writer->writeLineBreak(); - - // write meshes - Writer->writeElement("library_geometries", false); - Writer->writeLineBreak(); - writeAllMeshGeometries(); - Writer->writeClosingTag("library_geometries"); - Writer->writeLineBreak(); - - // write scene - Writer->writeElement("library_visual_scenes", false); - Writer->writeLineBreak(); - Writer->writeElement("visual_scene", false, "id", "default_scene"); - Writer->writeLineBreak(); - - // ambient light (instance_light also needs a node as parent so we have to create one) - Writer->writeElement("node", false); - Writer->writeLineBreak(); - Writer->writeElement("instance_light", true, "url", "#ambientlight"); - Writer->writeLineBreak(); - Writer->writeClosingTag("node"); - Writer->writeLineBreak(); - - // Write the scenegraph. - if ( writeRoot == 2 || (writeRoot == 1 && root->getType() != ESNT_SCENE_MANAGER) ) - { - // TODO: Not certain if we should really write the root or if we should just always only write the children. - // For now writing root to keep backward compatibility for this case, but if anyone needs to _not_ write - // that root-node we can add a parameter for this later on in writeScene. - writeSceneNode(root); - } - else - { - // The visual_scene element is identical to our scenemanager and acts as root, - // so we do not write the root itself if it points to the scenemanager. - const core::list& rootChildren = root->getChildren(); - for ( core::list::ConstIterator it = rootChildren.begin(); - it != rootChildren.end(); - ++ it ) - { - writeSceneNode(*it); - } - } - - - Writer->writeClosingTag("visual_scene"); - Writer->writeLineBreak(); - Writer->writeClosingTag("library_visual_scenes"); - Writer->writeLineBreak(); - - - // instance scene - Writer->writeElement("scene", false); - Writer->writeLineBreak(); - - Writer->writeElement("instance_visual_scene", true, "url", "#default_scene"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("scene"); - Writer->writeLineBreak(); - - - // close everything - - Writer->writeClosingTag("COLLADA"); - Writer->drop(); - - return true; -} - -void CColladaMeshWriter::makeMeshNames(irr::scene::ISceneNode * node) -{ - if ( !node || !getProperties() || !getProperties()->isExportable(node) || !getNameGenerator()) - return; - - IMesh* mesh = getProperties()->getMesh(node); - if ( mesh ) - { - if ( !Meshes.find(mesh) ) - { - SColladaMesh cm; - cm.Name = nameForMesh(mesh, 0); - Meshes.insert(mesh, cm); - } - } - - const core::list& children = node->getChildren(); - for ( core::list::ConstIterator it = children.begin(); it != children.end(); ++it ) - { - makeMeshNames(*it); - } -} - -void CColladaMeshWriter::writeNodeMaterials(irr::scene::ISceneNode * node) -{ - if ( !node || !getProperties() || !getProperties()->isExportable(node) ) - return; - - core::array materialNames; - - IMesh* mesh = getProperties()->getMesh(node); - if ( mesh ) - { - MeshNode * n = Meshes.find(mesh); - if ( !getProperties()->useNodeMaterial(node) ) - { - // no material overrides - write mesh materials - if ( n && !n->getValue().MaterialsWritten ) - { - writeMeshMaterials(mesh, getGeometryWriting() == ECGI_PER_MESH_AND_MATERIAL ? &materialNames : NULL); - n->getValue().MaterialsWritten = true; - } - } - else - { - // write node materials - for (u32 i=0; igetMaterialCount(); ++i) - { - video::SMaterial & material = node->getMaterial(i); - core::stringc strMat(nameForMaterial(material, i, mesh, node)); - writeMaterial(strMat); - if ( getGeometryWriting() == ECGI_PER_MESH_AND_MATERIAL ) - materialNames.push_back(strMat); - } - } - - // When we write another mesh-geometry for each new material-list we have - // to figure out here if we need another geometry copy and create a new name here. - if ( n && getGeometryWriting() == ECGI_PER_MESH_AND_MATERIAL ) - { - SGeometryMeshMaterials * geomMat = n->getValue().findGeometryMeshMaterials(materialNames); - if ( geomMat ) - geomMat->MaterialOwners.push_back(node); - else - { - SGeometryMeshMaterials gmm; - if ( n->getValue().GeometryMeshMaterials.empty() ) - gmm.GeometryName = n->getValue().Name; // first one can use the original name - else - gmm.GeometryName = nameForMesh(mesh, n->getValue().GeometryMeshMaterials.size()); - gmm.MaterialNames = materialNames; - gmm.MaterialOwners.push_back(node); - n->getValue().GeometryMeshMaterials.push_back(gmm); - } - } - } - - const core::list& children = node->getChildren(); - for ( core::list::ConstIterator it = children.begin(); it != children.end(); ++it ) - { - writeNodeMaterials( *it ); - } -} - -void CColladaMeshWriter::writeMaterial(const irr::core::stringc& materialname) -{ - if ( MaterialsWritten.find(materialname) ) - return; - MaterialsWritten.insert(materialname, true); - - Writer->writeElement("material", false, - "id", materialname.c_str(), - "name", materialname.c_str()); - Writer->writeLineBreak(); - - // We don't make a difference between material and effect on export. - // Every material is just using an instance of an effect. - core::stringc strFx(materialname); - strFx += "-fx"; - Writer->writeElement("instance_effect", true, - "url", (core::stringc("#") + strFx).c_str()); - Writer->writeLineBreak(); - - Writer->writeClosingTag("material"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeNodeEffects(irr::scene::ISceneNode * node) -{ - if ( !node || !getProperties() || !getProperties()->isExportable(node) || !getNameGenerator() ) - return; - - IMesh* mesh = getProperties()->getMesh(node); - if ( mesh ) - { - if ( !getProperties()->useNodeMaterial(node) ) - { - // no material overrides - write mesh materials - MeshNode * n = Meshes.find(mesh); - if ( n && !n->getValue().EffectsWritten ) - { - writeMeshEffects(mesh); - n->getValue().EffectsWritten = true; - } - } - else - { - // write node materials - for (u32 i=0; igetMaterialCount(); ++i) - { - video::SMaterial & material = node->getMaterial(i); - irr::core::stringc materialfxname(nameForMaterial(material, i, mesh, node)); - materialfxname += "-fx"; - writeMaterialEffect(materialfxname, material); - } - } - } - - const core::list& children = node->getChildren(); - for ( core::list::ConstIterator it = children.begin(); it != children.end(); ++it ) - { - writeNodeEffects( *it ); - } -} - -void CColladaMeshWriter::writeNodeLights(irr::scene::ISceneNode * node) -{ - if ( !node || !getProperties() || !getProperties()->isExportable(node)) - return; - - if ( node->getType() == ESNT_LIGHT ) - { - ILightSceneNode * lightNode = static_cast(node); - const video::SLight& lightData = lightNode->getLightData(); - - SColladaLight cLight; - cLight.Name = nameForNode(node); - LightNodes.insert(node, cLight); - - Writer->writeElement("light", false, "id", cLight.Name.c_str()); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - switch ( lightNode->getLightType() ) - { - case video::ELT_POINT: - Writer->writeElement("point", false); - Writer->writeLineBreak(); - - writeColorElement(lightData.DiffuseColor, false); - writeNode("constant_attenuation ", core::stringc(lightData.Attenuation.X).c_str()); - writeNode("linear_attenuation ", core::stringc(lightData.Attenuation.Y).c_str()); - writeNode("quadratic_attenuation", core::stringc(lightData.Attenuation.Z).c_str()); - - Writer->writeClosingTag("point"); - Writer->writeLineBreak(); - break; - - case video::ELT_SPOT: - Writer->writeElement("spot", false); - Writer->writeLineBreak(); - - writeColorElement(lightData.DiffuseColor, false); - - writeNode("constant_attenuation ", core::stringc(lightData.Attenuation.X).c_str()); - writeNode("linear_attenuation ", core::stringc(lightData.Attenuation.Y).c_str()); - writeNode("quadratic_attenuation", core::stringc(lightData.Attenuation.Z).c_str()); - - writeNode("falloff_angle", core::stringc(lightData.OuterCone * core::RADTODEG).c_str()); - writeNode("falloff_exponent", core::stringc(lightData.Falloff).c_str()); - - Writer->writeClosingTag("spot"); - Writer->writeLineBreak(); - break; - - case video::ELT_DIRECTIONAL: - Writer->writeElement("directional", false); - Writer->writeLineBreak(); - - writeColorElement(lightData.DiffuseColor, false); - - Writer->writeClosingTag("directional"); - Writer->writeLineBreak(); - break; - default: - break; - } - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("light"); - Writer->writeLineBreak(); - - } - - const core::list& children = node->getChildren(); - for ( core::list::ConstIterator it = children.begin(); it != children.end(); ++it ) - { - writeNodeLights( *it ); - } -} - -void CColladaMeshWriter::writeNodeCameras(irr::scene::ISceneNode * node) -{ - if ( !node || !getProperties() || !getProperties()->isExportable(node) ) - return; - - if ( isCamera(node) ) - { - ICameraSceneNode * cameraNode = static_cast(node); - irr::core::stringc name = nameForNode(node); - CameraNodes.insert(cameraNode, name); - - Writer->writeElement("camera", false, "id", name.c_str()); - Writer->writeLineBreak(); - - Writer->writeElement("optics", false); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - if ( cameraNode->isOrthogonal() ) - { - Writer->writeElement("orthographic", false); - Writer->writeLineBreak(); - - irr::core::matrix4 projMat( cameraNode->getProjectionMatrix() ); - irr::f32 xmag = 2.f/projMat[0]; - irr::f32 ymag = 2.f/projMat[5]; - - // Note that Irrlicht camera does not update near/far when setting the projection matrix, - // so we have to calculate that here (at least currently - maybe camera code will be updated at some time). - irr::f32 nearMinusFar = -1.f/projMat[10]; - irr::f32 zNear = projMat[14]*nearMinusFar; - irr::f32 zFar = 1.f/projMat[10] + zNear; - - writeNode("xmag", core::stringc(xmag).c_str()); - writeNode("ymag", core::stringc(ymag).c_str()); - writeNode("znear", core::stringc(zNear).c_str()); - writeNode("zfar", core::stringc(zFar).c_str()); - - Writer->writeClosingTag("orthographic"); - Writer->writeLineBreak(); - } - else - { - Writer->writeElement("perspective", false); - Writer->writeLineBreak(); - - writeNode("yfov", core::stringc(cameraNode->getFOV()*core::RADTODEG).c_str()); - writeNode("aspect_ratio", core::stringc(cameraNode->getAspectRatio()).c_str()); - writeNode("znear", core::stringc(cameraNode->getNearValue()).c_str()); - writeNode("zfar", core::stringc(cameraNode->getFarValue()).c_str()); - - Writer->writeClosingTag("perspective"); - Writer->writeLineBreak(); - } - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("optics"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("camera"); - Writer->writeLineBreak(); - } - - const core::list& children = node->getChildren(); - for ( core::list::ConstIterator it = children.begin(); it != children.end(); ++it ) - { - writeNodeCameras( *it ); - } -} - -void CColladaMeshWriter::writeAllMeshGeometries() -{ - core::map::ConstIterator it = Meshes.getConstIterator(); - for(; !it.atEnd(); it++ ) - { - IMesh* mesh = it->getKey(); - const SColladaMesh& colladaMesh = it->getValue(); - - if ( getGeometryWriting() == ECGI_PER_MESH_AND_MATERIAL && colladaMesh.GeometryMeshMaterials.size() > 1 ) - { - for ( u32 i=0; iisExportable(node) ) - return; - - // Collada doesn't require to set the id, but some other tools have problems if none exists, so we just add it. - irr::core::stringc nameId(nameForNode(node)); - Writer->writeElement("node", false, "id", nameId.c_str()); - Writer->writeLineBreak(); - - // DummyTransformationSceneNode don't have rotation, position, scale information - // But also don't always export the transformation matrix as that forces us creating - // new DummyTransformationSceneNode's on import. - if ( node->getType() == ESNT_DUMMY_TRANSFORMATION ) - { - writeMatrixElement(node->getRelativeTransformation()); - } - else if ( isCamera(node) ) - { - // TODO: We do not handle the case when ICameraSceneNode::getTargetAndRotationBinding() is false. Probably we would have to create a second - // node to do that. - - // Note: We can't use rotations for the camera as Irrlicht does not regard the up-vector in rotations so far. - // We could maybe use projection matrices, but avoiding them might allow us to get rid of some DummyTransformationSceneNodes on - // import in the future. So that's why we use the lookat element instead. - - ICameraSceneNode * camNode = static_cast(node); - writeLookAtElement(camNode->getPosition(), camNode->getTarget(), camNode->getUpVector()); - } - else - { - writeTranslateElement( node->getPosition() ); - - irr::core::vector3df rot(node->getRotation()); - core::quaternion quat(rot*core::DEGTORAD); - f32 angle; - core::vector3df axis; - quat.toAngleAxis(angle, axis); - writeRotateElement( axis, angle*core::RADTODEG ); - - writeScaleElement( node->getScale() ); - } - - // instance geometry - IMesh* mesh = getProperties()->getMesh(node); - if ( mesh ) - { - MeshNode * n = Meshes.find(mesh); - if ( n ) - { - const SColladaMesh& colladaMesh = n->getValue(); - writeMeshInstanceGeometry(colladaMesh.findGeometryNameForNode(node), mesh, node); - } - } - - // instance light - if ( node->getType() == ESNT_LIGHT ) - { - LightNode * n = LightNodes.find(node); - if ( n ) - writeLightInstance(n->getValue().Name); - } - - // instance camera - if ( isCamera(node) ) - { - CameraNode * camNode = CameraNodes.find(node); - if ( camNode ) - writeCameraInstance(camNode->getValue()); - } - - const core::list& children = node->getChildren(); - for ( core::list::ConstIterator it = children.begin(); it != children.end(); ++it ) - { - writeSceneNode( *it ); - } - - Writer->writeClosingTag("node"); - Writer->writeLineBreak(); -} - -//! writes a mesh -bool CColladaMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags) -{ - if (!file) - return false; - - reset(); - - Writer = FileSystem->createXMLWriterUTF8(file); - - if (!Writer) - { - os::Printer::log("Could not write file", file->getFileName()); - return false; - } - - Directory = FileSystem->getFileDir(FileSystem->getAbsolutePath( file->getFileName() )); - - os::Printer::log("Writing mesh", file->getFileName()); - - // write COLLADA header - - Writer->writeXMLHeader(); - - Writer->writeElement("COLLADA", false, - "xmlns", "http://www.collada.org/2005/11/COLLADASchema", - "version", "1.4.1"); - Writer->writeLineBreak(); - - // write asset data - writeAsset(); - - // write all materials - - Writer->writeElement("library_materials", false); - Writer->writeLineBreak(); - - writeMeshMaterials(mesh); - - Writer->writeClosingTag("library_materials"); - Writer->writeLineBreak(); - - Writer->writeElement("library_effects", false); - Writer->writeLineBreak(); - - writeMeshEffects(mesh); - - Writer->writeClosingTag("library_effects"); - Writer->writeLineBreak(); - - // images - writeLibraryImages(); - - // write mesh - - Writer->writeElement("library_geometries", false); - Writer->writeLineBreak(); - - irr::core::stringc meshname(nameForMesh(mesh, 0)); - writeMeshGeometry(meshname, mesh); - - Writer->writeClosingTag("library_geometries"); - Writer->writeLineBreak(); - - // write scene_library - if ( getWriteDefaultScene() ) - { - Writer->writeElement("library_visual_scenes", false); - Writer->writeLineBreak(); - - Writer->writeElement("visual_scene", false, "id", "default_scene"); - Writer->writeLineBreak(); - - Writer->writeElement("node", false); - Writer->writeLineBreak(); - - writeMeshInstanceGeometry(meshname, mesh); - - Writer->writeClosingTag("node"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("visual_scene"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("library_visual_scenes"); - Writer->writeLineBreak(); - - - // write scene - Writer->writeElement("scene", false); - Writer->writeLineBreak(); - - Writer->writeElement("instance_visual_scene", true, "url", "#default_scene"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("scene"); - Writer->writeLineBreak(); - } - - - // close everything - - Writer->writeClosingTag("COLLADA"); - Writer->drop(); - - return true; -} - -void CColladaMeshWriter::writeMeshInstanceGeometry(const irr::core::stringc& meshname, scene::IMesh* mesh, scene::ISceneNode* node) -{ - // - Writer->writeElement("instance_geometry", false, "url", toRef(meshname).c_str()); - Writer->writeLineBreak(); - - Writer->writeElement("bind_material", false); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - // instance materials - // - bool useNodeMaterials = node && node->getMaterialCount() == mesh->getMeshBufferCount(); - for (u32 i=0; igetMeshBufferCount(); ++i) - { - irr::core::stringc strMatSymbol(nameForMaterialSymbol(mesh, i)); - core::stringc strMatTarget = "#"; - video::SMaterial & material = useNodeMaterials ? node->getMaterial(i) : mesh->getMeshBuffer(i)->getMaterial(); - strMatTarget += nameForMaterial(material, i, mesh, node); - Writer->writeElement("instance_material", false, "symbol", strMatSymbol.c_str(), "target", strMatTarget.c_str()); - Writer->writeLineBreak(); - - // TODO: need to handle second UV-set - // - Writer->writeElement("bind_vertex_input", true, "semantic", "uv", "input_semantic", "TEXCOORD", "input_set", "0" ); - Writer->writeLineBreak(); - - Writer->writeClosingTag("instance_material"); - Writer->writeLineBreak(); - } - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("bind_material"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("instance_geometry"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeLightInstance(const irr::core::stringc& lightName) -{ - Writer->writeElement("instance_light", true, "url", toRef(lightName).c_str()); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeCameraInstance(const irr::core::stringc& cameraName) -{ - Writer->writeElement("instance_camera", true, "url", toRef(cameraName).c_str()); - Writer->writeLineBreak(); -} - -bool CColladaMeshWriter::hasSecondTextureCoordinates(video::E_VERTEX_TYPE type) const -{ - return type == video::EVT_2TCOORDS; -} - -void CColladaMeshWriter::writeVector(const irr::core::vector3df& vec) -{ - c8 tmpbuf[255]; - - snprintf_irr(tmpbuf, 255, "%f", vec.X); - WriteBuffer = tmpbuf; - WriteBuffer.eraseTrailingFloatZeros(); - - snprintf_irr(tmpbuf, 255, " %f", vec.Y); - WriteBuffer.append(tmpbuf); - WriteBuffer.eraseTrailingFloatZeros(); - - snprintf_irr(tmpbuf, 255, " %f", vec.Z*-1.f); // change handedness - WriteBuffer.append(tmpbuf); - WriteBuffer.eraseTrailingFloatZeros(); - - Writer->writeText(WriteBuffer.c_str()); -} - -void CColladaMeshWriter::writeUv(const irr::core::vector2df& vec) -{ - c8 tmpbuf[255]; - - snprintf_irr(tmpbuf, 255, "%f", vec.X); - WriteBuffer = tmpbuf; - WriteBuffer.eraseTrailingFloatZeros(); - - snprintf_irr(tmpbuf, 255, " %f", 1.f-vec.Y); // change handedness - WriteBuffer.append(tmpbuf); - WriteBuffer.eraseTrailingFloatZeros(); - - Writer->writeText(WriteBuffer.c_str()); -} - -void CColladaMeshWriter::writeColor(const irr::video::SColorf& colorf, bool writeAlpha) -{ - c8 tmpbuf[255]; - - snprintf_irr(tmpbuf, 255, "%f", colorf.getRed()); - WriteBuffer = tmpbuf; - WriteBuffer.eraseTrailingFloatZeros(); - - snprintf_irr(tmpbuf, 255, " %f", colorf.getGreen()); - WriteBuffer.append(tmpbuf); - WriteBuffer.eraseTrailingFloatZeros(); - - snprintf_irr(tmpbuf, 255, " %f", colorf.getBlue()); - WriteBuffer.append(tmpbuf); - WriteBuffer.eraseTrailingFloatZeros(); - - if ( writeAlpha ) - { - snprintf_irr(tmpbuf, 255, " %f", colorf.getAlpha()); - WriteBuffer.append(tmpbuf); - WriteBuffer.eraseTrailingFloatZeros(); - } - - Writer->writeText(WriteBuffer.c_str()); -} - -irr::core::stringc CColladaMeshWriter::toString(const irr::video::ECOLOR_FORMAT format) const -{ - switch ( format ) - { - case video::ECF_A1R5G5B5: return irr::core::stringc("A1R5G5B5"); - case video::ECF_R5G6B5: return irr::core::stringc("R5G6B5"); - case video::ECF_R8G8B8: return irr::core::stringc("R8G8B8"); - case video::ECF_A8R8G8B8: return irr::core::stringc("A8R8G8B8"); - default: return irr::core::stringc(""); - } -} - -irr::core::stringc CColladaMeshWriter::toString(const irr::video::E_TEXTURE_CLAMP clamp) const -{ - switch ( clamp ) - { - case video::ETC_REPEAT: - return core::stringc("WRAP"); - case video::ETC_CLAMP: - case video::ETC_CLAMP_TO_EDGE: - return core::stringc("CLAMP"); - case video::ETC_CLAMP_TO_BORDER: - return core::stringc("BORDER"); - case video::ETC_MIRROR: - case video::ETC_MIRROR_CLAMP: - case video::ETC_MIRROR_CLAMP_TO_EDGE: - case video::ETC_MIRROR_CLAMP_TO_BORDER: - return core::stringc("MIRROR"); - } - return core::stringc("NONE"); -} - -irr::core::stringc CColladaMeshWriter::toString(const irr::scene::E_COLLADA_TRANSPARENT_FX transparent) const -{ - if ( transparent & ECOF_RGB_ZERO ) - return core::stringc("RGB_ZERO"); - else - return core::stringc("A_ONE"); -} - -irr::core::stringc CColladaMeshWriter::toRef(const irr::core::stringc& source) const -{ - irr::core::stringc ref("#"); - ref += source; - return ref; -} - -bool CColladaMeshWriter::isCamera(const scene::ISceneNode* node) const -{ - // TODO: we need some ISceneNode::hasType() function to get rid of those checks - if ( node->getType() == ESNT_CAMERA - || node->getType() == ESNT_CAMERA_MAYA - || node->getType() == ESNT_CAMERA_FPS ) - return true; - return false; -} - -irr::core::stringc CColladaMeshWriter::nameForMesh(const scene::IMesh* mesh, int instance) const -{ - IColladaMeshWriterNames * nameGenerator = getNameGenerator(); - if ( nameGenerator ) - { - return nameGenerator->nameForMesh(mesh, instance); - } - return irr::core::stringc("missing_name_generator"); -} - -irr::core::stringc CColladaMeshWriter::nameForNode(const scene::ISceneNode* node) const -{ - IColladaMeshWriterNames * nameGenerator = getNameGenerator(); - if ( nameGenerator ) - { - return nameGenerator->nameForNode(node); - } - return irr::core::stringc("missing_name_generator"); -} - -irr::core::stringc CColladaMeshWriter::nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) -{ - irr::core::stringc matName; - if ( getExportSMaterialsOnlyOnce() ) - { - matName = findCachedMaterialName(material); - if ( !matName.empty() ) - return matName; - } - - IColladaMeshWriterNames * nameGenerator = getNameGenerator(); - if ( nameGenerator ) - { - matName = nameGenerator->nameForMaterial(material, materialId, mesh, node); - } - else - matName = irr::core::stringc("missing_name_generator"); - - if ( getExportSMaterialsOnlyOnce() ) - MaterialNameCache.push_back (MaterialName(material, matName)); - return matName; -} - -// Each mesh-material has one symbol which is replaced on instantiation -irr::core::stringc CColladaMeshWriter::nameForMaterialSymbol(const scene::IMesh* mesh, int materialId) const -{ - c8 buf[100]; - snprintf_irr(buf, 100, "mat_symb_%p_%d", mesh, materialId); - return irr::core::stringc(buf); -} - -irr::core::stringc CColladaMeshWriter::findCachedMaterialName(const irr::video::SMaterial& material) const -{ - for ( u32 i=0; i= 'A' && c <= 'Z') - || c == '_' - || (c >= 'a' && c <= 'z'); - /* Following would also be legal, but only when using real unicode. - We do only check ansi codes as they are sufficient for us. - || (c >= 0xC0 && c <= 0xD6) - || (c >= 0xD8 && c <= 0xF6) - || (c >= 0xF8 && c <= 0x2FF) - || (c >= 0x370 && c <= 0x37D) - || (c >= 0x37F && c <= 0x1FFF) - || (c >= 0x200C && c <= 0x200D) - || (c >= 0x2070 && c <= 0x218F) - || (c >= 0x2C00 && c <= 0x2FEF) - || (c >= 0x3001 && c <= 0xD7FF) - || (c >= 0xF900 && c <= 0xFDCF) - || (c >= 0xFDF0 && c <= 0xFFFD) - || (c >= 0x10000 && c <=0xEFFFF) -*/ - ; -} - -bool CColladaMeshWriter::isXmlNameChar(c8 c) const -{ - return isXmlNameStartChar(c) - || c == '-' - || c == '.' - || (c >= '0' && c <= '9'); - /* Following would also be legal, but only when using real unicode. - We do only check ansi codes for now as they are sufficient for us. - || c == 0xB7 - || (c >= 9x0300 && c <= 0x036F) - || (c >= 0x203F && c <= 0x2040) - */ -} - -// Restrict the characters to a set of allowed characters in xs:NCName. -irr::core::stringc CColladaMeshWriter::toNCName(const irr::core::stringc& oldString, const irr::core::stringc& prefix) const -{ - irr::core::stringc result(prefix); // help to ensure id starts with a valid char and reduce chance of name-conflicts - if ( oldString.empty() ) - return result; - - result.append( oldString ); - - // We replace all characters not allowed by a replacement char - const c8 REPLACMENT = '-'; - for ( irr::u32 i=1; i < result.size(); ++i ) - { - if ( result[i] == ':' || !isXmlNameChar(result[i]) ) - { - result[i] = REPLACMENT; - } - } - return result; -} - -const irr::core::stringc* CColladaMeshWriter::findGeometryNameForNode(ISceneNode* node) -{ - IMesh* mesh = getProperties()->getMesh(node); - if ( !mesh ) - return NULL; - - MeshNode * n = Meshes.find(mesh); - if ( !n ) - return NULL; - - const SColladaMesh& colladaMesh = n->getValue(); - return &colladaMesh.findGeometryNameForNode(node); -} - -// Restrict the characters to a set of allowed characters in xs:anyURI -irr::core::stringc CColladaMeshWriter::pathToURI(const irr::io::path& path) const -{ - irr::core::stringc result; - - // is this a relative path? - if ( path.size() > 1 - && path[0] != _IRR_TEXT('/') - && path[0] != _IRR_TEXT('\\') - && path[1] != _IRR_TEXT(':') ) - { - // not already starting with "./" ? - if ( path[0] != _IRR_TEXT('.') - || path[1] != _IRR_TEXT('/') ) - { - result.append("./"); - } - } - result.append(path); - - // Make correct URI (without whitespace) - u32 len = result.size(); - for (u32 i=0; iwriteElement("asset", false); - Writer->writeLineBreak(); - - Writer->writeElement("contributor", false); - Writer->writeLineBreak(); - Writer->writeElement("authoring_tool", false); - Writer->writeText("Irrlicht Engine"); - Writer->writeClosingTag("authoring_tool"); - Writer->writeLineBreak(); - Writer->writeClosingTag("contributor"); - Writer->writeLineBreak(); - - // The next two are required - Writer->writeElement("created", false); - Writer->writeText("2008-01-31T00:00:00Z"); - Writer->writeClosingTag("created"); - Writer->writeLineBreak(); - - Writer->writeElement("modified", false); - Writer->writeText("2008-01-31T00:00:00Z"); - Writer->writeClosingTag("modified"); - Writer->writeLineBreak(); - - // Revision 2.0 changes (since 1.0): - // - All coordinates are now written with right-handed coordinate system. - // Before only texture V of first textures was swapped and all other - // parameters where exported left-handed. - // For specific changes change svn revision 5708. - // - authoring_tool no longer mentions IrrEdit (this code has originated - // from irrEdit 0.7) to avoid conflicts as the software is now - // independent of each other and we're not aware of irrEdit revision numbers. - Writer->writeElement("revision", false); - Writer->writeText("2.0"); - Writer->writeClosingTag("revision"); - Writer->writeLineBreak(); - - Writer->writeElement("unit", true, "meter", core::stringc(getUnitMeter()).eraseTrailingFloatZeros().c_str(), "name", getUnitName().c_str()); - Writer->writeLineBreak(); - - Writer->writeClosingTag("asset"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeMeshMaterials(scene::IMesh* mesh, irr::core::array * materialNamesOut) -{ - u32 i; - for (i=0; igetMeshBufferCount(); ++i) - { - video::SMaterial & material = mesh->getMeshBuffer(i)->getMaterial(); - core::stringc strMat(nameForMaterial(material, i, mesh, NULL)); - writeMaterial(strMat); - if ( materialNamesOut ) - materialNamesOut->push_back(strMat); - } -} - -void CColladaMeshWriter::writeMaterialEffect(const irr::core::stringc& materialfxname, const video::SMaterial & material) -{ - if ( EffectsWritten.find(materialfxname) ) - return; - EffectsWritten.insert(materialfxname, true); - - Writer->writeElement("effect", false, - "id", materialfxname.c_str(), - "name", materialfxname.c_str()); - Writer->writeLineBreak(); - Writer->writeElement("profile_COMMON", false); - Writer->writeLineBreak(); - - int numTextures = 0; - if ( getWriteTextures() ) - { - // write texture surfaces and samplers and buffer all used imagess - for ( int t=0; t<4; ++t ) - { - const video::SMaterialLayer& layer = material.TextureLayer[t]; - if ( !layer.Texture ) - break; - ++numTextures; - - if ( LibraryImages.linear_search(layer.Texture) < 0 ) - LibraryImages.push_back( layer.Texture ); - - irr::core::stringc texName("tex"); - texName += irr::core::stringc(t); - - // write texture surface - // - irr::core::stringc texSurface(texName); - texSurface += "-surface"; - Writer->writeElement("newparam", false, "sid", texSurface.c_str()); - Writer->writeLineBreak(); - // - Writer->writeElement("surface", false, "type", "2D"); - Writer->writeLineBreak(); - - // internal_texturename - Writer->writeElement("init_from", false); - irr::io::path p(FileSystem->getRelativeFilename(layer.Texture->getName().getPath(), Directory)); - Writer->writeText(toNCName(irr::core::stringc(p)).c_str()); // same ID for internal name as in writeLibraryImages - Writer->writeClosingTag("init_from"); - Writer->writeLineBreak(); - - // A8R8G8B8 - Writer->writeElement("format", false); - video::ECOLOR_FORMAT format = layer.Texture->getColorFormat(); - Writer->writeText(toString(format).c_str()); - Writer->writeClosingTag("format"); - Writer->writeLineBreak(); - // - Writer->writeClosingTag("surface"); - Writer->writeLineBreak(); - // - Writer->writeClosingTag("newparam"); - Writer->writeLineBreak(); - - // write texture sampler - // - irr::core::stringc texSampler(texName); - texSampler += "-sampler"; - Writer->writeElement("newparam", false, "sid", texSampler.c_str()); - Writer->writeLineBreak(); - // - Writer->writeElement("sampler2D", false); - Writer->writeLineBreak(); - - // tex0-surface - Writer->writeElement("source", false); - Writer->writeText(texSurface.c_str()); - Writer->writeClosingTag("source"); - Writer->writeLineBreak(); - - // WRAP - Writer->writeElement("wrap_s", false); - Writer->writeText(toString((video::E_TEXTURE_CLAMP)layer.TextureWrapU).c_str()); - Writer->writeClosingTag("wrap_s"); - Writer->writeLineBreak(); - - // WRAP - Writer->writeElement("wrap_t", false); - Writer->writeText(toString((video::E_TEXTURE_CLAMP)layer.TextureWrapV).c_str()); - Writer->writeClosingTag("wrap_t"); - Writer->writeLineBreak(); - - // WRAP // TODO: Should only be written in Collada 1.5 - Writer->writeElement("wrap_p", false); - Writer->writeText(toString((video::E_TEXTURE_CLAMP)layer.TextureWrapW).c_str()); - Writer->writeClosingTag("wrap_p"); - Writer->writeLineBreak(); - - // LINEAR_MIPMAP_LINEAR - Writer->writeElement("minfilter", false); - Writer->writeText(minTexfilterToString(layer.BilinearFilter, layer.TrilinearFilter).c_str()); - Writer->writeClosingTag("minfilter"); - Writer->writeLineBreak(); - - // LINEAR - Writer->writeElement("magfilter", false); - Writer->writeText(magTexfilterToString(layer.BilinearFilter, layer.TrilinearFilter).c_str()); - Writer->writeClosingTag("magfilter"); - Writer->writeLineBreak(); - - // TBD - actually not sure how anisotropic should be written, so for now it writes in a way - // that works with the way the loader reads it again. - if ( layer.AnisotropicFilter ) - { - // LINEAR_MIPMAP_LINEAR - Writer->writeElement("mipfilter", false); - Writer->writeText("LINEAR_MIPMAP_LINEAR"); - Writer->writeClosingTag("mipfilter"); - Writer->writeLineBreak(); - } - - // - Writer->writeClosingTag("sampler2D"); - Writer->writeLineBreak(); - // - Writer->writeClosingTag("newparam"); - Writer->writeLineBreak(); - } - } - - Writer->writeElement("technique", false, "sid", "common"); - Writer->writeLineBreak(); - - E_COLLADA_TECHNIQUE_FX techFx = getProperties() ? getProperties()->getTechniqueFx(material) : ECTF_BLINN; - writeFxElement(material, techFx); - - Writer->writeClosingTag("technique"); - Writer->writeLineBreak(); - Writer->writeClosingTag("profile_COMMON"); - Writer->writeLineBreak(); - Writer->writeClosingTag("effect"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeMeshEffects(scene::IMesh* mesh) -{ - for (u32 i=0; igetMeshBufferCount(); ++i) - { - video::SMaterial & material = mesh->getMeshBuffer(i)->getMaterial(); - irr::core::stringc materialfxname(nameForMaterial(material, i, mesh, NULL)); - materialfxname += "-fx"; - writeMaterialEffect(materialfxname, material); - } -} - -void CColladaMeshWriter::writeMeshGeometry(const irr::core::stringc& meshname, scene::IMesh* mesh) -{ - core::stringc meshId(meshname); - - Writer->writeElement("geometry", false, "id", meshId.c_str(), "name", meshId.c_str()); - Writer->writeLineBreak(); - Writer->writeElement("mesh"); - Writer->writeLineBreak(); - - // do some statistics for the mesh to know which stuff needs to be saved into - // the file: - // - count vertices - // - check for the need of a second texture coordinate - // - count amount of second texture coordinates - // - check for the need of tangents (TODO) - - u32 totalVertexCount = 0; - u32 totalTCoords2Count = 0; - bool needsTangents = false; // TODO: tangents not supported here yet - u32 i=0; - for (i=0; igetMeshBufferCount(); ++i) - { - totalVertexCount += mesh->getMeshBuffer(i)->getVertexCount(); - - if (hasSecondTextureCoordinates(mesh->getMeshBuffer(i)->getVertexType())) - totalTCoords2Count += mesh->getMeshBuffer(i)->getVertexCount(); - - if (!needsTangents) - needsTangents = mesh->getMeshBuffer(i)->getVertexType() == video::EVT_TANGENTS; - } - - const irr::u32 mbCount = mesh->getMeshBufferCount(); - SComponentGlobalStartPos* globalIndices = new SComponentGlobalStartPos[mbCount]; - - // write positions - core::stringc meshPosId(meshId); - meshPosId += "-Pos"; - Writer->writeElement("source", false, "id", meshPosId.c_str()); - Writer->writeLineBreak(); - - core::stringc vertexCountStr(totalVertexCount*3); - core::stringc meshPosArrayId(meshPosId); - meshPosArrayId += "-array"; - Writer->writeElement("float_array", false, "id", meshPosArrayId.c_str(), - "count", vertexCountStr.c_str()); - Writer->writeLineBreak(); - - for (i=0; igetMeshBuffer(i); - u32 vertexCount = buffer->getVertexCount(); - - if ( i == 0 ) - globalIndices[i].PosStartIndex = 0; - - if (i+1 < mbCount) - globalIndices[i+1].PosStartIndex = globalIndices[i].PosStartIndex + vertexCount; - - u8* vertices = static_cast(buffer->getVertices()); - u32 vertexPitch = getVertexPitchFromType(buffer->getVertexType()); - for (u32 j=0; j(&vertices[j*vertexPitch])).Pos ); - Writer->writeLineBreak(); - } - } - - Writer->writeClosingTag("float_array"); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - vertexCountStr = core::stringc(totalVertexCount); - - Writer->writeElement("accessor", false, "source", toRef(meshPosArrayId).c_str(), - "count", vertexCountStr.c_str(), "stride", "3"); - Writer->writeLineBreak(); - - Writer->writeElement("param", true, "name", "X", "type", "float"); - Writer->writeLineBreak(); - Writer->writeElement("param", true, "name", "Y", "type", "float"); - Writer->writeLineBreak(); - Writer->writeElement("param", true, "name", "Z", "type", "float"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("accessor"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("source"); - Writer->writeLineBreak(); - - // write texture coordinates - - core::stringc meshTexCoord0Id(meshId); - meshTexCoord0Id += "-TexCoord0"; - Writer->writeElement("source", false, "id", meshTexCoord0Id.c_str()); - Writer->writeLineBreak(); - - vertexCountStr = core::stringc(totalVertexCount*2); - core::stringc meshTexCoordArrayId(meshTexCoord0Id); - meshTexCoordArrayId += "-array"; - Writer->writeElement("float_array", false, "id", meshTexCoordArrayId.c_str(), - "count", vertexCountStr.c_str()); - Writer->writeLineBreak(); - - for (i=0; igetMeshBuffer(i); - u32 vertexCount = buffer->getVertexCount(); - - if (i==0) - globalIndices[i].TCoord0StartIndex = 0; - - if (i+1 < mbCount) - globalIndices[i+1].TCoord0StartIndex = globalIndices[i].TCoord0StartIndex + vertexCount; - - u8* vertices = static_cast(buffer->getVertices()); - u32 vertexPitch = getVertexPitchFromType(buffer->getVertexType()); - for (u32 j=0; j(&vertices[j*vertexPitch])).TCoords ); - Writer->writeLineBreak(); - } - } - - Writer->writeClosingTag("float_array"); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - vertexCountStr = core::stringc(totalVertexCount); - - Writer->writeElement("accessor", false, "source", toRef(meshTexCoordArrayId).c_str(), - "count", vertexCountStr.c_str(), "stride", "2"); - Writer->writeLineBreak(); - - Writer->writeElement("param", true, "name", ParamNamesUV[0].c_str(), "type", "float"); - Writer->writeLineBreak(); - Writer->writeElement("param", true, "name", ParamNamesUV[1].c_str(), "type", "float"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("accessor"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("source"); - Writer->writeLineBreak(); - - // write normals - core::stringc meshNormalId(meshId); - meshNormalId += "-Normal"; - Writer->writeElement("source", false, "id", meshNormalId.c_str()); - Writer->writeLineBreak(); - - vertexCountStr = core::stringc(totalVertexCount*3); - core::stringc meshNormalArrayId(meshNormalId); - meshNormalArrayId += "-array"; - Writer->writeElement("float_array", false, "id", meshNormalArrayId.c_str(), - "count", vertexCountStr.c_str()); - Writer->writeLineBreak(); - - for (i=0; igetMeshBuffer(i); - u32 vertexCount = buffer->getVertexCount(); - - if ( i==0 ) - globalIndices[i].NormalStartIndex = 0; - - if (i+1 < mbCount) - globalIndices[i+1].NormalStartIndex = globalIndices[i].NormalStartIndex + vertexCount; - - u8* vertices = static_cast(buffer->getVertices()); - u32 vertexPitch = getVertexPitchFromType(buffer->getVertexType()); - for (u32 j=0; j(&vertices[j*vertexPitch])).Normal ); - Writer->writeLineBreak(); - } - } - - Writer->writeClosingTag("float_array"); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - vertexCountStr = core::stringc(totalVertexCount); - - Writer->writeElement("accessor", false, "source", toRef(meshNormalArrayId).c_str(), - "count", vertexCountStr.c_str(), "stride", "3"); - Writer->writeLineBreak(); - - Writer->writeElement("param", true, "name", "X", "type", "float"); - Writer->writeLineBreak(); - Writer->writeElement("param", true, "name", "Y", "type", "float"); - Writer->writeLineBreak(); - Writer->writeElement("param", true, "name", "Z", "type", "float"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("accessor"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("source"); - Writer->writeLineBreak(); - - // write second set of texture coordinates - core::stringc meshTexCoord1Id(meshId); - meshTexCoord1Id += "-TexCoord1"; - if (totalTCoords2Count) - { - Writer->writeElement("source", false, "id", meshTexCoord1Id.c_str()); - Writer->writeLineBreak(); - - vertexCountStr = core::stringc(totalTCoords2Count*2); - core::stringc meshTexCoord1ArrayId(meshTexCoord1Id); - meshTexCoord1ArrayId += "-array"; - Writer->writeElement("float_array", false, "id", meshTexCoord1ArrayId.c_str(), - "count", vertexCountStr.c_str()); - Writer->writeLineBreak(); - - for (i=0; igetMeshBuffer(i); - video::E_VERTEX_TYPE vtxType = buffer->getVertexType(); - u32 vertexCount = 0; - - if (hasSecondTextureCoordinates(vtxType)) - { - vertexCount = buffer->getVertexCount(); - switch(vtxType) - { - case video::EVT_2TCOORDS: - { - video::S3DVertex2TCoords* vtx = (video::S3DVertex2TCoords*)buffer->getVertices(); - for (u32 j=0; jwriteLineBreak(); - } - } - break; - default: - break; - } - } // end this buffer has 2 texture coordinates - - if ( i == 0 ) - globalIndices[i].TCoord1StartIndex = 0; - - if (i+1 < mbCount) - globalIndices[i+1].TCoord1StartIndex = globalIndices[i].TCoord1StartIndex + vertexCount; - } - - Writer->writeClosingTag("float_array"); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - vertexCountStr = core::stringc(totalTCoords2Count); - - Writer->writeElement("accessor", false, "source", toRef(meshTexCoord1ArrayId).c_str(), - "count", vertexCountStr.c_str(), "stride", "2"); - Writer->writeLineBreak(); - - Writer->writeElement("param", true, "name", ParamNamesUV[0].c_str(), "type", "float"); - Writer->writeLineBreak(); - Writer->writeElement("param", true, "name", ParamNamesUV[1].c_str(), "type", "float"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("accessor"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("source"); - Writer->writeLineBreak(); - } - - // write tangents - - // TODO - - // write vertices - core::stringc meshVtxId(meshId); - meshVtxId += "-Vtx"; - Writer->writeElement("vertices", false, "id", meshVtxId.c_str()); - Writer->writeLineBreak(); - - Writer->writeElement("input", true, "semantic", "POSITION", "source", toRef(meshPosId).c_str()); - Writer->writeLineBreak(); - - Writer->writeClosingTag("vertices"); - Writer->writeLineBreak(); - - // write polygons - - for (i=0; igetMeshBuffer(i); - - if ( buffer->getPrimitiveType() != EPT_TRIANGLES ) - { - os::Printer::log("Collada writer does not support non-triangle meshbuffers. Mesh: ", meshname.c_str(), ELL_WARNING); - continue; - } - - const u32 polyCount = buffer->getPrimitiveCount(); - core::stringc strPolyCount(polyCount); - irr::core::stringc strMat(nameForMaterialSymbol(mesh, i)); - - Writer->writeElement("triangles", false, "count", strPolyCount.c_str(), - "material", strMat.c_str()); - Writer->writeLineBreak(); - - Writer->writeElement("input", true, "semantic", "VERTEX", "source", toRef(meshVtxId).c_str(), "offset", "0"); - Writer->writeLineBreak(); - Writer->writeElement("input", true, "semantic", "TEXCOORD", "source", toRef(meshTexCoord0Id).c_str(), "offset", "1", "set", "0"); - Writer->writeLineBreak(); - Writer->writeElement("input", true, "semantic", "NORMAL", "source", toRef(meshNormalId).c_str(), "offset", "2"); - Writer->writeLineBreak(); - - bool has2ndTexCoords = hasSecondTextureCoordinates(buffer->getVertexType()); - if (has2ndTexCoords) - { - // TODO: when working on second uv-set - my suspicion is that this one should be called "TEXCOORD2" - // to allow bind_vertex_input to differentiate the uv-sets. - Writer->writeElement("input", true, "semantic", "TEXCOORD", "source", toRef(meshTexCoord1Id).c_str(), "idx", "3"); - Writer->writeLineBreak(); - } - - // write indices now - - // In Collada we us a single global buffer for all vertices, so indices have this offset compared to Irrlicht - u32 posIdx = globalIndices[i].PosStartIndex; - u32 tCoordIdx = globalIndices[i].TCoord0StartIndex; - u32 normalIdx = globalIndices[i].NormalStartIndex; - u32 tCoord2Idx = globalIndices[i].TCoord1StartIndex; - - Writer->writeElement("p", false); - - core::stringc strP; - strP.reserve(100); - for (u32 p=0; pgetIndices()[(p*3) + 2]; - strP = ""; - strP += irrIdx + posIdx; - strP += " "; - strP += irrIdx + tCoordIdx; - strP += " "; - strP += irrIdx + normalIdx; - strP += " "; - if (has2ndTexCoords) - { - strP += irrIdx + tCoord2Idx; - strP += " "; - } - - irrIdx = buffer->getIndices()[(p*3) + 1]; - strP += irrIdx + posIdx; - strP += " "; - strP += irrIdx + tCoordIdx; - strP += " "; - strP += irrIdx + normalIdx; - strP += " "; - if (has2ndTexCoords) - { - strP += irrIdx + tCoord2Idx; - strP += " "; - } - - irrIdx = buffer->getIndices()[(p*3) + 0]; - strP += irrIdx + posIdx; - strP += " "; - strP += irrIdx + tCoordIdx; - strP += " "; - strP += irrIdx + normalIdx; - if (has2ndTexCoords) - { - strP += " "; - strP += irrIdx + tCoord2Idx; - } - strP += " "; - - Writer->writeText(strP.c_str()); - } - - Writer->writeClosingTag("p"); - Writer->writeLineBreak(); - - // close index buffer section - - Writer->writeClosingTag("triangles"); - Writer->writeLineBreak(); - } - - // close mesh and geometry - delete [] globalIndices; - Writer->writeClosingTag("mesh"); - Writer->writeLineBreak(); - Writer->writeClosingTag("geometry"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeLibraryImages() -{ - if ( getWriteTextures() && !LibraryImages.empty() ) - { - Writer->writeElement("library_images", false); - Writer->writeLineBreak(); - - for ( irr::u32 i=0; igetRelativeFilename(LibraryImages[i]->getName().getPath(), Directory)); - // - irr::core::stringc ncname( toNCName(irr::core::stringc(p)) ); - Writer->writeElement("image", false, "id", ncname.c_str(), "name", ncname.c_str()); - Writer->writeLineBreak(); - // ../flowers/rose01.jpg - Writer->writeElement("init_from", false); - Writer->writeText(pathToURI(p).c_str()); - Writer->writeClosingTag("init_from"); - Writer->writeLineBreak(); - // - Writer->writeClosingTag("image"); - Writer->writeLineBreak(); - } - - Writer->writeClosingTag("library_images"); - Writer->writeLineBreak(); - } -} - -void CColladaMeshWriter::writeColorElement(const video::SColorf & col, bool writeAlpha) -{ - Writer->writeElement("color", false); - - writeColor(col, writeAlpha); - - Writer->writeClosingTag("color"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeColorElement(const video::SColor & col, bool writeAlpha) -{ - writeColorElement( video::SColorf(col), writeAlpha ); -} - -void CColladaMeshWriter::writeAmbientLightElement(const video::SColorf & col) -{ - Writer->writeElement("light", false, "id", "ambientlight"); - Writer->writeLineBreak(); - - Writer->writeElement("technique_common", false); - Writer->writeLineBreak(); - - Writer->writeElement("ambient", false); - Writer->writeLineBreak(); - - writeColorElement(col, false); - - Writer->writeClosingTag("ambient"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("technique_common"); - Writer->writeLineBreak(); - - Writer->writeClosingTag("light"); - Writer->writeLineBreak(); -} - -s32 CColladaMeshWriter::getCheckedTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs) -{ - if ( !getWriteTextures() - || !getProperties() ) - return -1; - - s32 idx = getProperties()->getTextureIdx(material, cs); - if ( idx >= 0 && !material.TextureLayer[idx].Texture ) - return -1; - - return idx; -} - -video::SColor CColladaMeshWriter::getColorMapping(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs, E_COLLADA_IRR_COLOR colType) -{ - switch ( colType ) - { - case ECIC_NONE: - return video::SColor(255, 0, 0, 0); - - case ECIC_CUSTOM: - return getProperties()->getCustomColor(material, cs); - - case ECIC_DIFFUSE: - return material.DiffuseColor; - - case ECIC_AMBIENT: - return material.AmbientColor; - - case ECIC_EMISSIVE: - return material.EmissiveColor; - - case ECIC_SPECULAR: - return material.SpecularColor; - } - return video::SColor(255, 0, 0, 0); -} - -void CColladaMeshWriter::writeTextureSampler(s32 textureIdx) -{ - irr::core::stringc sampler("tex"); - sampler += irr::core::stringc(textureIdx); - sampler += "-sampler"; - - // - Writer->writeElement("texture", true, "texture", sampler.c_str(), "texcoord", "uv" ); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeFxElement(const video::SMaterial & material, E_COLLADA_TECHNIQUE_FX techFx) -{ - core::stringc fxLabel; - bool writeEmission = true; - bool writeAmbient = true; - bool writeDiffuse = true; - bool writeSpecular = true; - bool writeShininess = true; - bool writeReflective = true; - bool writeReflectivity = true; - bool writeTransparent = true; - bool writeTransparency = true; - bool writeIndexOfRefraction = true; - switch ( techFx ) - { - case ECTF_BLINN: - fxLabel = "blinn"; - break; - case ECTF_PHONG: - fxLabel = "phong"; - break; - case ECTF_LAMBERT: - fxLabel = "lambert"; - writeSpecular = false; - writeShininess = false; - break; - case ECTF_CONSTANT: - fxLabel = "constant"; - writeAmbient = false; - writeDiffuse = false; - writeSpecular = false; - writeShininess = false; - break; - } - - Writer->writeElement(fxLabel.c_str(), false); - Writer->writeLineBreak(); - - // write all interesting material parameters - // attributes must be written in fixed order - if ( getProperties() ) - { - if ( writeEmission ) - { - writeColorFx(material, "emission", ECCS_EMISSIVE); - } - - if ( writeAmbient ) - { - writeColorFx(material, "ambient", ECCS_AMBIENT); - } - - if ( writeDiffuse ) - { - writeColorFx(material, "diffuse", ECCS_DIFFUSE); - } - - if ( writeSpecular ) - { - writeColorFx(material, "specular", ECCS_SPECULAR); - } - - if ( writeShininess ) - { - Writer->writeElement("shininess", false); - Writer->writeLineBreak(); - writeFloatElement(material.Shininess); - Writer->writeClosingTag("shininess"); - Writer->writeLineBreak(); - } - - if ( writeReflective ) - { - writeColorFx(material, "reflective", ECCS_REFLECTIVE); - } - - if ( writeReflectivity ) - { - f32 t = getProperties()->getReflectivity(material); - if ( t >= 0.f ) - { - // 1.000000 - Writer->writeElement("reflectivity", false); - Writer->writeLineBreak(); - writeFloatElement(t); - Writer->writeClosingTag("reflectivity"); - Writer->writeLineBreak(); - } - } - - if ( writeTransparent ) - { - E_COLLADA_TRANSPARENT_FX transparentFx = getProperties()->getTransparentFx(material); - writeColorFx(material, "transparent", ECCS_TRANSPARENT, "opaque", toString(transparentFx).c_str()); - } - - if ( writeTransparency ) - { - f32 t = getProperties()->getTransparency(material); - if ( t >= 0.f ) - { - // 1.000000 - Writer->writeElement("transparency", false); - Writer->writeLineBreak(); - writeFloatElement(t); - Writer->writeClosingTag("transparency"); - Writer->writeLineBreak(); - } - } - - if ( writeIndexOfRefraction ) - { - f32 t = getProperties()->getIndexOfRefraction(material); - if ( t >= 0.f ) - { - Writer->writeElement("index_of_refraction", false); - Writer->writeLineBreak(); - writeFloatElement(t); - Writer->writeClosingTag("index_of_refraction"); - Writer->writeLineBreak(); - } - } - } - - - Writer->writeClosingTag(fxLabel.c_str()); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeColorFx(const video::SMaterial & material, const c8 * colorname, E_COLLADA_COLOR_SAMPLER cs, const c8* attr1Name, const c8* attr1Value) -{ - irr::s32 idx = getCheckedTextureIdx(material, cs); - E_COLLADA_IRR_COLOR colType = idx < 0 ? getProperties()->getColorMapping(material, cs) : ECIC_NONE; - if ( idx >= 0 || colType != ECIC_NONE ) - { - Writer->writeElement(colorname, false, attr1Name, attr1Value); - Writer->writeLineBreak(); - if ( idx >= 0 ) - writeTextureSampler(idx); - else - writeColorElement(getColorMapping(material, cs, colType)); - Writer->writeClosingTag(colorname); - Writer->writeLineBreak(); - } -} - -void CColladaMeshWriter::writeNode(const c8 * nodeName, const c8 * content) -{ - Writer->writeElement(nodeName, false); - Writer->writeText(content); - Writer->writeClosingTag(nodeName); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeFloatElement(irr::f32 value) -{ - Writer->writeElement("float", false); - Writer->writeText(core::stringc((double)value).eraseTrailingFloatZeros().c_str()); - Writer->writeClosingTag("float"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeRotateElement(const irr::core::vector3df& axis, irr::f32 angle) -{ - Writer->writeElement("rotate", false); - irr::core::stringc txt(axis.X); - txt.eraseTrailingFloatZeros(); - txt += " "; - txt += irr::core::stringc(axis.Y); - txt.eraseTrailingFloatZeros(); - txt += " "; - txt += irr::core::stringc(axis.Z * -1.f); - txt.eraseTrailingFloatZeros(); - txt += " "; - txt += irr::core::stringc((double)angle * -1.f); - txt.eraseTrailingFloatZeros(); - Writer->writeText(txt.c_str()); - Writer->writeClosingTag("rotate"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeScaleElement(const irr::core::vector3df& scale) -{ - Writer->writeElement("scale", false); - irr::core::stringc txt(scale.X); - txt.eraseTrailingFloatZeros(); - txt += " "; - txt += irr::core::stringc(scale.Y); - txt.eraseTrailingFloatZeros(); - txt += " "; - txt += irr::core::stringc(scale.Z); - txt.eraseTrailingFloatZeros(); - Writer->writeText(txt.c_str()); - Writer->writeClosingTag("scale"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeTranslateElement(const irr::core::vector3df& translate) -{ - Writer->writeElement("translate", false); - irr::core::stringc txt(translate.X); - txt.eraseTrailingFloatZeros(); - txt += " "; - txt += irr::core::stringc(translate.Y); - txt.eraseTrailingFloatZeros(); - txt += " "; - txt += irr::core::stringc(translate.Z*-1.f); - txt.eraseTrailingFloatZeros(); - Writer->writeText(txt.c_str()); - Writer->writeClosingTag("translate"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeLookAtElement(const irr::core::vector3df& eyePos, const irr::core::vector3df& targetPos, const irr::core::vector3df& upVector) -{ - Writer->writeElement("lookat", false); - - c8 tmpbuf[255]; - snprintf_irr(tmpbuf, 255, "%f %f %f %f %f %f %f %f %f", eyePos.X, eyePos.Y, eyePos.Z*-1.f, targetPos.X, targetPos.Y, targetPos.Z*-1.f, upVector.X, upVector.Y, upVector.Z*-1.f); - Writer->writeText(tmpbuf); - - Writer->writeClosingTag("lookat"); - Writer->writeLineBreak(); -} - -void CColladaMeshWriter::writeMatrixElement(const irr::core::matrix4& matrixIrr) -{ - irr::core::matrix4 matrix(matrixIrr.getTransposed()); // transposed because row/lines are written other way round in Collada - // Convert to right-handed - matrix[2] *= -1.f; - matrix[6] *= -1.f; - matrix[8] *= -1.f; - matrix[9] *= -1.f; - matrix[11] *= -1.f; - matrix[14] *= -1.f; - - Writer->writeElement("matrix", false); - Writer->writeLineBreak(); - - for ( int a=0; a<4; ++a ) - { - irr::core::stringc txt; - for ( int b=0; b<4; ++b ) - { - if ( b > 0 ) - txt += " "; - txt += irr::core::stringc(matrix[a*4+b]).eraseTrailingFloatZeros(); - } - Writer->writeText(txt.c_str()); - Writer->writeLineBreak(); - } - - Writer->writeClosingTag("matrix"); - Writer->writeLineBreak(); -} - -} // end namespace -} // end namespace - -#endif - diff --git a/source/Irrlicht/CColladaMeshWriter.h b/source/Irrlicht/CColladaMeshWriter.h deleted file mode 100644 index 6c07d49..0000000 --- a/source/Irrlicht/CColladaMeshWriter.h +++ /dev/null @@ -1,282 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __IRR_C_COLLADA_MESH_WRITER_H_INCLUDED__ -#define __IRR_C_COLLADA_MESH_WRITER_H_INCLUDED__ - -#include "IColladaMeshWriter.h" -#include "S3DVertex.h" -#include "irrMap.h" -#include "IVideoDriver.h" -#include "IXMLWriter.h" - -namespace irr -{ -namespace io -{ - class IFileSystem; -} - -namespace scene -{ - //! Callback interface for properties which can be used to influence collada writing - // (Implementer note: keep namespace labels here to make it easier for users copying this one) - class CColladaMeshWriterProperties : public virtual IColladaMeshWriterProperties - { - public: - //! Which lighting model should be used in the technique (FX) section when exporting effects (materials) - virtual irr::scene::E_COLLADA_TECHNIQUE_FX getTechniqueFx(const irr::video::SMaterial& material) const _IRR_OVERRIDE_; - - //! Which texture index should be used when writing the texture of the given sampler color. - virtual irr::s32 getTextureIdx(const irr::video::SMaterial & material, irr::scene::E_COLLADA_COLOR_SAMPLER cs) const _IRR_OVERRIDE_; - - //! Return which color from Irrlicht should be used for the color requested by collada - virtual irr::scene::E_COLLADA_IRR_COLOR getColorMapping(const irr::video::SMaterial & material, irr::scene::E_COLLADA_COLOR_SAMPLER cs) const _IRR_OVERRIDE_; - - //! Return custom colors for certain color types requested by collada. - virtual irr::video::SColor getCustomColor(const irr::video::SMaterial & material, irr::scene::E_COLLADA_COLOR_SAMPLER cs) const _IRR_OVERRIDE_; - - //! Return the settings for transparence - virtual irr::scene::E_COLLADA_TRANSPARENT_FX getTransparentFx(const irr::video::SMaterial& material) const _IRR_OVERRIDE_; - - //! Transparency value for that material. - virtual irr::f32 getTransparency(const irr::video::SMaterial& material) const _IRR_OVERRIDE_; - - //! Reflectivity value for that material - virtual irr::f32 getReflectivity(const irr::video::SMaterial& material) const _IRR_OVERRIDE_; - - //! Return index of refraction for that material - virtual irr::f32 getIndexOfRefraction(const irr::video::SMaterial& material) const _IRR_OVERRIDE_; - - //! Should node be used in scene export? By default all visible nodes are exported. - virtual bool isExportable(const irr::scene::ISceneNode * node) const _IRR_OVERRIDE_; - - //! Return the mesh for the given nod. If it has no mesh or shouldn't export it's mesh return 0. - virtual irr::scene::IMesh* getMesh(irr::scene::ISceneNode * node) _IRR_OVERRIDE_; - - //! Return if the node has it's own material overwriting the mesh-materials - virtual bool useNodeMaterial(const scene::ISceneNode* node) const _IRR_OVERRIDE_; - }; - - class CColladaMeshWriterNames : public virtual IColladaMeshWriterNames - { - public: - CColladaMeshWriterNames(IColladaMeshWriter * writer); - virtual irr::core::stringc nameForMesh(const scene::IMesh* mesh, int instance) _IRR_OVERRIDE_; - virtual irr::core::stringc nameForNode(const scene::ISceneNode* node) _IRR_OVERRIDE_; - virtual irr::core::stringc nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node) _IRR_OVERRIDE_; - protected: - irr::core::stringc nameForPtr(const void* ptr) const; - private: - IColladaMeshWriter * ColladaMeshWriter; - }; - - - -//! class to write meshes, implementing a COLLADA (.dae, .xml) writer -/** This writer implementation has been originally developed for irrEdit and then -merged out to the Irrlicht Engine */ -class CColladaMeshWriter : public IColladaMeshWriter -{ -public: - - CColladaMeshWriter(ISceneManager * smgr, video::IVideoDriver* driver, io::IFileSystem* fs); - virtual ~CColladaMeshWriter(); - - //! Returns the type of the mesh writer - virtual EMESH_WRITER_TYPE getType() const _IRR_OVERRIDE_; - - //! writes a scene starting with the given node - virtual bool writeScene(io::IWriteFile* file, scene::ISceneNode* root, int writeRoot) _IRR_OVERRIDE_; - - //! writes a mesh - virtual bool writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE) _IRR_OVERRIDE_; - - // Restrict the characters of oldString a set of allowed characters in xs:NCName and add the prefix. - virtual irr::core::stringc toNCName(const irr::core::stringc& oldString, const irr::core::stringc& prefix=irr::core::stringc("_NC_")) const _IRR_OVERRIDE_; - - //! After export you can find out which name had been used for writing the geometry for this node. - virtual const irr::core::stringc* findGeometryNameForNode(ISceneNode* node) _IRR_OVERRIDE_; - -protected: - - void reset(); - bool hasSecondTextureCoordinates(video::E_VERTEX_TYPE type) const; - void writeUv(const irr::core::vector2df& vec); - void writeVector(const irr::core::vector3df& vec); - void writeColor(const irr::video::SColorf& colorf, bool writeAlpha=true); - inline irr::core::stringc toString(const irr::video::ECOLOR_FORMAT format) const; - inline irr::core::stringc toString(const irr::video::E_TEXTURE_CLAMP clamp) const; - inline irr::core::stringc toString(const irr::scene::E_COLLADA_TRANSPARENT_FX opaque) const; - inline irr::core::stringc toRef(const irr::core::stringc& source) const; - bool isCamera(const scene::ISceneNode* node) const; - irr::core::stringc nameForMesh(const scene::IMesh* mesh, int instance) const; - irr::core::stringc nameForNode(const scene::ISceneNode* node) const; - irr::core::stringc nameForMaterial(const video::SMaterial & material, int materialId, const scene::IMesh* mesh, const scene::ISceneNode* node); - irr::core::stringc nameForMaterialSymbol(const scene::IMesh* mesh, int materialId) const; - irr::core::stringc findCachedMaterialName(const irr::video::SMaterial& material) const; - irr::core::stringc minTexfilterToString(bool bilinear, bool trilinear) const; - irr::core::stringc magTexfilterToString(bool bilinear, bool trilinear) const; - irr::core::stringc pathToURI(const irr::io::path& path) const; - inline bool isXmlNameStartChar(c8 c) const; - inline bool isXmlNameChar(c8 c) const; - s32 getCheckedTextureIdx(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs); - video::SColor getColorMapping(const video::SMaterial & material, E_COLLADA_COLOR_SAMPLER cs, E_COLLADA_IRR_COLOR colType); - void writeAsset(); - void makeMeshNames(irr::scene::ISceneNode * node); - void writeNodeMaterials(irr::scene::ISceneNode * node); - void writeNodeEffects(irr::scene::ISceneNode * node); - void writeNodeLights(irr::scene::ISceneNode * node); - void writeNodeCameras(irr::scene::ISceneNode * node); - void writeAllMeshGeometries(); - void writeSceneNode(irr::scene::ISceneNode * node); - void writeMeshMaterials(scene::IMesh* mesh, irr::core::array * materialNamesOut=0); - void writeMeshEffects(scene::IMesh* mesh); - void writeMaterialEffect(const irr::core::stringc& materialname, const video::SMaterial & material); - void writeMeshGeometry(const irr::core::stringc& meshname, scene::IMesh* mesh); - void writeMeshInstanceGeometry(const irr::core::stringc& meshname, scene::IMesh* mesh, scene::ISceneNode* node=0); - void writeMaterial(const irr::core::stringc& materialname); - void writeLightInstance(const irr::core::stringc& lightName); - void writeCameraInstance(const irr::core::stringc& cameraName); - void writeLibraryImages(); - void writeColorFx(const video::SMaterial & material, const c8 * colorname, E_COLLADA_COLOR_SAMPLER cs, const c8* attr1Name=0, const c8* attr1Value=0); - void writeAmbientLightElement(const video::SColorf & col); - void writeColorElement(const video::SColor & col, bool writeAlpha=true); - void writeColorElement(const video::SColorf & col, bool writeAlpha=true); - void writeTextureSampler(s32 textureIdx); - void writeFxElement(const video::SMaterial & material, E_COLLADA_TECHNIQUE_FX techFx); - void writeNode(const c8 * nodeName, const c8 * content); - void writeFloatElement(irr::f32 value); - void writeRotateElement(const irr::core::vector3df& axis, irr::f32 angle); - void writeScaleElement(const irr::core::vector3df& scale); - void writeTranslateElement(const irr::core::vector3df& translate); - void writeLookAtElement(const irr::core::vector3df& eyePos, const irr::core::vector3df& targetPos, const irr::core::vector3df& upVector); - void writeMatrixElement(const irr::core::matrix4& matrix); - - struct SComponentGlobalStartPos - { - SComponentGlobalStartPos() : PosStartIndex(0), - NormalStartIndex(0), - TCoord0StartIndex(0), - TCoord1StartIndex(0) - { } - - u32 PosStartIndex; - u32 NormalStartIndex; - u32 TCoord0StartIndex; - u32 TCoord1StartIndex; - }; - - io::IFileSystem* FileSystem; - video::IVideoDriver* VideoDriver; - io::IXMLWriterUTF8* Writer; - core::array LibraryImages; - io::path Directory; - - // Helper struct for creating geometry copies for the ECGI_PER_MESH_AND_MATERIAL settings. - struct SGeometryMeshMaterials - { - bool equals(const core::array& names) const - { - if ( names.size() != MaterialNames.size() ) - return false; - for ( irr::u32 i=0; i MaterialNames; // Material names exported for this instance - core::array MaterialOwners; // Nodes using this specific mesh-material combination - }; - - // Check per mesh-ptr if stuff has been written for this mesh already - struct SColladaMesh - { - SColladaMesh() : MaterialsWritten(false), EffectsWritten(false) - { - } - - SGeometryMeshMaterials * findGeometryMeshMaterials(const irr::core::array materialNames) - { - for ( irr::u32 i=0; i= 0 ) - return GeometryMeshMaterials[i].GeometryName; - } - return Name; // (shouldn't get here usually) - } - - irr::core::stringc Name; - bool MaterialsWritten; // just an optimization doing that here in addition to the MaterialsWritten map - bool EffectsWritten; // just an optimization doing that here in addition to the EffectsWritten map - - core::array GeometryMeshMaterials; - }; - typedef core::map::Node MeshNode; - core::map Meshes; - - // structure for the lights library - struct SColladaLight - { - SColladaLight() {} - irr::core::stringc Name; - }; - typedef core::map::Node LightNode; - core::map LightNodes; - - // structure for the camera library - typedef core::map::Node CameraNode; - core::map CameraNodes; - - // Check per name if stuff has been written already - // TODO: second parameter not needed, we just don't have a core::set class yet in Irrlicht - core::map MaterialsWritten; - core::map EffectsWritten; - - // Cache material names - struct MaterialName - { - MaterialName(const irr::video::SMaterial & material, const irr::core::stringc& name) - : Material(material), Name(name) - {} - irr::video::SMaterial Material; - irr::core::stringc Name; - }; - irr::core::array< MaterialName > MaterialNameCache; - - irr::core::stringc WriteBuffer; // use for writing short strings to avoid regular memory allocations - - struct EscapeCharacterURL - { - EscapeCharacterURL(irr::c8 c, const irr::c8* e) - : Character(c) - { - Escape = e; - } - - irr::c8 Character; // unescaped (like ' ') - irr::core::stringc Escape; // escaped (like '%20') - }; - irr::core::array EscapeCharsAnyURI; -}; - - -} // end namespace -} // end namespace - -#endif diff --git a/source/Irrlicht/CFileSystem.cpp b/source/Irrlicht/CFileSystem.cpp index 6e336b9..6cdb0c6 100644 --- a/source/Irrlicht/CFileSystem.cpp +++ b/source/Irrlicht/CFileSystem.cpp @@ -14,8 +14,6 @@ #include "CTarReader.h" #include "CWADReader.h" #include "CFileList.h" -#include "CXMLReader.h" -#include "CXMLWriter.h" #include "stdio.h" #include "os.h" #include "CAttributes.h" @@ -981,133 +979,6 @@ bool CFileSystem::existFile(const io::path& filename) const } -//! Creates a XML Reader from a file. -IXMLReader* CFileSystem::createXMLReader(const io::path& filename) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - IReadFile* file = createAndOpenFile(filename); - if (!file) - return 0; - - IXMLReader* reader = createXMLReader(file); - file->drop(); - return reader; -#else - noXML(); - return 0; -#endif -} - - -//! Creates a XML Reader from a file. -IXMLReader* CFileSystem::createXMLReader(IReadFile* file) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - if (!file) - return 0; - - return createIXMLReader(file); -#else - noXML(); - return 0; -#endif -} - - -//! Creates a XML Reader from a file. -IXMLReaderUTF8* CFileSystem::createXMLReaderUTF8(const io::path& filename) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - IReadFile* file = createAndOpenFile(filename); - if (!file) - return 0; - - IXMLReaderUTF8* reader = createIXMLReaderUTF8(file); - file->drop(); - return reader; -#else - noXML(); - return 0; -#endif -} - - -//! Creates a XML Reader from a file. -IXMLReaderUTF8* CFileSystem::createXMLReaderUTF8(IReadFile* file) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - if (!file) - return 0; - - return createIXMLReaderUTF8(file); -#else - noXML(); - return 0; -#endif -} - - -//! Creates a XML Writer from a file. -IXMLWriter* CFileSystem::createXMLWriter(const io::path& filename) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - IWriteFile* file = createAndWriteFile(filename); - IXMLWriter* writer = 0; - if (file) - { - writer = createXMLWriter(file); - file->drop(); - } - return writer; -#else - noXML(); - return 0; -#endif -} - - -//! Creates a XML Writer from a file. -IXMLWriter* CFileSystem::createXMLWriter(IWriteFile* file) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - return createIXMLWriter(file); -#else - noXML(); - return 0; -#endif -} - -//! Creates a XML Writer from a file. -IXMLWriterUTF8* CFileSystem::createXMLWriterUTF8(const io::path& filename) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - IWriteFile* file = createAndWriteFile(filename); - IXMLWriterUTF8* writer = 0; - if (file) - { - writer = createXMLWriterUTF8(file); - file->drop(); - } - return writer; -#else - noXML(); - return 0; -#endif -} - - -//! Creates a XML Writer from a file. -IXMLWriterUTF8* CFileSystem::createXMLWriterUTF8(IWriteFile* file) -{ -#ifdef _IRR_COMPILE_WITH_XML_ - return createIXMLWriterUTF8(file); -#else - noXML(); - return 0; -#endif -} - - //! creates a filesystem which is able to open files from the ordinary file system, //! and out of zipfiles, which are able to be added to the filesystem. IFileSystem* createFileSystem() diff --git a/source/Irrlicht/CFileSystem.h b/source/Irrlicht/CFileSystem.h index 87c5134..d474010 100644 --- a/source/Irrlicht/CFileSystem.h +++ b/source/Irrlicht/CFileSystem.h @@ -127,30 +127,6 @@ public: //! determines if a file exists and would be able to be opened. virtual bool existFile(const io::path& filename) const _IRR_OVERRIDE_; - //! Creates a XML Reader from a file. - virtual IXMLReader* createXMLReader(const io::path& filename) _IRR_OVERRIDE_; - - //! Creates a XML Reader from a file. - virtual IXMLReader* createXMLReader(IReadFile* file) _IRR_OVERRIDE_; - - //! Creates a XML Reader from a file. - virtual IXMLReaderUTF8* createXMLReaderUTF8(const io::path& filename) _IRR_OVERRIDE_; - - //! Creates a XML Reader from a file. - virtual IXMLReaderUTF8* createXMLReaderUTF8(IReadFile* file) _IRR_OVERRIDE_; - - //! Creates a XML Writer from a file. - virtual IXMLWriter* createXMLWriter(const io::path& filename) _IRR_OVERRIDE_; - - //! Creates a XML Writer from a file. - virtual IXMLWriter* createXMLWriter(IWriteFile* file) _IRR_OVERRIDE_; - - //! Creates a XML Writer from a file which will write ASCII/UTF-8 characters (char*). - virtual IXMLWriterUTF8* createXMLWriterUTF8(const path& filename) _IRR_OVERRIDE_; - - //! Creates a XML Writer from a file which will write ASCII/UTF-8 characters (char*). - virtual IXMLWriterUTF8* createXMLWriterUTF8(IWriteFile* file) _IRR_OVERRIDE_; - //! Creates a new empty collection of attributes, usable for serialization and more. virtual IAttributes* createEmptyAttributes(video::IVideoDriver* driver) _IRR_OVERRIDE_; diff --git a/source/Irrlicht/CGUIEnvironment.cpp b/source/Irrlicht/CGUIEnvironment.cpp index 6a04b1e..e21281a 100644 --- a/source/Irrlicht/CGUIEnvironment.cpp +++ b/source/Irrlicht/CGUIEnvironment.cpp @@ -39,7 +39,6 @@ #include "CDefaultGUIElementFactory.h" #include "IWriteFile.h" -#include "IXMLWriter.h" #include "BuiltInFont.h" #include "os.h" @@ -49,10 +48,6 @@ namespace irr namespace gui { -const wchar_t IRR_XML_FORMAT_GUI_ENV[] = L"irr_gui"; -const wchar_t IRR_XML_FORMAT_GUI_ELEMENT[] = L"element"; -const wchar_t IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE[] = L"type"; - const io::path CGUIEnvironment::DefaultFontName = "#DefaultFont"; //! constructor @@ -788,22 +783,7 @@ bool CGUIEnvironment::saveGUI(const io::path& filename, IGUIElement* start) //! Saves the current gui into a file. bool CGUIEnvironment::saveGUI(io::IWriteFile* file, IGUIElement* start) { - if (!file) - { - return false; - } - - io::IXMLWriter* writer = FileSystem->createXMLWriter(file); - if (!writer) - { - return false; - } - - writer->writeXMLHeader(); - writeGUIElement(writer, start ? start : this); - writer->drop(); - - return true; + return false; } @@ -828,170 +808,7 @@ bool CGUIEnvironment::loadGUI(const io::path& filename, IGUIElement* parent) //! Loads the gui. Note that the current gui is not cleared before. bool CGUIEnvironment::loadGUI(io::IReadFile* file, IGUIElement* parent) { - if (!file) - { - os::Printer::log("Unable to open GUI file", ELL_ERROR); - return false; - } - - io::IXMLReader* reader = FileSystem->createXMLReader(file); - if (!reader) - { - os::Printer::log("GUI is not a valid XML file", file->getFileName(), ELL_ERROR); - return false; - } - - // read file - while(reader->read()) - { - readGUIElement(reader, parent); - } - - // finish up - - reader->drop(); - return true; -} - - -//! reads an element -void CGUIEnvironment::readGUIElement(io::IXMLReader* reader, IGUIElement* node) -{ - if (!reader) - return; - - io::EXML_NODE nodeType = reader->getNodeType(); - - if (nodeType == io::EXN_NONE || nodeType == io::EXN_UNKNOWN || nodeType == io::EXN_ELEMENT_END) - return; - - IGUIElement* deferedNode = 0; - if (!wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName())) - { - // GuiEnvironment always must be this as it would serialize into a wrong element otherwise. - // So we use the given node next time - if ( node && node != this ) - deferedNode = node; - node = this; // root - } - else if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName())) - { - // find node type and create it - const core::stringc attrName = reader->getAttributeValue(IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE); - - node = addGUIElement(attrName.c_str(), node); - - if (!node) - os::Printer::log("Could not create GUI element of unknown type", attrName.c_str()); - } - - // read attributes - - while(reader->read()) - { - bool endreached = false; - - switch (reader->getNodeType()) - { - case io::EXN_ELEMENT_END: - if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName()) || - !wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName())) - { - endreached = true; - } - break; - case io::EXN_ELEMENT: - if (!wcscmp(L"attributes", reader->getNodeName())) - { - // read attributes - io::IAttributes* attr = FileSystem->createEmptyAttributes(Driver); - attr->read(reader, true); - - if (node) - node->deserializeAttributes(attr); - - attr->drop(); - } - else - if (!wcscmp(IRR_XML_FORMAT_GUI_ELEMENT, reader->getNodeName()) || - !wcscmp(IRR_XML_FORMAT_GUI_ENV, reader->getNodeName())) - { - if ( deferedNode ) - readGUIElement(reader, deferedNode); - else - readGUIElement(reader, node); - } - else - { - os::Printer::log("Found unknown element in irrlicht GUI file", - core::stringc(reader->getNodeName()).c_str()); - } - - break; - default: - break; - } - - if (endreached) - break; - } -} - - -//! writes an element -void CGUIEnvironment::writeGUIElement(io::IXMLWriter* writer, IGUIElement* node) -{ - if (!writer || !node ) - return; - - const wchar_t* name = 0; - - // write properties - - io::IAttributes* attr = FileSystem->createEmptyAttributes(); - node->serializeAttributes(attr); - - // all gui elements must have at least one attribute - // if they have nothing then we ignore them. - if (attr->getAttributeCount() != 0) - { - if (node == this) - { - name = IRR_XML_FORMAT_GUI_ENV; - writer->writeElement(name, false); - } - else - { - name = IRR_XML_FORMAT_GUI_ELEMENT; - writer->writeElement(name, false, IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE, - core::stringw(node->getTypeName()).c_str()); - } - - writer->writeLineBreak(); - - attr->write(writer); - } - - // write children - - core::list::ConstIterator it = node->getChildren().begin(); - for (; it != node->getChildren().end(); ++it) - { - if (!(*it)->isSubElement()) - { - writer->writeLineBreak(); - writeGUIElement(writer, (*it)); - } - } - - // write closing brace if required - if (attr->getAttributeCount() != 0) - { - writer->writeClosingTag(name); - writer->writeLineBreak(); - } - - attr->drop(); + return false; } @@ -1460,35 +1277,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename) } IGUIFont* ifont=0; - io::IXMLReader *xml = FileSystem->createXMLReader(filename ); - if (xml) - { - // this is an XML font, but we need to know what type - EGUI_FONT_TYPE t = EGFT_CUSTOM; - - bool found=false; - while(!found && xml->read()) - { - if (xml->getNodeType() == io::EXN_ELEMENT) - { - if (core::stringw(L"font") == xml->getNodeName()) - { - if (core::stringw(L"vector") == xml->getAttributeValue(L"type")) - { - t = EGFT_VECTOR; - found=true; - } - else if (core::stringw(L"bitmap") == xml->getAttributeValue(L"type")) - { - t = EGFT_BITMAP; - found=true; - } - else found=true; - } - } - } - - if (t==EGFT_BITMAP) +#if 0 { CGUIFont* font = new CGUIFont(this, filename); ifont = (IGUIFont*)font; @@ -1503,17 +1292,7 @@ IGUIFont* CGUIEnvironment::getFont(const io::path& filename) ifont = 0; } } - else if (t==EGFT_VECTOR) - { - // todo: vector fonts - os::Printer::log("Unable to load font, XML vector fonts are not supported yet", f.NamedPath, ELL_ERROR); - - //CGUIFontVector* font = new CGUIFontVector(Driver); - //ifont = (IGUIFont*)font; - //if (!font->load(xml)) - } - xml->drop(); - } +#endif if (!ifont) diff --git a/source/Irrlicht/CGUIEnvironment.h b/source/Irrlicht/CGUIEnvironment.h index e87e236..1867138 100644 --- a/source/Irrlicht/CGUIEnvironment.h +++ b/source/Irrlicht/CGUIEnvironment.h @@ -254,12 +254,6 @@ public: //! Reads attributes of the environment. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_; - //! writes an element - virtual void writeGUIElement(io::IXMLWriter* writer, IGUIElement* node) _IRR_OVERRIDE_; - - //! reads an element - virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* node) _IRR_OVERRIDE_; - //! Find the next element which would be selected when pressing the tab-key virtual IGUIElement* getNextElement(bool reverse=false, bool group=false) _IRR_OVERRIDE_; diff --git a/source/Irrlicht/CGUIFont.cpp b/source/Irrlicht/CGUIFont.cpp index 0fa8298..a3fd107 100644 --- a/source/Irrlicht/CGUIFont.cpp +++ b/source/Irrlicht/CGUIFont.cpp @@ -8,7 +8,6 @@ #include "os.h" #include "coreutil.h" #include "IGUIEnvironment.h" -#include "IXMLReader.h" #include "IReadFile.h" #include "IVideoDriver.h" #include "IGUISpriteBank.h" @@ -63,6 +62,7 @@ CGUIFont::~CGUIFont() } +#if 0 //! loads a font file from xml bool CGUIFont::load(io::IXMLReader* xml, const io::path& directory) { @@ -195,6 +195,7 @@ bool CGUIFont::load(io::IXMLReader* xml, const io::path& directory) return true; } +#endif void CGUIFont::setMaxHeight() diff --git a/source/Irrlicht/CGUIFont.h b/source/Irrlicht/CGUIFont.h index c88441e..238e301 100644 --- a/source/Irrlicht/CGUIFont.h +++ b/source/Irrlicht/CGUIFont.h @@ -11,7 +11,6 @@ #include "IGUIFontBitmap.h" #include "irrString.h" #include "irrMap.h" -#include "IXMLReader.h" #include "IReadFile.h" #include "irrArray.h" @@ -45,10 +44,6 @@ public: //! loads a font from a texture file bool load(io::IReadFile* file); - //! loads a font from an XML file - //\param directory Directory in which the bitmaps can be found - bool load(io::IXMLReader* xml, const io::path& directory); - //! draws an text and clips it to the specified rectangle if wanted virtual void draw(const core::stringw& text, const core::rect& position, video::SColor color, bool hcenter=false, diff --git a/source/Irrlicht/CIrrMeshFileLoader.cpp b/source/Irrlicht/CIrrMeshFileLoader.cpp deleted file mode 100644 index f92b2dc..0000000 --- a/source/Irrlicht/CIrrMeshFileLoader.cpp +++ /dev/null @@ -1,556 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "IrrCompileConfig.h" -#ifdef _IRR_COMPILE_WITH_IRR_MESH_LOADER_ - -#include "CIrrMeshFileLoader.h" -#include "os.h" -#include "IXMLReader.h" -#include "SAnimatedMesh.h" -#include "fast_atof.h" -#include "IReadFile.h" -#include "IAttributes.h" -#include "IMeshSceneNode.h" -#include "CDynamicMeshBuffer.h" -#include "SMeshBufferLightMap.h" - -namespace irr -{ -namespace scene -{ - - -//! Constructor -CIrrMeshFileLoader::CIrrMeshFileLoader(scene::ISceneManager* smgr, - io::IFileSystem* fs) - : SceneManager(smgr), FileSystem(fs) -{ - - #ifdef _DEBUG - setDebugName("CIrrMeshFileLoader"); - #endif - -} - - -//! Returns true if the file maybe is able to be loaded by this class. -/** This decision should be based only on the file extension (e.g. ".cob") */ -bool CIrrMeshFileLoader::isALoadableFileExtension(const io::path& filename) const -{ - return core::hasFileExtension ( filename, "xml", "irrmesh" ); -} - - -//! creates/loads an animated mesh from the file. -//! \return Pointer to the created mesh. Returns 0 if loading failed. -//! If you no longer need the mesh, you should call IAnimatedMesh::drop(). -//! See IReferenceCounted::drop() for more information. -IAnimatedMesh* CIrrMeshFileLoader::createMesh(io::IReadFile* file) -{ - io::IXMLReader* reader = FileSystem->createXMLReader(file); - if (!reader) - return 0; - - // read until mesh section, skip other parts - - const core::stringc meshTagName = "mesh"; - IAnimatedMesh* mesh = 0; - - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - if (meshTagName == reader->getNodeName()) - { - mesh = readMesh(reader); - break; - } - else - skipSection(reader, true); // unknown section - } - } - - reader->drop(); - - return mesh; -} - - -//! reads a mesh sections and creates a mesh from it -IAnimatedMesh* CIrrMeshFileLoader::readMesh(io::IXMLReader* reader) -{ - SAnimatedMesh* animatedmesh = new SAnimatedMesh(); - SMesh* mesh = new SMesh(); - - animatedmesh->addMesh(mesh); - mesh->drop(); - - core::stringc bbSectionName = "boundingBox"; - core::stringc bufferSectionName = "buffer"; - core::stringc meshSectionName = "mesh"; - - if (!reader->isEmptyElement()) - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - const wchar_t* nodeName = reader->getNodeName(); - if (bbSectionName == nodeName) - { - // inside a bounding box, ignore it for now because - // we are calculating this anyway ourselves later. - } - else - if (bufferSectionName == nodeName) - { - // we've got a mesh buffer - - IMeshBuffer* buffer = readMeshBuffer(reader); - if (buffer) - { - mesh->addMeshBuffer(buffer); - buffer->drop(); - } - } - else - skipSection(reader, true); // unknown section - - } // end if node type is element - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (meshSectionName == reader->getNodeName()) - { - // end of mesh section reached, cancel out - break; - } - } - } // end while reader->read(); - - mesh->recalculateBoundingBox(); - animatedmesh->recalculateBoundingBox(); - - return animatedmesh; -} - - -//! reads a mesh sections and creates a mesh buffer from it -IMeshBuffer* CIrrMeshFileLoader::readMeshBuffer(io::IXMLReader* reader) -{ - CDynamicMeshBuffer* buffer = 0; - - core::stringc verticesSectionName = "vertices"; - core::stringc bbSectionName = "boundingBox"; - core::stringc materialSectionName = "material"; - core::stringc indicesSectionName = "indices"; - core::stringc bufferSectionName = "buffer"; - - bool insideVertexSection = false; - bool insideIndexSection = false; - - int vertexCount = 0; - int indexCount = 0; - - video::SMaterial material; - - if (!reader->isEmptyElement()) - while(reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT) - { - const wchar_t* nodeName = reader->getNodeName(); - if (bbSectionName == nodeName) - { - // inside a bounding box, ignore it for now because - // we are calculating this anyway ourselves later. - } - else - if (materialSectionName == nodeName) - { - //we've got a material - - material = video::SMaterial(); // reset - - io::IAttributes* attributes = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver()); - attributes->read(reader, true, L"material"); - - SceneManager->getVideoDriver()->fillMaterialStructureFromAttributes(material, attributes); - attributes->drop(); - } - else - if (verticesSectionName == nodeName) - { - // vertices section - - const core::stringc vertexTypeName1 = "standard"; - const core::stringc vertexTypeName2 = "2tcoords"; - const core::stringc vertexTypeName3 = "tangents"; - - const wchar_t* vertexType = reader->getAttributeValue(L"type"); - vertexCount = reader->getAttributeValueAsInt(L"vertexCount"); - - insideVertexSection = true; - - video::E_INDEX_TYPE itype = (vertexCount > 65536)?irr::video::EIT_32BIT:irr::video::EIT_16BIT; - if (vertexTypeName1 == vertexType) - { - buffer = new CDynamicMeshBuffer(irr::video::EVT_STANDARD, itype); - - } - else - if (vertexTypeName2 == vertexType) - { - buffer = new CDynamicMeshBuffer(irr::video::EVT_2TCOORDS, itype); - } - else - if (vertexTypeName3 == vertexType) - { - buffer = new CDynamicMeshBuffer(irr::video::EVT_TANGENTS, itype); - } - buffer->getVertexBuffer().reallocate(vertexCount); - buffer->Material = material; - } - else - if (indicesSectionName == nodeName) - { - // indices section - - indexCount = reader->getAttributeValueAsInt(L"indexCount"); - insideIndexSection = true; - } - - } // end if node type is element - else - if (reader->getNodeType() == io::EXN_TEXT) - { - // read vertex data - if (insideVertexSection) - { - readMeshBuffer(reader, vertexCount, buffer); - insideVertexSection = false; - - } // end reading vertex array - else - if (insideIndexSection) - { - readIndices(reader, indexCount, buffer->getIndexBuffer()); - insideIndexSection = false; - } - - } // end if node type is text - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - { - if (bufferSectionName == reader->getNodeName()) - { - // end of buffer section reached, cancel out - break; - } - } - } // end while reader->read(); - - if (buffer) - buffer->recalculateBoundingBox(); - - return buffer; -} - - -//! read indices -void CIrrMeshFileLoader::readIndices(io::IXMLReader* reader, int indexCount, IIndexBuffer& indices) -{ - indices.reallocate(indexCount); - - core::stringc data = reader->getNodeData(); - const c8* p = &data[0]; - - for (int i=0; igetNodeData(); - const c8* p = &data[0]; - scene::IVertexBuffer& Vertices = sbuffer->getVertexBuffer(); - video::E_VERTEX_TYPE vType = Vertices.getType(); - - if (sbuffer) - { - for (int i=0; igetNodeName()).c_str()); -#endif - - // skip if this element is empty anyway. - if (reader->isEmptyElement()) - return; - - // read until we've reached the last element in this section - u32 tagCounter = 1; - - while(tagCounter && reader->read()) - { - if (reader->getNodeType() == io::EXN_ELEMENT && - !reader->isEmptyElement()) - { - #ifdef _DEBUG - if (reportSkipping) - os::Printer::log("irrMesh unknown element:", core::stringc(reader->getNodeName()).c_str()); - #endif - - ++tagCounter; - } - else - if (reader->getNodeType() == io::EXN_ELEMENT_END) - --tagCounter; - } -} - - -//! parses a float from a char pointer and moves the pointer -//! to the end of the parsed float -inline f32 CIrrMeshFileLoader::readFloat(const c8** p) -{ - f32 ftmp; - *p = core::fast_atof_move(*p, ftmp); - return ftmp; -} - - -//! parses an int from a char pointer and moves the pointer to -//! the end of the parsed float -inline s32 CIrrMeshFileLoader::readInt(const c8** p) -{ - return (s32)readFloat(p); -} - - -//! places pointer to next begin of a token -void CIrrMeshFileLoader::skipCurrentNoneWhiteSpace(const c8** start) -{ - const c8* p = *start; - - while(*p && !(*p==' ' || *p=='\n' || *p=='\r' || *p=='\t')) - ++p; - - // TODO: skip comments - - *start = p; -} - -//! places pointer to next begin of a token -void CIrrMeshFileLoader::findNextNoneWhiteSpace(const c8** start) -{ - const c8* p = *start; - - while(*p && (*p==' ' || *p=='\n' || *p=='\r' || *p=='\t')) - ++p; - - // TODO: skip comments - - *start = p; -} - - -//! reads floats from inside of xml element until end of xml element -void CIrrMeshFileLoader::readFloatsInsideElement(io::IXMLReader* reader, f32* floats, u32 count) -{ - if (reader->isEmptyElement()) - return; - - while(reader->read()) - { - // TODO: check for comments inside the element - // and ignore them. - - if (reader->getNodeType() == io::EXN_TEXT) - { - // parse float data - core::stringc data = reader->getNodeData(); - const c8* p = &data[0]; - - for (u32 i=0; igetNodeType() == io::EXN_ELEMENT_END) - break; // end parsing text - } -} - - - - -} // end namespace scene -} // end namespace irr - -#endif // _IRR_COMPILE_WITH_IRR_MESH_LOADER_ diff --git a/source/Irrlicht/CIrrMeshFileLoader.h b/source/Irrlicht/CIrrMeshFileLoader.h deleted file mode 100644 index c190844..0000000 --- a/source/Irrlicht/CIrrMeshFileLoader.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __C_IRR_MESH_FILE_LOADER_H_INCLUDED__ -#define __C_IRR_MESH_FILE_LOADER_H_INCLUDED__ - -#include "IMeshLoader.h" -#include "IFileSystem.h" -#include "IVideoDriver.h" -#include "irrString.h" -#include "SMesh.h" -#include "SMeshBuffer.h" -#include "CDynamicMeshBuffer.h" -#include "ISceneManager.h" - -namespace irr -{ -namespace scene -{ - - -//! Meshloader capable of loading .irrmesh meshes, the Irrlicht Engine mesh format for static meshes -class CIrrMeshFileLoader : public IMeshLoader -{ -public: - - //! Constructor - CIrrMeshFileLoader(scene::ISceneManager* smgr, io::IFileSystem* fs); - - //! returns true if the file maybe is able to be loaded by this class - //! based on the file extension (e.g. ".cob") - virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_; - - //! creates/loads an animated mesh from the file. - //! \return Pointer to the created mesh. Returns 0 if loading failed. - //! If you no longer need the mesh, you should call IAnimatedMesh::drop(). - //! See IReferenceCounted::drop() for more information. - virtual IAnimatedMesh* createMesh(io::IReadFile* file) _IRR_OVERRIDE_; - -private: - - //! reads a mesh sections and creates a mesh from it - IAnimatedMesh* readMesh(io::IXMLReader* reader); - - //! reads a mesh sections and creates a mesh buffer from it - IMeshBuffer* readMeshBuffer(io::IXMLReader* reader); - - //! skips an (unknown) section in the irrmesh file - void skipSection(io::IXMLReader* reader, bool reportSkipping); - - //! reads a element and stores it in the material section - void readMaterial(io::IXMLReader* reader); - - //! parses a float from a char pointer and moves the pointer to - //! the end of the parsed float - inline f32 readFloat(const c8** p); - - //! parses an int from a char pointer and moves the pointer to - //! the end of the parsed float - inline s32 readInt(const c8** p); - - //! places pointer to next begin of a token - void findNextNoneWhiteSpace(const c8** p); - - //! places pointer to next begin of a token - void skipCurrentNoneWhiteSpace(const c8** p); - - //! reads floats from inside of xml element until end of xml element - void readFloatsInsideElement(io::IXMLReader* reader, f32* floats, u32 count); - - //! read the mesh buffers - void readMeshBuffer(io::IXMLReader* reader, int vertexCount, CDynamicMeshBuffer* sbuffer); - - //! read indices - void readIndices(io::IXMLReader* reader, int indexCount, IIndexBuffer& indices); - - - // member variables - - scene::ISceneManager* SceneManager; - io::IFileSystem* FileSystem; -}; - - -} // end namespace scene -} // end namespace irr - -#endif - diff --git a/source/Irrlicht/CIrrMeshWriter.cpp b/source/Irrlicht/CIrrMeshWriter.cpp deleted file mode 100644 index cb33fe9..0000000 --- a/source/Irrlicht/CIrrMeshWriter.cpp +++ /dev/null @@ -1,312 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "IrrCompileConfig.h" - -#ifdef _IRR_COMPILE_WITH_IRR_WRITER_ - -#include "CIrrMeshWriter.h" -#include "os.h" -#include "IWriteFile.h" -#include "IXMLWriter.h" -#include "IMesh.h" -#include "IAttributes.h" - -namespace irr -{ -namespace scene -{ - - -CIrrMeshWriter::CIrrMeshWriter(video::IVideoDriver* driver, - io::IFileSystem* fs) - : FileSystem(fs), VideoDriver(driver), Writer(0) -{ - #ifdef _DEBUG - setDebugName("CIrrMeshWriter"); - #endif - - if (VideoDriver) - VideoDriver->grab(); - - if (FileSystem) - FileSystem->grab(); -} - - -CIrrMeshWriter::~CIrrMeshWriter() -{ - if (VideoDriver) - VideoDriver->drop(); - - if (FileSystem) - FileSystem->drop(); -} - - -//! Returns the type of the mesh writer -EMESH_WRITER_TYPE CIrrMeshWriter::getType() const -{ - return EMWT_IRR_MESH; -} - - -//! writes a mesh -bool CIrrMeshWriter::writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags) -{ - if (!file) - return false; - - Writer = FileSystem->createXMLWriter(file); - - if (!Writer) - { - os::Printer::log("Could not write file", file->getFileName()); - return false; - } - - os::Printer::log("Writing mesh", file->getFileName()); - - // write IRR MESH header - - Writer->writeXMLHeader(); - - Writer->writeElement(L"mesh", false, - L"xmlns", L"http://irrlicht.sourceforge.net/IRRMESH_09_2007", - L"version", L"1.0"); - Writer->writeLineBreak(); - - // add some informational comment. Add a space after and before the comment - // tags so that some braindead xml parsers (AS anyone?) are able to parse this too. - - core::stringw infoComment = L" This file contains a static mesh in the Irrlicht Engine format with "; - infoComment += core::stringw(mesh->getMeshBufferCount()); - infoComment += L" materials."; - - Writer->writeComment(infoComment.c_str()); - Writer->writeLineBreak(); - - // write mesh bounding box - - writeBoundingBox(mesh->getBoundingBox()); - Writer->writeLineBreak(); - - // write mesh buffers - - for (int i=0; i<(int)mesh->getMeshBufferCount(); ++i) - { - scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i); - if (buffer) - { - writeMeshBuffer(buffer); - Writer->writeLineBreak(); - } - } - - Writer->writeClosingTag(L"mesh"); - - Writer->drop(); - return true; -} - - -void CIrrMeshWriter::writeBoundingBox(const core::aabbox3df& box) -{ - Writer->writeElement(L"boundingBox", true, - L"minEdge", getVectorAsStringLine(box.MinEdge).c_str(), - L"maxEdge", getVectorAsStringLine(box.MaxEdge).c_str()); -} - - -core::stringw CIrrMeshWriter::getVectorAsStringLine(const core::vector3df& v) const -{ - core::stringw str; - - str = core::stringw(v.X); - str += L" "; - str += core::stringw(v.Y); - str += L" "; - str += core::stringw(v.Z); - - return str; -} - - -core::stringw CIrrMeshWriter::getVectorAsStringLine(const core::vector2df& v) const -{ - core::stringw str; - - str = core::stringw(v.X); - str += L" "; - str += core::stringw(v.Y); - - return str; -} - - -void CIrrMeshWriter::writeMeshBuffer(const scene::IMeshBuffer* buffer) -{ - Writer->writeElement(L"buffer", false); - Writer->writeLineBreak(); - - // write bounding box - - writeBoundingBox(buffer->getBoundingBox()); - Writer->writeLineBreak(); - - // write material - - writeMaterial(buffer->getMaterial()); - - // write vertices - - const core::stringw vertexTypeStr = video::sBuiltInVertexTypeNames[buffer->getVertexType()]; - - Writer->writeElement(L"vertices", false, - L"type", vertexTypeStr.c_str(), - L"vertexCount", core::stringw(buffer->getVertexCount()).c_str()); - - Writer->writeLineBreak(); - - u32 vertexCount = buffer->getVertexCount(); - - switch(buffer->getVertexType()) - { - case video::EVT_STANDARD: - { - video::S3DVertex* vtx = (video::S3DVertex*)buffer->getVertices(); - for (u32 j=0; jwriteText(str.c_str()); - Writer->writeLineBreak(); - } - } - break; - case video::EVT_2TCOORDS: - { - video::S3DVertex2TCoords* vtx = (video::S3DVertex2TCoords*)buffer->getVertices(); - for (u32 j=0; jwriteText(str.c_str()); - Writer->writeLineBreak(); - } - } - break; - case video::EVT_TANGENTS: - { - video::S3DVertexTangents* vtx = (video::S3DVertexTangents*)buffer->getVertices(); - for (u32 j=0; jwriteText(str.c_str()); - Writer->writeLineBreak(); - } - } - break; - } - - Writer->writeClosingTag(L"vertices"); - Writer->writeLineBreak(); - - // write indices - - Writer->writeElement(L"indices", false, - L"indexCount", core::stringw(buffer->getIndexCount()).c_str()); - - Writer->writeLineBreak(); - - int indexCount = (int)buffer->getIndexCount(); - - video::E_INDEX_TYPE iType = buffer->getIndexType(); - - const u16* idx16 = buffer->getIndices(); - const u32* idx32 = (u32*) buffer->getIndices(); - const int maxIndicesPerLine = 25; - - for (int i=0; iwriteText(str.c_str()); - } - else - { - core::stringw str((int)idx32[i]); - Writer->writeText(str.c_str()); - } - - if (i % maxIndicesPerLine == maxIndicesPerLine-1) - Writer->writeLineBreak(); - else - Writer->writeText(L" "); - } - - if ((indexCount-1) % maxIndicesPerLine != maxIndicesPerLine-1) - Writer->writeLineBreak(); - - Writer->writeClosingTag(L"indices"); - Writer->writeLineBreak(); - - // close buffer tag - - Writer->writeClosingTag(L"buffer"); -} - - -void CIrrMeshWriter::writeMaterial(const video::SMaterial& material) -{ - // simply use irrlichts built-in attribute serialization capabilities here: - - io::IAttributes* attributes = - VideoDriver->createAttributesFromMaterial(material); - - if (attributes) - { - attributes->write(Writer, false, L"material"); - attributes->drop(); - } -} - - -} // end namespace -} // end namespace - -#endif - diff --git a/source/Irrlicht/CIrrMeshWriter.h b/source/Irrlicht/CIrrMeshWriter.h deleted file mode 100644 index c69d8bf..0000000 --- a/source/Irrlicht/CIrrMeshWriter.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __IRR_IRR_MESH_WRITER_H_INCLUDED__ -#define __IRR_IRR_MESH_WRITER_H_INCLUDED__ - -#include "IMeshWriter.h" -#include "S3DVertex.h" -#include "IVideoDriver.h" -#include "IFileSystem.h" -#include "IXMLWriter.h" - -namespace irr -{ - -namespace scene -{ - class IMeshBuffer; - - - //! class to write meshes, implementing a IrrMesh (.irrmesh, .xml) writer - /** This writer implementation has been originally developed for irrEdit and then - merged out to the Irrlicht Engine */ - class CIrrMeshWriter : public IMeshWriter - { - public: - - CIrrMeshWriter(video::IVideoDriver* driver, io::IFileSystem* fs); - virtual ~CIrrMeshWriter(); - - //! Returns the type of the mesh writer - virtual EMESH_WRITER_TYPE getType() const _IRR_OVERRIDE_; - - //! writes a mesh - virtual bool writeMesh(io::IWriteFile* file, scene::IMesh* mesh, s32 flags=EMWF_NONE) _IRR_OVERRIDE_; - - protected: - - void writeBoundingBox(const core::aabbox3df& box); - - void writeMeshBuffer(const scene::IMeshBuffer* buffer); - - void writeMaterial(const video::SMaterial& material); - - core::stringw getVectorAsStringLine(const core::vector3df& v) const; - - core::stringw getVectorAsStringLine(const core::vector2df& v) const; - - // member variables: - - io::IFileSystem* FileSystem; - video::IVideoDriver* VideoDriver; - io::IXMLWriter* Writer; - }; - -} // end namespace -} // end namespace - -#endif - diff --git a/source/Irrlicht/CMakeLists.txt b/source/Irrlicht/CMakeLists.txt index 7492c09..38dbbac 100644 --- a/source/Irrlicht/CMakeLists.txt +++ b/source/Irrlicht/CMakeLists.txt @@ -110,14 +110,12 @@ set(IRRMESHLOADER C3DSMeshFileLoader.cpp COgreMeshFileLoader.cpp COBJMeshFileLoader.cpp - CColladaFileLoader.cpp CCSMLoader.cpp CDMFLoader.cpp CLMTSMeshFileLoader.cpp CMY3DMeshFileLoader.cpp COCTLoader.cpp CXMeshFileLoader.cpp - CIrrMeshFileLoader.cpp CSTLMeshFileLoader.cpp CLWOMeshFileLoader.cpp CPLYMeshFileLoader.cpp @@ -126,8 +124,6 @@ set(IRRMESHLOADER ) set(IRRMESHWRITER - CColladaMeshWriter.cpp - CIrrMeshWriter.cpp CSTLMeshWriter.cpp COBJMeshWriter.cpp CPLYMeshWriter.cpp @@ -176,7 +172,6 @@ add_library(IRROBJ OBJECT CMeshCache.cpp CDefaultSceneNodeAnimatorFactory.cpp CDefaultSceneNodeFactory.cpp - CSceneLoaderIrr.cpp ) add_library(IRRPARTICLEOBJ OBJECT @@ -318,15 +313,12 @@ add_library(IRRIOOBJ OBJECT CMemoryFile.cpp CReadFile.cpp CWriteFile.cpp - CXMLReader.cpp - CXMLWriter.cpp CWADReader.cpp CZipReader.cpp CPakReader.cpp CNPKReader.cpp CTarReader.cpp CMountPointReader.cpp - irrXML.cpp CAttributes.cpp ) diff --git a/source/Irrlicht/CSceneLoaderIrr.cpp b/source/Irrlicht/CSceneLoaderIrr.cpp deleted file mode 100644 index 7705436..0000000 --- a/source/Irrlicht/CSceneLoaderIrr.cpp +++ /dev/null @@ -1,284 +0,0 @@ -// Copyright (C) 2010-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "CSceneLoaderIrr.h" -#include "ISceneNodeAnimatorFactory.h" -#include "ISceneUserDataSerializer.h" -#include "ISceneManager.h" -#include "IVideoDriver.h" -#include "IFileSystem.h" -#include "os.h" - -namespace irr -{ -namespace scene -{ - -//! Constructor -CSceneLoaderIrr::CSceneLoaderIrr(ISceneManager *smgr, io::IFileSystem* fs) - : SceneManager(smgr), FileSystem(fs), - IRR_XML_FORMAT_SCENE(L"irr_scene"), IRR_XML_FORMAT_NODE(L"node"), IRR_XML_FORMAT_NODE_ATTR_TYPE(L"type"), - IRR_XML_FORMAT_ATTRIBUTES(L"attributes"), IRR_XML_FORMAT_MATERIALS(L"materials"), - IRR_XML_FORMAT_ANIMATORS(L"animators"), IRR_XML_FORMAT_USERDATA(L"userData") -{ - -} - -//! Destructor -CSceneLoaderIrr::~CSceneLoaderIrr() -{ - -} - -//! Returns true if the class might be able to load this file. -bool CSceneLoaderIrr::isALoadableFileExtension(const io::path& filename) const -{ - return core::hasFileExtension(filename, "irr"); -} - -//! Returns true if the class might be able to load this file. -bool CSceneLoaderIrr::isALoadableFileFormat(io::IReadFile *file) const -{ - // todo: check inside the file - return true; -} - -//! Loads the scene into the scene manager. -bool CSceneLoaderIrr::loadScene(io::IReadFile* file, ISceneUserDataSerializer* userDataSerializer, - ISceneNode* rootNode) -{ - if (!file) - { - os::Printer::log("Unable to open scene file", ELL_ERROR); - return false; - } - - io::IXMLReader* reader = FileSystem->createXMLReader(file); - if (!reader) - { - os::Printer::log("Scene is not a valid XML file", file->getFileName().c_str(), ELL_ERROR); - return false; - } - - // TODO: COLLADA_CREATE_SCENE_INSTANCES can be removed when the COLLADA loader is a scene loader - bool oldColladaSingleMesh = SceneManager->getParameters()->getAttributeAsBool(COLLADA_CREATE_SCENE_INSTANCES); - SceneManager->getParameters()->setAttribute(COLLADA_CREATE_SCENE_INSTANCES, false); - - // read file - while (reader->read()) - { - readSceneNode(reader, rootNode, userDataSerializer); - } - - // restore old collada parameters - SceneManager->getParameters()->setAttribute(COLLADA_CREATE_SCENE_INSTANCES, oldColladaSingleMesh); - - // clean up - reader->drop(); - return true; -} - - -//! Reads the next node -void CSceneLoaderIrr::readSceneNode(io::IXMLReader* reader, ISceneNode* parent, - ISceneUserDataSerializer* userDataSerializer) -{ - if (!reader) - return; - - scene::ISceneNode* node = 0; - - if (!parent && IRR_XML_FORMAT_SCENE==reader->getNodeName()) - node = SceneManager->getRootSceneNode(); - else if (parent && IRR_XML_FORMAT_NODE==reader->getNodeName()) - { - // find node type and create it - core::stringc attrName = reader->getAttributeValue(IRR_XML_FORMAT_NODE_ATTR_TYPE.c_str()); - - node = SceneManager->addSceneNode(attrName.c_str(), parent); - - if (!node) - os::Printer::log("Could not create scene node of unknown type", attrName.c_str()); - } - else - node=parent; - - // read attributes - while(reader->read()) - { - bool endreached = false; - - const wchar_t* name = reader->getNodeName(); - - switch (reader->getNodeType()) - { - case io::EXN_ELEMENT_END: - if ((IRR_XML_FORMAT_NODE == name) || - (IRR_XML_FORMAT_SCENE == name)) - { - endreached = true; - } - break; - case io::EXN_ELEMENT: - if (IRR_XML_FORMAT_ATTRIBUTES == name) - { - // read attributes - io::IAttributes* attr = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver()); - attr->read(reader, true); - - if (node) - node->deserializeAttributes(attr); - - attr->drop(); - } - else - if (IRR_XML_FORMAT_MATERIALS == name) - readMaterials(reader, node); - else - if (IRR_XML_FORMAT_ANIMATORS == name) - readAnimators(reader, node); - else - if (IRR_XML_FORMAT_USERDATA == name) - readUserData(reader, node, userDataSerializer); - else - if ((IRR_XML_FORMAT_NODE == name) || - (IRR_XML_FORMAT_SCENE == name)) - { - readSceneNode(reader, node, userDataSerializer); - } - else - { - os::Printer::log("Found unknown element in irrlicht scene file", - core::stringc(name).c_str()); - } - break; - default: - break; - } - - if (endreached) - break; - } - if (node && userDataSerializer) - userDataSerializer->OnCreateNode(node); -} - -//! reads materials of a node -void CSceneLoaderIrr::readMaterials(io::IXMLReader* reader, ISceneNode* node) -{ - u32 nr = 0; - - while(reader->read()) - { - const wchar_t* name = reader->getNodeName(); - - switch(reader->getNodeType()) - { - case io::EXN_ELEMENT_END: - if (IRR_XML_FORMAT_MATERIALS == name) - return; - break; - case io::EXN_ELEMENT: - if (IRR_XML_FORMAT_ATTRIBUTES == name) - { - // read materials from attribute list - io::IAttributes* attr = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver()); - attr->read(reader); - - if (node && node->getMaterialCount() > nr) - { - SceneManager->getVideoDriver()->fillMaterialStructureFromAttributes( - node->getMaterial(nr), attr); - } - - attr->drop(); - ++nr; - } - break; - default: - break; - } - } -} - - -//! reads animators of a node -void CSceneLoaderIrr::readAnimators(io::IXMLReader* reader, ISceneNode* node) -{ - while(reader->read()) - { - const wchar_t* name = reader->getNodeName(); - - switch(reader->getNodeType()) - { - case io::EXN_ELEMENT_END: - if (IRR_XML_FORMAT_ANIMATORS == name) - return; - break; - case io::EXN_ELEMENT: - if (IRR_XML_FORMAT_ATTRIBUTES == name) - { - // read animator data from attribute list - io::IAttributes* attr = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver()); - attr->read(reader); - - if (node) - { - core::stringc typeName = attr->getAttributeAsString("Type"); - ISceneNodeAnimator* anim = SceneManager->createSceneNodeAnimator(typeName.c_str(), node); - - if (anim) - { - anim->deserializeAttributes(attr); - anim->drop(); - } - } - - attr->drop(); - } - break; - default: - break; - } - } -} - - -//! reads user data of a node -void CSceneLoaderIrr::readUserData(io::IXMLReader* reader, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer) -{ - while(reader->read()) - { - const wchar_t* name = reader->getNodeName(); - - switch(reader->getNodeType()) - { - case io::EXN_ELEMENT_END: - if (IRR_XML_FORMAT_USERDATA == name) - return; - break; - case io::EXN_ELEMENT: - if (IRR_XML_FORMAT_ATTRIBUTES == name) - { - // read user data from attribute list - io::IAttributes* attr = FileSystem->createEmptyAttributes(SceneManager->getVideoDriver()); - attr->read(reader); - - if (node && userDataSerializer) - { - userDataSerializer->OnReadUserData(node, attr); - } - - attr->drop(); - } - break; - default: - break; - } - } -} - -} // scene -} // irr - diff --git a/source/Irrlicht/CSceneLoaderIrr.h b/source/Irrlicht/CSceneLoaderIrr.h deleted file mode 100644 index 2ac73e4..0000000 --- a/source/Irrlicht/CSceneLoaderIrr.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2010-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __C_SCENE_LOADER_IRR_H_INCLUDED__ -#define __C_SCENE_LOADER_IRR_H_INCLUDED__ - -#include "ISceneLoader.h" - -#include "IXMLReader.h" - -namespace irr -{ - -namespace io -{ - class IFileSystem; -} - -namespace scene -{ - -class ISceneManager; - -//! Class which can load a scene into the scene manager. -class CSceneLoaderIrr : public virtual ISceneLoader -{ -public: - - //! Constructor - CSceneLoaderIrr(ISceneManager *smgr, io::IFileSystem* fs); - - //! Destructor - virtual ~CSceneLoaderIrr(); - - //! Returns true if the class might be able to load this file. - virtual bool isALoadableFileExtension(const io::path& filename) const _IRR_OVERRIDE_; - - //! Returns true if the class might be able to load this file. - virtual bool isALoadableFileFormat(io::IReadFile *file) const _IRR_OVERRIDE_; - - //! Loads the scene into the scene manager. - virtual bool loadScene(io::IReadFile* file, - ISceneUserDataSerializer* userDataSerializer=0, - ISceneNode* rootNode=0) _IRR_OVERRIDE_; - -private: - - //! Recursively reads nodes from the xml file - void readSceneNode(io::IXMLReader* reader, ISceneNode* parent, - ISceneUserDataSerializer* userDataSerializer); - - //! read a node's materials - void readMaterials(io::IXMLReader* reader, ISceneNode* node); - - //! read a node's animators - void readAnimators(io::IXMLReader* reader, ISceneNode* node); - - //! read any other data into the user serializer - void readUserData(io::IXMLReader* reader, ISceneNode* node, - ISceneUserDataSerializer* userDataSerializer); - - ISceneManager *SceneManager; - io::IFileSystem *FileSystem; - - //! constants for reading and writing XML. - //! Not made static due to portability problems. - // TODO: move to own header - const core::stringw IRR_XML_FORMAT_SCENE; - const core::stringw IRR_XML_FORMAT_NODE; - const core::stringw IRR_XML_FORMAT_NODE_ATTR_TYPE; - const core::stringw IRR_XML_FORMAT_ATTRIBUTES; - const core::stringw IRR_XML_FORMAT_MATERIALS; - const core::stringw IRR_XML_FORMAT_ANIMATORS; - const core::stringw IRR_XML_FORMAT_USERDATA; -}; - - -} // end namespace scene -} // end namespace irr - -#endif - diff --git a/source/Irrlicht/CSceneManager.cpp b/source/Irrlicht/CSceneManager.cpp index e49e0a9..70cb19c 100644 --- a/source/Irrlicht/CSceneManager.cpp +++ b/source/Irrlicht/CSceneManager.cpp @@ -8,7 +8,6 @@ #include "IFileSystem.h" #include "SAnimatedMesh.h" #include "CMeshCache.h" -#include "IXMLWriter.h" #include "ISceneUserDataSerializer.h" #include "IGUIEnvironment.h" #include "IMaterialRenderer.h" @@ -26,10 +25,6 @@ #include "CSkinnedMesh.h" #endif -#ifdef _IRR_COMPILE_WITH_IRR_MESH_LOADER_ -#include "CIrrMeshFileLoader.h" -#endif - #ifdef _IRR_COMPILE_WITH_BSP_LOADER_ #include "CBSPMeshFileLoader.h" #endif @@ -70,10 +65,6 @@ #include "CMY3DMeshFileLoader.h" #endif -#ifdef _IRR_COMPILE_WITH_COLLADA_LOADER_ -#include "CColladaFileLoader.h" -#endif - #ifdef _IRR_COMPILE_WITH_DMF_LOADER_ #include "CDMFLoader.h" #endif @@ -110,18 +101,6 @@ #include "CSMFMeshFileLoader.h" #endif -#ifdef _IRR_COMPILE_WITH_IRR_SCENE_LOADER_ -#include "CSceneLoaderIrr.h" -#endif - -#ifdef _IRR_COMPILE_WITH_COLLADA_WRITER_ -#include "CColladaMeshWriter.h" -#endif - -#ifdef _IRR_COMPILE_WITH_IRR_WRITER_ -#include "CIrrMeshWriter.h" -#endif - #ifdef _IRR_COMPILE_WITH_STL_WRITER_ #include "CSTLMeshWriter.h" #endif @@ -219,8 +198,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, : ISceneNode(0, 0), Driver(driver), FileSystem(fs), GUIEnvironment(gui), CursorControl(cursorControl), CollisionManager(0), ActiveCamera(0), ShadowColor(150,0,0,0), AmbientLight(0,0,0,0), Parameters(0), - MeshCache(cache), CurrentRenderPass(ESNRP_NONE), LightManager(0), - IRR_XML_FORMAT_SCENE(L"irr_scene"), IRR_XML_FORMAT_NODE(L"node"), IRR_XML_FORMAT_NODE_ATTR_TYPE(L"type") + MeshCache(cache), CurrentRenderPass(ESNRP_NONE), LightManager(0) { #ifdef _DEBUG ISceneManager::setDebugName("CSceneManager ISceneManager"); @@ -304,15 +282,9 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, #ifdef _IRR_COMPILE_WITH_MD2_LOADER_ MeshLoaderList.push_back(new CMD2MeshFileLoader()); #endif - #ifdef _IRR_COMPILE_WITH_IRR_MESH_LOADER_ - MeshLoaderList.push_back(new CIrrMeshFileLoader(this, FileSystem)); - #endif #ifdef _IRR_COMPILE_WITH_BSP_LOADER_ MeshLoaderList.push_back(new CBSPMeshFileLoader(this, FileSystem)); #endif - #ifdef _IRR_COMPILE_WITH_COLLADA_LOADER_ - MeshLoaderList.push_back(new CColladaFileLoader(this, FileSystem)); - #endif #ifdef _IRR_COMPILE_WITH_3DS_LOADER_ MeshLoaderList.push_back(new C3DSMeshFileLoader(this, FileSystem)); #endif @@ -329,11 +301,6 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, MeshLoaderList.push_back(new CB3DMeshFileLoader(this)); #endif - // scene loaders - #ifdef _IRR_COMPILE_WITH_IRR_SCENE_LOADER_ - SceneLoaderList.push_back(new CSceneLoaderIrr(this, FileSystem)); - #endif - // factories ISceneNodeFactory* factory = new CDefaultSceneNodeFactory(this); registerSceneNodeFactory(factory); @@ -2298,44 +2265,7 @@ bool CSceneManager::saveScene(const io::path& filename, ISceneUserDataSerializer //! Saves the current scene into a file. bool CSceneManager::saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer, ISceneNode* node) { - if (!file) - { - return false; - } - - bool result=false; - io::IXMLWriter* writer = FileSystem->createXMLWriter(file); - if (!writer) - { - os::Printer::log("Unable to create XML writer", file->getFileName(), ELL_ERROR); - } - else - { - result = saveScene(writer, FileSystem->getFileDir(FileSystem->getAbsolutePath(file->getFileName())), userDataSerializer, node); - writer->drop(); - } - return result; -} - - -//! Saves the current scene into a file. -bool CSceneManager::saveScene(io::IXMLWriter* writer, const io::path& currentPath, ISceneUserDataSerializer* userDataSerializer, ISceneNode* node) -{ - if (!writer) - return false; - - if (!node) - node=this; - - char* oldLocale = setlocale(LC_NUMERIC, NULL); - setlocale(LC_NUMERIC, "C"); // float number should to be saved with dots in this format independent of current locale settings. - - writer->writeXMLHeader(); - writeSceneNode(writer, node, userDataSerializer, currentPath.c_str(), true); - - setlocale(LC_NUMERIC, oldLocale); - - return true; + return false; } @@ -2380,139 +2310,6 @@ bool CSceneManager::loadScene(io::IReadFile* file, ISceneUserDataSerializer* use } -//! writes a scene node -void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer, - const fschar_t* currentPath, bool init) -{ - if (!writer || !node || node->isDebugObject()) - return; - - const wchar_t* name; - ISceneNode* tmpNode=node; - - if (init) - { - name = IRR_XML_FORMAT_SCENE.c_str(); - writer->writeElement(name, false); - node=this; - } - else - { - name = IRR_XML_FORMAT_NODE.c_str(); - writer->writeElement(name, false, IRR_XML_FORMAT_NODE_ATTR_TYPE.c_str(), - core::stringw(getSceneNodeTypeName(node->getType())).c_str()); - } - - writer->writeLineBreak(); - - // write properties - - io::IAttributes* attr = FileSystem->createEmptyAttributes(Driver); - io::SAttributeReadWriteOptions options; - if (currentPath) - { - options.Filename=currentPath; - options.Flags|=io::EARWF_USE_RELATIVE_PATHS; - } - node->serializeAttributes(attr, &options); - - if (attr->getAttributeCount() != 0) - { - attr->write(writer); - writer->writeLineBreak(); - } - - // write materials - - if (node->getMaterialCount() && Driver) - { - const wchar_t* materialElement = L"materials"; - - writer->writeElement(materialElement); - writer->writeLineBreak(); - - for (u32 i=0; i < node->getMaterialCount(); ++i) - { - io::IAttributes* tmp_attr = - Driver->createAttributesFromMaterial(node->getMaterial(i), &options); - tmp_attr->write(writer); - tmp_attr->drop(); - } - - writer->writeClosingTag(materialElement); - writer->writeLineBreak(); - } - - // write animators - - if (!node->getAnimators().empty()) - { - const wchar_t* animatorElement = L"animators"; - writer->writeElement(animatorElement); - writer->writeLineBreak(); - - ISceneNodeAnimatorList::ConstIterator it = node->getAnimators().begin(); - for (; it != node->getAnimators().end(); ++it) - { - attr->clear(); - attr->addString("Type", getAnimatorTypeName((*it)->getType())); - - (*it)->serializeAttributes(attr); - - attr->write(writer); - } - - writer->writeClosingTag(animatorElement); - writer->writeLineBreak(); - } - - // write possible user data - - if (userDataSerializer) - { - io::IAttributes* userData = userDataSerializer->createUserData(node); - if (userData) - { - const wchar_t* userDataElement = L"userData"; - - writer->writeLineBreak(); - writer->writeElement(userDataElement); - writer->writeLineBreak(); - - userData->write(writer); - - writer->writeClosingTag(userDataElement); - writer->writeLineBreak(); - writer->writeLineBreak(); - - userData->drop(); - } - } - // reset to actual root node - if (init) - node=tmpNode; - - // write children once root node is written - // if parent is not scene manager, we need to write out node first - if (init && (node != this)) - { - writeSceneNode(writer, node, userDataSerializer, currentPath); - } - else - { - ISceneNodeList::ConstIterator it = node->getChildren().begin(); - for (; it != node->getChildren().end(); ++it) - writeSceneNode(writer, (*it), userDataSerializer, currentPath); - } - - attr->drop(); - - writer->writeClosingTag(name); - writer->writeLineBreak(); - writer->writeLineBreak(); -} - - //! Returns a typename from a scene node type or null if not found const c8* CSceneManager::getSceneNodeTypeName(ESCENE_NODE_TYPE type) { @@ -2648,17 +2445,8 @@ IMeshWriter* CSceneManager::createMeshWriter(EMESH_WRITER_TYPE type) switch(type) { case EMWT_IRR_MESH: -#ifdef _IRR_COMPILE_WITH_IRR_WRITER_ - return new CIrrMeshWriter(Driver, FileSystem); -#else - return 0; -#endif case EMWT_COLLADA: -#ifdef _IRR_COMPILE_WITH_COLLADA_WRITER_ - return new CColladaMeshWriter(this, Driver, FileSystem); -#else return 0; -#endif case EMWT_STL: #ifdef _IRR_COMPILE_WITH_STL_WRITER_ return new CSTLMeshWriter(this); diff --git a/source/Irrlicht/CSceneManager.h b/source/Irrlicht/CSceneManager.h index 7340c95..516fd72 100644 --- a/source/Irrlicht/CSceneManager.h +++ b/source/Irrlicht/CSceneManager.h @@ -492,9 +492,6 @@ namespace scene //! Saves the current scene into a file. virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) _IRR_OVERRIDE_; - //! Saves the current scene into a file. - virtual bool saveScene(io::IXMLWriter* writer, const io::path& currentPath, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0) _IRR_OVERRIDE_; - //! Loads a scene. Note that the current scene is not cleared before. virtual bool loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0) _IRR_OVERRIDE_; @@ -542,9 +539,6 @@ namespace scene //! clears the deletion list void clearDeletionList(); - //! writes a scene node - void writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer, const fschar_t* currentPath=0, bool init=false); - struct DefaultNodeEntry { DefaultNodeEntry(ISceneNode* n) : @@ -660,12 +654,6 @@ namespace scene //! over the scene lighting and rendering. ILightManager* LightManager; - //! constants for reading and writing XML. - //! Not made static due to portability problems. - const core::stringw IRR_XML_FORMAT_SCENE; - const core::stringw IRR_XML_FORMAT_NODE; - const core::stringw IRR_XML_FORMAT_NODE_ATTR_TYPE; - IGeometryCreator* GeometryCreator; }; diff --git a/source/Irrlicht/CXMLReader.cpp b/source/Irrlicht/CXMLReader.cpp deleted file mode 100644 index db5a944..0000000 --- a/source/Irrlicht/CXMLReader.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "CXMLReader.h" - -#ifdef _IRR_COMPILE_WITH_XML_ -#include "CXMLReaderImpl.h" -#include "IReadFile.h" - -namespace irr -{ -namespace io -{ - //! Irrlicht implementation of the file read callback for the xml parser - class CIrrXMLFileReadCallBack : public IFileReadCallBack - { - public: - - //! construct from FILE pointer - CIrrXMLFileReadCallBack(IReadFile* file) - : ReadFile(file) - { - ReadFile->grab(); - } - - //! destructor - virtual ~CIrrXMLFileReadCallBack() - { - ReadFile->drop(); - } - - //! Reads an amount of bytes from the file. - virtual int read(void* buffer, int sizeToRead) _IRR_OVERRIDE_ - { - return (int)ReadFile->read(buffer, sizeToRead); - } - - //! Returns size of file in bytes - virtual long getSize() const _IRR_OVERRIDE_ - { - return ReadFile->getSize(); - } - - private: - - IReadFile* ReadFile; - }; // end class CMyXMLFileReadCallBack - - - // now create an implementation for IXMLReader using irrXML. - - //! Creates an instance of a wide character xml parser. - IXMLReader* createIXMLReader(IReadFile* file) - { - if (!file) - return 0; - - return new CXMLReaderImpl(new CIrrXMLFileReadCallBack(file)); - } - - //! Creates an instance of an UFT-8 or ASCII character xml parser. - IXMLReaderUTF8* createIXMLReaderUTF8(IReadFile* file) - { - if (!file) - return 0; - - return new CXMLReaderImpl(new CIrrXMLFileReadCallBack(file)); - } - -} // end namespace -} // end namespace -#else // not _IRR_COMPILE_WITH_XML_ -#include "os.h" -namespace irr -{ - -void noXML() -{ - irr::os::Printer::log("XML support disabled in IrrCompileConfig.", irr::ELL_ERROR); -} - -} // end namespace -#endif // _IRR_COMPILE_WITH_XML_ diff --git a/source/Irrlicht/CXMLReader.h b/source/Irrlicht/CXMLReader.h deleted file mode 100644 index 328b92a..0000000 --- a/source/Irrlicht/CXMLReader.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __C_XML_READER_H_INCLUDED__ -#define __C_XML_READER_H_INCLUDED__ - -#include "IXMLReader.h" - -namespace irr -{ -#ifdef _IRR_COMPILE_WITH_XML_ -namespace io -{ - class IReadFile; - - //! creates an IXMLReader - IXMLReader* createIXMLReader(IReadFile* file); - - //! creates an IXMLReader - IXMLReaderUTF8* createIXMLReaderUTF8(IReadFile* file); -} // end namespace irr -#else // _IRR_COMPILE_WITH_XML_ - //! print a message that Irrlicht is compiled without _IRR_COMPILE_WITH_XML_ - void noXML(); -#endif // _IRR_COMPILE_WITH_XML_ -} // end namespace io - -#endif - diff --git a/source/Irrlicht/CXMLReaderImpl.h b/source/Irrlicht/CXMLReaderImpl.h deleted file mode 100644 index 6f1192c..0000000 --- a/source/Irrlicht/CXMLReaderImpl.h +++ /dev/null @@ -1,821 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine" and the "irrXML" project. -// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h - -#ifndef __ICXML_READER_IMPL_H_INCLUDED__ -#define __ICXML_READER_IMPL_H_INCLUDED__ - -#include "irrXML.h" -#include "irrString.h" -#include "irrArray.h" -#include "fast_atof.h" - -#ifdef _DEBUG -#define IRR_DEBUGPRINT(x) printf((x)); -#else // _DEBUG -#define IRR_DEBUGPRINT(x) -#endif // _DEBUG - - -namespace irr -{ -namespace io -{ - - -//! implementation of the IrrXMLReader -template -class CXMLReaderImpl : public IIrrXMLReader -{ -public: - - //! Constructor - CXMLReaderImpl(IFileReadCallBack* callback, bool deleteCallBack = true) - : IgnoreWhitespaceText(true), TextData(0), P(0), TextBegin(0), TextSize(0), CurrentNodeType(EXN_NONE), - SourceFormat(ETF_ASCII), TargetFormat(ETF_ASCII), IsEmptyElement(false) - { - if (!callback) - return; - - storeTargetFormat(); - - // read whole xml file - - readFile(callback); - - // clean up - - if (deleteCallBack) - delete callback; - - // create list with special characters - - createSpecialCharacterList(); - - // set pointer to text begin - P = TextBegin; - } - - - //! Destructor - virtual ~CXMLReaderImpl() - { - delete [] TextData; - } - - - //! Reads forward to the next xml node. - //! \return Returns false, if there was no further node. - virtual bool read() _IRR_OVERRIDE_ - { - // if not end reached, parse the node - if (P && ((unsigned int)(P - TextBegin) < TextSize - 1) && (*P != 0)) - { - return parseCurrentNode(); - } - - return false; - } - - - //! Returns the type of the current XML node. - virtual EXML_NODE getNodeType() const _IRR_OVERRIDE_ - { - return CurrentNodeType; - } - - - //! Returns attribute count of the current XML node. - virtual unsigned int getAttributeCount() const _IRR_OVERRIDE_ - { - return Attributes.size(); - } - - - //! Returns name of an attribute. - virtual const char_type* getAttributeName(int idx) const _IRR_OVERRIDE_ - { - if ((u32)idx >= Attributes.size()) - return 0; - - return Attributes[idx].Name.c_str(); - } - - - //! Returns the value of an attribute. - virtual const char_type* getAttributeValue(int idx) const _IRR_OVERRIDE_ - { - if ((unsigned int)idx >= Attributes.size()) - return 0; - - return Attributes[idx].Value.c_str(); - } - - - //! Returns the value of an attribute. - virtual const char_type* getAttributeValue(const char_type* name) const _IRR_OVERRIDE_ - { - const SAttribute* attr = getAttributeByName(name); - if (!attr) - return 0; - - return attr->Value.c_str(); - } - - - //! Returns the value of an attribute - virtual const char_type* getAttributeValueSafe(const char_type* name) const _IRR_OVERRIDE_ - { - const SAttribute* attr = getAttributeByName(name); - if (!attr) - return EmptyString.c_str(); - - return attr->Value.c_str(); - } - - - - //! Returns the value of an attribute as integer. - virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound) const _IRR_OVERRIDE_ - { - const SAttribute* attr = getAttributeByName(name); - if (!attr) - return defaultNotFound; - - core::stringc c(attr->Value.c_str()); - return core::strtol10(c.c_str()); - } - - - //! Returns the value of an attribute as integer. - virtual int getAttributeValueAsInt(int idx, int defaultNotFound) const _IRR_OVERRIDE_ - { - const char_type* attrvalue = getAttributeValue(idx); - if (!attrvalue) - return defaultNotFound; - - core::stringc c(attrvalue); - return core::strtol10(c.c_str()); - } - - - //! Returns the value of an attribute as float. - virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound) const _IRR_OVERRIDE_ - { - const SAttribute* attr = getAttributeByName(name); - if (!attr) - return defaultNotFound; - - core::stringc c = attr->Value.c_str(); - return core::fast_atof(c.c_str()); - } - - - //! Returns the value of an attribute as float. - virtual float getAttributeValueAsFloat(int idx, float defaultNotFound) const _IRR_OVERRIDE_ - { - const char_type* attrvalue = getAttributeValue(idx); - if (!attrvalue) - return defaultNotFound; - - core::stringc c = attrvalue; - return core::fast_atof(c.c_str()); - } - - - //! Returns the name of the current node. - virtual const char_type* getNodeName() const _IRR_OVERRIDE_ - { - return NodeName.c_str(); - } - - - //! Returns data of the current node. - virtual const char_type* getNodeData() const _IRR_OVERRIDE_ - { - return NodeName.c_str(); - } - - - //! Returns if an element is an empty element, like - virtual bool isEmptyElement() const _IRR_OVERRIDE_ - { - return IsEmptyElement; - } - - //! Returns format of the source xml file. - virtual ETEXT_FORMAT getSourceFormat() const _IRR_OVERRIDE_ - { - return SourceFormat; - } - - //! Returns format of the strings returned by the parser. - virtual ETEXT_FORMAT getParserFormat() const _IRR_OVERRIDE_ - { - return TargetFormat; - } - -private: - - // Reads the current xml node - // return false if no further node is found - bool parseCurrentNode() - { - char_type* start = P; - - // more forward until '<' found - while(*P != L'<' && *P) - ++P; - - // not a node, so return false - if (!*P) - return false; - - if (P - start > 0) - { - // we found some text, store it - if (setText(start, P)) - return true; - } - - ++P; - - // based on current token, parse and report next element - switch(*P) - { - case L'/': - parseClosingXMLElement(); - break; - case L'?': - ignoreDefinition(); - break; - case L'!': - if (!parseCDATA()) - parseComment(); - break; - default: - parseOpeningXMLElement(); - break; - } - return true; - } - - - //! sets the state that text was found. Returns true if set should be set - bool setText(char_type* start, char_type* end) - { - // By default xml preserves all whitespace. But Irrlicht dropped some whitespace by default - // in the past which did lead to OS dependent behavior. We just ignore all whitespace for now - // as it's the closest to fixing behavior without breaking downward compatibility too much. - if ( IgnoreWhitespaceText ) - { - char_type* p = start; - for(; p != end; ++p) - if (!isWhiteSpace(*p)) - break; - - if (p == end) - return false; - } - - // set current text to the parsed text, and replace xml special characters - core::string s(start, (int)(end - start)); - NodeName = replaceSpecialCharacters(s); - - // current XML node type is text - CurrentNodeType = EXN_TEXT; - - return true; - } - - - - //! ignores an xml definition like - void ignoreDefinition() - { - CurrentNodeType = EXN_UNKNOWN; - - // move until end marked with '>' reached - while(*P != L'>') - ++P; - - ++P; - } - - - //! parses a comment - void parseComment() - { - CurrentNodeType = EXN_COMMENT; - P += 1; - - char_type *pCommentBegin = P; - - int count = 1; - - // move until end of comment reached - while(count) - { - if (*P == L'>') - --count; - else - if (*P == L'<') - ++count; - - ++P; - } - - P -= 3; - NodeName = core::string(pCommentBegin+2, (int)(P - pCommentBegin-2)); - P += 3; - } - - - //! parses an opening xml element and reads attributes - void parseOpeningXMLElement() - { - CurrentNodeType = EXN_ELEMENT; - IsEmptyElement = false; - Attributes.clear(); - - // find name - const char_type* startName = P; - - // find end of element - while(*P != L'>' && !isWhiteSpace(*P)) - ++P; - - const char_type* endName = P; - - // find Attributes - while(*P != L'>') - { - if (isWhiteSpace(*P)) - ++P; - else - { - if (*P != L'/') - { - // we've got an attribute - - // read the attribute names - const char_type* attributeNameBegin = P; - - while(!isWhiteSpace(*P) && *P != L'=') - ++P; - - const char_type* attributeNameEnd = P; - ++P; - - // read the attribute value - // check for quotes and single quotes, thx to murphy - while( (*P != L'\"') && (*P != L'\'') && *P) - ++P; - - if (!*P) // malformatted xml file - return; - - const char_type attributeQuoteChar = *P; - - ++P; - const char_type* attributeValueBegin = P; - - while(*P != attributeQuoteChar && *P) - ++P; - - if (!*P) // malformatted xml file - return; - - const char_type* attributeValueEnd = P; - ++P; - - SAttribute attr; - attr.Name = core::string(attributeNameBegin, - (int)(attributeNameEnd - attributeNameBegin)); - - core::string s(attributeValueBegin, - (int)(attributeValueEnd - attributeValueBegin)); - - attr.Value = replaceSpecialCharacters(s); - Attributes.push_back(attr); - } - else - { - // tag is closed directly - ++P; - IsEmptyElement = true; - break; - } - } - } - - // check if this tag is closing directly - if (endName > startName && *(endName-1) == L'/') - { - // directly closing tag - IsEmptyElement = true; - endName--; - } - - NodeName = core::string(startName, (int)(endName - startName)); - - ++P; - } - - - //! parses an closing xml tag - void parseClosingXMLElement() - { - CurrentNodeType = EXN_ELEMENT_END; - IsEmptyElement = false; - Attributes.clear(); - - ++P; - const char_type* pBeginClose = P; - - while(*P != L'>') - ++P; - - NodeName = core::string(pBeginClose, (int)(P - pBeginClose)); - ++P; - } - - //! parses a possible CDATA section, returns false if begin was not a CDATA section - bool parseCDATA() - { - if (*(P+1) != L'[') - return false; - - CurrentNodeType = EXN_CDATA; - - // skip '' && - (*(P-1) == L']') && - (*(P-2) == L']')) - { - cDataEnd = P - 2; - } - - ++P; - } - - if ( cDataEnd ) - NodeName = core::string(cDataBegin, (int)(cDataEnd - cDataBegin)); - else - NodeName = ""; - - return true; - } - - - // structure for storing attribute-name pairs - struct SAttribute - { - core::string Name; - core::string Value; - }; - - // finds a current attribute by name, returns 0 if not found - const SAttribute* getAttributeByName(const char_type* name) const - { - if (!name) - return 0; - - core::string n = name; - - for (int i=0; i<(int)Attributes.size(); ++i) - if (Attributes[i].Name == n) - return &Attributes[i]; - - return 0; - } - - // replaces xml special characters in a string and creates a new one - core::string replaceSpecialCharacters( - const core::string& origstr) - { - int pos = origstr.findFirst(L'&'); - int oldPos = 0; - - if (pos == -1) - return origstr; - - core::string newstr; - - while(pos != -1 && pos < (int)origstr.size()-2) - { - // check if it is one of the special characters - - int specialChar = -1; - for (int i=0; i<(int)SpecialCharacters.size(); ++i) - { - const char_type* p = &origstr.c_str()[pos]+1; - - if (equalsn(&SpecialCharacters[i][1], p, SpecialCharacters[i].size()-1)) - { - specialChar = i; - break; - } - } - - if (specialChar != -1) - { - newstr.append(origstr.subString(oldPos, pos - oldPos)); - newstr.append(SpecialCharacters[specialChar][0]); - pos += SpecialCharacters[specialChar].size(); - } - else - { - newstr.append(origstr.subString(oldPos, pos - oldPos + 1)); - pos += 1; - } - - // find next & - oldPos = pos; - pos = origstr.findNext(L'&', pos); - } - - if (oldPos < (int)origstr.size()-1) - newstr.append(origstr.subString(oldPos, origstr.size()-oldPos)); - - return newstr; - } - - - - //! reads the xml file and converts it into the wanted character format. - bool readFile(IFileReadCallBack* callback) - { - long size = callback->getSize(); - if (size<0) - return false; - // We need four terminating 0's at the end. - // For ASCII we need 1 0's, for UTF-16 2, for UTF-32 4. - size += 4; - - char* data8 = new char[size]; - - if (!callback->read(data8, size-4)) - { - delete [] data8; - return false; - } - - // add zeros at end - - memset(data8+size-4, 0, 4); - - char16* data16 = reinterpret_cast(data8); - char32* data32 = reinterpret_cast(data8); - - // now we need to convert the data to the desired target format - // based on the byte order mark. - - const unsigned char UTF8[] = {0xEF, 0xBB, 0xBF}; // 0xEFBBBF; - const u16 UTF16_BE = 0xFFFE; - const u16 UTF16_LE = 0xFEFF; - const u32 UTF32_BE = 0xFFFE0000; - const u32 UTF32_LE = 0x0000FEFF; - - // check source for all utf versions and convert to target data format - - if (size >= 4 && data32[0] - == static_cast(UTF32_BE)) - { - // UTF-32, big endian - SourceFormat = ETF_UTF32_BE; - convertTextData(data32+1, data8, (size/4)-1); // data32+1 because we need to skip the header - } - else - if (size >= 4 && data32[0] == static_cast(UTF32_LE)) - { - // UTF-32, little endian - SourceFormat = ETF_UTF32_LE; - convertTextData(data32+1, data8, (size/4)-1); // data32+1 because we need to skip the header - } - else - if (size >= 2 && data16[0] == UTF16_BE) - { - // UTF-16, big endian - SourceFormat = ETF_UTF16_BE; - convertTextData(data16+1, data8, (size/2)-1); // data16+1 because we need to skip the header - } - else - if (size >= 2 && data16[0] == UTF16_LE) - { - // UTF-16, little endian - SourceFormat = ETF_UTF16_LE; - convertTextData(data16+1, data8, (size/2)-1); // data16+1 because we need to skip the header - } - else - if (size >= 3 && memcmp(data8,UTF8,3)==0) - { - // UTF-8 - SourceFormat = ETF_UTF8; - convertTextData(data8+3, data8, size-3); // data8+3 because we need to skip the header - } - else - { - // ASCII - SourceFormat = ETF_ASCII; - convertTextData(data8, data8, size); - } - - return true; - } - - - //! converts the text file into the desired format. - /** \param source: begin of the text (without byte order mark) - \param pointerToStore: pointer to text data block which can be - stored or deleted based on the nesessary conversion. - \param sizeWithoutHeader: Text size in characters without header - */ - template - void convertTextData(src_char_type* source, char* pointerToStore, int sizeWithoutHeader) - { - // convert little to big endian if necessary - if (sizeof(src_char_type) > 1 && - isLittleEndian(TargetFormat) != isLittleEndian(SourceFormat)) - convertToLittleEndian(source); - - // check if conversion is necessary: - if (sizeof(src_char_type) == sizeof(char_type)) - { - // no need to convert - TextBegin = (char_type*)source; - TextData = (char_type*)pointerToStore; - TextSize = sizeWithoutHeader; - } - else - { - // convert source into target data format. - // TODO: implement a real conversion. This one just - // copies bytes. This is a problem when there are - // unicode symbols using more than one character. - - TextData = new char_type[sizeWithoutHeader]; - - if ( sizeof(src_char_type) == 1 ) - { - // we have to cast away negative numbers or results might add the sign instead of just doing a copy - for (int i=0; i(static_cast(source[i])); - } - } - else - { - for (int i=0; i(source[i]); - } - TextBegin = TextData; - TextSize = sizeWithoutHeader; - - // delete original data because no longer needed - delete [] pointerToStore; - } - } - - //! converts whole text buffer to little endian - template - void convertToLittleEndian(src_char_type* t) - { - if (sizeof(src_char_type) == 4) - { - // 32 bit - - while(*t) - { - *t = ((*t & 0xff000000) >> 24) | - ((*t & 0x00ff0000) >> 8) | - ((*t & 0x0000ff00) << 8) | - ((*t & 0x000000ff) << 24); - ++t; - } - } - else - { - // 16 bit - - while(*t) - { - *t = (*t >> 8) | (*t << 8); - ++t; - } - } - } - - //! returns if a format is little endian - inline bool isLittleEndian(ETEXT_FORMAT f) - { - return f == ETF_ASCII || - f == ETF_UTF8 || - f == ETF_UTF16_LE || - f == ETF_UTF32_LE; - } - - - //! returns true if a character is whitespace - inline bool isWhiteSpace(char_type c) - { - return (c==' ' || c=='\t' || c=='\n' || c=='\r'); - } - - - //! generates a list with xml special characters - void createSpecialCharacterList() - { - // list of strings containing special symbols, - // the first character is the special character, - // the following is the symbol string without trailing &. - - SpecialCharacters.push_back("&"); - SpecialCharacters.push_back("gt;"); - SpecialCharacters.push_back("\"quot;"); - SpecialCharacters.push_back("'apos;"); - - } - - - //! compares the first n characters of the strings - bool equalsn(const char_type* str1, const char_type* str2, int len) - { - int i; - for(i=0; str1[i] && str2[i] && i < len; ++i) - if (str1[i] != str2[i]) - return false; - - // if one (or both) of the strings was smaller then they - // are only equal if they have the same length - return (i == len) || (str1[i] == 0 && str2[i] == 0); - } - - - //! stores the target text format - void storeTargetFormat() - { - // get target format. We could have done this using template specialization, - // but VisualStudio 6 don't like it and we want to support it. - - switch(sizeof(char_type)) - { - case 1: - TargetFormat = ETF_UTF8; - break; - case 2: - TargetFormat = ETF_UTF16_LE; - break; - case 4: - TargetFormat = ETF_UTF32_LE; - break; - default: - TargetFormat = ETF_ASCII; // should never happen. - } - } - - - // instance variables: - bool IgnoreWhitespaceText; // do not return EXN_TEXT nodes for pure whitespace - char_type* TextData; // data block of the text file - char_type* P; // current point in text to parse - char_type* TextBegin; // start of text to parse - unsigned int TextSize; // size of text to parse in characters, not bytes - - EXML_NODE CurrentNodeType; // type of the currently parsed node - ETEXT_FORMAT SourceFormat; // source format of the xml file - ETEXT_FORMAT TargetFormat; // output format of this parser - - core::string NodeName; // name of the node currently in - also used for text - core::string EmptyString; // empty string to be returned by getSafe() methods - - bool IsEmptyElement; // is the currently parsed node empty? - - core::array< core::string > SpecialCharacters; // see createSpecialCharacterList() - - core::array Attributes; // attributes of current element - -}; // end CXMLReaderImpl - - -} // end namespace -} // end namespace - -#endif diff --git a/source/Irrlicht/CXMLWriter.cpp b/source/Irrlicht/CXMLWriter.cpp deleted file mode 100644 index 4e9d690..0000000 --- a/source/Irrlicht/CXMLWriter.cpp +++ /dev/null @@ -1,472 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "CXMLWriter.h" - -#ifdef _IRR_COMPILE_WITH_XML_ - -#include -#include "irrString.h" -#include "IrrCompileConfig.h" - -namespace irr -{ -namespace io -{ - -//! creates an IXMLReader -IXMLWriter* createIXMLWriter(IWriteFile* file) -{ - return new CXMLWriter(file); -} - -//! creates an IXMLReader -IXMLWriterUTF8* createIXMLWriterUTF8(IWriteFile* file) -{ - return new CXMLWriterUTF8(file); -} - -//! Constructor -CXMLWriter::CXMLWriter(IWriteFile* file) -: CXMLWriterCommon(file) -{ - #ifdef _DEBUG - setDebugName("CXMLWriter"); - #endif -} - - -//! Writes a xml 1.0 header like -void CXMLWriter::writeXMLHeader() -{ - if (!File) - return; - - if (sizeof(wchar_t)==2) - { - const u16 h = 0xFEFF; - File->write(&h, 2); - } - else - { - const u32 h = 0x0000FEFF; - File->write(&h, sizeof(wchar_t)); - } - - const wchar_t* const p = L""; - File->write(p, wcslen(p)*sizeof(wchar_t)); - - writeLineBreak(); - TextWrittenLast = false; -} - - - -//! Writes an xml element with maximal 5 attributes -void CXMLWriter::writeElement(const wchar_t* name, bool empty, - const wchar_t* attr1Name, const wchar_t* attr1Value, - const wchar_t* attr2Name, const wchar_t* attr2Value, - const wchar_t* attr3Name, const wchar_t* attr3Value, - const wchar_t* attr4Name, const wchar_t* attr4Value, - const wchar_t* attr5Name, const wchar_t* attr5Value) -{ - if (!File || !name) - return; - - if (Tabs > 0) - { - for (int i=0; iwrite(L"\t", sizeof(wchar_t)); - } - - // write name - - File->write(L"<", sizeof(wchar_t)); - File->write(name, wcslen(name)*sizeof(wchar_t)); - - // write attributes - - writeAttribute(attr1Name, attr1Value); - writeAttribute(attr2Name, attr2Value); - writeAttribute(attr3Name, attr3Value); - writeAttribute(attr4Name, attr4Value); - writeAttribute(attr5Name, attr5Value); - - // write closing tag - if (empty) - File->write(L" />", 3*sizeof(wchar_t)); - else - { - File->write(L">", sizeof(wchar_t)); - ++Tabs; - } - - TextWrittenLast = false; -} - -//! Writes an xml element with any number of attributes -void CXMLWriter::writeElement(const wchar_t* name, bool empty, - core::array &names, - core::array &values) -{ - if (!File || !name) - return; - - if (Tabs > 0) - { - for (int i=0; iwrite(L"\t", sizeof(wchar_t)); - } - - // write name - - File->write(L"<", sizeof(wchar_t)); - File->write(name, wcslen(name)*sizeof(wchar_t)); - - // write attributes - u32 i=0; - for (; i < names.size() && i < values.size(); ++i) - writeAttribute(names[i].c_str(), values[i].c_str()); - - // write closing tag - if (empty) - File->write(L" />", 3*sizeof(wchar_t)); - else - { - File->write(L">", sizeof(wchar_t)); - ++Tabs; - } - - TextWrittenLast = false; -} - - -void CXMLWriter::writeAttribute(const wchar_t* name, const wchar_t* value) -{ - if (!name || !value) - return; - - File->write(L" ", sizeof(wchar_t)); - File->write(name, wcslen(name)*sizeof(wchar_t)); - File->write(L"=\"", 2*sizeof(wchar_t)); - writeText(value); - File->write(L"\"", sizeof(wchar_t)); -} - - -//! Writes a comment into the xml file -void CXMLWriter::writeComment(const wchar_t* comment) -{ - if (!File || !comment) - return; - - File->write(L"", 3*sizeof(wchar_t)); -} - - -//! Writes the closing tag for an element. Like -void CXMLWriter::writeClosingTag(const wchar_t* name) -{ - if (!File || !name) - return; - - --Tabs; - - if (Tabs > 0 && !TextWrittenLast) - { - for (int i=0; iwrite(L"\t", sizeof(wchar_t)); - } - - File->write(L"write(name, wcslen(name)*sizeof(wchar_t)); - File->write(L">", sizeof(wchar_t)); - TextWrittenLast = false; -} - -//! Writes a text into the file. All occurrences of special characters like -//! & (&), < (<), > (>), and " (") are automatically replaced. -void CXMLWriter::writeText(const wchar_t* text) -{ - if (!File || !text) - return; - - static const CXMLWriter::XMLSpecialCharacters XMLWSChar[] = - { - { L'&', L"&" }, - { L'<', L"<" }, - { L'>', L">" }, - { L'"', L""" }, - { L'\0', 0 } - }; - - // TODO: we have to get rid of that reserve call as well as it slows down xml-writing seriously. - // Making a member-variable would work, but a lot of memory would stay around after writing. - // So the correct solution is probably using fixed block here and always write when that is full. - core::stringw s; - s.reserve(wcslen(text)+1); - const wchar_t* p = text; - - while(*p) - { - // check if it is matching - bool found = false; - for (s32 i=0; XMLWSChar[i].Character != '\0'; ++i) - if (*p == XMLWSChar[i].Character) - { - s.append(XMLWSChar[i].Symbol); - found = true; - break; - } - - if (!found) - s.append(*p); - ++p; - } - - // write new string - File->write(s.c_str(), s.size()*sizeof(wchar_t)); - TextWrittenLast = true; -} - - -//! Writes a line break -void CXMLWriter::writeLineBreak() -{ - if (!File) - return; - -#if defined(_IRR_OSX_PLATFORM_) - File->write(L"\r", sizeof(wchar_t)); -#elif defined(_IRR_WINDOWS_API_) - File->write(L"\r\n", 2*sizeof(wchar_t)); -#else - File->write(L"\n", sizeof(wchar_t)); -#endif - -} - - - -//! Constructor -CXMLWriterUTF8::CXMLWriterUTF8(IWriteFile* file) -: CXMLWriterCommon(file) -{ - #ifdef _DEBUG - setDebugName("CXMLWriter"); - #endif -} - - -//! Writes a xml 1.0 header like -void CXMLWriterUTF8::writeXMLHeader() -{ - if (!File) - return; - - // No BOM as it's not necessarily utf8 - - const c8* const p = ""; - File->write(p, strlen(p) * sizeof(c8)); - - writeLineBreak(); - TextWrittenLast = false; -} - - - -//! Writes an xml element with maximal 5 attributes -void CXMLWriterUTF8::writeElement(const c8* name, bool empty, - const c8* attr1Name, const c8* attr1Value, - const c8* attr2Name, const c8* attr2Value, - const c8* attr3Name, const c8* attr3Value, - const c8* attr4Name, const c8* attr4Value, - const c8* attr5Name, const c8* attr5Value) -{ - if (!File || !name) - return; - - if (Tabs > 0) - { - for (int i=0; iwrite("\t", sizeof(c8)); - } - - // write name - - File->write("<", sizeof(c8)); - File->write(name, strlen(name)*sizeof(c8)); - - // write attributes - - writeAttribute(attr1Name, attr1Value); - writeAttribute(attr2Name, attr2Value); - writeAttribute(attr3Name, attr3Value); - writeAttribute(attr4Name, attr4Value); - writeAttribute(attr5Name, attr5Value); - - // write closing tag - if (empty) - File->write(" />", 3*sizeof(c8)); - else - { - File->write(">", sizeof(c8)); - ++Tabs; - } - - TextWrittenLast = false; -} - -//! Writes an xml element with any number of attributes -void CXMLWriterUTF8::writeElement(const c8* name, bool empty, - core::array &names, - core::array &values) -{ - if (!File || !name) - return; - - if (Tabs > 0) - { - for (int i=0; iwrite("\t", sizeof(c8)); - } - - // write name - - File->write("<", sizeof(c8)); - File->write(name, strlen(name)*sizeof(c8)); - - // write attributes - u32 i=0; - for (; i < names.size() && i < values.size(); ++i) - writeAttribute(names[i].c_str(), values[i].c_str()); - - // write closing tag - if (empty) - File->write(" />", 3*sizeof(c8)); - else - { - File->write(">", sizeof(c8)); - ++Tabs; - } - - TextWrittenLast = false; -} - - -void CXMLWriterUTF8::writeAttribute(const c8* name, const c8* value) -{ - if (!name || !value) - return; - - File->write(" ", sizeof(c8)); - File->write(name, strlen(name)*sizeof(c8)); - File->write("=\"", 2*sizeof(c8)); - writeText(value); - File->write("\"", sizeof(c8)); -} - - -//! Writes a comment into the xml file -void CXMLWriterUTF8::writeComment(const c8* comment) -{ - if (!File || !comment) - return; - - File->write("", 3*sizeof(c8)); -} - - -//! Writes the closing tag for an element. Like -void CXMLWriterUTF8::writeClosingTag(const c8* name) -{ - if (!File || !name) - return; - - --Tabs; - - if (Tabs > 0 && !TextWrittenLast) - { - for (int i=0; iwrite("\t", sizeof(c8)); - } - - File->write("write(name, strlen(name)*sizeof(c8)); - File->write(">", sizeof(c8)); - TextWrittenLast = false; -} - - - -//! Writes a text into the file. All occurrences of special characters like -//! & (&), < (<), > (>), and " (") are automatically replaced. -void CXMLWriterUTF8::writeText(const c8* text) -{ - if (!File || !text) - return; - - static const CXMLWriterUTF8::XMLSpecialCharacters XMLWSChar[] = - { - { '&', "&" }, - { '<', "<" }, - { '>', ">" }, - { '"', """ }, - { '\0', 0 } - }; - - // TODO: we have to get rid of that reserve call as well as it slows down xml-writing seriously. - // Making a member-variable would work, but a lot of memory would stay around after writing. - // So the correct solution is probably using fixed block here and always write when that is full. - core::stringc s; - s.reserve(strlen(text)+1); - const c8* p = text; - - while(*p) - { - // check if it is matching - bool found = false; - for (s32 i=0; XMLWSChar[i].Character != '\0'; ++i) - if (*p == XMLWSChar[i].Character) - { - s.append(XMLWSChar[i].Symbol); - found = true; - break; - } - - if (!found) - s.append(*p); - ++p; - } - - // write new string - File->write(s.c_str(), s.size()*sizeof(c8)); - TextWrittenLast = true; -} - - -//! Writes a line break -void CXMLWriterUTF8::writeLineBreak() -{ - if (!File) - return; - -#if defined(_IRR_OSX_PLATFORM_) - File->write("\r", sizeof(c8)); -#elif defined(_IRR_WINDOWS_API_) - File->write("\r\n", 2*sizeof(c8)); -#else - File->write("\n", sizeof(c8)); -#endif - -} - -} // end namespace irr -} // end namespace io - -#endif // _IRR_COMPILE_WITH_XML_ diff --git a/source/Irrlicht/CXMLWriter.h b/source/Irrlicht/CXMLWriter.h deleted file mode 100644 index 6febc66..0000000 --- a/source/Irrlicht/CXMLWriter.h +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __C_XML_WRITER_H_INCLUDED__ -#define __C_XML_WRITER_H_INCLUDED__ - -#include "IXMLWriter.h" - -#ifdef _IRR_COMPILE_WITH_XML_ - -#include -#include "IWriteFile.h" - -namespace irr -{ -namespace io -{ - - //! creates an IXMLReader - IXMLWriter* createIXMLWriter(IWriteFile* file); - - //! creates an IXMLReader - IXMLWriterUTF8* createIXMLWriterUTF8(IWriteFile* file); - - // Stuff needed by implementations for all character types - // TODO: With some more work it could maybe become a pure template based thing like CXMLReaderImpl - // and replace the type based writer implementations. Sorry, too lazy for now :-/ - template - class CXMLWriterCommon - { - public: - //! Constructor - CXMLWriterCommon(IWriteFile* file): File(file), Tabs(0), TextWrittenLast(false) - { - if (File) - File->grab(); - } - - //! Destructor - virtual ~CXMLWriterCommon() - { - if (File) - File->drop(); - } - - struct XMLSpecialCharacters - { - char_type Character; - const char_type* Symbol; - }; - - protected: - IWriteFile* File; - s32 Tabs; - - bool TextWrittenLast; - }; - - - //! Implementation providing methods for making it easier to write XML files. - class CXMLWriter : public IXMLWriter, public CXMLWriterCommon - { - public: - - //! Constructor - CXMLWriter(IWriteFile* file); - - //! Destructor - virtual ~CXMLWriter() {} - - //! Writes a xml 1.0 header like - virtual void writeXMLHeader() _IRR_OVERRIDE_; - - //! Writes an xml element with maximal 5 attributes - virtual void writeElement(const wchar_t* name, bool empty=false, - const wchar_t* attr1Name = 0, const wchar_t* attr1Value = 0, - const wchar_t* attr2Name = 0, const wchar_t* attr2Value = 0, - const wchar_t* attr3Name = 0, const wchar_t* attr3Value = 0, - const wchar_t* attr4Name = 0, const wchar_t* attr4Value = 0, - const wchar_t* attr5Name = 0, const wchar_t* attr5Value = 0) _IRR_OVERRIDE_; - - //! Writes an xml element with any number of attributes - virtual void writeElement(const wchar_t* name, bool empty, - core::array &names, core::array &values) _IRR_OVERRIDE_; - - //! Writes a comment into the xml file - virtual void writeComment(const wchar_t* comment) _IRR_OVERRIDE_; - - //! Writes the closing tag for an element. Like - virtual void writeClosingTag(const wchar_t* name) _IRR_OVERRIDE_; - - //! Writes a text into the file. All occurrences of special characters like - //! & (&), < (<), > (>), and " (") are automatically replaced. - virtual void writeText(const wchar_t* text) _IRR_OVERRIDE_; - - //! Writes a line break - virtual void writeLineBreak() _IRR_OVERRIDE_; - - private: - - void writeAttribute(const wchar_t* att, const wchar_t* name); - }; - - //! Implementation providing methods for making it easier to write XML files. - class CXMLWriterUTF8 : public IXMLWriterUTF8, public CXMLWriterCommon - { - public: - - //! Constructor - CXMLWriterUTF8(IWriteFile* file); - - //! Destructor - virtual ~CXMLWriterUTF8() {} - - //! Writes a xml 1.0 header like - virtual void writeXMLHeader() _IRR_OVERRIDE_; - - //! Writes an xml element with maximal 5 attributes - virtual void writeElement(const c8* name, bool empty=false, - const c8* attr1Name = 0, const c8* attr1Value = 0, - const c8* attr2Name = 0, const c8* attr2Value = 0, - const c8* attr3Name = 0, const c8* attr3Value = 0, - const c8* attr4Name = 0, const c8* attr4Value = 0, - const c8* attr5Name = 0, const c8* attr5Value = 0) _IRR_OVERRIDE_; - - //! Writes an xml element with any number of attributes - virtual void writeElement(const c8* name, bool empty, - core::array &names, core::array &values) _IRR_OVERRIDE_; - - //! Writes a comment into the xml file - virtual void writeComment(const c8* comment) _IRR_OVERRIDE_; - - //! Writes the closing tag for an element. Like - virtual void writeClosingTag(const c8* name) _IRR_OVERRIDE_; - - //! Writes a text into the file. All occurrences of special characters like - //! & (&), < (<), > (>), and " (") are automatically replaced. - virtual void writeText(const c8* text) _IRR_OVERRIDE_; - - //! Writes a line break - virtual void writeLineBreak() _IRR_OVERRIDE_; - - private: - - void writeAttribute(const c8* att, const c8* name); - }; - - -} // end namespace irr -} // end namespace io - -#endif // _IRR_COMPILE_WITH_XML_ - -#endif - diff --git a/source/Irrlicht/irrXML.cpp b/source/Irrlicht/irrXML.cpp deleted file mode 100644 index 96f0ec7..0000000 --- a/source/Irrlicht/irrXML.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (C) 2002-2012 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine" and the "irrXML" project. -// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h - -#include "irrXML.h" - -#ifdef _IRR_COMPILE_WITH_XML_ - -#include "irrString.h" -#include "irrArray.h" -#include "fast_atof.h" -#include "CXMLReaderImpl.h" - -namespace irr -{ -namespace io -{ - -//! Implementation of the file read callback for ordinary files -class CFileReadCallBack : public IFileReadCallBack -{ -public: - - //! construct from filename - CFileReadCallBack(const char* filename) - : File(0), Size(-1), Close(true) - { - // open file - File = fopen(filename, "rb"); - - if (File) - getFileSize(); - } - - //! construct from FILE pointer - CFileReadCallBack(FILE* file) - : File(file), Size(-1), Close(false) - { - if (File) - getFileSize(); - } - - //! destructor - virtual ~CFileReadCallBack() - { - if (Close && File) - fclose(File); - } - - //! Reads an amount of bytes from the file. - virtual int read(void* buffer, int sizeToRead) _IRR_OVERRIDE_ - { - if (!File) - return 0; - - return (int)fread(buffer, 1, sizeToRead, File); - } - - //! Returns size of file in bytes - virtual long getSize() const _IRR_OVERRIDE_ - { - return Size; - } - -private: - - //! retrieves the file size of the open file - void getFileSize() - { - fseek(File, 0, SEEK_END); - Size = ftell(File); - fseek(File, 0, SEEK_SET); - } - - FILE* File; - long Size; - bool Close; - -}; // end class CFileReadCallBack - - - -// FACTORY FUNCTIONS: - - -//! Creates an instance of an UFT-8 or ASCII character xml parser. -IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(const char* filename) -{ - return createIrrXMLReader(new CFileReadCallBack(filename), true); -} - - -//! Creates an instance of an UFT-8 or ASCII character xml parser. -IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(FILE* file) -{ - return createIrrXMLReader(new CFileReadCallBack(file), true); -} - - -//! Creates an instance of an UFT-8 or ASCII character xml parser. -IRRLICHT_API IrrXMLReader* IRRCALLCONV createIrrXMLReader(IFileReadCallBack* callback, - bool deleteCallback) -{ - if (callback && (callback->getSize() >= 0)) - { - return new CXMLReaderImpl(callback, deleteCallback); - } - else - { - if(callback && deleteCallback) - delete callback; - - return 0; - } -} - - -//! Creates an instance of an UTF-16 xml parser. -IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(const char* filename) -{ - return createIrrXMLReaderUTF16(new CFileReadCallBack(filename), true); -} - - -//! Creates an instance of an UTF-16 xml parser. -IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(FILE* file) -{ - return createIrrXMLReaderUTF16(new CFileReadCallBack(file), true); -} - - -//! Creates an instance of an UTF-16 xml parser. -IRRLICHT_API IrrXMLReaderUTF16* IRRCALLCONV createIrrXMLReaderUTF16(IFileReadCallBack* callback, - bool deleteCallback) -{ - if (callback && (callback->getSize() >= 0)) - { - return new CXMLReaderImpl(callback, deleteCallback); - } - else - { - if(callback && deleteCallback) - delete callback; - - return 0; - } -} - - -//! Creates an instance of an UTF-32 xml parser. -IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(const char* filename) -{ - return createIrrXMLReaderUTF32(new CFileReadCallBack(filename), true); -} - - -//! Creates an instance of an UTF-32 xml parser. -IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32(FILE* file) -{ - return createIrrXMLReaderUTF32(new CFileReadCallBack(file), true); -} - - -//! Creates an instance of an UTF-32 xml parser. -IRRLICHT_API IrrXMLReaderUTF32* IRRCALLCONV createIrrXMLReaderUTF32( - IFileReadCallBack* callback, bool deleteCallback) -{ - if (callback && (callback->getSize() >= 0)) - { - return new CXMLReaderImpl(callback, deleteCallback); - } - else - { - if(callback && deleteCallback) - delete callback; - - return 0; - } -} - - -} // end namespace io -} // end namespace irr - -#endif // _IRR_COMPILE_WITH_XML_