-
Notifications
You must be signed in to change notification settings - Fork 69
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
Update object degradation tutorial; rename fouling_rating to distort_extent #185
Conversation
…gs. Rename fouling_rating in [0, 100] in mesh distortion to distort_extent in [0, 1]. Signed-off-by: Mabel Zhang <mabel@openrobotics.org>
Is it correct that the current subdivision level from 0~4 is the number of operations to divide an edge into two with a mid vertex? Are there methods we can define the density of the random vertexes generated by subdivision? Something like max edge lengths? (Still discussing what we need. No need to include in this PR :)) |
I played with it a bit on a cylinder and a cube, and it does look like what you described. Blender's official description doesn't say too much about the mathematical operation. "The Subdivision Surface modifier (often shorten to “Subdiv”) is used to split the faces of a mesh into smaller faces, giving it a smooth appearance." For the "Simple" mode, which is the current mode in the script, it "Only subdivides the surfaces, without any smoothing." For a cylinder, the top/bottom cap looks like this: |
Hmm there might be a way to script that, although I don't know if edge length can be a parameter to easily control. References: |
You didn't ask about this, but I guess you've already seen it and that's why you mentioned bump height in the meeting today:
|
Yes, the script you've made can designate offset (=bump height) magnitude (while they are also random). but cannot control the density. I was just asking for the density to calculate statistics for the minimum mesh edge length which would lead to average normal angles. Hmm |
The edge length could vary a lot depending on where you are on the mesh. With a cylinder, the edges of the circles are very small, while the edges on the wall can be very long for e.g. a pipe. Do you just want the normals? Blender has other ways to get the normals, e.g. https://docs.blender.org/api/current/bpy.types.Mesh.html |
Don't understand how the screenshot you've shown is possible. Maybe because it went through the process What I would like to have is some statistics on how much the mean normals have deviated from the original object shape. I was imagining the Or maybe we could ditch I think |
To clarify, the screenshot I showed in the meeting came straight from a single operation of vertex randomization. Nothing else. There's no subdivide happening. I made a short video below to show exactly what I mean. Blender's documentation doesn't talk about exactly how they do the randomization - that's beyond an artist's interest. We'd have to look at the source code to see how they do it. Judging from the result though, it seems it's a randomized offset of existing vertices. So if you have one vertex offset 0.1 m in one direction, and a consecutive vertex 0.1 m in the opposite direction, then you can get a 180 degree angle. Let's move the normals discussion to a separate issue, since it's turning out to be a longer thread. You or I can open an issue (update: issue opened #187). I'll look more into what data it can give us. Let's get this PR reviewed and merged first. It's pretty minimal code change, mostly documentation. Do you have the setup to review it? If not, I could re-tag Jessica for the review. Video of just vertex randomization on a stock cylinder object (radius 1 m, height 1 m), no other modifications: 2022-02-03-21-36_Blender_cylinder_randomVertices.mp4The ones I showed in the meeting for reference: vertex randomization offset 0.1: offset 1 m (same magnitude as cylinder radius and height, 1 m): |
@mabelzhang I have time this morning - I'll get the review done. I accidentally updated Blender so I can check if it works on version 3.x and downgrade my computer afterwards for the review... whoops! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mabelzhang One thing I'd recommend fixing: When running the tutorial as written, blender crashes (both 3.x and 2.92) - the issue is with passing the distort_extent value of 20 with 'subdiv_mod' as the method. Could you change the tutorial to read "distort_extent = 0.2"? It was a little hard to troubleshoot because the crash happens without any feedback, so it might also be good to do a value check on the input.
A few other tiny things that I tripped over - the method variable has to be specified as an array, even if it's only one item, which would be helpful to note for non-Python users, and when you specify the path, it shouldn't have a leading '/' - at least, on my computer. Change or ignore at your discretion :)
Signed-off-by: Mabel Zhang <mabel@openrobotics.org>
Yes! Thank you for retesting and finding that crash. I'm always looking to make my code as robust as possible, but I had not done enough checks in this prototype. Updated in e176ffd
Updated in README and in code in e176ffd
Are you using a relative path? I use absolute path for mine with a leading |
Looks good at first review - I'll run it once more when I get back to the other computer and approve. Now there's no way for me to get it wrong... :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we should change fouling_rating
to distort_extent
at coke_template.erb
fouling_rating = 10 |
dave/urdf/scripts/sdf_custom_properties/coke_template.erb
Lines 92 to 93 in 9eaee7f
<surface_props:biofouling_rating><%= fouling_rating %></surface_props:biofouling_rating> | |
<surface_props:roughness><%= fouling_rating * 0.01 %></surface_props:roughness> |
Another minor suggestion is add a link to 2.92 blender downloads: https://download.blender.org/release/Blender2.92/
So, at the current state, a distorted mesh obj file is created when the python script for a blender is performed. Then, Ruby erb script is used to make an sdf. Could we link these procedures into one? (this may be another PR or an issue).
I've used python script and template to produce a complete set of a model object by putting all necessary files into a separate model directory with mesh, texture, and sdf when generating dissected bathymetry tiles. I may be able to reconstruct and link two procedures into one using the python console on the blender. (S-size task) This maybe useful when linking the distort extent
to automatically calculate and write a custom SDF tag for plugins.
If you want to give it a peek about how it's done (uses linux sed
function with os.system
),
method = ['subdiv_mod', 'vert_rand', 'edge_subdiv'] | ||
``` | ||
|
||
Put the args into the input array: | ||
``` | ||
import sys | ||
sys.argv = ['distort.py', file_path, object_prefix, fouling_rating, method] | ||
sys.argv = ['distort.py', file_path, object_prefix, distort_extent, method] | ||
``` | ||
|
||
Run the script, replacing its path with the one on your machine: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path description in the distorted mesh's mtl
file uses absolute
path. The original coke.mtl
wrote map_Kd ../materials/coke.png
. The distorted file produced by the distort.py script writes map_Kd C:\\Users\\woens\\Downloads\\MeshDistortion\\Coke\\materials\\coke.png
. I think it would be better to keep to the relative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I added a path_mode='RELATIVE'
for the OBJ export, which exposed that in the API https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.obj 5f7030b
Side note: The COLLADA export (bpy.ops.wm.collada_export
) though doesn't have that in the API. We aren't using that right now, as it doesn't export textures correctly, so it shouldn't affect the instructions. I added a TODO item above that line.
@mabelzhang I ran the code again and couldn't break it! Looks good from the script perspective. @woensug-choi made a good point about updating the demo erb and the custom_surface_properties_plugin to match the new terminology and ranges here - do you want to add those updates to this PR or are they coming separately? |
…export relative path for OBJ material file; clarify README Signed-off-by: Mabel Zhang <mabel@openrobotics.org>
I believe 5f7030b addresses the comments. I debated when I opened the PR whether to rename the fouling parameter in
I added the link. I also reworded the README to clarify this, because the link looks like a raw folder that users shouldn't go to. They don't necessarily need 2.92. It is not a LTS, so I don't want to recommend that specific version; it's just the version I've tested in. 2.93 is LTS but I haven't tested there. The instructions should work for newer versions. The mentioning of 2.92 is because the Blender UI changed significantly in 2.92, so item locations, shortcuts, etc. as written might not work for older versions. They should work for newer versions though.
I don't know if that's possible, because the Blender Python script is executed from a Python interpreter within the Blender GUI, whereas the Ruby script is run on the command line, outside Python. I also don't know whether it's desirable to couple the two scripts. They take different parameters. The mesh distortion script is an artistic process for a general model file, whereas the SDF Ruby template is a physical process specific to parameters that will affect results in Gazebo. We happen to have the biofouling rating in both, but you can see they weren't the same name (now they are, but) as the two scripts weren't intended to be coupled. Somebody could add any custom SDF tags to their file, like material properties, with or without distortion. The fouling / distort SDF tag is just an example to illustrate the users can add whatever they want. If the user doesn't have any distortion, then there's really no relation between the two scripts to warrant linking them. Right now, it doesn't take too much effort for us to put in the same distort value for both. I don't know if it'll be worth the effort to link them. I also think that's something we can leave up to the user to do, as opposed to handling in DAVE. Less relevant, but when we upstream these two scripts, they will live in different repos. One will be in an SDF repo, and the other will be in |
FYI, @mabelzhang I've updated the multibeam sonar repo for the duplicate model directory. It's not in SDF file structure but a bare OBJ and MTL files now in the |
I tagged @j-herman (because you've run this in the past) or @woensug-choi (because you're looking into this now) for review. Only one is needed.
The current SDF tags are just dummy examples. @woensug-choi if you find more suitable terminology, feel free to update the example - remember to also update the Gazebo C++ plugin, see README section "To add new custom tags". Alternatively, just use whatever you like in the multibeam sonar plugin and the SDF it loads.
fouling_rating
variable in range [0, 100] todistort_extent
, now in range [0, 1]. This follows the discussion that we don't care about actually adhering to the navy fouling scale. It's now just an arbitrary relative scale.To test
Follow the mesh README to run the mesh modification script in Blender 2.92 and make sure it still works after the variable name change.