[Basics of Unity] 2. Mesh material mapping and resource packaging

 [Basics of Unity] 2. Mesh material mapping and resource packaging

    Hello everyone, I am Lampard~~

    Welcome to the Unity basics series blog. The knowledge you learned comes from Teacher Afa at Station B~Thank you 

(1) Mesh material texture

    If you come into contact with a 3D object for the first time, you will feel so magical. What is this object made of? In fact, 3D objects are basically composed of three parts: mesh, material and texture.

(1) Grid

    So what is a grid? First of all, we need to know that the 3D objects we see are actually composed of small triangles. We can select a Shaded Wireframe graphic wireframe mode under the Scene tab in the Unity compiler, and it will be very clear. As you can see, the greater the number of triangles, the more refined the graphics and the greater the rendering pressure on the GPU. A ball requires multiple triangles, while a cube only requires 12 triangles.

     Whether it is a ball or a cube, they are all composed of small triangles. Students who have many questions may ask, why is it a triangle? I immediately ChatGpt:

    Because triangles can describe the shape and surface details of an object more geometrically. Additionally , triangles are easier to handle and render because they have defined vertices and normals . Although quadrilaterals and other polygons can also be used for modeling, triangles remain the most common form of faces when using modern rendering techniques

    Um, that's a long way off... Okay, so what is the grid? In fact, it describes the surface of an object by describing some data such as triangles, vertex data, texture coordinates, normal information, etc. When we were learning openGL before, we came into contact with the [openGL2021 version] obj format file

(2) Material

    Okay, what is material?

The material properties, characteristics, or composition of an object. The material can be metal, plastic, wood, glass, ceramics, textiles, etc. The correct choice of materials can determine the quality, appearance, characteristics and longevity of an object. Materials can also be used to represent the look and feel of a 3D model. In computer graphics, materials are usually described by parameters such as texture, color, reflectivity, roughness, and transparency.

     Simply put, football and bowling look different, right? Although they are both balls, how do we express their differences? That is the role of materials.

     In Unity, we can create a new material for the object and hang it on it: first, right-click in the Assert directory and select create, and then select Material in the directory.

    The material has many attributes. Let's first set its Albedo albedo (color) and select a color you like. Next I created a red and a blue material

     So how do we make the objects in our scene use this material? It's very simple, just drag it over:

     Wow, it changed color instantly, isn’t it amazing? After setting it up, we can see that in the component on the right side of the object, in the Mesh Renderer mesh rendering, there is an additional material information we just created.

    There is a little check here. If we uncheck it, then this object will not be rendered.

     All in all, the role of materials is to make objects look more real, recording information such as luster like metal, reflection like glass, patterns on the surface, whether there are grooves and protrusions, etc.

(3) Texture map

   What is the texture? Because in our real life, objects rarely encounter solid colors. I'm sure every object, even every part of the object, is different. Texture is also an attribute of the material.

    So how to achieve this effect? It requires art students to produce a texture picture to show what the object looks like. We just mentioned that there will be texture coordinates in the grid, which are used to describe the area of ​​texture corresponding to each small triangle.

    In order to show it, I went to Baidu to find a more intuitive texture of the earth. It looks like a spread out earth, right~

Albedo albedo map

     So what do I need to do if I want to attach this texture to an object on Unity? We only need to drag the texture resources to the Assert directory

    Then there is a small button on the left side of the material setting albedo. Click it to select our texture and add skin to the object~

Normal Map normal map

    For example, if we want to create a rust-like object, we first need to attach an albedo material skin to the object.

   Hang this material on the cube. We can see that the rectangle has some rust, but it still feels like something is missing.

    What's the difference? That's right, it's that bumpy feeling, and our normal map does this job. We attach a normal map to the normalMap attribute of the material, and the effect is obvious and much better.

Metallic和Specular

    We can see that there are two properties, Metallic and Specular, in the editor.

     Metallic represents the metallicity of an object. The closer the attribute value is to 0, the less metal-like it is, and the closer it is to 1, the more metal-like it is.

     Specular is the smoothness, 0 is smoother, 1 is rougher, you can drag the progress bar to try it~

(2) Import and export resource packages

(1) Resource directory

    Unity's resources (models, scenes, scripts), etc. are all saved in the Assert directory. We can select a resource at random and right-click Show In Explore to see our resource directory in the Window folder.

   Rango, in addition to the files created in the editor, we also saw many strange .meta files. What are these?

     When in doubt, ask GPT:

In Unity, each resource file (such as scene, material, texture, sound, etc.) will have a corresponding meta file. This meta file contains resource-related information, such as name, UUID, dependencies, tags, modification time, etc.

The main function of the meta file is to make Unity more efficient and reliable when processing resources. Specifically, meta files can:

1. Confirm the uniqueness of resources: Since multiple files in Unity are allowed to use the same name, the unique UUID of the meta file can ensure that each resource has unique identity information.

2. Record the dependencies of resources: The meta file can record the dependencies between resources. When a resource is modified, Unity can automatically update other resources that depend on the resource.

3. Store the editing status of resources: The meta file can record the editing status of resources, including the last modification time, author, tags, comments, etc., to facilitate developers for version management and collaborative development.

   Simply put, it is a Log of a resource file, managed by the Unity engine itself . It should be noted that if the meta file is deleted, Unity will regenerate a new meta file, but the UUID of this new file may be different from the previous one, resulting in There is a problem with the resource reference. Therefore, it is generally not recommended to manually delete meta files

(2) Export resources

    OK, what if we have worked hard to compile content in a scene and want to share it with others? It's very simple. Just right-click Export package.

    For example, if I want to share the entire Assert content, right-click the Assert folder and export it.

    After exporting, you can see a file with the suffix unitypackage. This is all the information about our resources.

(3) Import resources

    Hmm... You might as well guess how to import this resource package. That's right! Just drag it in hahahahahahaha~ For convenience of display, we first create a new empty project, and then drag it in to see our resources:

Okay, that’s it for today, thanks for reading! ! !
Like and follow! ! !

Guess you like

Origin blog.csdn.net/cooclc/article/details/132640596