Utility for showing Replicad objects in the output of Jupyter cells when using the Deno Jupyter runtime
_Helpers for displaying Replicad objects in a Jupyter environment (via the Deno kernel)._
Ensure that peer dependencies are installed in the importing project:
``bash`
npm install && npm install opencascade.js@beta --force
> Note the @beta channel for opencascade.js
You can use Replicad Jupyter to initialize OpenCascade with Replicad and Deno. This does two things:
- Imports the Node build file of OC and passes that to Replicad (WASM does not make it happy in a Deno environment so this is non-standard compared to e.g. a browser's service worker environment).
- If running in CI (specified as the CI env variable being set to true), in which case Deno will not willingly evaluate a notebook via the nbconvert command and instead expects a plain TypeScript file, the global Jupyter display functions bulit into Deno will be set to no-op so that they do not throw errors.
`typescript
import replicadJupyter from 'npm:replicad-jupyter';
await replicadJupyter.initializeEnvironment();
`
> Environment initialization via this library is optional but recommended, you can also initialize OpenCascade yourself.
This library currently only supports "meshable" shapes, i.e. 3D objects that can be converted to vertices and faces. 2D shapes such as Drawings and Blueprints in Replicad are not currently supported, but on the roadmap.
To display a shape:
`typescript
import replicadJupyter from 'npm:replicad-jupyter';
// Initialization etc.
const baseShape = buildYourReplicadShape();
Deno.jupyter.html([
replicadJupyter(
// Objects to display
[
{
name: 'Base',
object: baseShape,
material: {
type: 'standard', // optional, 'standard' | 'basic'
color: 'rgb(128, 128, 128)', // optional, also supports CSS colors or 0x808080 notation
opacity: 1, // optional, [0, 1]
metalness: 0, // optional, [0, 1]
roughness: 1, // optional, [0. 1]
},
},
// ...
],
// Display configuration, optional
{
projection: 'orthographic', // optional, 'orthographic' | 'perspective'
defaultMaterial: {}, // same as object material configuration above
},
// Output format, optional
'html' // 'html' | 'json'
),
]);
`
The default display configuration argument can be set globally via replicadJupyter.setDefaultDisplayConfiguration({ projection, defaultMaterial })`.
The codebase is broken up between the "host" which is called by Deno, and the "embed" which is emitted as a bundle of HTML + JS and evaluated in the output cell.