{ "cells": [ { "cell_type": "markdown", "id": "a1b2c3d4", "metadata": {}, "source": [ "# Geometry Visualization\n", "\n", "OCC (OpenCascade) geometries can be rendered directly without meshing. The `GeometryRenderer` displays faces, edges, and vertices with proper colors." ] }, { "cell_type": "markdown", "id": "b2c3d4e5", "metadata": {}, "source": [ "## Rendering an OCC Shape" ] }, { "cell_type": "code", "execution_count": null, "id": "c3d4e5f6", "metadata": {}, "outputs": [], "source": [ "from netgen.occ import *\n", "from ngsolve_webgpu import GeometryRenderer\n", "from webgpu.jupyter import Draw\n", "\n", "box = Box((-1, -1, -1), (1, 1, 1))\n", "sphere = Sphere((1, 1, 1), 0.4)\n", "shape = box + sphere\n", "\n", "geo = OCCGeometry(shape)\n", "renderer = GeometryRenderer(geo)\n", "scene = Draw([renderer])" ] }, { "cell_type": "markdown", "id": "d4e5f6a7", "metadata": {}, "source": [ "`GeometryRenderer` wraps three sub-renderers: faces (solid surfaces), edges (wireframe lines), and vertices (points). Each can be toggled independently." ] }, { "cell_type": "markdown", "id": "e5f6a7b8", "metadata": {}, "source": [ "## Using the Draw Shortcut\n", "\n", "The convenience `Draw` function from `ngsolve_webgpu.jupyter` accepts shapes and geometries directly:" ] }, { "cell_type": "code", "execution_count": null, "id": "f6a7b8c9", "metadata": {}, "outputs": [], "source": [ "from netgen.occ import *\n", "from ngsolve_webgpu.jupyter import Draw\n", "\n", "shape = Box((-1, -1, -1), (1, 1, 1)) - Cylinder((0, 0, -2), Z, r=0.5, h=4)\n", "Draw(shape)" ] }, { "cell_type": "markdown", "id": "a7b8c9d0", "metadata": {}, "source": [ "When passed a `TopoDS_Shape` or `OCCGeometry`, `Draw` creates a `GeometryRenderer` automatically." ] }, { "cell_type": "markdown", "id": "b8c9d0e1", "metadata": {}, "source": [ "## Geometry with Clipping" ] }, { "cell_type": "code", "execution_count": null, "id": "c9d0e1f2", "metadata": {}, "outputs": [], "source": [ "from netgen.occ import *\n", "from ngsolve_webgpu import GeometryRenderer\n", "from webgpu.clipping import Clipping\n", "from webgpu.jupyter import Draw\n", "\n", "shape = Box((-1, -1, -1), (1, 1, 1)) - Sphere((0, 0, 0), 1.2)\n", "geo = OCCGeometry(shape)\n", "clipping = Clipping()\n", "renderer = GeometryRenderer(geo, clipping=clipping)\n", "Draw([renderer])" ] }, { "cell_type": "markdown", "id": "d0e1f2a3", "metadata": {}, "source": [ "Pass a `Clipping` object to `GeometryRenderer` to enable interactive clipping of the geometry." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.5" } }, "nbformat": 4, "nbformat_minor": 5 }