Skip to content

Integrating iJewel3D Rhino Plugin in custom workflows

This section outlines the technical details of iJewel Viewer plugin for McNeel Rhino 8. The plugin allows users to launch iJewel Viewer directly from Rhino via a custom command.

This guide can be followed to integrate iJewel viewer into any rhino plugin or workflow.

Rhino.Commands.Command is the abstract base class for custom commands within Rhino from RhinoCommon(the .NET SDK for Rhino). By overriding its RunCommand method, we enable Rhino to export model data, synchronize changes, and stream assets directly into iJewel Viewer.

The plugin is open-source and available on GitHub - https://github.com/ijewel3d/ijewel-rhino

Core Command Workflow

The central logic resides in the RunCommand method:

csharp
 protected override Result RunCommand(RhinoDoc doc, RunMode mode) {
    try {
        RhinoApp.WriteLine("Checking internet connectivity...");

        if (!CheckInternetConnectivity()) {
            RhinoApp.WriteLine("Error: No internet connection detected.");
            ShowNoInternetDialog();
            return Result.Failure;
        }

        RhinoApp.WriteLine("Internet connection verified.");
        RhinoApp.WriteLine("Starting IJewelViewer...");

        // Only start server if one isn't already running
        StartFileServer();

        RhinoApp.WriteLine("Exporting model...");
        ExportModel(doc);

        string uri = "https://ijewel.design/rhinoceros";

        if (Rhino.Runtime.HostUtils.RunningOnOSX) {
            if (!BrowserLauncher.LaunchBrowserInMac(uri)) {
                //launch webview if none of the supported browsers are available on mac
                var webViewForm = new WebViewForm(uri);
                webViewForm.Show();
            } 
        }
        else {
            //use webview directly on windows
            var webViewForm = new WebViewForm(uri);
            webViewForm.Show();
        }

        return Result.Success;
    }
    catch (Exception ex) {
        RhinoApp.WriteLine($"Error in RunCommand: {ex.Message}");
        RhinoApp.WriteLine($"Stack Trace: {ex.StackTrace}");
        return Result.Failure;
    }
 }

This workflow is divided into three major steps:

  1. Checking Intenet Connectivity

Validates an active internet connection. This is critical because iJewel Viewer pulls a rich library of assets from the cloud, including:

  • Photorealistic material definitions (metals, diamonds, gemstones)
  • HDR lighting environments
  • 3D asset templates
  • Texture maps and surface details

This ensures that every designer has access to the most updated visual assets.

  1. Local File Server Initialization and Model Observervation

The plugin starts a lightweight local file server to serves 3D model data to web clients.This enables Rhino’s 3D model data to be seamlessly streamed into the iJewel Viewer without manual exporting.

csharp
protected void StartFileServer()
{
    if (IsPortInUse(Port)) return;
    
    _listener = new HttpListener();
    _listener.Prefixes.Add($"http://localhost:{Port}/");
    _listener.Start();
    
    _serverThread = new Thread(() => 
        ServerUtility.ServerThreadStart(_listener, _cancellationTokenSource.Token));
    _serverThread.Start();
}

Alongside this, the RhinoModelObserver class continuously monitors model changes:

  • Model creation, deletion, or modification
  • Layer hiding or reassignment
  • Material and object property changes
  • Transformation changes

Every update is instantly reflected in the iJewel Viewer, ensuring what the designer sees is always accurate and up to date.

The RhinoModelObserver class tracks the above model changes. This ensures that any changes to the 3D model are automatically detected and can trigger re-exports or notifications to connected iJewel Viewer.

csharp
public sealed class RhinoModelObserver
{
    private RhinoModelObserver()
    {
        RhinoDoc.AddRhinoObject += (s, e) => MarkChanged();
        RhinoDoc.DeleteRhinoObject += (s, e) => MarkChanged();
        RhinoDoc.ReplaceRhinoObject += (s, e) => MarkChanged();
        // Additional event handlers...
    }
}
  1. Launching iJewelViewer in Browser or Embedded Window

Finally, the plugin launches the iJewel Viewer, either in:

  • The user’s default web browser, or
  • An embedded in-app web view
csharp
    string uri = "https://ijewel.design/rhinoceros";

    if (Rhino.Runtime.HostUtils.RunningOnOSX) {
        if (!BrowserLauncher.LaunchBrowserInMac(uri)) {
            //launch webview if none of the supported browsers are available on mac
            var webViewForm = new WebViewForm(uri);
            webViewForm.Show();
        } 
    }
    else {
        //use webview directly on windows
        var webViewForm = new WebViewForm(uri);
        webViewForm.Show();
    }
  • On macOS, it attempts to launch specific browsers (Chrome, Firefox, Opera) before falling back to an embedded WebView.
  • On Windows, the embedded WebView is the default.

TIP

Source Code Access

You can fork the github repo to get access to the complete source code - Here.