-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copia de NIF_Files.cpp
171 lines (144 loc) · 5.06 KB
/
Copia de NIF_Files.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Emergent Game Technologies and may not
// be copied or disclosed except in accordance with the terms of that
// agreement.
//
// Copyright (c) 1996-2009 Emergent Game Technologies.
// All Rights Reserved.
//
// Emergent Game Technologies, Chapel Hill, North Carolina 27517
// http://www.emergent.net
#include <NiMain.h>
#include <NiAnimation.h>
#include <NiParticle.h>
#include <NiLicense.h>
NiEmbedGamebryoLicenseCode;
#include "NIF_Files.h"
//---------------------------------------------------------------------------
NiApplication* NiApplication::Create()
{
return NiNew NIF_Files;
}
//---------------------------------------------------------------------------
NIF_Files::NIF_Files() : NiSample("Tutorial: Loading And Rendering a NIF File",
DEFAULT_WIDTH, DEFAULT_HEIGHT, true)
{
#if defined(_XENON)
SetMediaPath("D:/DATA/");
#elif defined (WIN32)
SetMediaPath("../../../DATA/");
#elif defined (_PS3)
SetMediaPath("../../../../Data/");
#elif defined(_WII)
SetMediaPath("/Tutorials/Graphics/Data/");
m_uiMaxOutputLogLines = 4;
#endif
m_bUseNavSystem = false;
}
//---------------------------------------------------------------------------
bool NIF_Files::CreateScene()
{
// Because our scene will have some billboards with alpha, we use
// a NiAlphaAccumulator in order that our alpha gets sorted and drawn
// correctly.
NiAlphaAccumulator* pkAccum = NiNew NiAlphaAccumulator;
m_spRenderer->SetSorter(pkAccum);
// NiStreams are used to load a NIF file from disk. Once a stream is
// loaded, it will contain one or more "top-level" objects. These objects
// could be NiNodes, NiTextures, or any other Gamebryo class. The Max and
// Maya exporters both place the scene graph as the first element in the
// NIF file.
NiStream kStream;
// Load in the scenegraph for our world...
bool bSuccess = kStream.Load(
NiApplication::ConvertMediaFilename("GameScene.nif"));
if (!bSuccess)
{
NiMessageBox("WORLD.NIF file could not be loaded!", "NIF Error");
return false;
}
m_spScene = (NiNode*) kStream.GetObjectAt(0);
NIASSERT(NiIsKindOf(NiNode, m_spScene));
// We expect the world to have been exported with a camera, so we
// look for it here.
// In order to render the scene graph, we need a camera. We're now going
// to recurse the scene graph looking for a camera.
if (!FindSceneCamera())
{
NiMessageBox("The NIF file has no camera!", "Camera Error");
return false;
}
NiTObjectArray<NiCameraPtr> kCameras;
NiTObjectArray<NiLightPtr> kLights;
NiTObjectArray<NiNodePtr> kScenes;
//NiStream kStream;
//bool bSuccess = kStream.Load(
// NiApplication::ConvertMediaFilename("GameScene.nif"));
// if (!bSuccess)
// {
// NiMessageBox("WORLD.NIF file could not be loaded!", "NIF Error");
// return false;
// }
for (unsigned int i = 0; i < kStream.GetObjectCount(); i++)
{
NiObject* pkObject = kStream.GetObjectAt(i);
if (NiIsKindOf(NiCamera, pkObject))
kCameras.Add((NiCamera*) pkObject);
else if (NiIsKindOf(NiLight, pkObject))
kLights.Add((NiLight*) pkObject);
else if (NiIsKindOf(NiNode, pkObject))
kScenes.Add((NiNode*) pkObject);
else
{
// unknown object, handle it somehow
}
}
//m_spScene = (NiNode*) kStream.GetObjectAt(0);
// NIASSERT(NiIsKindOf(NiNode, m_spScene));
return bSuccess;
}
//---------------------------------------------------------------------------
bool NIF_Files::CreateUIElements()
{
NiSample::CreateUIElements();
// The Log is a text output used by all NiSample derived classes
AddLogEntry("Press ESC or Start + Select to quit");
return true;
}
//---------------------------------------------------------------------------
bool NIF_Files::FindSceneCamera()
{
if (m_spScene)
{
m_spCamera = FindCamera(m_spScene);
}
return (m_spCamera != NULL);
}
//---------------------------------------------------------------------------
NiCamera* NIF_Files::FindCamera(NiAVObject* pkObject)
{
// This function recursively walks the scenegraph until a camera
// is found.
if (NiIsKindOf(NiCamera, pkObject))
{
return (NiCamera*) pkObject;
}
else if (NiIsKindOf(NiNode, pkObject))
{
// NiNodes are the primary structural objects in Gamebryo. They
// group other Gamebryo scene objects together under a common parent
// and coordinate system. NiNodes can have as many children as
// necessary, but those children are not guaranteed to be contiguous.
NiNode* pkNode = (NiNode*) pkObject;
for (unsigned int ui = 0; ui < pkNode->GetArrayCount(); ui++)
{
NiCamera* pkFoundCamera = FindCamera(pkNode->GetAt(ui));
if (pkFoundCamera)
return pkFoundCamera;
}
}
return NULL;
}
//---------------------------------------------------------------------------