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 /
  • Help Room /
avatar image
0
Question by SolvaterG · Aug 21, 2016 at 02:56 PM · prefabimportblendergenerator

How to fix this cube ?

I have imported cube with texture from Blender and it imports like that.alt text When I place it, it looks normal, but when I generate it through the code it appears like in the inspector.

1.png (45.8 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Monkiman300 · Aug 22, 2016 at 10:34 AM

You would need the following script. I dont remember where I got it from, but it makes the Blender models right side up for me. Just make sure to put it in the "Editor" folder and whatnot.

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 using System.IO;
 using System.Linq;
 
 
 public class BlenderAssetProcessor : AssetPostprocessor {
     public void OnPostprocessModel(GameObject obj  )
     {
 
         //only perform corrections with blender files
 
         ModelImporter importer = assetImporter as ModelImporter;
         if (Path.GetExtension(importer.assetPath) == ".blend")
         {
             RotateObject(obj.transform);
         }
 
         //Don't know why we need this...
         //Fixes wrong parent rotation
         obj.transform.rotation = Quaternion.identity;
     }
 
     //recursively rotate a object tree individualy
     private void RotateObject(Transform obj  )
     {
         Vector3 objRotation = obj.eulerAngles;
         objRotation.x += 90f;
         obj.eulerAngles = objRotation;
 
         //if a meshFilter is attached, we rotate the vertex mesh data
         MeshFilter meshFilter = obj.GetComponent(typeof(MeshFilter)) as MeshFilter;
         if (meshFilter)
         {
             RotateMesh(meshFilter.sharedMesh);
         }
 
         //do this too for all our children
         //Casting is done to get rid of implicit downcast errors
         foreach (Transform child in obj)
         {
             RotateObject(child);
         }
     }
 
     //"rotate" the mesh data
     private void RotateMesh(Mesh mesh)
     {
         int index = 0;
 
         //switch all vertex z values with y values
         Vector3[] vertices = mesh.vertices;
         for (index = 0; index < vertices.Length; index++)
         {
             vertices[index] = new Vector3(vertices[index].x, vertices[index].z, vertices[index].y);
         }
         mesh.vertices = vertices;
 
         //for each submesh, we invert the order of vertices for all triangles
         //for some reason changing the vertex positions flips all the normals???
         for (int submesh = 0; submesh < mesh.subMeshCount; submesh++)
         {
             int[] triangles = mesh.GetTriangles(submesh);
             for (index = 0; index < triangles.Length; index += 3)
             {
                 int intermediate = triangles[index];
                 triangles[index] = triangles[index + 2];
                 triangles[index + 2] = intermediate;
             }
             mesh.SetTriangles(triangles, submesh);
         }
 
         //recalculate other relevant mesh data
         mesh.RecalculateNormals();
         mesh.RecalculateBounds();
     }
 }
Comment
Add comment · Share
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

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

90 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

Related Questions

Instantiate a prefab of a Blender model w/ Behavior that supports changes to model 0 Answers

Imported Models Not Rendering Correctly? 5 Answers

Normal map seams 0 Answers

Blender to Unity armature not in correct place... 1 Answer

Can faces be made visable from both sides on assets from blender. 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