Drawing a very large number of items

Typically: "How do I... ", "How can I... " questions
Post Reply
pr0t0z
Posts: 19
Joined: 21 Nov 2014, 17:29

Drawing a very large number of items

Post by pr0t0z » 10 May 2018, 13:06

Hey!

I am working in a project to simulate a 5-axis printer.

Everything is working as intended, including the part where I simulate the material deposition. So I am using a single simAddDrawingObject and then adding simAddDrawingObjectItem (Cubes for best performance) to create a continuous stream of elements, that in the end resemble a 'filament'.

The only problem I still couldn't work around has to do with the fact that some pieces require a huge quantity of items to draw. Inevitably the rendering grows ever slower as this number increases to the point that the simulator can barely move.

I am contemplating strategies that may help me cope with this problem, I got the number of items to draw in a 'filament' to the minimum without discontinuities. I was hoping that perhaps you could give me some suggestions on how to tackle this problem. Perhaps working with more DrawingObjects? Or tweaking some OpenGL parameters?

Thanks in advance!

Carlos

coppelia
Site Admin
Posts: 6683
Joined: 14 Dec 2012, 00:25

Re: Drawing a very large number of items

Post by coppelia » 11 May 2018, 08:15

Hello Carlos,

yes, this can be problematic. You can probably do this faster via following (not tested):

start using drawing objects, and memorize them all. Once you have drawn 10000 items or so, remove them, and create a shape that contains those 10000 items. etc. My guess is that displaying a larger shape is faster than displaying thousands of small items (the rendering routines are also different). Also, shapes that are not in the field of view are not rendered at all (view frustum culling).

For that you will have to use sim.createMeshShape.

Cheers

coppelia
Site Admin
Posts: 6683
Joined: 14 Dec 2012, 00:25

Re: Drawing a very large number of items

Post by coppelia » 11 May 2018, 08:17

And maybe you could also have a look at octrees and the demo scene scenes/octreeGenerationDemo.ttt

Cheers

pr0t0z
Posts: 19
Joined: 21 Nov 2014, 17:29

Re: Drawing a very large number of items

Post by pr0t0z » 11 May 2018, 15:21

Hey!

Thanks for the quick reply as always!

Octrees are a very powerful structure, more than this particular problem, it may help me with the physics part of my problem, as I also wanted to have some sort of collision detection during printing.
I did a quick test, with this structure in a sample scene, and I think I got it.

- About octrees, I believe 1mm is the minimum possible voxel size, correct?
- I am working with a printing volume of around 575*520*335mm, which gives around 100,000,000 voxels... The simulations I am running only take up to 10/15% of this space at most, but it is still a very, very large number of entities in a octree, and I feel I will run into the same predicament since we are still drawing voxels as DrawingItems (with 15000 items, the rendering takes up to 90ms).
- I think I might find this still useful down the road, by creating a coarse grid, so I can do some collision detection.

Atm, I think my best shot is to create a mesh as you suggested. Maybe you can help me understand a little better the interface of sim.createMeshShape. I found this forum post, viewtopic.php?t=5618, and I feel I have a similar problem, since I am basically adding 'cube' Items based on a stream of consecutive points, in other words, a point cloud.

This post is from 2016, so I don't know if there has been any update. Assuming the problem is similar, maybe I should take a look at PCL to do this pointcloud -> mesh operation (http://pointclouds.org/documentation/tu ... ection.php). I haven't tried this yet, but I think retrieving the vertices and indices shouldn't be a problem.

Cheers,

coppelia
Site Admin
Posts: 6683
Joined: 14 Dec 2012, 00:25

Re: Drawing a very large number of items

Post by coppelia » 15 May 2018, 08:19

You will have to individually draw all triangles that form a cube, for each cube you want to include into your shape with sim.createMeshShape. That requires a bit of code and execution of that code will take some time. But once the shape is generated, performance is probably better. You will have to try. Here to create a shape with a single triangle:

Code: Select all

sim.createMeshShape(0,0,{0,0,0,0,0.1,0,0,0.1,0.1},{0,1,2})
Cheers

Post Reply