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

Geometry nodes support #160

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
de4f158
Added bindings for object_instances CollectionPropertyRNA access and …
Feb 2, 2022
03b74ef
Correct usage of CollectionPropertyIterator, binded to instance_objec…
Feb 3, 2022
ecc2693
Filtering out non meshes and non instances
Feb 3, 2022
19225c4
Created function for extracting instancing info, added code for stori…
Feb 4, 2022
9da1b70
Blender to Unity matrix corrections
Feb 7, 2022
d7518e8
Merge remote-tracking branch 'origin' into geometry_nodes_support
Feb 8, 2022
d966266
Instances are associated to the name of the mesh, not the name of the…
Feb 8, 2022
bf50ade
Extract Geometry node tree input parameters and set them as variant d…
Feb 9, 2022
3144c4b
move names when setting variant
Feb 10, 2022
4f1b0c2
macrs for compiling object instances code only for blender 3.0.0 and …
Feb 10, 2022
028352d
Auto-sync support
Feb 16, 2022
0e5f180
Fix for cleaning instances correctly, get updates from depsgraph on a…
Feb 17, 2022
a3904ea
Support manual sync when loading new file
Feb 17, 2022
0594b56
Implemented instances manager on MeshSyncClient. Converted Geometry n…
Feb 18, 2022
2816457
Reduced amount of times instances are accessed. Delete message is pop…
Feb 21, 2022
a0b0af4
Better name generation for instance info
Feb 21, 2022
971f369
fixed compilation error
Feb 22, 2022
289afed
small change on name translation
Feb 22, 2022
20071ae
Using entity path as instance info path
Feb 22, 2022
3d46c8a
null check guard
Feb 23, 2022
f0352d2
Covered use case where instances refer to meshes not in scene
Feb 23, 2022
53e081b
Support for instances on geometry that is not part of the scene
Mar 1, 2022
6a7c848
Fix for Release compilation not rendering intermediate meshes
Mar 9, 2022
ef8bd15
Corrected cmake syntex for using c++17
Mar 10, 2022
58e6eab
Avoid returning address of local var
Mar 10, 2022
127a133
Code depending on geometry nodes compiles only on 3.0.0 and above
Mar 10, 2022
636d57a
Fix for Python Lib check on Mac
Mar 10, 2022
9bf440c
Handled merge conflict
Mar 10, 2022
91c26e1
Fixed errors when compiling with XCode
Mar 10, 2022
0f7582e
Removed unused extern properties that caused importation errors
Mar 10, 2022
5da57da
Merge remote-tracking branch 'origin' into geometry_nodes_support
Mar 11, 2022
4db9d39
Handled merge conflict with develop
Mar 14, 2022
78b183c
Fix for compiation issues
Mar 14, 2022
95c0bee
Merge remote-tracking branch 'origin' into geometry_nodes_support
Mar 14, 2022
a21a80d
Merge https://github.com/Unity-Technologies/MeshSyncDCCPlugins into g…
Mar 15, 2022
5022bab
Merge branch 'geometry_nodes_support' of https://github.com/Unity-Tec…
Mar 15, 2022
471366f
Support for Blender 3.1
Mar 15, 2022
8fb890f
Used Shared Vector instead of std::Vector for instacing info transforms
Mar 16, 2022
92e9dc5
Handled merge conflicts with 0.12.x/dev
Mar 16, 2022
68cad81
Geometry Nodes: Refactored how objects are accessed so objects outsid…
Mar 22, 2022
8a9f422
Removed Object Instance ReferenceType from geometry nodes instances
Mar 22, 2022
ebc9b2a
Refactor: created a class that encapsulates the msblenContext state o…
Mar 23, 2022
745f94a
Merge remote-tracking branch 'origin' into geometry_nodes_support
Mar 23, 2022
8b8b301
Geometry Nodes: Fix for associating objects through data id instead o…
Mar 24, 2022
ded7658
Geometry Nodes: WIP refactor on accessing instances data
Mar 24, 2022
22fed3f
Geometry Nodes: support for passing the path of parent for instances
Mar 25, 2022
412f5ff
Geometry Nodes: Better support for exporting objects that are not par…
Mar 28, 2022
21fab1c
Geometry Nodes: avoid exporting objects that exist in the scene
Mar 30, 2022
6a606cb
Geometry Nodes: use unordered map instead of map for instances records
Mar 30, 2022
5fcc26b
Geometry Nodes: send local transforms for instances instead of world …
Mar 31, 2022
a2389d4
Geometry Nodes: Simplification on local matrix calculcation
Mar 31, 2022
bc50d44
Geometry Nodes: simplification on matrix calculations
Mar 31, 2022
141fe55
Geometry Nodes: small refactor on using how the geonode utility lamda…
Mar 31, 2022
9ff82ce
Geometry Nodes: moved RNA interfacing to appropriate classes
Apr 1, 2022
dd382e7
Visibility: fix for collection visibility
Apr 1, 2022
a163c78
Geometry Nodes: use parallel for when converting matrices
Apr 4, 2022
30693c0
Geometry Nodes: removed dead code
Apr 4, 2022
75fc523
Geometry Nodes: Temporary fix for skinned mesh renderer glitch
Apr 4, 2022
90910a5
Geometry Nodes: removed dead var
Apr 5, 2022
66dbca2
Geometry Nodes: Fix for compilation error for versions < 300
Apr 5, 2022
e973858
Geometry Nodes: fix for mac compilation issues
Apr 5, 2022
2aa1dea
Merge remote-tracking branch 'origin' into geometry_nodes_support
Apr 6, 2022
2e9d69f
Merge remote-tracking branch 'origin' into geometry_nodes_support
Apr 7, 2022
bebd542
Geometry Nodes: revert visibility fix, better formating in meshUtils
Apr 7, 2022
e7818c1
Geometry Nodes: style changes
Apr 7, 2022
f10f6ae
Geometry Nodes: reverted changes on BlenderPyContext for exposing vie…
Apr 7, 2022
374ded9
Geometry Nodes: Removed view layer RNA binding
Apr 7, 2022
777b4d1
Geometry Nodes: style update
Apr 7, 2022
8485342
Geometry Nodes: used override keyword for functions of EntityManager …
Apr 7, 2022
2afbcb0
Geometry Nodes: moved duplicate code in EntityManager and InstanceInf…
Apr 7, 2022
bf22554
Geometry Nodes: override keywords on path providers. Simplified code …
Apr 7, 2022
05b3f8d
Geometry Nodes: Chagend raw pointers to states to shared pointers. Re…
Apr 7, 2022
cba846a
Geometry Nodes: fixed typo
Apr 7, 2022
12fde34
Geometry Nodes: removed hungarian notation from local variable
Apr 7, 2022
38ee908
Geometry Nodes: Deduplicated code when exporting instances
Apr 7, 2022
dcdcebc
Geometry Nodes: moved msblenContext Geometry node function implemetat…
Apr 7, 2022
8be11f8
Geometry Nodes: added XML comments
Apr 7, 2022
bbd9c11
Geometry Nodes: Fixed formatting issue
Apr 11, 2022
37989d7
Geometry Nodes: simplified branching
Apr 11, 2022
18012d1
Geometry Nodes: Handeld merge conflicts with develop
Apr 11, 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
2 changes: 1 addition & 1 deletion Plugins~/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ include(UnityPackage)
setup_unity_package_version()
sindharta marked this conversation as resolved.
Show resolved Hide resolved
add_definitions(-DMESHSYNC_DCC_PLUGIN_VER="${UNITY_PACKAGE_VERSION}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

# Force Unicode character set
add_definitions(-DUNICODE -D_UNICODE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ PropertyRNA* BlenderPyContext_blend_data = nullptr;
PropertyRNA* BlenderPyContext_scene = nullptr;
FunctionRNA* BlenderPyContext_evaluated_depsgraph_get = nullptr;
FunctionRNA* BlenderPyContext_depsgraph_update = nullptr;
PropertyRNA* BlenderPyContext_depsgraph_object_instances = nullptr;
PropertyRNA* BlenderPyContext_depsgraph_instance_object = nullptr;
PropertyRNA* BlenderPyContext_depsgraph_is_instance = nullptr;
PropertyRNA* BlenderPyContext_depsgraph_world_matrix = nullptr;
PropertyRNA* BlenderPyContext_depsgraph_parent = nullptr;
PropertyRNA* BlenderPyContext_depsgraph_object = nullptr;



BlenderPyContext BlenderPyContext::get()
Expand All @@ -36,5 +43,74 @@ void BlenderPyContext::UpdateDepsgraph(Depsgraph* depsgraph) {
call<Depsgraph, void>(g_context, depsgraph, BlenderPyContext_depsgraph_update);
}

void BlenderPyContext::object_instances_begin(CollectionPropertyIterator* it, Depsgraph* depsgraph) {

PointerRNA rna;
rna.data = depsgraph;

CollectionPropertyRNA* cprop = (CollectionPropertyRNA*)BlenderPyContext_depsgraph_object_instances;

cprop->begin(it, &rna);
}

void BlenderPyContext::object_instances_end(CollectionPropertyIterator* it) {

CollectionPropertyRNA* cprop = (CollectionPropertyRNA*)BlenderPyContext_depsgraph_object_instances;
cprop->end(it);
}

void BlenderPyContext::object_instances_next(CollectionPropertyIterator * it){
CollectionPropertyRNA* cprop = (CollectionPropertyRNA*)BlenderPyContext_depsgraph_object_instances;
cprop->next(it);
}

PointerRNA BlenderPyContext::object_instances_get(CollectionPropertyIterator* it) {

auto collectionProp = (CollectionPropertyRNA*)BlenderPyContext_depsgraph_object_instances;
return collectionProp->get(it);

}

Object* BlenderPyContext::instance_object_get(PointerRNA instance) {
auto objectInstanceProp = (PointerPropertyRNA*)BlenderPyContext_depsgraph_instance_object;
auto object = objectInstanceProp->get(&instance);

if (object.type == nullptr || object.data == nullptr) {
return nullptr;
}

return (Object*)object.data;
}



bool BlenderPyContext::object_instances_is_instance(PointerRNA object) {
auto booleanProp = (BoolPropertyRNA*)BlenderPyContext_depsgraph_is_instance;
return booleanProp->get(&object);
}

void BlenderPyContext::world_matrix_get(PointerRNA* instance, mu::float4x4* result)
{
auto floatProp = (FloatPropertyRNA*)BlenderPyContext_depsgraph_world_matrix;
floatProp->getarray(instance, &(result->m[0][0])); // Sean Dillon - TODO: is the matrix object memory guaranteed to be aligned?
}

Object* BlenderPyContext::instance_parent_get(PointerRNA* instance) {
auto pointerProp = (PointerPropertyRNA*)BlenderPyContext_depsgraph_parent;
auto parent = pointerProp->get(instance);

return (Object*)parent.data;
}

Object* BlenderPyContext::object_get(PointerRNA instance) {
auto objectInstanceProp = (PointerPropertyRNA*)BlenderPyContext_depsgraph_object;
auto object = objectInstanceProp->get(&instance);

if (object.type == nullptr || object.data == nullptr) {
return nullptr;
}

return (Object*)object.data;
}

} // namespace blender
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <BKE_context.h> //bContext
#include "msblenMacros.h" //MSBLEN_BOILERPLATE2
#include "MeshUtils/muMath.h"

namespace blender
{
Expand All @@ -18,6 +19,17 @@ namespace blender

static void UpdateDepsgraph(Depsgraph* depsgraph);

void object_instances_begin(CollectionPropertyIterator* it, Depsgraph* depsgrah);
void object_instances_end(CollectionPropertyIterator* it);
void object_instances_next(CollectionPropertyIterator* it);
PointerRNA object_instances_get(CollectionPropertyIterator* it);


Object* instance_object_get(PointerRNA instance);
bool object_instances_is_instance(PointerRNA instance);
void world_matrix_get(PointerRNA* instance, mu::float4x4* world_matrix);
Object* instance_parent_get(PointerRNA* instance);
Object* object_get(PointerRNA instance);
};

} // namespace blender
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "BlenderPyDepsgraphUpdate.h"
#include "BlenderPyCommon.h"

