コード例 #1
0
        protected override void SetModel(string modelName)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            FreeModelDef();

            this.RenderEntity.Model = _animator.SetModel(modelName);

            if (this.RenderEntity.Model == null)
            {
                base.SetModel(modelName);
            }
            else
            {
                if (this.RenderEntity.CustomSkin == null)
                {
                    this.RenderEntity.CustomSkin = _animator.ModelDefinition.DefaultSkin;
                }

                // set the callback to update the joints
                this.RenderEntity.Callback = ModelCallback;
                this.RenderEntity.Joints   = _animator.GetJoints();

                _animator.GetBounds(idR.Game.Time, out this.RenderEntity.Bounds);

                UpdateVisuals();
            }
        }
コード例 #2
0
        public void CheckModelHierarchy(idRenderModel model)
        {
            if (_jointInfo.Length != model.JointCount)
            {
                idConsole.Error("Model '{0}' has different # of joints than anim '{1}'", model.Name, this.Name);
            }

            idMD5Joint[] modelJoints     = model.Joints;
            int          parent          = -1;
            int          jointCount      = _jointInfo.Length;
            int          modelJointCount = modelJoints.Length;

            for (int i = 0; i < jointCount; i++)
            {
                int jointIndex = _jointInfo[i].NameIndex;

                if (modelJoints[i].Name != idR.AnimManager.GetJointName(jointIndex))
                {
                    idConsole.Error("Model '{0}''s joint names don't match anim '{1}''s", model.Name, this.Name);
                }
                else if (modelJoints[i].Parent != null)
                {
                    for (int j = 0; j < modelJointCount; j++)
                    {
                        if (modelJoints[j] == modelJoints[i].Parent)
                        {
                            parent = j;
                            break;
                        }
                    }
                }
                else
                {
                    parent = -1;
                }

                if (parent != _jointInfo[i].ParentIndex)
                {
                    idConsole.Error("Model '{0}' has different joint hierarchy than anim '{1}'", model.Name, this.Name);
                }
            }
        }
コード例 #3
0
ファイル: idAnimator.cs プロジェクト: PEMantis/idtech4.net
        public idRenderModel SetModel(string modelName)
        {
            FreeData();

            // check if we're just clearing the model
            if ((modelName == null) || (modelName == string.Empty))
            {
                return(null);
            }

            _modelDef = idR.DeclManager.FindType <idDeclModel>(DeclType.ModelDef, modelName, false);

            if (_modelDef == null)
            {
                return(null);
            }

            idRenderModel renderModel = _modelDef.Model;

            if (renderModel == null)
            {
                _modelDef = null;
                return(null);
            }

            // make sure model hasn't been purged
            _modelDef.Touch();

            _modelDef.SetupJoints(_joints, ref _frameBounds, _removeOriginOffset);
            _modelDef.Model.Reset();

            // set the modelDef on all channels
            for (int i = (int)AnimationChannel.All; i < (int)AnimationChannel.Count; i++)
            {
                for (int j = 0; j < idR.AnimationCountPerChannel; j++)
                {
                    _channels[i, j].Reset(_modelDef);
                }
            }

            return(_modelDef.Model);
        }
コード例 #4
0
        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);
        }