Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
        }