BEngine for Unity
BEngine for Unity is a tool which allows to generate meshes and instances procedurally. Setting up Geometry Nodes and putting a blend file into Unity, it allows us to create amazing generations for games.
Features:
BEFORE THE INSTALLATION, PLEASE MAKE SURE YOUR LOCAL HOST IS NOT BLOCKED BY YOUR FIREWALL. OPEN YOUR CONSOLE AND TEST THIS: ping 127.0.0.10
That’s it. BEngine is ready to go!
MACOS Blender Path: for MacOS you will need to specify a full Blender path. It will look like: /Applications/Blender.app/Contents/MacOS/Blender
https://docs.blender.org/manual/en/latest/advanced/command_line/launch/macos.html
!!!IMPORTANT!!! Exclude the BEngine Python Module folder from your project. In other case you can violate the GPL License of Blender.
Then Tweak UI Inputs and press the Run Nodes button.
You can use either Networking or run Blender instance every time. Networking is much faster and recommended.
Please check out this video presentation.
Please set up RunBlenderType parameter as Run Networking.
Run Blender server in the BEngine->RunBlenderServer.
That’s all! Now Networking is working when “Update Nodes” and “Run Nodes” buttons are pressed.
The only thing left is managing Timeout minutes. So that Unity will not work infinitely when Blender’s server has any bugs.
BEngine for Unity supports following Inputs:
To transfer Geometry Nodes UI into Unity, please check out UI_Example.blend file in the Examples:
Default value is supported by most inputs. For example, it's possible to set up a default value of MyInteger=5, MyFloat=0.5, MyString=”Hello World”.
Also, Float, Integer and Vector inputs support Min and Max values. It’s possible to clamp these values. For example, MyFloat value can have Min=0.5 and Max=3.5.
There are also some special inputs. Label, Separator, Tab, Foldout. To use these inputs just create String input and set names:
The default geometry input isn’t used. Instead “Object Info” and “Collection Info” nodes are used to get geometry. In Unity you can define some GameObjects as an Input.
Normals are exported automatically for every mesh from Blender to Unity and there is no need to do any additional steps. But if you want to have custom normals then you can use the “be_normal” facecorner attribute for this.
Custom Normals:
Name: be_normal
Domain: FaceCorner
Type: Vector
To add some UVs just add uv_map, uv_map2, uv_map3 … uv_map8 attribute, FaceCorner domain. Unity supports up to 8 UV sets.
Name: uv_map, uv_map2, uv_map3 … uv_map8
Domain: FaceCorner
Type: Vector2, Vector
To add Vertex Colors to a mesh just simply add be_color attribute, FaceCorner domain.
Name: be_color
Domain: FaceCorner
Type: Color(Vector4)
Video Explanation of Materials
To set up Unity materials simply add a be_material attribute to faces in Geometry Nodes. A type of the material attribute should be Integer. That means an Index of a Unity material will be set.
Name: be_material
Domain: Face
Type: Integer
Video Explanation of Instances
Instances can be created with be_instance attribute. But the attribute domain can be any. But it’s better using the Face domain.
Name: be_instance
Domain: Any
Type: Integer
BEngine supports custom attributes which can be passed into C# ParseCustomMeshAttribs(), ParseCustomObjectAttribs(), EndCustomAttribs() functions.
Supported Types:
Float: Float, Boolean, Integer
Vector: Vector2D, Vector3D
Color: Color, ByteColor
Supported Domains:
Point, Edges, Face, FaceCorner
1 Create a C# Script.
2 Add this code. Extend the BEngineComponent and override functions below.
using UnityEngine;
using UnityEngine;
using BEngine;
using BESimpleJSON;
public class MyBEngineComponent : BEngineComponent
{
#if UNITY_EDITOR
public override Mesh ParseCustomMeshAttribs(Mesh mesh, JSONNode CustomAttribs)
{
// Your Code. It works per Generated Mesh.
UnityEngine.Debug.Log(CustomAttribs);
return mesh;
}
public override void ParseCustomObjectAttribs(GameObject gameObj, JSONNode CustomAttribs)
{
// Your Code. It works per Generated Object.
UnityEngine.Debug.Log(CustomAttribs);
}
public override void EndCustomAttribs()
{
// Your Code. It works at the end of all generated objects.
// Clear/Clean your variables.
}
#endif
}
3 Assign your custom script to an Object.
Use bem_* attribute names to create custom mesh attributes. They will be passed in the ParseCustomMeshAttribs() function.
Use beo_* attribute names to create custom object attributes. They will be passed in the ParseCustomObjectAttribs() function.
It’s possible to sample Unity Terrain to convert it to a mesh. Just create an empty GameObject and add a BEngineTerrain component. Then put this GameObject to a BEngine mesh input.
Add BEngineCurveComponent to a GameObject.
Shift+N - New Curve
Shift+A - Add a point (Select 1 or 2 points)
Shift+S - Select Points
Shift+X - Delete Selected Points
“Closed/Open” can switch a type of a curve.
Tilt is supported.
BEngine supports Sverchok Node System. Sverchok is a very amazing node system. If you want to add your own Python nodes or any Python/C++ library then this node system is for you.
Proper Installation.
It’s recommended to have these modules to be installed so that more Sverchok nodes to be available. But this is optional.
Please, download BEngine Python Module and get scripts for Sverchok. https://github.com/mifth/BEngine-Python-Module/tree/main/Sverchok/ScriptNodeLite/BEngineInOut
These scripts can be loaded in Blender with a Text Editor or can be placed into “addons\sverchok\node_scripts\SNLite_templates”.
Variant 1. Through Text Editor:
Variant 2. Or add Files to Sverchok:
After adding BEngine nodes for Sverchok you need to add a Script Node Lite node.
Input and output nodes look like this.
Inputs:
Outputs:
Please, try Examples for BEngine.
Sometimes you would probably like to save a mesh to use it in different scenes.