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:
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:
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.
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.
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.
public sealed class RhinoModelObserver
{
private RhinoModelObserver()
{
RhinoDoc.AddRhinoObject += (s, e) => MarkChanged();
RhinoDoc.DeleteRhinoObject += (s, e) => MarkChanged();
RhinoDoc.ReplaceRhinoObject += (s, e) => MarkChanged();
// Additional event handlers...
}
}
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
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
- You can replace the uri "https://ijewel.design/rhinoceros", with "https://ijewel.design/rhinoceros?rhino" to ensure that the iJewel Viewer will listen to any model changes made in your CAD software.
- To Launch iJewel Playground, change the uri to "https://playground.ijewel3d.com/v2/index.html"
Source Code Access
You can fork the github repo to get access to the complete source code - Here.