Пример #1
0
        public override List <RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
        {
            if (!camera.SphereInFrustum(Bounds))
            {
                return(EmptyRenderInfo);
            }

            List <RenderInfo> result = new List <RenderInfo>();

            RenderInfo outputInfo = new RenderInfo(mesh, 0, Matrix.Identity, (Selected) ? SelectedMaterial : UnSelectedMaterial, null, EditorOptions.RenderFillMode, Bounds);

            result.Add(outputInfo);

            textSprite.Begin(SpriteFlags.AlphaBlend);

            Matrix view       = camera.ToMatrix();
            Matrix projection = Matrix.PerspectiveFovRH(camera.FOV, camera.Aspect, 1, camera.DrawDistance);

            if (Selected)
            {
                for (int vIndx = 0; vIndx < splineData.Path.Count(); vIndx++)
                {
                    #region Draw Vertex IDs
                    Vector3 screenCoordinates = Vector3.Project(new Vector3(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z),
                                                                dev.Viewport, projection, view, Matrix.Identity);
                    Vector3 altScrCoord = Vector3.Project(new Vector3(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z),
                                                          dev.Viewport, dev.Transform.Projection, dev.Transform.View, Matrix.Identity);

                    EditorOptions.OnscreenFont.DrawText(textSprite, vIndx.ToString(), new Point((int)(screenCoordinates.X), (int)(screenCoordinates.Y)), Color.White);
                    #endregion

                    #region Draw Vertex Handles
                    transform.Push();

                    transform.Translate(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z);

                    result.Add(new RenderInfo(vertexHandleMesh, 0, transform.Top, UnSelectedMaterial, null, FillMode.Solid, new BoundingSphere(splineData.Path[vIndx].Position.X,
                                                                                                                                               splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z, 1f)));

                    if (vIndx == selectedKnot)
                    {
                        result.Add(new RenderInfo(vertexHandleMesh, 0, transform.Top, SelectedMaterial, null, FillMode.WireFrame, new BoundingSphere(splineData.Path[vIndx].Position.X,
                                                                                                                                                     splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z, 1f)));
                    }
                    transform.Pop();
                    #endregion
                }
            }

            textSprite.End();

            return(result);
        }
Пример #2
0
        internal void DrawLevel()
        {
            if (!loaded)
            {
                return;
            }
            d3ddevice.SetTransform(TransformType.Projection, Matrix.PerspectiveFovRH((float)(Math.PI / 4), panel1.Width / (float)panel1.Height, 1, cam.DrawDistance));
            d3ddevice.SetTransform(TransformType.View, cam.ToMatrix());
            Text = "X=" + cam.Position.X + " Y=" + cam.Position.Y + " Z=" + cam.Position.Z + " Pitch=" + cam.Pitch.ToString("X") + " Yaw=" + cam.Yaw.ToString("X") + " Interval=" + interval + (cam.mode == 1 ? " Distance=" + cam.Distance : "") + (animation != null ? " Animation=" + animation.Name + " Frame=" + animframe : "");
            d3ddevice.RenderState.FillMode = EditorOptions.RenderFillMode;
            d3ddevice.RenderState.CullMode = EditorOptions.RenderCullMode;
            d3ddevice.Material             = new Material {
                Ambient = Color.White
            };
            d3ddevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black.ToArgb(), 1, 0);
            d3ddevice.RenderState.ZBufferEnable = true;
            d3ddevice.BeginScene();
            //all drawings after this line
            EditorOptions.RenderStateCommonSetup(d3ddevice);

            MatrixStack transform = new MatrixStack();

            if (animation != null)
            {
                RenderInfo.Draw(model.DrawModelTreeAnimated(d3ddevice, transform, Textures, meshes, animation, animframe), d3ddevice, cam);
            }
            else
            {
                RenderInfo.Draw(model.DrawModelTree(d3ddevice, transform, Textures, meshes), d3ddevice, cam);
            }

            if (selectedObject != null)
            {
                DrawSelectedObject(model, transform);
            }

            d3ddevice.EndScene();             //all drawings before this line
            d3ddevice.Present();
        }
Пример #3
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));
            }
        }
