Tnet学习一 RFCs

效果:点击任意一个cube, cube颜色变化同时位置向z轴移动一个单位:

所有的示例都继承自TNBehaviour,这个示例使用的是ColoredObject:

大致流程:

1.ColoredObject监听Onclick事件,此事件触发点击事件:

tno.Send("OnColor", Target.AllSaved, color, this.transform.position);//TNObject调用发送命令 把消息传送给服务器

2.服务器收到消息,把此方法和参数加到RFC列表中,方便新加入客户端同步数据:

ch.AddRFC(target, funcName, buffer);

根据第二个参数TargetAllSaved,广播给channel中所有客户端中的此物体。如果reliable为true调用Tcp发送,如果为false调用Udp。其中,TNObject的send和SendQuickly方法区别也基于此。send是调用Tcp发送 reliable为true。SendQuickly调用Udp,reliable为false。

for (int i = 0; i < ch.players.size; ++i)
{
TcpPlayer tp = (TcpPlayer)ch.players[i];

if (reliable || !tp.udpIsUsable || tp.udpEndPoint == null || !mAllowUdp)
{
tp.SendTcpPacket(buffer);
}
else mUdp.Send(buffer, tp.udpEndPoint);
}

3.GameClient会循环处理Tcp和Udp消息,如果收到服务器发过来的结果,会触发回调:

case Packet.ForwardToOthersSaved:

if (onForwardedPacket != null) onForwardedPacket(channelID, reader);

4.TNManger的回调事件中会调用TNObject方法:

TNObject.FindAndExecute(channelID, objID, funcName, reader.ReadArray());

5.TNObject利用反射和uid,找到其他客户端相同ObjID物体,并触发方法OnColor方法:

TNObject obj = TNObject.Find(channelID, objID);
obj.Execute(funcName, parameters))
;

6.ColoredObject方法中OnColor得以执行,保证了所有客户端的同步。