namespace blender {

PropertyRNA* BlenderPyDepsgraphUpdate_updates = nullptr;
FunctionRNA* BlenderPyDepsgraphUpdate_id_type_updated = nullptr;
extern bContext* g_context;


CollectionPropertyRNA* get_property() {
return (CollectionPropertyRNA*)BlenderPyDepsgraphUpdate_updates;
}

void blender::BlenderPyDepgraphUpdate::updates_begin(CollectionPropertyIterator* it, Depsgraph* graph)
{
PointerRNA rna;
rna.data = graph;
get_property()->begin(it, &rna);
}

void blender::BlenderPyDepgraphUpdate::updates_next(CollectionPropertyIterator* it)
{
get_property()->next(it);
}

void blender::BlenderPyDepgraphUpdate::updates_end(CollectionPropertyIterator* it)
{
get_property()->end(it);
}

PointerRNA blender::BlenderPyDepgraphUpdate::updates_get(CollectionPropertyIterator* it)
{
return get_property()->get(it);
}

bool blender::BlenderPyDepgraphUpdate::id_type_updated(int type, Depsgraph* graph) {

return call<Depsgraph, bool, int>(g_context, graph, BlenderPyDepsgraphUpdate_id_type_updated, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <BKE_context.h> //bContext
#include "MeshUtils/muMath.h"
#include <DNA_modifier_types.h>
#include <RNA_define.h>

namespace blender
{
class BlenderPyDepgraphUpdate
{
public:

void updates_begin(CollectionPropertyIterator* it, Depsgraph* graph);
void updates_next(CollectionPropertyIterator* it);
void updates_end(CollectionPropertyIterator* it);
PointerRNA updates_get(CollectionPropertyIterator* it);

bool id_type_updated(int type, Depsgraph* graph);
};

} // namespace blender
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "pch.h"
#include "BlenderPyNodeTree.h"

namespace blender {

PropertyRNA* BlenderPyNodeTree_inputs = nullptr;
PropertyRNA* BlenderPyNodeTree_nodes = nullptr;
PropertyRNA* BlenderPyNodeTree_outputs = nullptr;
StructRNA* BlenderPyNodeTree_Tree = nullptr;

void begin(CollectionPropertyIterator* it, const bNodeTree* nodeTree, PropertyRNA* prop) {
auto cprop = (CollectionPropertyRNA*)prop;
PointerRNA rna;
rna.data = &nodeTree;
cprop->begin(it, &rna);
}

void next(CollectionPropertyIterator* it, PropertyRNA* prop) {
auto cprop = (CollectionPropertyRNA*)prop;
cprop->next(it);
}

void end(CollectionPropertyIterator* it, PropertyRNA* prop) {
auto cprop = (CollectionPropertyRNA*)prop;
cprop->end(it);
}

PointerRNA get(CollectionPropertyIterator* it, PropertyRNA* prop) {
auto cprop = (CollectionPropertyRNA*)prop;
return cprop->get(it);
}

/**Inputs**/
void BlenderPyNodeTree::inputs_begin(CollectionPropertyIterator* it, bNodeTree* nodeTree)
{
begin(it , nodeTree, BlenderPyNodeTree_inputs);
}
void BlenderPyNodeTree::inputs_next(CollectionPropertyIterator* it)
{
next(it, BlenderPyNodeTree_inputs);
}
void BlenderPyNodeTree::inputs_end(CollectionPropertyIterator* it)
{
end(it, BlenderPyNodeTree_inputs);
}

PointerRNA BlenderPyNodeTree::inputs_get(CollectionPropertyIterator* it)
{
return get(it, BlenderPyNodeTree_inputs);
}

void BlenderPyNodeTree::outputs_begin(CollectionPropertyIterator* it, bNodeTree* nodeTree)
{
begin(it, nodeTree, BlenderPyNodeTree_outputs);
}

void BlenderPyNodeTree::outputs_next(CollectionPropertyIterator* it)
{
next(it, BlenderPyNodeTree_outputs);
}

void BlenderPyNodeTree::outputs_end(CollectionPropertyIterator* it)
{
end(it, BlenderPyNodeTree_outputs);
}

PointerRNA BlenderPyNodeTree::outputs_get(CollectionPropertyIterator* it)
{
return get(it, BlenderPyNodeTree_outputs);
}

/*Outputs*/


/*Nodes*/
void BlenderPyNodeTree::nodes_begin(CollectionPropertyIterator* it, const bNodeTree* nodeTree) {
begin(it, nodeTree, BlenderPyNodeTree_nodes);
}

void BlenderPyNodeTree::nodes_next(CollectionPropertyIterator* it) {
next(it, BlenderPyNodeTree_nodes);
}

void BlenderPyNodeTree::nodes_end(CollectionPropertyIterator* it) {
end(it, BlenderPyNodeTree_nodes);
}

PointerRNA BlenderPyNodeTree::nodes_get(CollectionPropertyIterator* it) {
return get(it, BlenderPyNodeTree_nodes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <BKE_context.h> //bContext
#include "MeshUtils/muMath.h"
#include <DNA_modifier_types.h>
#include <RNA_define.h>

namespace blender
{
class BlenderPyNodeTree
{
public:

/*Inputs*/
void inputs_begin(CollectionPropertyIterator* it, bNodeTree* nodeTree);
void inputs_next(CollectionPropertyIterator* it);
void inputs_end(CollectionPropertyIterator* it);
PointerRNA inputs_get(CollectionPropertyIterator* it);

/*Outputs*/
void outputs_begin(CollectionPropertyIterator* it, bNodeTree* nodeTree);
void outputs_next(CollectionPropertyIterator* it);
void outputs_end(CollectionPropertyIterator* it);
PointerRNA outputs_get(CollectionPropertyIterator* it);

/*Nodes*/
void nodes_begin(CollectionPropertyIterator* it, const bNodeTree* nodeTree);
void nodes_next(CollectionPropertyIterator* it);
void nodes_end(CollectionPropertyIterator* it);
PointerRNA nodes_get(CollectionPropertyIterator* it);
};

} // namespace blender
24 changes: 22 additions & 2 deletions Plugins~/Src/MeshSyncClientBlender/MeshSyncClientBlender.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
#include "pch.h"
#include "msblenBinder.h"
#include "msblenContext.h"
#include "BlenderPyObjects/BlenderPyDepsgraphUpdate.h"
#include "BlenderPyObjects/BlenderPyContext.h"

#include "MeshSyncClient/ExportTarget.h"

namespace bl = blender;

static Depsgraph* DepsgraphFromPyObject(py::object graphObj) {
Depsgraph* graph;
BPy_StructRNA* rna = (BPy_StructRNA*)graphObj.ptr();
auto typeName = rna->ob_base.ob_type->tp_name;

if (strcmp(typeName, "Depsgraph") != 0) {
return nullptr;
}

blender::rna_sdata(graphObj, graph);

return graph;
}

static bool msblenSend(msblenContext& self, MeshSyncClient::ExportTarget target, MeshSyncClient::ObjectScope scope)
{
if (!self.isServerAvailable()) {
Expand Down Expand Up @@ -122,7 +138,7 @@ PYBIND11_MODULE(MeshSyncClientBlender, m)
[](self_t& self, bool v) { self->getSettings().make_double_sided = v; })
BindProperty(bake_modifiers,
[](const self_t& self) { return self->getSettings().BakeModifiers; },
[](self_t& self, bool v) { self->getSettings().BakeModifiers= v; })
[](self_t& self, bool v) { self->getSettings().BakeModifiers = v; })
BindProperty(bake_transform,
[](const self_t& self) { return self->getSettings().BakeTransform; },
[](self_t& self, bool v) { self->getSettings().BakeTransform = v; })
Expand Down Expand Up @@ -157,7 +173,11 @@ PYBIND11_MODULE(MeshSyncClientBlender, m)
BindMethod(clear, [](self_t& self) { self->clear(); })
BindMethod(exportUpdatedObjects, [](self_t& self) { self->sendObjects(MeshSyncClient::ObjectScope::Updated, false); })
BindMethod(export, [](self_t& self, int _target) { msblenSend(*self, (MeshSyncClient::ExportTarget)_target, MeshSyncClient::ObjectScope::All); })
;
BindMethod(OnDepsgraphUpdatePost,
[](self_t& self, py::object depsgraph) {
auto graph = DepsgraphFromPyObject(depsgraph);
self->onDepsgraphUpdatedPost(graph);
});
}
{
using self_t = CacheProxy;
Expand Down
Loading