2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-04-09 15:28:00 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <optional>
|
|
|
|
#include <physis.hpp>
|
|
|
|
|
|
|
|
#include "renderer.hpp"
|
|
|
|
|
|
|
|
struct GameData;
|
|
|
|
|
|
|
|
class VulkanWindow;
|
|
|
|
class StandaloneWindow;
|
2023-07-09 10:54:27 -04:00
|
|
|
class FileCache;
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-10-12 23:45:34 -04:00
|
|
|
class MDLPart : public QWidget
|
|
|
|
{
|
2023-07-09 10:54:27 -04:00
|
|
|
Q_OBJECT
|
2023-07-06 17:36:22 -04:00
|
|
|
|
2023-04-09 15:28:00 -04:00
|
|
|
public:
|
2023-10-12 23:45:34 -04:00
|
|
|
explicit MDLPart(GameData *data, FileCache &cache);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-10-12 23:45:34 -04:00
|
|
|
void exportModel(const QString &fileName);
|
2023-12-09 14:49:31 -05:00
|
|
|
RenderModel &getModel(int index);
|
|
|
|
void reloadModel(int index);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
int lastX = -1;
|
|
|
|
int lastY = -1;
|
2023-07-06 17:36:22 -04:00
|
|
|
|
2023-10-12 23:45:34 -04:00
|
|
|
enum class CameraMode { None, Orbit, Move };
|
2023-07-06 17:36:22 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
CameraMode cameraMode = CameraMode::None;
|
|
|
|
float pitch = 0.0f;
|
|
|
|
float yaw = 0.0f;
|
2023-09-26 20:42:45 -04:00
|
|
|
float cameraDistance = 2.0f;
|
2023-07-09 10:54:27 -04:00
|
|
|
glm::vec3 position{0, 0, 0};
|
2023-07-06 17:36:22 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
std::unique_ptr<physis_Skeleton> skeleton;
|
2023-07-07 16:01:39 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
struct BoneData {
|
|
|
|
glm::mat4 localTransform, finalTransform, inversePose;
|
|
|
|
};
|
2023-07-07 16:01:39 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
std::vector<BoneData> boneData;
|
2023-07-06 17:36:22 -04:00
|
|
|
|
2023-09-25 23:48:03 -04:00
|
|
|
std::function<void()> requestUpdate;
|
|
|
|
|
2023-04-09 15:28:00 -04:00
|
|
|
Q_SIGNALS:
|
2023-07-09 10:54:27 -04:00
|
|
|
void modelChanged();
|
|
|
|
void skeletonChanged();
|
2023-04-09 15:28:00 -04:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2023-07-09 10:54:27 -04:00
|
|
|
/// Clears all stored MDLs.
|
|
|
|
void clear();
|
2023-07-07 16:01:39 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
/// Adds a new MDL with a list of materials used.
|
2023-10-13 15:03:17 -04:00
|
|
|
void addModel(physis_MDL mdl, const QString &name, std::vector<physis_Material> materials, int lod, uint16_t fromBodyId = 101, uint16_t toBodyId = 101);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-09-25 23:48:03 -04:00
|
|
|
void removeModel(const physis_MDL &mdl);
|
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
/// Sets the skeleton any skinned MDLs should bind to.
|
|
|
|
void setSkeleton(physis_Skeleton skeleton);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
/// Clears the current skeleton.
|
|
|
|
void clearSkeleton();
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
void reloadBoneData();
|
|
|
|
void reloadRenderer();
|
2023-04-09 15:28:00 -04:00
|
|
|
|
|
|
|
private:
|
2023-10-12 23:45:34 -04:00
|
|
|
RenderMaterial createMaterial(const physis_Material &mat);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-10-12 23:45:34 -04:00
|
|
|
void calculateBoneInversePose(physis_Skeleton &skeleton, physis_Bone &bone, physis_Bone *parent_bone);
|
|
|
|
void calculateBone(physis_Skeleton &skeleton, physis_Bone &bone, const physis_Bone *parent_bone);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-10-12 23:45:34 -04:00
|
|
|
GameData *data = nullptr;
|
|
|
|
FileCache &cache;
|
2023-10-13 15:03:17 -04:00
|
|
|
physis_PBD pbd;
|
2023-04-09 15:28:00 -04:00
|
|
|
|
|
|
|
std::vector<RenderModel> models;
|
|
|
|
|
2023-10-12 23:45:34 -04:00
|
|
|
Renderer *renderer;
|
|
|
|
VulkanWindow *vkWindow;
|
|
|
|
StandaloneWindow *standaloneWindow;
|
2023-07-06 17:36:22 -04:00
|
|
|
bool firstTimeSkeletonDataCalculated = false;
|
2023-04-09 15:28:00 -04:00
|
|
|
};
|