Selva Compute API Reference - v1.1.2
    Preparing search index...

    Selva Compute API Reference - v1.1.2

    npm version npm downloads License: MIT TypeScript Node.js GitHub Repository

    selva-compute

    An intermediate-level TypeScript framework for building web applications with Rhino Compute and Grasshopper.

    selva-compute simplifies the process of communicating with Rhino Compute, handling Grasshopper definitions, and visualizing results in the browser with Three.js.

    npm install selva-compute three
    

    (Note: three is a peer dependency if you use the visualization features)

    selva-compute provides a type-safe, production-ready foundation for building with Rhino Compute:

    • Type-safe API – Full TypeScript support with advanced error handling for stability
    • High-level abstractions – Use GrasshopperClient and GrasshopperResponseProcessor to get started quickly
    • Ready-to-use visualization – Integrated Three.js setup with initScene() and configurable rendering options

    Whether you're building a simple solver or a complex web application, selva-compute handles the complexity so you can focus on your Grasshopper definitions.

    Note: The library currently focuses on the Grasshopper endpoint but is designed to support other Rhino Compute endpoints in future releases.

    // Configuration
    const DEFINITION_FILE = 'my-definition.gh';
    const COMPUTE_SERVER = 'http://localhost:6500';
    const API_KEY = 'your-api-key';

    const config = {
    serverUrl: COMPUTE_SERVER,
    apiKey: API_KEY
    } as GrasshopperComputeConfig;

    let client: GrasshopperClient | null = null;

    // Step 1: Create and initialize the client
    client = await GrasshopperClient.create(config);

    // Step 2: Get definition inputs and outputs
    const io = await client.getIO(DEFINITION_FILE);

    // Step 3: Build input data tree from definition parameters
    const inputTree = TreeBuilder.fromInputParams(io.inputs);

    // Step 4: Run the computation
    const result = await client.solve(DEFINITION_FILE, inputTree);

    // Step 5: Process and display results
    const processor = new GrasshopperResponseProcessor(result);
    const { values } = processor.getValues();
    • Node.js >= 20
    • three >= 0.179.0 (required for visualization features)

    selva-compute works with both standard Rhino Compute and enhanced versions:

    Standard Rhino Compute – The official McNeel repository works for basic Grasshopper solving with core features.

    Enhanced Setup (Recommended) – Unlock advanced features:

    1. Selva Rhino Plugin – Grasshopper plugin that simplifies building Three.js visualizations and exporting results directly from Grasshopper. Download from Food4Rhino. Detailed documentation will be available when the Selva project is open-sourced.
    2. Custom Compute Server – Our custom branch enables:
      • Input Grouping – Organize inputs with the groupName property
      • Persistent IDs – Uniquely identify inputs across definition changes using Grasshopper object GUIDs

    Features requiring the enhanced setup will be clearly marked in the documentation.

    This library is built on production experience and draws from several official McNeel repositories. Where code has been adapted, it is clearly marked in the relevant files.

    Key References:

    MIT