Exemple #1
0
        /// <summary>
        /// Builds a traverse list from the Scene and dispatches it for rendering</summary>
        /// <param name="scene">The scene to dispatch</param>
        /// <param name="camera">The camera</param>
        public virtual void Dispatch(Scene scene, Camera camera)
        {
            Util3D.RenderStats.ResetFrame();
            PreDispatch(scene, camera);

            // Clear traverse list
            m_traverseList.Clear();
            m_traverseList.SetViewMatrix(camera.ViewMatrix);

            s_stopWatch.Reset();
            s_stopWatch.Start();
            Util3D.RenderStats.TimeForConstraints = s_stopWatch.ElapsedMilliseconds;

            if (m_width > 0 && m_height > 0)
            {
                s_stopWatch.Reset();
                s_stopWatch.Start();
                BuildTraverseList(camera, m_traverseList, scene);
                Util3D.RenderStats.TraverseNodeCount = m_traverseList.Count;
                Util3D.RenderStats.TimeForTraverse = s_stopWatch.ElapsedMilliseconds;

                s_stopWatch.Reset();
                s_stopWatch.Start();
                RenderPass(m_traverseList, camera);
                Util3D.RenderStats.TimeForDispatchTraverseList = s_stopWatch.ElapsedMilliseconds;

                DrawStats(camera);
            }

            PostDispatch(scene, camera);
        }
Exemple #2
0
        /// <summary>
        /// Constructor</summary>
        /// <param name="scene">Scene graph</param>
        public DesignControl(Scene scene)
        {
            m_scene = scene;

            m_renderAction = new RenderAction(RenderStateGuardian);
            m_pickAction = new PickAction(RenderStateGuardian);

            // default render states. These correspond to the state of the toggles on the toolbar,
            //  like wireframe on/off, lighting on/off, backface culling on/off, and textures on/off.
            m_renderState.RenderMode = RenderMode.Smooth | RenderMode.CullBackFace | RenderMode.Textured | RenderMode.Lit | RenderMode.Alpha;
            m_renderState.WireframeColor = new Vec4F(0, 0.015f, 0.376f, 1.0f);
            m_renderState.SolidColor = new Vec4F(1,1,1, 1.0f);
        }
Exemple #3
0
        /// <summary>
        /// Generates a thumbnail image and saves it to the given path as a PNG-format file</summary>
        /// <param name="scene">Scene to render</param>
        /// <param name="action">Rendering action</param>
        /// <param name="path">Path of bitmap file, in the PNG format. The extension must be "png".</param>
        /// <param name="camera">Camera to use</param>
        public void Generate(Scene scene, IRenderAction action, Camera camera, string path)
        {
            if (Path.GetExtension(path) != ".png")
                throw new ArgumentException("the extension must be 'png'");

            m_scene = scene;
            m_action = action;
            m_camera = camera;

            // Paint the scene and save it.
            using (Bitmap bitmap = m_bitmapContext.CreateBitmap(Paint))
                bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Png);

            m_scene = null;
            m_action = null;
            m_camera = null;
        }
Exemple #4
0
        /// <summary>
        /// Dispatches the given traverse list for rendering</summary>
        /// <param name="traverseList">The traverse list</param>
        /// <param name="scene">The Scene to dispatch</param>
        /// <param name="camera">The camera</param>
        public virtual void Dispatch(ICollection<TraverseNode> traverseList, Scene scene, Camera camera)
        {
            Util3D.RenderStats.ResetFrame();
            PreDispatch(scene, camera);

            // Dispatch traverse list
            if (m_width > 0 && m_height > 0)
            {
                foreach (TraverseNode node in traverseList)
                {
                    PushMatrix(node.Transform, false);
                    node.RenderObject.Dispatch(node.GraphPath, node.RenderState, this, camera);
                    PopMatrix();
                }
            }

            PostDispatch(scene, camera);
        }
Exemple #5
0
        /// <summary>
        /// Dispatches the given traverse list for rendering</summary>
        /// <param name="traverseList">The traverse list</param>
        /// <param name="scene">The scene to dispatch</param>
        /// <param name="camera">The camera</param>
        public override void Dispatch(ICollection<TraverseNode> traverseList, Scene scene, Camera camera)
        {
            //Util3D.RenderStats.ResetFrame();
            PreDispatch(scene, camera);

            DispatchTraverseList(traverseList, camera);

            PostDispatch(scene, camera);            
        }
Exemple #6
0
        /// <summary>
        /// Builds a traverse list from the Scene and dispatches it for rendering</summary>
        /// <param name="scene">The scene to dispatch</param>
        /// <param name="camera">The camera</param>
        public override void Dispatch(Scene scene, Camera camera)
        {
            //We no longer want render stats for picking because when testing for the manipulator,
            //  this is very fast and leads to an artificially high frame rate. Better to let the
            //  displayed frame rate mean what people expect -- the number of times the visible
            //  frame buffer is rendered each second.
            //Util3D.RenderStats.ResetFrame();
            PreDispatch(scene, camera);

            // Cache current view frustum
            Frustum frust = new Frustum();
            frust.Set(camera.Frustum);

            // Set pick frustum
            camera.Frustum.Set(m_viewFrust0);

            // Clear traverse list
            m_traverseList.Clear();
            m_traverseList.SetViewMatrix(camera.ViewMatrix);

            // Make sure that solid-coloring is default, so that objects that don't implement
            // IRenderPick can still be picked when wireframe mode is on.
            RenderState origState = scene.StateStack.Peek();
            RenderState pickState;
            if (origState != null)
            {
                scene.StateStack.Pop();
                pickState = new RenderState(origState);
            }
            else
            {
                pickState = new RenderState();
            }
            pickState.RenderMode |= RenderMode.Smooth | RenderMode.SolidColor;
            pickState.RenderMode &= ~RenderMode.Wireframe;
            pickState.OverrideChildState |= RenderMode.Wireframe;
            scene.StateStack.Push(pickState);

            //s_stopWatch.Reset();
            //s_stopWatch.Start();
            BuildTraverseList(camera, m_traverseList, scene);
            //Util3D.RenderStats.TraverseNodeCount = m_traverseList.Count;
            //Util3D.RenderStats.TimeForTraverse = s_stopWatch.ElapsedMilliseconds;

            // Restore original render state.
            scene.StateStack.Pop();
            if (origState != null)
            {
                scene.StateStack.Push(origState);
            }

            //Restore view frustum for pick rendering
            camera.Frustum.Set(frust);

            //s_stopWatch.Reset();
            //s_stopWatch.Start();
            DispatchTraverseList(m_traverseList, camera);
            //Util3D.RenderStats.TimeForDispatchTraverseList = s_stopWatch.ElapsedMilliseconds;

            PostDispatch(scene, camera);            
        }
Exemple #7
0
        /// <summary>
        /// Shoots a ray into the scene and returns the intersection point</summary>
        /// <param name="camera">The camera</param>
        /// <param name="x">Ray X coordinate in screen space</param>
        /// <param name="y">Ray y coordinate in screen space</param>
        /// <param name="scene">The given scene</param>
        /// <param name="point">The point of intersection</param>
        /// <param name="firstHit">The HitRecord giving possible nearest vertex and surface normal</param>
        /// <returns>True if the ray intersects the scene</returns>
        public bool Intersect(Camera camera, int x, int y, Scene scene, ref Vec3F point,
            out HitRecord firstHit)
        {
            firstHit = null;

            //Too small of a pick tolerance makes Design View tooltips and right-click context
            //menus not work on wireframe / linework.
            //m_pickTolerance = 0.001f;
            Init(camera, x, y, x, y, false, true);
            Dispatch(scene, camera);
            HitRecord[] hits = GetHits();
            //m_pickTolerance = 3.0f;

            if (hits.Length == 0)
                return false;

            firstHit = hits[0];
            if (firstHit.HasWorldIntersection)
            {
                point = firstHit.WorldIntersection;
                return true;
            }

            return false;
        }
