Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        internal void DrawLevel()
        {
            if (!isStageLoaded || !Enabled || DeviceResizing)
            {
                return;
            }

            cam.FOV          = (float)(Math.PI / 4);
            cam.Aspect       = RenderPanel.Width / (float)RenderPanel.Height;
            cam.DrawDistance = 100000;
            UpdateTitlebar();

            #region D3D Parameters
            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);
            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, EditorOptions.FillColor.ToRawColorBGRA(), 1, 0);
            d3ddevice.SetRenderState(RenderState.ZEnable, true);
            #endregion

            d3ddevice.BeginScene();
            // all drawings after this line
            MatrixStack transform = new MatrixStack();
            EditorOptions.RenderStateCommonSetup(d3ddevice);
            if (LevelData.leveleff != null & viewSkyboxToolStripMenuItem.Checked)
            {
                d3ddevice.SetRenderState(RenderState.FogEnable, false);
                d3ddevice.SetRenderState(RenderState.ZWriteEnable, false);
                LevelData.leveleff.Render(d3ddevice, cam);
                d3ddevice.SetRenderState(RenderState.ZWriteEnable, true);
            }

            #region Fog settings
            if (currentStageFog != null && fogButton.Checked)
            {
                d3ddevice.SetRenderState(RenderState.FogColor, System.Drawing.Color.FromArgb(currentStageFog.A, currentStageFog.R, currentStageFog.G, currentStageFog.B).ToArgb());
                EditorOptions.SetStageFogData(currentStageFog);
                d3ddevice.SetRenderState(RenderState.FogEnable, currentStageFog.FogEnabled);
            }
            #endregion

            List <RenderInfo> renderlist_death = new List <RenderInfo>();
            List <RenderInfo> renderlist_geo   = new List <RenderInfo>();
            List <RenderInfo> renderlist_char  = new List <RenderInfo>();
            List <RenderInfo> renderlist_set   = new List <RenderInfo>();

            #region Adding Level Geometry

            if (LevelData.LevelItems != null)
            {
                foreach (LevelItem item in LevelData.LevelItems)
                {
                    bool display = false;

                    if (visibleToolStripMenuItem.Checked && item.Visible)
                    {
                        display = true;
                    }
                    else if (invisibleToolStripMenuItem.Checked && !item.Visible)
                    {
                        display = true;
                    }
                    else if (allToolStripMenuItem.Checked)
                    {
                        display = true;
                    }

                    if (display)
                    {
                        renderlist_geo.AddRange(item.Render(d3ddevice, cam, transform));
                    }
                }
            }

            if (LevelData.LevelAnims != null)
            {
                foreach (LevelAnim item in LevelData.LevelAnims)
                {
                    bool display = false;

                    if (visibleToolStripMenuItem.Checked || allToolStripMenuItem.Checked)
                    {
                        display = true;
                    }

                    if (display)
                    {
                        renderlist_geo.AddRange(item.Render(d3ddevice, cam, transform));
                    }
                }
            }
            #endregion

            if (LevelData.StartPositions != null)
            {
                renderlist_char.AddRange(LevelData.StartPositions[LevelData.Character].Render(d3ddevice, cam, transform));
            }

            #region Adding Death Zones
            if (LevelData.DeathZones != null & viewDeathZonesToolStripMenuItem.Checked)
            {
                foreach (DeathZoneItem item in LevelData.DeathZones)
                {
                    if (item.Visible)
                    {
                        renderlist_death.AddRange(item.Render(d3ddevice, cam, transform));
                    }
                }
            }
            #endregion

            #region Adding SET Layout
            if (!LevelData.SETItemsIsNull() && viewSETItemsToolStripMenuItem.Checked)
            {
                foreach (SETItem item in LevelData.SETItems(LevelData.Character))
                {
                    bool render = false;
                    if (item.ClipSetting == ClipSetting.All)
                    {
                        render = true;
                    }
                    else if (item.ClipSetting == ClipSetting.HighOnly && editorDetailSetting == ClipLevel.Far)
                    {
                        render = true;
                    }
                    else if (item.ClipSetting == ClipSetting.MediumAndHigh && (editorDetailSetting == ClipLevel.Medium || editorDetailSetting == ClipLevel.Far))
                    {
                        render = true;
                    }
                    if (render)
                    {
                        renderlist_set.AddRange(item.Render(d3ddevice, cam, transform));
                    }
                }
            }
            #endregion

            #region Adding CAM Layout
            if (LevelData.CAMItems != null && viewCAMItemsToolStripMenuItem.Checked)
            {
                foreach (CAMItem item in LevelData.CAMItems[LevelData.Character])
                {
                    renderlist_set.AddRange(item.Render(d3ddevice, cam, transform));
                }
            }
            #endregion

            #region Adding Mission SET Layout
            if (LevelData.MissionSETItems != null && viewMissionSETItemsToolStripMenuItem.Checked)
            {
                foreach (MissionSETItem item in LevelData.MissionSETItems[LevelData.Character])
                {
                    renderlist_set.AddRange(item.Render(d3ddevice, cam, transform));
                }
            }
            #endregion

            #region Adding splines
            if (viewSplinesToolStripMenuItem.Checked)
            {
                foreach (SplineData spline in LevelData.LevelSplines)
                {
                    renderlist_set.AddRange(spline.Render(d3ddevice, cam, transform));
                }
            }
            #endregion

            #region Debug Bounds Drawing
            if (boundsToolStripMenuItem.Checked)
            {
                MatrixStack debugBoundsStack = new MatrixStack();
                List <Item> selection        = selectedItems.GetSelection();
                debugBoundsStack.Push();
                foreach (Item item in selection)
                {
                    if (item is LevelItem)
                    {
                        LevelItem lvlItem = (LevelItem)item;
                        boundsMesh = Direct3D.Mesh.Sphere(lvlItem.CollisionData.Bounds.Radius, 9, 9);
                        debugBoundsStack.NJTranslate(lvlItem.CollisionData.Bounds.Center);
                        RenderInfo info = new RenderInfo(boundsMesh, 0, debugBoundsStack.Top, boundsMaterial, null, FillMode.Solid, item.Bounds);
                        renderlist_geo.Add(info);
                    }
                    else if (item is SETItem)
                    {
                        SETItem setitem = (SETItem)item;
                        boundsMesh = Direct3D.Mesh.Sphere(setitem.Bounds.Radius, 9, 9);
                        debugBoundsStack.NJTranslate(setitem.Bounds.Center);
                        RenderInfo info = new RenderInfo(boundsMesh, 0, debugBoundsStack.Top, boundsMaterial, null, FillMode.Solid, item.Bounds);
                        renderlist_set.Add(info);
                    }
                }
                debugBoundsStack.Pop();
            }
            #endregion

            if (dragType == DragType.Model)
            {
                if (dragPlaceLevelModel != null && dragPlaceLevelMesh != null)
                {
                    renderlist_set.AddRange(dragPlaceLevelModel.DrawModel(
                                                d3ddevice.GetRenderState <FillMode>(RenderState.FillMode),
                                                transform,
                                                LevelData.Textures[LevelData.leveltexs],
                                                dragPlaceLevelMesh,
                                                true));
                }
            }

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

            cam.DrawDistance = Math.Min(EditorOptions.RenderDrawDistance, EditorOptions.LevelDrawDistance);
            drawqueue.AddRange(RenderInfo.Queue(renderlist_geo, cam));

            cam.DrawDistance = Math.Min(EditorOptions.SetItemDrawDistance, EditorOptions.SetItemDrawDistance);
            drawqueue.AddRange(RenderInfo.Queue(renderlist_set, cam));

            cam.DrawDistance = Math.Min(EditorOptions.RenderDrawDistance, EditorOptions.RenderDrawDistance);
            EditorOptions.SetLightType(d3ddevice, EditorOptions.SADXLightTypes.Level);
            RenderInfo.Draw(drawqueue, d3ddevice, cam);

            d3ddevice.SetRenderState(RenderState.FogEnable, false);
            EditorOptions.SetLightType(d3ddevice, EditorOptions.SADXLightTypes.Character);
            RenderInfo.Draw(renderlist_char, d3ddevice, cam);

            d3ddevice.SetRenderState(RenderState.ZWriteEnable, false);
            RenderInfo.Draw(renderlist_death, d3ddevice, cam);
            d3ddevice.SetRenderState(RenderState.ZWriteEnable, true);

            // SADX water
            if (LevelData.leveleff != null & viewSkyboxToolStripMenuItem.Checked)
            {
                d3ddevice.SetRenderState(RenderState.ZWriteEnable, false);
                LevelData.leveleff.RenderLate(d3ddevice, cam);
                d3ddevice.SetRenderState(RenderState.ZWriteEnable, true);
            }

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

            #region Draw Helper Objects
            cam.DrawDistance = 100000;
            projection       = Matrix.PerspectiveFovRH(cam.FOV, cam.Aspect, 1, cam.DrawDistance);
            d3ddevice.SetTransform(TransformState.Projection, projection);
            cam.BuildFrustum(view, projection);

            foreach (PointHelper pointHelper in PointHelper.Instances)
            {
                pointHelper.DrawBox(d3ddevice, cam);
            }

            transformGizmo.Draw(d3ddevice, cam);

            foreach (PointHelper pointHelper in PointHelper.Instances)
            {
                pointHelper.Draw(d3ddevice, cam);
            }

            osd.ProcessMessages();
            #endregion

            d3ddevice.Present();
        }