Skip to content

Commit

Permalink
feat: preparation to add Unity->DCC Tools communication (#639)
Browse files Browse the repository at this point in the history
* Additional checks and handling for missing components or materials

* Exposing geometry nodes parameters in the Instance renderer inspector

* Using Utility function for destroying components to avoid branching

* using clamp instead of min of max

* Instances stored in a dictionary for more efficient lookup

* Removed toggle button for activating instance rendering from config, instance renderer is a private field of the server instead of a monobehavior, instance rendering is always active

* Adding a way to run blender from inside unity

* Updates to blender run modes.

* Moving sliders to mesh sync server

* prep

* Scene exporter uses the instance infos manager. msCore API adapted to use the instance infos in set messages. delete message support is WIP. Instance Renderer updated to listen to new events. Player Record class created for instance info, also WIP

* Updated how delete message is handled for instance infos

* Associating instances with entities instead of looking for gameobject in Scene

* WIP blender UI

* Support for receiving instances of meshes that are not part of the scene

* Skip sending only if there are no instances or instance meshes

* WIP property support

* Fix for instances not rendering on 2-window workflow

* Improved Fix for out of focus instance rendering

* Single camera support for Play mode

* Mutliple gameview camera support for Playmode

* WIP properties

* Support for multiple game views or multiple scene views rendering in edit mode

* Support for chaging camera mode from inspector. Instanting Rendering parameters are reflected from original gameobjects

* Support for moving/rotating/scaling instances when the referenced gameobject or a parent is moving/rotating/scaling

* Support for moving/rotating/scaling instances when the referenced gameobject or a parent is moving/rotating/scaling

* WIP properties

* Only redraw at the end of the set message sequence

* Support for light probe proxy volume

* Caching for instance world matrix recalculation

* Support for IL2CPP builds

* WIP properties

* Serialization support for instancing info

* Pin data to avoid issues with memory defragmentation

* Removed instance renderer clear from init

* Render to all cameras by default

* Fix for moveability error

* Try to reduce memory pressure at the end of a scene message

* Reverted manual garbage collection

* Changed c++ version to c++17

* Support to control geo node properties from unity.

* C++17 flag set for Apple

* Fix for race condition

* Avoid compilation errors when an unsupported build target is selected

* Fix for rendering issue when Undo/Redo is invoked

* Fix for compilation issues

* Implementing custom properties

* Fix: Support for instances of SkinnedMeshRenderer gameobjects

* Updated linux build instructions about using c++17 dev tools instead of c++14

* WIP perrmutation baker

* Fix: instance rendering handling for records without gameobject info

* Implemented copy and move ctors and assignment operators

* Avoid rendering instances while the scene is updating

* Geometry Nodes Support: Refactored how instanced meshes are exported, managed and sent. All instancing info is now sent in one frame. Removed need for reference type in geometry nodes

* Refactor: Remove Reference type from instance info. Simplified instance deletion code

* Refactor: simplified instance rendering by using the RenderPipelineManager.beginFrameRendering and Camera.OnPreCull events

* Instance Rendering: avoid rendering on the Preview Scene Camera on Built-in pipeline

* WIP variant export

* Refactor: Instance rendering and instance serialization. Each instanced gameobject has its own rendering component. The transform data are serialized in the gameobject

* Instance Rendering: Support for saving depending material and meshes in the Asset database when creating a prefab of an instance renderer

* wip baking

* Instance Rendering: changed layout of instance rendering components to match blender3d

* refactoring

* Instances: Improved the records and scene management for instance rendering components

* Instance Rendering: Allow instance rendering while scene is updating to avoid flickering

* merge fix

* Fix for render pipeline calllback

* Refactoring and fixes

* Instance Rendering: Use GraphicsSettings to check for the current rendering pipeline

* Instance Rendering: use root object as parent if parent is missing

* Instance Rendering: Fix for server poll delegate not unregistering from EditorApplication update. Hiding transforms from Inspector for avoiding GUI rendering performance issues

* Instance Rendering: Serialize inverse rendering info components to avoid issues with recompilation

* Serialization: Fixed Asset modified processor to handle all prefabs, not just instance rendering references

* Fixes and improvements for 2 way communication and baking

* Adding new exporter

* Instance Rendering: avoid rendering instanced on prefab scenes that do not contain the instanced gameobject

* Instance Rendering: Fixed unity runtime building errors. Better re-use of the transform/mesh entity update functions

* Fixes and refactoring for 2 way communication

* wip

* Fix for property request not timing out

* Refactoring and bug fixes

* Improved asset name sort

* Fix to save changed meshes for prefab variants

* More property support

* Property fixes

* Fix for running meshsync in background mode

* UI Improvements and fixes

* Documentation for geometry nodes [skip ci]

* geomentry node docs [skip ci]

* Update Geometry Nodes.md [skip ci]

* Added bakemodstups image

* Added instance light probes gif

* Updated GeometryNodes.md [skip ci]

* WIP curve support

* Use separate script to store blender properties

* Fixes for prefab export. Implemented different instance handling approaches.

* Cleanup

* Ensure visibility is updated from autosync.

* Fix for asset expoort and sharing assets between prefabs

* Fix for clashing property names. Refactoring

* Improved UI

* Adding curve support

* Curve fixes and multiple spline support.

* WIP curve refactor and mesh support.

* WIP mesh support.

* module dependency fixes

* Adding event to call before export.

* Limit regenerator to controller.
Fix for string properties.

* Added mesh support

* clean up

* fix for crash and refactor

* Adding dependencies

* Disable quads to make it faster

* Merge fixes

* Adding validation to ensure assets are blend files

* Removing not needed stuff

* Removing not needed stuff

* Cleanup

* Fix for serialization

* Removing unused setting

* Removing variant exporter

* Clean up

* Formatting fix

* Updating comment

* Removing not needed stuff.

* Updating compiled dll

* Adding mathematics package dependency.
Rebuilt dll for release.

* Updating protocol version.
Extracted string constant.

* Fix for prefab's asset dependency not being deleted.

* Refactoring

* Refactoring

* Renaming define

* Formatting revert

* Removing unused code

* Formatting revert

* Refactoring

* Adding spaces to fix macro string concatenation.

* Fix for dependencies and packages to work with unity 2019.

* Fix for windows only functionality

* Refactoring to draw ui for dcc tools in the meshsyncserver inspector.

* Using version compatible with unity 2019

* rebuilt dll

* Refactoring

* Fix for string concatenation

* Updating unit tests.

* Updated dlll

* Updated tests.

* Fix for latest splines package code changes.

* Reverting unwanted change

* revert

* Reverting not needed change

* Renaming method to be more clear what it does.

* Removing script that causes issues in the build pipeline.

* Compile fixes when building game.

* reverting changes

* Reverting changes

* Reverting changes

* Format revert

* Format fix

* Updating protocol version

* Fix for compiler errors on mac and linux

* Update linux so file
[skip ci]

* update Mac intel bundle
[skip ci]

* Update mscore mac Silicon bundle

* Deleting not needed code.

* Removing not needed code.

* Inverting if

* Refactoring

* Renaming field.

* Reducing included files.

* Fix for missing prefabs.
Renaming property request to match naming scheme of other requests of that kind.

* Removing dead code.

* Refactoring

* Refactoring

* Extracting methods.

* Adding TODO

* Removing commented out code

* Compile fix

* Encapsulating field.

* [skip ci] Adding documenation

* [skip ci] documenation updates

* Refactoring

* Removing unused code.

* Compile warning fix

* Renaming class

* Using map instead of vector.

* [skip ci] updating comment

* Extracting string constants

* Adding more vector type support.

* Adding tests to test undoing entity converters when sending data back.

* Renaming stuff to be more clear.

* Format fix

* Removing not needed code.

* Commenting code

* Refactoring probuilder editor code out to separate class.

* Renaming method to be more clear.

* Renaming message type

* Refactoring tests

* Using dispose method to clean up.

* Using hashset instead of list.

* Refactoring

* Using dictionary to store prefabs

* Making MeshSyncServerInspectorUtils internal

* Renaming to be more clear.

* Refactoring tests

* Extracting constants

* Updating comments

* Adding tests for array types.

* Format fix

* Increasing timeout

* Refactoring code to make it more complicated.

* Fix for null ref

* Adding vhash for bools.

* Renaming method to be more clear.

* update mac intel bundle
[skip ci]

* Update Linux so file

* Update mac silicon bundle

* Making method internal

* Changing access to internal

* Changing access to internal.

* Changing access to internal.

* Adding test

* Changing access to internal

Co-authored-by: Sean Dillon <[email protected]>
Co-authored-by: Sean Dillon <[email protected]>
Co-authored-by: Sin <[email protected]>
Co-authored-by: Sindharta Tanuwijaya <[email protected]>
  • Loading branch information
5 people authored Jul 13, 2022
1 parent ec38cb6 commit ec6b2c3
Show file tree
Hide file tree
Showing 73 changed files with 3,234 additions and 156 deletions.
54 changes: 54 additions & 0 deletions Documentation~/BidirectionalSupport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Unity <-> Blender Bidirectional support

This feature allows you to make changes in blender from inside Unity.

## Enabling bidirectional support
Turn on auto-sync in blender to enable bidirectional support.

## Custom properties and geometry node parameters
Unity displays blender object's custom properties and geometry node modifier values and allows changing them from inside Unity.
These properties are displayed in the inspector of a MeshSyncServerProperties MonoBehaviour below the MeshSyncServer.
The supported property types are:
* Integer
* Float
* Integer Array
* Float Array
* String (read-only)
This feature is intended to be used to easily change blender's procedural generation parameters from inside Unity.
Note: This feature requires blender version 3 or higher.

## Meshes
If ProBuilder is installed in the Unity project, the MeshSyncServer has an option to use ProBuilder Meshes.
These can be edited in Unity and are sent back to blender.
This feature is intended to be used to easily change geometry node mesh inputs from inside Unity.
Due to the way Unity represents the mesh, it is triangulated when it's sent back to blender and some mesh data like vertex groups and shape keys, etc. may get lost. If the option to bake modifiers was enabled in blender, a mesh that is sent from Unity back into blender will have those modifiers applied and removed.

## Splines
If the Unity Splines package version 2 is installed in the Unity project and "Curves as Mesh" is disbled in blender, the MeshSyncServer in Unity creates splines from blender curves. These can be edited in Unity and are sent back to blender.
This feature is intended to be used to easily change geometry node curve inputs from inside Unity.

## Instance handling
Instances of blender objects can be created in Unity in different ways, this is an option on the MeshSyncServer in Unity:
* Instance renderer
* Creates a MeshSync specific render component that batches the draw calls of each instance type. This is good for instances that do not need individual GameObjects.
* Copies
* Creates a GameObject for each instance. This is slower than the instance renderer but gives more control over each object.
* Prefabs
* Creates a prefab of the instanced object and places prefab instances in the scene. The prefab is saved in the 'Asset Dir' set on the MeshSyncServer. Using prefabs for instances allows you to make changes to the instanced object and add your own MonoBehaviours to it and apply that to all instances.
Note that prefabs are referenced by their blender name, if the name in blender changes, they are considered to be a new object and a new prefab is created.
Prefabs are not overwritten when their blender source object changes.
There is a "Clear prefabs" button to delete all prefabs for this server and regenerate them if blender is open and auto-sync is enabled.

## DCC Asset setting
The MeshSyncServer has a setting for an DCC asset file. This allows you to set a .blend file from the asset library, pressing 'Live Edit' beside it, opens the selected blender version and turns on MeshSync's Auto-Sync feature.
There are multiplee options for the Run mode:
* GUI
* Runs blender in normal window mode.
* Background
* Runs blender in headless mode without any window.
* Console
* Runs blender with the console window only.

## Tips
For some files to sync correctly, the Bake Modifiers option must be selected.
![Menu](images/BakeModsTip.png)
1 change: 1 addition & 0 deletions Documentation~/TableOfContents.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
* [Project Settings](ProjectSettings.md)
* [Preferences](Preferences.md)
* [Geometry Nodes](GeometryNodes.md)
* [Bidirectional support](BidirectionalSupport.md)
6 changes: 6 additions & 0 deletions Editor/DefaultAppUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal static class DefaultAppUtility
{
public static bool TryGetRegisteredApplication(string extension, out string registeredApp)
{
#if UNITY_EDITOR_WIN
string extensionId = GetClassesRootKeyDefaultValue(extension);
if (extensionId == null)
{
Expand All @@ -26,6 +27,11 @@ public static bool TryGetRegisteredApplication(string extension, out string regi
.Replace("\"", string.Empty)
.Trim();
return true;
#else
// Don't do this when not on windows:
registeredApp = null;
return false;
#endif
}

private static string GetClassesRootKeyDefaultValue(string keyPath)
Expand Down
11 changes: 8 additions & 3 deletions Editor/Scripts/BaseMeshSyncInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ protected static bool DrawAssetSyncSettings(BaseMeshSync t) {
guiFunc: () => EditorGUILayout.Toggle("Update Mesh Colliders", config.UpdateMeshColliders),
updateFunc: (bool toggle) => { config.UpdateMeshColliders = toggle; }
);

#if AT_USE_PROBUILDER
changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "MeshSync: Use Pro Builder",
guiFunc: () => EditorGUILayout.Toggle("Use Pro Builder", t.UseProBuilder),
updateFunc: (bool toggle) => { t.UseProBuilder = toggle; }
);
EditorGUI.indentLevel--;
#endif

changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "MeshSync: Sync Visibility",
guiFunc: () => EditorGUILayout.Toggle("Visibility", config.SyncVisibility),
Expand Down Expand Up @@ -257,8 +264,6 @@ protected static GUIStyle GetBoldFoldoutStyle() {
boldFoldoutStyle.fontStyle = FontStyle.Bold;
return boldFoldoutStyle;
}


}
}

} // end namespace
8 changes: 4 additions & 4 deletions Editor/Scripts/DCCIntegration/Launchers/BlenderLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using UnityEditor;
Expand Down Expand Up @@ -138,7 +138,7 @@ bool HandleBlenderPath(MeshSyncServer server)
if (!string.IsNullOrEmpty(newBlenderPath) && newBlenderPath != blenderPath)
{
SetBlenderPath(newBlenderPath);
OpenDCCTool(server.m_DCCAsset);
OpenDCCTool(server.DCCAsset);
}

