{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import random\n", "import os\n", "import os.path\n", "import sys\n", "\n", "from OCC.STEPControl import STEPControl_Reader\n", "from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def read_step_file(filename):\n", " \"\"\" read the STEP file and returns a compound\n", " \"\"\"\n", " step_reader = STEPControl_Reader()\n", " status = step_reader.ReadFile(filename)\n", "\n", " if status == IFSelect_RetDone: # check status\n", " failsonly = False\n", " step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)\n", " step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)\n", "\n", " ok = step_reader.TransferRoot(1)\n", " _nbs = step_reader.NbShapes()\n", " aResShape = step_reader.Shape(1)\n", " else:\n", " print(\"Error: can't read file.\")\n", " sys.exit(0)\n", " return aResShape\n", "\n", "shp = read_step_file(os.path.join('..', 'models', 'RC_Buggy_2_front_suspension.stp'))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "my_renderer = JupyterRenderer()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "31e8731dd2d9458cad5e2f639c9645dd", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type Renderer.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "Renderer(background='white', background_opacity=1.0, camera=PerspectiveCamera(children=[DirectionalLight(color='#ffffff', intensity=0.5, position=[50.0, 50.0, 50.0], scale=[1.0, 1.0, 1.0], up=[0.0, 1.0, 0.0])], position=[0.0, -319.77835558779555, 482.2885442623915], scale=[1.0, 1.0, 1.0], up=[0.0, 1.0, 0.0]), controls=[TrackballControls(controlling=PerspectiveCamera(children=[DirectionalLight(color='#ffffff', intensity=0.5, position=[50.0, 50.0, 50.0], scale=[1.0, 1.0, 1.0], up=[0.0, 1.0, 0.0])], position=[0.0, -319.77835558779555, 482.2885442623915], scale=[1.0, 1.0, 1.0], up=[0.0, 1.0, 0.0]), target=[0.0, 0.0, 0.0])], effect=None, scene=Scene(children=[Mesh(geometry=PlainBufferGeometry(faces=array([[ 0, 1, 2],\n", " [ 3, 4, 5],\n", " [ 6, 7, 8],\n", " ..., \n", " [1655790, 1655791, 1655792],\n", " [1655793, 1655794, 1655795],\n", " [1655796, 1655797, 1655798]], dtype=uint32), vertices=array([[ 13.35946369, 11.34571552, 22.5 ],\n", " [ 13.54709244, 11.3575201 , 22.5 ],\n", " [ 13.35946369, 11.34571552, 23.5 ],\n", " ..., \n", " [ 28.10727119, 26.04367065, -1.99000001],\n", " [ 28.15982437, 26.00403404, -1.99000001],\n", " [ 28.10086632, 26.03387642, -1.99000001]], dtype=float32)), material=PhongMaterial(color='#a6a6a6', envMap=None, lightMap=None, map=None, morphTargets=True, shininess=0.9, specularMap=None), position=[0.0, 0.0, 0.0], scale=[1.0, 1.0, 1.0], up=[0.0, 1.0, 0.0]), AmbientLight(color='#101010', position=[0.0, 0.0, 0.0], scale=[1.0, 1.0, 1.0], up=[0.0, 1.0, 0.0])], position=[0.0, 0.0, 0.0], scale=[1.0, 1.0, 1.0], up=[0.0, 1.0, 0.0]))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "my_renderer.DisplayShape(shp)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }