52 Real pr, best_pr = 2000000000.;
53 Real dist, best_dist = 2000000000.;
58 for (
size_t i = 0; i <
mesh->
Walls.size(); i++)
66 for (
int j = 0; j <
mesh->
Walls[i]->GetPolygonCount(); j++)
78 dist = orig_start.distance(cur_isect);
83 distance = start.distance(cur_isect);
102bool PolyMesh::CreateMesh(
const std::string &name,
const std::string &texture,
PolyArray &vertices,
Real tw,
Real th,
bool autosize,
Matrix3 &t_matrix,
Vector3 &t_vector, std::vector<std::vector<Polygon::Geometry> > &geometry, std::vector<Triangle> &triangles,
PolygonSet &converted_vertices)
108 return ReportError(
"PolyMesh: Cannot create geometry in a file-loaded mesh");
111 std::string texname = texture;
118 converted_vertices.resize(1);
120 converted_vertices[0].reserve(vertices.size());
121 for (
size_t i = 0; i < vertices.size(); i++)
122 converted_vertices[0].emplace_back(
sbs->
ToRemote(vertices[i]));
130 return ReportError(
"PolyMesh: Texture mapping error");
140 if (autosize ==
true)
144 Real tw2 = sizing.x, th2 = sizing.y;
157 return CreateMesh(name, material, converted_vertices, t_matrix, t_vector, geometry, triangles, converted_vertices, tw2, th2,
false);
160bool PolyMesh::CreateMesh(
const std::string &name,
const std::string &material,
PolygonSet &vertices,
Matrix3 &tex_matrix,
Vector3 &tex_vector, std::vector<std::vector<Polygon::Geometry> > &geometry, std::vector<Triangle> &triangles,
PolygonSet &converted_vertices,
Real tw,
Real th,
bool convert_vertices)
166 if (convert_vertices ==
true)
168 converted_vertices.resize(vertices.size());
169 for (
size_t i = 0; i < vertices.size(); i++)
171 converted_vertices[i].reserve(vertices[i].size());
172 for (
size_t j = 0; j < vertices[i].size(); j++)
173 converted_vertices[i].emplace_back(
sbs->
ToRemote(vertices[i][j]));
177 converted_vertices = vertices;
180 Vector2 *table =
GetTexels(tex_matrix, tex_vector, converted_vertices, tw, th);
184 size_t trimesh_size = converted_vertices.size();
186 for (
size_t i = 0; i < trimesh_size; i++)
190 trimesh[i].
triangles.reserve(converted_vertices[i].size() - 2);
191 for (
size_t j = 2; j < converted_vertices[i].size(); j++)
192 trimesh[i].triangles.emplace_back(
Triangle(0, j - 1, j));
197 geometry.resize(trimesh_size);
199 for (
size_t i = 0; i < trimesh_size; i++)
201 geometry[i].resize(converted_vertices[i].size());
207 for (
size_t i = 0; i < trimesh_size; i++)
209 for (
size_t j = 0; j < converted_vertices[i].size(); j++)
214 geometry[i][j].vertex = converted_vertices[i][j];
215 geometry[i][j].normal = normal;
216 geometry[i][j].texel = table[k];
228 for (
size_t i = 0; i < trimesh_size; i++)
230 if (triangles.capacity() < trimesh[i].
triangles.size())
231 triangles.reserve(trimesh[i].triangles.size());
232 for (
size_t j = 0; j < trimesh[i].
triangles.size(); j++)
236 triangles.emplace_back(tri);
238 location += converted_vertices[i].size();
259 size_t texel_count = 0;
260 for (
size_t i = 0; i < vertices.size(); i++)
261 texel_count += vertices[i].size();
267 for (
size_t i = 0; i < vertices.size(); i++)
269 for (
size_t j = 0; j < vertices[i].size(); j++)
271 texel_temp = tex_matrix * (vertices[i][j] - tex_vector);
272 texels[index].x = texel_temp.x;
273 texels[index].y = texel_temp.y;
std::vector< Wall * > Walls
virtual bool ReportError(const std::string &message)
Wall * FindWallIntersect(const Vector3 &start, const Vector3 &end, Vector3 &isect, Real &distance, Vector3 &normal, Wall *wall=0)
bool CreateMesh(const std::string &name, const std::string &texture, PolyArray &vertices, Real tw, Real th, bool autosize, Matrix3 &tex_matrix, Vector3 &tex_vector, std::vector< std::vector< Polygon::Geometry > > &geometry, std::vector< Triangle > &triangles, PolygonSet &converted_vertices)
Vector2 * GetTexels(Matrix3 &tex_matrix, Vector3 &tex_vector, PolygonSet &vertices, Real tw, Real th)
PolyMesh(MeshObject *mesh)
bool IntersectSegment(const Vector3 &start, const Vector3 &end, Vector3 &isect, Real *pr, Vector3 &normal)
TextureManager * GetTextureManager()
Real ToLocal(Real remote_value)
Real ToRemote(Real local_value)
bool ComputeTextureMap(Matrix3 &t_matrix, Vector3 &t_vector, PolyArray &vertices, const Vector3 &p1, const Vector3 &p2, const Vector3 &p3, Real tw, Real th)
bool GetTextureMapping(PolyArray &vertices, Vector3 &v1, Vector3 &v2, Vector3 &v3, int &direction)
Vector2 CalculateSizing(const std::string &texture, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, int direction, Real tw, Real th)
std::string GetTextureMaterial(const std::string &name, bool &result, bool report=true, const std::string &polygon_name="")
bool GetTextureTiling(const std::string &texture, Real &tw, Real &th)
Plane ComputePlane(PolyArray &vertices, bool flip_normal=true)
std::vector< Vector3 > PolyArray
std::vector< PolyArray > PolygonSet
#define SBS_PROFILE(name)
std::vector< Triangle > triangles