Jump to content

[SOLVED] ObjectMeshCluster disappearing, C++


photo

Recommended Posts

Hi,

Need to create mesh clusters per multiple instances of the same mesh. The cluster is created in 0, 0, 0 and multiple instances are positioned in it:

Unigine::ObjectMeshClusterPtr engCluster = Unigine::ObjectMeshCluster::create("meshCluster");

engCluster->getNode()->setParent(terrain->getNode());

engCluster->setMesh(mesh);

engCluster->setWorldTransform(Unigine::Math::Mat4_identity);

Unigine::Vector<Unigine::Math::Mat4> insts;
insts.resize(instNo);

// Compute instances transforms.
for(uint i=0; i<instNo; i++)
    compute insts

engCluster->createMeshes(insts);

for(uint S=0; S<engCluster->getNumSurfaces(); S++)
        engCluster->setMaterial("mesh_base", S);

engCluster->flushMesh();
engCluster->release();

All is fine, instances show where they should be, but when looking away from the origin the entire cluster disappears. Is there another function I should call to update its bounding box? Do I miss a call?

Regards,

Adrian

VSTEP BV

Link to comment

Never mind, I fixed it. The mesh that made up the instances was also constructed via code and didn't had its bounding box updated. Btw, can i just call setBoundBox or should I also call setBoundSphere?

Link to comment
  • 2 months later...

It seems that I've had a simular problem.

The ObjectMeshCluster object constructed from mesh-file using "create" method and having some meshes added using "createMeshes" method with precomputed transformation matrixes works great. But after iterating throw the cluster usung "setMeshTransform" method (even with same transformation matrixes) some instances became unvisible. Visibility changes depends of distance and camera orientation.

Should I make some manual updates aftre using "setMeshTransform" method ?

Edited by Corvax
Link to comment

This issue can be reproduced in cluster_00 sample. Just move meshes to the same postions using setMeshTransform function. When some of the meshes is out of camera view random other meshes became unvisible.

Is this issue a bug? Can setMeshTransform method be used for moving meshes in cluster ?

Here is the code. Add some lines in init method:

int init() {
	
	createInterface("samples/objects/");
	engine.render.loadSettings("samples/common/world/render.render");
	createDefaultPlayer(Vec3(30.0f,0.0f,20.0f));
	createDefaultPlane();
	
	int num = 0;
	int size = 7;
	
	Mat4 transforms[0];
	for(int z = -size; z <= size; z++) {
		for(int y = -size; y <= size; y++) {
			for(int x = -size; x <= size; x++) {
				transforms.append(translate(Vec3(x,y,z + 7.5f) * 1.5f));
				num++;
			}
		}
	}
	
	ObjectMeshCluster cluster = addToEditor(new ObjectMeshCluster("samples/objects/meshes/mesh_00.mesh"));
	cluster.setMaterial(get_mesh_material(0),"*");
	cluster.setSurfaceProperty("surface_base","*");
	cluster.createMeshes(transforms);

   // moving meshes to the same positions
   // using setMeshTramsform method
   num = 0;
	for(int z = -size; z <= size; z++) {
		for(int y = -size; y <= size; y++) {
			for(int x = -size; x <= size; x++) {
				cluster.setMeshTransform(num, translate(Vec3(x,y,z + 7.5f) * 1.5f));
				num++;
			}
		}
	}

	
	setDescription(format("ObjectMeshCluster with %d intances",num));
	return 1;
}

 

ClusterDisappearing.jpg

Link to comment

Hi Corvax,

Internally, ObjectMeshCluster use it's own spatial tree for fast intersection & culling which is not updated when you call setMeshTransform. The reason it's designed that way is performance and it's assumed that you''ll use clusters for static geometry which does not move.

I think this might be improved by adding ObjectMeshCluster::updateSpatial methor or so. Can't give you any ETA for this though. As a workaround you can collect all mesh transforms into array and pass it to ObjectMeshCluster::createMeshes or ObjectMeshCluster::appendMeshes. These two methods will rebuild internal spatial tree.

Link to comment

Thanks, unclebob !

I've made a workaround by removing all meshes from cluster and recreating it at each update step. This gives a little perfomance drop, but no so critical.

Link to comment
  • silent changed the title to [SOLVED] ObjectMeshCluster disappearing, C++

Please note that I don't recommend to do this each frame because you won't be able to get any performance improvements with this approach for dynamic geometry. It's better to do it once to bake static geometry.

Link to comment
×
×
  • Create New...