Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance rendering support #540

Closed
wants to merge 94 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
7f7111a
Instance rendering support
Feb 7, 2022
97058f2
Support for multiple materials
Feb 8, 2022
917e5d5
Merge remote-tracking branch 'origin' into instance-rendering-support
Feb 8, 2022
3033302
Additional checks and handling for missing components or materials
Feb 8, 2022
4fd523c
Using Utility function for destroying components to avoid branching
Feb 10, 2022
efbee5c
using clamp instead of min of max
Feb 10, 2022
5707585
Instances stored in a dictionary for more efficient lookup
Feb 10, 2022
1329b6e
Removed toggle button for activating instance rendering from config, …
Feb 10, 2022
0c573c0
Scene exporter uses the instance infos manager. msCore API adapted to…
Feb 18, 2022
97c9253
Updated how delete message is handled for instance infos
Feb 21, 2022
5bdaf01
Associating instances with entities instead of looking for gameobject…
Feb 22, 2022
f67cac1
Support for receiving instances of meshes that are not part of the scene
Mar 1, 2022
fcab4a9
Skip sending only if there are no instances or instance meshes
Mar 2, 2022
719e363
Fix for instances not rendering on 2-window workflow
Mar 3, 2022
069ecaa
Improved Fix for out of focus instance rendering
Mar 3, 2022
6f3f486
Single camera support for Play mode
Mar 3, 2022
538e766
Mutliple gameview camera support for Playmode
Mar 4, 2022
154721b
Support for multiple game views or multiple scene views rendering in …
Mar 4, 2022
0de16a6
Support for chaging camera mode from inspector. Instanting Rendering …
Mar 4, 2022
4c579a6
Support for moving/rotating/scaling instances when the referenced gam…
Mar 4, 2022
2dc3787
Support for moving/rotating/scaling instances when the referenced gam…
Mar 4, 2022
91c7328
Only redraw at the end of the set message sequence
Mar 4, 2022
dffa424
Support for light probe proxy volume
Mar 7, 2022
28a340a
Caching for instance world matrix recalculation
Mar 7, 2022
dc44868
Support for IL2CPP builds
Mar 8, 2022
165ec75
Serialization support for instancing info
Mar 8, 2022
b8a4db9
Pin data to avoid issues with memory defragmentation
Mar 8, 2022
8707dff
Removed instance renderer clear from init
Mar 8, 2022
f1cea68
Render to all cameras by default
Mar 8, 2022
e675749
Fix for moveability error
Mar 9, 2022
6c6d45a
Try to reduce memory pressure at the end of a scene message
Mar 9, 2022
699d314
Reverted manual garbage collection
Mar 10, 2022
fbcc728
Changed c++ version to c++17
Mar 10, 2022
80992f1
C++17 flag set for Apple
Mar 10, 2022
e4ab85f
Avoid compilation errors when an unsupported build target is selected
Mar 11, 2022
37edab1
Handled merge conflicts with develop
Mar 14, 2022
72f6131
Fix for rendering issue when Undo/Redo is invoked
Mar 14, 2022
1a4ffc5
Fix for compilation issues
Mar 14, 2022
a274c7f
Handled merge conflicts with develop
Mar 14, 2022
a90bb07
Merge https://github.com/unity3d-jp/MeshSync into instance-rendering-…
Mar 15, 2022
318fc41
Handled merge conflicts
Mar 15, 2022
1b81c34
Fix: Support for instances of SkinnedMeshRenderer gameobjects
Mar 15, 2022
6eb04ee
Updated linux build instructions about using c++17 dev tools instead …
Mar 16, 2022
42d52af
Fix: instance rendering handling for records without gameobject info
Mar 16, 2022
b5e437d
Implemented copy and move ctors and assignment operators
Mar 16, 2022
835a060
Avoid rendering instances while the scene is updating
Mar 16, 2022
4e8259e
Geometry Nodes Support: Refactored how instanced meshes are exported,…
Mar 22, 2022
be2169d
Refactor: Remove Reference type from instance info. Simplified instan…
Mar 23, 2022
83937e6
Refactor: simplified instance rendering by using the RenderPipelineMa…
Mar 23, 2022
3639dbe
Instance Rendering: avoid rendering on the Preview Scene Camera on Bu…
Mar 23, 2022
e7e3ce1
Handled merge conflicts with dev
Mar 23, 2022
890450e
Refactor: Instance rendering and instance serialization. Each instanc…
Mar 24, 2022
1cf0cfc
Instance Rendering: Support for saving depending material and meshes …
Mar 24, 2022
29446ad
Instance Rendering: changed layout of instance rendering components t…
Mar 25, 2022
83fbf2d
Instances: Improved the records and scene management for instance ren…
Mar 25, 2022
3e8a212
Instance Rendering: Allow instance rendering while scene is updating …
Mar 25, 2022
9dcdb63
Instance Rendering: Use GraphicsSettings to check for the current ren…
Mar 28, 2022
1e8b371
Instance Rendering: use root object as parent if parent is missing
Mar 30, 2022
123638b
Instance Rendering: Fix for server poll delegate not unregistering fr…
Mar 30, 2022
7d25b63
Instance Rendering: Serialize inverse rendering info components to av…
Mar 30, 2022
65e1cf4
Serialization: Fixed Asset modified processor to handle all prefabs, …
Mar 31, 2022
7141b85
Instance Rendering: avoid rendering instanced on prefab scenes that d…
Apr 1, 2022
860078b
Instance Rendering: Fixed unity runtime building errors. Better re-us…
Apr 1, 2022
cd53c6b
Merge remote-tracking branch 'origin' into instance-rendering-support
Apr 4, 2022
2d2b551
Instance rendering: use type instead of name for filtering out previe…
Apr 5, 2022
4f5f491
Instance rendering: removed asset processor script
Apr 6, 2022
eb91956
Instance Rendering: remove empty line change
Apr 6, 2022
44cfc60
Instance Rendering: removed dead code
Apr 6, 2022
bdcaab0
Instance Rendering: fixed compilation errors for runtime build
Apr 6, 2022
88978e2
Merge remote-tracking branch 'origin' into instance-rendering-support
Apr 6, 2022
abd2f19
Instance Rendering: removed dead code
Apr 7, 2022
f310a59
Instance rendering: drawing loop inverted for early exits
Apr 7, 2022
e96fd1b
Handled merge conflicts with develop
Apr 7, 2022
86623c2
Instance Rendering: fix error: handler removed
Apr 7, 2022
06d6b51
Instance Rendering: made fields private, removed duplicate code
Apr 7, 2022
42a7b23
Instance rendering: coding convention improvements
Apr 7, 2022
106dcf3
Instance Rendering: more styling changes
Apr 7, 2022
e4c3c7f
Instance Rendering: more styling changes
Apr 7, 2022
70a8105
Instance rendering: Replaced Instances Dictionary with Serialization …
Apr 7, 2022
80ba01c
Instance rendering: deduplicated common code when erasing instance re…
Apr 7, 2022
92c582a
Instance rendering: reverting fix for server issue
Apr 7, 2022
4698a9f
Instance Rendering: styling fix
Apr 7, 2022
488678d
Instance Rendering: more styling updates
Apr 7, 2022
9dfee71
Instance rendering: style changes
Apr 7, 2022
8dfc9d9
Instance rendering: style changes
Apr 7, 2022
694b619
Instance rendering: styling update
Apr 7, 2022
82ebfee
Instance rendering: styling update
Apr 7, 2022
b80bd5b
Instance Rendering: styling updates
Apr 7, 2022
c323304
Instance Rendering: styling updates
Apr 7, 2022
de98e60
Instance Rendering: styling updates
Apr 7, 2022
111a03b
Instance Rendering: adding mscore.dll
Apr 7, 2022
2a28917
Instance Rendering: Ubuntu build of mscore.so
Apr 8, 2022
06a3d23
Instance rendering: mscore for macOS
Apr 8, 2022
c7f22df
Instance Rendering: updated mscore.dll
Apr 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class Contents {

public static readonly GUIContent Visibility = EditorGUIUtility.TrTextContent("Visibility");
public static readonly GUIContent UpdateTransform = EditorGUIUtility.TrTextContent("Update Transform");
public static readonly GUIContent RenderInstances = EditorGUIUtility.TrTextContent("Render Instances");
seandillon92 marked this conversation as resolved.
Show resolved Hide resolved

public static readonly GUIContent[] ComponentSyncs = new [] {
EditorGUIUtility.TrTextContent("Camera"),
Expand Down Expand Up @@ -112,7 +113,7 @@ internal void Setup(VisualElement parent) {
AddPlayerConfigField<Toggle,bool>(syncSettingsFoldout, Contents.Visibility, config.SyncVisibility,
(bool newValue) => { config.SyncVisibility = newValue; }
);

//import
Foldout importSettingsFoldout = containerInstance.Query<Foldout>("ImportSettingsFoldout").First();
ModelImporterSettings modelImporterSettings = config.GetModelImporterSettings();
Expand Down
6 changes: 5 additions & 1 deletion Plugin~/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ endif()
# Custom scripts
include(AddPlugin)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
elseif(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
endif()

# Force Unicode character set
add_definitions(-DUNICODE -D_UNICODE)
Expand Down
2 changes: 1 addition & 1 deletion Plugin~/Docs/en/BuildPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ $ xcodebuild -scheme mscore -configuration Release build

### Prerequisites (Linux)

1. Make sure C++14 development is supported, and define `CC` and `CXX` environment variables to point to C++14 dev tools.
1. Make sure C++17 development is supported, and define `CC` and `CXX` environment variables to point to C++17 dev tools.
For example, by installing [devtoolset-7](https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/) in in CentOS 7,
and then defining `CC` and `CXX` environment variables as follows:
```
Expand Down
40 changes: 38 additions & 2 deletions Plugin~/Src/MeshSync/AsyncSceneSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,23 @@ void AsyncSceneSender::send()

if (assets.empty() && textures.empty() && materials.empty() &&
transforms.empty() && geometries.empty() && animations.empty() &&
deleted_entities.empty() && deleted_materials.empty())
instanceInfos.empty() && instanceMeshes.empty() &&
deleted_entities.empty() && deleted_materials.empty() &&
deleted_instances.empty())
return;

SetupDataFlags(transforms);
SetupDataFlags(geometries);
SetupDataFlags(instanceMeshes);

AssignIDs(transforms, id_table);
AssignIDs(geometries, id_table);
AssignIDs(instanceMeshes, id_table);

// sort by order. not id.
std::sort(transforms.begin(), transforms.end(), [](auto& a, auto& b) { return a->order < b->order; });
std::sort(geometries.begin(), geometries.end(), [](auto& a, auto& b) { return a->order < b->order; });
std::sort(instanceMeshes.begin(), instanceMeshes.end(), [](auto& a, auto& b) { return a->order < b->order; });

auto append = [](auto& dst, auto& src) { dst.insert(dst.end(), src.begin(), src.end()); };

Expand Down Expand Up @@ -154,6 +161,30 @@ void AsyncSceneSender::send()
};
}

//instance meshes
if (!instanceMeshes.empty()) {
for (auto& mesh : instanceMeshes) {
ms::SetMessage mes;
setup_message(mes);
mes.scene->settings = scene_settings;
mes.scene->instanceMeshes = { mesh };
succeeded = succeeded && client.send(mes);
if (!succeeded)
goto cleanup;
}
}

// instance infos
if (!instanceInfos.empty()) {
ms::SetMessage mes;
setup_message(mes);
mes.scene->settings = scene_settings;
mes.scene->instanceInfos = instanceInfos;
succeeded = succeeded && client.send(mes);
if (!succeeded)
goto cleanup;
}

// animations
if (!animations.empty()) {
ms::SetMessage mes;
Expand All @@ -166,11 +197,16 @@ void AsyncSceneSender::send()
}

// deleted
if (!deleted_entities.empty() || !deleted_materials.empty()) {
if (!deleted_entities.empty() ||
!deleted_materials.empty() ||
!deleted_instances.empty()) {

ms::DeleteMessage mes;
setup_message(mes);
mes.entities = deleted_entities;
mes.materials = deleted_materials;
mes.instances = deleted_instances;

succeeded = succeeded && client.send(mes);
if (!succeeded)
goto cleanup;
Expand Down
5 changes: 5 additions & 0 deletions Plugin~/Src/MeshSync/Include/MeshSync/SceneExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "MeshSync/msIDGenerator.h" //PathToID
#include "MeshSync/SceneGraph/msScene.h" //AssetPtr

msDeclClassPtr(InstanceInfo)

namespace ms {

class SceneExporter
Expand All @@ -18,9 +20,12 @@ class SceneExporter
std::vector<TransformPtr> transforms;
std::vector<TransformPtr> geometries;
std::vector<AnimationClipPtr> animations;
std::vector<InstanceInfoPtr> instanceInfos;
std::vector<TransformPtr> instanceMeshes;

std::vector<Identifier> deleted_entities;
std::vector<Identifier> deleted_materials;
std::vector<Identifier> deleted_instances;

std::function<void()> on_prepare, on_success, on_error, on_complete;
PathToID id_table;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#pragma once

#include "MeshSync/MeshSync.h"
#include "MeshSync/SceneGraph/msEntity.h"
#include "MeshSync/SceneGraph/msTransform.h"
#include "MeshSync/SceneGraph/msCamera.h"
#include "MeshSync/SceneGraph/msLight.h"
#include "MeshSync/SceneGraph/msMesh.h"
#include "MeshSync/SceneGraph/msPoints.h"
#include "MeshSync/SceneGraph/msAnimation.h"

msDeclClassPtr(AnimationClip)

namespace ms {

class Entity;
class Transform;
class Camera;
class Light;
class Mesh;
class Points;
class Animation;
class AnimationCurve;

class EntityConverter
{
public:
Expand Down
49 changes: 49 additions & 0 deletions Plugin~/Src/MeshSync/Include/MeshSync/SceneGraph/msInstanceInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once
#include "MeshUtils/muMath.h"
#include "MeshSync/msFoundation.h"
#include "MeshSync/SceneGraph/msIdentifier.h"
#include "MeshSync/SceneGraph/msMesh.h"

namespace ms {
using namespace std;
using namespace mu;
class InstanceInfo
{
uint64_t m_hash = 0;
seandillon92 marked this conversation as resolved.
Show resolved Hide resolved

public:

/// <summary>
/// /// Path on the hierachy tree to the mesh that the instances refer to.
/// /// </summary>
string path;

string parent_path;

/// <summary>
/// World transforms of the instances
/// </summary>
SharedVector<float4x4> transforms;

void serialize(ostream& os);
void deserialize(istream& is);

InstanceInfo();
InstanceInfo(const InstanceInfo& v);
InstanceInfo& operator=(const InstanceInfo& v);
InstanceInfo(InstanceInfo&& v) noexcept; // noexcept to enforce std::vector to use move constructor
InstanceInfo& operator=(InstanceInfo&& v);

msDefinePool(InstanceInfo);

void clear();

static shared_ptr<InstanceInfo> create(std::istream& is);
uint64_t hash();

Identifier getIdentifier();

};
msSerializable(InstanceInfo)
}

12 changes: 12 additions & 0 deletions Plugin~/Src/MeshSync/Include/MeshSync/SceneGraph/msScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
//Used in template
#include "MeshSync/SceneGraph/msTransform.h"

#include "MeshSync/SceneGraph/msInstanceInfo.h"

//Forward declarations
msDeclClassPtr(Asset);
msDeclClassPtr(Constraint);
msDeclClassPtr(Scene);

msDeclStructPtr(SceneImportSettings);
msDeclStructPtr(InstanceInfo)
msDeclClassPtr(EntityConverter)

namespace ms {

Expand All @@ -38,6 +42,8 @@ struct SceneDataFlags
uint32_t has_assets : 1;
uint32_t has_entities : 1;
uint32_t has_constraints : 1;
uint32_t has_instanceInfos : 1;
uint32_t has_instanceMeshes : 1;

SceneDataFlags();
};
Expand All @@ -51,6 +57,8 @@ class Scene
std::vector<AssetPtr> assets;
std::vector<TransformPtr> entities;
std::vector<ConstraintPtr> constraints;
std::vector<InstanceInfoPtr> instanceInfos;
std::vector<TransformPtr> instanceMeshes;

// non-serializable
std::list<RawVector<char>> scene_buffers;
Expand Down Expand Up @@ -105,6 +113,10 @@ class Scene
bool submeshesHaveUniqueMaterial() const;

void dbgDump() const;

private:
void updateEntities(const ms::SceneImportSettings& cv, const std::vector<ms::EntityConverterPtr>& converters, std::vector<ms::TransformPtr> entities);

};
msSerializable(Scene);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ using super = Entity;
mu::float4x4 toMatrix() const;
void assignMatrix(const mu::float4x4& v);
void applyMatrix(const mu::float4x4& v);
void reset();

void addUserProperty(const Variant& v);
void addUserProperty(Variant&& v);
Expand Down
1 change: 1 addition & 0 deletions Plugin~/Src/MeshSync/Include/MeshSync/msProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ using super = Message;
public:
std::vector<Identifier> entities;
std::vector<Identifier> materials;
std::vector<Identifier> instances;

DeleteMessage();
void serialize(std::ostream& os) const override;
Expand Down
2 changes: 2 additions & 0 deletions Plugin~/Src/MeshSync/SceneExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ void SceneExporter::clear()
transforms.clear();
geometries.clear();
animations.clear();
instanceInfos.clear();

deleted_entities.clear();
deleted_materials.clear();
deleted_instances.clear();
}

void SceneExporter::add(ScenePtr scene)
Expand Down
69 changes: 69 additions & 0 deletions Plugin~/Src/MeshSync/SceneGraph/msInstanceInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "MeshSync/SceneGraph/msInstanceInfo.h"
#include <MeshSync/msFoundation.h>
#include <MeshSync/SceneGraph/msIdentifier.h>

namespace ms {
void InstanceInfo::serialize(ostream& os)
{
write(os, path);
write(os, parent_path);
write(os, transforms);

}

void InstanceInfo::deserialize(istream& is)
{
read(is, path);
read(is, parent_path);
read(is, transforms);
}
void InstanceInfo::clear()
{
this->path = "";
this->parent_path = "";
this->transforms.clear();
}

shared_ptr<InstanceInfo> InstanceInfo::create(istream& is)
{
auto ret = InstanceInfo::create();
ret->deserialize(is);
return ret;
}

uint64_t InstanceInfo::hash()
{
return m_hash;
}
Identifier InstanceInfo::getIdentifier()
{
return Identifier{ path, InvalidID};
}

InstanceInfo::InstanceInfo() {}

InstanceInfo::InstanceInfo(const InstanceInfo& v)
{
*this = v;
}

InstanceInfo& InstanceInfo::operator=(const InstanceInfo& v)
{
path = v.path;
transforms = v.transforms;
return *this;
}

InstanceInfo::InstanceInfo(InstanceInfo&& v) noexcept
{
*this = std::move(v);
}

InstanceInfo& InstanceInfo::operator=(InstanceInfo&& v)
{
path = std::move(v.path);
transforms = std::move(v.transforms);
return *this;
seandillon92 marked this conversation as resolved.
Show resolved Hide resolved
}

}
Loading