| 1 | // tLodGroup.cpp  |
| 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 | #include "Scene/tLodGroup.h"  |
| 18 | namespace tScene  |
| 19 | {  |
| 20 |   |
| 21 |   |
| 22 | void tLodParam::Save(tChunkWriter& chunk) const  |
| 23 | {  |
| 24 | chunk.Begin(tChunkID::Scene_LodParam);  |
| 25 | {  |
| 26 | chunk.Write(ModelID);  |
| 27 | chunk.Write(Threshold);  |
| 28 | }  |
| 29 | chunk.End();  |
| 30 | }  |
| 31 |   |
| 32 |   |
| 33 | void tLodParam::Load(const tChunk& chunk)  |
| 34 | {  |
| 35 | tAssert(chunk.GetID() == tChunkID::Scene_LodParam);  |
| 36 | chunk.GetItem(ModelID);  |
| 37 | chunk.GetItem(Threshold);  |
| 38 | }  |
| 39 |   |
| 40 |   |
| 41 | void tLodGroup::Save(tChunkWriter& chunk) const  |
| 42 | {  |
| 43 | chunk.Begin(tChunkID::Scene_LodGroup);  |
| 44 | {  |
| 45 | if (!LodParams.IsEmpty())  |
| 46 | {  |
| 47 | chunk.Begin(tChunkID::Scene_LodParams);  |
| 48 | {  |
| 49 | for (tItList<tLodParam>::Iter info = LodParams.First(); info; ++info)  |
| 50 | info->Save(chunk);  |
| 51 | }  |
| 52 | chunk.End();  |
| 53 | }  |
| 54 | }  |
| 55 | chunk.End();  |
| 56 | }  |
| 57 |   |
| 58 |   |
| 59 | void tLodGroup::Load(const tChunk& lodChunk)  |
| 60 | {  |
| 61 | tAssert(lodChunk.GetID() == tChunkID::Scene_LodGroup);  |
| 62 | Clear();  |
| 63 |   |
| 64 | for (tChunk chunk = lodChunk.First(); chunk.IsValid(); chunk = chunk.Next())  |
| 65 | {  |
| 66 | switch (chunk.GetID())  |
| 67 | {  |
| 68 | case tChunkID::Scene_Object:  |
| 69 | tObject::Load(chunk);  |
| 70 | break;  |
| 71 |   |
| 72 | case tChunkID::Scene_LodParams:  |
| 73 | for (tChunk info = chunk.First(); info.Valid(); info = info.Next())  |
| 74 | {  |
| 75 | switch (info.GetID())  |
| 76 | {  |
| 77 | case tChunkID::Scene_LodParam:  |
| 78 | LodParams.Append(new tLodParam(info));  |
| 79 | break;  |
| 80 | }  |
| 81 | }  |
| 82 | break;  |
| 83 | }  |
| 84 | }  |
| 85 | }  |
| 86 |   |
| 87 |   |
| 88 | }  |
| 89 | |