-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathicr_loader.cpp
More file actions
93 lines (86 loc) · 2.38 KB
/
icr_loader.cpp
File metadata and controls
93 lines (86 loc) · 2.38 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
#include "icr_loader.h"
#include <stdio.h>
#include <vector>
#include "CSpline.h"
CMesh* loadRoad(const char* fname, CSpline** splinedst)
{
printf("loading %s...\n", fname);
FILE* f = fopen(fname, "r");
if (!f)
{
printf("cannot open file %s!\n", fname);
return 0;
}
CSpline* spline = new CSpline();
std::vector<vec3> stencil;
vec3 stencilscale;
vec3 b1, b2, b3, b4; // buffers
float scale = 1.f;
float texscale = 0.01f;
int subdiv = 200;
char type[50];
while (fscanf(f, "%s", &type) > 0)
{
if (!strcmp(type, "stencil")) {
fscanf(f, "%f %f %f", &b1.X, &b1.Y, &b1.Z);
stencil.push_back(b1);
} else if (!strcmp(type, "control")) {
fscanf(f, "%f %f %f", &b1.X, &b1.Y, &b1.Z);
fscanf(f, "%f %f %f", &b2.X, &b2.Y, &b2.Z);
fscanf(f, "%f %f %f", &b3.X, &b3.Y, &b3.Z);
fscanf(f, "%f %f %f", &b4.X, &b4.Y, &b4.Z);
spline->addControlPoint(SControlPoint(b1, b2, b3, b4) * scale);
} else if (!strcmp(type, "scalespline")) {
fscanf(f, "%f", &scale);
} else if (!strcmp(type, "scaletexture")) {
fscanf(f, "%f", &texscale);
} else if (!strcmp(type, "scalestencil")) {
fscanf(f, "%f %f", &stencilscale.X, &stencilscale.Y);
} else if (!strcmp(type, "subdiv")) {
fscanf(f, "%d", &subdiv);
} else if (!strcmp(type, "#")) {
while (fgetc(f) != '\n')
{ // deliberately empty
}
} else if (!strcmp(type, "break")) {
break;
}
}
fclose(f);
*splinedst = spline;
return new CMesh(spline, stencil, subdiv, texscale, stencilscale);
}
void loadRoadProperties(const char* fname, SRoadProperties& props)
{
printf("loading road props: %s ...\n", fname);
FILE* f = fopen(fname, "r");
if (!f)
{
printf("cannot open file %s!\n", fname);
return;
}
char type[50];
vec3 b1, b2, b3, b4; // buffers
while (fscanf(f, "%s", &type) > 0)
{
if (!strcmp(type, "stencil")) {
fscanf(f, "%f %f %f", &b1.X, &b1.Y, &b1.Z);
props.Stencil.push_back(b1);
} else if (!strcmp(type, "scalespline")) {
fscanf(f, "%f", &props.ScaleSpline);
} else if (!strcmp(type, "scaletexture")) {
fscanf(f, "%f", &props.ScaleTexture);
} else if (!strcmp(type, "scalestencil")) {
fscanf(f, "%f %f", &props.ScaleStencil.X, &props.ScaleStencil.Y);
} else if (!strcmp(type, "subdiv")) {
fscanf(f, "%d", &props.Subdiv);
} else if (!strcmp(type, "#")) {
while (fgetc(f) != '\n')
{ // deliberately empty
}
} else if (!strcmp(type, "break")) {
break;
}
}
fclose(f);
}