Closed McManning closed 2 years ago
Some references -
LuxCore does something similar as they also need split normals. Their approach is struct-per-version which looks to be a pain in the ass to maintain for future versions - https://github.com/LuxCoreRender/LuxCore/blob/master/src/luxcore/pyluxcoreforblender.cpp#L719-L727
For weights, I can get access to the weight list through Python but not the array of weight lists for all vertices - so I'm still iterating vertices in Python and calling into Blender to get the pointer to each weight group. Reference: https://github.com/sobotka/blender/blob/af316d276144b905cf6cf5a1b1d7ae727d545e2f/source/blender/makesrna/intern/rna_mesh.c#L527-L531
Maybe something like https://github.com/WaveEngine/RenderDoc.NET
Under the hood it uses https://github.com/xoofx/CppAst.NET for parsing C headers
Implemented as https://github.com/McManning/SharpRNA
Will now just need to integrate back into this project.
Obsolete with the new C++ core
Just a place for me to dump notes on this topic -
Depending on how much support I'm going to need and performance I need to squeeze out of this where I can't just do structs -> python -> C#, I'll need to have a realistic solution for just interacting with Blender DNA directly.
The primary problem is DNA struct changes between Blender versions, and having to build a DLL per-version or some technique in order to extract data I need without worrying too much about version changes.
Current / known use cases
Mesh->dvert
which currently requires an obscene number of memcpy ops if through PythonMesh->ldata
which currently does not seem easily accessible via Python in bulk - requiring a per-vertex-copy operation which is prohibitively slow.Both of the above are on the
Mesh
struct - and unfortunately the top of theMesh
struct is anID
which seems to be changing in size each version. Already, I'd need to have a copy ofID
defined in C# before even definingMesh
.bGPDstroke/bGPDspoint/etc
Considering how active GP development is, I expect these structs to change frequently.
Solutions
Autogenerated definitions
Overengineered solution - automatically generate a C# definitions file that includes all the Blender structs I need and their changes between different Blender versions.
Using a modified version of something like CppHeaderToCSharpConverter it could run through checkout revisions of Blender that we support, pull struct files, parse, and then create namespaced/grouped blocks of code representing each extracted struct that we need. As the DLL is loaded, Python passes the current Blender version in and the appropriate structs are used for all data extraction.
E.g. something like:
This, of course, is horrifying.
Python byte skipping
If I could figure out what offset
Mesh->ldata
is from the initial ptr of Mesh in Python - I could potentially do a.as_pointer()
for the mesh, and then offset from that. Or - if I could grab an initial entry in an array like I do for MVert/MLoopTri/etc.The main problem - each piece of data I'm grabbing needs a custom solution.
dvert
can't be grabbed from Python (only the underlying vertex weights that are referenced by each dvert entry can).