1 #include "property.hpp"
2
3 #include "data.hpp"
4 #include "controlled.hpp"
5
6 namespace Nif
7 {
8
read(NIFStream * nif)9 void NiTexturingProperty::Texture::read(NIFStream *nif)
10 {
11 inUse = nif->getBoolean();
12 if(!inUse) return;
13
14 texture.read(nif);
15 if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
16 {
17 clamp = nif->getInt();
18 nif->skip(4); // Filter mode. Ignoring because global filtering settings are more sensible
19 }
20 else
21 {
22 clamp = nif->getUShort() & 0xF;
23 }
24 // Max anisotropy. I assume we'll always only use the global anisotropy setting.
25 if (nif->getVersion() >= NIFStream::generateVersion(20,5,0,4))
26 nif->getUShort();
27
28 if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
29 uvSet = nif->getUInt();
30
31 // Two PS2-specific shorts.
32 if (nif->getVersion() < NIFStream::generateVersion(10,4,0,2))
33 nif->skip(4);
34 if (nif->getVersion() <= NIFStream::generateVersion(4,1,0,18))
35 nif->skip(2); // Unknown short
36 else if (nif->getVersion() >= NIFStream::generateVersion(10,1,0,0))
37 {
38 if (nif->getBoolean()) // Has texture transform
39 {
40 nif->getVector2(); // UV translation
41 nif->getVector2(); // UV scale
42 nif->getFloat(); // W axis rotation
43 nif->getUInt(); // Transform method
44 nif->getVector2(); // Texture rotation origin
45 }
46 }
47 }
48
post(NIFFile * nif)49 void NiTexturingProperty::Texture::post(NIFFile *nif)
50 {
51 texture.post(nif);
52 }
53
read(NIFStream * nif)54 void NiTexturingProperty::read(NIFStream *nif)
55 {
56 Property::read(nif);
57 if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB_OLD || nif->getVersion() >= NIFStream::generateVersion(20,1,0,2))
58 flags = nif->getUShort();
59 if (nif->getVersion() <= NIFStream::generateVersion(20,1,0,1))
60 apply = nif->getUInt();
61
62 unsigned int numTextures = nif->getUInt();
63
64 if (!numTextures)
65 return;
66
67 textures.resize(numTextures);
68 for (unsigned int i = 0; i < numTextures; i++)
69 {
70 textures[i].read(nif);
71 if (i == 5 && textures[5].inUse) // Bump map settings
72 {
73 envMapLumaBias = nif->getVector2();
74 bumpMapMatrix = nif->getVector4();
75 }
76 else if (i == 7 && textures[7].inUse && nif->getVersion() >= NIFStream::generateVersion(20,2,0,5))
77 /*float parallaxOffset = */nif->getFloat();
78 }
79
80 if (nif->getVersion() >= NIFStream::generateVersion(10,0,1,0))
81 {
82 unsigned int numShaderTextures = nif->getUInt();
83 shaderTextures.resize(numShaderTextures);
84 for (unsigned int i = 0; i < numShaderTextures; i++)
85 {
86 shaderTextures[i].read(nif);
87 if (shaderTextures[i].inUse)
88 nif->getUInt(); // Unique identifier
89 }
90 }
91 }
92
post(NIFFile * nif)93 void NiTexturingProperty::post(NIFFile *nif)
94 {
95 Property::post(nif);
96 for (size_t i = 0; i < textures.size(); i++)
97 textures[i].post(nif);
98 for (size_t i = 0; i < shaderTextures.size(); i++)
99 shaderTextures[i].post(nif);
100 }
101
read(NIFStream * nif)102 void BSShaderProperty::read(NIFStream *nif)
103 {
104 NiShadeProperty::read(nif);
105 if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3)
106 {
107 type = nif->getUInt();
108 flags1 = nif->getUInt();
109 flags2 = nif->getUInt();
110 envMapIntensity = nif->getFloat();
111 }
112 }
113
read(NIFStream * nif)114 void BSShaderLightingProperty::read(NIFStream *nif)
115 {
116 BSShaderProperty::read(nif);
117 if (nif->getBethVersion() <= NIFFile::BethVersion::BETHVER_FO3)
118 clamp = nif->getUInt();
119 }
120
read(NIFStream * nif)121 void BSShaderPPLightingProperty::read(NIFStream *nif)
122 {
123 BSShaderLightingProperty::read(nif);
124 textureSet.read(nif);
125 if (nif->getBethVersion() <= 14)
126 return;
127 refraction.strength = nif->getFloat();
128 refraction.period = nif->getInt();
129 if (nif->getBethVersion() <= 24)
130 return;
131 parallax.passes = nif->getFloat();
132 parallax.scale = nif->getFloat();
133 }
134
post(NIFFile * nif)135 void BSShaderPPLightingProperty::post(NIFFile *nif)
136 {
137 BSShaderLightingProperty::post(nif);
138 textureSet.post(nif);
139 }
140
read(NIFStream * nif)141 void BSShaderNoLightingProperty::read(NIFStream *nif)
142 {
143 BSShaderLightingProperty::read(nif);
144 filename = nif->getSizedString();
145 if (nif->getBethVersion() >= 27)
146 falloffParams = nif->getVector4();
147 }
148
read(NIFStream * nif)149 void NiFogProperty::read(NIFStream *nif)
150 {
151 Property::read(nif);
152 mFlags = nif->getUShort();
153 mFogDepth = nif->getFloat();
154 mColour = nif->getVector3();
155 }
156
read(NIFStream * nif)157 void S_MaterialProperty::read(NIFStream *nif)
158 {
159 if (nif->getBethVersion() < 26)
160 {
161 ambient = nif->getVector3();
162 diffuse = nif->getVector3();
163 }
164 specular = nif->getVector3();
165 emissive = nif->getVector3();
166 glossiness = nif->getFloat();
167 alpha = nif->getFloat();
168 if (nif->getBethVersion() >= 22)
169 emissiveMult = nif->getFloat();
170 }
171
read(NIFStream * nif)172 void S_VertexColorProperty::read(NIFStream *nif)
173 {
174 vertmode = nif->getInt();
175 lightmode = nif->getInt();
176 }
177
read(NIFStream * nif)178 void S_AlphaProperty::read(NIFStream *nif)
179 {
180 threshold = nif->getChar();
181 }
182
read(NIFStream * nif)183 void S_StencilProperty::read(NIFStream *nif)
184 {
185 if (nif->getVersion() <= NIFFile::NIFVersion::VER_OB)
186 {
187 enabled = nif->getChar();
188 compareFunc = nif->getInt();
189 stencilRef = nif->getUInt();
190 stencilMask = nif->getUInt();
191 failAction = nif->getInt();
192 zFailAction = nif->getInt();
193 zPassAction = nif->getInt();
194 drawMode = nif->getInt();
195 }
196 else
197 {
198 unsigned short flags = nif->getUShort();
199 enabled = flags & 0x1;
200 failAction = (flags >> 1) & 0x7;
201 zFailAction = (flags >> 4) & 0x7;
202 zPassAction = (flags >> 7) & 0x7;
203 drawMode = (flags >> 10) & 0x3;
204 compareFunc = (flags >> 12) & 0x7;
205 stencilRef = nif->getUInt();
206 stencilMask = nif->getUInt();
207 }
208 }
209
210
211
212 }
213