Esempio n. 1
0
        public override List <RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
        {
            float dist = Direct3D.Extensions.Distance(camera.Position, Position.ToVector3());

            if (dist > camera.DrawDistance)
            {
                return(EmptyRenderInfo);
            }

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

            transform.Push();
            transform.NJTranslate(0, offset, 0);
            transform.NJTranslate(Position);
            transform.NJRotateY(-0x8000 - YRotation);

            if (LevelData.Textures != null && LevelData.Textures.Count > 0 && LevelData.Textures.ContainsKey(texture) && !EditorOptions.DisableTextures)
            {
                if (hasWeight)
                {
                    result.AddRange(Model.DrawModelTreeWeighted(dev.GetRenderState <FillMode>(RenderState.FillMode), transform.Top, LevelData.Textures[texture], Meshes, EditorOptions.IgnoreMaterialColors, EditorOptions.OverrideLighting));
                }
                else
                {
                    result.AddRange(Model.DrawModelTree(dev.GetRenderState <FillMode>(RenderState.FillMode), transform, LevelData.Textures[texture], Meshes, EditorOptions.IgnoreMaterialColors, EditorOptions.OverrideLighting));
                }
            }
            else
            {
                if (hasWeight)
                {
                    result.AddRange(Model.DrawModelTreeWeighted(dev.GetRenderState <FillMode>(RenderState.FillMode), transform.Top, null, Meshes, EditorOptions.IgnoreMaterialColors));
                }
                else
                {
                    result.AddRange(Model.DrawModelTree(dev.GetRenderState <FillMode>(RenderState.FillMode), transform, null, Meshes, EditorOptions.IgnoreMaterialColors));
                }
            }
            if (Selected)
            {
                if (hasWeight)
                {
                    result.AddRange(Model.DrawModelTreeWeightedInvert(transform.Top, Meshes, EditorOptions.IgnoreMaterialColors));
                }
                else
                {
                    result.AddRange(Model.DrawModelTreeInvert(transform, Meshes, EditorOptions.IgnoreMaterialColors));
                }
            }
            transform.Pop();
            return(result);
        }
Esempio n. 2
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();
        }