kianzarrin / DirectConnectRoads

0 stars 1 forks source link

PERSONAL TASK: Run time continues junction barrier #1

Closed kianzarrin closed 2 years ago

kianzarrin commented 4 years ago

This asset already provides continues junction barrier. https://steamcommunity.com/sharedfiles/filedetails/?id=1319965985&searchtext=continues+junction+median

But I think it is better to be able to create junction barriers on demand while playing the game. This approach has several advantages:

The road mentioned above achieves continues junction barrier by providing an extra node texture that pretends to be a monorail connect group. This node has the same texture as the segments but the pavements have been removed. If we have access to _p.png we should easily be able to remove pavements from textures before rendering it.

~~Future plans:

Related/TODO:

originalfoo commented 4 years ago

Another thing to look at is the wire fence in the interactive prisons asset pack:

Srt1rIQ

See how it creates some mesh over top of road at junctions, which is something I've never seen any other network do. I assume it's just a road asset, and maybe something in the segment extends a prop out over the node or something?

originalfoo commented 4 years ago

Also, remember that if you start putting medians across junctions, the pathfinder needs to know. So again, it strikes me as something that should be in TM:PE because we can set up lane arrows/connectors automatically.

It would be cool also to be able to create fake junctions in roads with medians, to create places where traffic can do u-turns prior to reaching an actual proper junction.

And with fake junctions in roads, we are only a few inches away from having functionality like in the Crossings mod - eg. being able to give those fake junctions pedestrian crossings. The issue with Crossings mod is that you can't toggle the junction on and off (if memory serves) - so if you add a junction and later want to remove it, you have to replace the road which is somewhat annoying. Would be nice if there was just some way to toggle a crossing at any node on a road.

kianzarrin commented 4 years ago

@aubergine10 And with fake junctions in roads, we are only a few inches away from having functionality like in the Crossings mod - eg. being able to give those fake junctions pedestrian crossings. The issue with Crossings mod is that you can't toggle the junction on and off (if memory serves) - so if you add a junction and later want to remove it, you have to replace the road which is somewhat annoying. Would be nice if there was just some way to toggle a crossing at any node on a road.

You can remove the crossing nodes added by the crossing mod. but not other nodes.

kianzarrin commented 4 years ago

Direct connect node does not have any shader keywords. but normal node has shader keyword NET_NODE and normal segment has shader keyword NET_SEGMENT

info about 4 lanes road with continues junction median

Direct connect node -> m_nodeMaterial.DeffuseTexture 4-Lane Road with Junction Median0_node_1_d

m_segments[0].m_segmentMaterial.DeffuseTexture 4-Lane Road with Junction Median0_segment_0_d

The mesh for segment node and direct connect node: Screenshot (969)

kianzarrin commented 4 years ago

Screenshot (963) I was hoping that increasing corner offset would help those tracks to connect.

VictoriaCity: Track connection is done using direct connect nodes And whether they will be generated depends mainly on the maximum turning angle radius of curvature would be corner_offset * tan(turning_angle/2)

Max turn angle is the angle between m_start/endDirection of two connecting segment. so the smaller the angle, the sharper the turn. More info on max turn angle here: related https://github.com/CitiesSkylinesMods/TMPE/issues/649.

this issue calculates the radius of curved.

I don't know where VitoriaCity's got his formula radius of curvature = corner_offset * tan(turning_angle/2) but it seems right.

In practice its going to be much more complicated than that. calculating offset is hard. so for starters I assume half width = offset

max_turn_angle = Min(max_turn_angle1, max_turn_angle2)
offset0 =  hw * sin(max_turn_angle)
Rmin = offset0*tan(max_turn_angle/2)

offset_normal =  Max(hw1,hw2) * sin(current_angle)
offset = Max(offset_normal, offsetIn); // offsetIn is set in Node controller panel.
R = offset*tan(current_angle/2)

if R>Rmin then connect tracks.
victoriacity commented 4 years ago

Here's a figure showing how radius of curvature is calculated, I also realized that it should be corner_offset / tan(turning_angle/2) instead of multiply. figure1

Which should make sense with a sanity check: With turning angle=0 the radius will be infinity; l / tan(0) = l/0 = inf With turning angle=180 the radius will be zero. l / tan(90) = l/inf = 0

kianzarrin commented 4 years ago

CS code to use max turn angle:

float num8 = vector2.x * vector3.x + vector2.z * vector3.z;
float num9 = 0.01f - Mathf.Min(info2.m_maxTurnAngleCos, info3.m_maxTurnAngleCos);
if (num8 < num9) ...
kianzarrin commented 4 years ago

progress! ezgif com-optimize(1)

kianzarrin commented 4 years ago

I created this mesh dynamically(in game): image

kianzarrin commented 4 years ago

but for some reason I get this: image @victoriacity do you know what node/material/mesh properties I need to set for direct connect nodes?

kianzarrin commented 4 years ago

image I am comparing my auto-generated mesh(right) with mesh from the workshop road with a continuous junction barrier(left). I do not understand why the latter has a black box inside the display window and mine does not.

kianzarrin commented 4 years ago

I removed NET_NODE from material keywords and I get this: image why my road is flickering and the one from workshop does not?

kianzarrin commented 4 years ago

image I can see from blender that the workshop road uses a mesh that is tiny little bit higher than -0.3m.

kianzarrin commented 4 years ago

I got it working by elevating my mesh image but I still don't understand why I don't get the black box https://github.com/kianzarrin/DirectConnectRoads/issues/1#issuecomment-653861195 Is it because I do not clean up unused vertices? does it have something to do with Mesh.bounding?