Plasma Engine  2.0
Loading...
Searching...
No Matches
KrautGeneratorResource.h
1#pragma once
2
3#include <Core/ResourceManager/Resource.h>
4#include <KrautPlugin/KrautDeclarations.h>
5
6#include <KrautGenerator/Description/LodDesc.h>
7#include <KrautGenerator/Description/TreeStructureDesc.h>
8
10
11namespace Kraut
12{
13 struct TreeStructure;
14 struct TreeStructureDesc;
15}; // namespace Kraut
16
20
22{
23 plKrautMaterialType m_MaterialType = plKrautMaterialType::None;
24 plKrautBranchType m_BranchType = plKrautBranchType::None;
25 plMaterialResourceHandle m_hMaterial;
26};
27
28struct PL_KRAUTPLUGIN_DLL plKrautGeneratorResourceDescriptor : public plRefCounted
29{
30 Kraut::TreeStructureDesc m_TreeStructureDesc;
31 Kraut::LodDesc m_LodDesc[5];
32
34
35 plString m_sSurfaceResource;
36 float m_fStaticColliderRadius = 0.5f;
37 float m_fUniformScaling = 1.0f;
38 float m_fLodDistanceScale = 1.0f;
39 float m_fTreeStiffness = 10.0f;
40
41 plUInt16 m_uiDefaultDisplaySeed = 0;
42 plHybridArray<plUInt16, 16> m_GoodRandomSeeds;
43
44 plResult Serialize(plStreamWriter& inout_stream) const;
45 plResult Deserialize(plStreamReader& inout_stream);
46};
47
48class PL_KRAUTPLUGIN_DLL plKrautGeneratorResource : public plResource
49{
50 PL_ADD_DYNAMIC_REFLECTION(plKrautGeneratorResource, plResource);
51 PL_RESOURCE_DECLARE_COMMON_CODE(plKrautGeneratorResource);
52
53public:
55
56 const plSharedPtr<plKrautGeneratorResourceDescriptor>& GetDescriptor() const
57 {
58 return m_GeneratorDesc;
59 }
60
61 plKrautTreeResourceHandle GenerateTree(const plSharedPtr<plKrautGeneratorResourceDescriptor>& descriptor, plUInt32 uiRandomSeed) const;
62 plKrautTreeResourceHandle GenerateTreeWithGoodSeed(const plSharedPtr<plKrautGeneratorResourceDescriptor>& descriptor, plUInt16 uiGoodSeedIndex) const;
63
64 void GenerateTreeDescriptor(const plSharedPtr<plKrautGeneratorResourceDescriptor>& descriptor, plKrautTreeResourceDescriptor& dstDesc, plUInt32 uiRandomSeed) const;
65
66
67private:
68 virtual plResourceLoadDesc UnloadData(Unload WhatToUnload) override;
69 virtual plResourceLoadDesc UpdateContent(plStreamReader* Stream) override;
70 virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
71
72 plMutex m_DataMutex;
74
75
76 struct BranchNodeExtraData
77 {
78 float m_fSegmentLength = 0.0f;
79 float m_fDistanceAlongBranch = 0.0f;
80 float m_fBendinessAlongBranch = 0.0f;
81 };
82
83 struct BranchExtraData
84 {
85 plInt32 m_iParentBranch = -1; // trunks have parent ID -1
86 plUInt16 m_uiParentBranchNodeID = 0; // at which node of the parent, this branch is attached
87 plUInt8 m_uiBranchLevel = 0;
89 float m_fDistanceToAnchor = 0; // this will be zero for level 0 (trunk) and 1 (main branches) and only > 0 starting at level 2 (twigs)
90 float m_fBendinessToAnchor = 0;
91 plUInt32 m_uiRandomNumber = 0;
92 };
93
94 struct TreeStructureExtraData
95 {
97 };
98
99 mutable plKrautTreeResourceHandle m_hFallbackResource;
100
101 void InitializeExtraData(TreeStructureExtraData& extraData, const Kraut::TreeStructure& treeStructure, plUInt32 uiRandomSeed) const;
102 void ComputeDistancesAlongBranches(TreeStructureExtraData& extraData, const Kraut::TreeStructure& treeStructure) const;
103 void ComputeDistancesToAnchors(TreeStructureExtraData& extraData, const Kraut::TreeStructure& treeStructure) const;
104 void ComputeBendinessAlongBranches(TreeStructureExtraData& extraData, const Kraut::TreeStructure& treeStructure, float fWoodBendiness, float fTwigBendiness) const;
105 void ComputeBendinessToAnchors(TreeStructureExtraData& extraData, const Kraut::TreeStructure& treeStructure) const;
106 void GenerateExtraData(TreeStructureExtraData& treeStructureExtraData, const Kraut::TreeStructureDesc& treeStructureDesc, const Kraut::TreeStructure& treeStructure, plUInt32 uiRandomSeed, float fWoodBendiness, float fTwigBendiness) const;
107};
Definition DynamicArray.h:81
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition KrautGeneratorResource.h:49
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Base class for reference counted objects.
Definition RefCounted.h:52
The base class for all resources.
Definition Resource.h:10
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
Definition KrautGeneratorResource.h:29
Definition KrautGeneratorResource.h:22
Definition KrautTreeResource.h:22
Definition Resource.h:34
Describes in which loading state a resource currently is, and how many different quality levels there...
Definition Declarations.h:102
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54