コード例 #1
0
 public static void SetRailMesh(this NetInfo.Node node, string variation)
 {
     //if (WidthName == "10m")
     //{
     //    node
     //    .SetMeshes
     //       ($@"Meshes\{WidthName}\Rail{variation}.obj")
     //     .SetConsistentUVs();
     //}
     //else if (WidthName == "18m")
     //{
     node
     .SetMeshes
         ($@"Meshes\{WidthName}\Rail{variation}.obj",
         $@"Meshes\{WidthName}\Rail{variation}_LOD.obj")
     .SetConsistentUVs();
     //}
     //else
     //{
     //    node
     //    .SetMeshes
     //       ($@"Meshes\{WidthName}\Rail{variation}.obj",
     //       $@"Meshes\{WidthName}\Rail_LOD.obj")
     //     .SetConsistentUVs();
     //}
 }
コード例 #2
0
        // returns !(ConnectGroup == None && MetaData.ConnectGroups == null)
        // the next instruction is brfalse which aumatically takes a not of the above phrase so at the end it will be
        // (ConnectGroup == None && MetaData.ConnectGroups == null) ||
        public static bool CheckConnectGroup(NetInfo.ConnectGroup cg, NetInfo.Node node)
        {
#if DEBUG
            DirectConnectUtil.AssertNotEmpty(node.GetMetaData()?.ConnectGroupsHash, "connect groups");
#endif
            return(!(cg == 0 && node.GetMetaData()?.ConnectGroupsHash == null));
        }
コード例 #3
0
        public static bool ShouldConnectMedian(
            ushort nodeId,
            int nodeInfoIDX,
            ref RenderManager.Instance data)
        {
            ushort sourceSegmentID  = nodeId.ToNode().GetSegment(data.m_dataInt0 & 7);
            int    targetSegmentIDX = data.m_dataInt0 >> 4;
            ushort targetSegmentID  = nodeId.ToNode().GetSegment(targetSegmentIDX);

            NetInfo.Node nodeInfo = sourceSegmentID.ToSegment().Info.m_nodes[nodeInfoIDX];
            if (!DirectConnectUtil.IsMedian(nodeInfo, nodeId.ToNode().Info))
            {
                Log.Debug($"not a median: node:{nodeId} connect_group:{nodeInfo.m_connectGroup} vehcileTypes:{nodeId.ToNode().Info.m_vehicleTypes}");
                return(true); // ignore.
            }

            return(!DirectConnectUtil.OpenMedian(sourceSegmentID, targetSegmentID));

            if (TMPE_Exists_)
            {
                try {
                    return(!DirectConnectUtil.OpenMedian(sourceSegmentID, targetSegmentID));
                }
                catch {
                    TMPE_Exists_ = false;
                }
            }
            return(true); // ignore
        }
コード例 #4
0
        public static NetInfo.Node CreateDCNode(NetInfo.Node template, NetInfo netInfo)
        {
            Log.Debug("CreateDCNode called for " + netInfo?.name);
            var material = MaterialUtils.ContinuesMedianMaterial(netInfo);
            var mesh     = MaterialUtils.ContinuesMedianMesh(netInfo);

            mesh = mesh?.CutOutRoadSides();
            mesh?.Elevate();
            if (mesh == null || material == null)
            {
                return(null);
            }

            mesh.name     += "_DC";
            material.name += "_DC";
            NetInfo.Node node = Copy(template);
            node.m_mesh          = node.m_nodeMesh = mesh;
            node.m_material      = node.m_nodeMaterial = material;
            node.m_directConnect = true;
            node.m_connectGroup  = NetInfo.ConnectGroup.DoubleTrain;

            Log.Debug("CreateDCNode sucessful for " + netInfo?.name);
            node.m_nodeMesh.DumpMesh($"DC mesh for {netInfo.name}");
            return(node);
        }
コード例 #5
0
        public static NetInfo.Node SetFlagsDefault(this NetInfo.Node node)
        {
            node.m_flagsRequired  = NetNode.Flags.None;
            node.m_flagsForbidden = NetNode.Flags.None;

            return(node);
        }
コード例 #6
0
        public static VehicleInfo.VehicleType GetVehicleType(NetInfo.Node nodeInfo, NetInfo.ConnectGroup flags)
        {
            VehicleInfo.VehicleType    ret  = 0;
            const NetInfo.ConnectGroup TRAM =
                NetInfo.ConnectGroup.CenterTram |
                NetInfo.ConnectGroup.NarrowTram |
                NetInfo.ConnectGroup.SingleTram |
                NetInfo.ConnectGroup.WideTram;
            const NetInfo.ConnectGroup TRAIN =
                NetInfo.ConnectGroup.DoubleTrain |
                NetInfo.ConnectGroup.SingleTrain |
                NetInfo.ConnectGroup.TrainStation;
            const NetInfo.ConnectGroup MONO_RAIL =
                NetInfo.ConnectGroup.DoubleMonorail |
                NetInfo.ConnectGroup.SingleMonorail |
                NetInfo.ConnectGroup.MonorailStation;

            if ((flags & TRAM) != 0)
            {
                ret |= VehicleInfo.VehicleType.Tram;
            }
            if ((flags & TRAIN) != 0)
            {
                ret |= VehicleInfo.VehicleType.Train;
            }
            if ((flags & MONO_RAIL) != 0)
            {
                ret |= VehicleInfo.VehicleType.Monorail;
            }

            return(ret);
        }
コード例 #7
0
        public static NetInfo.Node SetConsistentUVs(this NetInfo.Node node, bool lodOnly = false)
        {
            var colors   = new List <Color>();
            var colors32 = new List <Color32>();

            if (lodOnly == false)
            {
                for (int i = 0; i < node.m_mesh.vertexCount; i++)
                {
                    colors.Add(new Color(255, 0, 255, 255));
                    colors32.Add(new Color32(255, 0, 255, 255));
                }
                node.m_mesh.colors   = colors.ToArray();
                node.m_mesh.colors32 = colors32.ToArray();
                colors   = new List <Color>();
                colors32 = new List <Color32>();
            }
            for (int i = 0; i < node.m_lodMesh.vertexCount; i++)
            {
                colors.Add(new Color(255, 0, 255, 255));
                colors32.Add(new Color32(255, 0, 255, 255));
            }
            node.m_lodMesh.colors   = colors.ToArray();
            node.m_lodMesh.colors32 = colors32.ToArray();

            return(node);
        }
コード例 #8
0
 internal static bool DetermineDirectConnect(
     ushort segmentId1,
     ushort segmentId2,
     ushort nodeId,
     ref NetInfo.Node nodeInfo,
     out bool flipMesh)
 {
     flipMesh = false;
     try {
         VehicleInfo.VehicleType vehicleType = nodeInfo.GetVehicleType();
         if (!HasLane(segmentId1, vehicleType) // vehicleType == 0 is also checked here
             /*.LogRet($"HasLane({segmentId1.ToSegment().Info.name}, {vehicleType})")*/)
         {
             return(true); // not a track ... but a median.
         }
         var nodeInfo2 = DetermineDirectConnect(
             nodeInfo,
             segmentId1,
             segmentId2,
             nodeId,
             NetInfo.LaneType.All,
             vehicleType,
             out flipMesh);
         if (nodeInfo2 == null)
         {
             return(false);
         }
         nodeInfo = nodeInfo2;
         return(true);
     } catch (Exception ex) {
         ex.Log();
         return(false);
     }
 }
コード例 #9
0
        public static NetInfo.Node SetConsistentUVs(this NetInfo.Node node)
        {
            var colors   = new List <Color>();
            var colors32 = new List <Color32>();

            for (int i = 0; i < node.m_mesh.vertexCount; i++)
            {
                colors.Add(new UnityEngine.Color(255, 0, 255, 255));
                colors32.Add(new UnityEngine.Color32(255, 0, 255, 255));
            }
            node.m_mesh.colors   = colors.ToArray();
            node.m_mesh.colors32 = colors32.ToArray();

            colors   = new List <Color>();
            colors32 = new List <Color32>();
            for (int i = 0; i < node.m_lodMesh.vertexCount; i++)
            {
                colors.Add(new UnityEngine.Color(255, 0, 255, 255));
                colors32.Add(new UnityEngine.Color32(255, 0, 255, 255));
            }
            node.m_lodMesh.colors   = colors.ToArray();
            node.m_lodMesh.colors32 = colors32.ToArray();

            return(node);
        }
