Ejemplo n.º 1
0
        private void AddToSceneTreeView(TreeNode node, ObjectBase obj)
        {
            var tempNode = new TreeNode(obj.Name);
            tempNode.Name = obj.UniqueId;
            int imageIndex = 1;

            if (obj.GetType().Equals(typeof(DirectionalLight)))
                imageIndex = 2;
            else if (obj.GetType().Equals(typeof(PointLight)))
                imageIndex = 3;
            else if (obj.GetType().Equals(typeof(Sound)))
                imageIndex = 4;
            else if (obj.GetType().Equals(typeof(Engine.Mesh)))
                imageIndex = 5;
            else if (obj.GetType().Equals(typeof(SkySphere)))
                imageIndex = 6;
            else if (obj.GetType().Equals(typeof(SkyBox)))
                imageIndex = 7;
            else if (obj.GetType().Equals(typeof(Water)))
                imageIndex = 8;
            else if (obj.GetType().Equals(typeof(Landscape)))
                imageIndex = 9;
            else if (obj.GetType().Equals(typeof(Trigger)))
                imageIndex = 10;
            else if (obj.GetType().Equals(typeof(Particle)))
                imageIndex = 11;

            tempNode.ImageIndex = imageIndex;
            tempNode.SelectedImageIndex = imageIndex;
            node.Nodes.Add(tempNode);
        }
Ejemplo n.º 2
0
        private ObjectBase CreateObjectCopy(ObjectBase selectedObject)
        {
            Cursor tmpCursor = Cursor.Current;
            Cursor = Cursors.WaitCursor;

            if (selectedObject.GetType().Equals(typeof(Engine.Mesh)))
            {
                var mesh = new Engine.Mesh(core, Settings, selectedObject.FileName);
                mesh.IsAnimated = (selectedObject as Engine.Mesh).IsAnimated;
                mesh.CustomTexture = (selectedObject as Engine.Mesh).CustomTexture;
                mesh.Visible = selectedObject.Visible;
                mesh.Position = selectedObject.Position;
                mesh.Rotation = selectedObject.Rotation;
                mesh.Scale = selectedObject.Scale;
                mesh.Mass = (selectedObject as Engine.Mesh).Mass;
                mesh.Bounding = (selectedObject as Engine.Mesh).Bounding;
                mesh.KineticFriction = (selectedObject as Engine.Mesh).KineticFriction;
                mesh.StaticFriction = (selectedObject as Engine.Mesh).StaticFriction;
                mesh.Bounciness = (selectedObject as Engine.Mesh).Bounciness;
                mesh.Softness = (selectedObject as Engine.Mesh).Softness;
                mesh.Material = (selectedObject as Engine.Mesh).Material;
                mesh.EnableLightning = (selectedObject as Engine.Mesh).EnableLightning;
                mesh.SetCustomCollection((selectedObject as Engine.Mesh).CustomParams);
                mesh.TextureScale = (selectedObject as Engine.Mesh).TextureScale;
                mesh.ScriptEnabled = (selectedObject as Engine.Mesh).ScriptEnabled;
                mesh.Script = (selectedObject as Engine.Mesh).Script.Replace((selectedObject as Engine.Mesh).Name, mesh.Name);
                mesh.Update();
                AddToSceneTreeView(sceneObjectsNode, mesh);
                Cursor = tmpCursor;
                return mesh;
            }

            if (selectedObject.GetType().Equals(typeof(PointLight)))
            {
                VECTOR3D pos = selectedObject.Position;
                var pointLight = (PointLight)selectedObject;
                var light = new PointLight(core, new TV_3DVECTOR(pos.X, pos.Y, pos.Z));
                light.Color = pointLight.Color;
                light.Radius = pointLight.Radius;
                light.Visible = pointLight.Visible;
                light.SetCustomCollection(pointLight.CustomParams);
                light.Update();
                AddToSceneTreeView(sceneLightsNode, light);
                Cursor = tmpCursor;
                return light;
            }

            if (selectedObject.GetType().Equals(typeof(Sound)))
            {
                var sound = new Sound(core, selectedObject.FileName);
                sound.Position = selectedObject.Position;
                sound.Stopped = (selectedObject as Sound).Stopped;
                sound.Volume = (selectedObject as Sound).Volume;
                sound.Loop = (selectedObject as Sound).Loop;
                sound.Is3D = (selectedObject as Sound).Is3D;
                sound.SetCustomCollection((selectedObject as Sound).CustomParams);
                sound.Update();
                AddToSceneTreeView(sceneSoundsNode, sound);
                Cursor = tmpCursor;
                return sound;
            }

            if (selectedObject.GetType().Equals(typeof(Engine.Trigger)))
            {
                var trigger = new Engine.Trigger(core);
                trigger.Position = selectedObject.Position;
                trigger.Rotation = selectedObject.Rotation;
                trigger.Scale = selectedObject.Scale;
                trigger.Color = (selectedObject as Trigger).Color;
                trigger.SetCustomCollection((selectedObject as Engine.Trigger).CustomParams);
                trigger.Update();
                AddToSceneTreeView(sceneTriggersNode, trigger);
                Cursor = tmpCursor;
                return trigger;
            }

            if (selectedObject.GetType().Equals(typeof(Engine.Particle)))
            {
                var particle = new Engine.Particle(core, selectedObject.FileName);
                particle.Position = selectedObject.Position;
                particle.Rotation = selectedObject.Rotation;
                particle.Scale = selectedObject.Scale;
                particle.Visible = selectedObject.Visible;
                particle.SetCustomCollection((selectedObject as Engine.Particle).CustomParams);
                particle.Update();
                AddToSceneTreeView(sceneParticlesNode, particle);
                Cursor = tmpCursor;
                return particle;
            }

            return null;
        }
