/// <summary> /// /// </summary> /// <param name="ent"></param> /// <param name="position"></param> /// <param name="rotation"></param> /// <param name="scale"></param> /// <param name="color"></param> public override void AddEntity(Entity ent, Vector3 position, Quaternion rotation, Vector3 scale, ColorEx color) { //Get the impostor batch that this impostor will be added to ImpostorBatch iBatch = ImpostorBatch.GetBatch(this, ent); //Then add the impostor to the batch iBatch.AddBillboard(position, rotation, scale, color); //Add the Y position to the center.y value (to be averaged later) mCenter.y += position.y + ent.BoundingBox.Center.y * scale.y; ++mAveCounter; }
/// <summary> /// /// </summary> /// <param name="group"></param> /// <param name="entity"></param> /// <returns></returns> public static ImpostorTexture GetTexture(ImpostorPage group, Entity entity) { //Search for an existing impostor texture for the given entity string entityKey = ImpostorBatch.GenerateEntityKey(entity); ImpostorTexture texture = null; if (!mSelfList.TryGetValue(entityKey, out texture)) { if (group != null) { texture = new ImpostorTexture(group, entity); } } return(texture); }
/// <summary> /// /// </summary> /// <param name="group"></param> /// <param name="entity"></param> /// <returns></returns> public static ImpostorBatch GetBatch(ImpostorPage group, Entity entity) { //Search for an existing impostor batch for this entity string entityKey = GenerateEntityKey(entity); ImpostorBatch batch = null; if (!group.mImpostorBatches.TryGetValue(entityKey, out batch)) { //Otherwise, create a new batch batch = new ImpostorBatch(group, entity); //Add it to the impostorBatches list group.mImpostorBatches.Add(entityKey, batch); } return(batch); }
/// <summary> /// /// </summary> /// <param name="group"></param> /// <param name="entity"></param> /// <returns></returns> public static ImpostorBatch GetBatch(ImpostorPage group, Entity entity) { //Search for an existing impostor batch for this entity string entityKey = GenerateEntityKey(entity); ImpostorBatch batch = null; if (!group.mImpostorBatches.TryGetValue(entityKey, out batch)) { //Otherwise, create a new batch batch = new ImpostorBatch(group, entity); //Add it to the impostorBatches list group.mImpostorBatches.Add(entityKey, batch); } return batch; }
/// <summary> /// /// </summary> /// <param name="group"></param> /// <param name="entity"></param> protected ImpostorTexture(ImpostorPage group, Entity entity) { //Store scene manager and entity mSceneMgr = group.SceneManager; mEntity = entity; //Add self to list of ImpostorTexture's mEntityKey = ImpostorBatch.GenerateEntityKey(entity); mSelfList.Add(mEntityKey, this); //Calculate the entity's bounding box and it's diameter mBoundingBox = entity.BoundingBox; //Note - this radius calculation assumes the object is somewhat rounded (like trees/rocks/etc.) float tmp = 0; mEntityRadius = mBoundingBox.Maximum.x - mBoundingBox.Center.x; tmp = mBoundingBox.Maximum.y - mBoundingBox.Center.y; if (tmp > mEntityRadius) { mEntityRadius = tmp; } tmp = mBoundingBox.Maximum.z - mBoundingBox.Center.z; if (tmp > mEntityRadius) { mEntityRadius = tmp; } mEntityDiameter = 2.0f * mEntityRadius; mEntityCenter = mBoundingBox.Center; //Render impostor textures RenderTextures(false); //Set up materials for (int o = 0; o < ImpostorYawAngles; o++) { for (int i = 0; i < ImpostorPitchAngles; i++) { mMaterial[i, o] = (Material)MaterialManager.Instance.Create(GetUniqueID("ImpostorMaterial"), "Impostors"); Material m = mMaterial[i, o]; Pass p = m.GetTechnique(0).GetPass(0); TextureUnitState t = p.CreateTextureUnitState(mTexture.Name); t.TextureScrollU = (float)(o / ImpostorYawAngles); t.TextureScrollV = (float)(i / ImpostorPitchAngles); p.LightingEnabled = false; m.ReceiveShadows = false; if (group.BlendMode == ImpostorBlendMode.AlphaReject) { p.AlphaRejectFunction = CompareFunction.GreaterEqual; p.AlphaRejectValue = 128; } else if (group.BlendMode == ImpostorBlendMode.AlphaBlend) { p.SetSceneBlending(SceneBlendFactor.SourceAlpha, SceneBlendFactor.OneMinusSourceAlpha); } } } }