Skip to content

Commit

Permalink
Add a method to change the camera parameters. Change "process" to "to…
Browse files Browse the repository at this point in the history
…_html".
  • Loading branch information
RobinEnjalbert committed Sep 13, 2024
1 parent f7e918a commit 780fc8b
Show file tree
Hide file tree
Showing 26 changed files with 331 additions and 182 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

*.html
*.ini
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
# SimExporter

A small **python** tool to **export standalone 3D animations** in **HTML files** using K3D.
A small **python** tool to **export standalone 3D interactive animations** in **HTML files** using K3D.

![gallery](docs/src/_static/gallery.gif)


## Presentation

**SimExporter** is a Python module for creating **3D scenes** of various 3D objects using
**SimExporter** is a Python module for creating **3D interactive scenes** of various 3D objects using
[**K3D**](http://www.k3d-jupyter.org/) and exporting a **3D plot** or a **3D animation** in a **standalone HTML file**.

This HTML file can then be opened in any browsers on any laptop, is can then be easily integrated into a **website** or
**presentation slides**.
This HTML file can then be shared and opened in any browsers and laptop, it can also be easily integrated into a
**website** or **presentation slides**.


## Gallery

See the interactive gallery in the [**documentation**]() !
See the interactive gallery in the [**documentation**](https://robinenjalbert.github.io/SimExporter/) !

![gallery](docs/src/_static/gallery.png)

Try an integrated animation on our [**team website**](https://mimesis.inria.fr/) !

![gallery](docs/src/_static/mimesis_website.gif)


## Install

Expand Down Expand Up @@ -48,7 +54,7 @@ exporter.objects.add_mesh(positions=...,
cells=...)

# Export the scene to an HTML file
exporter.process(filename='scene.html')
exporter.to_html(filename='scene.html')
```

The code below is the minimum for exporting a **3D animation** with various objects to a **standalone HTML file**:
Expand All @@ -67,13 +73,13 @@ exporter.objects.add_mesh(positions=...,
time_positions=...)

# Export the animation to an HTML file
exporter.process(filename='animation.html')
exporter.to_html(filename='animation.html')
```

To integrate the HTML file into a website or presentation slides, see the dedicated section in the
[**documentation**]().
[**documentation**](https://robinenjalbert.github.io/SimExporter/).


## Documentation

Just in case you missed it [**documentation**]()
See more [**documentation**](https://robinenjalbert.github.io/SimExporter/)
Binary file added docs/src/_static/gallery.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/_static/gallery.png
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/src/_static/html/meshes.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/src/_static/html/points.html

Large diffs are not rendered by default.

Binary file added docs/src/_static/mimesis_website.gif
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/src/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ API

.. autoclass:: SimExporter.core.exporter.Exporter
:special-members: __init__
:members: process
:members: to_html


.. autoclass:: SimExporter.core.factory.Factory
Expand Down
4 changes: 2 additions & 2 deletions docs/src/demo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Demo
time_positions=...)
# Export to HTML
exporter.process(filename='scene.html',
exporter.to_html(filename='scene.html',
background_color='black',
menu_visible=True,
grid_visible=False,
Expand Down Expand Up @@ -84,7 +84,7 @@ Demo
time_positions=...)
# Export to HTML
exporter.process(filename='scene.html',
exporter.to_html(filename='scene.html',
background_color='black',
menu_visible=True,
grid_visible=False,
Expand Down
12 changes: 9 additions & 3 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
SimExporter
===========

**SimExporter** is a Python module for creating 3D scenes of various 3D objects using
:K3D:`K3D <>` and exporting a 3D plot or a 3D animation in a standalone HTML file.
**SimExporter** is a Python module for creating **3D interactive scenes** of various 3D objects using
:K3D:`K3D <>` and exporting a **3D plot** or a **3D animation** in a standalone HTML file.

This HTML file can then be opened in any browsers on any laptop, is can then be easily integrated into a website or
This HTML file can then be shared and opened in any browsers and laptop, it can also be easily integrated into a website or
presentation slides.

.. image:: _static/gallery.gif


Features
--------
Expand All @@ -28,6 +30,10 @@ Gallery

.. image:: _static/gallery.png

Try an integrated animation on our `team website <https://mimesis.inria.fr/>`_ !

.. image:: _static/mimesis_website.gif



.. toctree::
Expand Down
14 changes: 12 additions & 2 deletions docs/src/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,18 @@ The **Exporter** exposes the methods to create several 3D objects in the :guilab
Step 3: Export in HTML
----------------------

Finally, the call to :py:meth:`process<SimExporter.core.exporter.Exporter.process>` will export the 3D scene in HTML:
Finally, the call to :py:meth:`to_html<SimExporter.core.exporter.Exporter.to_html>` will export the 3D scene in HTML:

.. code-block:: python
exporter.process(filename='scene.html')
exporter.to_html(filename='scene.html')
Step 4: Include in a webpage
----------------------------

To include an exported animation, you can simply use an **HTML Iframe**:

.. code-block:: html

<iframe src="animation.html" height="600px" width="100%"></iframe>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 14 additions & 10 deletions examples/core/export_arrows.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
from numpy import load, zeros, mean
from os.path import join
from numpy import load, zeros, mean, array
from vedo import Mesh

from SimExporter.core import Exporter


# Load the data
heart = Mesh('heart.obj')
heart_positions = load('heart.npy')
heart = Mesh(join('data', 'heart.obj'))
heart_positions = load(join('data', 'heart.npy'))


# Create the exporter
exporter = Exporter(animation=True,
fps=50)
exporter = Exporter(animation=True, fps=50)


# Add mesh and arrows to the scene
exporter.objects.add_mesh(positions=mean(heart_positions, axis=0),
time_positions=array([mean(heart_positions, axis=0) for _ in range(heart_positions.shape[0])]),
cells=heart.cells,
color='grey',
alpha=0.6,
wireframe=True)
exporter.objects.add_arrows(positions=mean(heart_positions, axis=0),
vectors=zeros((heart.npoints, 3)),
time_positions=array([mean(heart_positions, axis=0) for _ in range(heart_positions.shape[0])]),
scale=3,
line_width=0.5,
head_size=0.,
time_vectors=heart_positions[:] - mean(heart_positions, axis=0))

exporter.process(filename='arrows.html',
background_color='white',
menu_visible=True,
grid_visible=False,
frame_visible=False)

# Export to HTML with custom camera parameters
exporter.set_camera(factor=0.8, yaw=-80, pitch=60)
exporter.to_html(filename=join('html', 'arrows.html'), background_color='#0D1117', grid_visible=False,
menu_visible=True, frame_visible=False)
27 changes: 14 additions & 13 deletions examples/core/export_meshes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os.path import join
from numpy import load, mean
from numpy.linalg import norm
from vedo import Mesh
Expand All @@ -6,36 +7,36 @@


# Load the data
heart = Mesh('heart.obj')
heart_positions = load('heart.npy')
vessel = Mesh('vessels.obj')
vessel_positions = load('vessels.npy')
heart = Mesh(join('data', 'heart.obj'))
heart_positions = load(join('data', 'heart.npy'))
vessel = Mesh(join('data', 'vessels.obj'))
vessel_positions = load(join('data', 'vessels.npy'))


# Create the exporter
exporter = Exporter(animation=True,
fps=50)
exporter = Exporter(animation=True, fps=50)


# Add meshes to the scene
exporter.objects.add_mesh(positions=heart.vertices,
cells=heart.cells,
color=[192, 28, 40],
alpha=0.6,
flat_shading=False,
wireframe=True,
time_positions=heart_positions)
exporter.objects.add_mesh(positions=vessel.vertices,
cells=vessel.cells,
color='white',
alpha=1.,
flat_shading=False,
wireframe=True,
colormap_name='Reds',
colormap_range=[0, 1],
time_colormap_values=norm(vessel_positions - mean(vessel_positions, axis=0), axis=2),
time_positions=vessel_positions)

# Export to HTML
exporter.process(filename='meshes.html',
background_color='white',
menu_visible=True,
grid_visible=False,
frame_visible=True)

# Export to HTML with custom camera parameters
exporter.set_camera(factor=0.8, yaw=-80, pitch=60)
exporter.to_html(filename=join('html', 'meshes.html'), background_color='#0D1117', grid_visible=False,
menu_visible=True, frame_visible=True)
10 changes: 8 additions & 2 deletions examples/core/export_others.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from os.path import join
from numpy import array, float32
import k3d
from vedo import Mesh

from SimExporter.core import Exporter


# Load the data
mesh = Mesh('heart.obj')
mesh = Mesh(join('data', 'heart.obj'))
mesh = k3d.vtk_poly_data(mesh.dataset)


# Create the exporter
exporter = Exporter()


# Create k3d objects
lines = k3d.lines(vertices=array(mesh.vertices, dtype=float32),
indices=array(mesh.indices, dtype=float32),
Expand All @@ -20,8 +24,10 @@
position=mesh.vertices[500],
is_html=True)


# Add k3d objects to the scene
exporter.objects.add_k3d_objects(lines, text)


# Export to HTML
exporter.process(filename='others.html')
exporter.to_html(filename=join('html', 'others.html'))
21 changes: 11 additions & 10 deletions examples/core/export_points.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from os.path import join
from numpy import load, mean
from numpy.linalg import norm
from vedo import Mesh
Expand All @@ -6,12 +7,13 @@


# Load the data
heart = Mesh('heart.obj')
heart_positions = load('heart.npy')
heart = Mesh(join('data', 'heart.obj'))
heart_positions = load(join('data', 'heart.npy'))


# Create the exporter
exporter = Exporter(animation=True,
fps=50)
exporter = Exporter(animation=True, fps=50)


# Add mesh and points to the scene
exporter.objects.add_mesh(positions=heart.vertices,
Expand All @@ -26,9 +28,8 @@
time_colormap_values=norm(heart_positions - mean(heart_positions, axis=0), axis=2),
time_positions=heart_positions)

# Export to HTML
exporter.process(filename='points.html',
background_color='white',
menu_visible=True,
grid_visible=False,
frame_visible=True)

# Export to HTML with custom camera parameters
exporter.set_camera(factor=0.8, yaw=-80, pitch=60)
exporter.to_html(filename=join('html', 'points.html'), background_color='#0D1117', grid_visible=False,
menu_visible=True, frame_visible=True)
15 changes: 8 additions & 7 deletions examples/core/export_tetra_mesh.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
from os.path import join
from vedo import Mesh

from SimExporter.core import Exporter


# Load the data and create tetra mesh
mesh = Mesh('heart.obj')
mesh = Mesh(join('data', 'heart.obj'))
tetra = mesh.clone().tetralize(side=0.05)


# Create the exporter
exporter = Exporter()


# Add meshes to the scene
exporter.objects.add_mesh(positions=mesh.vertices,
cells=mesh.cells,
color='#f5c211',
alpha=0.9,
alpha=0.2,
wireframe=True)
exporter.objects.add_mesh(positions=tetra.vertices,
cells=tetra.cells,
color='#1c71d8',
alpha=0.05)

# Export to HTML
exporter.process(filename='tetra.html',
background_color='white',
menu_visible=True,
grid_visible=False,

# Export to HTML with custom camera parameters
exporter.set_camera(factor=0.8, yaw=-80, pitch=60)
exporter.to_html(filename=join('html', 'tetra.html'), background_color='grey', grid_visible=False, menu_visible=True,
frame_visible=True)
Loading

0 comments on commit 780fc8b

Please sign in to comment.