层 Layers

2024-02-06 05:38
文章标签 layers

本文主要是介绍层 Layers,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Layers are most commonly used by Cameras to render only a part of the scene, and by Lights to illuminate only parts of the scene. But they can also used by raycasting to selectively ignore colliders or to create collisions.

经常使用层的是相机和灯光,相机用它来渲染场景中的一部分物体,而灯光依靠层来仅仅照亮场景中的一部分物体。但是也经常利用层,通过光线投射来选择性地忽略碰撞器,或者添加碰撞功能。

Creating Layers 创建层

The first step is to create a new layer, which we can then assign to a GameObject. To create a new layer, open the Edit menu and select Project Settings->Tags.

首先是创建一个新的层,随后将它指派给一个GameObject(即与该GameObject关联)。创建一个新的层只需要,打开编辑菜单,选择工程设置->标签。

We create a new layer in one of the empty User Layers. We choose layer 8.

在空用户层里创建一个新的层,我们选曾第8层。

Assigning Layers 分配层

Now that you have created a new layer, you have to assign the layer to one of the game objects.

当你创建了一个新的层后,必须把它和一个游戏对象关联起来。

In the tag manager we assigned the Player layer to be in layer 8.

在标签管理器中,把玩家层放到层8中。

Drawing only a part of the scene with the camera's culling mask
使用相机剔除掩膜来对场景部分绘制

Using the camera's culling mask, you can selectively render objects which are in one particular layer. To do this, select the camera that should selectively render objects.

通过相机剔除掩膜,你可以有选择性地渲染那些在特定层中的物体。为了达到这一目的,首先选择目标相机。

Modify the culling mask by checking or unchecking layers in the culling mask property.

设置剔除掩膜,只需要在剔除掩膜属性中选择或删除相应层。

Casting Rays Selectively 选择性地投射光线

Using layers you can cast rays and ignore colliders in specific layers. For example you might want to cast a ray only against the player layer and ignore all other colliders.

通过层你可以在特定的层里投射光线、忽略碰撞器。比如说,你只想在玩家层中投射光线(即光线只跟玩家层中的碰撞体作用),进而忽略其他所有的碰撞器。

The Physics.Raycast function takes a bitmask, where each bit determines if a layer will be ignored or not. If all bits in the layerMask are on, we will collide against all colliders. If the layerMask = 0, we will never find any collisions with the ray.

Physics.Raycast函数里操作一个掩膜位,该掩膜位的每一位决定相应的层是否被忽略。如果layerMask中的每一位都为1,则将会与所有的碰撞器作用。相反如果layerMask=0,那么将会光线将不会与任何碰撞器作用。

// bit shift the index of the layer to get a bit mask
var layerMask = 1 << 8;
// Does the ray intersect any objects which are in the player layer.
if (Physics.Raycast (transform.position, Vector3.forward, Mathf.Infinity, layerMask))print ("The ray hit the player"); 

In the real world you want to do the inverse of that however. We want to cast a ray against all colliders except those in the Player layer.

在现实生活中,会遇到完全相反的情况。如我们只想排除玩家层(Player layer),即投射出的光线跟除玩家层中的碰撞器外的所有碰撞器作用。

function Update () {// Bit shift the index of the layer (8) to get a bit maskvar layerMask = 1 << 8;// This would cast rays only against colliders in layer 8.// But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.layerMask = ~layerMask;var hit : RaycastHit;// Does the ray intersect any objects excluding the player layerif (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), hit, Mathf.Infinity, layerMask)) {Debug.DrawRay (transform.position, transform.TransformDirection (Vector3.forward) * hit.distance, Color.yellow);print ("Did Hit");} else {Debug.DrawRay (transform.position, transform.TransformDirection (Vector3.forward) *1000, Color.white);print ("Did not Hit");}
}

When you don't pass a layerMask to the Raycast function, it will only ignore colliders that use the IgnoreRaycast layer. This is the easiest way to ignore some colliders when casting a ray.

当没有给Raycast函数传layerMask参数时,仅仅只忽略使用IgnoreRaycast层的碰撞器。这是投射光线时忽略某些碰撞器的最简单方法。

