• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Razakhel / RaZ / 8100413393

29 Feb 2024 05:51PM UTC coverage: 79.209% (+0.03%) from 79.184%
8100413393

push

github

Razakhel
[Data/MeshDistanceField] Added an MDF structure

- This computes signed distances to the nearest mesh geometry within a 3D grid using a BVH

- This can be used for some algorithms, such as rendering ones that can use sphere marching through the 3D volume created from this field

53 of 56 new or added lines in 3 files covered. (94.64%)

9 existing lines in 2 files now uncovered.

7955 of 10043 relevant lines covered (79.21%)

2104.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/src/RaZ/Script/LuaData.cpp
1
#include "RaZ/Data/Bitset.hpp"
2
#include "RaZ/Data/BoundingVolumeHierarchy.hpp"
3
#include "RaZ/Data/BoundingVolumeHierarchySystem.hpp"
4
#include "RaZ/Data/Color.hpp"
5
#include "RaZ/Data/Image.hpp"
6
#include "RaZ/Data/MeshDistanceField.hpp"
7
#include "RaZ/Script/LuaWrapper.hpp"
8
#include "RaZ/Utils/TypeUtils.hpp"
9

10
#define SOL_ALL_SAFETIES_ON 1
11
#include "sol/sol.hpp"
12

13
namespace Raz {
14

15
using namespace TypeUtils;
16

17
void LuaWrapper::registerDataTypes() {
2✔
18
  sol::state& state = getState();
2✔
19

20
  {
21
    sol::usertype<Bitset> bitset = state.new_usertype<Bitset>("Bitset",
22
                                                              sol::constructors<Bitset(),
×
23
                                                                                Bitset(std::size_t),
24
                                                                                Bitset(std::size_t, bool)>());
2✔
25
    bitset["getSize"]             = &Bitset::getSize;
2✔
26
    bitset["isEmpty"]             = &Bitset::isEmpty;
2✔
27
    bitset["getEnabledBitCount"]  = &Bitset::getEnabledBitCount;
2✔
28
    bitset["getDisabledBitCount"] = &Bitset::getDisabledBitCount;
2✔
29
    bitset["setBit"]              = sol::overload([] (Bitset& b, std::size_t p) { b.setBit(p); },
2✔
30
                                                  PickOverload<std::size_t, bool>(&Bitset::setBit));
4✔
31
    bitset["resize"]              = &Bitset::resize;
2✔
32
    bitset["reset"]               = &Bitset::reset;
2✔
33
    bitset["clear"]               = &Bitset::clear;
2✔
34
    bitset.set_function(sol::meta_function::bitwise_not, &Bitset::operator~);
2✔
35
    bitset.set_function(sol::meta_function::bitwise_and, &Bitset::operator&);
2✔
36
    bitset.set_function(sol::meta_function::bitwise_or, &Bitset::operator|);
2✔
37
    bitset.set_function(sol::meta_function::bitwise_xor, &Bitset::operator^);
2✔
38
    bitset.set_function(sol::meta_function::bitwise_left_shift, &Bitset::operator<<);
2✔
39
    bitset.set_function(sol::meta_function::bitwise_right_shift, &Bitset::operator>>);
2✔
40
    bitset.set_function(sol::meta_function::index, &Bitset::operator[]);
2✔
41
  }
2✔
42

43
  {
44
    {
45
      sol::usertype<BoundingVolumeHierarchyNode> bvhNode = state.new_usertype<BoundingVolumeHierarchyNode>("BoundingVolumeHierarchyNode",
46
                                                                                                           sol::constructors<BoundingVolumeHierarchyNode()>());
2✔
47
      bvhNode["getBoundingBox"] = &BoundingVolumeHierarchyNode::getBoundingBox;
2✔
48
      bvhNode["hasLeftChild"]   = &BoundingVolumeHierarchyNode::hasLeftChild;
2✔
49
      bvhNode["getLeftChild"]   = [] (const BoundingVolumeHierarchyNode& n) { return &n.getLeftChild(); };
2✔
50
      bvhNode["hasRightChild"]  = &BoundingVolumeHierarchyNode::hasRightChild;
2✔
51
      bvhNode["getRightChild"]  = [] (const BoundingVolumeHierarchyNode& n) { return &n.getRightChild(); };
2✔
52
      bvhNode["getTriangle"]    = &BoundingVolumeHierarchyNode::getTriangle;
2✔
53
      bvhNode["isLeaf"]         = &BoundingVolumeHierarchyNode::isLeaf;
2✔
54
      bvhNode["query"]          = sol::overload([] (const BoundingVolumeHierarchyNode& n, const Ray& r) { return n.query(r); },
3✔
55
                                                PickOverload<const Ray&, RayHit*>(&BoundingVolumeHierarchyNode::query));
4✔
56
    }
2✔
57

58
    {
59
      sol::usertype<BoundingVolumeHierarchy> bvh = state.new_usertype<BoundingVolumeHierarchy>("BoundingVolumeHierarchy",
60
                                                                                               sol::constructors<BoundingVolumeHierarchy()>());
2✔
61
      bvh["getRootNode"] = [] (const BoundingVolumeHierarchy& b) { return &b.getRootNode(); };
3✔
62
      // Sol doesn't seem to be able to bind a constant reference to std::vector; leaving a copy here as it is "cheap"
63
      bvh["build"]       = [] (BoundingVolumeHierarchy& b, std::vector<Entity*> e) { b.build(e); };
3✔
64
      bvh["query"]       = sol::overload([] (const BoundingVolumeHierarchy& b, const Ray& r) { return b.query(r); },
3✔
65
                                         PickOverload<const Ray&, RayHit*>(&BoundingVolumeHierarchy::query));
4✔
66
    }
2✔
67

68
    {
69
      sol::usertype<BoundingVolumeHierarchySystem> bvhSystem = state.new_usertype<BoundingVolumeHierarchySystem>("BoundingVolumeHierarchySystem",
70
                                                                                                                 sol::constructors<
×
71
                                                                                                                   BoundingVolumeHierarchySystem()
72
                                                                                                                 >(),
73
                                                                                                                 sol::base_classes, sol::bases<System>());
2✔
74
      bvhSystem["getBvh"] = [] (BoundingVolumeHierarchySystem& s) { return &s.getBvh(); };
3✔
75
    }
2✔
76
  }
77

78
  {
79
    sol::usertype<Color> color = state.new_usertype<Color>("Color",
80
                                                           sol::constructors<Color(),
×
81
                                                                             Color(const Vec3f&),
82
                                                                             Color(float, float, float),
83
                                                                             Color(const Vec3b&),
84
                                                                             Color(uint32_t)>());
2✔
85
    color["red"]   = PickConstOverload<>(&Color::red);
2✔
86
    color["green"] = PickConstOverload<>(&Color::green);
2✔
87
    color["blue"]  = PickConstOverload<>(&Color::blue);
2✔
88
    color["toVec"] = &Color::operator const Vec3f&;
2✔
89

90
    sol::table colorPreset     = state["ColorPreset"].get_or_create<sol::table>();
2✔
91
    colorPreset["Black"]       = ColorPreset::Black;
2✔
92
    colorPreset["Gray"]        = ColorPreset::Gray;
2✔
93
    colorPreset["Red"]         = ColorPreset::Red;
2✔
94
    colorPreset["Green"]       = ColorPreset::Green;
2✔
95
    colorPreset["Blue"]        = ColorPreset::Blue;
2✔
96
    colorPreset["MediumRed"]   = ColorPreset::MediumRed;
2✔
97
    colorPreset["MediumGreen"] = ColorPreset::MediumGreen;
2✔
98
    colorPreset["MediumBlue"]  = ColorPreset::MediumBlue;
2✔
99
    colorPreset["Cyan"]        = ColorPreset::Cyan;
2✔
100
    colorPreset["Magenta"]     = ColorPreset::Magenta;
2✔
101
    colorPreset["Yellow"]      = ColorPreset::Yellow;
2✔
102
    colorPreset["White"]       = ColorPreset::White;
2✔
103
  }
2✔
104

105
  {
106
    sol::usertype<MeshDistanceField> mdf = state.new_usertype<MeshDistanceField>("MeshDistanceField",
NEW
107
                                                                                 sol::constructors<
×
108
                                                                                   MeshDistanceField(const Raz::AABB&, unsigned int, unsigned int, unsigned int)
109
                                                                                 >());
2✔
110
    mdf["getDistance"]   = &MeshDistanceField::getDistance;
2✔
111
    mdf["setBvh"]        = &MeshDistanceField::setBvh;
2✔
112
    mdf["compute"]       = &MeshDistanceField::compute;
2✔
113
    mdf["recoverSlices"] = &MeshDistanceField::recoverSlices;
2✔
114
  }
2✔
115
}
2✔
116

117
} // namespace Raz
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc