{ "cells": [ { "cell_type": "markdown", "id": "323c664c", "metadata": {}, "source": [ "# Mesh Primitive\n", "\n", "This module allow user to draw custom geometry. The supported geometry are:\n", "\n", "- plane\n", "- box\n", "- sphere\n", "- cylinder\n", "- icosahedron\n", "- cone\n", "- torus\n", "- arrow\n", "\n", "
![Mesh Primitive](_static/images/mesh_primitive.png)
\n", "\n", "\n", "## Color\n", "The transparency of the color can be set by using the `opacity` parameter.\n", "\n", "\n", "## Example\n", "The following example shows how to use the mesh primitive to draw two cubes and a sphere.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "fa2ac151", "metadata": {}, "outputs": [], "source": [ "from weas_widget import WeasWidget\n", "\n", "viewer = WeasWidget()\n", "data = [\n", "{\n", " \"type\": \"cube\",\n", " \"materialType\": \"Standard\",\n", " \"opacity\": 0.5,\n", " \"shape\": {\n", " \"width\": 1,\n", " \"height\": 1,\n", " \"depth\": 1\n", " },\n", " \"instances\": [\n", " {\n", " \"position\": [-5, 0, 0],\n", " \"size\": 2,\n", " \"scale\": [1, 0.5, 1],\n", " \"rotation\": [0, 0, 0]\n", " },\n", " {\n", " \"position\": [5, 0, 1],\n", " \"size\": 1,\n", " \"scale\": [1, 0.5, 1],\n", " \"rotation\": [1, 1, 0],\n", " \"color\": \"#bd0d87\"\n", " }\n", " ]\n", "},\n", "{\n", " \"type\": \"cylinder\",\n", " \"shape\": {\n", " \"radiusTop\": 1,\n", " \"radiusBottom\": 1,\n", " \"height\": 1,\n", " \"radialSegments\": 12,\n", " \"heightSegments\": 1\n", " },\n", " \"instances\": [\n", " {\n", " \"position\": [0, 0, 0],\n", " \"segments\": 12,\n", " \"radius\": 1,\n", " \"scale\": [1, 5, 1],\n", " \"rotation\": [0, 0, 0],\n", " \"color\": \"#0d87bd\"\n", " }\n", " ]\n", "},\n", "]\n", "viewer.imp.settings = data\n", "viewer" ] }, { "cell_type": "markdown", "id": "a7ac2099", "metadata": {}, "source": [ "## Primitive Parameters\n", "\n", "### Cube\n", "The cube is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"size\": 2,\n", " \"scale\": [1, 1, 1],\n", " \"rotation\":[0, 0, 0],\n", " \"color\": \"#bd0d87\",\n", " \"materialType\": \"Standard\",\n", " }\n", "```\n", "\n", "### Cylinder\n", "The cylinder is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"segments\": 12,\n", " \"radius\": 1,\n", " \"depth\": 2,\n", " \"scale\": [1, 1, 1],\n", " \"rotation\":[0, 0, 0],\n", " \"color\": \"#bd0d87\",\n", " }\n", "```\n", "\n", "### Sphere\n", "The sphere is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"widthSegments\": 8,\n", " \"heightSegments\": 6,\n", " \"radius\": 1,\n", " \"scale\": [1, 1, 1],\n", " \"rotation\":[0, 0, 0],\n", " \"color\": \"#bd0d87\",\n", " }\n", "```\n", "\n", "### Plane\n", "The plane is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"size\": 2,\n", " \"scale\": [1, 1, 1],\n", " \"rotation\":[0, 0, 0],\n", " \"color\": \"#bd0d87\",\n", " }\n", "```\n", "\n", "### Icosahedron\n", "The icosahedron is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"radius\": 1,\n", " \"detail\": 2,\n", " \"scale\": [1, 1, 1],\n", " \"rotation\":[0, 0, 0],\n", " \"color\": \"#bd0d87\",\n", " }\n", "```\n", "\n", "### Cone\n", "The cone is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"segments\": 8,\n", " \"radius\": 1,\n", " \"height\": 2,\n", " \"scale\": [1, 1, 1],\n", " \"rotation\":[0, 0, 0],\n", " \"color\": \"#bd0d87\",\n", " }\n", "```\n", "\n", "### Arrow\n", "The arrow is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"direction\": [0, 0, 1],\n", " \"length\": 1,\n", " \"color\": \"#bd0d87\",\n", " \"materialType\": \"Standard\",\n", " }\n", "```\n", "\n", "### Torus\n", "The torus is defined by the following parameters:\n", "\n", "```python\n", "\n", " {\n", " \"position\": [0, 0, 0],\n", " \"radius\": 1,\n", " \"tube\": 0.4,\n", " \"radialSegments\": 8,\n", " \"tubularSegments\": 6,\n", " \"scale\": [1, 1, 1],\n", " \"rotation\":[0, 0, 0],\n", " \"color\": \"#bd0d87\",\n", " }\n", "```\n", "\n", ".. tip::\n", " Please check the [three.js documentation](https://threejs.org/manual/?q=primi#en/primitives) for more information about the parameters.\n" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }