trackgen: check all objects for spliting

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9110 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 8b744b82c7ef3a751c2b4eb1b795c6204ed71ef7
Former-commit-id: eb581c088946561f20d1d869dc93c83750998a43
This commit is contained in:
iobyte 2023-07-19 21:20:45 +00:00
parent fa05148cdd
commit e225866a01
4 changed files with 73 additions and 5 deletions

View file

@ -54,6 +54,13 @@ double Ac3d::V3d::length() const
return sqrt((*this)[0] * (*this)[0] + (*this)[1] * (*this)[1] + (*this)[2] * (*this)[2]);
}
void Ac3d::V3d::normalize()
{
const double l = length();
if (l != 0.0)
*this = *this / length();
}
double Ac3d::V3d::dot(const V3d &other) const
{
return (*this)[0] * other[0] + (*this)[1] * other[1] + (*this)[2] * other[2];
@ -692,7 +699,21 @@ void Ac3d::Object::parse(std::ifstream &fin, const std::string &objType)
{
const int numsurf = std::stoi(tokens.at(1));
for (int i = 0; i < numsurf; i++)
{
surfaces.emplace_back(fin);
Surface &surface = surfaces.back();
if (surface.isPolygon() && surface.refs.size() >= 3)
{
const V3d &p0 = vertices[surface.refs[0].index];
const V3d &p1 = vertices[surface.refs[1].index];
const V3d &p2 = vertices[surface.refs[2].index];
surface.normal = ((p1 - p0).cross(p2 - p1));
surface.normal.normalize();
}
}
}
else if (tokens.at(0) == "kids")
{
@ -918,12 +939,12 @@ void Ac3d::Object::splitBySURF()
for (std::list<Object>::iterator it = kids.begin(); it != kids.end(); ++it)
{
const Object &kid = *it;
Object &kid = *it;
std::set<int> surfTypes;
if (kid.type == "poly")
{
// get the different SURFs
std::set<int> surfTypes;
for (auto surface : kid.surfaces)
surfTypes.insert(surface.surf);
@ -952,6 +973,8 @@ void Ac3d::Object::splitBySURF()
it = last;
}
}
else
kid.splitBySURF();
}
}
@ -962,12 +985,12 @@ void Ac3d::Object::splitByMaterial()
for (std::list<Object>::iterator it = kids.begin(); it != kids.end(); ++it)
{
const Object &kid = *it;
Object &kid = *it;
std::set<int> materialTypes;
if (kid.type == "poly")
{
// get the different SURFs
std::set<int> materialTypes;
for (auto surface : kid.surfaces)
materialTypes.insert(surface.surf);
@ -996,6 +1019,41 @@ void Ac3d::Object::splitByMaterial()
it = last;
}
}
else
kid.splitByMaterial();
}
}
void Ac3d::Object::splitByUV()
{
if (type == "poly")
return;
for (std::list<Object>::iterator it = kids.begin(); it != kids.end(); ++it)
{
Object &kid = *it;
if (kid.type == "poly")
{
bool needSplit = false;
std::vector<std::set<V2d>> uvs(vertices.size());
for (const auto &surface : surfaces)
{
for (const auto &ref : surface.refs)
{
uvs[ref.index].insert(ref.coords[0]);
if (uvs[ref.index].size() > 1)
needSplit = true;
}
}
if (needSplit)
{
// TODO
}
}
else
kid.splitByUV();
}
}
@ -1397,3 +1455,8 @@ void Ac3d::splitByMaterial()
{
root.splitByMaterial();
}
void Ac3d::splitByUV()
{
root.splitByUV();
}

View file

@ -72,6 +72,7 @@ struct Ac3d
double dot(const V3d &other) const;
V3d cross(const V3d &other) const;
double length() const;
void normalize();
};
struct Color : public std::array<double, 3>
@ -165,6 +166,7 @@ struct Ac3d
SURF surf = PolygonSingleSidedFlat;
int mat = 0;
std::vector<Ref> refs;
V3d normal = { 0, 0, 0 };
Surface() = default;
explicit Surface(std::ifstream &fin);
@ -285,6 +287,7 @@ struct Ac3d
void flipAxes(bool in);
void splitBySURF();
void splitByMaterial();
void splitByUV();
void removeSurfacesNotSURF(int SURF);
void removeSurfacesNotMaterial(int material);
void removeUnusedVertices();
@ -312,6 +315,7 @@ struct Ac3d
void generateTriangles();
void splitBySURF();
void splitByMaterial();
void splitByUV();
void merge(const Ac3d &ac3d, bool mergeMaterials);
double getTerrainHeight(double x, double y) const;
double getTerrainAngle(double x, double y) const;

View file

@ -98,7 +98,7 @@ public:
//! Constructor.
Application::Application()
: GfApplication("TrackGen", "1.6.0.32", "Terrain generator for tracks")
: GfApplication("TrackGen", "1.6.0.33", "Terrain generator for tracks")
, HeightSteps(30)
, Bump(false)
, Raceline(false)

View file

@ -297,6 +297,7 @@ AddObject(tTrack *track, void *trackHandle, const Ac3d &terrainRoot, const Ac3d
obj.transform(m);
obj.splitBySURF();
obj.splitByMaterial();
obj.splitByUV();
objectsRoot.merge(obj, multipleMaterials);