Shrink-Wrap Constraint: Align to Normal (Option) #47440

Closed
opened 2016-02-16 17:10:27 +01:00 by Campbell Barton · 18 comments

Benefits: The ability to orient along the surface, so objects can be made to follow a surface without manually rotating.

Description: Currently the shrink-wrap constraint lets you snap one object onto the surface of another.
Aligning to normal would rotate the object as well, so it would be aligned to the geometry that its snapped to.
This should be a factor from 0 to 1 where 0.0 is not aligned and `1.0 is completely aligned.

Challenges:

  • Investigate good methods of defining an 'UP' axis, the direction defined by the original and snapped location may work well, or it may be necessary to support XYZ axis options for the user to specific what is up, (this may need some feedback from riggers).
  • For situations where a mesh will move across a surface, we will want to be able to (optionally) interpolate the vertex normals, so the object rotates smoothly as it moves across the mesh. This isn't essential for the initial quick-hack, however it would be worth investigating (we should be able to supported it, but will take some more work).
**Benefits:** The ability to orient along the surface, so objects can be made to follow a surface without manually rotating. **Description:** Currently the shrink-wrap constraint lets you snap one object onto the surface of another. Aligning to normal would rotate the object as well, so it would be aligned to the geometry that its snapped to. This should be a factor from `0 to 1` where `0.0` is not aligned and `1.0 is completely aligned. **Challenges:** - Investigate good methods of defining an 'UP' axis, the direction defined by the original and snapped location may work well, or it may be necessary to support XYZ axis options for the user to specific what is up, (this may need some feedback from riggers). - For situations where a mesh will move across a surface, we will want to be able to (optionally) interpolate the vertex normals, so the object rotates smoothly as it moves across the mesh. This isn't essential for the initial quick-hack, however it would be worth investigating *(we should be able to supported it, but will take some more work)*.
Author
Owner

Changed status to: 'Open'

Changed status to: 'Open'
Author
Owner

Added subscribers: @ideasman42, @JoshuaLeung, @BeornLeonard

Added subscribers: @ideasman42, @JoshuaLeung, @BeornLeonard

Added subscriber: @jbabbs

Added subscriber: @jbabbs

Added subscriber: @lhryniuk

Added subscriber: @lhryniuk

Added subscriber: @starintheuniverse

Added subscriber: @starintheuniverse
Masado Ishii self-assigned this 2016-08-03 22:45:33 +02:00
Masado Ishii was unassigned by Campbell Barton 2017-03-03 15:07:48 +01:00

Added subscriber: @Bleman

Added subscriber: @Bleman
Brian Leman self-assigned this 2017-10-18 12:35:50 +02:00

Am I ok to pick this task up please?

Am I ok to pick this task up please?

Hi @Bleman! I recently made a video demo of what my revision accomplishes. I added a link to the video in my revision summary: (https:*vimeo.com/234564499) (https:*developer.blender.org/D2154)
I hope it's helpful to you as you work on it! Cheers~

Hi @Bleman! I recently made a video demo of what my revision accomplishes. I added a link to the video in my revision summary: (https:*vimeo.com/234564499) (https:*developer.blender.org/D2154) I hope it's helpful to you as you work on it! Cheers~

Thanks for replying Masado Ishi. The video is really helpful thank you. :-)
I intend to work on this task within the next week.
i am going to be away from my computer for a few days but I will keep this post updated with any progress I make.
I am just preparing to download the blender source code and get setup with it so I can start the task.

Thanks for replying Masado Ishi. The video is really helpful thank you. :-) I intend to work on this task within the next week. i am going to be away from my computer for a few days but I will keep this post updated with any progress I make. I am just preparing to download the blender source code and get setup with it so I can start the task.

Added subscriber: @doublegamer26

Added subscriber: @doublegamer26

Hi. I would like to pick up this task if it is not being worked on. @starintheuniverse can you please elaborate what is it that exactly needs to be done here. I'm having some trouble understanding.

Hi. I would like to pick up this task if it is not being worked on. @starintheuniverse can you please elaborate what is it that exactly needs to be done here. I'm having some trouble understanding.

@doublegamer26: I didn't author the task, so at best I can explain my interpretation of what Campbell wrote. Do you have a specific question I might be able to help with? Also can I assume you are good with 3D math, and that you have also looked at the revision I submitted in Aug 2016?

I wonder how @Bleman is doing?

If you want to pick up where I left off, a possible first step would be to adapt the code I wrote to ensure it works with the newest version of Blender. My code revision was based on version 2.77. Blender has advanced by several versions since then.

Good luck!