Exemple #8
0
        /// <summary>
        /// Shoots a ray into the scene and returns the intersection point</summary>
        /// <param name="camera">The camera</param>
        /// <param name="x">Ray x coordinate in screen space</param>
        /// <param name="y">Ray y coordinate in screen space</param>
        /// <param name="scene">The given scene</param>
        /// <param name="traverseList">Traverse list to use when performing the intersection</param>
        /// <param name="point">The point of intersection</param>
        /// <returns>True if the ray intersects the scene</returns>
        public bool Intersect(Camera camera, int x, int y, Scene scene, ICollection<TraverseNode> traverseList
            , ref Vec3F point)
        {
            m_pickTolerance = 0.001f;
            Init(camera, x, y, x, y, false, true);
            Dispatch(traverseList, scene, camera);
            HitRecord[] hits = GetHits(traverseList);
            m_pickTolerance = 3.0f;

            Vec3F surfaceNormal;
            return Intersect(x, y, hits, ref point, out surfaceNormal);
        }
Exemple #9
0
        /// <summary>
        /// Shoots a ray into the scene and returns the intersection point</summary>
        /// <param name="camera">The camera</param>
        /// <param name="x">Ray x coordinate in screen space</param>
        /// <param name="y">Ray y coordinate in screen space</param>
        /// <param name="scene">The given scene</param>
        /// <param name="point">The point of intersection</param>
        /// <param name="surfaceNormal">The surface normal of the target object at the intersection
        /// point, or the zero vector if the surface normal could not be found</param>
        /// <returns>True if the ray intersects the scene</returns>
        public bool Intersect(Camera camera, int x, int y, Scene scene, ref Vec3F point,
            out Vec3F surfaceNormal)
        {
            //Too small of a pick tolerance makes Design View tooltips and right-click context
            //menus not work on wireframe / linework.
            //m_pickTolerance = 0.001f;
            Init(camera, x, y, x, y, false, true);
            Dispatch(scene, camera);
            HitRecord[] hits = GetHits();
            //m_pickTolerance = 3.0f;

            return Intersect(x, y, hits, ref point, out surfaceNormal);
        }
Exemple #10
0
 /// <summary>
 /// Shoots a ray into the scene and returns the intersection point</summary>
 /// <param name="camera">The camera</param>
 /// <param name="x">Ray x coordinate in screen space</param>
 /// <param name="y">Ray y coordinate in screen space</param>
 /// <param name="scene">The given scene</param>
 /// <param name="point">The point of intersection</param>
 /// <returns>True if the ray intersects the scene</returns>
 public bool Intersect(Camera camera, int x, int y, Scene scene, ref Vec3F point)
 {
     Vec3F surfaceNormal;
     return Intersect(camera, x, y, scene, ref point, out surfaceNormal);
 }
Exemple #11
0
 /// <summary>
 /// Construct render view</summary>
 public RenderView()
 {
     m_scene = new Scene();
     m_designControl = new DesignControl(m_scene);
 }
Exemple #12
0
 /// <summary>
 /// Called after dispatching the scene from the Dispatch method</summary>
 /// <param name="scene">The scene being dispatched</param>
 /// <param name="camera">A Camera</param>
 protected virtual void PostDispatch(Scene scene, Camera camera)
 {
 }
Exemple #13
0
        /// <summary>
        /// Called before dispatching the scene from the Dispatch method</summary>
        /// <param name="scene">The scene being dispatched</param>
        /// <param name="camera">The Camera</param>
        protected virtual void PreDispatch(Scene scene, Camera camera)
        {
            SetupProjection(camera);
            SetupView(camera);

            // set the clear values
            Color backgroundColor = scene.BackgroundColor;
            Gl.glClearColor(
                backgroundColor.R * (1.0f / 255),
                backgroundColor.G * (1.0f / 255),
                backgroundColor.B * (1.0f / 255),
                0);
            Gl.glClearDepth(1.0);

            // ensure that the buffers are writeable
            Gl.glDepthMask(Gl.GL_TRUE);
            Gl.glColorMask(Gl.GL_TRUE, Gl.GL_TRUE, Gl.GL_TRUE, Gl.GL_TRUE);

            // clear the buffers
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
        }
Exemple #14
0
 /// <summary>
 /// Builds a traverse list from the given scene</summary>
 /// <param name="camera">The camera</param>
 /// <param name="scene">The Scene for which to build the traverse list</param>
 /// <returns>The traverse list</returns>
 public ICollection<TraverseNode> BuildTraverseList(Camera camera, Scene scene)
 {
     m_traverseList.Clear();
     BuildTraverseList(camera, m_traverseList, scene);
     return m_traverseList;
 }