Jump to content

How to fill a mesh data in C++?


photo

Recommended Posts

I need to create a new type of object, so I copied the ObjectMesh class as my basic source, then i modified the loadWorld function to make it create a custom mesh object, I'm using these in my code

 

mesh_ptr = engine.renders->createMesh("core/dummy.mesh");
mesh_ptr->clear();

Vector<Mesh::Vertex> vertecis;
Vector<int> indecis;
Mesh::Vertex vertex;

// fill vertex and index
// ....

mesh_ptr->addTriangleSurface(String::format("stone%d",i), vertecis.get(), vertecis.size(), 
		indecis.get(), indecis.size());

mesh_ptr->flush();

 

then in engine, I found the object's bounding-box is correct, looks everything is correct, face number, triangle number, except one thing, the object rendered as nothing, after I changed it's material, it still rendered nothing on screen.

 

So, How can I use Mesh class and fill it's data? I can't use MeshDynamic, because there might be many of this kind of objects in my scene. MeshDynamic don't support instancing.

Link to comment

Use ObjectMeshDynamic. Instancing is perfectly working on cloned ObjectMeshDynamic nodes.

There is also a sample in samples/Api/Objects directory of ObjectMeshDynamic usage.

Link to comment

well, I've found the problem, engine didn't call my object's render function, nor getIntersection, that's why my object never get rendered.

 

but my question is, why engine don't call these function?

Link to comment

traced to these code in render_deferred_surfaces function of RenderRenderer.cpp

for(int i = 0; i < surfaces.size(); i++) {
	ObjectSurface *surface = surfaces[i];
	if(surface->getShader(RENDER_PASS_DEFERRED) == NULL) continue;
	Material *material = surface->getMaterial();
	if(material->getPostDeferred() != post_deferred) continue;
	deferred_surfaces.append(surface);
}

 

in my test scene, only my object is set to enable, and the surface->getShader() function always return 0, so that's why my object never get rendered.

Link to comment

Well, I've tested this:

1) copy whole ObjectMeshDynamic class to my ObjectTree class without any modification

2) add OBJECT_TREE id/name in Node.h and Node.cpp

3) replace all OBJECT_MESH_DYNAMIC id with my OBJECT_TREE id, and change factorycreator function.

 

 

so far, the ObjectTree class is almost same with ObjectMeshDynamic, only difference is class name and it's id.

 

But it sill don't render, the render function was not called by engine, because it always get null shader.

Link to comment

Got it.

You should declare an additional shader set for your new Object type.

Find in the "data/core/materials/unigine_meshes.mat" 186 line with "<bind object="mesh_dynamic" to="mesh"/>" content. And add "<bind object="mesh_tree" to="mesh"/>" line.

Moreover you should add new object types into the engine/render/Material.cpp file on 1298 and 1318 lines.

 

Why can't you use unmodified ObjectMeshDynamic?

Link to comment

all done, I'm compiling the source to see the result.

 

I don't get it, if I create a ObjectTree class which owns a member of ObjectMeshDynamic, then I fill the data with ObjectMeshDynamic's function, I think that would be less efficient.

 

So I create a new class to do this.

Link to comment
×
×
  • Create New...