96 mdl(0), mdx(0), state(0), texture(t) {
120 for (std::list<ModelNode_Jade *>::iterator n = nodes.begin(); n != nodes.end(); ++n)
166 if (version != 0x00008700)
205 float boundingMin[3], boundingMax[3];
227 uint32 nameOffset, nameCount;
230 std::vector<uint32> nameOffsets;
238 ctx.
nodes.push_back(rootNode);
247 const std::vector<uint32> &offsets,
uint32 offset,
248 std::vector<Common::UString> &strings) {
250 size_t pos = mdl.
pos();
252 strings.reserve(offsets.size());
253 for (std::vector<uint32>::const_iterator o = offsets.begin(); o != offsets.end(); ++o) {
254 mdl.
seek(offset + *o);
274 for (std::list<ModelNode_Jade *>::iterator n = ctx.
nodes.begin();
275 n != ctx.
nodes.end(); ++n) {
278 ctx.
state->
nodeMap.insert(std::make_pair((*n)->getName(), *n));
280 if (!(*n)->getParent())
311 if (nodeNumber2 < ctx.
names.size())
331 std::vector<uint32> children;
339 for (std::vector<uint32>::const_iterator child = children.begin(); child != children.end(); ++child) {
341 ctx.
nodes.push_back(childNode);
347 childNode->
load(ctx);
352 if (ctx.
state->name.size() != 0) {
353 meshName += ctx.
state->name;
355 meshName +=
"xoreos.default";
373 if (
MeshMan.getMesh(meshName)) {
374 warning(
"Warning: probable mesh duplication of: %s", meshName.
c_str());
382 if (
GfxMan.isRendererExperimental())
393 float boundingMin[3], boundingMax[3];
405 float pointsAverage[3];
494 if (materialID != 0xFFFFFFFF)
496 else if (!texture.
empty())
504 ctx.
vertices.resize(vertexCount * 3);
507 for (
uint32 i = 0; i < textureCount; i++)
508 ctx.
texCoords[i].resize(vertexCount * 2);
511 for (
uint32 i = 0; i < vertexCount; i++) {
512 ctx.
mdx->
seek(vertexOffset + i * mdxStructSize);
518 for (
uint32 t = 0; t < textureCount; t++) {
519 if ((offUV[t] != 0xFFFFFFFF) && ((offUV[t] + 8) <= mdxStructSize)) {
520 ctx.
mdx->
seek(vertexOffset + i * mdxStructSize + offUV[t]);
534 if (faceOffsetMDL != 0)
536 else if (faceOffsetMDX != 0)
545 size_t pos = stream.
pos();
549 indices.resize(count);
550 for (std::vector<uint16>::iterator i = indices.begin(); i != indices.end(); ++i)
559 size_t pos = stream.
pos();
566 indices.reserve(count);
570 if (chunk == stopValue)
573 uint32 chunkLength = ((chunk >> 16) & 0x1FFF) / 2;
576 for (
uint32 i = 0; i < toRead; i++)
593 warning(
"ModelNode_Jade \"%s\".\"%s\": Unsupported mesh type %d",
612 if (indices.size() < 3) {
617 std::vector<uint16> unfolded;
618 unfolded.reserve((indices.size() - 2) * 3);
620 for (
size_t i = 0; i < indices.size() - 2; i++) {
622 unfolded.push_back(indices[i]);
623 unfolded.push_back(indices[i + 2]);
624 unfolded.push_back(indices[i + 1]);
626 unfolded.push_back(indices[i]);
627 unfolded.push_back(indices[i + 1]);
628 unfolded.push_back(indices[i + 2]);
632 indices.swap(unfolded);
636 if (indices.size() < 3) {
641 std::vector<uint16> unfolded;
642 unfolded.reserve((indices.size() - 2) * 3);
644 for (
size_t i = 1; i < indices.size() - 1; i++) {
645 unfolded.push_back(indices[0]);
646 unfolded.push_back(indices[i]);
647 unfolded.push_back(indices[i + 1]);
650 indices.swap(unfolded);
657 if ((vertexCount == 0) || (indexCount == 0))
671 for (
uint t = 0; t < textureCount; t++)
677 for (
uint32 i = 0; i < vertexCount; i++) {
684 for (
uint t = 0; t < textureCount; t++) {
703 if (materialID == 0xFFFFFFFF) {
754 for (
int i = 0; i < 4; i++) {
757 if (textures.back() ==
"NULL")
758 textures.back().clear();
771 while (!textures.empty() && textures.back().empty())
#define ResMan
Shortcut for accessing the sound manager.
GLvoid * getData()
Access buffer data.
void unfoldFaces(std::vector< uint16 > &indices, uint32 meshType)
Unfolds triangle strips / fans into triangle lists.
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.
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...
Common::SeekableReadStream * mdl
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.
Common::SeekableReadStream * mdx
VertexBuffer * getVertexBuffer()
void readMesh(Model_Jade::ParserContext &ctx)
void loadTextures(const std::vector< Common::UString > &textures)
void readPlainIndices(Common::SeekableReadStream &stream, std::vector< uint16 > &indices, uint32 offset, uint32 count)
void readStrings(Common::SeekableReadStream &mdl, const std::vector< uint32 > &offsets, uint32 offset, std::vector< Common::UString > &strings)
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.
void readChunkedIndices(Common::SeekableReadStream &stream, std::vector< uint16 > &indices, uint32 offset, uint32 count)
NodeList rootNodes
The nodes in the state without a parent.
void setParent(ModelNode *parent)
Set the node's parent.
void setVertexDeclInterleave(uint32 vertCount, VertexDecl &decl)
Set the interleaved vertex declaration for this buffer.
State * _currentState
The current state.
Utility functions for generating unique IDs.
JadeMaterialData _jadeMaterialData
bool _render
Render the node?
const Common::UString & getName() const
Get the model's name.
Geometry, model mesh data.
Common::UString _fileName
The model's file name.
std::vector< VertexAttrib > VertexDecl
Vertex data layout.
#define IGNORE_UNUSED_VARIABLES
ParserContext(const Common::UString &name, const Common::UString &t)
void unfoldTriangleStrip(std::vector< uint16 > &indices)
ModelNode_Jade(Model &model)
std::vector< Common::UString > textures
Model * _model
The model this node belongs to.
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Common::UString _name
The model's name.
Model_Jade(const Common::UString &name, ModelType type=kModelTypeObject, const Common::UString &texture="")
friend class ModelNode_Jade
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
std::vector< float > vertices
ModelType
The display type of a model.
float selfIllum[3]
Self illumination color.
void createMesh(Model_Jade::ParserContext &ctx)
virtual void buildMaterial()
static void readArray(Common::SeekableReadStream &stream, uint32 offset, uint32 count, std::vector< T > &values)
std::vector< std::vector< float > > texCoords
void load(Model_Jade::ParserContext &ctx)
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
void readMaterialTextures(uint32 materialID, std::vector< Common::UString > &textures)
Opens the resource for the materialID and parses it to return the 4 normal textures.
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.
uint32 transparencyHintFull
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.
Basic reading stream interfaces.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
std::vector< Common::UString > names
void load(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).
std::vector< uint16 > indices
Graphics::Mesh::Mesh * rawMesh
Node raw mesh data.
Common::UString _name
The node's name.
A texture as used in the Aurora engines.
bool shadow
Does the node have a shadow?
static void readArrayDef(Common::SeekableReadStream &stream, uint32 &offset, uint32 &count)
GLvoid * getData()
Access buffer data.
float _orientation[4]
Orientation of the node.
UString readString(SeekableReadStream &stream, Encoding encoding)
Read a string with the given encoding of a stream.
static float rad2deg(float rad)
float bumpCoordMultiplier
void finalize()
Finalize the loading procedure.
bool isBackgroundGeometry
Loading MDL/MDX files found in Jade Empire.
std::list< ModelNode_Jade * > nodes
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
void unfoldTriangleFan(std::vector< uint16 > &indices)
void setName(const Common::UString &name)
UString generateIDRandomString()
void newState(ParserContext &ctx)
StateList _stateList
All states within this model.
Generic vertex attribute data.
Interface for a seekable & readable data stream.
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.
void addState(ParserContext &ctx)
float terrainCoordMultiplier