mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-06-08 03:13:28 +00:00
Merge pull request #17 from lioncash/connect
Connection: Minor miscellaneous changes
This commit is contained in:
commit
3a73ce7051
@ -12,32 +12,38 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cfloat>
|
|
||||||
#include <string>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
#include <ostream>
|
||||||
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <atomic>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "hecl/hecl.hpp"
|
#include "hecl/hecl.hpp"
|
||||||
|
#include "hecl/Backend.hpp"
|
||||||
#include "hecl/HMDLMeta.hpp"
|
#include "hecl/HMDLMeta.hpp"
|
||||||
#include "hecl/TypedVariant.hpp"
|
#include "hecl/TypedVariant.hpp"
|
||||||
#include "hecl/Backend.hpp"
|
|
||||||
#include "athena/Types.hpp"
|
#include <athena/Types.hpp>
|
||||||
#include "athena/MemoryWriter.hpp"
|
|
||||||
#include <optional>
|
|
||||||
#include "Token.hpp"
|
|
||||||
#include <fmt/ostream.h>
|
#include <fmt/ostream.h>
|
||||||
|
#include <logvisor/logvisor.hpp>
|
||||||
|
#include <xxhash/xxhash.h>
|
||||||
|
|
||||||
namespace hecl::blender {
|
namespace hecl::blender {
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
extern logvisor::Module BlenderLog;
|
|
||||||
class HMDLBuffers;
|
|
||||||
class Connection;
|
class Connection;
|
||||||
|
class HMDLBuffers;
|
||||||
|
|
||||||
|
extern logvisor::Module BlenderLog;
|
||||||
|
|
||||||
struct PoolSkinIndex {
|
struct PoolSkinIndex {
|
||||||
size_t m_poolSz = 0;
|
size_t m_poolSz = 0;
|
||||||
@ -136,15 +142,15 @@ struct Vector4f {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct Matrix3f {
|
struct Matrix3f {
|
||||||
atVec3f m[3];
|
std::array<atVec3f, 3> m;
|
||||||
inline atVec3f& operator[](size_t idx) { return m[idx]; }
|
atVec3f& operator[](size_t idx) { return m[idx]; }
|
||||||
inline const atVec3f& operator[](size_t idx) const { return m[idx]; }
|
const atVec3f& operator[](size_t idx) const { return m[idx]; }
|
||||||
};
|
};
|
||||||
struct Matrix4f {
|
struct Matrix4f {
|
||||||
atVec4f val[4];
|
std::array<atVec4f, 4> val;
|
||||||
Matrix4f() = default;
|
Matrix4f() = default;
|
||||||
void read(Connection& conn);
|
|
||||||
Matrix4f(Connection& conn) { read(conn); }
|
Matrix4f(Connection& conn) { read(conn); }
|
||||||
|
void read(Connection& conn);
|
||||||
const atVec4f& operator[](size_t idx) const { return val[idx]; }
|
const atVec4f& operator[](size_t idx) const { return val[idx]; }
|
||||||
};
|
};
|
||||||
struct Index {
|
struct Index {
|
||||||
@ -343,8 +349,8 @@ struct Mesh {
|
|||||||
struct Vert {
|
struct Vert {
|
||||||
uint32_t iPos = 0xffffffff;
|
uint32_t iPos = 0xffffffff;
|
||||||
uint32_t iNorm = 0xffffffff;
|
uint32_t iNorm = 0xffffffff;
|
||||||
uint32_t iColor[4] = {0xffffffff};
|
std::array<uint32_t, 4> iColor = {0xffffffff};
|
||||||
uint32_t iUv[8] = {0xffffffff};
|
std::array<uint32_t, 8> iUv = {0xffffffff};
|
||||||
uint32_t iSkin = 0xffffffff;
|
uint32_t iSkin = 0xffffffff;
|
||||||
uint32_t iBankSkin = 0xffffffff;
|
uint32_t iBankSkin = 0xffffffff;
|
||||||
|
|
||||||
@ -433,14 +439,14 @@ struct ColMesh {
|
|||||||
std::vector<Vector3f> verts;
|
std::vector<Vector3f> verts;
|
||||||
|
|
||||||
struct Edge {
|
struct Edge {
|
||||||
uint32_t verts[2];
|
std::array<uint32_t, 2> verts;
|
||||||
bool seam;
|
bool seam;
|
||||||
Edge(Connection& conn);
|
Edge(Connection& conn);
|
||||||
};
|
};
|
||||||
std::vector<Edge> edges;
|
std::vector<Edge> edges;
|
||||||
|
|
||||||
struct Triangle {
|
struct Triangle {
|
||||||
uint32_t edges[3];
|
std::array<uint32_t, 3> edges;
|
||||||
uint32_t matIdx;
|
uint32_t matIdx;
|
||||||
bool flip;
|
bool flip;
|
||||||
Triangle(Connection& conn);
|
Triangle(Connection& conn);
|
||||||
@ -454,10 +460,10 @@ struct ColMesh {
|
|||||||
struct World {
|
struct World {
|
||||||
struct Area {
|
struct Area {
|
||||||
ProjectPath path;
|
ProjectPath path;
|
||||||
Vector3f aabb[2];
|
std::array<Vector3f, 2> aabb;
|
||||||
Matrix4f transform;
|
Matrix4f transform;
|
||||||
struct Dock {
|
struct Dock {
|
||||||
Vector3f verts[4];
|
std::array<Vector3f, 4> verts;
|
||||||
Index targetArea;
|
Index targetArea;
|
||||||
Index targetDock;
|
Index targetDock;
|
||||||
Dock(Connection& conn);
|
Dock(Connection& conn);
|
||||||
@ -666,30 +672,30 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Connection {
|
class Connection {
|
||||||
|
friend class ANIMOutStream;
|
||||||
friend class DataStream;
|
friend class DataStream;
|
||||||
friend class PyOutStream;
|
friend class PyOutStream;
|
||||||
friend class ANIMOutStream;
|
friend struct Action;
|
||||||
friend struct PyOutStream::StreamBuf;
|
friend struct Actor;
|
||||||
friend struct Mesh;
|
friend struct Armature;
|
||||||
friend struct Material;
|
friend struct Bone;
|
||||||
|
friend struct Boolean;
|
||||||
friend struct ColMesh;
|
friend struct ColMesh;
|
||||||
friend struct World;
|
friend struct Float;
|
||||||
|
friend struct Index;
|
||||||
friend struct Light;
|
friend struct Light;
|
||||||
friend struct MapArea;
|
friend struct MapArea;
|
||||||
friend struct MapUniverse;
|
friend struct MapUniverse;
|
||||||
friend struct Actor;
|
friend struct Material;
|
||||||
friend struct Armature;
|
friend struct Matrix3f;
|
||||||
friend struct Action;
|
friend struct Matrix4f;
|
||||||
friend struct Bone;
|
friend struct Mesh;
|
||||||
friend struct PathMesh;
|
friend struct PathMesh;
|
||||||
|
friend struct PyOutStream::StreamBuf;
|
||||||
friend struct Vector2f;
|
friend struct Vector2f;
|
||||||
friend struct Vector3f;
|
friend struct Vector3f;
|
||||||
friend struct Vector4f;
|
friend struct Vector4f;
|
||||||
friend struct Matrix3f;
|
friend struct World;
|
||||||
friend struct Matrix4f;
|
|
||||||
friend struct Index;
|
|
||||||
friend struct Float;
|
|
||||||
friend struct Boolean;
|
|
||||||
|
|
||||||
std::atomic_bool m_lock = {false};
|
std::atomic_bool m_lock = {false};
|
||||||
bool m_pyStreamActive = false;
|
bool m_pyStreamActive = false;
|
||||||
@ -701,8 +707,8 @@ class Connection {
|
|||||||
#else
|
#else
|
||||||
pid_t m_blenderProc = 0;
|
pid_t m_blenderProc = 0;
|
||||||
#endif
|
#endif
|
||||||
int m_readpipe[2];
|
std::array<int, 2> m_readpipe{};
|
||||||
int m_writepipe[2];
|
std::array<int, 2> m_writepipe{};
|
||||||
BlendType m_loadedType = BlendType::None;
|
BlendType m_loadedType = BlendType::None;
|
||||||
bool m_loadedRigged = false;
|
bool m_loadedRigged = false;
|
||||||
ProjectPath m_loadedBlend;
|
ProjectPath m_loadedBlend;
|
||||||
|
@ -1,23 +1,28 @@
|
|||||||
|
#include <algorithm>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
#include <cfloat>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <csignal>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cinttypes>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <system_error>
|
|
||||||
#include <string>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <system_error>
|
||||||
|
#include <thread>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
#include <hecl/hecl.hpp>
|
#include <hecl/hecl.hpp>
|
||||||
#include <hecl/Database.hpp>
|
#include <hecl/Database.hpp>
|
||||||
#include "logvisor/logvisor.hpp"
|
|
||||||
#include "hecl/Blender/Connection.hpp"
|
#include "hecl/Blender/Connection.hpp"
|
||||||
|
#include "hecl/Blender/Token.hpp"
|
||||||
#include "hecl/SteamFinder.hpp"
|
#include "hecl/SteamFinder.hpp"
|
||||||
#include "MeshOptimizer.hpp"
|
#include "MeshOptimizer.hpp"
|
||||||
|
|
||||||
|
#include <athena/MemoryWriter.hpp>
|
||||||
|
#include <logvisor/logvisor.hpp>
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -283,14 +288,14 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
/* Construct communication pipes */
|
/* Construct communication pipes */
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
_pipe(m_readpipe, 2048, _O_BINARY);
|
_pipe(m_readpipe.data(), 2048, _O_BINARY);
|
||||||
_pipe(m_writepipe, 2048, _O_BINARY);
|
_pipe(m_writepipe.data(), 2048, _O_BINARY);
|
||||||
HANDLE writehandle = HANDLE(_get_osfhandle(m_writepipe[0]));
|
HANDLE writehandle = HANDLE(_get_osfhandle(m_writepipe[0]));
|
||||||
SetHandleInformation(writehandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
SetHandleInformation(writehandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
||||||
HANDLE readhandle = HANDLE(_get_osfhandle(m_readpipe[1]));
|
HANDLE readhandle = HANDLE(_get_osfhandle(m_readpipe[1]));
|
||||||
SetHandleInformation(readhandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
SetHandleInformation(readhandle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
|
||||||
|
|
||||||
SECURITY_ATTRIBUTES sattrs = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
|
SECURITY_ATTRIBUTES sattrs = {sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
|
||||||
HANDLE consoleOutReadTmp, consoleOutWrite, consoleErrWrite, consoleOutRead;
|
HANDLE consoleOutReadTmp, consoleOutWrite, consoleErrWrite, consoleOutRead;
|
||||||
if (!CreatePipe(&consoleOutReadTmp, &consoleOutWrite, &sattrs, 1024))
|
if (!CreatePipe(&consoleOutReadTmp, &consoleOutWrite, &sattrs, 1024))
|
||||||
BlenderLog.report(logvisor::Fatal, fmt("Error with CreatePipe"));
|
BlenderLog.report(logvisor::Fatal, fmt("Error with CreatePipe"));
|
||||||
@ -350,7 +355,7 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
|
|
||||||
STARTUPINFO sinfo = {sizeof(STARTUPINFO)};
|
STARTUPINFO sinfo = {sizeof(STARTUPINFO)};
|
||||||
HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sattrs, OPEN_EXISTING,
|
HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sattrs, OPEN_EXISTING,
|
||||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||||
sinfo.dwFlags = STARTF_USESTDHANDLES;
|
sinfo.dwFlags = STARTF_USESTDHANDLES;
|
||||||
sinfo.hStdInput = nulHandle;
|
sinfo.hStdInput = nulHandle;
|
||||||
if (verbosityLevel == 0) {
|
if (verbosityLevel == 0) {
|
||||||
@ -361,11 +366,12 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
sinfo.hStdOutput = consoleOutWrite;
|
sinfo.hStdOutput = consoleOutWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CreateProcessW(blenderBin, const_cast<wchar_t*>(cmdLine.c_str()), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
|
if (!CreateProcessW(blenderBin, cmdLine.data(), nullptr, nullptr, TRUE, NORMAL_PRIORITY_CLASS, nullptr, nullptr,
|
||||||
NULL, NULL, &sinfo, &m_pinfo)) {
|
&sinfo, &m_pinfo)) {
|
||||||
LPWSTR messageBuffer = nullptr;
|
LPWSTR messageBuffer = nullptr;
|
||||||
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
|
nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0,
|
||||||
|
nullptr);
|
||||||
BlenderLog.report(logvisor::Fatal, fmt(L"unable to launch blender from {}: {}"), blenderBin, messageBuffer);
|
BlenderLog.report(logvisor::Fatal, fmt(L"unable to launch blender from {}: {}"), blenderBin, messageBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,7 +389,7 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
DWORD nCharsWritten;
|
DWORD nCharsWritten;
|
||||||
|
|
||||||
while (m_consoleThreadRunning) {
|
while (m_consoleThreadRunning) {
|
||||||
if (!ReadFile(consoleOutRead, lpBuffer, sizeof(lpBuffer), &nBytesRead, NULL) || !nBytesRead) {
|
if (!ReadFile(consoleOutRead, lpBuffer, sizeof(lpBuffer), &nBytesRead, nullptr) || !nBytesRead) {
|
||||||
DWORD err = GetLastError();
|
DWORD err = GetLastError();
|
||||||
if (err == ERROR_BROKEN_PIPE)
|
if (err == ERROR_BROKEN_PIPE)
|
||||||
break; // pipe done - normal exit path.
|
break; // pipe done - normal exit path.
|
||||||
@ -393,7 +399,7 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
|
|
||||||
// Display the character read on the screen.
|
// Display the character read on the screen.
|
||||||
auto lk = logvisor::LockLog();
|
auto lk = logvisor::LockLog();
|
||||||
if (!WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), lpBuffer, nBytesRead, &nCharsWritten, NULL)) {
|
if (!WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), lpBuffer, nBytesRead, &nCharsWritten, nullptr)) {
|
||||||
// BlenderLog.report(logvisor::Error, fmt("Error with WriteConsole: %08X"), GetLastError());
|
// BlenderLog.report(logvisor::Error, fmt("Error with WriteConsole: %08X"), GetLastError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -427,7 +433,7 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
/* Try user-specified blender first */
|
/* Try user-specified blender first */
|
||||||
if (blenderBin) {
|
if (blenderBin) {
|
||||||
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(),
|
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(),
|
||||||
writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), NULL);
|
writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr);
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
||||||
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
||||||
@ -445,7 +451,7 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
#endif
|
#endif
|
||||||
blenderBin = steamBlender.c_str();
|
blenderBin = steamBlender.c_str();
|
||||||
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(),
|
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(),
|
||||||
writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), NULL);
|
writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr);
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
||||||
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
||||||
@ -455,7 +461,7 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
|
|
||||||
/* Otherwise default blender */
|
/* Otherwise default blender */
|
||||||
execlp(DEFAULT_BLENDER_BIN, DEFAULT_BLENDER_BIN, "--background", "-P", blenderShellPath.c_str(), "--",
|
execlp(DEFAULT_BLENDER_BIN, DEFAULT_BLENDER_BIN, "--background", "-P", blenderShellPath.c_str(), "--",
|
||||||
readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), NULL);
|
readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), nullptr);
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
||||||
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
||||||
@ -558,8 +564,9 @@ std::streambuf::int_type PyOutStream::StreamBuf::overflow(int_type ch) {
|
|||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* BlendTypeStrs[] = {"NONE", "MESH", "CMESH", "ACTOR", "AREA", "WORLD",
|
constexpr std::array<const char*, 11> BlendTypeStrs{
|
||||||
"MAPAREA", "MAPUNIVERSE", "FRAME", "PATH", nullptr};
|
"NONE", "MESH", "CMESH", "ACTOR", "AREA", "WORLD", "MAPAREA", "MAPUNIVERSE", "FRAME", "PATH", nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
bool Connection::createBlend(const ProjectPath& path, BlendType type) {
|
bool Connection::createBlend(const ProjectPath& path, BlendType type) {
|
||||||
if (m_lock) {
|
if (m_lock) {
|
||||||
@ -831,8 +838,7 @@ Mesh::Mesh(Connection& conn, HMDLTopology topologyIn, int skinSlotCount, bool us
|
|||||||
Index matSetCount(conn);
|
Index matSetCount(conn);
|
||||||
materialSets.reserve(matSetCount.val);
|
materialSets.reserve(matSetCount.val);
|
||||||
for (uint32_t i = 0; i < matSetCount.val; ++i) {
|
for (uint32_t i = 0; i < matSetCount.val; ++i) {
|
||||||
materialSets.emplace_back();
|
std::vector<Material>& materials = materialSets.emplace_back();
|
||||||
std::vector<Material>& materials = materialSets.back();
|
|
||||||
Index matCount(conn);
|
Index matCount(conn);
|
||||||
materials.reserve(matCount.val);
|
materials.reserve(matCount.val);
|
||||||
for (uint32_t j = 0; j < matCount.val; ++j)
|
for (uint32_t j = 0; j < matCount.val; ++j)
|
||||||
@ -995,26 +1001,12 @@ Material::Material(Connection& conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Mesh::Surface::Vert::operator==(const Vert& other) const {
|
bool Mesh::Surface::Vert::operator==(const Vert& other) const {
|
||||||
if (iPos != other.iPos)
|
return std::tie(iPos, iNorm, iColor, iUv, iSkin) ==
|
||||||
return false;
|
std::tie(other.iPos, other.iNorm, other.iColor, other.iUv, other.iSkin);
|
||||||
if (iNorm != other.iNorm)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < 4; ++i)
|
|
||||||
if (iColor[i] != other.iColor[i])
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < 8; ++i)
|
|
||||||
if (iUv[i] != other.iUv[i])
|
|
||||||
return false;
|
|
||||||
if (iSkin != other.iSkin)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool VertInBank(const std::vector<uint32_t>& bank, uint32_t sIdx) {
|
static bool VertInBank(const std::vector<uint32_t>& bank, uint32_t sIdx) {
|
||||||
for (uint32_t idx : bank)
|
return std::any_of(bank.cbegin(), bank.cend(), [sIdx](auto index) { return index == sIdx; });
|
||||||
if (sIdx == idx)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::SkinBanks::Bank::addSkins(const Mesh& parent, const std::vector<uint32_t>& skinIdxs) {
|
void Mesh::SkinBanks::Bank::addSkins(const Mesh& parent, const std::vector<uint32_t>& skinIdxs) {
|
||||||
@ -1179,8 +1171,7 @@ MapArea::Surface::Surface(Connection& conn) {
|
|||||||
conn._readBuf(&borderCount, 4);
|
conn._readBuf(&borderCount, 4);
|
||||||
borders.reserve(borderCount);
|
borders.reserve(borderCount);
|
||||||
for (uint32_t i = 0; i < borderCount; ++i) {
|
for (uint32_t i = 0; i < borderCount; ++i) {
|
||||||
borders.emplace_back();
|
std::pair<Index, Index>& idx = borders.emplace_back();
|
||||||
std::pair<Index, Index>& idx = borders.back();
|
|
||||||
conn._readBuf(&idx, 8);
|
conn._readBuf(&idx, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1370,14 +1361,13 @@ Actor::Subtype::Subtype(Connection& conn) {
|
|||||||
name.assign(bufSz, ' ');
|
name.assign(bufSz, ' ');
|
||||||
conn._readBuf(&name[0], bufSz);
|
conn._readBuf(&name[0], bufSz);
|
||||||
|
|
||||||
std::string meshPath;
|
|
||||||
conn._readBuf(&bufSz, 4);
|
conn._readBuf(&bufSz, 4);
|
||||||
if (bufSz) {
|
if (bufSz != 0) {
|
||||||
meshPath.assign(bufSz, ' ');
|
std::string meshPath(bufSz, ' ');
|
||||||
conn._readBuf(&meshPath[0], bufSz);
|
conn._readBuf(meshPath.data(), meshPath.size());
|
||||||
SystemStringConv meshPathAbs(meshPath);
|
const SystemStringConv meshPathAbs(meshPath);
|
||||||
|
|
||||||
SystemString meshPathRel =
|
const SystemString meshPathRel =
|
||||||
conn.getBlendPath().getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs.sys_str());
|
conn.getBlendPath().getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs.sys_str());
|
||||||
mesh.assign(conn.getBlendPath().getProject().getProjectWorkingPath(), meshPathRel);
|
mesh.assign(conn.getBlendPath().getProject().getProjectWorkingPath(), meshPathRel);
|
||||||
}
|
}
|
||||||
@ -1393,14 +1383,13 @@ Actor::Subtype::Subtype(Connection& conn) {
|
|||||||
overlayName.assign(bufSz, ' ');
|
overlayName.assign(bufSz, ' ');
|
||||||
conn._readBuf(&overlayName[0], bufSz);
|
conn._readBuf(&overlayName[0], bufSz);
|
||||||
|
|
||||||
std::string meshPath;
|
|
||||||
conn._readBuf(&bufSz, 4);
|
conn._readBuf(&bufSz, 4);
|
||||||
if (bufSz) {
|
if (bufSz != 0) {
|
||||||
meshPath.assign(bufSz, ' ');
|
std::string meshPath(bufSz, ' ');
|
||||||
conn._readBuf(&meshPath[0], bufSz);
|
conn._readBuf(meshPath.data(), meshPath.size());
|
||||||
SystemStringConv meshPathAbs(meshPath);
|
const SystemStringConv meshPathAbs(meshPath);
|
||||||
|
|
||||||
SystemString meshPathRel =
|
const SystemString meshPathRel =
|
||||||
conn.getBlendPath().getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs.sys_str());
|
conn.getBlendPath().getProject().getProjectRootPath().getProjectRelativeFromAbsolute(meshPathAbs.sys_str());
|
||||||
overlayMeshes.emplace_back(std::move(overlayName),
|
overlayMeshes.emplace_back(std::move(overlayName),
|
||||||
ProjectPath(conn.getBlendPath().getProject().getProjectWorkingPath(), meshPathRel));
|
ProjectPath(conn.getBlendPath().getProject().getProjectWorkingPath(), meshPathRel));
|
||||||
@ -1457,9 +1446,7 @@ Action::Action(Connection& conn) {
|
|||||||
conn._readBuf(&aabbCount, 4);
|
conn._readBuf(&aabbCount, 4);
|
||||||
subtypeAABBs.reserve(aabbCount);
|
subtypeAABBs.reserve(aabbCount);
|
||||||
for (uint32_t i = 0; i < aabbCount; ++i) {
|
for (uint32_t i = 0; i < aabbCount; ++i) {
|
||||||
subtypeAABBs.emplace_back();
|
subtypeAABBs.emplace_back(conn, conn);
|
||||||
subtypeAABBs.back().first.read(conn);
|
|
||||||
subtypeAABBs.back().second.read(conn);
|
|
||||||
// printf("AABB %s %d (%f %f %f) (%f %f %f)\n", name.c_str(), i,
|
// printf("AABB %s %d (%f %f %f) (%f %f %f)\n", name.c_str(), i,
|
||||||
// float(subtypeAABBs.back().first.val.simd[0]), float(subtypeAABBs.back().first.val.simd[1]),
|
// float(subtypeAABBs.back().first.val.simd[0]), float(subtypeAABBs.back().first.val.simd[1]),
|
||||||
// float(subtypeAABBs.back().first.val.simd[2]), float(subtypeAABBs.back().second.val.simd[0]),
|
// float(subtypeAABBs.back().first.val.simd[2]), float(subtypeAABBs.back().second.val.simd[0]),
|
||||||
@ -1559,7 +1546,7 @@ std::pair<atVec3f, atVec3f> DataStream::getMeshAABB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* DataStream::MeshOutputModeString(HMDLTopology topology) {
|
const char* DataStream::MeshOutputModeString(HMDLTopology topology) {
|
||||||
static const char* STRS[] = {"TRIANGLES", "TRISTRIPS"};
|
static constexpr std::array<const char*, 2> STRS{"TRIANGLES", "TRISTRIPS"};
|
||||||
return STRS[int(topology)];
|
return STRS[int(topology)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1814,12 +1801,11 @@ std::vector<std::string> DataStream::getArmatureNames() {
|
|||||||
m_parent->_readBuf(&armCount, 4);
|
m_parent->_readBuf(&armCount, 4);
|
||||||
ret.reserve(armCount);
|
ret.reserve(armCount);
|
||||||
for (uint32_t i = 0; i < armCount; ++i) {
|
for (uint32_t i = 0; i < armCount; ++i) {
|
||||||
ret.emplace_back();
|
std::string& name = ret.emplace_back();
|
||||||
std::string& name = ret.back();
|
|
||||||
uint32_t bufSz;
|
uint32_t bufSz;
|
||||||
m_parent->_readBuf(&bufSz, 4);
|
m_parent->_readBuf(&bufSz, 4);
|
||||||
name.assign(bufSz, ' ');
|
name.assign(bufSz, ' ');
|
||||||
m_parent->_readBuf(&name[0], bufSz);
|
m_parent->_readBuf(name.data(), name.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -1843,12 +1829,11 @@ std::vector<std::string> DataStream::getSubtypeNames() {
|
|||||||
m_parent->_readBuf(&subCount, 4);
|
m_parent->_readBuf(&subCount, 4);
|
||||||
ret.reserve(subCount);
|
ret.reserve(subCount);
|
||||||
for (uint32_t i = 0; i < subCount; ++i) {
|
for (uint32_t i = 0; i < subCount; ++i) {
|
||||||
ret.emplace_back();
|
std::string& name = ret.emplace_back();
|
||||||
std::string& name = ret.back();
|
|
||||||
uint32_t bufSz;
|
uint32_t bufSz;
|
||||||
m_parent->_readBuf(&bufSz, 4);
|
m_parent->_readBuf(&bufSz, 4);
|
||||||
name.assign(bufSz, ' ');
|
name.assign(bufSz, ' ');
|
||||||
m_parent->_readBuf(&name[0], bufSz);
|
m_parent->_readBuf(name.data(), name.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -1872,12 +1857,11 @@ std::vector<std::string> DataStream::getActionNames() {
|
|||||||
m_parent->_readBuf(&actCount, 4);
|
m_parent->_readBuf(&actCount, 4);
|
||||||
ret.reserve(actCount);
|
ret.reserve(actCount);
|
||||||
for (uint32_t i = 0; i < actCount; ++i) {
|
for (uint32_t i = 0; i < actCount; ++i) {
|
||||||
ret.emplace_back();
|
std::string& name = ret.emplace_back();
|
||||||
std::string& name = ret.back();
|
|
||||||
uint32_t bufSz;
|
uint32_t bufSz;
|
||||||
m_parent->_readBuf(&bufSz, 4);
|
m_parent->_readBuf(&bufSz, 4);
|
||||||
name.assign(bufSz, ' ');
|
name.assign(bufSz, ' ');
|
||||||
m_parent->_readBuf(&name[0], bufSz);
|
m_parent->_readBuf(name.data(), name.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -1901,12 +1885,11 @@ std::vector<std::string> DataStream::getSubtypeOverlayNames(std::string_view nam
|
|||||||
m_parent->_readBuf(&subCount, 4);
|
m_parent->_readBuf(&subCount, 4);
|
||||||
ret.reserve(subCount);
|
ret.reserve(subCount);
|
||||||
for (uint32_t i = 0; i < subCount; ++i) {
|
for (uint32_t i = 0; i < subCount; ++i) {
|
||||||
ret.emplace_back();
|
std::string& subtypeName = ret.emplace_back();
|
||||||
std::string& name = ret.back();
|
|
||||||
uint32_t bufSz;
|
uint32_t bufSz;
|
||||||
m_parent->_readBuf(&bufSz, 4);
|
m_parent->_readBuf(&bufSz, 4);
|
||||||
name.assign(bufSz, ' ');
|
subtypeName.assign(bufSz, ' ');
|
||||||
m_parent->_readBuf(&name[0], bufSz);
|
m_parent->_readBuf(subtypeName.data(), subtypeName.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -1930,12 +1913,11 @@ std::vector<std::string> DataStream::getAttachmentNames() {
|
|||||||
m_parent->_readBuf(&attCount, 4);
|
m_parent->_readBuf(&attCount, 4);
|
||||||
ret.reserve(attCount);
|
ret.reserve(attCount);
|
||||||
for (uint32_t i = 0; i < attCount; ++i) {
|
for (uint32_t i = 0; i < attCount; ++i) {
|
||||||
ret.emplace_back();
|
std::string& name = ret.emplace_back();
|
||||||
std::string& name = ret.back();
|
|
||||||
uint32_t bufSz;
|
uint32_t bufSz;
|
||||||
m_parent->_readBuf(&bufSz, 4);
|
m_parent->_readBuf(&bufSz, 4);
|
||||||
name.assign(bufSz, ' ');
|
name.assign(bufSz, ' ');
|
||||||
m_parent->_readBuf(&name[0], bufSz);
|
m_parent->_readBuf(name.data(), name.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -1962,23 +1944,22 @@ std::unordered_map<std::string, Matrix3f> DataStream::getBoneMatrices(std::strin
|
|||||||
m_parent->_readBuf(&boneCount, 4);
|
m_parent->_readBuf(&boneCount, 4);
|
||||||
ret.reserve(boneCount);
|
ret.reserve(boneCount);
|
||||||
for (uint32_t i = 0; i < boneCount; ++i) {
|
for (uint32_t i = 0; i < boneCount; ++i) {
|
||||||
std::string name;
|
|
||||||
uint32_t bufSz;
|
uint32_t bufSz;
|
||||||
m_parent->_readBuf(&bufSz, 4);
|
m_parent->_readBuf(&bufSz, 4);
|
||||||
name.assign(bufSz, ' ');
|
std::string mat_name(bufSz, ' ');
|
||||||
m_parent->_readBuf(&name[0], bufSz);
|
m_parent->_readBuf(mat_name.data(), bufSz);
|
||||||
|
|
||||||
Matrix3f matOut;
|
Matrix3f matOut;
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int mat_i = 0; mat_i < 3; ++mat_i) {
|
||||||
for (int j = 0; j < 3; ++j) {
|
for (int mat_j = 0; mat_j < 3; ++mat_j) {
|
||||||
float val;
|
float val;
|
||||||
m_parent->_readBuf(&val, 4);
|
m_parent->_readBuf(&val, 4);
|
||||||
matOut[i].simd[j] = val;
|
matOut[mat_i].simd[mat_j] = val;
|
||||||
}
|
}
|
||||||
reinterpret_cast<atVec4f&>(matOut[i]).simd[3] = 0.f;
|
reinterpret_cast<atVec4f&>(matOut[mat_i]).simd[3] = 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.emplace(std::make_pair(std::move(name), std::move(matOut)));
|
ret.emplace(std::move(mat_name), std::move(matOut));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#include "hecl/Blender/Connection.hpp"
|
#include "hecl/Blender/Connection.hpp"
|
||||||
#include <cmath>
|
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <athena/MemoryWriter.hpp>
|
||||||
|
|
||||||
#undef min
|
#undef min
|
||||||
#undef max
|
#undef max
|
||||||
|
Loading…
x
Reference in New Issue
Block a user