feat: add cube test geometry node

This commit is contained in:
parker
2025-07-31 22:12:38 +01:00
parent 8b7793cc73
commit ab6b5ac935
7 changed files with 115 additions and 21 deletions

View File

@@ -119,8 +119,6 @@ void GLMesh::setPosBuffer(enzo::geo::Geometry& geometry)
IC(vertexCount, pointIndex);
IC(p.x(), p.y(), p.z());
vertices.push_back({ vertices.push_back({
{ p.x(), { p.x(),
p.y(), p.y(),

View File

@@ -99,12 +99,16 @@ void ViewportGLWidget::initializeGL()
void main() void main()
{ {
// FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
vec3 lightDir = normalize(vec3(1.0,1.0,1.0)); vec3 lightDir = normalize(vec3(1.0,1.0,1.0));
float brightness = remap(dot(Normal, lightDir), -1, 1, 0.5, 1); float brightness = remap(dot(Normal, lightDir), -1, 1, 0.5, 1);
vec4 Color = vec4(remap(Normal, vec3(-1), vec3(1), vec3(0), vec3(1)), 1.0f);
FragColor = Color; vec4 Color = vec4(1.0f,1.0f,1.0f,1.0f);
// set color to normal
// Color = vec4(remap(Normal, vec3(-1), vec3(1), vec3(0), vec3(1)), 1.0f);
FragColor = Color*vec4(vec3(brightness), 1.0f);
} }
)"; )";
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

View File

@@ -21,6 +21,7 @@ add_library(${libName} SHARED
../Engine/Parameter/Parameter.cpp ../Engine/Parameter/Parameter.cpp
GopTransform.cpp GopTransform.cpp
GopHouse.cpp GopHouse.cpp
GopTestCube.cpp
) )
target_link_libraries(${libName} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen TBB::tbb) target_link_libraries(${libName} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen TBB::tbb)

View File

@@ -36,10 +36,6 @@ void GOP_house::cookOp(enzo::op::Context context)
{0,2,-1}, {0,2,-1},
{0,2,1} {0,2,1}
}; };
for (auto& p : pts) PAttrHandle.addValue(p);
auto pointAttr = geo.getAttribByName(ga::AttrOwner::VERTEX, "point");
ga::AttributeHandleInt pointAttrHandle(pointAttr);
std::vector<std::vector<int>> faces = { std::vector<std::vector<int>> faces = {
{7,9,6,2,3}, {7,9,6,2,3},
{4,8,5,1,0}, {4,8,5,1,0},
@@ -51,6 +47,11 @@ void GOP_house::cookOp(enzo::op::Context context)
{9,6,5}, {9,6,5},
{8,5,9} {8,5,9}
}; };
for (auto& p : pts) PAttrHandle.addValue(p);
auto pointAttr = geo.getAttribByName(ga::AttrOwner::VERTEX, "point");
ga::AttributeHandleInt pointAttrHandle(pointAttr);
for (auto& f : faces) for (int i : f) pointAttrHandle.addValue(startPt + i); for (auto& f : faces) for (int i : f) pointAttrHandle.addValue(startPt + i);
auto vertexCountAttr = geo.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount"); auto vertexCountAttr = geo.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
@@ -67,18 +68,6 @@ void GOP_house::cookOp(enzo::op::Context context)
} }
// ---- // ----
constexpr int N = 10000;
std::vector<double> results(N);
oneapi::tbb::parallel_for(0, N, [&](int i) {
double val = 0;
for (int j = 0; j < 100; ++j) {
val += std::sin(i + j);
}
results[i] = val;
});
// set output geometry // set output geometry
setOutputGeometry(0, geo); setOutputGeometry(0, geo);
} }

View File

@@ -0,0 +1,72 @@
#include "OpDefs/GopTestCube.h"
#include "Engine/Operator/AttributeHandle.h"
#include <oneapi/tbb/parallel_for.h>
GopTestGeoCube::GopTestGeoCube(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
: GeometryOpDef(network, opInfo)
{
}
void GopTestGeoCube::cookOp(enzo::op::Context context)
{
using namespace enzo;
if (outputRequested(0))
{
geo::Geometry geo = context.cloneInputGeo(0);
auto PAttr = geo.getAttribByName(ga::AttrOwner::POINT, "P");
ga::AttributeHandleVector3 PAttrHandle(PAttr);
const int startPt = PAttrHandle.getSize();
const std::vector<bt::Vector3> pts = {
{-1, -1, 1},
{ 1, -1, 1},
{ 1, 1, 1},
{-1, 1, 1},
{-1, -1, -1},
{ 1, -1, -1},
{ 1, 1, -1},
{-1, 1, -1}
};
for (const auto &p : pts) PAttrHandle.addValue(p);
const std::vector<std::vector<int>> faces = {
{0, 1, 2, 3},
{7, 6, 5, 4},
{0, 3, 7, 4},
{5, 6, 2, 1},
{3, 2, 6, 7},
{4, 5, 1, 0}
};
auto pointAttr = geo.getAttribByName(ga::AttrOwner::VERTEX, "point");
ga::AttributeHandleInt pointAttrHandle(pointAttr);
for (const auto &f : faces)
for (int i : f)
pointAttrHandle.addValue(startPt + i);
auto vertexCountAttr = geo.getAttribByName(ga::AttrOwner::PRIMITIVE,
"vertexCount");
ga::AttributeHandleInt vertexCountHandle(vertexCountAttr);
for (const auto &f : faces)
vertexCountHandle.addValue(static_cast<int>(f.size()));
const float s = context.evalFloatParm("size");
for (int i = 0; i < PAttrHandle.getAllValues().size(); ++i)
{
bt::Vector3 v = PAttrHandle.getValue(i);
v *= s;
PAttrHandle.setValue(i, v);
}
setOutputGeometry(0, geo);
}
}
enzo::prm::Template GopTestGeoCube::parameterList[] =
{
enzo::prm::Template(enzo::prm::Type::FLOAT, "size", 1),
enzo::prm::Terminator
};

18
src/OpDefs/GopTestCube.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include "Engine/Operator/GeometryOpDef.h"
#include "Engine/Parameter/Template.h"
class GopTestGeoCube
: public enzo::nt::GeometryOpDef
{
public:
GopTestGeoCube(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo);
virtual void cookOp(enzo::op::Context context);
static enzo::nt::GeometryOpDef* ctor(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo)
{
return new GopTestGeoCube(network, opInfo);
}
static BOOST_SYMBOL_EXPORT enzo::prm::Template parameterList[];
};

View File

@@ -1,6 +1,7 @@
#include "Engine/Operator/OpInfo.h" #include "Engine/Operator/OpInfo.h"
#include "Engine/Operator/OperatorTable.h" #include "Engine/Operator/OperatorTable.h"
#include "GopHouse.h" #include "GopHouse.h"
#include "GopTestCube.h"
#include "OpDefs/GopTransform.hpp" #include "OpDefs/GopTransform.hpp"
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/dll.hpp> #include <boost/dll.hpp>
@@ -31,6 +32,17 @@ extern "C"
1, 1,
} }
); );
addOperator(
enzo::op::OpInfo {
"testGeoCube",
"Test Cube",
&GopTestGeoCube::ctor,
GopTestGeoCube::parameterList,
0,
0,
1,
}
);
} }
} }