[RFC] void OnColor (Color c, Vector3 position)
   
   {
       
   mMat.color = c;
       
   this.transform.position = position;
   
   
}

   



  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用以下代码实现PointNet深度学习网络: ``` import torch import torch.nn as nn import torch.nn.functional as F class TNet(nn.Module): def __init__(self, k=3): super(TNet, self).__init__() self.k = k self.conv1 = nn.Conv1d(k, 64, 1) self.conv2 = nn.Conv1d(64, 128, 1) self.conv3 = nn.Conv1d(128, 1024, 1) self.fc1 = nn.Linear(1024, 512) self.fc2 = nn.Linear(512, 256) self.fc3 = nn.Linear(256, k*k) self.bn1 = nn.BatchNorm1d(64) self.bn2 = nn.BatchNorm1d(128) self.bn3 = nn.BatchNorm1d(1024) self.bn4 = nn.BatchNorm1d(512) self.bn5 = nn.BatchNorm1d(256) self.transform = nn.Parameter(torch.eye(k).unsqueeze(0)) def forward(self, x): batchsize = x.size()[0] x = F.relu(self.bn1(self.conv1(x))) x = F.relu(self.bn2(self.conv2(x))) x = F.relu(self.bn3(self.conv3(x))) x = torch.max(x, 2, keepdim=True)[0] x = x.view(-1, 1024) x = F.relu(self.bn4(self.fc1(x))) x = F.relu(self.bn5(self.fc2(x))) x = self.fc3(x) iden = torch.eye(self.k).view(1, self.k*self.k).repeat(batchsize, 1) if x.is_cuda: iden = iden.cuda() x = x + iden x = x.view(-1, self.k, self.k) return x class STN3d(nn.Module): def __init__(self, k=3): super(STN3d, self).__init__() self.k = k self.conv1 = nn.Conv1d(k, 64, 1) self.conv2 = nn.Conv1d(64, 128, 1) self.conv3 = nn.Conv1d(128, 1024, 1) self.fc1 = nn.Linear(1024, 512) self.fc2 = nn.Linear(512, 256) self.fc3 = nn.Linear(256, k*k) self.bn1 = nn.BatchNorm1d(64) self.bn2 = nn.BatchNorm1d(128) self.bn3 = nn.BatchNorm1d(1024) self.bn4 = nn.BatchNorm1d(512) self.bn5 = nn.BatchNorm1d(256) self.transform = nn.Parameter(torch.zeros(batchsize, self.k, self.k)) nn.init.constant_(self.transform, 0) def forward(self, x): batchsize = x.size()[0] x = F.relu(self.bn1(self.conv1(x))) x = F.relu(self.bn2(self.conv2(x))) x = F.relu(self.bn3(self.conv3(x))) x = torch.max(x, 2, keepdim=True)[0] x = x.view(-1, 1024) x = F.relu(self.bn4(self.fc1(x))) x = F.relu(self.bn5(self.fc2(x))) x = self.fc3(x) iden = torch.eye(self.k).view(1, self.k*self.k).repeat(batchsize, 1) if x.is_cuda: iden = iden.cuda() x = x + iden x = x.view(-1, self.k, self.k) return x class PointNetEncoder(nn.Module): def __init__(self, global_feat=True, feature_transform=False): super(PointNetEncoder, self).__init__() self.stn = STN3d() self.conv1 = nn.Conv1d(3, 64, 1) self.conv2 = nn.Conv1d(64, 128, 1) self.conv3 = nn.Conv1d(128, 1024, 1) self.bn1 = nn.BatchNorm1d(64) self.bn2 = nn.BatchNorm1d(128) self.bn3 = nn.BatchNorm1d(1024) self.global_feat = global_feat self.feature_transform = feature_transform if self.feature_transform: self.fstn = TNet(k=64) def forward(self, x): n_pts = x.size()[2] trans = self.stn(x) x = x.transpose(2, 1) x = torch.bmm(x, trans) x = x.transpose(2, 1) x = F.relu(self.bn1(self.conv1(x))) if self.feature_transform: trans_feat = self.fstn(x) x = x.transpose(2,1) x = torch.bmm(x, trans_feat) x = x.transpose(2,1) else: trans_feat = None x = F.relu(self.bn2(self.conv2(x))) x = self.bn3(self.conv3(x)) x = torch.max(x, 2, keepdim=True)[0] x = x.view(-1, 1024) if self.global_feat: return x, trans, trans_feat else: x = x.view(-1, 1024, 1).repeat(1, 1, n_pts) return torch.cat([x, trans], 1), trans_feat class PointNetDecoder(nn.Module): def __init__(self, feature_transform=False): super(PointNetDecoder, self).__init__() self.feature_transform = feature_transform if self.feature_transform: self.fstn = TNet(k=128) self.conv1 = nn.Conv1d(1088, 512, 1) self.conv2 = nn.Conv1d(512, 256, 1) self.conv3 = nn.Conv1d(256, 128, 1) self.conv4 = nn.Conv1d(128, 3, 1) self.bn1 = nn.BatchNorm1d(512) self.bn2 = nn.BatchNorm1d(256) self.bn3 = nn.BatchNorm1d(128) def forward(self, x, trans, trans_feat): n_pts = x.size()[2] x = F.relu(self.bn1(self.conv1(x))) if self.feature_transform: x = x.transpose(2,1) trans_feat = self.fstn(x) x = x.transpose(2,1) x = F.relu(self.bn2(self.conv2(x))) x = F.relu(self.bn3(self.conv3(x))) x = self.conv4(x) x = x.transpose(2,1) x = torch.bmm(x, trans) x = x.transpose(2,1) return x class PointNet(nn.Module): def __init__(self, feature_transform=False): super(PointNet, self).__init__() self.feature_transform = feature_transform self.encoder = PointNetEncoder(global_feat=True, feature_transform=self.feature_transform) self.decoder = PointNetDecoder(feature_transform=self.feature_transform) def forward(self, x): x, trans, trans_feat = self.encoder(x) x = self.decoder(x, trans, trans_feat) return x ``` 这个代码实现了一个PointNet深度学习网络,可以用于点云分类、分割和重建等任务。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值