121 mdl(0), mdx(0), state(0), texture(t), kotor2(k2), xbox(x), mdxStructSize(0), vertexCount(0),
146 for (std::list<ModelNode_KotOR *>::iterator n = nodes.begin(); n != nodes.end(); ++n)
206 uint32 animOffset, animCount;
211 float boundingMin[3], boundingMax[3];
231 uint32 nameOffset, nameCount;
234 std::vector<uint32> nameOffsets;
242 ctx.
nodes.push_back(rootNode);
249 std::vector<uint32> animOffsets;
252 for (std::vector<uint32>::const_iterator offset = animOffsets.begin(); offset != animOffsets.end(); ++offset) {
297 uint32 eventOffset, eventCount;
303 ctx.
nodes.push_back(rootNode);
316 for (std::list<ModelNode_KotOR *>::iterator n = ctx.
nodes.begin(); n != ctx.
nodes.end(); ++n) {
327 bool foundInCache =
false;
331 if (super != modelCache->end()) {
341 if (modelCache && !foundInCache)
347 const std::vector<uint32> &offsets,
uint32 offset,
348 std::vector<Common::UString> &strings) {
350 size_t pos = mdl.
pos();
352 strings.reserve(offsets.size());
353 for (std::vector<uint32>::const_iterator o = offsets.begin(); o != offsets.end(); ++o) {
354 mdl.
seek(offset + *o);
374 for (std::list<ModelNode_KotOR *>::iterator n = ctx.
nodes.begin();
375 n != ctx.
nodes.end(); ++n) {
378 ctx.
state->
nodeMap.insert(std::make_pair((*n)->getName(), *n));
380 if (!(*n)->getParent())
397 for (NodeList::const_iterator n = nodes.begin();
398 n != nodes.end(); ++n) {
403 if (mesh && mesh->
skin) {
407 int index =
static_cast<int>(skin->
boneMapping[i]);
451 uint32 childrenOffset, childrenCount;
454 std::vector<uint32> children;
457 uint32 controllerKeyOffset, controllerKeyCount;
460 uint32 controllerDataOffset, controllerDataCount;
463 std::vector<float> controllerDataFloat;
465 controllerDataCount, controllerDataFloat);
467 std::vector<uint32> controllerDataInt;
469 controllerDataCount, controllerDataInt);
472 controllerKeyCount, controllerDataFloat, controllerDataInt);
474 if ((flags & 0xFC00) != 0)
516 for (std::vector<uint32>::const_iterator child = children.begin(); child != children.end(); ++child) {
518 ctx.
nodes.push_back(childNode);
523 childNode->
load(ctx);
529 if (ctx.
state->name.size() != 0) {
530 meshName += ctx.
state->name;
532 meshName +=
"xoreos.default";
536 #ifdef MESH_KOTOR_USE_MESHMAN 547 if (ctx.
state->name.size() == 0) {
548 while (mystery_mesh) {
550 mystery_mesh =
MeshMan.getMesh(meshName);
582 if (
GfxMan.isRendererExperimental())
588 uint32 offset,
uint32 count, std::vector<float> &dataFloat, std::vector<uint32> &dataInt) {
590 for (
uint32 i = 0; i < count; i++) {
615 uint16 dataIndex, std::vector<float> &data) {
616 bool bezier = columnCount & 16;
617 switch (columnCount) {
620 for (
int r = 0; r < rowCount; r++) {
622 p.
time = data[timeIndex + r];
623 int index = dataIndex + (bezier ? 9 : 3) * r;
624 p.
x = data[index + 0];
625 p.
y = data[index + 1];
626 p.
z = data[index + 2];
631 warning(
"Position controller with %d values", columnCount);
637 uint16 timeIndex,
uint16 dataIndex, std::vector<float> &dataFloat, std::vector<uint32> &dataInt) {
638 switch (columnCount) {
640 for (
int r = 0; r < rowCount; r++) {
642 q.
time = dataFloat[timeIndex + r];
644 uint32 temp = dataInt[dataIndex + r];
645 q.
x = 1.0f -
static_cast<float>(temp & 0x7ff) / 1023.0f;
646 q.
y = 1.0f -
static_cast<float>((temp >> 11) & 0x7ff) / 1023.0f;
647 q.
z = 1.0f -
static_cast<float>(temp >> 22) / 511.0f;
649 float temp2 = q.
x * q.
x + q.
y * q.
y + q.
z * q.
z;
651 q.
q = -sqrtf(1.0f - temp2);
653 temp2 = sqrtf(temp2);
664 for (
int r = 0; r < rowCount; r++) {
666 q.
time = dataFloat[timeIndex + r];
667 int index = dataIndex + 4 * r;
668 q.
x = dataFloat[index + 0];
669 q.
y = dataFloat[index + 1];
670 q.
z = dataFloat[index + 2];
671 q.
q = dataFloat[index + 3];
676 warning(
"Orientation controller with %d values", columnCount);
686 uint32 facesOffset, facesCount;
689 float boundingMin[3], boundingMax[3];
701 float pointsAverage[3];
725 std::vector<Common::UString> textures;
734 uint32 offOffVerts, offOffVertsCount;
737 if (offOffVertsCount > 1)
738 throw Common::Exception(
"Face offsets offsets count wrong (%d)", offOffVertsCount);
777 if ((offOffVertsCount < 1) || (ctx.
vertexCount == 0) || (facesCount == 0))
787 if (textureCount > 2) {
788 warning(
"Model_KotOR::readMesh(): textureCount > 2 (%d)", textureCount);
795 textures.resize(textureCount);
805 for (
uint t = 0; t < textureCount; t++)
832 for (
uint16 t = 0; t < textureCount; t++) {
833 if (offUV[t] != 0xFFFFFFFF) {
855 for (
uint32 i = 0; i < facesCount * 3; i++)
879 for (
uint32 i = 0; i < boneMappingCount; i++) {
static const uint32 kControllerTypeBounce_Co
#define ResMan
Shortcut for accessing the sound manager.
GLvoid * getData()
Access buffer data.
A node within an animation.
friend class ModelNode_KotOR
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
void newState(ParserContext &ctx)
Generic image decoder interface.
static const uint32 kControllerTypePercentEnd
std::vector< float > boneMapping
NodeMap nodeMap
The nodes within the state, indexed by name.
static const uint32 kControllerTypeBlurLength
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...
static const int kNodeFlagHasEmitter
static const uint32 P[kRoundCount+2]
Model_KotOR(const Common::UString &name, bool kotor2, bool xbox, ModelType type=kModelTypeObject, const Common::UString &texture="", ModelCache *modelCache=0)
A class holding an UTF-8 string.
static const uint32 kControllerTypePercentMid
void setLength(float length)
static const int kNodeFlagHasReference
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
An animation to be applied to a model.
static const uint32 kControllerTypeOrientation
static const uint32 kControllerTypeAlpha
static const uint32 kControllerTypeSpread
VertexBuffer * getVertexBuffer()
std::vector< float > boneWeights
void makeBoneNodeMap()
Map bone indices to model node references for better peformance.
static const uint32 kControllerTypeScale
static const uint32 kControllerTypeSizeEnd
bool readAnim(ParserContext &ctx, uint32 offset)
void loadTextures(const std::vector< Common::UString > &textures)
static const uint32 kControllerTypePosition
void init()
General mesh initialisation, queuing the mesh for GL resource creation.
The Aurora texture manager.
static const uint32 kControllerTypeRandVel
static const int kNodeFlagHasAABB
bool render
Render this mesh?
Common::UString name
The state's name.
NodeList rootNodes
The nodes in the state without a parent.
void setParent(ModelNode *parent)
Set the node's parent.
static const uint32 kControllerTypeCombineTime
void setVertexDeclInterleave(uint32 vertCount, VertexDecl &decl)
Set the interleaved vertex declaration for this buffer.
State * _currentState
The current state.
Common::SeekableReadStream * mdl
Utility functions for generating unique IDs.
Diffuse textures first, then blend the environment map in.
bool _render
Render the node?
Geometry, model mesh data.
static const uint32 kControllerTypeMass
Common::UString _fileName
The model's file name.
static const uint32 kControllerTypeThreshold
std::vector< VertexAttrib > VertexDecl
Vertex data layout.
static const uint32 kControllerTypeVelocity
void computeInverseBindPose()
#define IGNORE_UNUSED_VARIABLES
Utility templates and functions for working with strings and streams.
static const uint32 kControllerTypeP2P_Bezier3
static const uint32 kControllerTypeDrag
std::vector< ModelNode * > boneNodeMap
Exception that provides a stack of explanations.
Model * _model
The model this node belongs to.
Common::UString _name
The model's name.
ParserContext(const Common::UString &name, const Common::UString &t, bool k2, bool x)
Basic exceptions to throw.
static const uint32 kControllerTypeLightningDelay
static const uint32 kControllerTypeColorEnd
const char * c_str() const
Return the (utf8 encoded) string data.
static const uint32 kControllerTypeGrav
static const uint32 kControllerTypeSizeMid_Y
AnimationMap _animationMap
Map of all animations in this model.
std::vector< float > initialVertexCoords
Initial node vertex coordinates.
void load(Model_KotOR::ParserContext &ctx)
ModelType
The display type of a model.
static const uint32 kControllerTypeShadowRadius
ModelType _type
The model's type.
void addState(ParserContext &ctx)
static const uint32 kControllerTypeYSize
void setTransTime(float transtime)
static const int kNodeFlagHasSkin
static const uint32 kControllerTypeAlphaStart
void loadSuperModel(ModelCache *modelCache, bool kotor2, bool xbox)
virtual void buildMaterial()
static void readArray(Common::SeekableReadStream &stream, uint32 offset, uint32 count, std::vector< T > &values)
void readStrings(Common::SeekableReadStream &mdl, const std::vector< uint32 > &offsets, uint32 offset, std::vector< Common::UString > &strings)
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
static const uint32 kControllerTypeMultiplier
static const uint32 kControllerTypeLifeExp
static const uint32 kControllerTypeBirthRate
static const uint32 kControllerTypeVerticalDisplacement
static const uint32 kControllerTypeAlphaMid
void readNodeControllers(Model_KotOR::ParserContext &ctx, uint32 offset, uint32 count, std::vector< float > &dataFloat, std::vector< uint32 > &dataInt)
static const uint32 kControllerTypeParticleRot
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.
static const uint32 kControllerTypeSizeMid
const std::list< ModelNode * > & getNodes()
Get all nodes in the current state.
float specular[3]
Specular color.
Common::SeekableReadStream * mdx
static const uint32 kControllerTypeSizeEnd_Y
static const uint32 kControllerTypeLightningScale
std::vector< QuaternionKeyFrame > _orientationFrames
Keyframes for orientation animation.
FORCEINLINE int16 readSint16LE()
Read a signed 16-bit word stored in little endian (LSB first) order from the stream and return it...
float _position[3]
Position of the node.
NodeList nodeList
The nodes within the state.
static const uint32 kControllerTypeSelfIllumColor
void warning(const char *s,...)
Loading MDL files found in Star Wars: Knights of the Old Republic.
void readPositionController(uint8 columnCount, uint16 rowCount, uint16 timeIndex, uint16 dataIndex, std::vector< float > &data)
StateMap _stateMap
All states within this model, index by name.
Basic reading stream interfaces.
std::list< ModelNode * > NodeList
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
std::vector< Common::UString > names
FORCEINLINE float readIEEEFloatLE()
Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it...
static const uint32 kControllerTypeFrameStart
void readOrientationController(uint8 columnCount, uint16 rowCount, uint16 timeIndex, uint16 dataIndex, std::vector< float > &dataFloat, std::vector< uint32 > &dataInt)
std::vector< float > boneMappingId
#define MeshMan
Shortcut for accessing the shader manager.
static const uint32 kControllerTypeXSize
Basic type definitions to handle files used in BioWare's Aurora engine.
Plain, unextended ASCII (7bit clean).
static const uint32 kControllerTypeSizeStart
static const int kNodeFlagHasLight
Graphics::Mesh::Mesh * rawMesh
Node raw mesh data.
static const uint32 kControllerTypeColorStart
Common::UString _name
The node's name.
static const int kNodeFlagHasAnim
static const int kNodeFlagHasMesh
A texture as used in the Aurora engines.
bool shadow
Does the node have a shadow?
EnvironmentMapMode envMapMode
The way the environment map is applied.
static const uint32 kControllerTypeLightningRadius
static const uint32 kControllerTypeSizeStart_Y
static void readArrayDef(Common::SeekableReadStream &stream, uint32 &offset, uint32 &count)
GLvoid * getData()
Access buffer data.
void readSkin(Model_KotOR::ParserContext &ctx)
float diffuse[3]
Diffuse color.
void setName(Common::UString &name)
float _orientation[4]
Orientation of the node.
float _orientationBuffer[4]
Model * _superModel
The actual super model.
UString readString(SeekableReadStream &stream, Encoding encoding)
Read a string with the given encoding of a stream.
void addAnimNode(AnimNode *node)
static float rad2deg(float rad)
void finalize()
Finalize the loading procedure.
static const uint32 kControllerTypeFPS
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
void readMesh(Model_KotOR::ParserContext &ctx)
void setName(const Common::UString &name)
std::vector< PositionKeyFrame > _positionFrames
Keyframes for position animation.
static const uint32 kControllerTypeAlphaEnd
static const uint32 kControllerTypeDetonate
UString generateIDRandomString()
static const uint32 kControllerTypeColor
ModelNode * getNode(const Common::UString &node)
Get the specified node, from the current state.
StateList _stateList
All states within this model.
static const int kNodeFlagHasDangly
Common::UString _superModelName
Name of the super model.
static const uint32 kControllerTypeRadius
Generic vertex attribute data.
Interface for a seekable & readable data stream.
void load(ParserContext &ctx)
static const uint32 kControllerTypeFrameEnd
byte readByte()
Read an unsigned byte from the stream and return it.
IndexBuffer * getIndexBuffer()
static IGNORE_UNUSED_VARIABLES const int kNodeFlagHasHeader
#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.
static const uint32 kControllerTypeP2P_Bezier2
void setSkinned(bool skinned)
Set the flag if the model has skinned animations.
static const uint32 kControllerTypePercentStart
ModelNode_KotOR(Model &model)
std::list< ModelNode_KotOR * > nodes
static const uint32 kControllerTypeColorMid