这篇关于层 Layers的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/683289

相关文章

OpenXR Monado compositor处理应用layers(cheduled->delivered)

OpenXR Monado compositor处理应用的layer,scheduled->delivered  @src/xrt/targets/common/target_instance.ct_instance_create_system@src/xrt/compositor/main/comp_compositor.ccomp_main_create_system_composito

Convolutional layers/Pooling layers/Dense Layer 卷积层/池化层/稠密层

Convolutional layers/Pooling layers/Dense Layer 卷积层/池化层/稠密层 Convolutional layers 卷积层 Convolutional layers, which apply a specified number of convolution filters to the image. For each subregion, the

C++卷积神经网络实例:tiny_cnn代码详解(11)——层结构容器layers类源码分析

在这篇博文中我们对tiny_cnn卷积神经网络模型中的最后一个网络结构方面的类——layers做简要分析。   首先,layers通俗的讲可以被称为是层结构的vector,即层结构容器。由于卷积神经网络是一个多层的网络模型,因此有必要将网络中各个层进行统一管理,这便引出了本篇博文中所要介绍的layers类。layers类是一个vector类型的变量,其中压入的元素就是网络中的各个层模型,这里

tf.layers.conv1d函数解析(一维卷积)

一维卷积一般用于处理文本,所以输入一般是一段长文本,就是词的列表   函数定义如下: tf.layers.conv1d(inputs,filters,kernel_size,strides=1,padding='valid',data_format='channels_last',dilation_rate=1,activation=None,use_bias=True,

pytorch--Pooling layers

文章目录 1.torch.nn.MaxPool1d()2.torch.nn.MaxPool2d3.torch.nn.AvgPool2d()4.torch.nn.FractionalMaxPool2d()5.torch.nn.AdaptiveMaxPool2d()6.torch.nn.AdaptiveAvgPool2d() 1.torch.nn.MaxPool1d()   t

Llama模型家族之Stanford NLP ReFT源代码探索 (二)Intervention Layers层

LlaMA 3 系列博客 基于 LlaMA 3 + LangGraph 在windows本地部署大模型 (一) 基于 LlaMA 3 + LangGraph 在windows本地部署大模型 (二) 基于 LlaMA 3 + LangGraph 在windows本地部署大模型 (三) 基于 LlaMA 3 + LangGraph 在windows本地部署大模型 (四) 基于 LlaMA 3

神经网络 torch.nn---Linear Layers(nn.Linear)

torch.nn - PyTorch中文文档 (pytorch-cn.readthedocs.io) torch.nn — PyTorch 2.3 documentation nn.Linear torch.nn.Linear(in_features, out_features, bias=True, device=None, dtype=None) 参数: in_features -

Keras深度学习框架基础第四讲:层接口(layers API)“层权重约束”

1、层权重约束概述 1.1 层权重约束的定义 Keras层权重约束的定义主要涉及到在训练神经网络模型时,对层的权重参数施加一定的限制或约束,以提高模型的泛化能力和稳定性。以下是关于Keras层权重约束的详细定义: 约束的目的: 防止过拟合:通过限制权重的大小或范围,可以减少模型对训练数据的过度依赖,从而提高模型在未见数据上的性能。 提高模型稳定性:约束可以确保权重参数在合理的范围内变化

Keras深度学习框架基础第二讲:层接口(layers API)第二部分“基本层类”

1、layer 类 典型的layer类如下 keras.layers.Layer(activity_regularizer=None,trainable=True,dtype=None,autocast=True,name=None,**kwargs) 这是一个所有层都继承的基类。 一个层是一个可调用的对象,它接受一个或多个张量作为输入,并输出一个或多个张量。它涉及计算,这些计算在ca

meshlab: pymeshlab合并多个物体模型并保存(flatten visible layers)

一、关于环境  请参考:pymeshlab遍历文件夹中模型、缩放并导出指定格式-CSDN博客 二、关于代码 本文所给出代码仅为参考,禁止转载和引用,仅供个人学习。 本文所给出的例子是https://download.csdn.net/download/weixin_42605076/89233917中的obj_000001.ply和obj_000009.ply。 合并多个物体模型并不是布