-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRMCCoasterMeshGenerator.cs
More file actions
177 lines (132 loc) · 5.83 KB
/
Copy pathRMCCoasterMeshGenerator.cs
File metadata and controls
177 lines (132 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using UnityEngine;
public class RMCCoasterMeshGenerator : MeshGenerator
{
private BoxExtruder collisionMeshExtruder;
private BoxExtruder leftBeamExtruder;
private BoxExtruder rightBeamExtruder;
private const float mainCrossBeamSupportDistance = .3f;
private BoxExtruder crossBeamOuterExtruder;
private BoxExtruder crossBeamInnerExtruder;
private BoxExtruder mainDropdownSideSupports;
private TubeExtruder CementPillerExtruder;
public override void prepare(TrackSegment4 trackSegment, GameObject putMeshOnGO)
{
base.prepare(trackSegment, putMeshOnGO);
leftBeamExtruder = new BoxExtruder(.04782f, .03054f);
leftBeamExtruder.setUV(0, 9);
rightBeamExtruder = new BoxExtruder(.04782f, .03054f);
rightBeamExtruder.setUV(0, 9);
crossBeamOuterExtruder = new BoxExtruder(.04782f, .1f);
crossBeamOuterExtruder.closeEnds = true;
crossBeamInnerExtruder = new BoxExtruder(.04782f, .1f);
crossBeamInnerExtruder.closeEnds = true;
collisionMeshExtruder = new BoxExtruder(trackWidth, .03054f);
buildVolumeMeshExtruder = new BoxExtruder(this.getRailWidth(trackSegment), .03054f);
buildVolumeMeshExtruder.closeEnds = true;
mainDropdownSideSupports = new BoxExtruder(.02f,.08f);
mainDropdownSideSupports.closeEnds = true;
setModelExtruders(rightBeamExtruder, leftBeamExtruder);
}
public override void sampleAt(TrackSegment4 trackSegment, float t)
{
base.sampleAt(trackSegment, t);
Vector3 normal = trackSegment.getNormal(t);
Vector3 trackPivot = getTrackPivot(trackSegment.getPoint(t), normal);
Vector3 tangentPoint = trackSegment.getTangentPoint(t);
Vector3 binormal = Vector3.Cross(normal, tangentPoint).normalized;
Vector3 leftRail = trackPivot + binormal * trackWidth / 2f;
Vector3 rightRail = trackPivot - binormal * trackWidth / 2f;
Vector3 midPoint = trackPivot + normal * getCenterPointOffsetY();
leftBeamExtruder.extrude(leftRail, tangentPoint, normal);
rightBeamExtruder.extrude(rightRail, tangentPoint, normal);
collisionMeshExtruder.extrude(trackPivot, tangentPoint, normal);
if (liftExtruder != null)
{
liftExtruder.extrude(midPoint, tangentPoint, normal);
}
}
public override void afterExtrusion(TrackSegment4 trackSegment, GameObject putMeshOnGO)
{
base.afterExtrusion(trackSegment, putMeshOnGO);
float sample = trackSegment.getLength() / Mathf.RoundToInt(trackSegment.getLength() / crossBeamSpacing);
float pos = 0.0f;
int index = 0;
while (pos < trackSegment.getLength())
{
float tForDistance = trackSegment.getTForDistance(pos);
index++;
pos += sample;
Vector3 normal = trackSegment.getNormal(tForDistance);
Vector3 tangentPoint = trackSegment.getTangentPoint(tForDistance);
Vector3 binormal = Vector3.Cross(normal, tangentPoint).normalized;
Vector3 trackPivot = getTrackPivot(trackSegment.getPoint(tForDistance), normal);
Vector3 binormalFlat = Vector3.Cross(Vector3.up, tangentPoint).normalized;
if (!(trackSegment is Station))
{
crossBeamOuterExtruder.extrude(trackPivot + tangentPoint * (mainDropdownSideSupports.width) + normal * crossBeamOuterExtruder.width + binormal * mainCrossBeamSupportDistance, -1f * binormal, Vector3.up);
crossBeamOuterExtruder.extrude(trackPivot + tangentPoint * (mainDropdownSideSupports.width) + normal * crossBeamOuterExtruder.width - binormal * mainCrossBeamSupportDistance, -1f * binormal, Vector3.up);
crossBeamOuterExtruder.end();
crossBeamInnerExtruder.extrude(trackPivot - tangentPoint * (mainDropdownSideSupports.width ) + normal * crossBeamOuterExtruder.width + binormal * mainCrossBeamSupportDistance, -1f * binormal, Vector3.up);
crossBeamInnerExtruder.extrude(trackPivot - tangentPoint * (mainDropdownSideSupports.width) + normal * crossBeamOuterExtruder.width - binormal * mainCrossBeamSupportDistance, -1f * binormal, Vector3.up);
crossBeamInnerExtruder.end();
{
Vector3 dropDownPoint = trackPivot + normal * (crossBeamOuterExtruder.width / 2.0f) + binormal * mainCrossBeamSupportDistance;
float height= GameController.Instance.park.getHeightAt(dropDownPoint);
mainDropdownSideSupports.extrude(dropDownPoint, Vector3.down, -1f * binormal);
mainDropdownSideSupports.extrude(new Vector3(dropDownPoint.x, height,dropDownPoint.z), Vector3.down, -1f * binormal);
mainDropdownSideSupports.end();
}
{
Vector3 dropDownPoint = trackPivot + normal * (crossBeamOuterExtruder.width / 2.0f) - binormal * mainCrossBeamSupportDistance;
float height = GameController.Instance.park.getHeightAt(dropDownPoint);
mainDropdownSideSupports.extrude(dropDownPoint, Vector3.down, -1f * binormal);
mainDropdownSideSupports.extrude(new Vector3(dropDownPoint.x,height,dropDownPoint.z), Vector3.down, -1f * binormal);
mainDropdownSideSupports.end();
}
//TODO: check banking and deterim if track needs secondary angled out supports
}
}
}
protected override void Initialize()
{
base.Initialize();
trackWidth = .34406f;
crossBeamSpacing = .5f;
}
public override Extruder getBuildVolumeMeshExtruder()
{
return buildVolumeMeshExtruder;
}
public override Mesh getCollisionMesh(GameObject putMeshOnGO)
{
return collisionMeshExtruder.getMesh(putMeshOnGO.transform.worldToLocalMatrix);
}
public override Mesh getMesh(GameObject putMeshOnGO)
{
return MeshCombiner.start().add(leftBeamExtruder, rightBeamExtruder, crossBeamOuterExtruder, crossBeamInnerExtruder, mainDropdownSideSupports).end(putMeshOnGO.transform.worldToLocalMatrix);
}
public override float trackOffsetY()
{
return .065f;
}
protected override float railHalfHeight()
{
return .065f;
}
public override float getSupportOffsetY()
{
return 0.05f;
}
public override float getTunnelOffsetY()
{
return 0.15f;
}
public override float getTunnelWidth(TrackSegment4 trackSegment, float t)
{
return 0.7f;
}
public override float getTunnelHeight()
{
return 0.95f;
}
}