コード例 #10
0
        /// <param name="consistencyLevel">0=consistent 1=inconsistent</param>
        public NodeInfoClass(NetInfo.Node nodeInfo, int usedIndex, int inconsistencyLevel)
        {
            InconsistencyLevel = inconsistencyLevel;

            UsedIndex        = usedIndex;
            Track            = nodeInfo.m_connectGroup.GetTrackType();
            RequireWindSpeed = nodeInfo.m_requireWindSpeed;

            RequiredFlags      = default;
            ForbiddenFlags     = default;
            Layer              = -1;
            EmptyTransparent   = default;
            RequireSurfaceMaps = default;

            if (inconsistencyLevel <= 1)
            {
                RequiredFlags = nodeInfo.m_flagsRequired;
            }

            if (inconsistencyLevel == 0)
            {
                ForbiddenFlags = nodeInfo.m_flagsForbidden;

                Layer              = nodeInfo.m_layer;
                EmptyTransparent   = nodeInfo.m_emptyTransparent;
                RequireSurfaceMaps = nodeInfo.m_requireSurfaceMaps;
            }
        }
コード例 #11
0
        public static NetInfo.Node SetFlags(this NetInfo.Node node, NetNode.Flags required, NetNode.Flags forbidden)
        {
            node.m_flagsRequired  = required;
            node.m_flagsForbidden = forbidden;

            return(node);
        }
コード例 #12
0
        public static IEnumerable <NetInfo.Node> CreateDCNodes(NetInfo.Node template, NetInfo netInfo, float voffset /* = NetInfoUtil.ASPHALT_HEIGHT*/)
        {
            Assertion.AssertNotNull(netInfo, "netInfo");
            Log.Info($"CreateDCNode({netInfo},{voffset}) called", false);
            var ret = new List <NetInfo.Node>();

            for (int i = 0; i < netInfo.m_segments.Length; ++i)
            {
                var segmentInfo = netInfo.m_segments[i];
                if (!IsSegmentInfoSuitable(segmentInfo))
                {
                    Log.Info($"Skiping segment[{i}]", false);
                    continue;
                }
                Log.Info($"processing segment[{i}]", false);
                var material = new Material(segmentInfo.m_material);
                var mesh     = segmentInfo.m_mesh;
                //Log.Debug("[1] mesh=" + mesh?.name ?? "null", false);
                mesh = mesh?.CutOutRoadSides(voffset);
                mesh?.Elevate();
                if (mesh == null || material == null)
                {
                    Log.Info("skipping null ...", false);
                    continue;
                }

                mesh.name     += "_DC";
                material.name += "_DC";
                //{
                //    var c = material.color;
                //    c.a = 0.01f;
                //    material.color = c;

                //    var tex = material.TryGetTexture2D(TextureUtils.ID_Defuse);
                //    tex = tex.GetReadableCopy();
                //    tex.Fade(0.1f);
                //    material.SetTexture(TextureUtils.ID_Defuse, tex);
                //}


                NetInfo.Node node = Copy(template);
                node.m_mesh          = node.m_nodeMesh = mesh;
                node.m_material      = node.m_nodeMaterial = material;
                node.m_directConnect = true;
                node.m_connectGroup  = NetInfo.ConnectGroup.TrainStation;
                //node.m_emptyTransparent = true; // is this causing blue textures?

                node.m_lodMaterial = null;
                node.m_lodMesh     = null;
                node.m_combinedLod = null;

                Log.Info("CreateDCNode sucessful for " + netInfo.name, false);
#if DEBUG
                //node.m_nodeMesh.DumpMesh($"DC mesh for {netInfo.name}");
#endif
                ret.Add(node);
            }
            return(ret);
        }
コード例 #13
0
 public static bool HideBrokenARMedians(this NetInfo.Node node)
 {
     if (hideBrokenMedians_ == null)
     {
         return(true);
     }
     return(hideBrokenMedians_(node));
 }
コード例 #14
0
 public static VehicleInfo.VehicleType ARVehicleTypes(this NetInfo.Node node)
 {
     if (nodeVehicleTypes_ == null)
     {
         return(0);
     }
     return(nodeVehicleTypes_(node));
 }
コード例 #15
0
 public static NetInfo.Node CopyNodeInfo_shallow(NetInfo.Node nodeInfo)
 {
     Assert(nodeInfo != null, "nodeInfo==null");
     NetInfo.Node ret = new NetInfo.Node();
     ReflectionHelpers.CopyProperties <NetInfo.Node>(ret, nodeInfo);
     Assert(nodeInfo.m_material != null, $"nodeInfo m_material is null");
     return(ret);
 }
コード例 #16
0
 public static NetInfo.LaneType LaneTypes(this NetInfo.Node node)
 {
     if (nodeLaneTypes_ == null)
     {
         return(0);
     }
     return(nodeLaneTypes_(node));
 }
