Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Lvl1Lasagna · Mar 21, 2021 at 01:17 AM · meshesmeshfiltermesh renderermesh manipulation

Imported model's mesh reading differently than built-in unity meshes

I'm trying to make a system that can smoothly blend one mesh into another mesh. It works great for the built-in unity meshes (sphere, cube, cylinder, and capsule), but absolutely goes mad when I try to do so to an imported fbx file from blender.

My thought is that the imported fbx meshes are rendered differently, but I've been unable to find that information anywhere if it is the case.

Here is the code I'm using to convert the meshes to something usable by me.

 public Vector3[] ConvertMeshVerticesToSphericalCast(Vector3[] sphereVertices, Vector3[] meshToConvertVertices, int[] meshToConvertTriangles)
     {
         // Return vertices
         Vector3[] castVertices = new Vector3[sphereVertices.Length];
         // Current index of the 
         int index = 0;
         foreach (Vector3 sphVert in sphereVertices)
         {
             Vector3 rayDir = sphVert.normalized;
             float smallDist = float.MaxValue;
             for (int i = 2; i < meshToConvertTriangles.Length; i+=3)
             {
                 // Get each of the points of this triangle
                 Vector3 qA = meshToConvertVertices[meshToConvertTriangles[i - 2]];
                 Vector3 qB = meshToConvertVertices[meshToConvertTriangles[i - 1]];
                 Vector3 qC = meshToConvertVertices[meshToConvertTriangles[i]];
                 // Calculate normal of the triangle
                 Vector3 triN = -Vector3.Cross((qA - qC), (qB - qC)).normalized;
 
                 // Get the denominator first to avoid dividing by 0
                 float denom = Vector3.Dot(triN, rayDir);
                 if (Mathf.Abs(denom) > Mathf.Epsilon)
                 {
                     // Get the center of the plane
                     Vector3 qCenter = (1.0f / 3) * (qA + qB + qC);
                     // Get the distance from the plane the current vertex is
                     float t = Vector3.Dot((qCenter - sphVert), triN) / denom;
                     // If the distance is positive and smaller than the current smallest, its the new smallest
                     if (t >= 0 && t < smallDist)
                     {
                         smallDist = t;
                     }
                 }
             }
             // Use the distance to update the 
             castVertices[index] = smallDist * rayDir + sphVert;
 
             ++index;
         }
         return castVertices;
     }



Comment
Add comment
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

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

156 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Terrain tree from 2 crossed sprites/quads 1 Answer

Strange lighting behaviour when generating a mesh. 0 Answers

I need help in "stretching an object like rubber" in Unity3D 0 Answers

Unexpected vertex amount when importing .blend file 0 Answers

How to combine meshes for trees 0 Answers


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