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
#include "Headers/SkinnedSubMesh.h"
#include "Headers/Mesh.h"

#include "Core/Headers/ParamHandler.h"
#include "Core/Math/Headers/Transform.h"
#include "Managers/Headers/SceneManager.h"

#include "Geometry/Animations/Headers/AnimationController.h"
#include "Graphs/Components/Headers/AnimationComponent.h"

namespace Divide {

const static bool USE_MUTITHREADED_LOADING = false;

SkinnedSubMesh::SkinnedSubMesh(const stringImpl& name)
    : SubMesh(name, Object3D::ObjectFlag::OBJECT_FLAG_SKINNED) {
    _animator = MemoryManager_NEW SceneAnimator();
    _buildingBoundingBoxes = false;
}

SkinnedSubMesh::~SkinnedSubMesh() { MemoryManager::DELETE(_animator); }

/// After we loaded our mesh, we need to add submeshes as children nodes
void SkinnedSubMesh::postLoad(SceneGraphNode& sgn) {
    sgn.setComponent(SGNComponent::SGN_COMP_ANIMATION,
                     MemoryManager_NEW AnimationComponent(_animator, sgn));
    SubMesh::postLoad(sgn);
}

/// update possible animations
bool SkinnedSubMesh::updateAnimations(SceneGraphNode& sgn) {
    assert(sgn.getComponent<AnimationComponent>());

    return getBoundingBoxForCurrentFrame(sgn);
}

void SkinnedSubMesh::buildBoundingBoxesForAnimCompleted(U32 animationIndex) {
    _buildingBoundingBoxes = false;
    std::atomic_bool& currentBBStatus = _boundingBoxesAvailable[animationIndex];
    currentBBStatus = true;
    std::atomic_bool& currentBBComputing = _boundingBoxesComputing[animationIndex];
    currentBBComputing = false;
}

void SkinnedSubMesh::buildBoundingBoxesForAnim(
    U32 animationIndex, AnimationComponent* const animComp) {
    const AnimEvaluator& currentAnimation =
        animComp->GetAnimationByIndex(animationIndex);

    boundingBoxPerFrame& currentBBs = _boundingBoxes[animationIndex];
    std::atomic_bool& currentBBStatus = _boundingBoxesAvailable[animationIndex];
    std::atomic_bool& currentBBComputing = _boundingBoxesComputing[animationIndex];
    // We might need to recompute BBs so clear any possible old values
    currentBBs.clear();
    currentBBStatus = false;
    currentBBComputing = true;

    VertexBuffer* parentVB = _parentMesh->getGeometryVB();
    U32 partitionOffset = parentVB->getPartitionOffset(_geometryPartitionID);
    U32 partitionCount =
        parentVB->getPartitionCount(_geometryPartitionID) + partitionOffset;

    const vectorImpl<vec3<F32> >& verts = parentVB->getPosition();
    const vectorImpl<vec4<U8> >& indices = parentVB->getBoneIndices();
    const vectorImpl<vec4<F32> >& weights = parentVB->getBoneWeights();

    I32 frameCount = animComp->frameCount(animationIndex);
    //#pragma omp parallel for
    for (I32 i = 0; i < frameCount; ++i) {
        BoundingBox& bb = currentBBs[i];
        bb.reset();

        const vectorImpl<mat4<F32> >& transforms =
            currentAnimation.GetTransformsConst(static_cast<U32>(i));

        // loop through all vertex weights of all bones
        for (U32 j = partitionOffset; j < partitionCount; ++j) {
            U32 idx = parentVB->getIndex(j);
            const vec4<U8>& ind = indices[idx];
            const vec4<F32>& wgh = weights[idx];
            const vec3<F32>& curentVert = verts[idx];

            F32 fwgh = 1.0f - (wgh.x + wgh.y + wgh.z);

            bb.Add((wgh.x * (transforms[ind.x] * curentVert)) +
                   (wgh.y * (transforms[ind.y] * curentVert)) +
                   (wgh.z * (transforms[ind.z] * curentVert)) +
                   (fwgh * (transforms[ind.w] * curentVert)));
        }

        bb.setComputed(true);
    }
}

bool SkinnedSubMesh::getBoundingBoxForCurrentFrame(SceneGraphNode& sgn) {
    AnimationComponent* animComp = sgn.getComponent<AnimationComponent>();
    // If anymations are paused or unavailable, keep the current BB
    if (!animComp->playAnimations()) {
        return true;
    }
    // Attempt to get the map of BBs for the current animation
    U32 animationIndex = animComp->animationIndex();
    boundingBoxPerFrame& animBB = _boundingBoxes[animationIndex];
    // If the BBs are computed, set the BB for the current frame as the node BB
    if (!animBB.empty()) {
        // Update the BB, only if the calculation task has finished
        if (!_boundingBoxesComputing[animationIndex]) {
            sgn.setInitialBoundingBox(animBB[animComp->frameIndex()]);
            return true;
        }
        return false;
    }

    if (!_buildingBoundingBoxes) {
        _buildingBoundingBoxes = true;
        if (USE_MUTITHREADED_LOADING) {
            Kernel& kernel = Application::getInstance().getKernel();
            Task* task = kernel.AddTask(
                1, 1,
                DELEGATE_BIND(&SkinnedSubMesh::buildBoundingBoxesForAnim,
                                this, animationIndex, animComp),
                DELEGATE_BIND(
                    &SkinnedSubMesh::buildBoundingBoxesForAnimCompleted,
                    this, animationIndex));
            task->startTask();
        } else {
            buildBoundingBoxesForAnim(animationIndex, animComp);
            buildBoundingBoxesForAnimCompleted(animationIndex);
        }
    }

    return true;
}
};

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

