Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by flanagak · Dec 05, 2016 at 07:32 AM · rotationgameobjecttransformmesh

How to rotate child 3D object to match bend of mesh

Another new developer to Unity here so I apologize if this approach makes no sense.

So I have a project with a single flat mesh which can be bent by the user. (Think like Virtual Desktop or BigScreen and changing the curvature of the desktop)

I have 2 separate 3D models that I placed on either side of the above noted mesh. In the project I made the 2 models children of the mesh in the hierarchy.

What I am trying to do is to re-position and rotate the models as the mesh bends so they stay at the edge of the mesh and their orientation rotates to match the bend. ( Imagine a piece of paper with a paper clip on either side lying flat on your desk. Now curl the paper until the paper clips touch each other. Or think of a belt with clips on each end bending around a single radius, eventually coming together )

How do I keep my model objects attached to the edge of the mesh and have them rotate as the mesh bends?

Thank you, --flanagak--

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Dec 05, 2016 at 12:59 PM 0
Share

It would be cool if you could include a simple image showing what you are trying to achieve. I can kinda see what you are looking for, but it'd be a shame to spent time on helping on the issue only to find out I misunderstood the question after all ;)

avatar image flanagak · Dec 05, 2016 at 02:42 PM 0
Share

Here are a couple of pictures to help explain.

What I am attempting to do is make the objects on either side of the blue mesh appear as thought they are clamped to the edge of the mesh.

So as the mesh bends and the edges curl towards the camera, the objects stay fixed at the edge of the mesh and rotate to match the bend.

example-01.png (211.4 kB)
example-02.png (148.7 kB)
avatar image Cherno flanagak · Dec 05, 2016 at 03:17 PM 0
Share

I can't think of an easy or elegant way to do it. You'd have to find one of the triangles along the edge, and use it's normal to set the position of the object. This could be done via Raycast (not ideal since it's on the very edge, and requires a collider), or purely via code.

avatar image Glurth · Dec 05, 2016 at 04:10 PM 0
Share

What method are you currently using to bend the mesh? Are you modifying each vertex? If so, I agree with Cherno. Except that I think you will probably want to use the cross product of the edge-vertex normal, and the direction to the next-edge-vertex: the result will be perpendicular to both.

avatar image flanagak · Dec 06, 2016 at 02:44 AM 0
Share

I am using the uDesktopDuplication project from GitHub. I have been using this for learning since I can be in VR and play around with objects in virtual space....

So I am not 100% sure how the mesh is being bent. From what I can tell it looks like it is being done in the shader. Though still new so not sure if this is whats actually doing the bending.

 inline void uddBendVertex(inout float3 v, half radius, half width, half thickness)
 {
 #ifdef BEND_ON
     half angle = width * v.x / radius;
     #ifdef _FORWARD_Z
     v.z *= thickness;
     radius += v.z;
     v.z -= radius * (1 - cos(angle));
     #elif _FORWARD_Y
     v.y *= thickness;
     radius += v.y;
     v.y += radius * (1 - cos(angle));
     #endif
     v.x = radius * sin(angle) / width;
 #else
     #ifdef _FORWARD_Z
     v.y *= thickness;
     #elif _FORWARD_Y
     v.z *= thickness;
     #endif
 #endif
 }
 
 inline float3 uddRotateY(float3 n, float angle)
 {
     float c = cos(angle);
     float s = sin(angle);
     return float3(c * n.x - s * n.z, n.y, s * n.x + c * n.z);
 }
 
 inline float3 uddRotateX(float3 n, float angle)
 {
     float c = cos(angle);
     float s = sin(angle);
     return float3(n.x, c * n.y + s * n.z, -s * n.y + c * n.z);
 }
 
 inline void uddBendNormal(float4 x, inout float3 n, half radius, half width)
 {
 #ifdef BEND_ON
     half angle = width * x / radius;
     #ifdef _FORWARD_Z
     n = uddRotateY(n, -angle);
     #elif _FORWARD_Y
     n = uddRotateX(n, -angle);
     #endif
 #endif
 }


avatar image Glurth flanagak · Dec 14, 2016 at 06:23 PM 0
Share

From what you posted, it looks like all the verticies are passed through that uddBendVertex function. Now, we need to deter$$anonymous$$e where those values are stored (after passing through that function), so you can use them to compute the placement of your other objects. The tricky part will then be deter$$anonymous$$ing WHICH of the vertices are the center edges we want: might just have to use trial and error.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to keep a Gameobject in the same position after a transform.Rotate? 2 Answers

GameObject Rotation is always postive 0 Answers

Neutralising child rotations -> Parent 1 Answer

Adding Rotation to a Gameobject 1 Answer

Why Local Rotation Faster than World Rotation (Degrees/Second) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges