Ejemplo n.º 1
0
        public override bool Load()
        {
            if (IsLoaded)
            {
                return(true);
            }

            if (base.Load())
            {
                this.entityHandle = MogitorsRoot.Instance.SceneManager.CreateEntity(Name, MeshFile);
                this.handle.AttachObject(this.entityHandle);
                this.entityHandle.QueryFlags  = QueryFlags.Movable;
                this.entityHandle.CastShadows = this.castShadows;
                for (int i = 0; i < subMeshes.Count; ++i)
                {
                    this.entityHandle.GetSubEntity((uint)i).SetVisible(this.subMeshes[i].Visible);
                    this.entityHandle.GetSubEntity((uint)i).MaterialName = this.subMeshes[i].Material;
                }
                if (this.subMeshes.Count == 0)
                {
                    SubMeshData data = new SubMeshData();
                    for (int i = 0; i < this.entityHandle.NumSubEntities; ++i)
                    {
                        data.Visible  = this.entityHandle.GetSubEntity((uint)i).IsVisible;
                        data.Material = this.entityHandle.GetSubEntity((uint)i).MaterialName;
                        this.subMeshes.Add(data);
                    }
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
        private bool FindNewClosest(Mogre.Ray ray, ref float closestDistance, Mogre.Entity entity)
        {
            // mesh data to retrieve
            uint vertexCount, indexCount;

            Mogre.Vector3[] vertices;
            uint[]          indices;

            // get the mesh information
            GetMeshInformationEx(entity.GetMesh(), out vertexCount, out vertices, out indexCount, out indices,
                                 entity.ParentNode._getDerivedPosition(),
                                 entity.ParentNode._getDerivedOrientation(),
                                 entity.ParentNode._getDerivedScale());

            // test for hitting individual triangles on the mesh
            bool newClosestFound = false;

            for (uint i = 0; i < indexCount; i += 3)
            {
                // check for a hit against this triangle
                var hit = Mogre.Math.Intersects(ray, vertices[indices[i]], vertices[indices[i + 1]], vertices[indices[i + 2]], true, false);

                // if it was a hit check if its the closest
                if (hit.first)
                {
                    if ((closestDistance < 0.0f) || (hit.second < closestDistance))
                    {
                        // this is the closes so far, save it off
                        closestDistance = hit.second;
                        newClosestFound = true;
                    }
                }
            }
            return(newClosestFound);
        }
Ejemplo n.º 3
0
 /** Rotate the textures of eacht entity.
  */
 public void _rotateTexture(VisualParticle particle, Mogre.Entity entity)
 {
     if (particle == null)
     {
         throw new ArgumentNullException("particle cannot be null!");
     }
     if (entity == null)
     {
         throw new ArgumentNullException("entity cannot be null!");
     }
     EntityRenderer__rotateTexture(nativePtr, particle.nativePtr, (IntPtr)entity.NativePtr);
 }
Ejemplo n.º 4
0
        public override bool UnLoad()
        {
            if (!IsLoaded)
            {
                return(true);
            }

            if (this.entityHandle != null)
            {
                this.entityHandle.ParentSceneNode.DetachObject(this.entityHandle);
                this.entityHandle._getManager().DestroyEntity(this.entityHandle);
                this.entityHandle = null;
            }

            return(base.UnLoad());
        }
Ejemplo n.º 5
0
        public override bool Load()
        {
            if (IsLoaded)
                return true;

            if (base.Load())
            {
                this.entityHandle = MogitorsRoot.Instance.SceneManager.CreateEntity(Name, MeshFile);
                this.handle.AttachObject(this.entityHandle);
                this.entityHandle.QueryFlags = QueryFlags.Movable;
                this.entityHandle.CastShadows = this.castShadows;
                for (int i = 0; i < subMeshes.Count; ++i)
                {
                    this.entityHandle.GetSubEntity((uint)i).SetVisible(this.subMeshes[i].Visible);
                    this.entityHandle.GetSubEntity((uint)i).MaterialName = this.subMeshes[i].Material;
                }
                if (this.subMeshes.Count == 0)
                {
                    SubMeshData data = new SubMeshData();
                    for (int i = 0; i < this.entityHandle.NumSubEntities; ++i)
                    {
                        data.Visible = this.entityHandle.GetSubEntity((uint)i).IsVisible;
                        data.Material = this.entityHandle.GetSubEntity((uint)i).MaterialName;
                        this.subMeshes.Add(data);
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 6
0
        public override bool UnLoad()
        {
            if (!IsLoaded)
                return true;

            if (this.entityHandle != null)
            {
                this.entityHandle.ParentSceneNode.DetachObject(this.entityHandle);
                this.entityHandle._getManager().DestroyEntity(this.entityHandle);
                this.entityHandle = null;
            }

            return base.UnLoad();
        }
Ejemplo n.º 7
0
        private void CreateImages(ObservableCollection <IconTextItem> retlist, bool skipCached)
        {
            retlist.Clear();

            Mogre.TexturePtr texture = Mogre.TextureManager.Singleton.CreateManual("EntityTex",
                                                                                   Mogre.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, Mogre.TextureType.TEX_TYPE_2D,
                                                                                   256, 256, 0, Mogre.PixelFormat.PF_A8R8G8B8, (int)Mogre.TextureUsage.TU_RENDERTARGET);

            Mogre.RenderTexture rttTex   = texture.GetBuffer().GetRenderTarget();
            Mogre.SceneManager  sceneMgr = Mogre.Root.Singleton.CreateSceneManager("OctreeSceneManager", "EntityTexMgr");

            Mogre.Light dir1 = sceneMgr.CreateLight("DisplayLight");
            dir1.SetDirection(-1, -1, -1);
            dir1.SetDiffuseColour(1, 1, 1);
            dir1.Type = Mogre.Light.LightTypes.LT_DIRECTIONAL;

            Mogre.Camera RTTCam = sceneMgr.CreateCamera("EntityCam");
            RTTCam.NearClipDistance = 0.01F;
            RTTCam.FarClipDistance  = 0;
            RTTCam.AspectRatio      = 1;
            RTTCam.FOVy             = new Mogre.Radian(new Mogre.Degree(90));
            RTTCam.Position         = new Mogre.Vector3(0, 0, 1);
            RTTCam.LookAt(0, 0, 0);

            Mogre.Viewport v = rttTex.AddViewport(RTTCam);
            v.SetClearEveryFrame(true);
            v.BackgroundColour = new Mogre.ColourValue(0, 0, 0, 0);

            Mogre.StringVector list = Mogre.ResourceGroupManager.Singleton.FindResourceNames("ProjectResources", "*.mesh", false);

            IDictionary <string, string> entities = new Dictionary <string, string>(list.Count);

            foreach (string addstr in list)
            {
                if (entities.Values.Contains(addstr) == false)
                {
                    entities.Add(addstr, addstr);
                }
            }

            foreach (KeyValuePair <string, string> ite in entities)
            {
                string addstr     = ite.Key;
                string addstrFile = MogitorsSystem.Instance.CombinePath(MogitorsRoot.Instance.ProjectOptions.ProjectDir, addstr + ".png");

                if (!skipCached || !System.IO.File.Exists(addstrFile))
                {
                    Mogre.Entity entity = sceneMgr.CreateEntity("scbDisplay", addstr);
                    sceneMgr.RootSceneNode.AttachObject(entity);

                    Mogre.Vector3 vSize   = entity.BoundingBox.HalfSize;
                    Mogre.Vector3 vCenter = entity.BoundingBox.Center;

                    vSize += new Mogre.Vector3(vSize.z, vSize.z, vSize.z);

                    float maxsize = Math.Max(Math.Max(vSize.x, vSize.y), vSize.z);

                    vSize = new Mogre.Vector3(0, 0, maxsize * 1.1f) + vCenter;

                    RTTCam.SetPosition(vSize.x, vSize.y, vSize.z);
                    RTTCam.LookAt(vCenter.x, vCenter.y, vCenter.z);

                    rttTex.Update();
                    rttTex.WriteContentsToFile(addstrFile);

                    entity.ParentSceneNode.DetachObject(entity);
                    sceneMgr.DestroyEntity(entity);
                }

                retlist.Add(new IconTextItem(addstr.Remove(addstr.Length - 5, 5), addstrFile));
            }

            rttTex.RemoveAllViewports();
            Mogre.Root.Singleton.DestroySceneManager(sceneMgr);
            Mogre.Root.Singleton.DetachRenderTarget(rttTex.Name);
            Mogre.TextureManager.Singleton.Unload(texture.Name);
            Mogre.TextureManager.Singleton.Remove(texture.Name);

            list = null;
        }
        public bool PickEntity(Mogre.RaySceneQuery raySceneQuery, Mogre.Ray ray, out Mogre.Entity result, Mogre.Vector3 hitPoint, string excludedObject, float maxDistance)
        {
            result = null;

            raySceneQuery.Ray       = ray;
            raySceneQuery.QueryMask = QueryFlags.Movable;
            raySceneQuery.SetSortByDistance(true);

            if (raySceneQuery.Execute().Count <= 0)
            {
                result = null;
                return(false);
            }

            // at this point we have raycast to a series of different objects bounding boxes.
            float closestDistance = maxDistance;

            Mogre.Vector3 closestResult = Mogre.Vector3.ZERO;
            foreach (var thisResult in raySceneQuery.GetLastResults())
            {
                // stop checking if we have found a raycast hit that is closer
                // than all remaining entities
                if ((closestDistance >= 0.0f) && (closestDistance < thisResult.distance))
                {
                    break;
                }

                // only check this result if its a hit against an entity
                if ((thisResult.movable != null) && (thisResult.movable.MovableType == "Entity"))
                {
                    Mogre.Entity entity = thisResult.movable as Mogre.Entity;

                    if (!entity.Visible || entity.Name == excludedObject)
                    {
                        continue;
                    }

                    bool newClosestFound = FindNewClosest(ray, ref closestDistance, entity);

                    // if we found a new closes raycast for this object, update the
                    // closes_result before moving on to the next object.
                    if (newClosestFound)
                    {
                        closestResult = ray.GetPoint(closestDistance);
                        result        = entity;
                    }
                }
            }

            // Return the result
            if (closestDistance != maxDistance)
            {
                hitPoint = closestResult;
                return(true);
            }
            else
            {
                // Raycast failed
                return(false);
            }
        }