/src/assimp/code/PostProcessing/GenBoundingBoxesProcess.cpp
Line | Count | Source |
1 | | /* |
2 | | --------------------------------------------------------------------------- |
3 | | Open Asset Import Library (assimp) |
4 | | --------------------------------------------------------------------------- |
5 | | |
6 | | Copyright (c) 2006-2026, assimp team |
7 | | |
8 | | All rights reserved. |
9 | | |
10 | | Redistribution and use of this software in source and binary forms, |
11 | | with or without modification, are permitted provided that the following |
12 | | conditions are met: |
13 | | |
14 | | * Redistributions of source code must retain the above |
15 | | copyright notice, this list of conditions and the |
16 | | following disclaimer. |
17 | | |
18 | | * Redistributions in binary form must reproduce the above |
19 | | copyright notice, this list of conditions and the |
20 | | following disclaimer in the documentation and/or other |
21 | | materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the assimp team, nor the names of its |
24 | | contributors may be used to endorse or promote products |
25 | | derived from this software without specific prior |
26 | | written permission of the assimp team. |
27 | | |
28 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
29 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
31 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
32 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
33 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
34 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
35 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
36 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
37 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
38 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
39 | | --------------------------------------------------------------------------- |
40 | | */ |
41 | | |
42 | | #ifndef ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS |
43 | | |
44 | | #include "PostProcessing/GenBoundingBoxesProcess.h" |
45 | | |
46 | | #include <assimp/postprocess.h> |
47 | | #include <assimp/scene.h> |
48 | | |
49 | | namespace Assimp { |
50 | | |
51 | 2.01k | bool GenBoundingBoxesProcess::IsActive(unsigned int pFlags) const { |
52 | 2.01k | return 0 != ( pFlags & aiProcess_GenBoundingBoxes ); |
53 | 2.01k | } |
54 | | |
55 | 0 | void checkMesh(aiMesh* mesh, aiVector3D& min, aiVector3D& max) { |
56 | 0 | ai_assert(nullptr != mesh); |
57 | |
|
58 | 0 | if (0 == mesh->mNumVertices) { |
59 | 0 | return; |
60 | 0 | } |
61 | | |
62 | 0 | for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { |
63 | 0 | const aiVector3D &pos = mesh->mVertices[i]; |
64 | 0 | if (pos.x < min.x) { |
65 | 0 | min.x = pos.x; |
66 | 0 | } |
67 | 0 | if (pos.y < min.y) { |
68 | 0 | min.y = pos.y; |
69 | 0 | } |
70 | 0 | if (pos.z < min.z) { |
71 | 0 | min.z = pos.z; |
72 | 0 | } |
73 | |
|
74 | 0 | if (pos.x > max.x) { |
75 | 0 | max.x = pos.x; |
76 | 0 | } |
77 | 0 | if (pos.y > max.y) { |
78 | 0 | max.y = pos.y; |
79 | 0 | } |
80 | 0 | if (pos.z > max.z) { |
81 | 0 | max.z = pos.z; |
82 | 0 | } |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | 0 | void GenBoundingBoxesProcess::Execute(aiScene* pScene) { |
87 | 0 | if (nullptr == pScene) { |
88 | 0 | return; |
89 | 0 | } |
90 | | |
91 | 0 | for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) { |
92 | 0 | aiMesh* mesh = pScene->mMeshes[i]; |
93 | 0 | if (nullptr == mesh) { |
94 | 0 | continue; |
95 | 0 | } |
96 | | |
97 | 0 | aiVector3D min(999999, 999999, 999999), max(-999999, -999999, -999999); |
98 | 0 | checkMesh(mesh, min, max); |
99 | 0 | mesh->mAABB.mMin = min; |
100 | 0 | mesh->mAABB.mMax = max; |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | | } // Namespace Assimp |
105 | | |
106 | | #endif // ASSIMP_BUILD_NO_GENBOUNDINGBOXES_PROCESS |