mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Add MaterialX files.
Add tinyxml2.
This commit is contained in:
@@ -144,6 +144,7 @@ set(TINYUSDZ_DEP_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/src/pxrLZ4/lz4.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/external/fpng.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/external/staticstruct.cc
|
||||
${PROJECT_SOURCE_DIR}/src/external/tinyxml2/tinyxml2.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/external/ryu/ryu/s2d.c
|
||||
${PROJECT_SOURCE_DIR}/src/external/ryu/ryu/s2f.c)
|
||||
|
||||
|
||||
@@ -227,6 +227,7 @@ mkdir -p ~/.config/blender/2.93/scripts/addons/modules
|
||||
* [ ] Support Nested USDZ
|
||||
* [ ] UDIM texture support
|
||||
* [ ] Support big endian architecture.
|
||||
* [ ] MaterialX support
|
||||
|
||||
## Fuzzing test
|
||||
|
||||
@@ -258,3 +259,5 @@ TinyUSDZ is licensed under MIT license.
|
||||
* mapbox/recursive_wrapper: BSL 1.0 license. https://github.com/mapbox/variant
|
||||
* par_shapes.h generate parametric surfaces and other simple shapes: MIT license https://github.com/prideout/par
|
||||
* staticstruct: MIT license. https://github.com/syoyo/staticstruct
|
||||
* MaterialX: Apache 2.0 license. https://github.com/AcademySoftwareFoundation/MaterialX
|
||||
* tinyxml2: zlib license. https://github.com/leethomason/tinyxml2
|
||||
|
||||
176
data/materialx/LICENSE
Normal file
176
data/materialx/LICENSE
Normal file
@@ -0,0 +1,176 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
3
data/materialx/README.md
Normal file
3
data/materialx/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Files copied from MaterialX repo: https://github.com/AcademySoftwareFoundation/MaterialX
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0"?>
|
||||
<materialx version="1.38" colorspace="lin_rec709">
|
||||
<nodegraph name="NG_brass1" fileprefix="../../../Images/">
|
||||
<tiledimage name="image_color" type="color3">
|
||||
<input name="file" type="filename" value="brass_color.jpg" colorspace="srgb_texture" />
|
||||
<input name="uvtiling" type="vector2" value="1.0, 1.0" />
|
||||
</tiledimage>
|
||||
<tiledimage name="image_roughness" type="float">
|
||||
<input name="file" type="filename" value="brass_roughness.jpg" />
|
||||
<input name="uvtiling" type="vector2" value="1.0, 1.0" />
|
||||
</tiledimage>
|
||||
<output name="out_color" type="color3" nodename="image_color" />
|
||||
<output name="out_roughness" type="float" nodename="image_roughness" />
|
||||
</nodegraph>
|
||||
<UsdPreviewSurface name="SR_brass1" type="surfaceshader">
|
||||
<input name="diffuseColor" type="color3" nodegraph="NG_brass1" output="out_color" />
|
||||
<input name="metallic" type="float" value="1" />
|
||||
<input name="roughness" type="float" nodegraph="NG_brass1" output="out_roughness" />
|
||||
</UsdPreviewSurface>
|
||||
<surfacematerial name="USD_Tiled_Brass" type="material">
|
||||
<input name="surfaceshader" type="surfaceshader" nodename="SR_brass1" />
|
||||
</surfacematerial>
|
||||
</materialx>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0"?>
|
||||
<materialx version="1.38" colorspace="lin_rec709">
|
||||
<UsdPreviewSurface name="SR_default" type="surfaceshader">
|
||||
<input name="diffuseColor" type="color3" value="0.18, 0.18, 0.18" />
|
||||
<input name="emissiveColor" type="color3" value="0, 0, 0" />
|
||||
<input name="useSpecularWorkflow" type="integer" value="0" />
|
||||
<input name="specularColor" type="color3" value="0, 0, 0" />
|
||||
<input name="metallic" type="float" value="0" />
|
||||
<input name="roughness" type="float" value="0.5" />
|
||||
<input name="clearcoat" type="float" value="0" />
|
||||
<input name="clearcoatRoughness" type="float" value="0.01" />
|
||||
<input name="opacity" type="float" value="1" />
|
||||
<input name="opacityThreshold" type="float" value="0" />
|
||||
<input name="ior" type="float" value="1.5" />
|
||||
<input name="normal" type="vector3" value="0, 0, 1" />
|
||||
<input name="displacement" type="float" value="0" />
|
||||
<input name="occlusion" type="float" value="1" />
|
||||
</UsdPreviewSurface>
|
||||
<surfacematerial name="USD_Default" type="material">
|
||||
<input name="surfaceshader" type="surfaceshader" nodename="SR_default" />
|
||||
</surfacematerial>
|
||||
</materialx>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<materialx version="1.38" colorspace="lin_rec709">
|
||||
<UsdPreviewSurface name="SR_glass" type="surfaceshader">
|
||||
<input name="diffuseColor" type="color3" value="0.0, 0.0, 0.0" />
|
||||
<input name="useSpecularWorkflow" type="integer" value="0" />
|
||||
<input name="metallic" type="float" value="0" />
|
||||
<input name="roughness" type="float" value="0.01" />
|
||||
<input name="opacity" type="float" value="0" />
|
||||
<input name="opacityThreshold" type="float" value="0" />
|
||||
<input name="ior" type="float" value="1.52" />
|
||||
</UsdPreviewSurface>
|
||||
<surfacematerial name="USD_Glass" type="material">
|
||||
<input name="surfaceshader" type="surfaceshader" nodename="SR_glass" />
|
||||
</surfacematerial>
|
||||
</materialx>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<materialx version="1.38" colorspace="lin_rec709">
|
||||
<UsdPreviewSurface name="SR_gold" type="surfaceshader">
|
||||
<input name="diffuseColor" type="color3" value="0.944, 0.776, 0.373" />
|
||||
<input name="metallic" type="float" value="1" />
|
||||
<input name="roughness" type="float" value="0.02" />
|
||||
</UsdPreviewSurface>
|
||||
<surfacematerial name="USD_Gold" type="material">
|
||||
<input name="surfaceshader" type="surfaceshader" nodename="SR_gold" />
|
||||
</surfacematerial>
|
||||
</materialx>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0"?>
|
||||
<materialx version="1.38" colorspace="lin_rec709">
|
||||
<UsdPreviewSurface name="SR_plastic" type="surfaceshader">
|
||||
<input name="diffuseColor" type="color3" value="0.10470402, 0.24188282, 0.81800002" />
|
||||
<input name="roughness" type="float" value="0.32467532157897949" />
|
||||
<input name="ior" type="float" value="1.5" />
|
||||
</UsdPreviewSurface>
|
||||
<surfacematerial name="USD_Plastic" type="material">
|
||||
<input name="surfaceshader" type="surfaceshader" nodename="SR_plastic" />
|
||||
</surfacematerial>
|
||||
</materialx>
|
||||
14
sandbox/materialx/Makefile
Normal file
14
sandbox/materialx/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
CXX=clang++
|
||||
CXXFLAGS=-Weverything -Wall
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
all: tinyxml2.o
|
||||
$(CXX) $(CXXFLAGS) -o materialx_test -I../../src/external materialx-main.cc tinyxml2.o
|
||||
|
||||
tinyxml2.o: ../../src/external/tinyxml2/tinyxml2.cpp
|
||||
$(CXX) -o $@ -c $<
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf materialx_test tinyxml2.o
|
||||
40
sandbox/materialx/materialx-main.cc
Normal file
40
sandbox/materialx/materialx-main.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Weverything"
|
||||
#endif
|
||||
|
||||
#include "tinyxml2/tinyxml2.h"
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::string filename = "../../data/materialx/UsdPreviewSurface/usd_preview_surface_default.mtlx";
|
||||
|
||||
if (argc > 1) {
|
||||
filename = argv[1];
|
||||
}
|
||||
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.LoadFile(filename.c_str());
|
||||
if (doc.ErrorID() != 0) {
|
||||
std::cerr << "XML Parising error: code = " << doc.ErrorID() << "\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::cout << "Read OK\n";
|
||||
|
||||
tinyxml2::XMLPrinter printer;
|
||||
doc.Print(&printer);
|
||||
|
||||
std::cout << printer.CStr() << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
18
src/external/tinyxml2/LICENSE.txt
vendored
Normal file
18
src/external/tinyxml2/LICENSE.txt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
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.
|
||||
330
src/external/tinyxml2/readme.md
vendored
Normal file
330
src/external/tinyxml2/readme.md
vendored
Normal file
@@ -0,0 +1,330 @@
|
||||
TinyXML-2
|
||||
=========
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
TinyXML-2 is a simple, small, efficient, C++ XML parser that can be
|
||||
easily integrated into other programs.
|
||||
|
||||
The master is hosted on github:
|
||||
https://github.com/leethomason/tinyxml2
|
||||
|
||||
The online HTML version of these docs:
|
||||
http://leethomason.github.io/tinyxml2/
|
||||
|
||||
Examples are in the "related pages" tab of the HTML docs.
|
||||
|
||||
What it does.
|
||||
-------------
|
||||
|
||||
In brief, TinyXML-2 parses an XML document, and builds from that a
|
||||
Document Object Model (DOM) that can be read, modified, and saved.
|
||||
|
||||
XML stands for "eXtensible Markup Language." It is a general purpose
|
||||
human and machine readable markup language to describe arbitrary data.
|
||||
All those random file formats created to store application data can
|
||||
all be replaced with XML. One parser for everything.
|
||||
|
||||
http://en.wikipedia.org/wiki/XML
|
||||
|
||||
There are different ways to access and interact with XML data.
|
||||
TinyXML-2 uses a Document Object Model (DOM), meaning the XML data is parsed
|
||||
into a C++ objects that can be browsed and manipulated, and then
|
||||
written to disk or another output stream. You can also construct an XML document
|
||||
from scratch with C++ objects and write this to disk or another output
|
||||
stream. You can even use TinyXML-2 to stream XML programmatically from
|
||||
code without creating a document first.
|
||||
|
||||
TinyXML-2 is designed to be easy and fast to learn. It is one header and
|
||||
one cpp file. Simply add these to your project and off you go.
|
||||
There is an example file - xmltest.cpp - to get you started.
|
||||
|
||||
TinyXML-2 is released under the ZLib license,
|
||||
so you can use it in open source or commercial code. The details
|
||||
of the license are at the top of every source file.
|
||||
|
||||
TinyXML-2 attempts to be a flexible parser, but with truly correct and
|
||||
compliant XML output. TinyXML-2 should compile on any reasonably C++
|
||||
compliant system. It does not rely on exceptions, RTTI, or the STL.
|
||||
|
||||
What it doesn't do.
|
||||
-------------------
|
||||
|
||||
TinyXML-2 doesn't parse or use DTDs (Document Type Definitions) or XSLs
|
||||
(eXtensible Stylesheet Language.) There are other parsers out there
|
||||
that are much more fully featured. But they are generally bigger and
|
||||
more difficult to use. If you are working with
|
||||
browsers or have more complete XML needs, TinyXML-2 is not the parser for you.
|
||||
|
||||
TinyXML-1 vs. TinyXML-2
|
||||
-----------------------
|
||||
|
||||
TinyXML-2 long been the focus of all development. It is well tested
|
||||
and should be used instead of TinyXML-1.
|
||||
|
||||
TinyXML-2 uses a similar API to TinyXML-1 and the same
|
||||
rich test cases. But the implementation of the parser is completely re-written
|
||||
to make it more appropriate for use in a game. It uses less memory, is faster,
|
||||
and uses far fewer memory allocations.
|
||||
|
||||
TinyXML-2 has no requirement or support for STL.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
### Code Page
|
||||
|
||||
TinyXML-2 uses UTF-8 exclusively when interpreting XML. All XML is assumed to
|
||||
be UTF-8.
|
||||
|
||||
Filenames for loading / saving are passed unchanged to the underlying OS.
|
||||
|
||||
### Memory Model
|
||||
|
||||
An XMLDocument is a C++ object like any other, that can be on the stack, or
|
||||
new'd and deleted on the heap.
|
||||
|
||||
However, any sub-node of the Document, XMLElement, XMLText, etc, can only
|
||||
be created by calling the appropriate XMLDocument::NewElement, NewText, etc.
|
||||
method. Although you have pointers to these objects, they are still owned
|
||||
by the Document. When the Document is deleted, so are all the nodes it contains.
|
||||
|
||||
### White Space
|
||||
|
||||
#### Whitespace Preservation (default)
|
||||
|
||||
Microsoft has an excellent article on white space: http://msdn.microsoft.com/en-us/library/ms256097.aspx
|
||||
|
||||
By default, TinyXML-2 preserves white space in a (hopefully) sane way that is almost compliant with the
|
||||
spec. (TinyXML-1 used a completely different model, much more similar to 'collapse', below.)
|
||||
|
||||
As a first step, all newlines / carriage-returns / line-feeds are normalized to a
|
||||
line-feed character, as required by the XML spec.
|
||||
|
||||
White space in text is preserved. For example:
|
||||
|
||||
<element> Hello, World</element>
|
||||
|
||||
The leading space before the "Hello" and the double space after the comma are
|
||||
preserved. Line-feeds are preserved, as in this example:
|
||||
|
||||
<element> Hello again,
|
||||
World</element>
|
||||
|
||||
However, white space between elements is **not** preserved. Although not strictly
|
||||
compliant, tracking and reporting inter-element space is awkward, and not normally
|
||||
valuable. TinyXML-2 sees these as the same XML:
|
||||
|
||||
<document>
|
||||
<data>1</data>
|
||||
<data>2</data>
|
||||
<data>3</data>
|
||||
</document>
|
||||
|
||||
<document><data>1</data><data>2</data><data>3</data></document>
|
||||
|
||||
#### Whitespace Collapse
|
||||
|
||||
For some applications, it is preferable to collapse whitespace. Collapsing
|
||||
whitespace gives you "HTML-like" behavior, which is sometimes more suitable
|
||||
for hand typed documents.
|
||||
|
||||
TinyXML-2 supports this with the 'whitespace' parameter to the XMLDocument constructor.
|
||||
(The default is to preserve whitespace, as described above.)
|
||||
|
||||
However, you may also use COLLAPSE_WHITESPACE, which will:
|
||||
|
||||
* Remove leading and trailing whitespace
|
||||
* Convert newlines and line-feeds into a space character
|
||||
* Collapse a run of any number of space characters into a single space character
|
||||
|
||||
Note that (currently) there is a performance impact for using COLLAPSE_WHITESPACE.
|
||||
It essentially causes the XML to be parsed twice.
|
||||
|
||||
#### Error Reporting
|
||||
|
||||
TinyXML-2 reports the line number of any errors in an XML document that
|
||||
cannot be parsed correctly. In addition, all nodes (elements, declarations,
|
||||
text, comments etc.) and attributes have a line number recorded as they are parsed.
|
||||
This allows an application that performs additional validation of the parsed
|
||||
XML document (e.g. application-implemented DTD validation) to report
|
||||
line number information for error messages.
|
||||
|
||||
### Entities
|
||||
|
||||
TinyXML-2 recognizes the pre-defined "character entities", meaning special
|
||||
characters. Namely:
|
||||
|
||||
& &
|
||||
< <
|
||||
> >
|
||||
" "
|
||||
' '
|
||||
|
||||
These are recognized when the XML document is read, and translated to their
|
||||
UTF-8 equivalents. For instance, text with the XML of:
|
||||
|
||||
Far & Away
|
||||
|
||||
will have the Value() of "Far & Away" when queried from the XMLText object,
|
||||
and will be written back to the XML stream/file as an ampersand.
|
||||
|
||||
Additionally, any character can be specified by its Unicode code point:
|
||||
The syntax ` ` or ` ` are both to the non-breaking space character.
|
||||
This is called a 'numeric character reference'. Any numeric character reference
|
||||
that isn't one of the special entities above, will be read, but written as a
|
||||
regular code point. The output is correct, but the entity syntax isn't preserved.
|
||||
|
||||
### Printing
|
||||
|
||||
#### Print to file
|
||||
You can directly use the convenience function:
|
||||
|
||||
XMLDocument doc;
|
||||
...
|
||||
doc.SaveFile( "foo.xml" );
|
||||
|
||||
Or the XMLPrinter class:
|
||||
|
||||
XMLPrinter printer( fp );
|
||||
doc.Print( &printer );
|
||||
|
||||
#### Print to memory
|
||||
Printing to memory is supported by the XMLPrinter.
|
||||
|
||||
XMLPrinter printer;
|
||||
doc.Print( &printer );
|
||||
// printer.CStr() has a const char* to the XML
|
||||
|
||||
#### Print without an XMLDocument
|
||||
|
||||
When loading, an XML parser is very useful. However, sometimes
|
||||
when saving, it just gets in the way. The code is often set up
|
||||
for streaming, and constructing the DOM is just overhead.
|
||||
|
||||
The Printer supports the streaming case. The following code
|
||||
prints out a trivially simple XML file without ever creating
|
||||
an XML document.
|
||||
|
||||
XMLPrinter printer( fp );
|
||||
printer.OpenElement( "foo" );
|
||||
printer.PushAttribute( "foo", "bar" );
|
||||
printer.CloseElement();
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
#### Load and parse an XML file.
|
||||
|
||||
/* ------ Example 1: Load and parse an XML file. ---- */
|
||||
{
|
||||
XMLDocument doc;
|
||||
doc.LoadFile( "dream.xml" );
|
||||
}
|
||||
|
||||
#### Lookup information.
|
||||
|
||||
/* ------ Example 2: Lookup information. ---- */
|
||||
{
|
||||
XMLDocument doc;
|
||||
doc.LoadFile( "dream.xml" );
|
||||
|
||||
// Structure of the XML file:
|
||||
// - Element "PLAY" the root Element, which is the
|
||||
// FirstChildElement of the Document
|
||||
// - - Element "TITLE" child of the root PLAY Element
|
||||
// - - - Text child of the TITLE Element
|
||||
|
||||
// Navigate to the title, using the convenience function,
|
||||
// with a dangerous lack of error checking.
|
||||
const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText();
|
||||
printf( "Name of play (1): %s\n", title );
|
||||
|
||||
// Text is just another Node to TinyXML-2. The more
|
||||
// general way to get to the XMLText:
|
||||
XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText();
|
||||
title = textNode->Value();
|
||||
printf( "Name of play (2): %s\n", title );
|
||||
}
|
||||
|
||||
Using and Installing
|
||||
--------------------
|
||||
|
||||
There are 2 files in TinyXML-2:
|
||||
* tinyxml2.cpp
|
||||
* tinyxml2.h
|
||||
|
||||
And additionally a test file:
|
||||
* xmltest.cpp
|
||||
|
||||
Generally speaking, the intent is that you simply include the tinyxml2.cpp and
|
||||
tinyxml2.h files in your project and build with your other source code.
|
||||
|
||||
There is also a CMake build included. CMake is the general build for TinyXML-2.
|
||||
Additional build systems are costly to maintain, and tend to bit-rot.
|
||||
|
||||
A Visual Studio project is included, but that is largely for developer convenience,
|
||||
and is not intended to integrate well with other builds.
|
||||
|
||||
Building TinyXML-2 - Using vcpkg
|
||||
--------------------------------
|
||||
|
||||
You can download and install TinyXML-2 using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
||||
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
./vcpkg install tinyxml2
|
||||
|
||||
The TinyXML-2 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
Versioning
|
||||
----------
|
||||
|
||||
TinyXML-2 uses semantic versioning. http://semver.org/ Releases are now tagged in github.
|
||||
|
||||
Note that the major version will (probably) change fairly rapidly. API changes are fairly
|
||||
common.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
TinyXML-2 is released under the zlib license:
|
||||
|
||||
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.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
Thanks very much to everyone who sends suggestions, bugs, ideas, and
|
||||
encouragement. It all helps, and makes this project fun.
|
||||
|
||||
The original TinyXML-1 has many contributors, who all deserve thanks
|
||||
in shaping what is a very successful library. Extra thanks to Yves
|
||||
Berquin and Andrew Ellerton who were key contributors.
|
||||
|
||||
TinyXML-2 grew from that effort. Lee Thomason is the original author
|
||||
of TinyXML-2 (and TinyXML-1) but TinyXML-2 has been and is being improved
|
||||
by many contributors.
|
||||
|
||||
Thanks to John Mackay at http://john.mackay.rosalilastudio.com for the TinyXML-2 logo!
|
||||
|
||||
|
||||
2994
src/external/tinyxml2/tinyxml2.cpp
vendored
Executable file
2994
src/external/tinyxml2/tinyxml2.cpp
vendored
Executable file
File diff suppressed because it is too large
Load Diff
2380
src/external/tinyxml2/tinyxml2.h
vendored
Executable file
2380
src/external/tinyxml2/tinyxml2.h
vendored
Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user