104 for (std::list<ModelNode_Witcher *>::iterator n = nodes.begin(); n != nodes.end(); ++n)
145 throw Common::Exception(
"Unsupported model count %d in The Witcher MDB", modelCount);
200 ctx.
nodes.push_back(rootNode);
220 for (std::list<ModelNode_Witcher *>::iterator n = ctx.
nodes.begin();
221 n != ctx.
nodes.end(); ++n) {
224 ctx.
state->
nodeMap.insert(std::make_pair((*n)->getName(), *n));
226 if (!(*n)->getParent())
258 uint32 childrenOffset, childrenCount;
261 std::vector<uint32> children;
264 uint32 controllerKeyOffset, controllerKeyCount;
267 uint32 controllerDataOffset, controllerDataCount;
270 std::vector<float> controllerData;
272 controllerDataCount, controllerData);
275 controllerKeyCount, controllerData);
302 if (ctx.
state->name.size() != 0) {
303 meshName += ctx.
state->name;
305 meshName +=
"xoreos.default";
321 if (ctx.
state->name.size() == 0) {
322 while (mystery_mesh) {
324 mystery_mesh =
MeshMan.getMesh(meshName);
331 warning(
"Warning: probable mesh duplication of: %s, attempting to correct", meshName.
c_str());
346 if ((minLOD != -1) && (maxLOD != -1) && (minLOD > 0))
349 for (std::vector<uint32>::const_iterator child = children.begin(); child != children.end(); ++child) {
351 ctx.
nodes.push_back(childNode);
356 childNode->
load(ctx);
368 float boundingMin[3], boundingMax[3];
393 float textureTransRot[3];
410 for (
int t = 0; t < 4; t++) {
413 if (texture[t] ==
"NULL")
438 bool distFromScreenCenterFace = ctx.
mdb->
readByte() == 1;
458 float reflectionPlaneNormal[3];
465 bool fadeOnCameraCollision = ctx.
mdb->
readByte() == 1;
474 bool ignoreLODReflection = ctx.
mdb->
readByte() == 1;
485 uint32 vertexOffset, vertexCount;
488 uint32 normalsOffset, normalsCount;
491 uint32 tangentsOffset, tangentsCount;
494 uint32 biNormalsOffset, biNormalsCount;
497 uint32 tVertsOffset[4], tVertsCount[4];
498 for (
uint t = 0; t < 4; t++)
501 uint32 unknownOffset, unknownCount;
504 uint32 facesOffset, facesCount;
511 if ((vertexCount == 0) || (facesCount == 0)) {
520 std::vector<Common::UString> textures;
523 evaluateTextures(4, textures, texture, tVertsCount, dayNightLightMaps, lightMapName);
527 size_t texCount = textures.size();
535 for (
uint t = 0; t < texCount; t++)
543 for (
uint32 i = 0; i < vertexCount; i++) {
550 assert(normalsCount == vertexCount);
553 for (
uint32 i = 0; i < normalsCount; i++) {
560 for (
uint t = 0; t < texCount; t++) {
564 for (
uint32 i = 0; i < tVertsCount[t]; i++) {
565 if (i < tVertsCount[t]) {
582 for (
uint32 i = 0; i < facesCount; i++) {
603 uint32 layersOffset, layersCount;
615 float boundingMin[3], boundingMax[3];
634 float textureTransRot[3];
668 float reflectionPlaneNormal[3];
675 bool fadeOnCameraCollision = ctx.
mdb->
readByte() == 1;
687 bool ignoreLODReflection = ctx.
mdb->
readByte() == 1;
695 uint32 vertexOffset, vertexCount;
698 uint32 normalsOffset, normalsCount;
701 uint32 tangentsOffset, tangentsCount;
704 uint32 biNormalsOffset, biNormalsCount;
707 uint32 tVertsOffset[4], tVertsCount[4];
708 for (
uint t = 0; t < 4; t++)
711 uint32 unknownOffset, unknownCount;
714 uint32 facesOffset, facesCount;
717 if ((vertexCount == 0) || (facesCount == 0)) {
726 std::vector<TexturePaintLayer> layers;
727 layers.resize(layersCount);
729 for (
uint32 l = 0; l < layersCount; l++) {
733 if (!layers[l].hasTexture)
741 uint32 weightsOffset, weightsCount;
745 layers[l].weights.resize(weightsCount);
747 for (std::vector<float>::iterator w = layers[l].weights.begin(); w != layers[l].weights.end(); ++w)
751 std::vector<Common::UString> textures;
752 textures.push_back(lightMapName);
754 evaluateTextures(1, textures, 0, tVertsCount, dayNightLightMaps, lightMapName);
758 size_t texCount = textures.size();
766 for (
uint t = 0; t < texCount; t++)
774 for (
uint32 i = 0; i < vertexCount; i++) {
781 assert(normalsCount == vertexCount);
784 for (
uint32 i = 0; i < normalsCount; i++) {
791 for (
uint t = 0; t < texCount; t++) {
795 for (
uint32 i = 0; i < tVertsCount[t]; i++) {
796 if (i < tVertsCount[t]) {
813 for (
uint32 i = 0; i < facesCount; i++) {
828 if (
GfxMan.isRendererExperimental())
833 std::vector<Common::UString> &textures) {
846 std::vector<Common::UString> textureLine;
847 textureLine.resize(textureCount);
848 for (std::vector<Common::UString>::iterator line = textureLine.begin(); line != textureLine.end(); ++line) {
857 int hasShaderTex =
false;
859 for (std::vector<Common::UString>::const_iterator line = textureLine.begin(); line != textureLine.end(); ++line) {
863 if (line->beginsWith(
"texture texture0 ")) {
865 n = 0 + (hasShaderTex ? 1 : 0);
866 }
else if (line->beginsWith(
"texture texture1 ")) {
868 n = 1 + (hasShaderTex ? 1 : 0);
869 }
else if (line->beginsWith(
"texture texture2 ")) {
871 n = 2 + (hasShaderTex ? 1 : 0);
872 }
else if (line->beginsWith(
"texture texture3 ")) {
875 }
else if (line->beginsWith(
"texture tex ")) {
877 n = 0 + (hasShaderTex ? 1 : 0);
878 }
else if (line->beginsWith(
"shader ")) {
882 if ((shader ==
"dadd_al_mul_alp") ||
883 (shader ==
"corona") ||
884 (shader ==
"normalmap") ||
885 (shader ==
"norm_env_rim_ao") ||
886 (shader ==
"transparency_2ps") ||
887 (shader ==
"skin_n_rim_ao"))
888 hasShaderTex =
false;
892 textures[n] = line->substr(line->getPosition(s), line->end());
903 for (
int t = 0; t < n; t++) {
904 if (textures[t].empty() && staticTextures)
905 textures[t] = staticTextures[t];
907 if (tVertsCount[t] == 0)
910 if (textures[t].empty())
913 if (lightMapDayNight && (textures[t] == lightMapName)) {
934 while (!textures.empty() && textures.back().empty())
939 uint32 offset,
uint32 count, std::vector<float> &data) {
945 for (
uint32 i = 0; i < count; i++) {
953 if (rowCount == 0xFFFF)
958 if (columnCount != 3)
966 if (columnCount != 4)
1035 if (textureCount == 0) {
1056 uint32 materialFlags = 0;
1061 for (
uint32 i = 0; i < decl.size(); ++i) {
1062 switch (decl[i].index) {
1099 materialName += penvmap->
getName();
1129 if (textureCount >= 1) {
1130 if (!phandles[0].empty()) {
1131 materialName += phandles[0].
getName();
1137 if (textureCount >= 2) {
1146 if (phandles[0].getTexture().getTXI().getFeatures().blending) {
1150 if (phandles[0].getTexture().getTXI().getFeatures().decal) {
1173 if (textureCount >= 2) {
1174 if (!phandles[1].empty()) {
1175 materialName +=
".";
1176 materialName += phandles[1].
getName();
1187 if (textureCount >= 3) {
1188 if (!phandles[2].empty()) {
1189 materialName +=
".";
1190 materialName += phandles[2].
getName();
1196 if (textureCount >= 4) {
1198 if (!phandles[3].empty()) {
1199 materialName +=
".";
1200 materialName += phandles[3].
getName();
1208 materialName += penvmap->
getName();
1222 surface =
SurfaceMan.getSurface(materialName);
1228 materialFlags &= ~Shader::ShaderMaterial::MATERIAL_OPAQUE;
1232 cripter.
genName(vertexShaderName);
1233 fragmentShaderName = vertexShaderName +
".frag";
1234 vertexShaderName +=
".vert";
1241 if (!vertexObject) {
1243 bool isGL3 =
GfxMan.isGL3();
1248 cripter.
build(isGL3, vertexStringFinal, fragmentStringFinal);
1263 sampler->
handle = *penvmap;
1266 if (textureCount >= 1) {
1267 if (!phandles[0].empty()) {
1268 if (textureCount >= 2) {
1273 sampler->
handle = phandles[0];
1277 if (textureCount >= 2) {
1278 if (!phandles[1].empty()) {
1280 sampler->
handle = phandles[1];
#define ResMan
Shortcut for accessing the sound manager.
GLvoid * getData()
Access buffer data.
const Common::UString & getState() const
Return the name of the current state.
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
Generic image decoder interface.
NodeMap nodeMap
The nodes within the state, indexed by name.
EnvironmentMapMode
The way the environment map is applied to a model node.
void build(bool isGL3, Common::UString &v_string, Common::UString &f_string)
Vertex texture coordinates, VTCOORDi = VTCOORD + i.
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
ParserContext(const Common::UString &name)
Texture & getTexture() const
Not strictly speaking an input, but generated for an output.
A class holding an UTF-8 string.
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
VertexBuffer * getVertexBuffer()
Model_Witcher(const Common::UString &name, ModelType type=kModelTypeObject)
#define SurfaceMan
Shortcut for accessing the shader manager.
void loadTextures(const std::vector< Common::UString > &textures)
void addState(ParserContext &ctx)
void * getVariableData(uint32 index) const
bool beginsWith(const UString &with) const
void init()
General mesh initialisation, queuing the mesh for GL resource creation.
The Aurora texture manager.
bool render
Render this mesh?
Common::UString name
The state's name.
NodeList rootNodes
The nodes in the state without a parent.
void readMesh(Model_Witcher::ParserContext &ctx)
void setParent(ModelNode *parent)
Set the node's parent.
State * _currentState
The current state.
Render hint; material has no transparency.
Utility functions for generating unique IDs.
Diffuse textures first, then blend the environment map in.
bool _render
Render the node?
void load(ParserContext &ctx)
Different to default blending. Maybe this should be extended one day.
TextureHandle * getEnvironmentMap(EnvironmentMapMode &mode)
void declareSampler(ShaderDescriptor::Sampler sampler, ShaderDescriptor::SamplerType type)
bool isCubeMap() const
Is this image a cube map?
Common::UString _fileName
The model's file name.
friend class ModelNode_Witcher
TextureHandle * getTextures(uint32 &count)
std::vector< VertexAttrib > VertexDecl
Vertex data layout.
#define IGNORE_UNUSED_VARIABLES
void connect(ShaderDescriptor::Sampler sampler, ShaderDescriptor::Input input, ShaderDescriptor::Action action)
Connect an input to a sampler and an action.
Exception that provides a stack of explanations.
const VertexDecl & getVertexDecl() const
Access vertex declaration.
void setFlags(uint32 flags)
NodeTrimeshControllerType
Environment map first, then blend the diffuse textures in.
Model * _model
The model this node belongs to.
Common::UString _name
The model's name.
const ImageDecoder & getImage() const
Return the image.
bool _dirtyRender
Rendering information needs updating.
Basic exceptions to throw.
UString substr(iterator from, iterator to) const
UString readStringLine(SeekableReadStream &stream, Encoding encoding)
Read a line with the given encoding out of a stream.
const char * c_str() const
Return the (utf8 encoded) string data.
Not strictly speaking an input, but generated for an output.
Graphics::Aurora::TextureHandle handle
void readNodeControllers(Model_Witcher::ParserContext &ctx, uint32 offset, uint32 count, std::vector< float > &data)
ModelType
The display type of a model.
Common::SeekableReadStream * mdb
TextureHandle envMap
The environment map texture.
Not really blending, but component-wise multiply.
static void readArray(Common::SeekableReadStream &stream, uint32 offset, uint32 count, std::vector< T > &values)
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
Material definitely has transparency.
void readTextures(Model_Witcher::ParserContext &ctx, std::vector< Common::UString > &textures)
void setVertexDeclLinear(uint32 vertCount, VertexDecl &decl)
Set the linear vertex declaration for this buffer.
float ambient[3]
Ambient color.
Utility functions for working with differing string encodings.
The global shader material manager.
bool empty() const
Is the string empty?
The global shader surface manager.
#define MaterialMan
Shortcut for accessing the shader material manager.
float _position[3]
Position of the node.
NodeList nodeList
The nodes within the state.
void warning(const char *s,...)
StateMap _stateMap
All states within this model, index by name.
std::vector< TextureHandle > textures
Textures.
Basic reading stream interfaces.
void evaluateTextures(int n, std::vector< Common::UString > &textures, const Common::UString *staticTextures, const uint32 *tVertsCount, bool lightMapDayNight, const Common::UString &lightMapName)
void load(Model_Witcher::ParserContext &ctx)
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
FORCEINLINE float readIEEEFloatLE()
Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it...
#define MeshMan
Shortcut for accessing the shader manager.
Basic type definitions to handle files used in BioWare's Aurora engine.
Plain, unextended ASCII (7bit clean).
Shader sampler is used to bind a texture to a texture unit.
Loading MDB files found in The Witcher.
Graphics::Mesh::Mesh * rawMesh
Node raw mesh data.
Common::UString _name
The node's name.
Uniform variable colour information.
std::vector< Shader::ShaderRenderable > _renderableArray
Damn you bioware.
A texture as used in the Aurora engines.
bool shadow
Does the node have a shadow?
#define ShaderMan
Shortcut for accessing the shader manager.
void genName(Common::UString &n_string)
Generate a name to asscoiate with the current description.
static void readArrayDef(Common::SeekableReadStream &stream, uint32 &offset, uint32 &count)
GLvoid * getData()
Access buffer data.
float diffuse[3]
Diffuse color.
float _orientation[4]
Orientation of the node.
void addPass(ShaderDescriptor::Action action, ShaderDescriptor::Blend blend)
UString readString(SeekableReadStream &stream, Encoding encoding)
Read a string with the given encoding of a stream.
static float rad2deg(float rad)
void finalize()
Finalize the loading procedure.
void readTexturePaint(Model_Witcher::ParserContext &ctx)
ModelNode * _rootStateNode
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
const Common::UString & getName() const
void newState(ParserContext &ctx)
void setName(const Common::UString &name)
void declareInput(ShaderDescriptor::Input input)
std::list< ModelNode_Witcher * > nodes
ModelNode * getNode(const Common::UString &node)
Get the specified node, from the current state.
StateList _stateList
All states within this model.
void clear()
Clear the string's contents.
Generic vertex attribute data.
byte readByte()
Read an unsigned byte from the stream and return it.
IndexBuffer * getIndexBuffer()
#define GfxMan
Shortcut for accessing the graphics manager.
void setSize(uint32 indexCount, uint32 indexSize, GLenum indexType)
Change buffer size.
The global resource manager for Aurora resources.
ModelNode_Witcher(Model &model)