Ejemplo n.º 3
0
 private void DeselectAllObjects()
 {
     propertyGrid.SelectedObject = null;
     selectedObject = null;
     foreach (var ob in core.AllObjects)
     {
         ob.Deselect();
     }
 }
Ejemplo n.º 4
0
 private void UpdateSelectedObject(ObjectBase obj)
 {
     obj.Update();
     propertyGrid.SelectedObject = obj;
 }
Ejemplo n.º 5
0
        private void UpdateInput()
        {
            try
            {
                int mouseRelativeX = 0;
                int mouseRelativeY = 0;
                int mouseAbsoluteX = 0;
                int mouseAbsoluteY = 0;
                int mouseScroll = 0;
                bool mouseB1 = false;
                bool mouseB2 = false;
                bool mouseB3 = false;
                bool mouseB4 = false;

                core.Input.GetMouseState(ref mouseRelativeX, ref mouseRelativeY, ref mouseB1, ref mouseB2, ref mouseB3,
                                         ref mouseB4, ref mouseScroll);
                core.Input.GetAbsMouseState(ref mouseAbsoluteX, ref mouseAbsoluteY, ref mouseB1, ref mouseB2,
                                            ref mouseB3);
                core.CollisionResult = core.Scene.MousePick(mouseAbsoluteX, mouseAbsoluteY,
                                                            (int)CONST_TV_OBJECT_TYPE.TV_OBJECT_MESH);

                FPSCamera(0, 0, mouseScroll, false);
                if (mouseB1 && !core.PreviewingScene)
                {
                    if (selectedTool == Tool.None && core.CollisionResult.IsCollision())
                    {
                        DeselectAllObjects();

                        TVMesh colMesh = core.CollisionResult.GetCollisionMesh();
                        selectedObject = core.GetObjectByUniqueId(colMesh.GetMeshName());

                        selectedObject.Select();
                        propertyGrid.SelectedObject = selectedObject;
                    }

                    if (selectedObject != null)
                    {
                        if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFTCONTROL) && !creatingObjectCopy)
                        {
                            creatingObjectCopy = true;
                            selectedObject = CreateObjectCopy(selectedObject);
                        }

                        switch (selectedTool)
                        {
                            case Tool.MoveHorizontal:
                                MoveHorizontal(mouseAbsoluteX, mouseAbsoluteY);
                                break;
                            case Tool.MoveVertical:
                                MoveVertical(mouseAbsoluteX, mouseAbsoluteY);
                                break;
                        }
                    }
                }
                else if (core.PreviewingScene)
                {
                    if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_ESCAPE))
                    {
                        core.PreviewingScene = false;
                        PrepareObjectsForPreview(false);
                        Thread.Sleep(200);
                    }
                    else if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_F6))
                    {
                        PreviewReset();
                    }
                    else
                    {
                        Cursor.Position = oldMousePosition;
                        pnlRenderer.Focus();
                        core.Engine.ShowWinCursor(false);
                        core.SoundFactory.StartAllSounds();
                        FPSCamera(mouseRelativeX, mouseRelativeY, mouseScroll, true);
                    }
                }
                else if (mouseB2)
                {
                    Cursor.Position = oldMousePosition;
                    pnlRenderer.Focus();
                    core.Engine.ShowWinCursor(false);
                    core.SoundFactory.StartAllSounds();
                    FPSCamera(mouseRelativeX, mouseRelativeY, mouseScroll, true);
                }
                else
                {
                    if (selectedTool != Tool.None)
                    {
                        DeselectAllObjects();

                        if (core.CollisionResult.IsCollision())
                        {
                            ChangeMouseCursor();
                            mousePosition3D = core.Globals.Vector3(0, 0, 0);
                            TVMesh colMesh = core.CollisionResult.GetCollisionMesh();
                            selectedObject = core.GetObjectByUniqueId(colMesh.GetMeshName());
                            selectedObject.Select();
                            propertyGrid.SelectedObject = selectedObject;
                        }
                        else
                        {
                            Cursor = Cursors.Default;
                        }
                    }

                    if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_DELETE))
                    {
                        RemoveSelectedObject();
                    }
                    else if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_ESCAPE) ||
                             core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_SPACE))
                    {
                        core.PreviewingScene = false;
                        selectedTool = Tool.None;
                        Cursor = Cursors.Default;
                        DeselectAllObjects();
                    }
                    else if (!core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFTCONTROL))
                    {
                        creatingObjectCopy = false;
                    }

                    if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_Q))
                    {
                        SelectHorizontalTool();
                    }

                    if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_E))
                    {
                        SelectVerticalTool();
                    }

                    if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_C))
                    {
                        PutObjectOnGround();
                    }

                    if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_F6))
                    {
                        StartPreview();
                    }

                    if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_F5))
                    {
                        RunProgram();
                    }

                    oldMousePosition = Cursor.Position;
                    core.Engine.ShowWinCursor(true);
                    core.SoundFactory.StopAllSounds();
                    UpdateMenu();
                }

                // Update all objects if not scene preview.
                if (!core.PreviewingScene)
                    core.AllObjects.ForEach(o => o.Update());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 6
