Skip to content

Commit

Permalink
Update technical doc
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Jul 17, 2022
1 parent 37b46a6 commit f4152d5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Documentation
| dev | https://docs.blender.org/manual/en/dev/addons/import_export/scene_gltf2.html |

Notes:
* 3.1 is the current stable release. Check the `blender-v3.1-release` branch.
* 2.80 - 3.0 are previous stable releases.
* 3.2 is the current stable release. Check the `blender-v3.2-release` branch.
* 2.80 - 3.1 are previous stable releases.
* 2.93 is the current Blender LTS release. Check the `blender-v2.93-release` branch.
* 3.2 will be the next release. Check the `blender-v3.2-release` branch.
* 3.3 will be the next release.
* master branch of this addon is mirrored in [Blender Addons master](https://developer.blender.org/diffusion/BA/browse/master/io_scene_gltf2/), that will become Blender 3.3.

### Legacy 2.79 Support
Expand Down Expand Up @@ -81,3 +81,8 @@ To run the tests locally, your system should have a `blender` executable in the
The latest version of [Yarn](https://yarnpkg.com/en/) should also be installed.

Then, in the `tests` folder of this repository, run `yarn install`, followed by `yarn run test`.

Some Technical documentation
----------------------------

Want to fix some bugs or add some enhancement? You will find some technical overview of this addon [here](Technical.md)
45 changes: 45 additions & 0 deletions Technical.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Technical overview

## Importer

Here are the main step of the importer:

- Reading and parsing file (See *__init__.py* and *gltf2_blender_gltf.py* files)
- Creating virtual tree and compute nodes (see *gltf2_blender_vnode.py* file)
- Then Blender objects are created, based on virtual tree nodes (see all *create* static methods of *blender/imp/gltf2_blender_* files)
- For animations, all gltf animations are created, but only the first one is then set as Blender active action.

### Adding a new material extension

If you want to add a new material extension, here are some steps you need to follow:

- Add the extension in list of managed extensions, in *extensions_managed* list of *glTFImporter* class
- If your extension need a node that is not Principled Shader node, add it, and correspondance links, in *make_output_nodes* function, in *gltf2_blender_pbrMetallicRoughness.py* file
- Add your newly created nodes for textures in *calc_locations* function, in order to have the nodes correcly displayed without overlapping
- Add you new function at end of *pbr_metallic_roughness* function. Create this function in a new file, on *blender/imp/* directory


## Exporter

Here are the main step of the exporter:

- A virtual node tree is created, then filtered (See *blender/exp/gltf2_blender_gather_tree.py* file)
- Based on this tree, nodes are exported, with some cache, avoiding calculating multiple time the same things
- At end of process, json tabs are created, replacing references to nodes by index in tabs (See multiple *traverse* functions)

### Adding a new material extension

- In *gltf2_blender_gather_materials.py/__gather_extensions*, add a function to manage your extension
- Create an *Extension* class to store your extension data.
- Third parameter is used to set the extension required
- If you need an extension at root of json, use ChildOfRootExtension instead
- If your texture is a simple mapping of channels:
- Add your channel mapping in *__get_image_data_mapping* function
- Example: *Clearcoat*
- If your texture needs a complex calculation:
- Add a check in *__get_image_data* function to call your specific function
- In your function, create an *ExportImage* class, setting a function as numpy calculation, calling the *set_calc* method
- In this function, store needed data for calculation, by using *store_data* method
- Create a new file in *blender/exp/*, storing your numpy calculation function. This function will use data stored in ExportImage class
- Example: *Specular*
- If your extension manages some texture, make sure to manage active UVMaps checks in *gltf2_blender_gather_materials.py/gather_material* function

0 comments on commit f4152d5

Please sign in to comment.