1 | /* |
2 | --------------------------------------------------------------------------- |
3 | Open Asset Import Library (assimp) |
4 | --------------------------------------------------------------------------- |
5 | |
6 | Copyright (c) 2006-2017, assimp team |
7 | |
8 | |
9 | All rights reserved. |
10 | |
11 | Redistribution and use of this software in source and binary forms, |
12 | with or without modification, are permitted provided that the following |
13 | conditions are met: |
14 | |
15 | * Redistributions of source code must retain the above |
16 | copyright notice, this list of conditions and the |
17 | following disclaimer. |
18 | |
19 | * Redistributions in binary form must reproduce the above |
20 | copyright notice, this list of conditions and the |
21 | following disclaimer in the documentation and/or other |
22 | materials provided with the distribution. |
23 | |
24 | * Neither the name of the assimp team, nor the names of its |
25 | contributors may be used to endorse or promote products |
26 | derived from this software without specific prior |
27 | written permission of the assimp team. |
28 | |
29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
33 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
34 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
35 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
36 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
37 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
38 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
39 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
40 | --------------------------------------------------------------------------- |
41 | */ |
42 | #include <assimp/scene.h> |
43 | |
44 | aiNode::aiNode() |
45 | : mName("" ) |
46 | , mParent(NULL) |
47 | , mNumChildren(0) |
48 | , mChildren(NULL) |
49 | , mNumMeshes(0) |
50 | , mMeshes(NULL) |
51 | , mMetaData(NULL) { |
52 | // empty |
53 | } |
54 | |
55 | aiNode::aiNode(const std::string& name) |
56 | : mName(name) |
57 | , mParent(NULL) |
58 | , mNumChildren(0) |
59 | , mChildren(NULL) |
60 | , mNumMeshes(0) |
61 | , mMeshes(NULL) |
62 | , mMetaData(NULL) { |
63 | // empty |
64 | } |
65 | |
66 | /** Destructor */ |
67 | aiNode::~aiNode() { |
68 | // delete all children recursively |
69 | // to make sure we won't crash if the data is invalid ... |
70 | if (mChildren && mNumChildren) |
71 | { |
72 | for (unsigned int a = 0; a < mNumChildren; a++) |
73 | delete mChildren[a]; |
74 | } |
75 | delete[] mChildren; |
76 | delete[] mMeshes; |
77 | delete mMetaData; |
78 | } |
79 | |
80 | const aiNode *aiNode::FindNode(const char* name) const { |
81 | if (nullptr == name) { |
82 | return nullptr; |
83 | } |
84 | if (!::strcmp(mName.data, name)) { |
85 | return this; |
86 | } |
87 | for (unsigned int i = 0; i < mNumChildren; ++i) { |
88 | const aiNode* const p = mChildren[i]->FindNode(name); |
89 | if (p) { |
90 | return p; |
91 | } |
92 | } |
93 | // there is definitely no sub-node with this name |
94 | return nullptr; |
95 | } |
96 | |
97 | aiNode *aiNode::FindNode(const char* name) { |
98 | if (!::strcmp(mName.data, name))return this; |
99 | for (unsigned int i = 0; i < mNumChildren; ++i) |
100 | { |
101 | aiNode* const p = mChildren[i]->FindNode(name); |
102 | if (p) { |
103 | return p; |
104 | } |
105 | } |
106 | // there is definitely no sub-node with this name |
107 | return nullptr; |
108 | } |
109 | |
110 | void aiNode::addChildren(unsigned int numChildren, aiNode **children) { |
111 | if (nullptr == children || 0 == numChildren) { |
112 | return; |
113 | } |
114 | |
115 | for (unsigned int i = 0; i < numChildren; i++) { |
116 | aiNode *child = children[i]; |
117 | if (nullptr != child) { |
118 | child->mParent = this; |
119 | } |
120 | } |
121 | |
122 | if (mNumChildren > 0) { |
123 | aiNode **tmp = new aiNode*[mNumChildren]; |
124 | ::memcpy(tmp, mChildren, sizeof(aiNode*) * mNumChildren); |
125 | delete[] mChildren; |
126 | mChildren = new aiNode*[mNumChildren + numChildren]; |
127 | ::memcpy(mChildren, tmp, sizeof(aiNode*) * mNumChildren); |
128 | ::memcpy(&mChildren[mNumChildren], children, sizeof(aiNode*)* numChildren); |
129 | mNumChildren += numChildren; |
130 | delete[] tmp; |
131 | } |
132 | else { |
133 | mChildren = new aiNode*[numChildren]; |
134 | for (unsigned int i = 0; i < numChildren; i++) { |
135 | mChildren[i] = children[i]; |
136 | } |
137 | mNumChildren = numChildren; |
138 | } |
139 | } |
140 | |