Java .Blend Viewer
Demo Application and Examples for Java .Blend
This is a collection of examples to demonstrate the use of Java .Blend.
src: Source code of the viewer application.
jb-examples: Some examples demonstrating reading and writing of .blend files.
examples: Example blender files to be displayed by the viewer.
src-dna: Source code of Java .Blend DNA API for Blender v2.83.18 files.
src-io: Source code of the blender I/O utils required by DNA API.
src-soapbox: Source code of a simple render engine (beta).
resources: GLSL shader programs used by soapbox.
src-appbase: Source code of utilities used by soapbox.
src-json: Source code of a JSON API.
lib: Libraries (JAR) of LWJGL and JOML.
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 is meant for demonstration purposes only!
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".