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>
|
|
|
|
|
2023-12-09 15:39:35 -05:00
|
|
|
#include "mdlexport.h"
|
2024-04-21 17:35:48 -04:00
|
|
|
#include "rendermanager.h"
|
2023-04-09 15:28:00 -04:00
|
|
|
|
|
|
|
struct GameData;
|
|
|
|
|
|
|
|
class VulkanWindow;
|
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-12-09 21:28:02 -05:00
|
|
|
explicit MDLPart(GameData *data, FileCache &cache, QWidget *parent = nullptr);
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2023-10-12 23:45:34 -04:00
|
|
|
void exportModel(const QString &fileName);
|
2024-04-21 17:35:48 -04:00
|
|
|
DrawObject &getModel(int index);
|
2023-12-09 14:49:31 -05:00
|
|
|
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;
|
2024-04-14 14:00:50 -04:00
|
|
|
float minimumCameraDistance = 1.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
|
|
|
std::vector<BoneData> boneData;
|
2023-07-06 17:36:22 -04:00
|
|
|
|
2023-09-25 23:48:03 -04:00
|
|
|
std::function<void()> requestUpdate;
|
|
|
|
|
2024-04-14 14:09:40 -04:00
|
|
|
void setWireframe(bool wireframe);
|
|
|
|
bool wireframe() const;
|
|
|
|
|
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.
|
2024-02-02 14:28:01 -05:00
|
|
|
void addModel(physis_MDL mdl,
|
2024-02-02 14:37:58 -05:00
|
|
|
bool skinned,
|
2024-02-02 14:28:01 -05:00
|
|
|
glm::vec3 position,
|
|
|
|
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
|
|
|
|
2024-02-02 14:28:01 -05:00
|
|
|
void enableFreemode();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool event(QEvent *event) override;
|
|
|
|
|
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-12-09 15:24:54 -05:00
|
|
|
physis_PBD pbd{};
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2024-04-21 17:35:48 -04:00
|
|
|
std::vector<DrawObject> models;
|
2023-04-09 15:28:00 -04:00
|
|
|
|
2024-04-21 17:35:48 -04:00
|
|
|
RenderManager *renderer = nullptr;
|
2023-12-09 15:24:54 -05:00
|
|
|
VulkanWindow *vkWindow = nullptr;
|
2023-07-06 17:36:22 -04:00
|
|
|
bool firstTimeSkeletonDataCalculated = false;
|
2023-04-09 15:28:00 -04:00
|
|
|
};
|