C# - Editing static object during runtime

Hello everyone,

I'm trying to do some low poly, procedurally generated terrain. My thought was to create a static object, and then edit it's vertices and faces.

For starters I want to draw a simple triangle to the level:

Code: Select all

var statObject = Engine.Engine3D.CreateStatObj(); var material = Engine.Engine3D.GetMaterialManager().GetDefaultMaterial(); statObject.SetMaterial(material); var mesh = statObject.GetIndexedMesh(true); var vertexCount = 3; var triangleCount = 1; mesh.SetVertexCount(vertexCount); mesh.SetFaceCount(triangleCount); mesh.SetTexCoordCount(vertexCount); SMeshNormal normals = mesh.GetMesh().m_pNorms; SMeshFace faces = mesh.GetMesh().m_pFaces; Vec3 vertices = mesh.GetMesh().m_pPositions;
Now, the problem is, in C++ pMesh->GetMesh()->GetStreamPtr<Vec3>(CMesh::POSITIONS);
would return a pointer to the vertices, in which I could edit the position. Same for the faces and the normals.
In C#, mesh.GetMesh().m_pPositions returns a vec3, instead of an array of vec3. How am I supposed to get the next vertex?
Same goes for m_pFaces and m_pNorms, which return SMeshFace and SMeshNormal instances respectively.

Re: C# - Editing static object during runtime

This is a limitation of how SWIG exposes the C++ code to C#. We've run into this a few times with other functions as well. On way of fixing it is by adding a GetAtIndex function in either C++ or to the SWIG intermediate files that gets the vertex at the specified index of the array. The problem with this is that it can give a lot of overhead when this is used to access the array a lot of times.
Another option to try is using the AutoPinner to fill a buffer. This was done in the CryEngine.File class for C#.

Our goal is to eventually wrap all of these function in the CryEngine.Core, where we will properly handle these types of arrays. Sadly it takes quite a bit of time to wrap the entire C++ API in C#.

Re: C# - Editing static object during runtime

This is most unfortunate, since I only now the very basics of C++, barely enough to read files with some guesses here and there. I'll take a look into the AutoPinner object you referenced me, this is probably easier for me then to write some (efficient) extensions to the C++ source code.
Anyway, thanks for the information, and I hope you guys add some more functionality to the C# world soon :)

Who is online

Users browsing this forum: No registered users and 1 guest