Exemple #1
0
 private void SetPanelCam()
 {
     if (selectedModelIndex >= 0)
     {
         panelCam.MoveToShowBounds(modelList[selectedModelIndex].Value.Bounds);
     }
 }
Exemple #2
0
        private void RenderModel(int modelToRender, bool renderToTexture = false)
        {
            EditorCamera camera = ((renderToTexture) ? defaultCam : panelCam);

            camera.FOV    = (float)(Math.PI / 4);
            camera.Aspect = splitContainer1.Panel2.Width / (float)splitContainer1.Panel2.Height;
            float cameraDistance = camera.DrawDistance;

            if (renderToTexture && (modelToRender <= 0))             // we're using our default camera, set it to a position that will show the entire model
            {
                camera.MoveToShowBounds(modelList[modelToRender].Value.Bounds);

                cameraDistance = Math.Max(camera.Distance, Vector3.Distance(camera.Position, camera.Position + (camera.Look * modelList[modelToRender].Value.Bounds.Radius * 2)));

                if (cameraDistance < camera.DrawDistance)
                {
                    cameraDistance = camera.DrawDistance;
                }
            }

            d3dDevice.SetTransform(TransformState.Projection, Matrix.PerspectiveFovRH(camera.FOV, camera.Aspect, 1, cameraDistance));
            d3dDevice.SetTransform(TransformState.View, camera.ToMatrix());
            UpdateTitleBar(camera);
            d3dDevice.SetRenderState(RenderState.FillMode, EditorOptions.RenderFillMode);
            d3dDevice.SetRenderState(RenderState.CullMode, EditorOptions.RenderCullMode);
            d3dDevice.Material = new Material {
                Ambient = System.Drawing.Color.White.ToRawColor4()
            };
            d3dDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Gray.ToRawColorBGRA(), 1, 0);
            d3dDevice.SetRenderState(RenderState.ZEnable, true);
            if (renderToTexture)
            {
                if (screenRenderTexture == null)                 // we can't render onto a null surface
                {
                    screenRenderTexture = new Texture(d3dDevice, 256, 256, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                }

                d3dDevice.SetRenderTarget(0, screenRenderTexture.GetSurfaceLevel(0));
            }
            else
            {
                d3dDevice.SetRenderTarget(0, defaultRenderTarget);
            }
            d3dDevice.BeginScene();
            //all drawings after this line

            if (modelToRender >= 0)
            {
                MatrixStack transform = new MatrixStack();
                njs_object.Attach = modelList[modelToRender].Value;
                RenderInfo.Draw(njs_object.DrawModel(d3dDevice.GetRenderState <FillMode>(RenderState.FillMode), transform, null, meshes[modelToRender], true), d3dDevice, camera);
            }
            else             // invalid selection, show a message telling the user to select something
            {
                // see if we can hide the panel's picture and/or draw an actual label here
                //onscreenFont.DrawText(textSprite, "No model selected.", screenCenter, Color.Black);
            }

            d3dDevice.EndScene();             //all drawings before this line
            d3dDevice.Present();

            if (renderToTexture)
            {
                int renderIndex = -1;
                renderIndex = attachListRenders.FindIndex(item => item.Key == modelList[modelToRender].Key);

                // convert our texture into a bitmap, add it to the rendertextures list
                Surface surface       = screenRenderTexture.GetSurfaceLevel(0);
                Stream  surfaceStream = Surface.ToStream(surface, ImageFileFormat.Bmp);
                attachListRenders[renderIndex] = new KeyValuePair <int, Bitmap>(modelList[modelToRender].Key, new Bitmap(surfaceStream));
            }
        }
Exemple #3
0
        private void ActionInputCollector_OnActionRelease(ActionInputCollector sender, string actionName)
        {
            if (!loaded)
            {
                return;
            }

            bool draw = false;             // should the scene redraw after this action

            switch (actionName)
            {
            case ("Camera Mode"):
                eventcamera = !eventcamera;

                draw = true;
                break;

            case ("Zoom to target"):
                if (selectedObject != null)
                {
                    BoundingSphere bounds = (selectedObject.Model?.Attach != null) ? selectedObject.Model.Attach.Bounds :
                                            new BoundingSphere(selectedObject.Position.X, selectedObject.Position.Y, selectedObject.Position.Z, 10);

                    bounds.Center += selectedObject.Position;
                    cam.MoveToShowBounds(bounds);
                }

                draw = true;
                break;

            case ("Change Render Mode"):
                if (EditorOptions.RenderFillMode == FillMode.Solid)
                {
                    EditorOptions.RenderFillMode = FillMode.Point;
                }
                else
                {
                    EditorOptions.RenderFillMode += 1;
                }

                draw = true;
                break;

            case ("Increase camera move speed"):
                cam.MoveSpeed += 0.0625f;
                //UpdateTitlebar();
                break;

            case ("Decrease camera move speed"):
                cam.MoveSpeed -= 0.0625f;
                //UpdateTitlebar();
                break;

            case ("Reset camera move speed"):
                cam.MoveSpeed = EditorCamera.DefaultMoveSpeed;
                //UpdateTitlebar();
                break;

            case ("Reset Camera Position"):
                if (!eventcamera)
                {
                    cam.Position = new Vector3();
                    draw         = true;
                }
                break;

            case ("Reset Camera Rotation"):
                if (!eventcamera)
                {
                    cam.Pitch = 0;
                    cam.Yaw   = 0;
                    draw      = true;
                }
                break;

            case ("Camera Move"):
                cameraKeyDown = false;
                break;

            case ("Camera Zoom"):
                zoomKeyDown = false;
                break;

            case ("Camera Look"):
                lookKeyDown = false;
                break;

            case ("Next Scene"):
                scenenum++;
                animframe = (timer1.Enabled ? 0 : -1);
                decframe  = animframe;
                if (scenenum == @event.Scenes.Count)
                {
                    if (timer1.Enabled)
                    {
                        scenenum = 1;
                    }
                    else
                    {
                        scenenum = 0;
                    }
                }

                draw = true;
                break;

            case ("Previous Scene"):
                scenenum--;
                animframe = (timer1.Enabled ? 0 : -1);
                decframe  = animframe;
                if (scenenum == -1 || (timer1.Enabled && scenenum == 0))
                {
                    scenenum = @event.Scenes.Count - 1;
                }

                draw = true;
                break;

            case ("Previous Frame"):
                if (scenenum > 0 && !timer1.Enabled)
                {
                    animframe--;
                    if (animframe < -1)
                    {
                        scenenum--;
                        if (scenenum == 0)
                        {
                            scenenum = @event.Scenes.Count - 1;
                        }
                        animframe = @event.Scenes[scenenum].FrameCount - 1;
                    }
                    decframe = animframe;

                    draw = true;
                }
                break;

            case ("Next Frame"):
                if (scenenum > 0 && !timer1.Enabled)
                {
                    animframe++;
                    if (animframe == @event.Scenes[scenenum].FrameCount)
                    {
                        scenenum++;
                        if (scenenum == @event.Scenes.Count)
                        {
                            scenenum = 1;
                        }
                        animframe = -1;
                    }
                    decframe = animframe;

                    draw = true;
                }
                break;

            case ("Play/Pause Animation"):
                if (!timer1.Enabled)
                {
                    if (scenenum == 0)
                    {
                        scenenum = 1;
                    }
                    if (animframe == -1)
                    {
                        decframe = animframe = 0;
                    }
                }
                timer1.Enabled = !timer1.Enabled;
                draw           = true;
                break;

            default:
                break;
            }

            if (draw)
            {
                UpdateWeightedModels();
                DrawEntireModel();
            }
        }