Developing a Process for Automating UV Mapping and Polygon Reduction
Total Page:16
File Type:pdf, Size:1020Kb
Linköping University | Department of Computer and Information Science Bachelor’s Thesis | Computer Science Spring Term 2016 | LIU-IDA/LITH-EX-G--16/063—SE Developing a process for automating UV mapping and polygon reduction Julius Willén Tutor, Ivan Ukhov Examinator, Petru Ion Eles Upphovsrätt Detta dokument hålls tillgängligt på Internet – eller dess framtida ersättare – under 25 år från publiceringsdatum under förutsättning att inga extraordinära omständigheter uppstår. Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat för ickekommersiell forskning och för undervisning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av dokumentet kräver upphovsmannens medgivande. För att garantera äktheten, säkerheten och tillgängligheten finns lösningar av teknisk och administrativ art. Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsmannens litterära eller konstnärliga anseende eller egenart. För ytterligare information om Linköping University Electronic Press se förlagets hemsida http://www.ep.liu.se/. Copyright The publishers will keep this document online on the Internet – or its possible replacement – for a period of 25 years starting from the date of publication barring exceptional circumstances. The online availability of the document implies permanent permission for anyone to read, to download, or to print out single copies for his/hers own use and to use it unchanged for non- commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional upon the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authenticity, security and accessibility. According to intellectual property law the author has the right to be mentioned when his/her work is accessed as described above and to be protected against infringement. For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its www home page: http://www.ep.liu.se/. © Julius Willén Link¨opingUniversity Abstract An exploratory research project was conducted through a company focusing on CAD and their own developed real-time 3D model viewer. The company needed to be able to convert CAD models to use in Unreal Engine with great visual quality. Before this project, another was conducted to perform the simple conversion of CAD models to the FBX file format, which Unreal uses. In ex- tension to the previous project, one needed to add functionalities to manipulate the models for better quality and performance. The tasks were carried out and performed with good results. Page 1 Link¨opingUniversity Acknowledgements I would like to thank XperDi and all the people working there, more specifically; Mehdi Tarkian, Leon Poot and Manokar Munisamy, along with the students that performed their master's thesis during the spring of 2016. Page 2 Contents 1 Introduction 6 1.1 Background . .6 1.1.1 Research questions . .7 1.2 Methodology . .7 1.2.1 Analysis . .7 1.2.2 Program design . .7 1.2.3 Coding . .8 1.2.4 Testing . .8 1.3 The file formats . .9 1.3.1 STEP . .9 1.3.2 Wavefront's .obj . .9 1.3.3 FBX . 10 2 UV mapping 11 2.1 Prestudy . 11 2.2 Method . 11 2.2.1 Blender . 12 2.3 Implementation . 13 2.4 Results . 14 3 Polygon reduction 15 3.1 Prestudy . 15 3.2 Theory . 15 3.2.1 Calculating the cost . 16 3.2.2 Collapsing the vertices . 16 3.3 Implementation . 19 3.4 Results . 21 3.4.1 Testing method . 21 3.4.2 The Stanford bunny . 21 3.4.3 Visual differences . 22 3.4.4 Data collection . 23 3 CONTENTS Link¨oping University 4 Discussion 25 4.1 Results . 25 4.1.1 UV mapping . 25 4.1.2 Polygon reduction . 25 4.2 Method . 26 4.2.1 Replicability, Reliability and Validity . 26 4.3 The work in a wider context . 26 4.4 Conclusion . 27 4.4.1 Answer to the first research question . 27 4.4.2 Answer to the second research question . 27 4.4.3 Answer to the third research question . 27 4.4.4 Future work . 28 List of Figures 31 Page 4 Glossary Blender Is an open source 3D editing software and game engine. 11 C++ Is a cross platform programming language developed by Bjarne Strous- trup in 1979. 8 CAD Is a type of computer program that allows for the design of models and their documentation. 6 face Is a number of connected vertices, in this thesis a face is equal to a triangle. 15 mesh Is the outer bounds, or surface, of a 3D model which consists of vertices, edges and triangles. 15 Microsoft Visual Studio 2013 Is an Integrated Development Environment for aiding software developers in their programming. 8 Notepad++ Is an advanced text editor to be used for manipulating and de- veloping code in multiple languages. 8 polygon Is the building block of 3D modeling. 15 Python Is a dynamic programming language developed by Guido van Rossum. 8 Roadkill UV tool Is an open source 3D editing software. 11 Unreal Engine 4 Is a version of the game engine called Unreal Engine, devel- oped by Epic Games. 6 vertex Is a geometrical point consisting of the coordinates x, y and z. 15 vertices Is the plural form of vertex. 15 5 Chapter 1 Introduction 1.1 Background XperDi is a start-up company that is in the development phase of two software tools; a CAD configurator and a sales configurator. The CAD configurator is a tool, or plug-in, for already established CAD programs such as Creo or Solidworks, which helps users to create extensive models of different types and configurations quickly and efficiently. These models can then be viewed in the sales configurator, which is developed with Unreal Engine 4, to show them in a more photo realistic environment than what is commonly used in CAD programs, with different textures and lighting. Since the standard CAD file types are not supported in Unreal, there has to be a conversion which allows the sales configurator to actually be able to show the models that the user has created. This conversion has been developed as another bachelor's thesis in the fall of 2015, by Rasmus Siljedahl at Link¨oping University. The product of his thesis work is a software called StepImporter, which is a proof of concept that shows that the conversion is possible to automate using different open source tools. Figure 1.1: StepImporter 6 CHAPTER 1. INTRODUCTION Link¨opingUniversity StepImporter works as intended, and the models from the CAD configurator can, after being converted, be viewed in the sales configurator. However, the models are missing one important component: a UV map, which is basically a two dimensional image on which you apply the texture of the model in question. Without a UV map, textures will not show properly. UV maps are generally created manually in a 3D editing software. Since the users of the CAD configurator often create models which include up to hundreds and sometimes thousands of parts, a way to optimize the models for being viewed in a real time environment must be investigated, since it is not currently feasible for a game engine to show models of that significance with all the different textures and lighting. 1.1.1 Research questions In this thesis, I wanted to answer the following questions: 1. How can one automate the process of creating UV maps for an arbitrary amount of models? 2. Is there a way to efficiently optimize the models with regard to perfor- mance during run-time? 3. Would it be best to use proprietary, open source or self written software to answer the previous questions? 1.2 Methodology While being inspired by the waterfall method [9], it is clear that some of the steps included are unnecessary based on the scope of this thesis. There are four general steps I used from the waterfall method; analysis, program design, coding and testing. 1.2.1 Analysis Since the project revolved around two general areas of research, the analysis in this thesis consists of two different prestudies which are described in chapters 2 and 3. In the prestudies, it was essential to have clear requirements of what to look for. There were not any revisions of the analysis. 1.2.2 Program design Given that StepImporter is an already established proof of concept, it would be difficult not to inherit most of the available functions in the software. The task at hand was less about designing functions available to the users, than it was about implementing functionalities that work "under the hood". It is also important to know that StepImporter was to be used as a type of testing platform for the Page 7 CHAPTER 1. INTRODUCTION Link¨opingUniversity implementations I produced during the project, but the company ultimately didn't want three different stand alone tools in its chain, so the functionalities of this project were to be integrated as an export option in the CAD configurator. What this means is that the resulting software of this thesis was to be built into a class library for use as a functionality in the CAD configurator, and the user interface of the functionality was, in the end, designed by a developer at the company.