Ejemplo n.º 1
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (!loaded)
            {
                return;
            }

            if (e.Button == MouseButtons.Middle)
            {
                actionInputCollector.KeyDown(Keys.MButton);
            }

            if (e.Button == MouseButtons.Left)
            {
                HitResult   dist = HitResult.NoHit;
                EventEntity entity = null;
                Vector3     mousepos = new Vector3(e.X, e.Y, 0);
                Viewport    viewport = d3ddevice.Viewport;
                Matrix      proj = d3ddevice.GetTransform(TransformState.Projection);
                Matrix      view = d3ddevice.GetTransform(TransformState.View);
                Vector3     Near, Far;
                Near   = mousepos;
                Near.Z = 0;
                Far    = Near;
                Far.Z  = -1;
                for (int i = 0; i < @event.Scenes[0].Entities.Count; i++)
                {
                    if (@event.Scenes[0].Entities[i].Model != null)
                    {
                        HitResult hit;
                        if (@event.Scenes[0].Entities[i].Model.HasWeight)
                        {
                            hit = @event.Scenes[0].Entities[i].Model.CheckHitWeighted(Near, Far, viewport, proj, view, Matrix.Identity, meshes[0][i]);
                        }
                        else
                        {
                            hit = @event.Scenes[0].Entities[i].Model.CheckHit(Near, Far, viewport, proj, view, new MatrixStack(), meshes[0][i]);
                        }
                        if (hit < dist)
                        {
                            dist   = hit;
                            entity = @event.Scenes[0].Entities[i];
                        }
                    }
                }
                if (scenenum > 0)
                {
                    for (int i = 0; i < @event.Scenes[scenenum].Entities.Count; i++)
                    {
                        if (@event.Scenes[scenenum].Entities[i].Model != null)
                        {
                            HitResult hit;
                            if (@event.Scenes[scenenum].Entities[i].Model.HasWeight)
                            {
                                hit = @event.Scenes[scenenum].Entities[i].Model.CheckHitWeighted(Near, Far, viewport, proj, view, Matrix.Identity, meshes[scenenum][i]);
                            }
                            else if (animframe == -1 || @event.Scenes[scenenum].Entities[i].Motion == null)
                            {
                                hit = @event.Scenes[scenenum].Entities[i].Model.CheckHit(Near, Far, viewport, proj, view, new MatrixStack(), meshes[scenenum][i]);
                            }
                            else
                            {
                                hit = @event.Scenes[scenenum].Entities[i].Model.CheckHitAnimated(Near, Far, viewport, proj, view, new MatrixStack(), meshes[scenenum][i], @event.Scenes[scenenum].Entities[i].Motion, animframe);
                            }
                            if (hit < dist)
                            {
                                dist   = hit;
                                entity = @event.Scenes[scenenum].Entities[i];
                            }
                        }
                    }
                }
                if (dist.IsHit)
                {
                    selectedObject = entity;
                    SelectedItemChanged();
                }
                else
                {
                    selectedObject = null;
                    SelectedItemChanged();
                }
            }

            if (e.Button == MouseButtons.Right)
            {
                contextMenuStrip1.Show(panel1, e.Location);
            }
        }
Ejemplo n.º 2
0
        private void LoadFile(string filename)
        {
            loaded = false;
            Environment.CurrentDirectory = Path.GetDirectoryName(filename);
            timer1.Stop();
            scenenum  = 0;
            animframe = -1;
            @event    = new Event(filename);
            meshes    = new List <List <Mesh[]> >();
            bigmeshes = new List <Mesh[]>();
            foreach (EventScene scene in @event.Scenes)
            {
                List <Mesh[]> scenemeshes = new List <Mesh[]>();
                foreach (EventEntity entity in scene.Entities)
                {
                    if (entity.Model != null)
                    {
                        if (entity.Model.HasWeight)
                        {
                            scenemeshes.Add(entity.Model.ProcessWeightedModel().ToArray());
                        }
                        else
                        {
                            entity.Model.ProcessVertexData();
                            NJS_OBJECT[] models  = entity.Model.GetObjects();
                            Mesh[]       entmesh = new Mesh[models.Length];
                            for (int i = 0; i < models.Length; i++)
                            {
                                if (models[i].Attach != null)
                                {
                                    try { entmesh[i] = models[i].Attach.CreateD3DMesh(); }
                                    catch { }
                                }
                            }
                            scenemeshes.Add(entmesh);
                        }
                    }
                    else
                    {
                        scenemeshes.Add(null);
                    }
                }
                meshes.Add(scenemeshes);
                if (scene.Big?.Model != null)
                {
                    if (scene.Big.Model.HasWeight)
                    {
                        bigmeshes.Add(scene.Big.Model.ProcessWeightedModel().ToArray());
                    }
                    else
                    {
                        scene.Big.Model.ProcessVertexData();
                        NJS_OBJECT[] models  = scene.Big.Model.GetObjects();
                        Mesh[]       entmesh = new Mesh[models.Length];
                        for (int i = 0; i < models.Length; i++)
                        {
                            if (models[i].Attach != null)
                            {
                                try { entmesh[i] = models[i].Attach.CreateD3DMesh(); }
                                catch { }
                            }
                        }
                        bigmeshes.Add(entmesh);
                    }
                }
                else
                {
                    bigmeshes.Add(null);
                }
            }

            TexturePackName = Path.GetFileNameWithoutExtension(filename) + "texture.prs";
            TextureInfo     = TextureArchive.GetTextures(TexturePackName);

            Textures = new Texture[TextureInfo.Length];
            for (int j = 0; j < TextureInfo.Length; j++)
            {
                Textures[j] = TextureInfo[j].Image.ToTexture(d3ddevice);
            }

            loaded         = true;
            selectedObject = null;
            SelectedItemChanged();

            currentFileName = filename;
        }