changed = true;
Expand All @@ -159,7 +159,7 @@ void HandleRunMmode(MeshSyncServer server)
runMode = newRunMode;
if (m_blenderProcess != null)
{
OpenDCCTool(server.m_DCCAsset);
OpenDCCTool(server.DCCAsset);
}
}

Expand All @@ -174,7 +174,7 @@ void HandleRedirect(MeshSyncServer server)
redirectBlenderToUnityConsole = newRedirect;
if (m_blenderProcess != null)
{
OpenDCCTool(server.m_DCCAsset);
OpenDCCTool(server.DCCAsset);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Editor/Scripts/MeshSyncMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -53,7 +53,7 @@ static void LiveEditInBlender()
server = CreateMeshSyncServerMenu(null);
}

server.m_DCCAsset = selectedAsset;
server.DCCAsset = selectedAsset;

MeshSyncServerInspectorUtils.OpenDCCAsset(server);
}
Expand Down
54 changes: 45 additions & 9 deletions Editor/Scripts/MeshSyncServerInspector.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Unity.FilmInternalUtilities;
using System.Collections.Generic;
using Unity.FilmInternalUtilities.Editor;
using UnityEditor;
using UnityEngine;

namespace Unity.MeshSync.Editor {
[CustomEditor(typeof(MeshSyncServer))]
internal class MeshSyncServerInspector : BaseMeshSyncInspector {
[InitializeOnLoad]
internal class MeshSyncServerInspector : BaseMeshSyncInspector {

//----------------------------------------------------------------------------------------------------------------------

Expand All @@ -26,6 +26,7 @@ public override void OnInspectorGUI()
DrawMiscSettings(m_meshSyncServer);
DrawDefaultMaterialList(m_meshSyncServer);
DrawExportAssets(m_meshSyncServer);
DrawInstanceSettings(m_meshSyncServer);
DrawDCCToolInfo(m_meshSyncServer);
DrawPluginVersion();

Expand Down Expand Up @@ -86,23 +87,58 @@ public void DrawServerSettings(MeshSyncServer t)
}
}

private void DrawInstanceSettings(MeshSyncServer t)
{
var style = EditorStyles.foldout;
style.fontStyle = FontStyle.Bold;
t.foldInstanceSettings = EditorGUILayout.Foldout(t.foldInstanceSettings, "Instances", true, style);
if (t.foldInstanceSettings)
{
t.InstanceHandling = (BaseMeshSync.InstanceHandlingType)EditorGUILayout.EnumPopup("Instance handling", t.InstanceHandling);

DrawPrefabListElement(t);
}

EditorGUILayout.LabelField($"Instance count: {t.InstanceCount}");
}

static void DrawPrefabListElement(MeshSyncServer t)
{
if (t.prefabDict.Count > 0)
{
EditorGUILayout.LabelField("Instance prefabs:");

EditorGUI.indentLevel++;
foreach (var prefabHolder in t.prefabDict.Values)
{
EditorGUILayout.ObjectField(prefabHolder.name, prefabHolder.prefab, typeof(GameObject), true);
}
EditorGUI.indentLevel--;

if (GUILayout.Button("Clear prefabs"))
{
t.ClearInstancePrefabs();
}
}
}

static void DrawDCCToolInfo(MeshSyncServer server)
{
if (server != null)
{
GUILayout.BeginHorizontal();

var newAsset = EditorGUILayout.ObjectField("DCC asset file:",
server.m_DCCAsset,
server.DCCAsset,
typeof(UnityEngine.Object), true);

if (newAsset != server.m_DCCAsset)
if (newAsset != server.DCCAsset)
{
server.m_DCCAsset = newAsset;
server.m_DCCInterop = MeshSyncServerInspectorUtils.GetLauncherForAsset(server.m_DCCAsset);
server.DCCAsset = newAsset;
server.m_DCCInterop = MeshSyncServerInspectorUtils.GetLauncherForAsset(server.DCCAsset);
}

if (server.m_DCCAsset != null)
if (server.DCCAsset != null)
{
if (GUILayout.Button("Live Edit"))
{
Expand All @@ -116,7 +152,7 @@ static void DrawDCCToolInfo(MeshSyncServer server)

if (server.m_DCCInterop == null)
{
server.m_DCCInterop = MeshSyncServerInspectorUtils.GetLauncherForAsset(server.m_DCCAsset);
server.m_DCCInterop = MeshSyncServerInspectorUtils.GetLauncherForAsset(server.DCCAsset);
}

server.m_DCCInterop?.DrawDCCMenu(server);
Expand Down
Loading

0 comments on commit ec6b2c3

Please sign in to comment.