From 8b7793cc73651fc85b84fa6c650440f14b0c9690 Mon Sep 17 00:00:00 2001 From: parker Date: Thu, 31 Jul 2025 21:33:16 +0100 Subject: [PATCH] feat: hard face normals per vertex --- src/Engine/Operator/Geometry.cpp | 28 +++++++++++++++++++- src/Gui/Viewport/GLMesh.cpp | 37 +++++++++++++++++++++++---- src/Gui/Viewport/ViewportGLWidget.cpp | 12 ++++++--- src/OpDefs/GopHouse.cpp | 24 +++++++++++++---- src/OpDefs/GopTransform.cpp | 9 +++++++ 5 files changed, 95 insertions(+), 15 deletions(-) diff --git a/src/Engine/Operator/Geometry.cpp b/src/Engine/Operator/Geometry.cpp index 9aaf233..9e2abf0 100644 --- a/src/Engine/Operator/Geometry.cpp +++ b/src/Engine/Operator/Geometry.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "icecream.hpp" using namespace enzo; @@ -43,6 +45,8 @@ enzo::geo::HeMesh geo::Geometry::computeHalfEdgeMesh() createdPoints.push_back(point); } + CGAL::Polygon_mesh_processing::orient(heMesh); + // iterate through each prim for(int primIndx=0; primIndx vertexCounts = vertexCountHandle.getAllValues(); unsigned int vertexCount = 0; + unsigned int primStartVert = 0; for (int primIndx=0; primIndx=3) + { + const unsigned v0 = primStartVert; + const unsigned v1 = primStartVert + 1; + const unsigned v2 = primStartVert + 2; + + const enzo::bt::Vector3 pos1 = pointPositions[vertexPointIndices[v0]]; + const enzo::bt::Vector3 pos2 = pointPositions[vertexPointIndices[v1]]; + const enzo::bt::Vector3 pos3 = pointPositions[vertexPointIndices[v2]]; + + const enzo::bt::Vector3 tang1 = (pos2-pos1).normalized(); + const enzo::bt::Vector3 tang2 = (pos3-pos1).normalized(); + + n = tang1.cross(tang2); + } + + for(int i=0; i< faceVertCnt; ++i) { unsigned int pointIndex = vertexPointIndices[vertexCount]; enzo::bt::Vector3& p = pointPositions[pointIndex]; + + + IC(vertexCount, pointIndex); IC(p.x(), p.y(), p.z()); vertices.push_back({ { p.x(), p.y(), p.z()}, - { p.x(), - p.y(), - p.z()} + { n.x(), + n.y(), + n.z()} }); ++vertexCount; } + primStartVert+=faceVertCnt; } @@ -126,7 +153,7 @@ void GLMesh::setIndexBuffer(std::vector pointIndices, std::vector prim int primVertexCount = primVertexCounts[primNum]; - for(size_t i=0; i 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}, - {0,2,-1},{0,2,1} + {-1,-1,-1}, + {1,-1,-1}, + {1,-1,1}, + {-1,-1,1}, + {-1,1,-1}, + {1,1,-1}, + {1,1,1}, + {-1,1,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> faces = { - {3,2,6,9,7},{0,1,5,8,4},{0,3,7,4},{1,2,6,5}, - {0,1,2,3},{4,7,9},{4,9,8},{5,6,9},{5,9,8} + {7,9,6,2,3}, + {4,8,5,1,0}, + {4,7,3,0}, + {5,6,2,1}, + {0,1,2,3}, + {9,7,4}, + {8,9,4}, + {9,6,5}, + {8,5,9} }; for (auto& f : faces) for (int i : f) pointAttrHandle.addValue(startPt + i); diff --git a/src/OpDefs/GopTransform.cpp b/src/OpDefs/GopTransform.cpp index c0a40f7..dc4bfb6 100644 --- a/src/OpDefs/GopTransform.cpp +++ b/src/OpDefs/GopTransform.cpp @@ -1,6 +1,8 @@ #include "OpDefs/GopTransform.hpp" #include "Engine/Operator/AttributeHandle.h" #include "Engine/Parameter/Template.h" +#include +#include GopTransform::GopTransform(enzo::nt::NetworkManager* network, enzo::op::OpInfo opInfo) : GeometryOpDef(network, opInfo) @@ -26,6 +28,10 @@ void GopTransform::cookOp(enzo::op::Context context) for(int i=0; i