mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-31 08:56:34 +00:00
ifcviewer: section-plane cut tool on web — shared gizmo, true-face pick, drag/Del
Full section tool for the web viewport, with the gizmo + interaction shared with desktop from one codebase. - True-face surface pick. pickSurfaceAt had always ray-cast the instance AABB (to skip a depth readback), so cuts sat in front of the real surface. The pick fragment already computes the exact world_pos (it clips sections with it); now it OUTPUTS it to a 3rd pick MRT (RGBA32F) that every pick path renders, and pickSurfaceAt / pickSurfaceAtAsync read it back (decodeMappedPickPosition; ray-AABB kept only as a fallback). The web async pick chains id -> normal -> position spontaneous staging maps. - Web tool: LMB drops a cut at the picked surface (LMB drag still orbits), K toggles, Shift+K clears; oriented to the real MRT surface normal. Exports + a Section / Clear cuts toolbar pair. - Shared gizmo: lifted the section-gizmo renderer (SECTION_WGSL + thick-line AA + quad+arrow VBO + pack + screen-space hit-test) out of the Qt-coupled OverlayRenderer into a Qt-free SectionGizmoRenderer that ViewportCore::render draws for BOTH desktop and web (both already render via render()). One identical gizmo; OverlayRenderer's now-dead section code removed. Fixed 1 m size (matches the desktop constant). - Interaction (shared): hitTestSectionGizmo (SectionGizmoRenderer::hitTest) + beginSectionDrag / updateSectionDrag / endSectionDrag live in ViewportCore. Drag a gizmo arrow to slide the plane along its normal; Del/Backspace removes the most recent cut. Desktop's ViewportWindow dropped its duplicate hit-test / drag math + state and delegates to the core; web wires the same calls. Tests: sectionPlaneCount add/clear/cap (Catch2, 125); web smoke "click a surface cuts geometry, clear restores" exercises the shared gizmo + 3-MRT pick (11/11). Desktop object-pick / marquee unaffected; BonsaiViewer builds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/********************************************************************************
|
||||
* *
|
||||
* This file is part of IfcOpenShell. *
|
||||
* *
|
||||
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the Lesser GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3.0 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* IfcOpenShell is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* Lesser GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the Lesser GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef SECTIONGIZMORENDERER_H
|
||||
#define SECTIONGIZMORENDERER_H
|
||||
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
#include <Eigen/Dense>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "SectionPlane.h"
|
||||
|
||||
// Qt-free renderer for the section-plane gizmo — a red quad outline plus a
|
||||
// normal arrow, drawn with anti-aliased thick lines. Lifted out of the
|
||||
// Qt-coupled OverlayRenderer so BOTH the desktop and web builds draw one
|
||||
// identical gizmo from a single place (ViewportCore::render calls it on both).
|
||||
//
|
||||
// The gizmo is plane-local geometry scaled by each plane's visual radius and
|
||||
// oriented by a stable tangent/bitangent basis derived from the plane normal.
|
||||
class SectionGizmoRenderer {
|
||||
public:
|
||||
SectionGizmoRenderer() = default;
|
||||
~SectionGizmoRenderer();
|
||||
SectionGizmoRenderer(const SectionGizmoRenderer&) = delete;
|
||||
SectionGizmoRenderer& operator=(const SectionGizmoRenderer&) = delete;
|
||||
|
||||
// Create the pipeline, gizmo VBO, and per-plane uniform buffer. `color_format`
|
||||
// is the render target's format; `sample_count` the MSAA count. Returns false
|
||||
// (and leaves the renderer inert) if pipeline creation fails.
|
||||
bool init(WGPUDevice device, WGPUQueue queue,
|
||||
WGPUTextureFormat color_format, int sample_count);
|
||||
void destroy();
|
||||
bool ready() const { return pipeline_ != nullptr; }
|
||||
|
||||
// Draw one gizmo per plane into an already-open render pass (the main pass).
|
||||
void encode(WGPURenderPassEncoder pass, const Eigen::Matrix4f& view_proj,
|
||||
const std::vector<SectionPlane>& planes,
|
||||
int viewport_w_px, int viewport_h_px, int device_pixel_ratio);
|
||||
|
||||
// Screen-space hit test: index of the plane whose gizmo (arrow segment,
|
||||
// origin→origin+normal) the (x, y) logical-pixel point lies within
|
||||
// `tolerance_px` of, or -1. Pure math — no GPU. Nearest wins.
|
||||
static int hitTest(int x, int y, const std::vector<SectionPlane>& planes,
|
||||
const Eigen::Matrix4f& view, const Eigen::Matrix4f& proj,
|
||||
int viewport_w_px, int viewport_h_px,
|
||||
float tolerance_px = 12.0f);
|
||||
|
||||
private:
|
||||
WGPUDevice device_ = nullptr;
|
||||
WGPUQueue queue_ = nullptr;
|
||||
WGPURenderPipeline pipeline_ = nullptr;
|
||||
WGPUPipelineLayout layout_ = nullptr;
|
||||
WGPUBindGroupLayout bgl_ = nullptr;
|
||||
WGPUBindGroup bind_group_ = nullptr;
|
||||
WGPUBuffer vertex_buffer_ = nullptr;
|
||||
WGPUBuffer uniform_buffer_ = nullptr;
|
||||
WGPUShaderModule shader_ = nullptr;
|
||||
int vertex_count_ = 0;
|
||||
};
|
||||
|
||||
#endif // SECTIONGIZMORENDERER_H
|
||||
Reference in New Issue
Block a user