• 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 Phobos001 · Apr 17, 2018 at 04:53 PM · meshprogramminguv

Quake Texture Map Generation in Unity - What am I doing wrong?

Hello! I am working on integrating TrenchBroom .map files in Unity, but I have a problem with generating the correct UVs for each brush. Basically after making the geometry, I go over each Brush, and then each BrushPlane and do this:

 Vector3 normal = Vector3.Cross(plane.p3 - plane.p1, plane.p2 - plane.p1);
 if (normal == Vector3.zero) continue;
 Quaternion rotation = Quaternion.Inverse(Quaternion.LookRotation(normal));
 
 Vector2 matScale = (new Vector2(plane.material.mainTexture.width, plane.material.mainTexture.height));
 matScale.x *= plane.uvScale.x;
 matScale.y *= plane.uvScale.y;
 matScale *= QMC.QUAKE_TO_UNITY_SCALE;
 Vector2 offset = plane.uvOffset; // not actually applying the offset yet.
 
 Vector3 upAxis, rightAxis; // Uses ported code from QBSP but doesn't seem to do anything
 upAxis = QMC.TextureAxisFromPlane(normal, false);
 rightAxis = QMC.TextureAxisFromPlane(normal, true);
 
 uvs = new Vector2[verticies.Length];
 for (int i = 0; i < uvs.Length; i++) {
     Vector3 v = (rotation*verticies[i]); // Makes vertex flat against the XY axis
     float s = (Vector3.Dot(v, rightAxis)) / matScale.x;
     float t = (Vector3.Dot(v, upAxis)) / matScale.y;
     Vector2 uv = new Vector2(s, t);
     uv = Quaternion.Euler(0, 0, plane.uvAngle) * uv; // Is supposed to rotate the uv but also doesn't do anything
     uvs[i] = uv;
 }

TextureAxisFromPlane is stolen from QBSP's source:

 // Stolen from QBSP
         private static readonly Vector3[] QBSP_BASE_AXIS = new Vector3[] {
             Vector3.forward, Vector3.right, -Vector3.up, // Floor
             -Vector3.forward, Vector3.right, -Vector3.up, // Ceiling
             Vector3.forward, Vector3.up, -Vector3.forward, // West Wall
             -Vector3.right, Vector3.up, -Vector3.forward, // East Wall
             Vector3.up, Vector3.right, -Vector3.forward, // South Wall
             -Vector3.up, Vector3.right, -Vector3.forward // North Wall
         };
 
         public static Vector3 TextureAxisFromPlane(Vector3 normal, bool isRightAxis)
         {
             int    bestaxis = 0;
             float dot, best = 0;
             
             best = 0;
             bestaxis = 0;
             
             for (int i = 0; i < 6; i++)
             {
                 dot = Vector3.Dot (normal, QBSP_BASE_AXIS[i*3]);
                 if (dot > best)
                 {
                     best = dot;
                     bestaxis = i;
                 }
             }
             
             Vector3 final;
             if (isRightAxis)
                 final = QuakeToUnityVectorNoScaling(QBSP_BASE_AXIS[bestaxis*3+1]);
             else
                 final = QuakeToUnityVectorNoScaling(QBSP_BASE_AXIS[bestaxis*3+2]);
 
             return final;
         }

It works on most surfaces, but on ones that are parallel with the Y axis are streched like its using a box projection:

alt text

Can someone that knows about this stuff more than I do help me? I've been wracking my brain trying to figure this out. Thank you again for your time! :)

help-me-2.jpg (449.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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

92 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

Related Questions

Multiple Cars not working 1 Answer

issues with mobile build 0 Answers

How do I get mesh data into post-processing shader (or render a mesh shader to a texture)? 0 Answers

Creating a mesh programatically for a tile-based 2D game 1 Answer

Normalizing mesh UVS? 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