0
        private void tvObjects_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            var type = Helpers.GetObjectType(e.Node.FullPath);
            var fullPath = Path.Combine(Application.StartupPath, e.Node.FullPath);
            var position = core.Camera.GetFrontPosition(10.0f);

            position.x = (float)Math.Round(position.x);
            position.y = (float)Math.Round(position.y);
            position.z = (float)Math.Round(position.z);

            bool skyBoxExists, skySphereExists = false;
            switch (type)
            {
                case Helpers.ObjectType.DirectionalLight:
                    var sunId = -1;
                    sunId = core.LightEngine.GetLightFromName(Helpers.SUN);
                    if (sunId == -1)
                    {
                        var directionalLight = new DirectionalLight(core, position);
                        directionalLight.Update();
                        selectedObject = directionalLight;
                        AddToSceneTreeView(sceneLightsNode, directionalLight);
                    }
                    else
                    {
                        MessageBox.Show("There should be only one directional light.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;
                case Helpers.ObjectType.PointLight:
                    var pointLight = new PointLight(core, position);
                    pointLight.Update();
                    selectedObject = pointLight;
                    AddToSceneTreeView(sceneLightsNode, pointLight);
                    break;
                case Helpers.ObjectType.SpotLight:
                    MessageBox.Show("Not implemented.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                case Helpers.ObjectType.StaticMesh:
                    var mesh = new Engine.Mesh(core, Settings, fullPath)
                                   {
                                       Position = new VECTOR3D(position.x, position.y, position.z)
                                   };
                    mesh.Update();
                    selectedObject = mesh;
                    AddToSceneTreeView(sceneObjectsNode, mesh);
                    break;
                case Helpers.ObjectType.AnimatedMesh:
                    var animatedMesh = new Engine.Mesh(core, Settings, fullPath)
                    {
                        Position = new VECTOR3D(position.x, position.y, position.z)
                    };
                    animatedMesh.Update();
                    selectedObject = animatedMesh;
                    AddToSceneTreeView(sceneObjectsNode, animatedMesh);
                    break;
                case Helpers.ObjectType.Sound:
                    var sound = new Sound(core, fullPath);
                    sound.Update();
                    selectedObject = sound;
                    AddToSceneTreeView(sceneSoundsNode, sound);
                    break;
                case Helpers.ObjectType.SkyBox:
                    skyBoxExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkyBox)) == null ? false : true;
                    if (skyBoxExists)
                        break;
                    skySphereExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkySphere)) == null ? false : true;
                    if (skySphereExists)
                    {
                        if (MessageBox.Show("This will remove existing sky sphere. Remove?", "Remove sky sphere?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                        {
                            selectedObject = core.AllObjects.FindLast(o => o.GetType() == typeof(SkySphere));
                            RemoveSelectedObject();
                        }
                        else
                            break;
                    }
                    var skyBox = new SkyBox(core);
                    skyBox.Update();
                    AddToSceneTreeView(sceneSkyNode, skyBox);
                    selectedObject = skyBox;
                    break;
                case Helpers.ObjectType.SkySphere:
                    skySphereExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkySphere)) == null ? false : true;
                    if (skySphereExists)
                        break;
                    skyBoxExists = core.AllObjects.FindLast(o => o.GetType() == typeof(SkyBox)) == null ? false : true;
                    if (skyBoxExists)
                    {
                        if (MessageBox.Show("This will remove existing sky box. Remove?", "Remove sky box?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                        {
                            selectedObject = core.AllObjects.FindLast(o => o.GetType() == typeof(SkyBox));
                            RemoveSelectedObject();
                        }
                        else
                            break;
                    }
                    var skySphere = new SkySphere(core);
                    skySphere.Update();
                    AddToSceneTreeView(sceneSkyNode, skySphere);
                    selectedObject = skySphere;
                    break;
                case Helpers.ObjectType.Water:
                    var water = new Water(core);
                    selectedObject = water;
                    AddToSceneTreeView(sceneWaterNode, water);
                    break;
                case Helpers.ObjectType.Landscape:
                    var landscape = new Landscape(core)
                    {
                        Position = new VECTOR3D(position.x, position.y, position.z)
                    };
                    landscape.Update();
                    selectedObject = landscape;
                    AddToSceneTreeView(sceneLandscapeNode, landscape);
                    break;
                case Helpers.ObjectType.Trigger:
                    var trigger = new Trigger(core)
                    {
                        Position = new VECTOR3D(position.x, position.y, position.z)
                    };
                    trigger.Update();
                    selectedObject = trigger;
                    AddToSceneTreeView(sceneTriggersNode, trigger);
                    break;
                case Helpers.ObjectType.Particle:
                    var particle = new Particle(core, fullPath);
                    particle.Update();
                    selectedObject = particle;
                    AddToSceneTreeView(sceneParticlesNode, particle);
                    break;
                case Helpers.ObjectType.NotDetected:
                    RunRegisteredExtension(fullPath);
                    break;
            }

            propertyGrid.SelectedObject = selectedObject;

            Cursor = Cursors.Default;
        }
Ejemplo n.º 7
0
        private bool SelectObject(ObjectBase obj)
        {
            if (obj != null)
            {
                var o = core.GetObjectByUniqueId(obj.UniqueId);

                if (o != null)
                {
                    DeselectAllObjects();
                    selectedObject = o;
                    selectedObject.Select();
                    propertyGrid.SelectedObject = selectedObject;

                    return true;
                }

                return false;
            }

            return false;
        }
Ejemplo n.º 8
0
        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            selectedObject = core.GetObjectByUniqueId(tvSceneObjects.SelectedNode.Name);

            if (selectedObject != null)
            {
                RemoveSelectedObject();
            }
        }