So basically I created this little tree generation program using some space colonization algorithm, and it works pretty well, BUT!
For now I can only view the results in the engine itself:
I’m creating the model inside Urho3D in this way:
struct tVertex {
Tree::vec3f position, normal;
};
std::vector<tVertex> vertexData;
std::vector<Tree::vec3us> indexData;
//some magic filling in the data...
SharedPtr<VertexBuffer> vb(new VertexBuffer(context_));
vb->SetShadowed(true); // Shadowed buffer needed for raycasts to work, and so that data can be
automatically restored on device loss
PODVector<VertexElement> elements;
elements.Push(VertexElement(TYPE_VECTOR3, SEM_POSITION));
elements.Push(VertexElement(TYPE_VECTOR3, SEM_NORMAL));
vb->SetSize(vertexData.size(), elements);
vb->SetData(static_cast<void*>(vertexData.data()));
SharedPtr<IndexBuffer> ib(new IndexBuffer(context_));
ib->SetShadowed(true);
ib->SetSize(indexData.size() * 3, false);
ib->SetData(static_cast<void*>(indexData.data()));
SharedPtr<Geometry> geom(new Geometry(context_));
geom->SetVertexBuffer(0, vb);
geom->SetIndexBuffer(ib);
geom->SetDrawRange(TRIANGLE_LIST, 0, indexData.size() * 3);
return geom;
So please if someone knows how a way to export the geometry could you explain it to a Urho3D newbie? I know there is Assimp integration in the engine, thus theoretically exporting is possible out of the box?
Thanks for help in advance!
If you need a different format or more data than OBJ supports you can refer to those as a bit of a guide.
Unless it has been stripped out there’s a menu to do this through the editor, I did the initial work and the use-cases were focused on merge-batching or dumping geometry to use for modeling pefect fit geometry against (load the exported scene so you can model those tree roots to be in the right place, etc).
I don’t believe it is bound to Lua though, just C++ and Angelscript.
Yeah soo, how can I convert my geometry to a Drawable? I thought that I can just take my StaticModel I used to render and make a cast to Drawable because it is it’s base class…
But nope:
And I don’t know why because my variables aren’t const…
Could you please show a snippet of code converting from geometry to a Drawable in a way that I can use it with WriteDrawablesToOBJ?
Sorry if this is basic but I’m new to Urho3D and C++
//#EDIT:
I’m taking geometry created before and using it to make a StaticModel like this
SharedPtr<Urho3D::Model> TreeModel(new Urho3D::Model(context_));
TreeModel->SetNumGeometries(1);
TreeModel->SetGeometry(0, 0, geom);
TreeModel->SetBoundingBox(BoundingBox(
Vector3( BBsize.x * -0.5f, 0.0f, BBsize.z * -0.5f ),
Vector3( BBsize.x * 0.5f, BBsize.y, BBsize.z * 0.5f )
));
// Though not necessary to render, the vertex & index buffers must be listed in the model so that it can be saved properly
Vector<SharedPtr<VertexBuffer> > vertexBuffers;
Vector<SharedPtr<IndexBuffer> > indexBuffers;
vertexBuffers.Push(SharedPtr<VertexBuffer>(geom->GetVertexBuffer(0)));
indexBuffers.Push(SharedPtr<IndexBuffer>(geom->GetIndexBuffer()));
// Morph ranges could also be not defined. Here we simply define a zero range (no morphing) for the vertex buffer
PODVector<unsigned> morphRangeStarts;
PODVector<unsigned> morphRangeCounts;
morphRangeStarts.Push(0);
morphRangeCounts.Push(0);
TreeModel->SetVertexBuffers(vertexBuffers, morphRangeStarts, morphRangeCounts);
TreeModel->SetIndexBuffers(indexBuffers);
return TreeModel;
Code provided by @elix22 creates file in root folder of You program and even if it fail to create .obj, empty file still should be created in the same folder as executable.
Are You running it directly from VS? I think that, in this case file will be created in the folder that is set as “working directory” in project’s properties, have You checked it?