コード例 #17
0
 public static VehicleInfo.VehicleType GetVehicleType(this NetInfo.Node nodeInfo)
 {
     VehicleInfo.VehicleType vehicleType = AdaptiveRoadsUtil.ARVehicleTypes(nodeInfo);
     if (vehicleType == 0)
     {
         vehicleType = GetVehicleType(nodeInfo.m_connectGroup);
     }
     return(vehicleType);
 }
コード例 #18
0
 public static void OnAfterDrawMesh(
     ushort nodeID,
     ref RenderManager.Instance renderData,
     NetInfo.Node nodeInfo)
 {
     if (nodeInfo == Overlay.HoveredInfo)
     {
         Enqueue(nodeID, ref renderData);
     }
 }
コード例 #19
0
 public static NetInfo.Node[] AddNode(NetInfo.Node[] nodeArray, NetInfo.Node node)
 {
     NetInfo.Node[] ret = new NetInfo.Node[nodeArray.Length + 1];
     for (int i = 0; i < nodeArray.Length; ++i)
     {
         ret[i] = nodeArray[i];
     }
     ret[nodeArray.Length] = node;
     return(ret);
 }
コード例 #20
0
 public static bool CheckConnectGroup(bool flagsMatch, NetInfo.Node node, NetInfo info)
 {
     if (flagsMatch)
     {
         return(true);
     }
     return(DirectConnectUtil.ConnectGroupsMatch(
                node.GetMetaData()?.ConnectGroupsHash,
                info.GetMetaData()?.ConnectGroupsHash));
 }
コード例 #21
0
        public static NetInfo.Node SetMeshes(this NetInfo.Node node, string newMeshPath, string newLODMeshPath = null)
        {
            node.m_mesh = AssetManager.instance.GetMesh(newMeshPath);

            if (newLODMeshPath != null)
            {
                node.m_lodMesh = AssetManager.instance.GetMesh(newLODMeshPath);
            }

            return(node);
        }
コード例 #22
0
        /// <summary>
        /// find a match with NetInfo.Node
        /// this happens if NodeInfoClass matches ignoring used index and elements excluded by inconsitency level
        /// but including NodeInfoClassMetaData.ConnectGroup.
        /// </summary>
        public bool Matches(NetInfo.Node nodeInfo)
        {
            NodeInfoClass nodeInfoClass2 = new NodeInfoClass(
                nodeInfo,
                NodeInfoClass.UsedIndex,         // ignore used index
                NodeInfoClass.InconsistencyLevel // ignore excluded
                );

            return(ConnectGroup == nodeInfo.m_connectGroup &&
                   NodeInfoClass.Equals(nodeInfoClass2));
        }
