Polyphase Game Engine
Loading...
Searching...
No Matches
CharacterRigBuilder.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include "SmartPointer.h"
6
7#include <glm/glm.hpp>
8#include <string>
9
10class Node;
11class Node3D;
12class SkeletalMesh;
13class AssetDir;
14struct AssetStub;
15
35enum class CharacterRigType : uint8_t
36{
37 FirstPerson,
38 ThirdPerson
39};
40
41struct CharacterRigSpec
42{
43 CharacterRigType mType = CharacterRigType::FirstPerson;
44 std::string mName = "Player"; // Root node name; also the Scene asset name
45 float mHeight = 1.8f; // Total capsule height in metres (feet to top)
46 SkeletalMesh* mSkeletalMesh = nullptr; // Optional for first person, expected for third person
47 bool mFitMeshToHeight = false; // Scale the mesh so its bind-pose box is mHeight tall (else scale 1)
48 std::string mScriptFile; // Script name as the Node "Script" property takes it
49 bool mTagAsPlayer = true;
50 bool mMainCamera = true;
51};
52
53// Numbers derived from the spec height. Shared by the builder and the
54// dialog's preview text so both agree.
55struct CharacterRigMetrics
56{
57 float mHeight = 0.0f; // Clamped total height
58 float mRadius = 0.0f; // Capsule radius
59 float mCapsuleSegment = 0.0f; // Capsule3D::mHeight (cylinder part; total = segment + 2r)
60 float mRootY = 0.0f; // Root local Y that puts the feet on y = 0
61 float mEyeLocalY = 0.0f; // First person camera Y relative to the root
62 float mPivotLocalY = 0.0f; // Third person pivot Y relative to the root
63 float mCameraDistance = 0.0f; // Third person camera distance behind the pivot
64 float mFollowCamHeight = 0.0f; // Third person follow-cam height
65};
66
67namespace CharacterRigBuilder
68{
69 CharacterRigMetrics ComputeMetrics(const CharacterRigSpec& spec);
70
71 // Built detached from any world at the origin. Null + outError on failure
72 // (script file not found / class table missing).
73 SharedPtr<Node3D> BuildRig(const CharacterRigSpec& spec, std::string& outError);
74
75 // Undoable: clones the rig into the open scene under parent (null = world
76 // root), standing with its feet at feetPos, and selects it. One undo step.
77 Node* SpawnRigIntoScene(const CharacterRigSpec& spec, Node* parent, glm::vec3 feetPos, std::string& outError);
78
79 // Writes <spec.mName>.oct (uniquified on collision) into dir. Returns the stub.
80 AssetStub* SaveRigAsScene(const CharacterRigSpec& spec, AssetDir* dir, std::string& outError);
81
82 // Output-directory helpers. Paths may be absolute or relative to the
83 // project's asset root; anything outside that root is refused. Missing
84 // folders are created on disk and in the AssetDir tree.
85 AssetDir* ResolveOrCreateOutputDir(const std::string& userPath, std::string& outError);
86 // False when the path is outside the asset root. outRel has no leading or
87 // trailing slash and is empty for the root itself.
88 bool ToProjectRelativeAssetPath(const std::string& path, std::string& outRel);
89 std::string GetProjectAssetRoot(); // absolute, forward slashes, trailing '/', "" if no project
90}
91
92#endif // EDITOR
Definition AssetDir.h:13
Definition Node3d.h:14
Definition Node.h:67
Definition SmartPointer.h:33
Definition SkeletalMesh.h:114
Definition Asset.h:94