Inheritance: IDisposable
Ejemplo n.º 1
0
        public void Init()
        {
            // TODO: cmds

            /*cmdSystem->AddCommand( "listModels", ListModels_f, CMD_FL_RENDERER, "lists all models" );
             * cmdSystem->AddCommand( "printModel", PrintModel_f, CMD_FL_RENDERER, "prints model info", idCmdSystem::ArgCompletion_ModelName );
             * cmdSystem->AddCommand( "reloadModels", ReloadModels_f, CMD_FL_RENDERER|CMD_FL_CHEAT, "reloads models" );
             * cmdSystem->AddCommand( "touchModel", TouchModel_f, CMD_FL_RENDERER, "touches a model", idCmdSystem::ArgCompletion_ModelName );*/

            _insideLevelLoad = false;

            // create a default model
            idRenderModel_Static model = new idRenderModel_Static();

            model.InitEmpty("_DEFAULT");
            model.MakeDefault();
            model.IsLevelLoadReferenced = true;

            _defaultModel = model;

            AddModel(model);

            // create the beam model
            // TODO: beam

            /*idRenderModelStatic *beam = new idRenderModelBeam;
             * beam->InitEmpty( "_BEAM" );
             * beam->SetLevelLoadReferenced( true );
             * beamModel = beam;
             * AddModel( beam );*/

            // TODO: sprite

            /*idRenderModelStatic *sprite = new idRenderModelSprite;
             * sprite->InitEmpty( "_SPRITE" );
             * sprite->SetLevelLoadReferenced( true );
             * spriteModel = sprite;
             * AddModel( sprite );*/
        }
Ejemplo n.º 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);
				}
			}
		}
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a static model based on the definition and view currently.
 /// </summary>
 /// <remarks>
 /// This will be regenerated for every view, even though
 /// some models, like character meshes, could be used for multiple (mirror)
 /// views in a frame, or may stay static for multiple frames (corpses)
 /// The renderer will delete the returned dynamic model the next view.
 /// </remarks>
 /// <param name="renderEntity"></param>
 /// <param name="view"></param>
 /// <param name="cachedModel"></param>
 /// <returns></returns>
 public abstract idRenderModel InstantiateDynamicModel(idRenderEntity renderEntity, View view, idRenderModel cachedModel);
Ejemplo n.º 4
0
        public override idRenderModel InstantiateDynamicModel(idTech4.Renderer.idRenderEntity renderEntity, View view, idRenderModel cachedModel)
        {
            if (this.Disposed == true)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            idConsole.Warning("TODO: idRenderModel_PRT.InstantiateDynamicModel");

            return(null);
        }
Ejemplo n.º 5
0
        public override idRenderModel InstantiateDynamicModel(idRenderEntity renderEntity, View view, idRenderModel cachedModel)
        {
            if (cachedModel != null)
            {
                cachedModel.Dispose();
            }

            idConsole.Error("InstantiateDynamicModel called on static model '{0}'", this.Name);

            return(null);
        }
Ejemplo n.º 6
0
		/// <summary>
		/// Creates a static model based on the definition and view currently.
		/// </summary>
		/// <remarks>
		/// This will be regenerated for every view, even though
		/// some models, like character meshes, could be used for multiple (mirror)
		/// views in a frame, or may stay static for multiple frames (corpses)
		/// The renderer will delete the returned dynamic model the next view.
		/// </remarks>
		/// <param name="renderEntity"></param>
		/// <param name="view"></param>
		/// <param name="cachedModel"></param>
		/// <returns></returns>
		public abstract idRenderModel InstantiateDynamicModel(idRenderEntity renderEntity, View view, idRenderModel cachedModel);
Ejemplo n.º 7
0
		public override idRenderModel InstantiateDynamicModel(idRenderEntity renderEntity, View view, idRenderModel cachedModel)
		{
			if(cachedModel != null)
			{
				cachedModel.Dispose();
			}

			idConsole.Error("InstantiateDynamicModel called on static model '{0}'", this.Name);

			return null;
		}
Ejemplo n.º 8
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();
			}
		}
Ejemplo n.º 9
0
		public override idRenderModel InstantiateDynamicModel(idTech4.Renderer.idRenderEntity renderEntity, View view, idRenderModel cachedModel)
		{
			if(this.Disposed == true)
			{
				throw new ObjectDisposedException(this.GetType().Name);
			}

			idConsole.Warning("TODO: idRenderModel_PRT.InstantiateDynamicModel");

			return null;
		}
Ejemplo n.º 10
0
 /// <summary>
 /// World map parsing will add all the inline models with this call.
 /// </summary>
 /// <param name="model"></param>
 public void AddModel(idRenderModel model)
 {
     _models.Add(model.Name, model);
 }
Ejemplo n.º 11
0
 public void RemoveModel(idRenderModel model)
 {
     _models.Remove(model.Name);
 }
Ejemplo n.º 12
0
		/// <summary>
		/// World map parsing will add all the inline models with this call.
		/// </summary>
		/// <param name="model"></param>
		public void AddModel(idRenderModel model)
		{
			_models.Add(model.Name, model);
		}
Ejemplo n.º 13
0
		public void RemoveModel(idRenderModel model)
		{
			_models.Remove(model.Name);
		}
Ejemplo n.º 14
0
		public void Init()
		{
			// TODO: cmds
			/*cmdSystem->AddCommand( "listModels", ListModels_f, CMD_FL_RENDERER, "lists all models" );
			cmdSystem->AddCommand( "printModel", PrintModel_f, CMD_FL_RENDERER, "prints model info", idCmdSystem::ArgCompletion_ModelName );
			cmdSystem->AddCommand( "reloadModels", ReloadModels_f, CMD_FL_RENDERER|CMD_FL_CHEAT, "reloads models" );
			cmdSystem->AddCommand( "touchModel", TouchModel_f, CMD_FL_RENDERER, "touches a model", idCmdSystem::ArgCompletion_ModelName );*/

			_insideLevelLoad = false;
			
			// create a default model
			idRenderModel_Static model = new idRenderModel_Static();
			model.InitEmpty("_DEFAULT");
			model.MakeDefault();
			model.IsLevelLoadReferenced = true;

			_defaultModel = model;

			AddModel(model);

			// create the beam model
			// TODO: beam
			/*idRenderModelStatic *beam = new idRenderModelBeam;
			beam->InitEmpty( "_BEAM" );
			beam->SetLevelLoadReferenced( true );
			beamModel = beam;
			AddModel( beam );*/

			// TODO: sprite
			/*idRenderModelStatic *sprite = new idRenderModelSprite;
			sprite->InitEmpty( "_SPRITE" );
			sprite->SetLevelLoadReferenced( true );
			spriteModel = sprite;
			AddModel( sprite );*/
		}
Ejemplo n.º 15
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;
		}