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 SkandYxyz · Jan 29, 2016 at 05:04 PM · meshresourcesquadprimitives

Load default quad mesh from resources

Hi!

Is it possible to load the primitive quad mesh from resources? Something like this:

 // Load default quad mesh
 Mesh _quadMesh = Resources.Load("Quad",typeof(Mesh)) as Mesh;


Thank you in advance!

best, Andre

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
2
Best Answer

Answer by SkandYxyz · Jan 29, 2016 at 05:41 PM

It seems that the shortest way to do this is to write a script that generates a quad from scratch. Here is a script that I found:

 using System;
 using UnityEngine;
 using UnityEditor;
 
 public class CreateQuadMesh : Editor {
   
     [MenuItem("Assets/Create/Quad Mesh", false, 10000)]
     public static void Create ()
     {
         Mesh mesh = BuildQuad (1, 1);
         string name = "Quad Mesh";
         mesh.name = name;
         AssetDatabase.CreateAsset (mesh, String.Format ("Assets/{0}.asset", name));
         EditorUtility.FocusProjectWindow ();
         Selection.activeObject = mesh;
     }
     
     private static Mesh BuildQuad (float width, float height)
     {
         Mesh mesh = new Mesh ();
         
         // Setup vertices
         Vector3[] newVertices = new Vector3[4];
         float halfHeight = height * 0.5f;
         float halfWidth = width * 0.5f;
         newVertices [0] = new Vector3 (-halfWidth, -halfHeight, 0);
         newVertices [1] = new Vector3 (-halfWidth, halfHeight, 0);
         newVertices [2] = new Vector3 (halfWidth, -halfHeight, 0);
         newVertices [3] = new Vector3 (halfWidth, halfHeight, 0);
         
         // Setup UVs
         Vector2[] newUVs = new Vector2[newVertices.Length];
         newUVs [0] = new Vector2 (0, 0);
         newUVs [1] = new Vector2 (0, 1);
         newUVs [2] = new Vector2 (1, 0);
         newUVs [3] = new Vector2 (1, 1);
         
         // Setup triangles
         int[] newTriangles = new int[] { 0, 1, 2, 3, 2, 1 };
         
         // Setup normals
         Vector3[] newNormals = new Vector3[newVertices.Length];
         for (int i = 0; i < newNormals.Length; i++) {
             newNormals [i] = Vector3.forward;
         }
         
         // Create quad
         mesh.vertices = newVertices;
         mesh.uv = newUVs;
         mesh.triangles = newTriangles;
         mesh.normals = newNormals;
         
         return mesh;
     }
 }

Comment
Add comment · Show 1 · 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
avatar image andrew-lukasik · Jun 15, 2018 at 05:22 PM 0
Share

You can! Check this amazing answer by @Bunny83

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

37 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

Related Questions

Create grid of points inside irregular quad. 1 Answer

Is it possible to set a Mesh Filter's Mesh property to quad in code? 1 Answer

Procedual quad doesnt display texture - only single color 1 Answer

Get Vertice of a Quad (two tris) via raycast? 0 Answers

Mesh's corners are not where it's supposed to be 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