Skip to content

Commit ef1056c

Browse files
Merge pull request #1 from losanc/main
First publish
2 parents 6c88149 + bdcc826 commit ef1056c

33 files changed

+3991
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__pycache__/
2+
.DS_Store
3+
.vs_code/
4+
*.zip
5+
6+
# the following ignores are used to ignore the local softlink files
7+
# the extern folder won't be affected by this
8+
rich
9+
meshio
10+
future
11+
fileseq

.gitmodules

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
[submodule "extern/meshio"]
3+
path = extern/meshio
4+
url = https://github.com/nschloe/meshio
5+
[submodule "extern/python-future"]
6+
path = extern/python-future
7+
url = https://github.com/PythonCharmers/python-future
8+
[submodule "extern/fileseq"]
9+
path = extern/fileseq
10+
url = https://github.com/justinfx/fileseq
11+
[submodule "extern/rich"]
12+
path = extern/rich
13+
url = https://github.com/Textualize/rich

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
![](images/logo.svg)
2+
3+
Loading animation sequences with meshio and fileseq
4+
5+
- [1. Installation](#1-installation)
6+
- [1.1 Build from source (optional)](#11-build-from-source-optional)
7+
- [1.2 Install Addon](#12-install-addon)
8+
- [1.3 FAQs](#13-faqs)
9+
- [2. How to use](#2-how-to-use)
10+
- [2. Load the animation sequence you want](#2-load-the-animation-sequence-you-want)
11+
- [2.1 Absolute vs. Relative Paths](#21-absolute-vs-relative-paths)
12+
- [2.2 Sequence List View](#22-sequence-list-view)
13+
- [2.2.1 Enable/ Disable](#221-enable-disable)
14+
- [2.2.1 Refresh Sequence](#221-refresh-sequence)
15+
- [2.3 Settings](#23-settings)
16+
- [2.3.1 Geometry Nodes](#231-geometry-nodes)
17+
- [2.3.2 Path Information](#232-path-information)
18+
- [2.3.3 Attributes Settings](#233-attributes-settings)
19+
- [2.3.4 Split Norm per Vertex](#234-split-norm-per-vertex)
20+
21+
## 1. Installation
22+
23+
### 1.1 Build from source (optional)
24+
25+
1. Clone the project to download both project and dependencies
26+
27+
```shell
28+
git clone https://www.graphics.rwth-aachen.de:9000/hhui/blendertool --recurse-submodules
29+
```
30+
31+
2. Build the installable `.zip` file by simply running the following command. This should produce a file called `blender_sequence_loader_{date}.zip`, where `{date}` is replaced with todays date. No other dependency other than standard python3 libraries are needed to build the addon.
32+
33+
```shell
34+
python3 build_addon.py
35+
```
36+
37+
### 1.2 Install Addon
38+
39+
After obtaining an installable `.zip` file either from the releases page or from manually building the addon, this should be installed into blender. For more information on how to install addons see [here](https://docs.blender.org/manual/en/latest/editors/preferences/addons.html#installing-add-ons) for more details.
40+
41+
### 1.3 FAQs
42+
43+
1. You may need to restart blender after enabling the addon for the first time, otherwise some functionality may not work. Technically this should not be **required**, but might be necessary in some untested versions of Blender.
44+
45+
2. You may have to manually remove old versions of this addon (if present), before installing a new version into Blender. This should rarely be the case but might be the cause of some confusing error messages and issues.
46+
47+
## 2. How to use
48+
49+
DISCLAIMER: Some of the screenshots may not be up to date with the most recent version of the addon, especially with respect to the text and ordering of UI elements.
50+
51+
After installing addon, you can find it in the toolbar, which is accessible here or toggled by pressing the `n` key.
52+
53+
![start](images/0.png)
54+
55+
Then you can find it here.
56+
57+
![homepage](images/1.png)
58+
59+
### 2. Load the animation sequence you want
60+
61+
You can select the directory in which your data is located through the GUI by clicking the rightmost icon. It will open the default blender file explorer. Then you can go to the directory you want, for example, like image showed below. **You only need navigate to the directory and click "Accept". Files are shown but not selectable in this dialogue.**
62+
63+
![selecticon](images/2.png)
64+
65+
Then the addon will automatically try to detect the sequences in this directory, so that you simply select the sequence you want. If the desired sequence is not shown, you can switch to enter a manual pattern, where a single `@` character is used to denote a running frame index.
66+
67+
![after_selecting](images/3.png)
68+
69+
#### 2.1 Absolute vs. Relative Paths
70+
71+
There is a small checkbox about whether to use `relative paths` or not.
72+
73+
When toggled on, the blender file must be saved before loading the sequence. Then this sequence will be loaded using relative path from the location of the saved `.blend` file. As such, if you move the `.blend` file in conjunction with the data to another directory (keeping their relative locations the same) the sequence loader will still work. This is especially useful when working with cloud synchronized folders, whose absolute paths may be different on different computers.
74+
75+
If toggled off (default), it will use absolute path to load the sequence. For this, the `.blend` file does not have to be saved in advance.
76+
77+
![relative_path](images/4.png)
78+
79+
#### 2.2 Sequence List View
80+
81+
After the sequence being imported, it will be available in the `Imported Sequences` panel, with more settings being available in `Sequence Settings` panel once a sequence has been selected.
82+
83+
![settings](images/5.png)
84+
85+
By default, all supported file formats are simply imported as geometry (a collection of vertices, lines, triangles and quads). As such, you should be able to directly play/render the animation if it contains geometry.
86+
87+
Note: When rendering the animation, please turn on the `Lock Interface`. This will prevent artifacts from occurring, especially if the user continues to operate the Blender interface during the render process.
88+
89+
![lock interface](images/6.png)
90+
91+
##### 2.2.1 Enable/ Disable
92+
93+
It is possible to individually enable and disable sequences from updating when the animation frame changes. This is very useful when working with very large files or many sequences as it reduces the computational overhead of loading these sequences.
94+
`Enabled` means, that the sequence will be updated on frame change, and `Disabled` means that the sequence won't be updated on frame change.
95+
96+
##### 2.2.1 Refresh Sequence
97+
98+
`Refresh Sequence` can be useful when the sequence is imported while the data is still being generated and not yet complete. Refreshing the sequence can detect the frames added after being imported.
99+
100+
#### 2.3 Settings
101+
102+
#### 2.3.1 Geometry Nodes
103+
104+
While all files are imported as plain geometry, we provide some templates that we have found to be incredibly useful for visualizing particle data.
105+
106+
Applying the `Point Cloud` geometry node, the vertices of the mesh are converted to a point cloud, which can be rendered only by [cycles](https://docs.blender.org/manual/en/latest/render/cycles/introduction.html) and only as spheres. The exact geometry node setup can be seen in the geometry nodes tab and may be modified as desired, e.g. to set the particle radius.
107+
108+
Applying `Instances` geometry nodes, the vertices of the mesh are converted to cubes, which can be rendered by both [eevee](https://docs.blender.org/manual/en/latest/render/eevee/index.html) and [cycles](https://docs.blender.org/manual/en/latest/render/cycles/introduction.html). The exact geometry node setup can be seen in the geometry nodes tab and may be modified as desired, e.g. to set the particle radius and to change the instanced geometry. **CAUTION: Because this node setup relies on the `Realize Instances` node, the memory usage increases extremely rapidly. Make sure to save the `.blend` file before attempting this, as Blender may run out of memory!!!**
109+
110+
Applying the `Mesh` geometry node will restore the default geometry nodes, which simply display the imported geometry as it is.
111+
112+
Notes:
113+
114+
1. `Instances` is super memory hungry compared with `Point Cloud`.
115+
2. After applying `Point Cloud` or `Instances` geometry nodes, you need to assign the material inside the geometry nodes. So to save your work, you can simply assign the material here, then apply the `Point Cloud` or `Instances` geometry nodes.
116+
3. To access the attributes for shading, use the `Attribute` node in the Shader Editor and simply specify the attribute string. The imported attributes can be seen in the spreadsheet browser of the Geometry Nodes tab and are also listed in the addon UI.
117+
118+
![material](images/7.png)
119+
120+
#### 2.3.2 Path Information
121+
122+
This shows the path of the sequence for debugging purposes, however it's not editable.
123+
124+
#### 2.3.3 Attributes Settings
125+
126+
This panel shows the available **Vertex Attributes**, it's not editable.
127+
128+
Note: In order to avoid conflicts with Blenders built-in attributes, all the attributes names are renamed by prefixing `bseq_`. For example, `id` -> `bseq_id`. Keep this in mind when accessing attributes in the shader editor.
129+
130+
#### 2.3.4 Split Norm per Vertex
131+
132+
We also provide the ability to use a per-vertex vector attribute as custom normals for shading.
133+
For more details check the official documentation [here](https://docs.blender.org/manual/en/latest/modeling/meshes/structure.html#modeling-meshes-normals-custom).
134+
135+
Note: the addon does not check if the selected attribute is suitable for normals or not. E.g. if the data type of the attribute is int instead of float, then Blender will simply give a runtime error.

__init__.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
bl_info = {
2+
"name": "Sequence Loader",
3+
"description": "Loader for meshio supported mesh files/ simulation sequences",
4+
"author": "Interactive Computer Graphics",
5+
"version": (1, 0),
6+
"blender": (3, 1, 0),
7+
"warning": "",
8+
"support": "COMMUNITY",
9+
"category": "Import-Export",
10+
}
11+
12+
import bpy
13+
import os
14+
import sys
15+
16+
current_folder = os.path.dirname(os.path.abspath(__file__))
17+
if current_folder not in sys.path:
18+
sys.path.append(current_folder)
19+
20+
if bpy.context.preferences.filepaths.use_relative_paths == True:
21+
bpy.context.preferences.filepaths.use_relative_paths = False
22+
23+
from simloader import *
24+
25+
classes = [
26+
SIMLOADER_obj_property,
27+
SIMLOADER_scene_property,
28+
SIMLOADER_mesh_property,
29+
SIMLOADER_OT_load,
30+
SIMLOADER_OT_edit,
31+
SIMLOADER_OT_resetpt,
32+
SIMLOADER_OT_resetins,
33+
SIMLOADER_OT_resetmesh,
34+
SIMLOADER_Import,
35+
SIMLOADER_List_Panel,
36+
SIMLOADER_UL_Obj_List,
37+
SIMLOADER_Settings,
38+
SIMLOADER_Templates,
39+
SIMLOADER_UL_Att_List,
40+
SIMLOADER_OT_set_as_split_norm,
41+
SIMLOADER_OT_remove_split_norm,
42+
SIMLOADER_OT_disable_selected,
43+
SIMLOADER_OT_enable_selected,
44+
SIMLOADER_OT_refresh_seq,
45+
]
46+
47+
48+
def register():
49+
bpy.app.handlers.load_post.append(SIMLOADER_initialize)
50+
for cls in classes:
51+
bpy.utils.register_class(cls)
52+
bpy.types.TEXT_MT_templates.append(draw_template)
53+
bpy.types.Scene.SIMLOADER = bpy.props.PointerProperty(type=SIMLOADER_scene_property)
54+
bpy.types.Object.SIMLOADER = bpy.props.PointerProperty(type=SIMLOADER_obj_property)
55+
bpy.types.Mesh.SIMLOADER = bpy.props.PointerProperty(type=SIMLOADER_mesh_property)
56+
57+
58+
# manually call this function once
59+
# so when addon being installed, it can run correctly
60+
# because scene is not used, so pass None into it
61+
SIMLOADER_initialize(None)
62+
63+
def unregister():
64+
for cls in classes:
65+
bpy.utils.unregister_class(cls)
66+
bpy.types.TEXT_MT_templates.remove(draw_template)
67+
del bpy.types.Scene.SIMLOADER
68+
del bpy.types.Object.SIMLOADER
69+
bpy.app.handlers.load_post.remove(SIMLOADER_initialize)
70+
unsubscribe_to_selected()
71+
72+
73+
if __name__ == "__main__":
74+
75+
# unregister()
76+
register()

additional_file_formats/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from .mzd import readMZD_to_bpymesh, readMZD_to_meshio
2+
from .bgeo import readbgeo_to_meshio
3+
4+
additional_format_loader = {'bgeo': readbgeo_to_meshio, 'mzd': readMZD_to_meshio}
5+
6+
__all__ = [
7+
readMZD_to_bpymesh, readMZD_to_meshio, readbgeo_to_meshio, additional_format_loader
8+
]

additional_file_formats/bgeo.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import gzip
2+
import numpy as np
3+
import meshio
4+
5+
6+
def readbgeo_to_meshio(filepath):
7+
with gzip.open(filepath, 'r') as file:
8+
byte = file.read(5)
9+
if byte != b"BgeoV":
10+
raise Exception('not bgeo file format')
11+
byte = file.read(4)
12+
version = int.from_bytes(byte, byteorder="big")
13+
if version != 5:
14+
raise Exception('bgeo file not version 5')
15+
16+
header = {}
17+
point_attributes = {}
18+
point_attributes_names = []
19+
point_attributes_sizes = []
20+
point_attributes_types = []
21+
position = None
22+
23+
byte = file.read(4)
24+
header['nPoints'] = int.from_bytes(byte, byteorder="big")
25+
26+
byte = file.read(4)
27+
header['nPrims'] = int.from_bytes(byte, byteorder="big")
28+
29+
byte = file.read(4)
30+
header['nPointGroups'] = int.from_bytes(byte, byteorder="big")
31+
32+
byte = file.read(4)
33+
header['nPrimGroups'] = int.from_bytes(byte, byteorder="big")
34+
35+
byte = file.read(4)
36+
header['nPointAttrib'] = int.from_bytes(byte, byteorder="big")
37+
38+
byte = file.read(4)
39+
header['nVertexAttrib'] = int.from_bytes(byte, byteorder="big")
40+
41+
byte = file.read(4)
42+
header['nPrimAttrib'] = int.from_bytes(byte, byteorder="big")
43+
44+
byte = file.read(4)
45+
header['nAttrib'] = int.from_bytes(byte, byteorder="big")
46+
47+
particle_size = 4
48+
49+
for _ in range(header['nPointAttrib']):
50+
byte = file.read(2)
51+
namelength = int.from_bytes(byte, byteorder="big")
52+
name_binary = file.read(namelength)
53+
name = name_binary.decode('utf-8')
54+
point_attributes_names.append(name)
55+
56+
byte = file.read(2)
57+
size = int.from_bytes(byte, byteorder="big")
58+
point_attributes_sizes.append(size)
59+
particle_size += size
60+
61+
byte = file.read(4)
62+
houdni_type = int.from_bytes(byte, byteorder="big")
63+
if houdni_type == 0:
64+
point_attributes_types.append('FLOAT')
65+
# read default value
66+
# not going to do anything about it
67+
byte = file.read(size * 4)
68+
elif houdni_type == 1:
69+
point_attributes_types.append('INT')
70+
# read default value
71+
# not going to do anything about it
72+
byte = file.read(size * 4)
73+
elif houdni_type == 5:
74+
point_attributes_types.append('VECTOR')
75+
# read default value
76+
# not going to do anything about it
77+
byte = file.read(size * 4)
78+
else:
79+
raise Exception('houdni_type unknown/ unsupported')
80+
byte = file.read(particle_size * header['nPoints'] * 4)
81+
# > means big endian
82+
attribute_data = np.frombuffer(byte, dtype='>f')
83+
attribute_data = np.reshape(attribute_data, (header['nPoints'], particle_size))
84+
# the first 3 column is its position data
85+
position = attribute_data[:, :3]
86+
# the 4th column is homogeneous coordiante, which is all 1, and will be ignored
87+
88+
current_attribute_start_point = 4
89+
for i in range(header['nPointAttrib']):
90+
if point_attributes_types[i] == 'FLOAT':
91+
point_attributes[point_attributes_names[i]] = attribute_data[:, current_attribute_start_point]
92+
current_attribute_start_point += 1
93+
elif point_attributes_types[i] == 'VECTOR':
94+
point_attributes[
95+
point_attributes_names[i]] = attribute_data[:,
96+
current_attribute_start_point:current_attribute_start_point + 3]
97+
current_attribute_start_point += 3
98+
elif point_attributes_types[i] == 'INT':
99+
data = (attribute_data[:, current_attribute_start_point]).tobytes()
100+
# > means big endian
101+
point_attributes[point_attributes_names[i]] = np.frombuffer(data, dtype='>i')
102+
current_attribute_start_point += 1
103+
remaining = file.read()
104+
if not remaining == b'\x00\xff':
105+
raise Exception("file didn't end")
106+
return meshio.Mesh(position, [('vertex', [])], point_data=point_attributes)
107+

0 commit comments

Comments
 (0)