/// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static string GenerateEntityKey(Entity entity)
        {
            string entityKey = string.Empty;
            entityKey = entity.Mesh.Name;
            for (int i = 0; i < entity.SubEntityCount; i++)
                entityKey += "-" + entity.GetSubEntity(i).Name;

            return entityKey;
        }
Beispiel #2
0
 public static void setEntityOpacity(Entity ent, float val)
 {
     for (uint x = 0; x < ent.NumSubEntities; x++)
     {
         Mogre.MaterialPtr mat = ent.GetSubEntity(x).GetMaterial();
         Technique t = mat.GetTechnique(0); // we are only bothering the fade with the first technique.
         //t.SetSceneBlending(SceneBlendFactor.SBF_DEST_ALPHA, SceneBlendFactor.SBF_ONE_MINUS_DEST_COLOUR); //sweet color invert effect
         t.SetSceneBlending(SceneBlendFactor.SBF_DEST_ALPHA, SceneBlendFactor.SBF_SOURCE_ALPHA); //works
         t.SetDepthWriteEnabled(false);
         t.SetSelfIllumination(ColourValue.Green);
         t.SetAmbient(ColourValue.Green);
         // iterate through passes and textureUnitStates, setting their opacity.
         for (ushort p = 0; p < t.NumPasses; p++)
         {
             for (ushort s = 0; s < t.GetPass(p).NumTextureUnitStates; s++)
             {
                 t.GetPass(p).GetTextureUnitState(s).SetAlphaOperation(LayerBlendOperationEx.LBX_MODULATE, LayerBlendSource.LBS_MANUAL, LayerBlendSource.LBS_CURRENT, val);
             }
         }
         mat.Dispose();
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="position"></param>
        /// <param name="orientation"></param>
        /// <param name="scale"></param>
        /// <param name="color"></param>
        public void AddEntity(Entity ent, Vector3 position, Quaternion orientation, Vector3 scale, ColorEx color) {
            Mesh mesh = ent.Mesh;
            if (mesh.SharedVertexData != null)
                throw new Exception("Shared vertex data not allowed");

            //For each subentity
            for (int i = 0; i < ent.SubEntityCount; i++) {
                //get the subentity
                SubEntity subEntity = ent.GetSubEntity(i);
                SubMesh subMesh = subEntity.SubMesh;

                //Generate a format string that uniquely identifies this material & vertex/index format
                if (subMesh.vertexData == null)
                    throw new Exception("Submesh vertex data not found!");

                string formatStr = GetFormatString(subEntity);
                //If a batch using an identical format exists...
                SubBatch batch = null;
                if (!mSubBatches.TryGetValue(formatStr, out batch)) {
                    batch = new SubBatch(this, subEntity);
                    mSubBatches.Add(formatStr, batch);
                }
                //Now add the submesh to the compatible batch
                batch.AddSubEntity(subEntity, position, orientation, scale, color);
            }//end for

            //Update bounding box
            Matrix4 mat = Matrix4.FromMatrix3(orientation.ToRotationMatrix());
            mat.Scale = scale;
            AxisAlignedBox entBounds = ent.BoundingBox;
            entBounds.Transform(mat);
            if (mBoundsUndefinded) {
                mBounds.Minimum = entBounds.Minimum + position;
                mBounds.Maximum = entBounds.Maximum + position;
                mBoundsUndefinded = false;
            }
            else {
                Vector3 min = mBounds.Minimum;
                Vector3 max = mBounds.Maximum;

                min.Floor(entBounds.Minimum + position);
                max.Ceil(entBounds.Maximum + position);
                mBounds.Minimum = min;
                mBounds.Maximum = max;
            }
        }
 public void SetParameters(Entity ent, Vector4 translationScale, Vector4 color)
 {
     ent.GetSubEntity(0).SetCustomParameter(TransXYscaleXY, translationScale);
     ent.GetSubEntity(0).SetCustomParameter(ColorAndHeightScale, color);
 }
Beispiel #5
0
        public void FillData(string _filename, ref Entity _entity)
        {
            filename = _filename;
              entity = _entity;
              components = new List<ModelComponent>();

              ModelComponent m;
              Pass p;
              String foundPath = "";
              FileInfoListPtr fileInfos;
              FileInfoList.Iterator it;

              Mesh.Const_SubMeshNameMap map = entity.GetMesh().GetSubMeshNameMap();
              for (uint i = 0; i < map.Count; i++)
              {
            for (Mesh.Const_SubMeshNameMap.ConstIterator start = map.Begin();
              start != map.End(); start++)
            {
              if (start.Value == i)
              {
            // Name
            m = new ModelComponent(start.Key);

            // SubEntity
            m.SubEntity = entity.GetSubEntity(start.Key);

            // Type (Button, Joystick, Body?)
            if(start.Key.Contains("Button") ||
              start.Key.Contains("Plunger") ||
              start.Key.Contains("Cylinder"))
              m.Type = FragmentType.BUTTON;
            else if(start.Key.Contains("Balltop") ||
              start.Key.Contains("Shaft") ||
              start.Key.Contains("Dust"))
              m.Type = FragmentType.JOYSTICK;
            else
              m.Type = FragmentType.MODEL;

            //m.Parent =;

            // Texture
            p = m.SubEntity.GetMaterial().GetBestTechnique().GetPass(0);
            if(p.NumTextureUnitStates > 0)
            {
              // Set the texture
              m.Texture = TextureManager.Singleton.GetByName(p.GetTextureUnitState(0).TextureName);
              // Get a bitmap version to display
              foundPath = m.Texture.Name;
              fileInfos = ResourceGroupManager.Singleton.FindResourceFileInfo("General", foundPath );
              it = fileInfos.Begin();
              if(it != fileInfos.End())
                 foundPath = it.Value.archive.Name + "/" + foundPath;
              else
                 foundPath = "";
              m.TextureImage = new Bitmap(foundPath);
            }
            else
            {
              m.Texture = null;
              // TODO: Put in a no texture image
              m.TextureImage = null;
            }

            // Color
            m.Color = Color.White;

            components.Add(m);
            break;
              }
            }
              }
        }