### Install Node.js Dependencies Source: https://github.com/pboyer/verb/blob/master/docs/README.md Installs the necessary Node.js packages for the project by running the npm install command in the project directory. ```bash npm install ``` -------------------------------- ### Verify Haxe and Node.js Installation Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Commands to check the installed versions of Haxe and Node.js, which are essential prerequisites for building and using the verb library. ```Shell haxe --version ``` ```Shell node --version ``` -------------------------------- ### Install Node.js and Haxe Dependencies Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Commands to install project dependencies using npm for Node.js packages and haxelib for Haxe libraries, required for building and running verb. ```Shell npm install ``` ```Shell haxelib install promhx ``` -------------------------------- ### Install verb-nurbs JavaScript Package Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Command to install the pre-compiled JavaScript version of verb using npm, making it available for use in Node.js or browser environments. ```Shell npm install verb-nurbs ``` -------------------------------- ### Compile verb for C# Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Instructions to install the Haxe C# compiler library and then build the verb library for the C# platform using Haxe. ```Shell haxelib install hxcs ``` ```Shell haxe buildcs.hxml ``` -------------------------------- ### Install verb-nurbs via npm Source: https://github.com/pboyer/verb/blob/master/README.md This command installs the verb-nurbs package using npm, the Node.js package manager. It's the standard way to include the library in JavaScript projects for server-side or build-tool environments. ```bash npm install verb-nurbs ``` -------------------------------- ### Compile verb for C++ Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Instructions to install the Haxe C++ compiler library and then build the verb library for the C++ platform using Haxe. ```Shell haxelib install hxcpp ``` ```Shell haxe buildcpp.hxml ``` -------------------------------- ### Initialize and Render NURBS Surface with verb.geom and Three.js Source: https://github.com/pboyer/verb/blob/master/examples/surfaceAdaptiveTessellation.html This JavaScript code snippet initializes a 3D scene, defines a NURBS surface using control points, knots, and degree, and then renders it as a wireframe mesh using Three.js. It relies on external functions like `setupScene()`, `addMeshToScene()`, and `renderScene()` which are not provided but are assumed to handle scene setup and rendering. ```javascript setupScene(); var degree = 3 , knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1] , pts = [ [ [0, 0, -10], [10, 0, 0], [20, 0, 0], [30, 0, 0] , [40, 0, 0], [50, 0, 0] ], [ [0, -10, 0], [10, -10, 10], [20, -10, 10], [30, -10, 0] , [40, -10, 0], [50, -10, 0] ], [ [0, -20, 0], [10, -20, 10], [20, -20, 10], [30, -20, 0] , [40, -20, -2], [50, -20, -12] ], [ [0, -30, 0], [10, -30, 0], [20, -30, -23], [30, -30, 0] , [40, -30, 0], [50, -30, 0] ], [ [0, -40, 0], [10, -40, 0], [20, -40, 0], [30, -40, 4] , [40, -40, -20], [50, -40, 0] ], [ [0, -50, 12], [10, -50, 0], [20, -50, 20], [30, -50, 0] , [50, -50, -10], [50, -50, -15] ] ]; var srf = verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts ); var mat = new THREE.MeshBasicMaterial( { color: 0xffffff, side: THREE.DoubleSide, wireframe: true }); addMeshToScene( srf.toThreeGeometry(), mat ); renderScene(); ``` -------------------------------- ### Define Two Planar NURBS Surfaces for Intersection Source: https://github.com/pboyer/verb/blob/master/examples/meshIntersection.html This function defines two distinct planar NURBS surfaces, each created using four corner points. This setup is used to demonstrate the intersection of two arbitrary planes. ```javascript function exPlanePlane(){ var p1 = [5,0,0] , p2 = [5,0,6] , p3 = [0,1,6] , p4 = [0,0,0]; srf1 = verb.geom.NurbsSurface.byCorners( p1, p2, p3, p4 ); var p5 = [5,-5,-5] , p6 = [5,5,5] , p7 = [0,5,9] , p8 = [0,-5,-5]; srf2 = verb.geom.NurbsSurface.byCorners( p5, p6, p7, p8 ); } ``` -------------------------------- ### Example Output Structure of Verb.js API Documentation Source: https://github.com/pboyer/verb/blob/master/docs/template.md This snippet illustrates the conceptual structure of the API documentation generated by the EJS template. It outlines the expected format for documenting types (classes, interfaces, typedefs), their methods, and properties, including key attributes like names, types, descriptions, and signatures. ```APIDOC APIDOC: Verb.js Type Documentation Structure Type: Namespace: verb.. Kind: Source: #L Description: [Optional] Typedef Alias: = [If Class/Interface]: [Optional] Extends: [Optional] Implements: , Methods: : Kind: METHOD Source: #L Signature: (: , ...): Description: Parameters: : ... Returns: Properties: : Kind: PROPERTY Source: #L Signature: : = Type: [Optional] Default Value: Description: ``` -------------------------------- ### Execute Surface Intersection and Render Scene (JavaScript) Source: https://github.com/pboyer/verb/blob/master/examples/surfaceIntersection.html This snippet initializes the scene, calls one of the surface definition functions (e.g., `exNurbsSurfacePlane`), adds the defined surfaces to the scene, performs the surface-surface intersection using `verb.geom.Intersect.surfaces`, measures the execution time, and then renders the resulting intersection curves and the overall scene. ```javascript setupScene(); exNurbsSurfacePlane(); // This is the active example in the provided text addMeshToScene( srf1.toThreeGeometry() ); addMeshToScene( srf2.toThreeGeometry() ); var res; var runs = 10; var d1 = Date.now(); for (var i = 0 ; i < runs; i++){ res = verb.geom.Intersect.surfaces( srf1, srf2, 1e-6 ); } var d2 = Date.now(); console.log( "intersected in ", (d2 - d1) / runs, " ms and " + res.length + " curves were discovered"); for (var i = 0; i < res.length; i++){ var res2 = res[i].toThreeGeometry(); addCurveToScene( res2 ); } renderScene(); ``` -------------------------------- ### Create and Render an Extruded Surface from a Bezier Curve Source: https://github.com/pboyer/verb/blob/master/examples/extrudedSurface.html This JavaScript snippet initializes a scene, defines a Bezier curve as a profile, then extrudes this profile along a vector to create a 3D surface. The resulting curve and surface are converted to Three.js geometries and added to the scene for rendering. It showcases basic usage of `verb.geom.BezierCurve` and `verb.geom.ExtrudedSurface`. ```JavaScript setupScene(); var prof = new verb.geom.BezierCurve( [[0,0,0], [5,10,0], [10,0,0], [15,20,0],] ); var srf = new verb.geom.ExtrudedSurface( prof, [0,0,10] ); addCurveToScene( prof.toThreeGeometry() ); addMeshToScene( srf.toThreeGeometry() ); renderScene(); ``` -------------------------------- ### Define Torus and Cylindrical Surface for Intersection (Example 3) Source: https://github.com/pboyer/verb/blob/master/examples/meshIntersection.html Similar to Example 1, this function defines a revolved surface (torus) and a cylindrical surface. This version introduces a slight variation in the cylindrical surface's base position ([8,0,2]) to explore different intersection outcomes. ```javascript function exTorusCylindricalSurface3(){ // center, xaxis, yaxis, radius var profile = new verb.geom.Circle( [5,0,0], [1,0,0], [0,0,1], 2 ); var base = [0,0,0]; var axis = [0,0,1]; var angle = 2 * Math.PI srf1 = new verb.geom.RevolvedSurface( profile, base, axis, angle ); var axis = [-1,0,0] , xaxis = [0,0,1] , base = [8,0,2] , height = 16 , radius = 2; srf2 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius ); } ``` -------------------------------- ### Perform Mesh Intersection and Render Results Source: https://github.com/pboyer/verb/blob/master/examples/meshIntersection.html This code block orchestrates the intersection process. It first tessellates the two previously defined surfaces (`srf1`, `srf2`) into meshes. Then, it uses `verb.eval.Intersect.meshes` to compute the intersection curves, measures the performance, and finally adds both the original surfaces and the resulting intersection polylines to the scene for visualization. ```javascript exTorusCylindricalSurface(); //exGlancingPlaneCylindricalSurface(); //exPlanePlane(); //exPlanePlane(); //exNurbsSurfacePlane(); //exTorusCylindricalSurface3(); var tess1 = srf1.tessellate(); var tess2 = srf2.tessellate(); addMeshToScene( srf1.toThreeGeometry(), null, true ); addMeshToScene( srf2.toThreeGeometry(), null, true ); var res; var runs = 1; var d1 = Date.now(); for (var i = 0 ; i < runs; i++){ res = verb.eval.Intersect.meshes( tess1, tess2 ); } var d2 = Date.now(); var numLengths = res.reduce(function(a,x){ return a + x.length-1; }, 0); console.log( "intersected in ", (d2 - d1) / runs, " ms and " + res.length + " polylines were discovered"); console.log( numLengths + " edges were formed in total "); for (var i = 0; i < res.length; i++){ var res2 = res[i].map(function(x){ return x.point; }); addCurveToScene( pointsAsGeometry( res2 )); } renderScene(); ``` -------------------------------- ### Define Torus and Cylindrical Surface for Intersection (Example 1) Source: https://github.com/pboyer/verb/blob/master/examples/meshIntersection.html This function defines a revolved surface (torus) from a circle profile and a cylindrical surface. These two surfaces are set up to be intersected later, demonstrating a basic torus-cylinder intersection. ```javascript function exTorusCylindricalSurface(){ // center, xaxis, yaxis, radius var profile = new verb.geom.Circle( [5,0,0], [1,0,0], [0,0,1], 2 ); var base = [0,0,0]; var axis = [0,0,1]; var angle = 2 * Math.PI srf1 = new verb.geom.RevolvedSurface( profile, base, axis, angle ); var axis = [-1,0,0] , xaxis = [0,0,1] , base = [8,0,0] , height = 16 , radius = 2; srf2 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius ); } ``` -------------------------------- ### Create a Swept Surface with verb.geom Source: https://github.com/pboyer/verb/blob/master/examples/sweptSurface.html This snippet initializes a scene, defines a rail curve and a profile curve using `verb.geom.BezierCurve`, and then creates a `verb.geom.SweptSurface` by sweeping the profile along the rail. Finally, it adds the generated geometry to the scene for rendering. ```JavaScript setupScene(); var rail = new verb.geom.BezierCurve( [[0,0,0], [10,5,10], [20,10,10]] ); var prof = new verb.geom.BezierCurve( [[0,0,0], [10,10,0], [20,0,0]] ); var srf = new verb.geom.SweptSurface( prof, rail ); addCurveToScene( rail.toThreeGeometry() ); addCurveToScene( prof.toThreeGeometry() ); addMeshToScene( srf.toThreeGeometry() ); renderScene(); ``` -------------------------------- ### Define Offset Torus and Cylindrical Surface for Intersection (JavaScript) Source: https://github.com/pboyer/verb/blob/master/examples/surfaceIntersection.html Similar to `exTorusCylindricalSurface`, this function defines a torus via revolution and a cylindrical surface. The cylindrical surface's base is slightly offset in the Z-axis compared to the previous example, demonstrating a different intersection scenario. ```javascript function exTorusCylindricalSurface2(){ // center, xaxis, yaxis, radius var profile = new verb.geom.Circle( [5,0,0], [1,0,0], [0,0,1], 2 ); var base = [0,0,0]; var axis = [0,0,1]; var angle = 2 * Math.PI srf1 = new verb.geom.RevolvedSurface( profile, base, axis, angle ); var axis = [-1,0,0] , xaxis = [0,0,1] , base = [8,0,1] , height = 16 , radius = 2; srf2 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius ); } ``` -------------------------------- ### Define Torus and Cylindrical Surface for Intersection (JavaScript) Source: https://github.com/pboyer/verb/blob/master/examples/surfaceIntersection.html This function creates a torus by revolving a circle profile and a cylindrical surface. These two surfaces are then ready to be used as inputs for the surface intersection algorithm provided by the `verb.geom` library. ```javascript function exTorusCylindricalSurface(){ // center, xaxis, yaxis, radius var profile = new verb.geom.Circle( [5,0,0], [1,0,0], [0,0,1], 2 ); var base = [0,0,0]; var axis = [0,0,1]; var angle = 2 * Math.PI srf1 = new verb.geom.RevolvedSurface( profile, base, axis, angle ); var axis = [-1,0,0] , xaxis = [0,0,1] , base = [8,0,0] , height = 16 , radius = 2; srf2 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius ); } ``` -------------------------------- ### Define Complex NURBS Surface and Planar Surface for Intersection Source: https://github.com/pboyer/verb/blob/master/examples/meshIntersection.html This function defines a highly complex NURBS surface using a detailed set of degrees, knots, and control points, along with a simpler planar NURBS surface. This example demonstrates the library's capability to handle intricate surface definitions for intersection calculations. ```javascript function exNurbsSurfacePlane(){ var degree = 3 , knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1] , pts = [ [ [0, 0, -10], [10, 0, 0], [20, 0, 0], [30, 0, 0] , [40, 0, 0], [50, 0, 9] ], [ [0, -10, 0], [10, -10, 10], [20, -10, 10], [30, -10, 0] , [40, -10, 0], [50, -10, 0] ], [ [0, -20, 0], [10, -20, 10], [20, -20, 10], [30, -20, 0] , [40, -20, -2], [50, -20, 0] ], [ [0, -30, 0], [10, -30, 0], [20, -30, 0], [30, -30, 0] , [40, -30, 0], [50, -30, 0] ], [ [0, -40, 0], [10, -40, 0], [20, -40, 0], [30, -40, 4] , [40, -40, -20], [50, -40, 0] ], [ [0, -50, 12], [10, -50, 0], [20, -50, 0], [30, -50, 0] , [50, -50, 0], [50, -50, 15] ] ]; srf1 = new verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts ); var p5 = [50,-50,3] , p6 = [50,0,3] , p7 = [0,0,3] , p8 = [0,-50,5]; srf2 = verb.geom.NurbsSurface.byCorners( p5, p6, p7, p8 ); } ``` -------------------------------- ### Define Plane and Cylindrical Surface for Intersection (JavaScript) Source: https://github.com/pboyer/verb/blob/master/examples/surfaceIntersection.html This function sets up a cylindrical surface using an axis, x-axis, base, height, and radius, and a plane defined by four corner points. These surfaces are intended for intersection calculations within the `verb.geom` framework. ```javascript function exPlaneCylindricalSurface(){ var axis = [0,0,1] , xaxis = [1,0,0] , base = [0,0,0] , height = 50 , radius = 30; srf1 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius ); var p5 = [50,50,50] , p6 = [-50,50,50] , p7 = [-50,-50,0] , p8 = [50,-50,0]; srf2 = verb.geom.NurbsSurface.byCorners( p5, p6, p7, p8 ); } ``` -------------------------------- ### Define Glancing Plane and Cylindrical Surface for Intersection Source: https://github.com/pboyer/verb/blob/master/examples/meshIntersection.html This function sets up a cylindrical surface and a planar NURBS surface. The plane is defined by four corner points, creating a scenario where the plane might 'glance' or tangentially intersect the cylinder. ```javascript function exGlancingPlaneCylindricalSurface(){ var axis = [0,0,1] , xaxis = [1,0,0] , base = [0,0,0] , height = 5 , radius = 3; srf1 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius ); var p5 = [5,5,0] , p6 = [-5,5,0] , p7 = [-5,-5,0] , p8 = [5,-5,0]; srf2 = verb.geom.NurbsSurface.byCorners( p5, p6, p7, p8 ); } ``` -------------------------------- ### Define NURBS Surface and Plane for Intersection (JavaScript) Source: https://github.com/pboyer/verb/blob/master/examples/surfaceIntersection.html This function defines two surfaces: a complex NURBS surface using control points and knots, and a simple plane using four corner points. These surfaces are prepared for a subsequent intersection operation using the `verb.geom` library. ```javascript function exNurbsSurfacePlane(){ var degree = 3 , knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1] , pts = [ [ [0, 0, -10], [10, 0, 0], [20, 0, 0], [30, 0, 0] , [40, 0, 0], [50, 0, 9] ], [ [0, -10, 0], [10, -10, 10], [20, -10, 10], [30, -10, 0] , [40, -10, 0], [50, -10, 0] ], [ [0, -20, 0], [10, -20, 10], [20, -20, 10], [30, -20, 0] , [40, -20, -2], [50, -20, 0] ], [ [0, -30, 0], [10, -30, 0], [20, -30, 0], [30, -30, 0] , [40, -30, 0], [50, -30, 0] ], [ [0, -40, 0], [10, -40, 0], [20, -40, 0], [30, -40, 4] , [40, -40, -20], [50, -40, 0] ], [ [0, -50, 12], [10, -50, 0], [20, -50, 0], [30, -50, 0] , [50, -50, 0], [50, -50, 15] ] ]; srf1 = new verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts ); var p5 = [50,-50,3] , p6 = [50,0,3] , p7 = [0,0,3] , p8 = [0,-50,5]; srf2 = verb.geom.NurbsSurface.byCorners( p5, p6, p7, p8 ); } ``` -------------------------------- ### Define Two Cylindrical Surfaces for Intersection Source: https://github.com/pboyer/verb/blob/master/examples/meshIntersection.html This function defines two cylindrical surfaces with different orientations and positions. This configuration allows for exploring the intersection of two cylinders, which can result in complex curves. ```javascript function exCylindricalSurfaceCylindricalSurface(){ var axis = [0,0,1] , xaxis = [1,0,0] , base = [0,0,0] , height = 5 , radius = 3; srf1 = new verb.geom.CylindricalSurface( axis, xaxis, base, height, radius ); var axis2 = [1,0,0] , xaxis2 = [0,1,0] , base2 = [0,0,-1] , height2 = 10 , radius2 = 3; srf2 = new verb.geom.CylindricalSurface( axis2, xaxis2, base2, height2, radius2 ); } ``` -------------------------------- ### Build Static HTML Documentation with MkDocs Source: https://github.com/pboyer/verb/blob/master/docs/README.md Uses the MkDocs tool to compile the generated Markdown files into a complete set of static HTML documentation, ready for deployment or viewing. ```bash mkdocs build ``` -------------------------------- ### Generate Markdown Files from Haxe Sources Source: https://github.com/pboyer/verb/blob/master/docs/README.md Executes a Node.js script (gen.js) to process Haxe (.hx) source files and convert them into Markdown (.md) documentation files, which are then placed into the 'docs' directory. ```bash node gen.js ``` -------------------------------- ### Compile and Package verb for JavaScript Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Commands to build, package (creating both ES and UMD versions), and run unit tests for the JavaScript output of the verb library. ```Shell npm run build ``` ```Shell npm run package ``` ```Shell npm run test ``` -------------------------------- ### Initialize Google Analytics Tracking Source: https://github.com/pboyer/verb/blob/master/site/index.html This JavaScript snippet initializes Google Analytics to track page views on the website. It sets up the 'ga' function, loads the analytics script asynchronously, creates a tracker with a specific ID, and sends an initial pageview event. ```JavaScript (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-56796889-1', 'auto'); ga('send', 'pageview'); ``` -------------------------------- ### Compile verb for PHP Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Command to build the verb library for the PHP platform using Haxe, generating PHP output files. ```Shell haxe buildphp.hxml ``` -------------------------------- ### Create and Display a NURBS Surface in JavaScript Source: https://github.com/pboyer/verb/blob/master/examples/surface.html This snippet demonstrates how to define a NURBS surface using control points and knot vectors, then convert it to a Three.js geometry and add it to the scene for rendering. It utilizes the `verb` geometry library for surface creation and a Three.js-like environment for display. ```javascript setupScene(); var degree = 3 , knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1] , pts = [ [ [0, 0, -10], [10, 0, 0], [20, 0, 0], [30, 0, 0] , [40, 0, 0], [50, 0, 0] ], [ [0, -10, 0], [10, -10, 10], [20, -10, 10], [30, -10, 0] , [40, -10, 0], [50, -10, 0] ], [ [0, -20, 0], [10, -20, 10], [20, -20, 10], [30, -20, 0] , [40, -20, -2], [50, -20, -12] ], [ [0, -30, 0], [10, -30, 0], [20, -30, -23], [30, -30, 0] , [40, -30, 0], [50, -30, 0] ], [ [0, -40, 0], [10, -40, 0], [20, -40, 0], [30, -40, 4] , [40, -40, -20], [50, -40, 0] ], [ [0, -50, 12], [10, -50, 0], [20, -50, 20], [30, -50, 0] , [50, -50, -10], [50, -50, -15] ] ]; var srf = verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts ); addMeshToScene( srf.toThreeGeometry() ); renderScene(); ``` -------------------------------- ### Compile verb for Python Source: https://github.com/pboyer/verb/blob/master/docs/docs/index.md Command to build the verb library for the Python platform using Haxe, generating a Python output file. ```Shell haxe buildpython.hxml ``` -------------------------------- ### Render Hierarchical Navigation Menu with Jinja2/Nunjucks Source: https://github.com/pboyer/verb/blob/master/docs/custom_theme/base.html This Jinja2/Nunjucks template code iterates through a `nav` object to construct a hierarchical navigation menu. It dynamically checks for child items to create nested lists, linking to respective documentation URLs. ```Jinja2 {% for nav_item in nav %} {% if nav_item.children %}* {{ nav_item.title }} {% for nav_item in nav_item.children %}* [{{ nav_item.title }}]({{ nav_item.url }}) {% endfor %} {% else %}* [{{ nav_item.title }}]({{ nav_item.url }}) {% endif %} {% endfor %} ``` -------------------------------- ### Generate Table of Contents with Jinja2/Nunjucks Source: https://github.com/pboyer/verb/blob/master/docs/custom_theme/base.html This Jinja2/Nunjucks template snippet generates a table of contents by looping through a `toc` variable. It creates clickable links for each top-level item and its immediate children, facilitating easy navigation within the document. ```Jinja2 {% for toc_item in toc %}* [{{ toc_item.title }}]({{ toc_item.url }}) {% for toc_item in toc_item.children %}* [{{ toc_item.title }}]({{ toc_item.url }}) {% endfor %} {% endfor %} ``` -------------------------------- ### Perform Mesh Slicing with verb.eval.Intersect.meshSlices Source: https://github.com/pboyer/verb/blob/master/examples/meshSlicing.html This JavaScript snippet initializes a scene, constructs a NURBS surface using control points and knots, and then tessellates it into a mesh. It subsequently uses `verb.eval.Intersect.meshSlices` to compute slices of the mesh between specified Z-coordinates, demonstrating a core capability for geometric analysis. The results are then visualized by adding the generated curves to the scene. ```javascript setupScene(); var degree = 3 , knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1] , pts = [ [ [0, 0, -10], [10, 0, 0], [20, 0, 0], [30, 0, 0] , [40, 0, 0], [50, 0, 10] ], [ [0, -10, 0], [10, -10, 10], [20, -10, 10], [30, -10, 0] , [40, -10, 0], [50, -10, 0] ], [ [0, -20, 0], [10, -20, 10], [20, -20, 10], [30, -20, 0] , [40, -20, -2], [50, -20, -12] ], [ [0, -30, 0], [10, -30, 0], [20, -30, -23], [30, -30, 0] , [40, -30, 0], [50, -30, 0] ], [ [0, -40, 0], [10, -40, 0], [20, -40, 0], [30, -40, 4] , [40, -40, -20], [50, -40, 0] ], [ [0, -50, 12], [10, -50, 0], [20, -50, 20], [30, -50, 0] , [50, -50, -10], [50, -50, -15] ], ]; var srf = verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts ); addMeshToScene( srf.toThreeGeometry(), null, true ); var mesh = srf.tessellate(); var res; var runs = 1; var d1 = Date.now(); for (var i = 0 ; i < runs; i++){ res = verb.eval.Intersect.meshSlices( mesh, -15, 15, 1 ); } console.log( res ); var d2 = Date.now(); console.log( res.length," slices in ", (d2 - d1) / runs, " ms"); for (var i = 0; i < res.length; i++){ for (var j = 0; j < res[i].length; j++){ var pwl = res[i][j].map(function(x){ return x.point; }); addCurveToScene( pointsAsGeometry( pwl )); } } renderScene(); ``` -------------------------------- ### Instantiate and Render verb.geom Conics and Curves Source: https://github.com/pboyer/verb/blob/master/examples/conics.html This JavaScript snippet initializes a 3D scene, then creates instances of various geometric shapes including an Arc, Circle, Ellipse, EllipseArc, and a BezierCurve using the `verb.geom` library. Each geometric object is then converted into a Three.js geometry using `toThreeGeometry()` and added to the scene for rendering. It demonstrates the basic workflow for defining and visualizing complex curves. ```javascript setupScene(); var arc = new verb.geom.Arc([0,0,0], [1,0,0], [0,1,0], 5, 0, 3* Math.PI/2 ); var circle = new verb.geom.Circle([12,0,0], [1,0,0], [0,1,0], 5 ); var ellipse = new verb.geom.Ellipse([24,0,0], [5,0,0], [0,2,0] ); var ellipseArc = new verb.geom.EllipseArc([36,0,0], [5,0,0], [0,2,0], 0, 3* Math.PI/2 ); var parabola = new verb.geom.BezierCurve([[43,5,0], [48,-10,0], [51,5,0]] ); addCurveToScene( circle.toThreeGeometry() ); addCurveToScene( arc.toThreeGeometry() ); addCurveToScene( ellipse.toThreeGeometry() ); addCurveToScene( ellipseArc.toThreeGeometry() ); addCurveToScene( parabola.toThreeGeometry() ); renderScene(); ``` -------------------------------- ### Calculate Closest Point on NURBS Surface with verb.geom Source: https://github.com/pboyer/verb/blob/master/examples/surfaceClosestPoint.html This JavaScript snippet sets up a NURBS surface using `verb.geom.NurbsSurface` with specified degree, knots, and control points. It then generates a grid of 25 test points. For each test point, it calculates the closest point on the surface using `srf.closestPoint(p0)` and visualizes the connection between the test point and the closest point on the surface using Three.js lines. The surface and test points are also rendered. ```javascript setupScene(); var degree = 3 , knots = [0, 0, 0, 0, 0.333, 0.666, 1, 1, 1, 1] , pts = [ [ [0, 0, -5], [10, 0, 0], [20, 0, 0], [30, 0, 0] , [40, 0, 0], [50, 0, 0] ], [ [0, -10, 0], [10, -10, 10], [20, -10, 10], [30, -10, 0] , [40, -10, 0], [50, -10, 0] ], [ [0, -20, 0], [10, -20, 10], [20, -20, 10], [30, -20, 0] , [40, -20, -2], [50, -20, -12] ], [ [0, -30, 0], [10, -30, 0], [20, -30, -23], [30, -30, 0] , [40, -30, 0], [50, -30, 0] ], [ [0, -40, 0], [10, -40, 0], [20, -40, 0], [30, -40, 4] , [40, -40, -20], [50, -40, 0] ], [ [0, -50, 12], [10, -50, 0], [20, -50, 10], [30, -50, 0] , [50, -50, -3], [50, -50, -5] ], ]; var srf = verb.geom.NurbsSurface.byKnotsControlPointsWeights( degree, degree, knots, knots, pts ); var lineMat = new THREE.LineBasicMaterial(); var pts = []; var c = 5; for (var i = 0; i < c; i++){ for (var j = 0; j < c; j++){ var p0 = [60 * i / (c-1) - 10, -60 * j / (c-1) + 10, 7 ]; pts.push( p0 ); var p = srf.closestPoint( p0 ); var l = new verb.geom.Line(p, p0); addCurveToScene( l.toThreeGeometry(), lineMat ); } } addPointsToScene( pts ); addMeshToScene( srf.toThreeGeometry() ); renderScene(); ``` -------------------------------- ### EJS Template for Verb.js API Documentation Generation Source: https://github.com/pboyer/verb/blob/master/docs/template.md This EJS template iterates over a collection of 'types' (classes, interfaces, typedefs) to generate structured API documentation. It dynamically renders details such as type names, namespaces, descriptions, inheritance, implemented interfaces, methods (with signatures, parameters, and return types), and properties (with types and default values). ```EJS <% _.each(types, function(x) { %> # <%= x.name %> `verb.<%= namespace + "." + x.name %>` **<%= x.$type.toUpperCase() %>** [Source code](<%= sourceFile + "#L" + x.line %>) <%= x.$type.toUpperCase() === "TYPEDEF" && x.alias ? "`" + x.name + " = " + x.alias + "`" : "" %> <%= x.description %> <% if (x.$type === "Class" || x.$type === "Interface") { %> <% if (x.parentClass) { %> **Extends:** [<%= x.parentClass %>]( <%= x.parentClass %>) <% } %> <% if (x.interfaces && x.interfaces.length) { %> **Implements:** <%= _.map(x.interfaces, function(x){ return "[`" + x + "`](" + x + ")"}).join(", ") %> <% } %> <% _.each(x.methods, function(y) { %> ## <%= y.name === "new" ? "constructor" : y.name %> **<%= y.isStatic ? "STATIC " : "" %>METHOD** [Source code](<%= sourceFile + "#L" + y.line %>) `<%= y.name === "new" ? y.name + " " + x.name : y.name %>(<%= _.map(y.args,function(x){ return x.name + " : " + x.type }).join(", ") %>) <% if (y.returnType) { %>: <%= y.returnType %><% } %>` <%= y.description %> <% }) %> <% _.each(x.properties, function(y) { %> ## <%= y.name %> **<%= y.isStatic ? "STATIC " : "" %>PROPERTY** [Source code](<%= sourceFile + "#L" + y.line %>) `<%= y.name %> <% if (y.type) { %>: <%=y.type %><% } %><% if (y.defaultValue) { %> = <%=y.defaultValue %><% } %>` <%= (y.description || "").replace(/\n\+/g,"\n*") %> <% }) %> <% } %> <% }) %> ```