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;
181 Vector2 *table =
GetTexels(tex_matrix, tex_vector, converted_vertices, tw, th, texel_count);
185 size_t trimesh_size = converted_vertices.size();
187 for (
size_t i = 0; i < trimesh_size; i++)
191 trimesh[i].
triangles.reserve(converted_vertices[i].size() - 2);
192 for (
size_t j = 2; j < converted_vertices[i].size(); j++)
193 trimesh[i].triangles.emplace_back(
Triangle(0, j - 1, j));
198 geometry.resize(trimesh_size);
200 for (
size_t i = 0; i < trimesh_size; i++)
202 geometry[i].resize(converted_vertices[i].size());
208 for (
size_t i = 0; i < trimesh_size; i++)
210 for (
size_t j = 0; j < converted_vertices[i].size(); j++)
215 geometry[i][j].vertex = converted_vertices[i][j];
216 geometry[i][j].normal = normal;
218 if (k >= texel_count)
219 return ReportError(
"PolyMesh: invalid texel index");
220 geometry[i][j].texel = table[k];
232 for (
size_t i = 0; i < trimesh_size; i++)
234 if (triangles.capacity() < trimesh[i].
triangles.size())
235 triangles.reserve(trimesh[i].triangles.size());
236 for (
size_t j = 0; j < trimesh[i].
triangles.size(); j++)
240 triangles.emplace_back(tri);
242 location += converted_vertices[i].size();
265 for (
size_t i = 0; i < vertices.size(); i++)
266 texel_count += vertices[i].size();
272 for (
size_t i = 0; i < vertices.size(); i++)
274 for (
size_t j = 0; j < vertices[i].size(); j++)
276 texel = tex_matrix * (vertices[i][j] - tex_vector);
277 texels[index].x = texel.x;
278 texels[index].y = texel.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, size_t &texel_count)
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