Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Object3D.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_OBJECT_3D_H_
34#define DVD_OBJECT_3D_H_
35
39
40namespace Divide {
41
42class BoundingBox;
43enum class RigidBodyShape : U8;
44
45[[nodiscard]] FORCE_INLINE constexpr PrimitiveTopology GetGeometryBufferType(const SceneNodeType type) noexcept
46{
47 if ( !Is3DObject( type ) ) [[unlikely]]
48 {
50 }
51 if (type == SceneNodeType::TYPE_BOX_3D ||
54 {
56 }
57
59}
60
62{
63 public:
64
65 explicit Object3D( const ResourceDescriptorBase& descriptor, SceneNodeType type);
66
67 void setMaterialTpl( Handle<Material> material) override;
68
69 [[nodiscard]] const VertexBuffer_ptr& geometryBuffer();
70
71 inline void geometryBuffer(const VertexBuffer_ptr& vb) noexcept { _geometryBuffer = vb; }
72
73 virtual void onAnimationChange([[maybe_unused]] SceneGraphNode* sgn, [[maybe_unused]] const U32 newIndex) {}
74
75 [[nodiscard]] U8 getGeometryPartitionCount() const noexcept {
76 U8 ret = 0;
77 for (auto partition : _geometryPartitionIDs) {
78 if (partition == VertexBuffer::INVALID_PARTITION_ID) {
79 break;
80 }
81 ++ret;
82 }
83
84 return ret;
85 }
86
87 [[nodiscard]] U16 getGeometryPartitionID(const U8 lodIndex) noexcept {
88 return _geometryPartitionIDs[std::min(lodIndex, to_U8(_geometryPartitionIDs.size()))];
89 }
90
91 void setGeometryPartitionID(const U8 lodIndex, const U16 partitionID) noexcept {
92 if (lodIndex < _geometryPartitionIDs.size()) {
93 _geometryPartitionIDs[lodIndex] = partitionID;
94 }
95 }
96
97 [[nodiscard]] const vector<vec3<U32>>& getTriangles(const U16 partitionID)
98 {
99 if (!computeTriangleList(partitionID))
100 {
102 }
103
104 return _geometryTriangles[partitionID];
105 }
106
107 void addTriangles(const U16 partitionID, const vector<vec3<U32>>& triangles)
108 {
109 if (partitionID >= _geometryTriangles.size())
110 {
111 _geometryTriangles.resize(to_size(partitionID) + 1);
112 }
113
114 _geometryTriangles[partitionID].insert(cend(_geometryTriangles[partitionID]),
115 cbegin(triangles),
116 cend(triangles));
117 }
118
119 [[nodiscard]] bool saveCache(ByteBuffer& outputBuffer) const override;
120 [[nodiscard]] bool loadCache(ByteBuffer& inputBuffer) override;
121
122 void saveToXML(boost::property_tree::ptree& pt) const override;
123 void loadFromXML(const boost::property_tree::ptree& pt) override;
124
125 PROPERTY_RW(bool, geometryDirty, true);
126 PROPERTY_R_IW(bool, playAnimationsOverride, false);
127
128 protected:
129 // Create a list of triangles from the vertices + indices lists based on primitive type
130 [[nodiscard]] bool computeTriangleList(U16 partitionID, bool force = false);
131
132 virtual void rebuildInternal();
133
134 void buildDrawCommands(SceneGraphNode* sgn, GenericDrawCommandContainer& cmdsOut) override;
135
136 protected:
137 std::array<U16, 4> _geometryPartitionIDs;
141 vector<vector<vec3<U32>>> _geometryTriangles;
142 VertexBuffer_ptr _geometryBuffer = nullptr;
143};
144
146
147}; // namespace Divide
148
149#endif //DVD_OBJECT_3D_H_
#define PROPERTY_RW(...)
Convenience method to add a class member with public read access and write access.
#define PROPERTY_R_IW(...)
Convenience method to add a class member with public read access but protected write access including...
#define TYPEDEF_SMART_POINTERS_FOR_TYPE(T)
#define DIVIDE_UNEXPECTED_CALL()
#define FORCE_INLINE
#define DEFINE_NODE_BASE_TYPE(Name, Enum)
Definition: SceneNodeFwd.h:124
static constexpr U16 INVALID_PARTITION_ID
Definition: VertexBuffer.h:52
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
FORCE_INLINE constexpr PrimitiveTopology GetGeometryBufferType(const SceneNodeType type) noexcept
Definition: Object3D.h:45
uint8_t U8
SceneNodeType
ToDo: Move particle emitter to components (it will make them way more dynamic) - Ionut.
Definition: SceneNodeFwd.h:47
eastl::vector< Type > vector
Definition: Vector.h:42
uint16_t U16
constexpr U8 to_U8(const T value)
eastl::fixed_vector< GenericDrawCommand, 1, true > GenericDrawCommandContainer
FORCE_INLINE constexpr bool Is3DObject(const SceneNodeType type) noexcept
Definition: SceneNodeFwd.h:98
constexpr size_t to_size(const T value)
uint32_t U32