-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bone data to Mesh and MeshVertext structs
- Loading branch information
1 parent
eee2d47
commit 0b5bda2
Showing
24 changed files
with
817 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ on: | |
type: boolean | ||
|
||
env: | ||
VERSION: '1.0.0' | ||
VERSION: '2.0.0' | ||
|
||
jobs: | ||
Build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "BonesReader.h" | ||
|
||
namespace nc::asset | ||
{ | ||
auto ReadMatrix(RawNcaBuffer& bytes) -> DirectX::XMMATRIX | ||
{ | ||
float buf[16]; | ||
bytes.Read(buf, 16 * sizeof(float)); | ||
return DirectX::XMMATRIX{buf}; | ||
} | ||
|
||
auto ReadVertexToBoneMatrices(RawNcaBuffer& bytes, size_t matrixCount) -> std::vector<nc::asset::VertexSpaceToBoneSpace> | ||
{ | ||
auto vertexSpaceToBoneSpaceMatrices = std::vector<nc::asset::VertexSpaceToBoneSpace>{}; | ||
vertexSpaceToBoneSpaceMatrices.reserve(matrixCount); | ||
for (auto i = 0u; i < matrixCount; i++) | ||
{ | ||
auto boneNameSize = size_t{}; | ||
bytes.Read(&boneNameSize); | ||
auto vertexSpaceToBoneSpace = nc::asset::VertexSpaceToBoneSpace{}; | ||
vertexSpaceToBoneSpace.boneName.resize(boneNameSize); | ||
bytes.Read(vertexSpaceToBoneSpace.boneName.data(), boneNameSize); | ||
vertexSpaceToBoneSpace.transformationMatrix = ReadMatrix(bytes); | ||
vertexSpaceToBoneSpaceMatrices.push_back(std::move(vertexSpaceToBoneSpace)); | ||
} | ||
return vertexSpaceToBoneSpaceMatrices; | ||
} | ||
|
||
auto ReadBoneToParentMatrices(RawNcaBuffer& bytes, size_t matrixCount) -> std::vector<nc::asset::BoneSpaceToParentSpace> | ||
{ | ||
auto boneSpaceToParentSpaceMatrices = std::vector<nc::asset::BoneSpaceToParentSpace>{}; | ||
boneSpaceToParentSpaceMatrices.reserve(matrixCount); | ||
for (auto i = 0u; i < matrixCount; i++) | ||
{ | ||
auto numChildren = uint32_t{}; | ||
auto indexOfFirstChild = uint32_t{}; | ||
auto boneNameSize = size_t{}; | ||
bytes.Read(&boneNameSize); | ||
auto boneSpaceToParentSpace = nc::asset::BoneSpaceToParentSpace{}; | ||
boneSpaceToParentSpace.boneName.resize(boneNameSize); | ||
bytes.Read(boneSpaceToParentSpace.boneName.data(), boneNameSize); | ||
boneSpaceToParentSpace.transformationMatrix = ReadMatrix(bytes); | ||
bytes.Read(&numChildren); | ||
boneSpaceToParentSpace.numChildren = numChildren; | ||
bytes.Read(&indexOfFirstChild); | ||
boneSpaceToParentSpace.indexOfFirstChild = indexOfFirstChild; | ||
boneSpaceToParentSpaceMatrices.push_back(std::move(boneSpaceToParentSpace)); | ||
} | ||
return boneSpaceToParentSpaceMatrices; | ||
} | ||
} // namespace nc::asset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "ncasset/Assets.h" | ||
#include "RawNcaBuffer.h" | ||
|
||
namespace nc::asset | ||
{ | ||
/** @brief Read a VertexSpaceToBoneSpace vector from a RawNcaBuffer byte stream. | ||
* A VertexSpaceToBoneSpace object represents the transformation matrix required to transform the vertex/vertices affected by the named bone into the bone's space. | ||
* | ||
* @param bytes The byte stream to read from. | ||
* @param matrixCount The count of items in the VertexSpaceToBoneSpace vector. | ||
* @returns A VertexSpaceToBoneSpace vector | ||
*/ | ||
auto ReadVertexToBoneMatrices(RawNcaBuffer& bytes, size_t matrixCount) -> std::vector<nc::asset::VertexSpaceToBoneSpace>; | ||
|
||
/** @brief Read a BoneSpaceToParentSpace vector from a RawNcaBuffer byte stream. | ||
* A BoneSpaceToParentSpace object represents the transformation matrix required to transform the named bone's space into it's parent bone's space. | ||
* | ||
* @param bytes The byte stream to read from. | ||
* @param matrixCount The count of items in the BoneSpaceToParentSpace vector. | ||
* @returns A vector of BoneSpaceToParentSpace objects. | ||
*/ | ||
auto ReadBoneToParentMatrices(RawNcaBuffer& bytes, size_t matrixCount) -> std::vector<nc::asset::BoneSpaceToParentSpace>; | ||
|
||
/** @brief Read a DirectX::XMMATRIX from a RawNcaBuffer byte stream. | ||
* | ||
* @param bytes The byte stream to read from. | ||
*/ | ||
auto ReadMatrix(RawNcaBuffer& bytes) -> DirectX::XMMATRIX; | ||
} // namespace nc::asset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "BonesWriter.h" | ||
#include "builder/DataWriter.h" | ||
|
||
#include <cstring> | ||
|
||
namespace nc::convert | ||
{ | ||
void Write(std::ostream& stream, const std::vector<nc::asset::VertexSpaceToBoneSpace>& vertexSpaceToBoneSpaceMatrices) | ||
{ | ||
for (const auto& toBoneSpace : vertexSpaceToBoneSpaceMatrices) | ||
{ | ||
Write(stream, toBoneSpace.boneName.size()); | ||
Write(stream, toBoneSpace.boneName.data(), toBoneSpace.boneName.size()); | ||
Write(stream, toBoneSpace.transformationMatrix); | ||
} | ||
} | ||
|
||
void Write(std::ostream& stream, const std::vector<nc::asset::BoneSpaceToParentSpace>& boneSpaceToParentSpaceMatrices) | ||
{ | ||
for (const auto& toParentSpace : boneSpaceToParentSpaceMatrices) | ||
{ | ||
Write(stream, toParentSpace.boneName.size()); | ||
Write(stream, toParentSpace.boneName.data(), toParentSpace.boneName.size()); | ||
Write(stream, toParentSpace.transformationMatrix); | ||
Write(stream, toParentSpace.numChildren); | ||
Write(stream, toParentSpace.indexOfFirstChild); | ||
} | ||
} | ||
|
||
void Write(std::ostream& stream, const DirectX::XMMATRIX& matrix) | ||
{ | ||
DirectX::XMFLOAT4X4 view; | ||
XMStoreFloat4x4(&view, matrix); | ||
Write(stream, view.m, sizeof(float)*16); | ||
} | ||
} // namespace nc::convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include "ncasset/Assets.h" | ||
|
||
#include <ostream> | ||
|
||
namespace nc::convert | ||
{ | ||
/** @brief Write a VertexSpaceToBoneSpace vector to a binary stream. | ||
* | ||
* @param stream The byte stream to write to. | ||
* @param vertexSpaceToBoneSpaceMatrices A vector of VertexSpaceToBoneSpace objects. | ||
* A VertexSpaceToBoneSpace object represents the transformation matrix required to transform the vertex/vertices affected by the named bone into the bone's space. | ||
*/ | ||
void Write(std::ostream& stream, const std::vector<nc::asset::VertexSpaceToBoneSpace>& vertexSpaceToBoneSpaceMatrices); | ||
|
||
/** @brief Write a BoneSpaceToParentSpace vector to a binary stream. | ||
* | ||
* @param stream The byte stream to write to. | ||
* @param boneSpaceToParentSpace A vector of BoneSpaceToParentSpace objects. | ||
* A BoneSpaceToParentSpace object represents the transformation matrix required to transform the named bone's space into it's parent bone's space. | ||
*/ | ||
void Write(std::ostream& stream, const std::vector<nc::asset::BoneSpaceToParentSpace>& boneSpaceToParentSpace); | ||
|
||
/** @brief Write a DirectX::XMMATRIX to a binary stream. | ||
* | ||
* @param bytes The byte stream to write to. | ||
*/ | ||
void Write(std::ostream& stream, const DirectX::XMMATRIX& matrix); | ||
} // namespace nc::convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <ostream> | ||
|
||
namespace nc::convert | ||
{ | ||
/** @brief Write the asset header into the given stream. | ||
* | ||
* @param stream The byte stream to write to. | ||
* @param magicNumber The string_view used to reperesent the asset type. See NcaHeader.h | ||
* @param assetId The unique ID for the asset. | ||
* @param size The size of the asset. | ||
*/ | ||
inline void WriteHeader(std::ostream& stream, std::string_view magicNumber, size_t assetId, size_t size) | ||
{ | ||
constexpr char defaultAlgo[5] = "NONE"; // not yet supported | ||
stream.write(magicNumber.data(), 4); | ||
stream.write(defaultAlgo, 4); | ||
stream.write(reinterpret_cast<const char*>(&assetId), sizeof(size_t)); | ||
stream.write(reinterpret_cast<const char*>(&size), sizeof(size)); | ||
} | ||
|
||
/** @brief Write the data into the stream. | ||
* | ||
* @param stream The byte stream to read to. | ||
* @param data The data to write. | ||
*/ | ||
template<class T> | ||
void Write(std::ostream& stream, const T& data) | ||
{ | ||
stream.write(reinterpret_cast<const char*>(&data), sizeof(T)); | ||
} | ||
|
||
/** @brief Write the data into the stream. Used for vectors/arrays. | ||
* | ||
* @param stream The byte stream to read to. | ||
* @param data The data to write. | ||
* @param size The size of the data to write. | ||
*/ | ||
template<class T> | ||
void Write(std::ostream& stream, const T* data, size_t size) | ||
{ | ||
stream.write(reinterpret_cast<const char*>(data), size); | ||
} | ||
} // namespace nc::convert |
Oops, something went wrong.