コード例 #23
0
 /// <summary>
 /// Precondition: assuming that the segments can have connected lanes.
 /// </summary>
 internal static NetInfo.Node DetermineDirectConnect(
     NetInfo.Node nodeInfo,
     ushort sourceSegmentId,
     ushort targetSegmentId,
     ushort nodeId,
     NetInfo.LaneType laneType,
     VehicleInfo.VehicleType vehicleType,
     out bool flipMesh)
 {
     flipMesh = false;
     try {
         ref NetSegment sourceSegment = ref sourceSegmentId.ToSegment();
         ref NetSegment targetSegment = ref targetSegmentId.ToSegment();
コード例 #24
0
        public static Node GetOrCreateMetaData(this NetInfo.Node node)
        {
            Assertion.Assert(node is IInfoExtended);
            var node2 = node as IInfoExtended;
            var ret   = node2.GetMetaData <Node>();

            if (ret == null)
            {
                ret = new Node(node);
                node2.SetMetaData(ret);
            }
            return(ret);
        }
コード例 #25
0
        public static bool ShouldRenderBendNodeLod(ushort nodeId, NetInfo.Node node)
        {
            if (_electricityNetShader == null)
            {
                _electricityNetShader = Shader.Find("Custom/Net/Electricity");
            }

            if (node.m_material?.shader != _electricityNetShader)
            {
                return(true);
            }

            // copied from CalculateGroupData
            var    netManager      = global::NetManager.instance;
            ushort segmentId1      = 0;
            ushort segmentId2      = 0;
            var    segmentId1Found = false;
            var    counter         = 0;

            for (var s = 0; s < 8; s++)
            {
                var segmentId = netManager.m_nodes.m_buffer[nodeId].GetSegment(s);
                if (segmentId == 0)
                {
                    continue;
                }

                var netSegment  = netManager.m_segments.m_buffer[segmentId];
                var first       = ++counter == 1;
                var isStartNode = (netSegment.m_startNode == nodeId);
                if (!first && !segmentId1Found)
                {
                    segmentId1Found = true;
                    segmentId1      = segmentId;
                }
                else if (first && !isStartNode)
                {
                    segmentId1Found = true;
                    segmentId1      = segmentId;
                }
                else
                {
                    segmentId2 = segmentId;
                }
            }

            var segmentSkin1 = NetworkSkinManager.SegmentSkins[segmentId1];
            var segmentSkin2 = NetworkSkinManager.SegmentSkins[segmentId2];

            return((segmentSkin1 == null || segmentSkin1.m_hasWires) && (segmentSkin2 == null || segmentSkin2.m_hasWires));
        }
コード例 #26
0
        /// <returns>if new meshes where generated.</returns>
        public bool GenerateExtraMeshes()
        {
            if (TwoWayDouble == null)
            {
                return(false);
            }

            NodeInfoFamily cached = MeshLUT[TwoWayDouble.m_nodeMesh];

            if (TwoWayRight == null)
            {
                TwoWayRight = CopyNodeInfo_shallow(TwoWayDouble);
                if (cached != null)
                {
                    TwoWayRight.m_nodeMesh = cached.TwoWayRight.m_nodeMesh;
                }
                else
                {
                    TwoWayRight.m_nodeMesh = TwoWayDouble.m_nodeMesh.CutMesh2(keepLeftSide: false);
                }
            }
            if (TwoWayLeft == null)
            {
                TwoWayLeft = CopyNodeInfo_shallow(TwoWayDouble);
                if (cached != null)
                {
                    TwoWayLeft.m_nodeMesh = cached.TwoWayLeft.m_nodeMesh;
                }
                else
                {
                    TwoWayLeft.m_nodeMesh = TwoWayDouble.m_nodeMesh.CutMesh2(keepLeftSide: true);
                }
            }

            MeshLUT[TwoWayDouble.m_nodeMesh] = this;
            if (StationDouble != null)
            {
                MeshLUT[StationDouble.m_nodeMesh] = this;
            }
            if (StationSingle != null)
            {
                MeshLUT[StationSingle.m_nodeMesh] = this;
            }
            if (Station != null)
            {
                MeshLUT[Station.m_nodeMesh] = this;
            }

            return(cached == null);
        }
コード例 #27
0
        public static NetInfo.Node[] RemoveNode(NetInfo.Node[] nodeArray, NetInfo.Node node)
        {
            NetInfo.Node[] ret = new NetInfo.Node[nodeArray.Length - 1];
            int            j   = 0;

            for (int i = 0; i < nodeArray.Length; ++i)
            {
                if (node == nodeArray[i])
                {
                    continue;
                }
                ret[j++] = nodeArray[i];
            }
            return(ret);
        }
コード例 #28
0
 public static NetInfo GetParent(this NetInfo.Node node, out int nodeIndex)
 {
     foreach (var netInfo in NetInfoExtionsion.EditedNetInfos)
     {
         for (int i = 0; i < netInfo.m_nodes.Length; ++i)
         {
             if (netInfo.m_nodes[i] == node)
             {
                 nodeIndex = i;
                 return(netInfo);
             }
         }
     }
     nodeIndex = -1;
     return(null);
 }
コード例 #29
0
        public static bool ShouldRenderBendNode(NetInfo.Node node, ushort segment1, ushort segment2)
        {
            if (_electricityNetShader == null)
            {
                _electricityNetShader = Shader.Find("Custom/Net/Electricity");
            }

            if (node.m_material?.shader != _electricityNetShader)
            {
                return(true);
            }

            var segmentSkin1 = NetworkSkinManager.SegmentSkins[segment1];
            var segmentSkin2 = NetworkSkinManager.SegmentSkins[segment2];

            return((segmentSkin1 == null || segmentSkin1.m_hasWires) && (segmentSkin2 == null || segmentSkin2.m_hasWires));
        }
コード例 #30
0
        public void FillInTheBlanks(NodeInfoFamily source, bool station = false)
        {
            TwoWayDouble = TwoWayDouble ?? source.TwoWayDouble;
            TwoWayRight  = TwoWayRight ?? source.TwoWayRight;
            TwoWayLeft   = TwoWayLeft ?? source.TwoWayLeft;

            OneWay      = OneWay ?? source.OneWay;
            OneWayEnd   = OneWayEnd ?? source.OneWayEnd;
            OneWayStart = OneWayStart ?? source.OneWayStart;

            if (station)
            {
                StationDouble = StationDouble ?? source.StationDouble;
                StationSingle = StationSingle ?? source.StationSingle;
                Station       = Station ?? source.Station;
            }
        }