Diff revisions: vs.
Revision Author Commited Message
365 Diff Diff IonutCava picture IonutCava Sun 08 Mar, 2015 21:26:10 +0000

[Ionut]
- More enum-related type safety changes

358 Diff Diff IonutCava picture IonutCava Sun 01 Mar, 2015 22:44:38 +0000

[Ionut]
- Fixed some OpenGL initialization issues and function calls (no proper support for DSA yet)
- Cleanup up the Sound and Physics Wrappers
- Some readability improvements here and there

354 Diff Diff IonutCava picture IonutCava Fri 20 Feb, 2015 17:17:37 +0000

[Ionut]
- Replaced GLEW with glbinding (requires a CEGUI recompile. It currently crashes)
- Replaced most “SceneGraphNode* const sgn” expressions with "SceneGraphNode& sgn"
- Replaced some pointers to kernel to references to kernel
- Fixed compilation issues with EASTL
- Removed NPOT -> POT texture conversion code. Modern GPUs handle NPOT textures perfectly fine

352 Diff Diff IonutCava picture IonutCava Thu 12 Feb, 2015 17:10:21 +0000

[Ionut]
- Moved per-frame-per-animation bounding boxes back to SkinnedSubMesh class with better multithreading support
- Fixed a Util::Mat4::multiply related crash
- Added a basic framework (non-functional yet) for registering events with floating point data and a basic plotting system
- Removed custom M_PI define and changed code to use the one in math.h
- Added Scoped classes for rendering (they revert state back to what it was upon destruction)
— Scoped classes for 2D rendering, toggling the rasterizer on/off, changing viewport and changing line width

350 Diff Diff IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)

349 Diff Diff IonutCava picture IonutCava Fri 06 Feb, 2015 17:11:39 +0000

[Ionut]
- More raw pointer replacements
- Removed some redundant parameters to a few scene and application functions

340 Diff Diff IonutCava picture IonutCava Mon 12 Jan, 2015 23:38:52 +0000

[Ionut]
- Some timing corrections

339 Diff Diff IonutCava picture IonutCava Fri 09 Jan, 2015 14:42:42 +0000

[Ionut]
- Animation system cleanup and improvements
- SkinnedSubMeshes can now compute bounding boxes for animations in a separate thread (experimental)

331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

325 IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)