Skyscraper 2.0
mesh.h
Go to the documentation of this file.
1/*
2 Scalable Building Simulator - Mesh Object
3 The Skyscraper Project - Version 2.0
4 Copyright (C)2004-2024 Ryan Thoryk
5 https://www.skyscrapersim.net
6 https://sourceforge.net/projects/skyscraper/
7 Contact - ryan@skyscrapersim.net
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22*/
23
24#ifndef _SBS_MESH_H
25#define _SBS_MESH_H
26
27#include "triangle.h"
28
29namespace SBS {
30
31struct Extents
32{
33 unsigned int min;
34 unsigned int max;
35
36 Extents(unsigned int min, unsigned int max)
37 {
38 this->min = min;
39 this->max = max;
40 }
41};
42
44{
45public:
46 std::string name; //mesh name
47 bool create_collider; //set to false if collider shouldn't be automatically generated
48 bool tricollider; //collider type; box if false, triangle if true
49 bool remove_on_disable; //if true (the default), remove the collider from world when disabling mesh
50
51 MeshObject(Object* parent, const std::string &name, DynamicMesh* wrapper = 0, const std::string &filename = "", const std::string &meshname = "", Real max_render_distance = 0, Real scale_multiplier = 1, bool create_collider = true, bool dynamic_buffers = false);
52 virtual ~MeshObject();
53 void Enabled(bool value);
54 void EnableCollider(bool value);
55 bool IsEnabled();
56 Wall* CreateWallObject(const std::string &name);
57 Wall* GetWallByName(std::string name);
58 void Prepare(bool force = false);
59 void EnableDebugView(bool value);
60 void CreateColliderFromModel(int &vertex_count, Vector3* &vertices, int &index_count, unsigned long* &indices);
61 void CreateBoxCollider();
62 void DeleteWalls();
63 void DeleteWalls(Object *parent);
64 Vector3 GetPoint(const std::string &wallname, const Vector3 &start, const Vector3 &end);
65 Vector3 GetWallExtents(const std::string &name, Real altitude, bool get_max);
66 void OnMove(bool parent);
67 void OnRotate(bool parent);
68 bool IsVisible(Ogre::Camera *camera);
69 bool IsPhysical();
70 Vector3 GetOffset();
71 void Cut(Vector3 start, Vector3 end, bool cutwalls, bool cutfloors, int checkwallnumber = 0, bool reset_check = true);
72 void CutOutsideBounds(Vector3 start, Vector3 end, bool cutwalls, bool cutfloors);
73 bool UsingDynamicBuffers();
74 void GetBounds();
75 void ChangeHeight(Real newheight);
76 void EnableShadows(bool value);
77 PolyMesh* GetPolyMesh();
78 bool IsPrepared();
79 void ResetPrepare();
80 bool ReplaceTexture(const std::string &oldtexture, const std::string &newtexture);
81 bool ChangeTexture(const std::string &texture, bool matcheck = true);
82 Vector2 GetExtents(int coord, bool flip_z = false);
83 Real GetHeight();
84 Real HitBeam(const Vector3 &origin, const Vector3 &direction, Real max_distance);
85 void CreateCollider();
86 void DeleteCollider();
87 Wall* FindPolygon(const std::string &name, int &index);
88 bool InBoundingBox(const Vector3 &pos, bool check_y);
89 DynamicMesh* GetDynamicMesh();
90 void GetMeshInformation(const Ogre::Mesh* const mesh, int &vertex_count, Vector3* &vertices, int &index_count, unsigned long* &indices, Ogre::AxisAlignedBox &extents);
91 unsigned int GetVertexCount();
92 unsigned int GetTriangleCount(const std::string &material, bool total);
93 bool LoadFromMesh(const std::string &meshname);
94 void SetMaterial(const std::string& material);
95 void EnablePhysics(bool value, Real restitution = 0, Real friction = 0, Real mass = 0);
96 size_t GetSize();
97
98 DynamicMesh *MeshWrapper; //dynamic mesh this mesh object uses
99 std::vector<Wall*> Walls; //associated wall (polygon container) objects
100
101 SceneNode *collider_node; //collider scenenode for box collider offsets
102 Ogre::AxisAlignedBox *Bounds; //mesh bounds
103
104 OgreBulletDynamics::RigidBody* mBody;
105 OgreBulletCollisions::CollisionShape* mShape;
106
107 std::string Filename; //filename, if a loaded model
108 std::string Meshname; //name of loaded Ogre mesh (used for primitives)
109 bool model_loaded; //true if a model was loaded successfully
110
111private:
114 Real restitution, friction, mass;
117 bool LoadFromFile(const std::string &filename);
118 bool LoadColliderModel(Ogre::MeshPtr &collidermesh);
119
121 Ogre::MeshPtr collidermesh;
122 size_t size;
123};
124
125}
126
127#endif
OgreBulletCollisions::CollisionShape * mShape
Definition mesh.h:105
std::string Filename
Definition mesh.h:107
size_t size
Definition mesh.h:122
Real friction
Definition mesh.h:114
bool model_loaded
Definition mesh.h:109
std::vector< Wall * > Walls
Definition mesh.h:99
bool wrapper_selfcreate
Definition mesh.h:116
PolyMesh * polymesh
Definition mesh.h:120
bool remove_on_disable
Definition mesh.h:49
Ogre::MeshPtr collidermesh
Definition mesh.h:121
bool is_physical
Definition mesh.h:113
bool tricollider
Definition mesh.h:48
bool enabled
Definition mesh.h:112
OgreBulletDynamics::RigidBody * mBody
Definition mesh.h:104
Ogre::AxisAlignedBox * Bounds
Definition mesh.h:102
DynamicMesh * MeshWrapper
Definition mesh.h:98
bool prepared
Definition mesh.h:115
bool create_collider
Definition mesh.h:47
SceneNode * collider_node
Definition mesh.h:101
std::string name
Definition mesh.h:46
std::string Meshname
Definition mesh.h:108
Ogre::Vector3 Vector3
Definition globals.h:58
Ogre::Real Real
Definition globals.h:57
Ogre::Vector2 Vector2
Definition globals.h:59
#define SBSIMPEXP
Definition globals.h:53
Extents(unsigned int min, unsigned int max)
Definition mesh.h:36
unsigned int min
Definition mesh.h:33
unsigned int max
Definition mesh.h:34