GithubHelp home page GithubHelp logo

yuki-koyama / blender-cli-rendering Goto Github PK

View Code? Open in Web Editor NEW
737.0 21.0 107.0 207.37 MB

Blender Python scripts for rendering images directly from command-line interface

License: GNU General Public License v3.0

Python 97.95% Shell 2.05%
blender python rendering cycles

blender-cli-rendering's Introduction

blender-cli-rendering

GitHub Blender

A set of Blender Python scripts for generating scenes and rendering images directly from command-line interface.

Principles

  • Able to run without display (thus, the renderer should be Cycles instead of EEVEE)
  • Support the latest LTS release (currently 2.93)

Possible Usages

  • Material to learn how to use Blender Python APIs.
  • Visualization of 3D data with fancy rendering quality.
  • Generation of synthetic training datasets for machine learning-based computer vision.

Scripts

01_cube.py

  • Cycles renderer

01_cube

02_suzanne.py

  • Directional light
  • Algorithmic object placement
  • Subdivision surfaces
  • TRACK_TO constraint to achieve camera's look-at behavior
  • Depth of field
  • Smooth shading

02_suzanne

03_ibl.py

  • Node-tree
  • Image-based lighting using an HDR image

03_ibl

04_principled_bsdf.py

  • Principled BSDF
  • Denoising
  • Empty object as a target

04_principled_bsdf

05_composition.py

  • Composition nodes
  • Node group

05_composition

06_split_tone.py

  • Split tone effect
  • Checker board texture

06_split_tone

07_texturing.py

  • Image texture

07_texturing

08_animation.py

  • Keyframing
  • Motion blur

08_animation

09_armature.py

  • Skeletal animation
  • Skinning

09_armature

10_mocap.py

  • Mesh creation from Python data
  • BVH data import
  • Texture tiling
  • Camera following

10_mocap

11_mesh_visualization.py

  • Wireframe
  • Vertex colors
  • Transparent background

11_mesh_visualization

12_cloth.py

  • Cloth modifier
  • Collision modifier
  • Area light

12_cloth

13_matcap.py

  • MatCap (a.k.a. Lit Sphere)
  • Image filtering (e.g., sharpen)
  • Simple RGB background
  • Node frame

13_matcap

14_procedural_texturing.py

  • Noise texture

14_procedural_texturing

License

GNU General Public License v3.0 (GPL-3.0). We have chosen this license because we respect the philosophy of free software.

blender-cli-rendering's People

Contributors

bsridatta avatar cgcooke avatar yuki-koyama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blender-cli-rendering's Issues

Fix cycles utils

The current utils.set_cycles_renderer takes non-cycles parameters as inputs, which is not very meaningful. This should be fixed.

[Question] Transparent background

11_mesh_vizualization.py has the feature transparent background but the rendered image isn't transparent, even after changing the format to PNG to support alpha channel. When running the code with UI, I see that it does get the transparent background when I change the view of the rendering to View Layer -> combined. But the image being saved is using the Composite option instead of view layer. Is there anyway to enable saving the combined view layer? or any workaround. Thank you very much!

image

Error when using cc0assetloader.

Hi, script number 7 (as well as 8,9,10 and 12) fail with this error:

Blender 2.80 (sub 75)
Traceback (most recent call last):
  File "/home/david/coding/blender-cli-rendering/./07_texturing.py", line 66, in <module>
    focus_target = set_scene_objects()
  File "/home/david/coding/blender-cli-rendering/./07_texturing.py", line 14, in set_scene_objects
    loader.build_pbr_textured_nodes_from_name("Leather05")
  File "/home/david/coding/blender-cli-rendering/external/cc0assetsloader/__init__.py", line 144, in build_pbr_textured_nodes_from_name
    scale=scale)
  File "/home/david/coding/blender-cli-rendering/external/cc0assetsloader/__init__.py", line 124, in build_pbr_textured_nodes
    nodelayout.arrange_nodes(node_tree, use_current_layout_as_initial_guess=False)
AttributeError: module 'nodelayout' has no attribute 'arrange_nodes'

Do I need to install something to make it work?

Windows support

Thanks for great examples of how to render using Blender from the terminal.
I tried this on Windows 10 and it failed with path errors:

PS C:\Users\chuong\Documents\blender-cli-rendering> & "C:\Program Files\Blender Foundation\Blender 2.91\blender.exe" --background --python .\07_texturing.py --render-frame 1 -- ./07_texturing.png 100 4
Blender 2.91.0 (hash 0f45cab862b8 built 2020-11-25 09:02:56)
Read prefs: C:\Users\ngu10t\AppData\Roaming\Blender Foundation\Blender\2.91\config\userpref.blend
found bundled python: C:\Program Files\Blender Foundation\Blender 2.91\2.91\python
C:\Users\chuong\Documents\blender-cli-rendering
Error: Cannot read './assets/cc0textures.com/[2K]Leather05/Leather05_col.jpg': No such file or directory
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\chuong\Documents\blender-cli-rendering\.\07_texturing.py", line 115, in <module>
    focus_target = set_scene_objects()
  File "C:\Users\chuong\Documents\blender-cli-rendering\.\07_texturing.py", line 63, in set_scene_objects
    add_named_material("Leather05")
  File "C:\Users\chuong\Documents\blender-cli-rendering\.\07_texturing.py", line 58, in add_named_material
    displacement_scale=displacement_scale)
  File "C:\Users\chuong\Documents\blender-cli-rendering\utils\material.py", line 147, in build_pbr_textured_nodes
    texture_node = create_texture_node(node_tree, color_texture_path, True)
  File "C:\Users\chuong\Documents\blender-cli-rendering\utils\material.py", line 11, in create_texture_node
    texture_node.image = bpy.data.images.load(path)
RuntimeError: Error: Cannot read './assets/cc0textures.com/[2K]Leather05/Leather05_col.jpg': No such file or directory

Error: Cannot render, no camera
Fra:0 Mem:7.48M (Peak 7.54M) | Time:00:00.00 | Sce:  Ve:0 Fa:0 La:0

Blender quit

I suspect there are 2 problems: 1) Windows is not happy with "...[2K]..." in the paths, 2) the relative path is not used correctly.

TODO: FreeStyle Utilities

I'm interested in using FreeStyle for NPR and visualization. I hope I can add FreeStyle API utilities to this repository soon.

Remove support of 2.79

I guess I no longer use 2.79 even in headless environments. I think it's time to remove support of 2.79 for easier code maintenance.

Toon shading

One of the next target features may be toon shading; especially I want to reproduce cell-look shading used in Japanese anime.

Remove CC0AssetsLoader from dependency?

CC0AssetsLoader, which is currently included as a git submodule, has some large-size assets. This means that every time cloning this repository requires a huge download. Also, CC0AssetsLoader implicitly uses Git LFS, which may confuse some users.

Use as a package/module

utils.py now contains many general-purpose utility functions that may be useful in other script/plug-in development. It would be nice if they are provided as a python package or module.

Copyright Licence

In your readme, you consider that this package is a “derivative work” of Blender, so therefore has to be subject to the same licence. Certainly the Blender Foundation also seems to think the same of users of its APIs, but I should point out that this goes against just about every discussion of the subject in other open-source projects.

For the best-known example, you may have heard of the Oracle vs Google case. The US Supreme Court verdict on that made it quite clear that Oracle could not stop Google from using the Java APIs (even if it actually dodged the question of copyrightability of APIs).

For another example, the Linux kernel docs explicitly say that userland code can make use of APIs that interface to the kernel without implications for their licensing. (Kernel modules, on the other hand, are considered “derivative works”.)

The basic point is that compatibility with APIs is essential for providing basic purely technical functionality, and so cannot be restricted by copyright for that reason.

I’m not asking you to change the licensing of your project, merely pointing out that it is not as constrained--should not be as constrained!--as you might think.

weird mocap rendering result

Hi, thanks for sharing this codebase! I'm trying your mocap script (10_mocap.py) by following this command:

blender --background --python ./10_mocap.py ${ANIM_FRAMES_OPTION} -- ./assets/motion/102_01.bvh ${OUT_DIR}/10/frame_ ${RESOLUTION} ${SAMPLINGS}

Yet the results I got seems pretty weird,
frame_0001

I'm rather new to blender and cannot quite debug it on my end. I imagine it might be caused by wrong ambient value of the scene. What is your idea?

Use absolute paths

The current scripts implicitly assume that they are called from the top directory of this repository. Instead, it should use the following code to obtain the absolute path of the directory:

os.path.dirname(os.path.abspath(__file__))

Doesn't work on recent Blender (4.0) API

Hi, thanks for sharing these scripts! I am a complete newbie to Blender and I really appreciate them.

I tried those scripts with the new Blender 4.0 and it seems this version introduced some major changes in the API which broke them.

Error: Python: Traceback (most recent call last):
  File "/test/blender-cli-rendering/10_mocap.py", line 137, in <module>
    utils.build_scene_composition(scene)
  File "/test/blender-cli-rendering/utils/composition.py", line 184, in build_scene_composition
    vignette_node = create_vignette_node(scene.node_tree)
  File "/test/blender-cli-rendering/utils/composition.py", line 165, in create_vignette_node
    vignette_node_group = add_vignette_node_group()
  File "/test/blender-cli-rendering/utils/composition.py", line 118, in add_vignette_node_group
    group.inputs.new("NodeSocketColor", "Image")
AttributeError: 'CompositorNodeTree' object has no attribute 'inputs'
Error: Cannot render, no camera

Would it be possible to have a version compatible with Blender 4.0?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.