Пример #4
0
        internal void DrawLevel()
        {
            if (!loaded)
            {
                return;
            }
            cam.FOV          = (float)(Math.PI / 4);
            cam.Aspect       = panel1.Width / (float)panel1.Height;
            cam.DrawDistance = 10000;
            Matrix projection = Matrix.PerspectiveFovRH(cam.FOV, cam.Aspect, 1, cam.DrawDistance);
            Matrix view       = cam.ToMatrix();

            d3ddevice.SetTransform(TransformState.Projection, projection);
            d3ddevice.SetTransform(TransformState.View, view);
            Text = "X=" + cam.Position.X + " Y=" + cam.Position.Y + " Z=" + cam.Position.Z + " Pitch=" + cam.Pitch.ToString("X") + " Yaw=" + cam.Yaw.ToString("X") + " Interval=" + interval + (cam.mode == 1 ? " Distance=" + cam.Distance : "");
            d3ddevice.SetRenderState(RenderState.FillMode, (int)EditorOptions.RenderFillMode);
            d3ddevice.SetRenderState(RenderState.CullMode, (int)EditorOptions.RenderCullMode);
            d3ddevice.Material = new Material {
                Ambient = Color.White.ToRawColor4()
            };
            d3ddevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black.ToRawColorBGRA(), 1, 0);
            d3ddevice.SetRenderState(RenderState.ZEnable, true);
            d3ddevice.BeginScene();
            //all drawings after this line
            cam.DrawDistance = EditorOptions.RenderDrawDistance;
            cam.BuildFrustum(view, projection);

            EditorOptions.RenderStateCommonSetup(d3ddevice);

            MatrixStack       transform  = new MatrixStack();
            List <RenderInfo> renderlist = new List <RenderInfo>();

            if (LevelData.LevelItems != null)
            {
                for (int i = 0; i < LevelData.LevelItemCount; i++)
                {
                    bool display = false;
                    if (visibleToolStripMenuItem.Checked && LevelData.GetLevelitemAtIndex(i).Visible)
                    {
                        display = true;
                    }
                    else if (invisibleToolStripMenuItem.Checked && !LevelData.GetLevelitemAtIndex(i).Visible)
                    {
                        display = true;
                    }
                    else if (allToolStripMenuItem.Checked)
                    {
                        display = true;
                    }
                    if (display)
                    {
                        renderlist.AddRange(LevelData.GetLevelitemAtIndex(i).Render(d3ddevice, cam, transform));
                    }
                }
            }
            RenderInfo.Draw(renderlist, d3ddevice, cam);

            d3ddevice.EndScene();             // scene drawings go before this line

            transformGizmo.Draw(d3ddevice, cam);
            d3ddevice.Present();
        }
