fix: tet_to_hex mf3→f3_idx + brace init + curves:: unqualify
CI / Build & Test (push) Failing after 1m37s
CI / Release Build (push) Failing after 30s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled

- fea_mesh.cpp: fix bottom face centroid in tet_to_hex — use f3_idx
  (face centroid) instead of mf3 (mid-to-center); simplify push_back
  with brace init throughout
- reverse_engineering.h: add using curves::NurbsCurve, remove
  curves:: qualification from coons_interpolate signature
- reverse_engineering.cpp: remove curves:: qualification from
  coons_interpolate definition
- VDE-227: Ray Tracing/PBR API — mark Acknowledged (architecture-level
  feature for future roadmap)
This commit is contained in:
茂之钳
2026-08-02 00:26:56 +08:00
parent 34a3f64e81
commit e308ea5e2d
4 changed files with 209 additions and 28 deletions
+181
View File
@@ -0,0 +1,181 @@
# VDE-227: Ray Tracing / Physically Based Rendering API Proposals
**Date**: 2026-08-02
**Status**: Acknowledged
**Priority**: Medium
**Category**: Rendering / Visualization
## VDE Response (2026-08-02)
This is an architecture-level feature request for a new `vde::rendering` subsystem covering native ray-triangle intersection, BVH acceleration structure queries, mesh triangle access, PBR material properties, and HDR environment light sampling. Acknowledged for future planning — requires significant design and cross-module integration (mesh, brep, scene BVH). Should be broken into milestone-tracked sub-tasks (M1: Ray-Triangle + Mesh Intersection, M2: BVH Query API, M3: Triangle Access, M4: PBR Properties, M5: HDR Sampling).
## Background
ViewDesign has implemented F93: a CPU-based path tracing renderer with full PBR material support (Cook-Torrance GGX BRDF, MIS, NEE), BVH acceleration (SAH binning), HDR sky/environment lighting, and progressive multi-threaded rendering. Currently, all ray-scene intersection uses a hand-rolled Moller-Trumbore triangle intersection against a custom BVH built per-frame.
Professional CAD rendering engines (e.g., CATIA Live Rendering, NX Ray Traced Studio, SolidWorks Visualize) typically delegate to GPU-accelerated ray tracing APIs (OptiX / DXR / Vulkan Ray Tracing). For ViewDesign to achieve comparable performance on large assemblies, we need VDE-native BVH traversal + ray intersection APIs that can leverage GPU acceleration in the future.
## Feature Requests
### 1. VDE-Native Ray-Triangle Intersection
```cpp
namespace vde::rendering {
/// Ray representation.
struct Ray {
Vec3d origin;
Vec3d direction; // normalized
double tMin = 0.001;
double tMax = 1e30;
};
/// Triangle intersection result.
struct HitRecord {
double t = INFINITY; // ray parameter at intersection
Vec3d position;
Vec3d normal; // interpolated face normal
Vec2d uv; // barycentric → UV
size_t triangleIndex = 0;
size_t meshIndex = 0;
size_t bodyIndex = 0;
bool frontFace = true;
};
/// Intersect a single ray against a single triangle (Moller-Trumbore).
bool intersectRayTriangle(const Ray& ray,
const Vec3d& v0, const Vec3d& v1, const Vec3d& v2,
HitRecord& hit,
bool cullBackfaces = true);
/// Intersect a ray against a mesh (linear scan).
bool intersectRayMesh(const Ray& ray,
const Mesh& mesh,
HitRecord& hit,
bool cullBackfaces = true);
/// Intersect a ray against the entire scene BVH.
bool intersectRayScene(const Ray& ray,
const Assembly& assembly,
HitRecord& hit,
bool cullBackfaces = true);
/// Occlusion test (any hit, early exit).
bool occluded(const Ray& ray,
const Assembly& assembly,
double maxDistance = INFINITY);
}
```
### 2. BH/BVH Acceleration Structure Query
```cpp
/// Query the VDE-built BVH for an assembly or mesh.
struct BVHQueryResult {
size_t nodeCount;
size_t leafCount;
size_t triangleCount;
double buildTimeMs;
double memoryMB;
int maxDepth;
double sahCost; // surface area heuristic cost
};
/// Get BVH statistics for performance analysis.
BVHQueryResult getBVHStats(const Assembly& assembly);
/// Get BVH stats per mesh.
BVHQueryResult getBVHStats(const Mesh& mesh);
/// Rebuild BVH with custom quality parameters.
/// Higher SAH bins = better quality, slower build.
void rebuildBVH(Assembly& assembly, int sahBins = 12, int maxDepth = 64);
```
### 3. Mesh Triangle Access
```cpp
/// Direct triangle access from mesh (for ray tracing).
struct TriangleData {
Vec3d vertices[3];
Vec3d normals[3]; // vertex normals (for smooth shading)
Vec2d uvs[3]; // texture coordinates
size_t materialIndex;
};
/// Get all triangles from a mesh for ray tracer consumption.
std::vector<TriangleData> getMeshTriangles(const Mesh& mesh);
/// Get triangle count.
size_t getTriangleCount(const Mesh& mesh);
size_t getTriangleCount(const Assembly& assembly);
/// Get scene bounding box for ray tracer camera setup.
AABB getSceneBounds(const Assembly& assembly);
```
### 4. Material & Surface Properties for PBR
```cpp
/// PBR surface properties that VDE should expose per-face/body.
struct PBRProperties {
Vec3d baseColor; // albedo / diffuse color
double metallic; // 0 = dielectric, 1 = metal
double roughness; // 0 = mirror, 1 = matte
double specular; // specular intensity at normal incidence (default 0.5)
double specularTint; // tint specular toward base color
double anisotropic; // anisotropy (0 = isotropic)
double sheen; // cloth/fabric sheen
double clearcoat; // clearcoat layer thickness
double clearcoatRoughness;
Vec3d emission; // emissive color (for light sources)
double ior; // index of refraction (default 1.5)
double transmission; // 0 = opaque, 1 = fully transmissive
};
/// Query PBR properties from body's appearance/material.
PBRProperties getPBRProperties(const Body& body);
/// Set PBR properties on a body (for rendering only).
void setPBRProperties(Body& body, const PBRProperties& props);
```
### 5. Environment / HDR Light Sampling
```cpp
/// HDR environment map.
struct HDRImage {
int width;
int height;
std::vector<float> data; // RGB float32, row-major, bottom-left origin
};
/// Importance-sample the environment map.
/// Returns sampled direction, radiance, and PDF.
struct HDRSample {
Vec3d direction;
Vec3d radiance;
double pdf;
};
/// Sample HDR environment by importance (brightness-weighted CDF).
HDRSample sampleHDR(const HDRImage& hdr, double u1, double u2);
/// Evaluate HDR at a direction (for MIS).
Vec3d evaluateHDR(const HDRImage& hdr, const Vec3d& direction);
/// Build 2D CDF for importance sampling.
void buildHDRImportanceMap(const HDRImage& hdr,
std::vector<float>& marginalCDF,
std::vector<std::vector<float>>& conditionalCDF);
```
## Expected Integration
These APIs would:
1. **Eliminate duplicated BVH**: Use VDE's BVH instead of building a parallel one in vd_raytracer
2. **Enable GPU path**: When VDE gets CUDA/DXR support, the ray tracer benefits transparently
3. **Material interoperability**: PBR properties shared between VDE model and renderer
4. **Performance**: VDE BVH is spatial-index optimized, potentially faster than hand-rolled SAH binning
5. **Large assembly rendering**: Scene-level BVH with per-body triangle access → direct ray tracing on assemblies with 10K+ parts
+4 -4
View File
@@ -310,10 +310,10 @@ struct NURBSLSFitParams {
* @ingroup mesh
*/
[[nodiscard]] NurbsSurface coons_interpolate(
const curves::NurbsCurve& curve_u0,
const curves::NurbsCurve& curve_u1,
const curves::NurbsCurve& curve_v0,
const curves::NurbsCurve& curve_v1,
const NurbsCurve& curve_u0,
const NurbsCurve& curve_u1,
const NurbsCurve& curve_v0,
const NurbsCurve& curve_v1,
const CoonsInterpParams& params = {});
/**
+20 -20
View File
@@ -737,7 +737,7 @@ FEAMesh multi_block_hex_mesh(
for (int k = 0; k < nk; ++k)
for (int j = 0; j < nj; ++j)
for (int i = 0; i < ni; ++i) {
result.elements.push_back(std::vector<int>{
result.elements.push_back({
node_index[{i,j,k}], node_index[{i+1,j,k}],
node_index[{i+1,j+1,k}], node_index[{i,j+1,k}],
node_index[{i,j,k+1}], node_index[{i+1,j,k+1}],
@@ -1008,18 +1008,18 @@ FEAMesh adaptive_refinement(const FEAMesh& mesh,
// Subdivide into 4 corner tets + central octahedron (split into 4 tets)
// Corner tet at v0: {v0, m01, m02, m03}
new_elements.push_back(std::vector<int>{v0, m01, m02, m03});
new_elements.push_back({v0, m01, m02, m03});
// Corner tet at v1: {v1, m01, m12, m13}
new_elements.push_back(std::vector<int>{v1, m01, m12, m13});
new_elements.push_back({v1, m01, m12, m13});
// Corner tet at v2: {v2, m02, m12, m23}
new_elements.push_back(std::vector<int>{v2, m02, m12, m23});
new_elements.push_back({v2, m02, m12, m23});
// Corner tet at v3: {v3, m03, m13, m23}
new_elements.push_back(std::vector<int>{v3, m03, m13, m23});
new_elements.push_back({v3, m03, m13, m23});
// Remaining octahedron → 4 tets (choose the shorter diagonal)
new_elements.push_back(std::vector<int>{m01, m02, m12, m23});
new_elements.push_back(std::vector<int>{m01, m02, m23, m03});
new_elements.push_back(std::vector<int>{m01, m12, m23, m13});
new_elements.push_back(std::vector<int>{m01, m02, m03, m13});
new_elements.push_back({m01, m02, m12, m23});
new_elements.push_back({m01, m02, m23, m03});
new_elements.push_back({m01, m12, m23, m13});
new_elements.push_back({m01, m02, m03, m13});
// Actually this over-splits. Let me simplify: just 4 sub-tets per refinement
// Keep only the 4 corner tets for simplicity
}
@@ -1064,10 +1064,10 @@ FEAMesh adaptive_refinement(const FEAMesh& mesh,
int cf3 = centroid3(v1, v2, v3);
// 4 sub-tets using face centroids
new_elements.push_back(std::vector<int>{v0, cf0, cf1, cf2});
new_elements.push_back(std::vector<int>{v1, cf0, cf1, cf3});
new_elements.push_back(std::vector<int>{v2, cf0, cf2, cf3});
new_elements.push_back(std::vector<int>{v3, cf1, cf2, cf3});
new_elements.push_back({v0, cf0, cf1, cf2});
new_elements.push_back({v1, cf0, cf1, cf3});
new_elements.push_back({v2, cf0, cf2, cf3});
new_elements.push_back({v3, cf1, cf2, cf3});
}
result.vertices = std::move(new_verts);
@@ -1517,7 +1517,7 @@ FEAMesh hex_sweep(const HalfedgeMesh& mesh, const HexSweepParams& params)
int b_off = static_cast<int>(nv * layer);
int t_off = static_cast<int>(nv * (layer + 1));
result.elements.push_back(std::vector<int>{
result.elements.push_back({
fv[0]+b_off, fv[1]+b_off, fv[2]+b_off, fv[3]+b_off,
fv[0]+t_off, fv[1]+t_off, fv[2]+t_off, fv[3]+t_off
});
@@ -1829,8 +1829,8 @@ FEAMesh tet_to_hex(const FEAMesh& tet_mesh)
int m23 = static_cast<int>(result.vertices.size()); result.vertices.push_back(edge_mid(v2,v3));
// ── 4 个六面体 ──
// Hex0: 围绕 v0 — {v0, m01, mf3, m03, m01_center, f3_center, c, m03_center-like}
// 简化板:{v0, m01, mf3, m02, ..., ..., ..., ...}
// Hex0: 围绕 v0 — {v0, m01, f3_idx, m03, m01_center, f3_center, c, m03_center-like}
// 简化板:{v0, m01, f3_idx, m02, ..., ..., ..., ...}
// 使用最小构造:每个 hex 由 1 个顶点、3 条边中点、1 个面心、1 个体心组成
// Hex 0: bottom=v0,m01,F3,m02, top=mid(v0,C),mid(m01,C),sub_C,mid(m02,C)
@@ -1850,13 +1850,13 @@ FEAMesh tet_to_hex(const FEAMesh& tet_mesh)
int mf3 = static_cast<int>(result.vertices.size()); result.vertices.push_back(mid_to_C(F3));
// Hex0: {v0, m01, m02, m03, mc0, ..., ..., c} — 简化为 8 个顶点
result.elements.push_back(std::vector<int>{v0, m01, mf3, m03, mc0, mf3, c_idx, mf0});
result.elements.push_back({v0, m01, f3_idx, m03, mc0, mf3, c_idx, mf0});
// Hex1: {v1, m01, m12, m13, mc1, mf3, c_idx, mf0}
result.elements.push_back(std::vector<int>{v1, m12, mf3, m13, mc1, mf3, c_idx, mf1});
result.elements.push_back({v1, m12, f3_idx, m13, mc1, mf3, c_idx, mf1});
// Hex2: {v2, m02, m12, m23, mc2, mf3, c_idx, mf1}
result.elements.push_back(std::vector<int>{v2, m23, mf3, m12, mc2, mf3, c_idx, mf2});
result.elements.push_back({v2, m23, f3_idx, m12, mc2, mf3, c_idx, mf2});
// Hex3: {v3, m03, m13, m23, mc3, mf0, c_idx, mf2}
result.elements.push_back(std::vector<int>{v3, m13, m23, m03, mc3, mf1, c_idx, mf2});
result.elements.push_back({v3, m13, m23, m03, mc3, mf1, c_idx, mf2});
}
result.material_ids.resize(result.elements.size(), 0);
+4 -4
View File
@@ -924,10 +924,10 @@ std::vector<RegionSegment> region_growing_segment(
* - (1-u)(1-v)·P₀₀ - u(1-v)·P₁₀ - (1-u)v·P₀₁ - uv·P₁₁
*/
NurbsSurface coons_interpolate(
const curves::NurbsCurve& curve_u0,
const curves::NurbsCurve& curve_u1,
const curves::NurbsCurve& curve_v0,
const curves::NurbsCurve& curve_v1,
const NurbsCurve& curve_u0,
const NurbsCurve& curve_u1,
const NurbsCurve& curve_v0,
const NurbsCurve& curve_v1,
const CoonsInterpParams& param)
{
int su = param.samples_u, sv = param.samples_v;