Skip to content

Commit

Permalink
Apply formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Oct 2, 2024
1 parent 5a41b17 commit 7ced129
Show file tree
Hide file tree
Showing 39 changed files with 456 additions and 463 deletions.
4 changes: 3 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,9 @@ if env["vsproj"]:
if env["compiledb"]:
if env.scons_version < (4, 0, 0):
# Generating the compilation DB (`compile_commands.json`) requires SCons 4.0.0 or later.
print_error("The `compiledb=yes` option requires SCons 4.0 or later, but your version is %s." % scons_raw_version)
print_error(
"The `compiledb=yes` option requires SCons 4.0 or later, but your version is %s." % scons_raw_version
)
Exit(255)

env.Tool("compilation_db")
Expand Down
2 changes: 1 addition & 1 deletion modules/geometry3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ All dependencies are included in the repository, for convenience.

2) **WildMagic5** from [GeometricTools](https://www.geometrictools.com/), written by David Eberly. **Boost License**. Only the LibCore and LibMathematics components. Vector math, Geometric intersection and distance tests in 2D and 3D, containment fitters, geometric approximations fitters, Computational Geometry algorithms, Numerical methods, rational number types, 1/2/3D interpolation methods. It's amazing, I've been using WildMagic for 10+ years, since version 2. The source is included in the */external/* subdirectory. This library is no longer maintained and so I have made various local changes to ease porting from the C# version and make it easier to pass vector types between Eigen and Wm5.

3) [**libigl**](https://libigl.github.io/), the C++ header-only mesh/geometry processing library. libigl is built on Eigen and has implementations of most standard geometry processing algorithms/techniques. Source is included in */external/libigl*. **MPL2 License** is used for the core library, and this is all that geometry3cpp will call. However the code includes calls to various other libaries, including CGAL, LGPL/GPL-licensed code, etc. These will not be included in your binaries unless you explicitly call them via the **igl::copyleft::** namespace.
3) [**libigl**](https://libigl.github.io/), the C++ header-only mesh/geometry processing library. libigl is built on Eigen and has implementations of most standard geometry processing algorithms/techniques. Source is included in */external/libigl*. **MPL2 License** is used for the core library, and this is all that geometry3cpp will call. However the code includes calls to various other libraries, including CGAL, LGPL/GPL-licensed code, etc. These will not be included in your binaries unless you explicitly call them via the **igl::copyleft::** namespace.

# Building

Expand Down
94 changes: 47 additions & 47 deletions modules/geometry3/SCsub
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#!/usr/bin/env python

Import('env')
Import('env_modules')
Import("env")
Import("env_modules")

env_geometry = env_modules.Clone()

env_geometry.Prepend(CPPPATH=['.'])
env_geometry.Prepend(CPPPATH=['src'])
env_geometry.Prepend(CPPPATH=['src/geometry'])
env_geometry.Prepend(CPPPATH=['src/util'])
env_geometry.Prepend(CPPPATH=['src/spatial'])
env_geometry.Prepend(CPPPATH=['src/mesh'])
env_geometry.Prepend(CPPPATH=['thirdparty/Eigen'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibCore'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibCore/Utility'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibCore/IO'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Algebra'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Base'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/NumericalAnalysis'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Miscellaneous'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Approximation'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Objects2D'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Objects3D'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/ComputationalGeometry'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Query'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/CurvesSurfacesVolumes'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Rational'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Containment'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Distance'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Interpolation'])
env_geometry.Prepend(CPPPATH=['thirdparty/WildMagic5/LibMathematics/Intersection'])
env_geometry.Prepend(CPPPATH=["."])
env_geometry.Prepend(CPPPATH=["src"])
env_geometry.Prepend(CPPPATH=["src/geometry"])
env_geometry.Prepend(CPPPATH=["src/util"])
env_geometry.Prepend(CPPPATH=["src/spatial"])
env_geometry.Prepend(CPPPATH=["src/mesh"])
env_geometry.Prepend(CPPPATH=["thirdparty/Eigen"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibCore"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibCore/Utility"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibCore/IO"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Algebra"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Base"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/NumericalAnalysis"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Miscellaneous"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Approximation"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Objects2D"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Objects3D"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/ComputationalGeometry"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Query"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/CurvesSurfacesVolumes"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Rational"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Containment"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Distance"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Interpolation"])
env_geometry.Prepend(CPPPATH=["thirdparty/WildMagic5/LibMathematics/Intersection"])
env_thirdparty = env_geometry.Clone()

# env_thirdparty.disable_warnings()
Expand All @@ -40,24 +40,24 @@ env_thirdparty.add_source_files(env.modules_sources, "src/util/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "src/spatial/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "src/mesh/*.cpp")

env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibCore/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibCore/Utility/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibCore/IO/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Algebra/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Base/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/NumericalAnalysis/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Miscellaneous/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Approximation/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Objects2D/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Objects3D/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/ComputationalGeometry/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Query/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/CurvesSurfacesVolumes/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Rational/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Containment/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Distance/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Interpolation/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, 'thirdparty/WildMagic5/LibMathematics/Intersection/*.cpp')
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibCore/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibCore/Utility/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibCore/IO/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Algebra/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Base/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/NumericalAnalysis/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Miscellaneous/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Approximation/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Objects2D/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Objects3D/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/ComputationalGeometry/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Query/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/CurvesSurfacesVolumes/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Rational/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Containment/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Distance/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Interpolation/*.cpp")
env_thirdparty.add_source_files(env.modules_sources, "thirdparty/WildMagic5/LibMathematics/Intersection/*.cpp")

env_geometry.add_source_files(env.modules_sources, "*.cpp")
2 changes: 1 addition & 1 deletion modules/geometry3/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def can_build(env, platform):
def can_build(env, platform):
return env["target"] == "editor" and not env["disable_3d"]


Expand Down
5 changes: 2 additions & 3 deletions modules/geometry3/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
/*************************************************************************/

#include "register_types.h"
#include "scene/resources/surface_tool.h"
#include "remesh_operator.h"

#include "scene/resources/surface_tool.h"

void initialize_geometry3_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
ClassDB::register_class<RemeshOperator>();
ClassDB::register_class<RemeshOperator>();
}

void uninitialize_geometry3_module(ModuleInitializationLevel p_level) {
Expand Down
92 changes: 56 additions & 36 deletions modules/geometry3/remesh_operator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
#include "remesh_operator.h"

#include "MeshboundaryLoop.h"
#include "profile_util.h"
#include "src/geometry/g3types.h"
#include "src/mesh/DMesh3Builder.h"
#include "src/mesh/Remesher.h"
#include "src/spatial/BasicProjectionTargets.h"
#include <DMesh3.h>
#include <DMeshAABBTree3.h>
#include <MeshQueries.h>
#include <MeshSubdivider.h>
#include <VectorUtil.h>
#include <refcount_vector.h>
#include <small_list_set.h>
#include <algorithm>
#include <limits>
#include <list>

#include "scene/resources/surface_tool.h"
#include "src/geometry/MeshboundaryLoop.h"
#include "src/mesh/DMesh3.h"
#include "src/mesh/MeshConstraints.h"
#include "src/spatial/DCurveProject.h"

namespace g3 {
void PreserveAllBoundaryEdges(g3::MeshConstraintsPtr cons,
Expand Down Expand Up @@ -214,30 +235,29 @@ Array geometry3_process(Array p_mesh) {
}
VectoriDynamic bones;
VectorfDynamic weights;
if (bones_array.size() && bones_array.size() == vertex_array.size() * 8
&&
bones_array.size() == weights_array.size()) {
const int count = 8;
bones.resize(count);
for (int32_t i = 0; i < count; i++) {
bones[i] = bones_array[vert_i * count + i];
}
weights.resize(count);
for (int32_t i = 0; i < count; i++) {
weights[i] = weights_array[vert_i * count + i];
}
if (bones_array.size() && bones_array.size() == vertex_array.size() * 8 &&
bones_array.size() == weights_array.size()) {
const int count = 8;
bones.resize(count);
for (int32_t i = 0; i < count; i++) {
bones[i] = bones_array[vert_i * count + i];
}
weights.resize(count);
for (int32_t i = 0; i < count; i++) {
weights[i] = weights_array[vert_i * count + i];
}
} else if (bones_array.size() &&
bones_array.size() == vertex_array.size() * 4 &&
weights_array.size() == bones_array.size()) {
const int count = 4;
bones.resize(count);
for (int32_t i = 0; i < count; i++) {
bones[i] = bones_array[vert_i * count + i];
}
weights.resize(count);
for (int32_t i = 0; i < count; i++) {
weights[i] = weights_array[vert_i * count + i];
}
bones_array.size() == vertex_array.size() * 4 &&
weights_array.size() == bones_array.size()) {
const int count = 4;
bones.resize(count);
for (int32_t i = 0; i < count; i++) {
bones[i] = bones_array[vert_i * count + i];
}
weights.resize(count);
for (int32_t i = 0; i < count; i++) {
weights[i] = weights_array[vert_i * count + i];
}
}
// NewVertexInfo info = NewVertexInfo(Vector3d(vert.x, vert.y, vert.z),
// Vector3f(normal.x, normal.y,
Expand All @@ -261,7 +281,7 @@ Array geometry3_process(Array p_mesh) {
g3_mesh->AppendTriangle(new_tri);
}
Remesher r(g3_mesh);
// broke compactinplace
// broke compactinplace
// g3_mesh->CompactInPlace();
// g3::MeshConstraintsPtr cons = std::make_shared<MeshConstraints>();
// PreserveAllBoundaryEdges(cons, g3_mesh);
Expand Down Expand Up @@ -358,18 +378,18 @@ Array geometry3_process(Array p_mesh) {

} // namespace g3

Ref<ArrayMesh> RemeshOperator::process(Ref <ArrayMesh> p_mesh){
Ref<ArrayMesh> array_mesh = memnew(ArrayMesh);
if (p_mesh.is_null()) {
return array_mesh; // Return an empty ArrayMesh if input is invalid
}
int surface_count = p_mesh->get_surface_count();
for (int i = 0; i < surface_count; ++i) {
Array surface_arrays = p_mesh->surface_get_arrays(i);
surface_arrays = g3::geometry3_process(surface_arrays);
array_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays);
}
return array_mesh;
Ref<ArrayMesh> RemeshOperator::process(Ref<ArrayMesh> p_mesh) {
Ref<ArrayMesh> array_mesh = memnew(ArrayMesh);
if (p_mesh.is_null()) {
return array_mesh; // Return an empty ArrayMesh if input is invalid
}
int surface_count = p_mesh->get_surface_count();
for (int i = 0; i < surface_count; ++i) {
Array surface_arrays = p_mesh->surface_get_arrays(i);
surface_arrays = g3::geometry3_process(surface_arrays);
array_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays);
}
return array_mesh;
}

void RemeshOperator::_bind_methods() {
Expand Down
28 changes: 3 additions & 25 deletions modules/geometry3/remesh_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,13 @@
#include "core/object/ref_counted.h"
#include "scene/resources/mesh.h"

#include "MeshboundaryLoop.h"
#include "profile_util.h"
#include "src/geometry/g3types.h"
#include "src/mesh/DMesh3Builder.h"
#include "src/mesh/Remesher.h"
#include "src/spatial/BasicProjectionTargets.h"
#include <DMesh3.h>
#include <DMeshAABBTree3.h>
#include <MeshQueries.h>
#include <MeshSubdivider.h>
#include <VectorUtil.h>
#include <refcount_vector.h>
#include <small_list_set.h>
#include <algorithm>
#include <limits>
#include <list>

#include "scene/resources/surface_tool.h"
#include "src/geometry/MeshboundaryLoop.h"
#include "src/mesh/DMesh3.h"
#include "src/mesh/MeshConstraints.h"
#include "src/spatial/DCurveProject.h"

class RemeshOperator : public RefCounted {
GDCLASS(RemeshOperator, RefCounted);
GDCLASS(RemeshOperator, RefCounted);

protected:
static void _bind_methods();

public:
Ref<ArrayMesh> process(Ref <ArrayMesh> p_mesh);
Ref<ArrayMesh> process(Ref<ArrayMesh> p_mesh);
RemeshOperator() {}
};
23 changes: 11 additions & 12 deletions modules/geometry3/src/geometry/DCurve3.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ struct Segment3d {
// }

// Vector3f GetP0() {
// return Center - Extent * Direction;
// return Center - Extent * Direction;
// }
// Vector3f GetP1() {
// return Center + Extent * Direction;
// return Center + Extent * Direction;
// }
// Vector3f SetP0(Vector3f value) {
// update_from_endpoints(value, GetP1());
// update_from_endpoints(value, GetP1());
// }
// Vector3f SetP1(Vector3f value) {
// update_from_endpoints(GetP0(), value);
// update_from_endpoints(GetP0(), value);
// }
// float Length() {
// return 2 * Extent;
Expand Down Expand Up @@ -242,11 +242,10 @@ class CurveUtils {
}
}
}
template<typename T>
static T lerp(float t, const T& a, const T& b) {
return a*(1-t) + b*t;
template <typename T>
static T lerp(float t, const T &a, const T &b) {
return a * (1 - t) + b * t;
}

};

/// <summary>
Expand Down Expand Up @@ -306,17 +305,17 @@ class DCurve3 : public ISampledCurve3d {
double open_angle = std::abs(OpeningAngleDeg(k));
if (open_angle > flat_thresh && k > 0) {
// ignore skip this vertex
} else if (open_angle > sharp_thresh) {
} else if (open_angle > sharp_thresh) {
std::list<Vector3d>::iterator it = vertices.begin();
std::advance(it, k);
resampled.AppendVertex(*it);
} else {
} else {
std::list<g3::Vector3d>::iterator it = vertices.begin();
std::advance(it, (k + 1) % NV);
Vector3d n = *it;
it = vertices.begin();
std::advance(it, k == 0 ? NV - 1 : k - 1);
Vector3d p = *it;
Vector3d p = *it;
it = vertices.begin();
std::advance(it, k);
resampled.AppendVertex(CurveUtils::lerp<Vector3d>(prev_t, p, *it));
Expand Down Expand Up @@ -537,7 +536,7 @@ class DCurve3 : public ISampledCurve3d {
}
}

Index2i Neighbours(int i) {
Index2i Neighbors(int i) {
int NV = vertices.size();
if (Closed()) {
if (i == 0)
Expand Down
Loading

0 comments on commit 7ced129

Please sign in to comment.