@doublegamer26: I didn't author the task, so at best I can explain my interpretation of what Campbell wrote. Do you have a specific question I might be able to help with? Also can I assume you are good with 3D math, and that you have also looked at the revision I submitted in Aug 2016? I wonder how @Bleman is doing? If you want to pick up where I left off, a possible first step would be to adapt the code I wrote to ensure it works with the newest version of Blender. My code revision was based on version 2.77. Blender has advanced by several versions since then. Good luck!

@starintheuniverse I am a very new developer and hence, I am mostly looking for a direction in which I should proceed. I am well versed with 3d maths so that's not an issue. I did have a look at your revision.
Also, how do I replicate the simulation for my testing?

@starintheuniverse I am a very new developer and hence, I am mostly looking for a direction in which I should proceed. I am well versed with 3d maths so that's not an issue. I did have a look at your revision. Also, how do I replicate the simulation for my testing?

@doublegamer26 Very good, that's great. (Forewarning--I am also a new developer. This was the first task I submitted a revision for, and I have not been too active since then. Also note that I never received feedback on what I submitted. So again, my guess is little better than yours.) Here are my suggested steps, depending where you are starting from:

  • Make sure you can build Blender from source. (https://wiki.blender.org/index.php/Dev:Doc/Building_Blender). Also make sure you can efficiently search through the massive code base for names of functions that are not explained well in Blender's documentation.
  • To test your code as you write, I would recommend making a simpler scene, such as a sphere-surface and a stick-person. However, for you to replicate my video, I'll attach the blend file I made for it.This blend file includes a configuration for the Align-to-Normal settings in the Shrinkwrap constraint, though of course that setting will not even appear in your Blender until you change Blender's code and rebuild.
  • Look up the files that are modified in my revision, and make the corresponding modifications. The constraint.c file contains the workings of the constraint algorithms. The "DNA" and "RNA" have to do with defining Blender's data model and serialization. The .py script in bl_ui creates the settings in the UI panel. (I realize my inline comments are a bit cryptic. Let me know if sending a copy of my geometric analysis would be helpful.)
  • Now, finally, what needs to be done: Figure out how to get the vertex normal when the user has forced us into case MOD_SHRINKWRAP_NEAREST_VERTEX. Notice my comment /* XXX target mesh normal is not available from nearest when bvh tree made from verts. */ Finding out what a BVH tree is, and what kind of information is given by bvhtree_from_mesh_verts() or bvhtree_from_mesh_looptri(), was a tedious task. It involved probing the depths of Blender. Unfortunately I remember only what I made notes of; see below.
  • Plan how to extend the function to optionally interpolate over surface/vertex normals. Forward thinking here may change how you solve the above problem. For example, you may want to extract information about neighboring vertices/faces for interpolation. Conversely, the locations of neighboring vertices may help you manually calculate the current vertex normal as well. If you can knock out two birds with one stone, that's great.

Best of luck~

Shrinkwrap_SpikySuzanne.blend


Notes on BLI_bvhtree_find_nearest (in hopes of getting access to precomputed normals) (M. Ishii, 2016-08-15)

  • object_get_derived_final (in blenkernel/intern/DerivedMesh.c) returns either
    • ob->derivedFinal; or
    • ob->data->edit_btmesh->derivedFinal;
  • BLI_bvhtree_find_nearest calculates the projection of co onto each of the kdop axes, then invokes a dfs algorithm; utilizes data structure BVHNearestData. Returns an index (for a node?), with side effect on nearest.
  • dfs_find_nearest_dfs recursively runs down the bvh tree, selecting children by a distance calculation involving the above mentioned projection. In the recursive base case, data->callback is invoked with userdata, node->index, and fields inside data (co and nearest). If there is not a non-NULL callback, then nearest.index, nearest.dist_sq, and nearest.co are updated.
  • When shrinkwrap_get_tarmat invokes BLI_bvhtree_find_nearest, the user data is treedata, and the supplied callback is treedata.nearest_callback. These objects will have been prepared by a call to bvhtree_from_mesh_verts or a call to bvhtree_from_mesh_looptri.
  • bvhtree_from_mesh_verts (in blenkernel/intern/bvhutils.c) sets up a NULL nearest_callback; while bvhtree_from_mesh_looptri sets up a callback called mesh_looptri_nearest_point.
  • bvhtree_from_mesh_looptri supplies normals using a geometry function called normal_tri_v3 (See blenlib/intern/math_geom.c).
    • Presumably normal_tri_v3 calculates the normal of the plane determined by three points.
  • Conclusion: bvhtree_from_mesh_verts does not collect normals; there is no surface.
@doublegamer26 Very good, that's great. (Forewarning--I am also a new developer. This was the first task I submitted a revision for, and I have not been too active since then. Also note that I never received feedback on what I submitted. So again, my guess is little better than yours.) Here are my suggested steps, depending where you are starting from: - Make sure you can build Blender from source. (https://wiki.blender.org/index.php/Dev:Doc/Building_Blender). Also make sure you can efficiently search through the massive code base for names of functions that are not explained well in Blender's documentation. - To test your code as you write, I would recommend making a simpler scene, such as a sphere-surface and a stick-person. However, for you to replicate my video, I'll attach the blend file I made for it.This blend file includes a configuration for the Align-to-Normal settings in the Shrinkwrap constraint, though of course that setting will not even appear in your Blender until you change Blender's code and rebuild. - Look up the files that are modified in my revision, and make the corresponding modifications. The constraint.c file contains the workings of the constraint algorithms. The "DNA" and "RNA" have to do with defining Blender's data model and serialization. The .py script in bl_ui creates the settings in the UI panel. (I realize my inline comments are a bit cryptic. Let me know if sending a copy of my geometric analysis would be helpful.) - (Alternative to 3. which may or may not work) You could try to apply my revision using patch/diff, which are standard Unix utilities. (https://wiki.blender.org/index.php/Dev:Doc/Tools/Patches). If you go to [D2154: Shrink-Wrap Constraint: Align to Normal (Option) -- iteration 1](https://archive.blender.org/developer/D2154), then look on the right hand side of the page, there is a link to "Download Raw Diff"; the .diff file should be compatible with the patch/diff method. However, due to version differences (at the very least, line numbers will have likely changed), I can't say whether this will work. - **Now, finally, what needs to be done**: Figure out how to get the vertex normal when the user has forced us into case `MOD_SHRINKWRAP_NEAREST_VERTEX`. Notice my comment `/* XXX target mesh normal is not available from nearest when bvh tree made from verts. */` Finding out what a BVH tree is, and what kind of information is given by `bvhtree_from_mesh_verts()` or `bvhtree_from_mesh_looptri()`, was a tedious task. It involved probing the depths of Blender. Unfortunately I remember only what I made notes of; see below. - Plan how to extend the function to optionally interpolate over surface/vertex normals. Forward thinking here may change how you solve the above problem. For example, you may want to extract information about neighboring vertices/faces for interpolation. Conversely, the locations of neighboring vertices may help you manually calculate the current vertex normal as well. If you can knock out two birds with one stone, that's great. Best of luck~ [Shrinkwrap_SpikySuzanne.blend](https://archive.blender.org/developer/F1359970/Shrinkwrap_SpikySuzanne.blend) ---- Notes on BLI_bvhtree_find_nearest (in hopes of getting access to precomputed normals) (M. Ishii, 2016-08-15) - object_get_derived_final (in blenkernel/intern/DerivedMesh.c) returns either - ob->derivedFinal; or - ob->data->edit_btmesh->derivedFinal; - BLI_bvhtree_find_nearest calculates the projection of co onto each of the kdop axes, then invokes a dfs algorithm; utilizes data structure BVHNearestData. Returns an index (for a node?), with side effect on nearest. - dfs_find_nearest_dfs recursively runs down the bvh tree, selecting children by a distance calculation involving the above mentioned projection. In the recursive base case, data->callback is invoked with userdata, node->index, and fields inside data (co and nearest). If there is not a non-NULL callback, then nearest.index, nearest.dist_sq, and nearest.co are updated. - When shrinkwrap_get_tarmat invokes BLI_bvhtree_find_nearest, the user data is treedata, and the supplied callback is treedata.nearest_callback. These objects will have been prepared by a call to bvhtree_from_mesh_verts or a call to bvhtree_from_mesh_looptri. - bvhtree_from_mesh_verts (in blenkernel/intern/bvhutils.c) sets up a NULL nearest_callback; while bvhtree_from_mesh_looptri sets up a callback called mesh_looptri_nearest_point. - bvhtree_from_mesh_looptri supplies normals using a geometry function called normal_tri_v3 (See blenlib/intern/math_geom.c). - Presumably normal_tri_v3 calculates the normal of the plane determined by three points. - Conclusion: bvhtree_from_mesh_verts does not collect normals; there is no surface.

Added subscriber: @angavrilov

Added subscriber: @angavrilov

Is there any point in this task after e5b18390?

Is there any point in this task after e5b18390?

Probably not. It now certainly does what I was asking for when Campbell created this task.

Probably not. It now certainly does what I was asking for when Campbell created this task.
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
9 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#47440
No description provided.