Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include "Headers/Object3D.h"

#include "Core/Headers/PlatformContext.h"
#include "Managers/Headers/SceneManager.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Geometry/Material/Headers/Material.h"
#include "Physics/Headers/PXDevice.h"

namespace Divide {

Object3D::Object3D(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, ObjectType type, ObjectFlag flag)
    : Object3D(context, parentCache, descriptorHash, name, name, "", type, to_U32(flag))
{
}

Object3D::Object3D(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, ObjectType type, U32 flagMask)
    : Object3D(context, parentCache, descriptorHash, name, name, "", type, flagMask)
{
}

Object3D::Object3D(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, const stringImpl& resourceName, const stringImpl& resourceLocation, ObjectType type, ObjectFlag flag)
    : Object3D(context, parentCache, descriptorHash, name, resourceName, resourceLocation, type, to_U32(flag))
{
}

Object3D::Object3D(GFXDevice& context, ResourceCache& parentCache, size_t descriptorHash, const stringImpl& name, const stringImpl& resourceName, const stringImpl& resourceLocation, ObjectType type, U32 flagMask)
    : SceneNode(parentCache, descriptorHash, name, resourceName, resourceLocation, SceneNodeType::TYPE_OBJECT3D),
    _context(context),
    _update(false),
    _buffer(nullptr),
    _playAnimations(true),
    _geometryType(type),
    _geometryFlagMask(flagMask),
    _geometryPartitionID(0U)
{
    if (!getObjectFlag(ObjectFlag::OBJECT_FLAG_NO_VB)) {
        _buffer = context.newVB();
    }

    switch (type) {
        case ObjectType::BOX_3D :
            _rigidBodyShape = RigidBodyShape::SHAPE_BOX;
            break;
        case ObjectType::QUAD_3D :
            _rigidBodyShape = RigidBodyShape::SHAPE_PLANE;
            break;
        case ObjectType::SPHERE_3D :
            _rigidBodyShape = RigidBodyShape::SHAPE_SPHERE;
            break;
        case ObjectType::TERRAIN :
            _rigidBodyShape = RigidBodyShape::SHAPE_HEIGHTFIELD;
            break;
        case ObjectType::TEXT_3D :
            _rigidBodyShape = RigidBodyShape::SHAPE_TRIANGLEMESH;
        case ObjectType::MESH: {
            STUBBED("ToDo: Add capsule and convex mesh support for 3D Objects! -Ionut");
            //if (true) { // general meshes? Maybe have a concave flag?
                _rigidBodyShape = RigidBodyShape::SHAPE_TRIANGLEMESH;
            /*} else { 
                if (true) { // skinned characters?
                    _rigidBodyShape = RigidBodyShape::SHAPE_CAPSULE;
                } else { // have a convex flag for imported meshes?
                    _rigidBodyShape = RigidBodyShape::SHAPE_CONVEXMESH;
                }
            }*/
            } break;
        default:
            _rigidBodyShape = RigidBodyShape::SHAPE_COUNT;
            break;
    };
}

Object3D::~Object3D()
{
}

bool Object3D::isPrimitive() {
    return _geometryType == ObjectType::BOX_3D ||
           _geometryType == ObjectType::QUAD_3D ||
           _geometryType == ObjectType::PATCH_3D ||
           _geometryType == ObjectType::SPHERE_3D ||
           _geometryType == ObjectType::TEXT_3D;
}

void Object3D::postLoad(SceneGraphNode& sgn) {
     computeTriangleList();
     SceneNode::postLoad(sgn);
}

void Object3D::setGeometryVB(VertexBuffer* const vb) {
    DIVIDE_ASSERT(_buffer == nullptr,
                  "Object3D error: Please remove the previous vertex buffer of "
                  "this Object3D before specifying a new one!");
    _buffer = vb;
}

VertexBuffer* const Object3D::getGeometryVB() const {
    return _buffer;
}

bool Object3D::onRender(const RenderStagePass& renderStagePass) {
    return getState() == ResourceState::RES_LOADED;
}

void Object3D::initialiseDrawCommands(SceneGraphNode& sgn,
                                      const RenderStagePass& renderStagePass,
                                      GenericDrawCommands& drawCommandsInOut) {
    if (drawCommandsInOut.empty()) {
        GenericDrawCommand cmd;
        VertexBuffer* const vb = getGeometryVB();
        cmd.sourceBuffer(vb);
        cmd.cmd().indexCount = to_U32(vb->getIndexCount());
        drawCommandsInOut.push_back(cmd);
    }

    SceneNode::initialiseDrawCommands(sgn, renderStagePass, drawCommandsInOut);
}

// Create a list of triangles from the vertices + indices lists based on
// primitive type
bool Object3D::computeTriangleList(bool force) {
    if (!_geometryTriangles.empty() && !force) {
        return true;
    }

    VertexBuffer* geometry = getGeometryVB();

    DIVIDE_ASSERT(geometry != nullptr,
                  "Object3D error: Please specify a valid VertexBuffer before "
                  "calculating the triangle list!");

    U32 partitionOffset = geometry->getPartitionOffset(_geometryPartitionID);
    U32 partitionCount = geometry->getPartitionIndexCount(_geometryPartitionID);
    PrimitiveType type = (_geometryType == ObjectType::MESH ||
                          _geometryType == ObjectType::SUBMESH
                              ? PrimitiveType::TRIANGLES
                              : PrimitiveType::TRIANGLE_STRIP);
    // We can't have a VB without vertex positions
    DIVIDE_ASSERT(!geometry->getVertices().empty(),
                  "Object3D error: computeTriangleList called with no position "
                  "data available!");

    if (!_geometryTriangles.empty() && force) {
        _geometryTriangles.resize(0);
    }

    if (geometry->getIndexCount() == 0) {
        return false;
    }

    U32 indiceCount = partitionCount;
    bool largeIndices = geometry->usesLargeIndices();
    if (type == PrimitiveType::TRIANGLE_STRIP) {
        U32 indiceStart = 2 + partitionOffset;
        U32 indiceEnd = indiceCount + partitionOffset;
        vec3<U32> curTriangle;
        _geometryTriangles.reserve(indiceCount / 2);
        if (largeIndices) {
            const vectorImplBest<U32>& indices = geometry->getIndices<U32>();
            for (U32 i = indiceStart; i < indiceEnd; i++) {
                curTriangle.set(indices[i - 2], indices[i - 1], indices[i]);
                // Check for correct winding
                if (i % 2 != 0)
                    std::swap(curTriangle.y, curTriangle.z);
                _geometryTriangles.push_back(curTriangle);
            }
        } else {
            const vectorImplBest<U16>& indices = geometry->getIndices<U16>();
            for (U32 i = indiceStart; i < indiceEnd; i++) {
                curTriangle.set(indices[i - 2], indices[i - 1], indices[i]);
                // Check for correct winding
                if (i % 2 != 0)
                    std::swap(curTriangle.y, curTriangle.z);
                _geometryTriangles.push_back(curTriangle);
            }
        }
    } else if (type == PrimitiveType::TRIANGLES) {
        indiceCount /= 3;
        _geometryTriangles.reserve(indiceCount);
        if (largeIndices) {
            const vectorImplBest<U32>& indices = geometry->getIndices<U32>();
            for (U32 i = 0; i < indiceCount; i++) {
                _geometryTriangles.push_back(vec3<U32>(indices[i * 3 + 0],
                                                       indices[i * 3 + 1],
                                                       indices[i * 3 + 2]));
            }
        } else {
            const vectorImplBest<U16>& indices = geometry->getIndices<U16>();
            for (U32 i = 0; i < indiceCount; i++) {
                _geometryTriangles.push_back(vec3<U32>(indices[i * 3 + 0],
                                                       indices[i * 3 + 1],
                                                       indices[i * 3 + 2]));
            }
        }
    }

    // Check for degenerate triangles
    _geometryTriangles.erase(
        std::partition(
            std::begin(_geometryTriangles), std::end(_geometryTriangles),
            [](const vec3<U32>& triangle) -> bool {
                return (triangle.x != triangle.y && triangle.x != triangle.z &&
                        triangle.y != triangle.z);
            }),
        std::end(_geometryTriangles));

    DIVIDE_ASSERT(!_geometryTriangles.empty(),
                  "Object3D error: computeTriangleList() failed to generate "
                  "any triangles!");
    return true;
}

vectorImpl<SceneGraphNode_wptr> Object3D::filterByType(const vectorImpl<SceneGraphNode_wptr>& nodes, ObjectType filter) {
    vectorImpl<SceneGraphNode_wptr> result;
    result.reserve(nodes.size());

    for (SceneGraphNode_wptr ptr : nodes) {
        if (!ptr.expired() && ptr.lock()->getNode<Object3D>()->getObjectType() == filter) {
            result.push_back(ptr);
        }
    };

    return result;
}

};

