Java .Blend Viewer
Demo Application and Examples for Java .Blend
This is a collection of examples to demonstrate the use of Java .Blend.
gen: Generated Java .Blend DNA lib for Blender v2.79 files.
src: Source code of the viewer application.
jb-examples: Some examples showing reading and writing of .blend files.
resources: Blender files and glsl shaders required by the demo application.
Import in Eclipse
- Extract downloaded zip-file
- In Eclipse create a new Java project and select the extracted directory as Location
- Click on Finish
Java .Blend Viewer
The application reads a given Blender file and displays it. It will start in a Debug View, which shows normals and camera orientation as well as key-bindings (use F1-key to see regular view).
DISCLAIMER: This application and the underlying render engine are WORK IN PROGRESS. Currently, its purpose is to demonstrate how to access data in .blend files through Java .Blend. Its purpose is not to explain rendering of that data in OpenGL.
The application is based on LWJGL, JOML and contains an object-oriented abstraction layer (packages
The most important part of the application is found in package
src/org.cakelab.blender.io. There is a class
BlenderInput, which offers all kinds of methods to retrieve data from an associated blender file using the generated DNA classes for a specific render engine of course. BlenderInput uses a converter class
ConvertBlender2OpenGL located in the same package. It converts data of the .blend file in internal representations used by the underlying render engine in
.blend to JSON
This example demonstrates how to implement a class which converts the whole Blender file into a JSON representation. The example makes use of the java reflection API to perform its task on top of the generated data model. This approach was just used to further demonstrate the use of the data model.
The conversion allows to easily visualise the content of a Blender file which helps in understanding the meaning of member variables of classes in the generated data model.
Example: Exchanging Data with Blender via Copybuffer
Blender provides a clipboard functionality of its own kind. On
CTRL+C Blender copies selected objects into a temporary .blend file which is stored in
/tmp/copybuffer.blend (I guess it's
%APPDATA%/.. on windows). Accordingly, on
CTRL+V the content of this file is pasted in the currently selected scene.
The example code in
ExampleCopybufferExchange.java demonstrates how to fill the copybuffer with a mesh (simple cube with texture).
Example: Creating new Blocks
The factory class of the generated data model (see gen/org/cakelab/blender/utils/BlenderFactory.java) provides several methods to create new blocks for structs, arrays and pointers. This example provides multiple examples to demonstrate the use of those methods.
This work is published under GPL v3.0.
This work includes a copy of LWJGL 3 which is licensed under "a BSD license".
This work includes a copy of JOML which is published under an "MIT license".