1 | // tLodGroup.h  |
2 | //  |
3 | // This unit implements scene LOD groups. LOD groups basically specify what model to use based on a size threshold.  |
4 | // The threshold is based on screen-size, not distance. This is much more correct as it allows narrow camera FOVs  |
5 | // without things looking pixelated.  |
6 | //  |
7 | // Copyright (c) 2006, 2017 Tristan Grimmer.  |
8 | // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby  |
9 | // granted, provided that the above copyright notice and this permission notice appear in all copies.  |
10 | //  |
11 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL  |
12 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,  |
13 | // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  |
14 | // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  |
15 | // PERFORMANCE OF THIS SOFTWARE.  |
16 |   |
17 | #pragma once  |
18 | #include <Foundation/tList.h>  |
19 | #include "Scene/tObject.h"  |
20 | namespace tScene  |
21 | {  |
22 |   |
23 |   |
24 | class tLodParam  |
25 | {  |
26 | public:  |
27 | tLodParam() { }  |
28 | tLodParam(const tChunk& chunk) { Load(chunk); }  |
29 | virtual ~tLodParam() { }  |
30 |   |
31 | void Save(tChunkWriter&) const;  |
32 | void Load(const tChunk&);  |
33 |   |
34 | uint32 ModelID = 0;  |
35 |   |
36 | // The threshold is the proportion of screen width at which the LOD swap should occur. Doing it this way makes it  |
37 | // respect the camera FOV and does not tie it to screen resolution. The runtime can decide to consider the current  |
38 | // screen resolution if it likes. A value of 1.0 means that the object takes up the entire screen, 0.5 means half  |
39 | // the screen. The values are NOT restricted to [0.0, 1.0]. It is valid to have values > 1.0. If a runtime object  |
40 | // takes up less room than the threshold then the ModelID should not be used. The biggest lod info threshold value  |
41 | // that is less than the current percent is the right one.  |
42 | float Threshold = 0.0f;  |
43 | };  |
44 |   |
45 |   |
46 | class tLodGroup : public tObject  |
47 | {  |
48 | public:  |
49 | tLodGroup() : tObject(), LodParams() { }  |
50 | tLodGroup(const tChunk& chunk) : tObject(), LodParams() { Load(chunk); }  |
51 | virtual ~tLodGroup() { }  |
52 |   |
53 | void Load(const tChunk&);  |
54 | void Save(tChunkWriter&) const;  |
55 | void Clear() { tObject::Clear(); LodParams.Empty(); }  |
56 | int GetNumLodInfos() const { return LodParams.GetNumItems(); }  |
57 |   |
58 | // This call will sort all the lod params from highest threshold to lowest.  |
59 | void Sort() { LodParams.Sort(ThresholdCompare); }  |
60 | tItList<tLodParam> LodParams;  |
61 |   |
62 | private:  |
63 | // Implements a > b so the list is sorted in descending order.  |
64 | inline static bool ThresholdCompare(const tLodParam& a, const tLodParam& b) { return (a.Threshold > b.Threshold) ? true : false; }  |
65 | };  |
66 |   |
67 |   |
68 | }  |
69 | |