层次结构和继承
In UNIGINE, materials can form hierarchy. However, there are several rules and constraints that described below and must be taken into account.在UNIGINE中,材质可以形成层次结构。但是,下面描述了一些规则和约束,必须予以考虑。
Materials Hierarchy材质层次结构#
Materials hierarchy forms by inheriting one material from another. A parent material passes its properties to the inherited material so that they can be overridden.材质层次结构是通过从另一材质继承一种材质而形成的。父材质将其属性传递给继承的材质,以便可以覆盖它们。
UNIGINE provides a set of base materials with the built-in shaders which are always at the top of the materials hierarchy. The base materials cannot be organized in hierarchy: no base material can be inherited from another base material. Moreover, properties of the base materials cannot be changed. So, to modify one of the base materials, you should inherit a user material from it: the base material will pass its properties to the inherited material. UNIGINE提供了一组 基础材质 ,这些着色器始终位于 materials层次结构的顶部。基础材质不能按层次结构进行组织:不能从其他基础材质继承基础材质。而且,基材的性能不能改变。因此,要修改基础材质之一,您应该从中继承 用户材质 :基础材质会将其属性传递给继承的材质。
However, not only base materials can be used as parent ones. You can inherit a new material from any user material.但是,不仅基础材质可以用作母材。您可以从任何用户材质继承新材质。
The parent of the material can be changed by dragging the material to a new parent.可以通过将材质拖动到新的父级来更改其父级。
In this way, there are the following reasons to create materials hierarchy: 这样,创建材质层次结构的原因如下:
- Inheriting from the base material allows editing its properties via Materials Editor.从基础材质继承可通过“材质编辑器”编辑其属性。
- Inheriting from the user material allows for mass controlling values of multiple materials parameters.从用户物料继承可对多个物料参数进行质量控制。
Base mesh_base material材质 mesh_base 基础
|
Child material inherited from mesh_base 从 mesh_base 继承的子材质
|
The material ball on the left picture is rendered using the mesh_base base material from the default set of materials. The material ball on the right picture is inherited from mesh_base and has 1 texture changed (the albedo texture). All the other properties are identical to the base material ones.左侧图片上的材质球是使用默认材质集中的 mesh_base 基础材质渲染的。右侧图片上的材质球是从 mesh_base 继承的,并且更改了1个纹理( albedo 纹理)。所有其他属性都与基础材质相同。
Materials Loading Order物料装载顺序#
Materials hierarchy doesn't affect the loading order of materials: on the engine start-up, all materials of the project are loaded, the base materials are loaded first. And since each user material refers to both the parent and the base materials, the base material is used as the parent one until the actual parent is loaded. So, when the application is loaded, all materials existing in the project are presented in the materials hierarchy.材质层次结构不会影响材质的加载顺序:在引擎启动时,将加载项目的所有材质,首先加载基础材质。而且,由于每种用户材质都引用了父级材质和基础材质,因此在加载实际的父级之前,将基础材质用作父级材质。因此,在加载应用程序时,项目中存在的所有材质都将显示在材质层次结构中。
Referring Materials by GUIDs通过GUID查阅材质#
A GUID (Globally Unique Identifier) is an identifier for a material. The GUID is a 40-character hexadecimal string generated by using the SHA-1 hash algorithm. GUID (全局唯一标识符)是材质的标识符。 GUID是使用SHA-1哈希算法生成的40个字符的十六进制字符串。
Materials hierarchy is based on GUIDs: all materials are referred by GUIDs, even the base and manual ones (the GUIDs for such materials are generated in run-time by their names).物料层次结构基于GUID:所有物料均由GUID引用,甚至是基础物料和手动物料(此类物料的GUID在运行时均按其名称生成)。
Only the user materials store their GUIDs explicitly: the GUID is generated automatically on user material creation and is written in the *.mat file.只有用户材质显式存储其GUID:GUID在用户材质创建时自动生成,并写入*.mat文件中。
For example:例如:
<material version="2.5.0.2" name="mesh_base_0" guid="3e7f5c9535777e15966cb5f915d25b62620b2bef" parent="401e90ccd85f4f2bb97c19ab9e1351325c4012eb" base_material="mesh_base"/>
The user material GUID is stored in the guid attribute. If the user material is inherited from another user material, it will refer the parent by its GUID (the parent attribute in the example above). 用户材质GUID存储在 guid 属性中。如果用户材质是从另一个用户材质继承的,则它将通过其GUID(在上面的示例中为parent attribute in the example above).
Using GUIDs makes it difficul to edit the user materials manually. For example, to rename such material, it is required to generate a GUID for the new name and replace the current GUID. 使用GUID使手动编辑用户材质变得困难。例如,要重命名此类材质,需要为新名称生成一个GUID并替换当前的GUID。
For the base and manual materials, the GUIDs are generated in run-time by their names. If the name of such material is changed, the GUID will also be changed. That is why the base and manual materials cannot be renamed in run-time. For the same reason, the *.basemat and *.mat files store their names, not GUIDs. And references to such materials stored in these files are usually name-based too. 对于基础和手册材质,GUID是在运行时通过其名称生成的。如果更改此类材质的名称,则GUID也将更改。这就是为什么无法在运行时重命名基础材质和手册材质的原因。出于相同的原因,*.basemat和*.mat文件存储其名称,而不存储GUID。这些文件中存储的此类材质的引用通常也是基于名称的。
Types of Inheritance继承类型#
As it was mentioned above, the user material can be inherited from the base, user or manual user material. Depending on the type of the parent, the *.mat file will store the reference to it as follows:如上所述,用户材质可以从基础,用户或手册用户材质中继承。根据父级的类型,*.mat文件将存储对它的引用,如下所示:
- Parent: base material. The *.mat file stores a GUID of the user material and a name of the base material.
父级:基础材质。 *.mat文件存储用户材质的GUID和基础材质的名称。
<material version="2.5.0.2" name="mesh_base_4" guid="67cc0594c0ff0f50ac7b34978a5e04c73c2cff90" base_material="mesh_base"/>
<material version="2.5.0.2" name="mesh_base_4" guid="67cc0594c0ff0f50ac7b34978a5e04c73c2cff90" base_material="mesh_base"/>
- Parent: user material. The *.mat file stores a GUID of the user material, a GUID of the parent material and a name of the base material.
父级:用户材质。 *.mat文件存储用户材质的GUID,父材质的GUID和基础材质的名称。
<material version="2.5.0.2" name="mesh_base_6" guid="9542cd76ae16362527359168ea2e9ff1b42c8c2e" parent="67cc0594c0ff0f50ac7b34978a5e04c73c2cff90" base_material="mesh_base"/>
<material version="2.5.0.2" name="mesh_base_6" guid="9542cd76ae16362527359168ea2e9ff1b42c8c2e" parent="67cc0594c0ff0f50ac7b34978a5e04c73c2cff90" base_material="mesh_base"/>
- Parent: manual user material.
- If the inherited user material is also manual, the *.mat file stores a name of the user material, a name of the parent material and a name of the base material.
Only the manual material can refer to the parent manual material by the name.Only the manual material can refer to the parent manual material by the name.Only the manual material can refer to the parent manual material by the name.If the inherited user material is also manual, the *.mat file stores a name of the user material, a name of the parent material and a name of the base material.
<material version="2.5.0.2" manual="1" name="mesh_base_2" parent_name="mesh_base_1" base_material="mesh_base"/>
Only the manual material can refer to the parent manual material by the name.Only the manual material can refer to the parent manual material by the name.<material version="2.5.0.2" manual="1" name="mesh_base_2" parent_name="mesh_base_1" base_material="mesh_base"/>
- If the inherited user material isn't manual, the *.mat file stores a GUID of the user material, a GUID of the parent material (generated in run-time by its name) and a name of the base material.
If the inherited user material isn't manual, the *.mat file stores a GUID of the user material, a GUID of the parent material (generated in run-time by its name) and a name of the base material.
<material version="2.5.0.2" manual="1" name="mesh_base_2" guid="8c8cc0a19ff114521d9594e04a178a1c6b25ec5c" parent="ee43b4c84571cebeafd4153e24e35c113b5f56c2" base_material="mesh_base"/>
<material version="2.5.0.2" manual="1" name="mesh_base_2" guid="8c8cc0a19ff114521d9594e04a178a1c6b25ec5c" parent="ee43b4c84571cebeafd4153e24e35c113b5f56c2" base_material="mesh_base"/>
Only the manual material can refer to the parent manual material by the name.Only the manual material can refer to the parent manual material by the name.Only the manual material can refer to the parent manual material by the name.If the inherited user material isn't manual, the *.mat file stores a GUID of the user material, a GUID of the parent material (generated in run-time by its name) and a name of the base material.<material version="2.5.0.2" manual="1" name="mesh_base_2" parent_name="mesh_base_1" base_material="mesh_base"/>
父级:用户手册。<material version="2.5.0.2" manual="1" name="mesh_base_2" guid="8c8cc0a19ff114521d9594e04a178a1c6b25ec5c" parent="ee43b4c84571cebeafd4153e24e35c113b5f56c2" base_material="mesh_base"/>
- If the inherited user material is also manual, the *.mat file stores a name of the user material, a name of the parent material and a name of the base material.
Only the manual material can refer to the parent manual material by the name.Only the manual material can refer to the parent manual material by the name.Only the manual material can refer to the parent manual material by the name.如果继承的用户材质也是手册,则*.mat文件存储用户材质的名称,父材质的名称和基础材质的名称。
<material version="2.5.0.2" manual="1" name="mesh_base_2" parent_name="mesh_base_1" base_material="mesh_base"/>
Only the manual material can refer to the parent manual material by the name.只有手册材质可以通过名称引用父手册材质。<material version="2.5.0.2" manual="1" name="mesh_base_2" parent_name="mesh_base_1" base_material="mesh_base"/>
- If the inherited user material isn't manual, the *.mat file stores a GUID of the user material, a GUID of the parent material (generated in run-time by its name) and a name of the base material.
如果继承的用户材质不是手动的,则*.mat文件存储用户材质的GUID,父材质的GUID(在运行时通过其名称生成)和基础材质的名称。
<material version="2.5.0.2" manual="1" name="mesh_base_2" guid="8c8cc0a19ff114521d9594e04a178a1c6b25ec5c" parent="ee43b4c84571cebeafd4153e24e35c113b5f56c2" base_material="mesh_base"/>
<material version="2.5.0.2" manual="1" name="mesh_base_2" guid="8c8cc0a19ff114521d9594e04a178a1c6b25ec5c" parent="ee43b4c84571cebeafd4153e24e35c113b5f56c2" base_material="mesh_base"/>
- If the inherited user material is also manual, the *.mat file stores a name of the user material, a name of the parent material and a name of the base material.
Creating a User Material创建用户材质#
UNIGINE provides the huge set of built-in base materials to meet practically all user's demands. So, the fastest and the safest way to create a new material is to create a user material by inheriting it from the base one and adjusting its properties.UNIGINE提供了丰富的内置基础材质集,可以满足几乎所有用户的需求。因此,创建新材质的最快,最安全的方法是通过从基础材质继承并调整其属性来创建用户材质。
To inherit a material, perform the following in the Materials Editor:要继承材质,请在 材质编辑器 中执行以下操作:
- Select the base material.选择基础材质。
- Inherit from this material: click the Create Child button or right-click the material and choose Create Child.
The new *.mat file that stores a GUID of the new material and a reference to the mesh_base base material will be created. To rename the material, right-click the material and choose Rename: the file will be renamed as well.The new *.mat file that stores a GUID of the new material and a reference to the mesh_base base material will be created. To rename the material, right-click the material and choose Rename: the file will be renamed as well.
The new *.mat file that stores a GUID of the new material and a reference to the mesh_base base material will be created. To rename the material, right-click the material and choose Rename: the file will be renamed as well.从此材质继承:单击Create Child按钮或右键单击材质,然后选择Create Child.
The new *.mat file that stores a GUID of the new material and a reference to the mesh_base base material will be created. To rename the material, right-click the material and choose Rename: the file will be renamed as well.将创建新的*.mat文件,该文件存储新材质的GUID和对mesh_base基础材质的引用。要重命名材质,请右键单击材质,然后选择Rename:文件也将重命名。
- Enable properties you want to apply to your material in the States tab of the inherited material.
在继承的材质的状态标签中启用要应用于材质的属性。
- Replace default textures with your prepared ones in the Textures tab of the inherited material.
在继承的材质的纹理选项卡中,用准备好的纹理替换默认纹理。
- Tweak the available parameters in the Parameters tab of the inherited material.
在继承的材质的参数选项卡中调整可用参数。