[235] | 1 | #include "ViewCell.h"
|
---|
| 2 | #include "Mesh.h"
|
---|
| 3 | #include "MeshKdTree.h"
|
---|
| 4 | #include "Triangle3.h"
|
---|
| 5 |
|
---|
[265] | 6 | ViewCell::ViewCell(): mMesh(NULL)
|
---|
| 7 | {
|
---|
| 8 | }
|
---|
[235] | 9 |
|
---|
| 10 | ViewCell::ViewCell(Mesh *mesh): mMesh(mesh), mPvs(NULL) |
---|
| 11 | { |
---|
| 12 | } |
---|
| 13 | |
---|
[261] | 14 | ViewCell::~ViewCell() |
---|
| 15 | { |
---|
[262] | 16 | // NOTE: should I really do this here? (I know that there is only one mesh per view cell) |
---|
[261] | 17 | DEL_PTR(mMesh); |
---|
| 18 | } |
---|
| 19 | |
---|
[235] | 20 | Mesh *ViewCell::GetMesh() |
---|
| 21 | { |
---|
| 22 | return mMesh; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | BspPvs *ViewCell::GetPVS() |
---|
| 26 | { |
---|
| 27 | return mPvs; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | AxisAlignedBox3 ViewCell::GetBox()
|
---|
| 31 | {
|
---|
| 32 | return mMesh->mBox;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | int ViewCell::CastRay(Ray &ray)
|
---|
| 36 | {
|
---|
| 37 | return 0;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | bool ViewCell::IsConvex() |
---|
| 41 | { |
---|
| 42 | return mMesh->mIsConvex; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | bool ViewCell::IsWatertight() |
---|
| 46 | { |
---|
| 47 | return mMesh->mIsWatertight; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | float ViewCell::IntersectionComplexity() |
---|
| 51 | { |
---|
[239] | 52 | return (float)mMesh->mFaces.size(); |
---|
[235] | 53 | } |
---|
| 54 | |
---|
| 55 | int ViewCell::Type() const
|
---|
| 56 | {
|
---|
| 57 | return VIEWCELL;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | void ViewCell::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
|
---|
| 61 | {
|
---|
| 62 | point = Vector3(0,0,0);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void ViewCell::DeriveViewCells(const ObjectContainer &objects,
|
---|
| 66 | ViewCellContainer &viewCells,
|
---|
[239] | 67 | const int maxViewCells)
|
---|
[235] | 68 | {
|
---|
[237] | 69 | // maximal max viewcells
|
---|
[245] | 70 | int limit = maxViewCells > 0 ? Min((int)objects.size(), maxViewCells) : (int)objects.size();
|
---|
[237] | 71 |
|
---|
[239] | 72 | for (int i = 0; i < limit; ++i)
|
---|
[235] | 73 | {
|
---|
| 74 | Intersectable *object = objects[i];
|
---|
[256] | 75 |
|
---|
[235] | 76 | // extract the mesh instances
|
---|
| 77 | if (object->Type() == Intersectable::MESH_INSTANCE)
|
---|
| 78 | {
|
---|
| 79 | MeshInstance *inst = dynamic_cast<MeshInstance *>(object);
|
---|
| 80 |
|
---|
| 81 | ViewCell *viewCell = new ViewCell(inst->GetMesh());
|
---|
| 82 | viewCells.push_back(viewCell);
|
---|
| 83 | }
|
---|
[237] | 84 | //TODO: transformed meshes
|
---|
[235] | 85 | }
|
---|
[245] | 86 | } |
---|
[260] | 87 | |
---|
[261] | 88 | ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height) |
---|
[260] | 89 | {
|
---|
[261] | 90 | // one mesh per view cell
|
---|
[260] | 91 | Mesh *mesh = new Mesh();
|
---|
[261] | 92 |
|
---|
| 93 | //-- construct prism
|
---|
[260] | 94 |
|
---|
[261] | 95 | // bottom
|
---|
[264] | 96 | mesh->mFaces.push_back(new Face(2,1,0));
|
---|
[261] | 97 | // top
|
---|
[264] | 98 | mesh->mFaces.push_back(new Face(3,4,5));
|
---|
[261] | 99 | // sides
|
---|
[264] | 100 | mesh->mFaces.push_back(new Face(1, 4, 3, 0));
|
---|
| 101 | mesh->mFaces.push_back(new Face(2, 5, 4, 1));
|
---|
| 102 | mesh->mFaces.push_back(new Face(3, 5, 2, 0));
|
---|
[261] | 103 |
|
---|
| 104 | //--- extrude new vertices for top of prism
|
---|
| 105 | Vector3 triNorm = baseTri.GetNormal();
|
---|
| 106 |
|
---|
| 107 | Triangle3 topTri;
|
---|
| 108 |
|
---|
| 109 | // add base vertices and calculate top vertices
|
---|
| 110 | for (int i = 0; i < 3; ++i)
|
---|
| 111 | {
|
---|
| 112 | mesh->mVertices.push_back(baseTri.mVertices[i]);
|
---|
| 113 | topTri.mVertices[i] = baseTri.mVertices[i] + height * triNorm;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | // add top vertices
|
---|
| 117 | for (int i = 0; i < 3; ++i)
|
---|
[262] | 118 | mesh->mVertices.push_back(topTri.mVertices[i]);
|
---|
[261] | 119 |
|
---|
[263] | 120 | mesh->Preprocess();
|
---|
| 121 |
|
---|
[260] | 122 | return new ViewCell(mesh); |
---|
| 123 | } |
---|