Coverage Report

Created: 2026-01-07 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/Pbrt/PbrtExporter.h
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2025, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
copyright notice, this list of conditions and the
15
following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
copyright notice, this list of conditions and the
19
following disclaimer in the documentation and/or other
20
materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
contributors may be used to endorse or promote products
24
derived from this software without specific prior
25
written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39
----------------------------------------------------------------------
40
*/
41
42
/** @file PbrtExporter.h
43
* Declares the exporter class to write a scene to a pbrt file
44
*/
45
#ifndef AI_PBRTEXPORTER_H_INC
46
#define AI_PBRTEXPORTER_H_INC
47
48
#ifndef ASSIMP_BUILD_NO_PBRT_EXPORTER
49
50
#include <assimp/types.h>
51
#include <assimp/StreamWriter.h>
52
#include <assimp/Exceptional.h>
53
54
#include <map>
55
#include <set>
56
#include <string>
57
#include <sstream>
58
59
struct aiScene;
60
struct aiNode;
61
struct aiMaterial;
62
struct aiMesh;
63
64
namespace Assimp {
65
66
class IOSystem;
67
class IOStream;
68
class ExportProperties;
69
70
// ---------------------------------------------------------------------
71
/** Helper class to export a given scene to a Pbrt file. */
72
// ---------------------------------------------------------------------
73
class PbrtExporter {
74
public:
75
    /// Constructor for a specific scene to export
76
    PbrtExporter(const aiScene *pScene, IOSystem *pIOSystem,
77
            const std::string &path, const std::string &file, const std::string &texturesPath);
78
79
    /// Destructor
80
0
    virtual ~PbrtExporter() = default;
81
82
private:
83
    aiMatrix4x4 GetNodeTransform(const aiString &name) const;
84
    static std::string TransformAsString(const aiMatrix4x4 &m);
85
    static std::string RemoveSuffix(std::string filename);
86
    std::string CleanTextureFilename(const aiString &f, bool rewriteExtension = true) const;
87
    void WriteMetaData();
88
    void WriteWorldDefinition();
89
    void WriteCameras();
90
    void WriteCamera(int i);
91
    void WriteLights();
92
    void WriteTextures();
93
    static bool TextureHasAlphaMask(const std::string &filename);
94
    void WriteMaterials();
95
    void WriteMaterial(int i);
96
    void WriteMesh(aiMesh *mesh);
97
    void WriteInstanceDefinition(int i);
98
    void WriteGeometricObjects(aiNode *node, aiMatrix4x4 parentTransform,
99
            std::map<int, int> &meshUses);
100
101
private:
102
    // the scene to export
103
    const aiScene* mScene;
104
105
    /// Stringstream to write all output into
106
    std::stringstream mOutput;
107
108
    /// The IOSystem for output
109
    IOSystem* mIOSystem;
110
111
    /// Path of the directory where the scene will be exported
112
    const std::string mPath;
113
114
    /// Name of the file (without extension) where the scene will be exported
115
    const std::string mFile;
116
117
    /// Path of the textures directory (inlcuding seperator)
118
    const std::string mTexturesPath;
119
120
    //  A private set to keep track of which textures have been declared
121
    std::set<std::string> mTextureSet;
122
123
    // Transform to apply to the root node and all root objects such as cameras, lights, etc.
124
    aiMatrix4x4 mRootTransform;
125
};
126
127
} // namespace Assimp
128
129
#endif // ASSIMP_BUILD_NO_PBRT_EXPORTER
130
131
#endif // AI_PBRTEXPORTER_H_INC