Пример #5
0
        internal void DrawEntireModel()
        {
            if (!loaded)
            {
                return;
            }
            d3ddevice.SetTransform(TransformState.Projection, Matrix.PerspectiveFovRH(cam.FOV, panel1.Width / (float)panel1.Height, 1, cam.DrawDistance));
            d3ddevice.SetTransform(TransformState.View, cam.ToMatrix());
            UpdateStatusString();
            d3ddevice.SetRenderState(RenderState.FillMode, EditorOptions.RenderFillMode);
            d3ddevice.SetRenderState(RenderState.CullMode, EditorOptions.RenderCullMode);
            d3ddevice.Material = new Material {
                Ambient = Color.White.ToRawColor4()
            };
            d3ddevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black.ToRawColorBGRA(), 1, 0);
            d3ddevice.SetRenderState(RenderState.ZEnable, true);
            d3ddevice.BeginScene();

            //all drawings after this line
            EditorOptions.RenderStateCommonSetup(d3ddevice);

            MatrixStack       transform  = new MatrixStack();
            List <RenderInfo> renderList = new List <RenderInfo>();

            for (int i = 0; i < @event.Scenes[0].Entities.Count; i++)
            {
                NJS_OBJECT model = @event.Scenes[0].Entities[i].Model;
                if (model == null)
                {
                    model = @event.Scenes[0].Entities[i].GCModel;
                }
                if (model != null)
                {
                    if (model.HasWeight)
                    {
                        renderList.AddRange(model.DrawModelTreeWeighted(EditorOptions.RenderFillMode, transform.Top, Textures, meshes[0][i]));
                        if (@event.Scenes[0].Entities[i] == selectedObject)
                        {
                            renderList.AddRange(model.DrawModelTreeWeightedInvert(transform.Top, meshes[0][i]));
                        }
                    }
                    else
                    {
                        renderList.AddRange(model.DrawModelTree(EditorOptions.RenderFillMode, transform, Textures, meshes[0][i]));
                        if (@event.Scenes[0].Entities[i] == selectedObject)
                        {
                            renderList.AddRange(model.DrawModelTreeInvert(transform, meshes[0][i]));
                        }
                    }
                }
            }
            if (scenenum > 0)
            {
                for (int i = 0; i < @event.Scenes[scenenum].Entities.Count; i++)
                {
                    NJS_OBJECT model = @event.Scenes[scenenum].Entities[i].Model;
                    if (model == null)
                    {
                        model = @event.Scenes[scenenum].Entities[i].GCModel;
                    }
                    if (model != null)
                    {
                        if (model.HasWeight)
                        {
                            if (animframe != -1 && @event.Scenes[scenenum].Entities[i].Motion != null)
                            {
                                transform.Push();
                                transform.NJTranslate(@event.Scenes[scenenum].Entities[i].Motion.Models[0].GetPosition(animframe));
                            }
                            renderList.AddRange(model.DrawModelTreeWeighted(EditorOptions.RenderFillMode, transform.Top, Textures, meshes[scenenum][i]));
                            if (@event.Scenes[scenenum].Entities[i] == selectedObject)
                            {
                                renderList.AddRange(model.DrawModelTreeWeightedInvert(transform.Top, meshes[scenenum][i]));
                            }
                            if (animframe != -1 && @event.Scenes[scenenum].Entities[i].Motion != null)
                            {
                                transform.Pop();
                            }
                        }
                        else if (animframe == -1 || @event.Scenes[scenenum].Entities[i].Motion == null)
                        {
                            renderList.AddRange(model.DrawModelTree(EditorOptions.RenderFillMode, transform, Textures, meshes[scenenum][i]));
                            if (@event.Scenes[scenenum].Entities[i] == selectedObject)
                            {
                                renderList.AddRange(model.DrawModelTreeInvert(transform, meshes[scenenum][i]));
                            }
                        }
                        else
                        {
                            renderList.AddRange(model.DrawModelTreeAnimated(EditorOptions.RenderFillMode, transform, Textures, meshes[scenenum][i], @event.Scenes[scenenum].Entities[i].Motion, animframe));
                            if (@event.Scenes[scenenum].Entities[i] == selectedObject)
                            {
                                renderList.AddRange(model.DrawModelTreeAnimatedInvert(transform, meshes[scenenum][i], @event.Scenes[scenenum].Entities[i].Motion, animframe));
                            }
                        }
                    }
                }
                if (@event.Scenes[scenenum].Big?.Model != null)
                {
                    if (@event.Scenes[scenenum].Big.Model.HasWeight)
                    {
                        renderList.AddRange(@event.Scenes[scenenum].Big.Model.DrawModelTreeWeighted(EditorOptions.RenderFillMode, transform.Top, Textures, bigmeshes[scenenum]));
                    }
                    else if (animframe == -1)
                    {
                        renderList.AddRange(@event.Scenes[scenenum].Big.Model.DrawModelTree(EditorOptions.RenderFillMode, transform, Textures, bigmeshes[scenenum]));
                    }
                    else
                    {
                        int an = 0;
                        int fr = animframe;
                        while (an < @event.Scenes[scenenum].Big.Motions.Count && @event.Scenes[scenenum].Big.Motions[an].a.Frames < fr)
                        {
                            fr -= @event.Scenes[scenenum].Big.Motions[an].a.Frames;
                            an++;
                        }
                        if (an < @event.Scenes[scenenum].Big.Motions.Count)
                        {
                            renderList.AddRange(@event.Scenes[scenenum].Big.Model.DrawModelTreeAnimated(EditorOptions.RenderFillMode, transform, Textures, bigmeshes[scenenum], @event.Scenes[scenenum].Big.Motions[an].a, fr));
                        }
                    }
                }
                if (!eventcamera && animframe != -1 && showCameraToolStripMenuItem.Checked)
                {
                    transform.Push();
                    transform.LoadMatrix(cammatrix);
                    renderList.AddRange(cammodel.DrawModel(EditorOptions.RenderFillMode, transform, null, cammesh, true));
                    transform.Pop();
                }
            }

            RenderInfo.Draw(renderList, d3ddevice, cam);
            d3ddevice.EndScene();             //all drawings before this line
            d3ddevice.Present();
        }