mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 07:37:28 +02:00
update use of vectors
This commit is contained in:
parent
ce6f2b7bcc
commit
8439019c4e
2 changed files with 21 additions and 26 deletions
|
@ -734,8 +734,7 @@ glm::mat4 GLTFSerializer::getModelTransform(const GLTFNode& node) {
|
||||||
return tmat;
|
return tmat;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<float>> GLTFSerializer::getSkinInverseBindMatrices() {
|
void GLTFSerializer::getSkinInverseBindMatrices(std::vector<std::vector<float>>& inverseBindMatrixValues) {
|
||||||
std::vector<std::vector<float>> inverseBindMatrixValues;
|
|
||||||
for (auto &skin : _file.skins) {
|
for (auto &skin : _file.skins) {
|
||||||
GLTFAccessor& indicesAccessor = _file.accessors[skin.inverseBindMatrices];
|
GLTFAccessor& indicesAccessor = _file.accessors[skin.inverseBindMatrices];
|
||||||
GLTFBufferView& indicesBufferview = _file.bufferviews[indicesAccessor.bufferView];
|
GLTFBufferView& indicesBufferview = _file.bufferviews[indicesAccessor.bufferView];
|
||||||
|
@ -750,31 +749,28 @@ std::vector<std::vector<float>> GLTFSerializer::getSkinInverseBindMatrices() {
|
||||||
indicesAccessor.componentType);
|
indicesAccessor.componentType);
|
||||||
inverseBindMatrixValues.push_back(matrices.toStdVector());
|
inverseBindMatrixValues.push_back(matrices.toStdVector());
|
||||||
}
|
}
|
||||||
return inverseBindMatrixValues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> GLTFSerializer::nodeDFS(int n, std::vector<int>& children, int stride) {
|
void GLTFSerializer::getNodeQueueByDepthFirstChildren(std::vector<int>& children, int stride, std::vector<int>& result) {
|
||||||
std::vector<int> result;
|
int startingIndex = 0;
|
||||||
result.push_back(n);
|
int finalIndex = (int)children.size();
|
||||||
int rootDFS = 0;
|
|
||||||
int finalDFS = (int)children.size();
|
|
||||||
if (stride == -1) {
|
if (stride == -1) {
|
||||||
rootDFS = (int)children.size() - 1;
|
startingIndex = (int)children.size() - 1;
|
||||||
finalDFS = -1;
|
finalIndex = -1;
|
||||||
}
|
}
|
||||||
for (int index = rootDFS; index != finalDFS; index += stride) {
|
for (int index = startingIndex; index != finalIndex; index += stride) {
|
||||||
int c = children[index];
|
int c = children[index];
|
||||||
|
result.push_back(c);
|
||||||
std::vector<int> nested = _file.nodes[c].children.toStdVector();
|
std::vector<int> nested = _file.nodes[c].children.toStdVector();
|
||||||
if (nested.size() != 0) {
|
if (nested.size() != 0) {
|
||||||
std::sort(nested.begin(), nested.end());
|
std::sort(nested.begin(), nested.end());
|
||||||
for (int n : nodeDFS(c, nested, stride)) {
|
for (int r : nested) {
|
||||||
result.push_back(n);
|
if (result.end() == std::find(result.begin(), result.end(), r)) {
|
||||||
|
getNodeQueueByDepthFirstChildren(nested, stride, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
result.push_back(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -810,7 +806,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::URL& url) {
|
||||||
|
|
||||||
|
|
||||||
// initialize order in which nodes will be parsed
|
// initialize order in which nodes will be parsed
|
||||||
QVector<int> nodeQueue;
|
std::vector<int> nodeQueue;
|
||||||
nodeQueue.reserve(numNodes);
|
nodeQueue.reserve(numNodes);
|
||||||
int rootNode = 0;
|
int rootNode = 0;
|
||||||
int finalNode = numNodes;
|
int finalNode = numNodes;
|
||||||
|
@ -832,14 +828,12 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::URL& url) {
|
||||||
}
|
}
|
||||||
for (int index = sceneRootNode; index != sceneFinalNode; index += nodeListStride) {
|
for (int index = sceneRootNode; index != sceneFinalNode; index += nodeListStride) {
|
||||||
int i = initialSceneNodes[index];
|
int i = initialSceneNodes[index];
|
||||||
|
nodeQueue.push_back(i);
|
||||||
std::vector<int> children = _file.nodes[i].children.toStdVector();
|
std::vector<int> children = _file.nodes[i].children.toStdVector();
|
||||||
std::sort(children.begin(), children.end());
|
std::sort(children.begin(), children.end());
|
||||||
for (int n : nodeDFS(i, children, nodeListStride)) {
|
getNodeQueueByDepthFirstChildren(children, nodeListStride, nodeQueue);
|
||||||
nodeQueue.append(n);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Build joints
|
// Build joints
|
||||||
HFMJoint joint;
|
HFMJoint joint;
|
||||||
joint.distanceToParent = 0;
|
joint.distanceToParent = 0;
|
||||||
|
@ -851,7 +845,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::URL& url) {
|
||||||
|
|
||||||
joint.parentIndex = -1;
|
joint.parentIndex = -1;
|
||||||
if (!_file.scenes[_file.scene].nodes.contains(nodeIndex)) {
|
if (!_file.scenes[_file.scene].nodes.contains(nodeIndex)) {
|
||||||
joint.parentIndex = nodeQueue.indexOf(nodeDependencies[nodeIndex][0]);
|
joint.parentIndex = std::distance(nodeQueue.begin(), std::find(nodeQueue.begin(), nodeQueue.end(), nodeDependencies[nodeIndex][0]));
|
||||||
}
|
}
|
||||||
joint.transform = node.transforms.first();
|
joint.transform = node.transforms.first();
|
||||||
joint.translation = extractTranslation(joint.transform);
|
joint.translation = extractTranslation(joint.transform);
|
||||||
|
@ -869,7 +863,8 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::URL& url) {
|
||||||
std::vector<glm::mat4> jointInverseBindTransforms;
|
std::vector<glm::mat4> jointInverseBindTransforms;
|
||||||
if (!_file.skins.isEmpty()) {
|
if (!_file.skins.isEmpty()) {
|
||||||
int matrixIndex = 0;
|
int matrixIndex = 0;
|
||||||
std::vector<std::vector<float>> inverseBindValues = getSkinInverseBindMatrices();
|
std::vector<std::vector<float>> inverseBindValues;
|
||||||
|
getSkinInverseBindMatrices(inverseBindValues);
|
||||||
jointInverseBindTransforms.resize(numNodes);
|
jointInverseBindTransforms.resize(numNodes);
|
||||||
|
|
||||||
int jointIndex = finalNode;
|
int jointIndex = finalNode;
|
||||||
|
|
|
@ -712,8 +712,8 @@ private:
|
||||||
hifi::ByteArray _glbBinary;
|
hifi::ByteArray _glbBinary;
|
||||||
|
|
||||||
glm::mat4 getModelTransform(const GLTFNode& node);
|
glm::mat4 getModelTransform(const GLTFNode& node);
|
||||||
std::vector<std::vector<float>> getSkinInverseBindMatrices();
|
void getSkinInverseBindMatrices(std::vector<std::vector<float>>& inverseBindMatrixValues);
|
||||||
std::vector<int> nodeDFS(int n, std::vector<int>& children, int stride);
|
void getNodeQueueByDepthFirstChildren(std::vector<int>& children, int stride, std::vector<int>& result);
|
||||||
|
|
||||||
bool buildGeometry(HFMModel& hfmModel, const hifi::URL& url);
|
bool buildGeometry(HFMModel& hfmModel, const hifi::URL& url);
|
||||||
bool parseGLTF(const hifi::ByteArray& data);
|
bool parseGLTF(const hifi::ByteArray& data);
|
||||||
|
|
Loading…
Reference in a new issue