예제 #1
0
 /*!
  * Events are moved from the Vixen SharedWorld to the C#
  * application through a shared event queue. Events
  * observed and handled by the Vixen SharedWorld object
  * are put into a queue. The Canvas3D class maintains a separate
  * thread which waits on this queue and converts any Vixen Events
  * it finds into C# Vixen.EventArgs and raises a .NET event
  * which can be handled in the C# application.
  */
 protected void EventLoop()
 {
     _stopevents = false;
     if ((_world == null) || (_scene == null))
     {
         return;
     }
     if ((_world.FileName != null) && SharedWorld.DoAsyncLoad)
     {
         _world.LoadAsync(_world.FileName, _scene);
     }
     while (!_stopevents)
     {
         try
         {
             Event ev = _world.NextEvent();
             if (ev == null)
             {
                 break;
             }
             string            name    = ev.GetName();
             EventArgs         args    = new VixenEventArgs(ev, RoutedVixenEvent);
             object[]          list    = { this, args };
             VixenEventHandler handler = new VixenEventHandler(PostVixenEvent);
             //SharedWorld.Trace("Canvas3D:Event " + name + "\n");
             Dispatcher.BeginInvoke(handler, list);
         }
         catch (Exception ex)
         {
             SharedWorld.LogError("exception in event loop " + ex.Message);
         }
     }
     _world.Stop();
 }
예제 #2
0
 /*!
  * @param world Vixen 3D world
  * Initializes the Vixen 3D environment for the given world.
  * If you do not provide an initial world, one is created for you.
  * This function does not start 3D display - RunVixen does that.
  * The world can only be initialized once - subsequent calls do nothing.
  *
  * @return -> Vixen SharedWorld or null if initialization failed
  */
 static public SharedWorld StartVixen(SharedWorld world)
 {
     _world = world;
     if (_world == null)
     {
         _world = new Viewer3D();
     }
     else if (_world.FileName != null)
     {
         string dir = Path.GetDirectoryName(_world.FileName);
         if ((dir != null) && (dir.Length > 0))
         {
             Directory.SetCurrentDirectory(dir);
             _world.SetMediaDir(dir);
         }
     }
     if ((_world == null) || !_world.OnInit())
     {
         SharedWorld.LogError("cannot initialize Vixen");
         return(null);
     }
     GC.KeepAlive(_world);
     _world.MakeLock();
     if (UsePhysics)
     {
         Physics.Startup();
     }
     return(_world);
 }
예제 #3
0
        /*!
         * Start up Vixen 3D display and event processing.
         * This function should not be called until the
         * underlying Window has been created and the
         * OS window handle is available. Vixen will display
         * the 3D content in this window.
         */
        public virtual bool RunVixen()
        {
            bool loadasync = World.DoAsyncLoad;

            if (_world == null)
            {
                SharedWorld.LogError("Vixen did not start");
                return(false);
            }
            if (_window == null)
            {
                SharedWorld.LogError("Cannot get window handle for parent window");
                return(false);
            }
            if (_world.IsRunning())
            {
                return(false);
            }
            //world.SetDebugLevel(1);
            if (MediaDir != null)
            {
                _world.SetMediaDir(MediaDir);
            }
            if (ContentFile == null)
            {
                loadasync = false;
            }
            else if (loadasync)
            {
                _world.FileName = GetMediaPath(ContentFile);
            }
            _world.Run((long)_window);
            if (_world.IsRunning())
            {
                ThreadStart eventloop = new ThreadStart(EventLoop);
                Thread      thread    = new Thread(eventloop);

                _scene = SharedWorld.MainScene;
                thread.Start();
                if (!loadasync)
                {
                    try
                    {
                        Scene scene = MakeScene();
                        if (scene != null)
                        {
                            GC.KeepAlive(scene);
                            _world.SetScene(scene);
                        }
                    }
                    catch (Exception ex)
                    {
                        SharedWorld.LogError("exception making initial scene " + ex.Message);
                    }
                }
                return(true);
            }
            return(false);
        }
예제 #4
0
        /*!
         * Start up Vixen 3D display and event processing.
         * This function should not be called until the
         * underlying Window has been created and the
         * OS window handle is available. Vixen will display
         * the 3D content in this window.
         */
        public virtual bool RunVixen()
        {
            SharedWorld world        = SharedWorld.Get();
            IntPtr      windowHandle = Handle;
            Scene       scene        = null;

            try
            {
                if (windowHandle == null)
                {
                    LogError("Cannot get window handle for parent window");
                    return(false);
                }
                if ((world != null) && world.IsRunning())
                {
                    return(false);
                }
                //world.SetDebugLevel(1);
                world.Run((uint)windowHandle);
            }
            catch (Exception ex)
            {
                LogError("exception starting 3D  " + ex.Message);
            }
            if (world.IsRunning())
            {
                ThreadStart eventloop = new ThreadStart(EventLoop);
                Thread      thread    = new Thread(eventloop);
                bool        loadasync = World.DoAsyncLoad;

                if (MediaDir != null)
                {
                    world.SetMediaDir(MediaDir);
                }
                if (ContentFile != null)
                {
                    world.FileName = GetMediaPath(ContentFile);
                }
                else
                {
                    loadasync = false;
                }
                thread.Start();
                if (!loadasync)
                {
                    try
                    {
                        scene = MakeScene();
                        if (scene != null)
                        {
                            world.SetScene(scene);
                        }
                    }
                    catch (Exception ex)
                    {
                        SharedWorld.LogError("exception making initial scene " + ex.Message);
                    }
                }
                scene = world.GetScene();
                if (scene != null)
                {
                    scene.OnResize();
                }
                return(true);
            }
            return(false);
        }