example IDL file
namespace MyGame;
struct Vec3 {
x:float;
y:float;
z:float;
}
table Mesh {
positions:[Vec3]; // array of structs.. (works fine with single instances rather than an array)
indices:[int];
}
root_type Mesh;...
class Program
{
static void Main(string[] args)
{
var fbb = new FlatBufferBuilder(1);
Mesh.StartPositionsVector(fbb, 9);
fbb.AddOffset(Vec3.CreateVec3(fbb, -1f, +2f, -3f));
fbb.AddOffset(Vec3.CreateVec3(fbb, +4f, -5f, +6f));
fbb.AddOffset(Vec3.CreateVec3(fbb, -7f, +8f, -9f));
int positionsVector = fbb.EndVector();
var indicesVector = Mesh.CreateIndicesVector(fbb, new int[] { 1, 2, 3 });
int wm = Mesh.CreateMesh(fbb, positionsVector, indicesVector);
Mesh.FinishMeshBuffer(fbb, wm);
var readMesh = Mesh.GetRootAsMesh(fbb.DataBuffer);
Vec3 scratch = new Vec3();
for (int i = 0; i < readMesh.PositionsLength(); i++)
{
var v = readMesh.Positions(scratch, i);
Console.WriteLine("{0},{1},{2}", v.X().ToString("F2"), v.Y().ToString("F2"), v.Z().ToString("F2"));
}
var indicesLength = readMesh.IndicesLength();
for (int i = 0; i < indicesLength; i++)
{
Console.WriteLine(readMesh.Indices(i));
}
}
}
--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
var fbb = new FlatBufferBuilder(1);
Mesh.StartPositionsVector(fbb, 3);
fbb.AddFloat(-9);
fbb.AddFloat(+8);
fbb.AddFloat(-7);
fbb.AddFloat(+6);
fbb.AddFloat(-5);
fbb.AddFloat(+4);
fbb.AddFloat(-3);
fbb.AddFloat(+2);
fbb.AddFloat(-1);
int positionsVector = fbb.EndVector();
var indicesVector = Mesh.CreateIndicesVector(fbb, new int[] { 1, 2, 3 });
int wm = Mesh.CreateMesh(fbb, positionsVector, indicesVector);
Mesh.FinishMeshBuffer(fbb, wm);