Commits for Divide-Framework/trunk/Source Code/Geometry/Shapes/Object3D.cpp

Diff revisions: vs.
Revision Author Commited Message
888 Diff Diff IonutCava picture IonutCava Mon 03 Apr, 2017 20:04:19 +0000

[IonutCava]
- Terrain <-> Water body collision checking for caustics

886 Diff Diff IonutCava picture IonutCava Wed 29 Mar, 2017 23:36:51 +0000

[Ionut]
- Initial code for multiple water block support (position + length/width/depth)

877 Diff Diff IonutCava picture IonutCava Thu 16 Mar, 2017 21:55:59 +0000

[IonutCava]
- Reflection updates
- Sky parallax fixes
- Initial support for Tessellation patches (used by the new terrain system – W.I.P.)

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

863 Diff Diff IonutCava picture IonutCava Wed 15 Feb, 2017 16:27:26 +0000

[IonutCava]
- Split Resource class into Resource and CachedResource
— CachedResource is the only resource held in a ResourceCache and loaded from a ResourceDescriptor
— CachedResource is mapped by its creation descriptor’s hash value, instead of the resource name
-— Multiple cached resources can now exist with the same name if the have different properties, for example.

859 Diff Diff IonutCava picture IonutCava Mon 13 Feb, 2017 17:18:06 +0000

[IonutCava]
- Multi-threaded mesh load
- ByteBuffer fixes and unit test

852 Diff Diff IonutCava picture IonutCava Tue 07 Feb, 2017 17:17:27 +0000

[IonutCava]
- Separate Pass Type from Render Stage:
— Render Stage: Display, Shadow, Reflection, Refraction, etc
— Pass Type: Depth pass, Colour Pass, etc
- ToDo: Bug fixes for issues introduced with this change

851 Diff Diff IonutCava picture IonutCava Mon 06 Feb, 2017 23:38:14 +0000

[IonutCava]
- Replaced most RenderStage params with RenderStagePass types
- More work on water rendering

833 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 22:04:33 +0000

[IonutCava]
- Fix most build errors. Divide-Server does not build for now.

829 IonutCava picture IonutCava Tue 24 Jan, 2017 17:28:39 +0000

[IonutCava]
- Separate resourceLocation for resources into resourceLocation and resourceName.
- More XML config loading refactoring