public override bool Parse(string text)
{
if(this.Disposed == true)
{
throw new ObjectDisposedException(this.GetType().Name);
}
idLexer lexer = new idLexer(idDeclFile.LexerOptions);
lexer.LoadMemory(text, this.FileName, this.LineNumber);
lexer.SkipUntilString("{");
int defaultAnimationCount = 0;
idToken token;
idToken token2;
string tokenValue;
string fileName;
string extension;
int count;
idMD5Joint[] md5Joints;
while(true)
{
if((token = lexer.ReadToken()) == null)
{
break;
}
tokenValue = token.ToString();
if(tokenValue == "}")
{
break;
}
if(tokenValue == "inherit")
{
idConsole.WriteLine("TODO: inherit");
/*if( !src.ReadToken( &token2 ) ) {
src.Warning( "Unexpected end of file" );
MakeDefault();
return false;
}
const idDeclModelDef *copy = static_cast<const idDeclModelDef *>( declManager->FindType( DECL_MODELDEF, token2, false ) );
if ( !copy ) {
common->Warning( "Unknown model definition '%s'", token2.c_str() );
} else if ( copy->GetState() == DS_DEFAULTED ) {
common->Warning( "inherited model definition '%s' defaulted", token2.c_str() );
MakeDefault();
return false;
} else {
CopyDecl( copy );
numDefaultAnims = anims.Num();
}*/
}
else if(tokenValue == "skin")
{
if((token2 = lexer.ReadToken()) == null)
{
lexer.Warning("Unexpected end of file");
MakeDefault();
return false;
}
_skin = idE.DeclManager.FindSkin(token2.ToString());
if(_skin == null)
{
lexer.Warning("Skin '{0}' not found", token2.ToString());
MakeDefault();
return false;
}
}
else if(tokenValue == "mesh")
{
if((token2 = lexer.ReadToken()) == null)
{
lexer.Warning("Unexpected end of file");
MakeDefault();
return false;
}
fileName = token2.ToString();
extension = Path.GetExtension(fileName);
if(extension != idRenderModel_MD5.MeshExtension)
{
lexer.Warning("Invalid model for MD5 mesh");
MakeDefault();
return false;
}
_model = idE.RenderModelManager.FindModel(fileName);
if(_model == null)
{
lexer.Warning("Model '{0}' not found", fileName);
MakeDefault();
return false;
}
else if(_model.IsDefault == true)
{
lexer.Warning("Model '{0}' defaulted", fileName);
MakeDefault();
return false;
}
// get the number of joints
count = _model.JointCount;
if(count == 0)
{
lexer.Warning("Model '{0}' has no joints", fileName);
}
// set up the joint hierarchy
md5Joints = _model.Joints;
_joints = new JointInfo[count];
_jointParents = new int[count];
_channelJoints = new int[(int) AnimationChannel.Count][];
_channelJoints[0] = new int[count];
for(int i = 0; i < count; i++)
{
_joints[i] = new JointInfo();
_joints[i].Channel = AnimationChannel.All;
_joints[i].Index = i;
if(md5Joints[i].Parent != null)
{
_joints[i].ParentIndex = _model.GetJointIndex(md5Joints[i].Parent);
}
else
{
_joints[i].ParentIndex = -1;
}
_jointParents[i] = _joints[i].ParentIndex;
_channelJoints[0][i] = i;
}
}
else if(tokenValue == "remove")
{
idConsole.Warning("TODO: remove");
// removes any anims whos name matches
/*if( !src.ReadToken( &token2 ) ) {
src.Warning( "Unexpected end of file" );
MakeDefault();
return false;
}
num = 0;
for( i = 0; i < anims.Num(); i++ ) {
if ( ( token2 == anims[ i ]->Name() ) || ( token2 == anims[ i ]->FullName() ) ) {
delete anims[ i ];
anims.RemoveIndex( i );
if ( i >= numDefaultAnims ) {
src.Warning( "Anim '%s' was not inherited. Anim should be removed from the model def.", token2.c_str() );
MakeDefault();
return false;
}
i--;
numDefaultAnims--;
num++;
continue;
}
}
if ( !num ) {
src.Warning( "Couldn't find anim '%s' to remove", token2.c_str() );
MakeDefault();
return false;
}*/
}
else if(tokenValue == "anim")
{
if(_model == null)
{
lexer.Warning("Must specify mesh before defining anims");
MakeDefault();
return false;
}
else if(ParseAnimation(lexer, defaultAnimationCount) == false)
{
MakeDefault();
return false;
}
}
else if(tokenValue == "offset")
{
float[] tmp = lexer.Parse1DMatrix(3);
if(tmp == null)
{
lexer.Warning("Expected vector following 'offset'");
MakeDefault();
return false;
}
_offset = new Vector3(tmp[0], tmp[1], tmp[2]);
}
else if(tokenValue == "channel")
{
if(_model == null)
{
lexer.Warning("Must specify mesh before defining channels");
MakeDefault();
return false;
}
// set the channel for a group of joints
if((token2 = lexer.ReadToken()) == null)
{
lexer.Warning("Unexpected end of file");
MakeDefault();
return false;
}
if(lexer.CheckTokenString("(") == false)
{
lexer.Warning("Expected { after '{0}'", token2.ToString());
MakeDefault();
return false;
}
int i;
int channelCount = (int) AnimationChannel.Count;
for(i = (int) AnimationChannel.All + 1; i < channelCount; i++)
{
if(ChannelNames[i].Equals(token2.ToString(), StringComparison.OrdinalIgnoreCase) == true)
{
break;
}
}
if(i >= channelCount)
{
lexer.Warning("Unknown channel '{0}'", token2.ToString());
MakeDefault();
return false;
}
int channel = i;
StringBuilder jointNames = new StringBuilder();
string token2Value;
while(lexer.CheckTokenString(")") == false)
{
if((token2 = lexer.ReadToken()) == null)
{
lexer.Warning("Unexpected end of file");
MakeDefault();
return false;
}
token2Value = token2.ToString();
jointNames.Append(token2Value);
if((token2Value != "*") && (token2Value != "-"))
{
jointNames.Append(" ");
}
}
int[] jointList = GetJointList(jointNames.ToString());
int jointLength = jointList.Length;
List<int> channelJoints = new List<int>();
for(count = i = 0; i < jointLength; i++)
{
int jointIndex = jointList[i];
if(_joints[jointIndex].Channel != AnimationChannel.All)
{
lexer.Warning("Join '{0}' assigned to multiple channels", _model.GetJointName(jointIndex));
continue;
}
_joints[jointIndex].Channel = (AnimationChannel) channel;
channelJoints.Add(jointIndex);
}
_channelJoints[channel] = channelJoints.ToArray();
}
else
{
lexer.Warning("unknown token '{0}'", token.ToString());
MakeDefault();
return false;
}
}
return true;
}