Skip to content

Commit

Permalink
add meshPrimitives
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Mar 1, 2024
1 parent 632cf8a commit 184ee8a
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 2 deletions.
Binary file added docs/source/_static/images/mesh_primitive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/source/edit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ There are two methods for selecting atoms:


Move, Rotate and Duplicate selected atoms
===========================
=========================================

Press the transform shortcut, and move your mouse.

Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ A widget to visualize and interact with atomistic structures in Jupyter Notebook
measurement
isosurface
vector_field
mesh_primitive
selection


Expand Down
198 changes: 198 additions & 0 deletions docs/source/mesh_primitive.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
Mesh Primitive
=================
This module allow user to draw custom geometry. The supported geometry are:

- plane
- box
- sphere
- cylinder
- icosahedron
- cone
- torus
- arrow

.. figure:: _static/images/mesh_primitive.png
:align: center


Example
-----------------------------
The following example shows how to use the mesh primitive to draw two cubes and a sphere.


.. figure:: _static/images/mesh_primitive_example.png
:align: center
:width: 50%

.. code-block:: python
from weas_widget import WeasWidget
viewer = WeasWidget()
data = [
{
"type": "cube",
"data": [
{
"positions": [-5, 0, 0],
"size": 2,
"scale": [1, 0.5, 1],
"rotation": [0, 0, 0]
},
{
"positions": [5, 0, 1],
"size": 1,
"scale": [1, 0.5, 1],
"rotation": [1, 1, 0],
"color": "#bd0d87"
}
]
},
{
"type": "cylinder",
"data": [
{
"positions": [0, 0, 0],
"segments": 12,
"radius": 1,
"depth": 5,
"scale": [1, 1, 1],
"rotation": [0, 0, 0],
"color": "#0d87bd"
}
]
},
]
viewer.meshPrimitives = data
viewer
Primitive Parameters
-----------------------------

Cube
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The cube is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"size": 2,
"scale": [1, 1, 1],
"rotation":[0, 0, 0],
"color": "#bd0d87",
"materialType": "Standard",
}
Cylinder
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The cylinder is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"segments": 12,
"radius": 1,
"depth": 2,
"scale": [1, 1, 1],
"rotation":[0, 0, 0],
"color": "#bd0d87",
}
Sphere
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The sphere is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"widthSegments": 8,
"heightSegments": 6,
"radius": 1,
"scale": [1, 1, 1],
"rotation":[0, 0, 0],
"color": "#bd0d87",
}
Plane
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The plane is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"size": 2,
"scale": [1, 1, 1],
"rotation":[0, 0, 0],
"color": "#bd0d87",
}
Icosahedron
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The icosahedron is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"radius": 1,
"detail": 2,
"scale": [1, 1, 1],
"rotation":[0, 0, 0],
"color": "#bd0d87",
}
Cone
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The cone is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"segments": 8,
"radius": 1,
"height": 2,
"scale": [1, 1, 1],
"rotation":[0, 0, 0],
"color": "#bd0d87",
}
Arrow
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The arrow is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"direction": [0, 0, 1],
"length": 1,
"color": "#bd0d87",
"materialType": "Standard",
}
Torus
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The torus is defined by the following parameters:

.. code-block:: python
{
"positions": [0, 0, 0],
"radius": 1,
"tube": 0.4,
"radialSegments": 8,
"tubularSegments": 6,
"scale": [1, 1, 1],
"rotation":[0, 0, 0],
"color": "#bd0d87",
}
.. tip::
Please check the `three.js documentation <https://threejs.org/manual/?q=primi#en/primitives>`_ for more information about the parameters.
10 changes: 9 additions & 1 deletion js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function render({ model, el }) {
// vector field
avr.VFManager.fromSettings(model.get("vectorField"));
avr.showVectorField = model.get("showVectorField")
// mesh primitives
avr.meshPrimitive.fromSettings(model.get("meshPrimitives"));

avr.drawModels();
avr.render();
Expand Down Expand Up @@ -155,7 +157,13 @@ function render({ model, el }) {
avr.VFManager.fromSettings(data);
avr.VFManager.drawVectorFields();
});

// mesh primitives
model.on("change:meshPrimitives", () => {
const data = model.get("meshPrimitives");
console.log("meshPrimitives: ", data);
avr.meshPrimitive.fromSettings(data);
avr.meshPrimitive.drawMesh();
});
}
function createVolumeData(data, cell=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]) {
// get the dimensions
Expand Down
2 changes: 2 additions & 0 deletions src/weas_widget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class WeasWidget(anywidget.AnyWidget):
vectorField = tl.List().tag(sync=True)
showVectorField = tl.Bool(True).tag(sync=True)
guiConfig = tl.Dict({}).tag(sync=True)
# mesh primitives
meshPrimitives = tl.List(tl.Dict({})).tag(sync=True)
# viewer
viewerStyle = tl.Dict({}).tag(sync=True)
# task
Expand Down

0 comments on commit 184ee8a

Please sign in to comment.