Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pybullet.addUserDebugPoints #3996

Merged
merged 3 commits into from
Mar 7, 2022

Conversation

wkentaro
Copy link
Contributor

2021-10-14_20-24-42.mp4
2021-10-14_20-25-12.mp4

@wkentaro wkentaro force-pushed the addUserDebugPoints branch 4 times, most recently from 267b24e to e7460f1 Compare October 15, 2021 16:11
@@ -1926,6 +1936,7 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float color[
break;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can anyone help to add colors to this efficient batch rendering of the points?
At the moment, it uses glUniform4f to change color of points, which makes hard to have different color for each point.
(so current implementation draw each point one-by-one with changing color by glUniform4f, which is slow)

#if 1
// FIXME: this is slow. cannot draw with color efficiently
for (int i = 0; i < numPoints; i++) {
glUniform4f(lines_colour, colors[4 * i + 0], colors[4 * i + 1], colors[4 * i + 2], colors[4 * i + 3]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glUniform4f for changing the color of the point.

glBufferSubData(GL_ARRAY_BUFFER, 0, pointStrideInBytes, positions + i * (pointStrideInBytes / sizeof(float)));
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, pointStrideInBytes / sizeof(float), GL_FLOAT, GL_FALSE, pointStrideInBytes, 0);
glDrawArrays(GL_POINTS, 0, 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why points are drawn one-by-one, which is slow.

@wkentaro wkentaro force-pushed the addUserDebugPoints branch 3 times, most recently from 8fc3c18 to 9e73df2 Compare October 16, 2021 13:39
@wkentaro
Copy link
Contributor Author

Managed the efficient colored points rendering.

2021-10-16_14-43-30.mp4

@erwincoumans
Copy link
Member

Very nice, thanks for the contribution. I will check it, make sure it still works on various platforms.

Some minor suggestions:

Please add fields in 'examples/SharedMemory/SharedMemoryCommands.h' at the end of a structure, to avoid crashes when using different versions. In particular, UserDebugDrawArgs, add m_debugPointNum and m_pointSize as last new members, not in the middle of the struct.

Change comment from

"Add a user debug draw point

to

"Add user debug draw points

@erwincoumans
Copy link
Member

erwincoumans commented Nov 14, 2021

Thanks for the fixes! One last request, do you have a simple example python script how to use it? You could reply with a zipped attachment (zip files work, other extension often don't).

@wkentaro
Copy link
Contributor Author

Does this work for you? my_example.zip

pip install trimesh[easy]
python example_01.py

Screen Shot 2021-11-14 at 12 08 09

@erwincoumans
Copy link
Member

Thanks for the example. Close/re-open to re-trigger CI.

@erwincoumans erwincoumans reopened this Mar 7, 2022
@erwincoumans
Copy link
Member

LGTM, let's merge the PR. Thanks for the contribution!

@erwincoumans erwincoumans merged commit a8e1ce8 into bulletphysics:master Mar 7, 2022
@wkentaro wkentaro deleted the addUserDebugPoints branch March 7, 2022 08:38
@wkentaro
Copy link
Contributor Author

wkentaro commented Mar 7, 2022

Great! 👍

@erwincoumans
Copy link
Member

tested with pybullet 3.22 (pip install pybullet) and it works:
Screenshot from 2022-03-25 21-45-29

@erwincoumans
Copy link
Member

There is a regression in line drawing. Not clear if this is related to this PR, but if so, we may have to revert it until fixed:

image

I will check if reverting this PR fixes it.

erwincoumans added a commit that referenced this pull request Apr 23, 2022
fix for debug lines / point rendering, introduced in PR #3996
@erwincoumans
Copy link
Member

A minor note: to improve file loading in PyBullet, disable rendering before, and re-enable rendering after loading:

p.connect(p.GUI)
p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0)

root_dir = "YCB_Video_Models"
for i, model_dir in enumerate(os.listdir(root_dir)[:10]):
    model_dir = osp.join(root_dir, model_dir)
    obj_file = osp.join(model_dir, "textured_simple.obj")
    mesh = trimesh.load_mesh(obj_file)
    mesh.apply_translation([i * 0.2 - 1, 0, 0])
    points = mesh.vertices
    colors = mesh.visual.to_color().vertex_colors
    p.addUserDebugPoints(points[:5000], colors[:5000, :3] / 255)

p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,1)

@WhomightIB
Copy link

Yup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants